Compare commits

..

9 Commits

5 changed files with 71 additions and 24 deletions
+11 -4
View File
@@ -6,14 +6,14 @@
<groupId>me.youhavetrouble</groupId>
<artifactId>PreventStabby</artifactId>
<version>2.0.0-pre-2</version>
<version>2.0.0-pre-5</version>
<packaging>jar</packaging>
<name>PreventStabby</name>
<description>Stop people from getting stabbed!</description>
<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -31,7 +31,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -46,6 +46,13 @@
<shadedPattern>me.youhavetrouble.preventstabby.bstats</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
@@ -78,7 +85,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -1,16 +1,14 @@
package me.youhavetrouble.preventstabby.config;
import me.youhavetrouble.preventstabby.PreventStabby;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class ConfigCache {
@@ -36,6 +34,7 @@ public class ConfigCache {
public final double combat_time, login_protection_time, teleport_protection_time, bucket_stopper_radius,
fire_stopper_radius, block_stopper_radius;
private final Set<String> combatBlockedCommands = new HashSet<>();
private final Set<Material> dangerousBlocks = new HashSet<>();
private final FileConfiguration config;
@@ -66,12 +65,14 @@ public class ConfigCache {
List.of("Should killing of a player that logged out of combat be announced?")
);
this.combatBlockedCommands.addAll(getList(
List<String> commandsBlockedInCombat = getList(
"settings.block_in_combat.commands",
List.of("spawn", "tpa", "home"),
List.of("Commands to block when player is in combat")
)
);
for (String command : commandsBlockedInCombat) {
this.combatBlockedCommands.add(command.toLowerCase(Locale.ENGLISH));
}
this.block_teleports_in_combat = getBoolean(
"settings.block_in_combat.teleports",
@@ -125,6 +126,21 @@ public class ConfigCache {
2.5,
List.of("Distance from the player where placing dangerous blocks will be disallowed")
);
List<String> rawDangerousBlocks = getList(
"settings.environmental.block_stopper.blocks",
List.of("tnt", "magma_block", "cactus", "campfire"),
List.of("List of dangerous blocks that will be blocked when placed near players with pvp off")
);
for (String block : rawDangerousBlocks) {
Material material = Material.matchMaterial(block);
if (material != null) {
dangerousBlocks.add(material);
} else {
plugin.getLogger().warning("Invalid material: " + block);
}
}
// Messages
this.pvp_enabled = getString("messages.pvp_enabled", "<red>You enabled PvP!");
@@ -174,6 +190,10 @@ public class ConfigCache {
return Collections.unmodifiableSet(combatBlockedCommands);
}
public Set<Material> getDangerousBlocks() {
return Collections.unmodifiableSet(dangerousBlocks);
}
private String getString(String path, @NotNull String def) {
return getString(path, def, null);
}
@@ -31,7 +31,7 @@ public class EnvironmentalListener implements Listener {
dangerousBuckets.add(Material.POWDER_SNOW_BUCKET);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onDangerousBucketDump(PlayerBucketEmptyEvent event) {
ConfigCache config = plugin.getConfigCache();
if (!config.bucket_stopper_enabled) return;
@@ -53,7 +53,7 @@ public class EnvironmentalListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent event) {
ConfigCache config = plugin.getConfigCache();
if (!config.fire_stopper_enabled) return;
@@ -77,14 +77,15 @@ public class EnvironmentalListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockIgnite(BlockPlaceEvent event) {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onDangerousBlockPlace(BlockPlaceEvent event) {
ConfigCache config = plugin.getConfigCache();
if (!config.block_stopper_enabled) return;
Player player = event.getPlayer();
Location location = event.getBlock().getLocation().toCenterLocation();
Target target = Target.getTarget(player);
if (target == null) return;
if (!config.getDangerousBlocks().contains(event.getBlock().getType())) return;
double radius = config.block_stopper_radius;
BoundingBox boundingBox = BoundingBox.of(location.toVector(), radius, radius, radius);
@@ -2,19 +2,20 @@ package me.youhavetrouble.preventstabby.listeners;
import me.youhavetrouble.preventstabby.PreventStabby;
import me.youhavetrouble.preventstabby.data.DamageCheckResult;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.Locale;
public class PvpListener implements Listener {
@@ -24,7 +25,7 @@ public class PvpListener implements Listener {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity victim = event.getEntity();
@@ -36,7 +37,7 @@ public class PvpListener implements Listener {
plugin.getPlayerManager().handleDamageCheck(result);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
if (!(event.getEntity().getShooter() instanceof Player thrower)) return;
boolean harmful = false;
@@ -56,11 +57,14 @@ public class PvpListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPotionCloudEffectApply(AreaEffectCloudApplyEvent event) {
if (!(event.getEntity().getSource() instanceof Player thrower)) return;
boolean harmful = false;
for (PotionEffect effect : event.getEntity().getBasePotionType().getPotionEffects()) {
AreaEffectCloud cloud = event.getEntity();
if (cloud.getBasePotionType() == null) return;
PotionType potionType = cloud.getBasePotionType();
for (PotionEffect effect : potionType.getPotionEffects()) {
if (!PotionEffectType.Category.HARMFUL.equals(effect.getType().getEffectCategory())) continue;
harmful = true;
break;
@@ -78,7 +82,7 @@ public class PvpListener implements Listener {
});
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFish(PlayerFishEvent event) {
if (event.getCaught() instanceof Item) return;
if (plugin.getConfigCache().allow_fishing_rod_pull) return;
@@ -93,4 +97,19 @@ public class PvpListener implements Listener {
plugin.getPlayerManager().handleDamageCheck(result);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCommandInCombat(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (!plugin.getPlayerManager().getPlayer(player.getUniqueId()).isInCombat()) return;
String message = event.getMessage().toLowerCase(Locale.ROOT);
if (message.startsWith("/")) {
message = message.substring(1);
}
message = message.split(" ")[0];
if (!plugin.getConfigCache().getCombatBlockedCommands().contains(message)) return;
event.setCancelled(true);
player.sendMessage(plugin.getConfigCache().cant_do_that_during_combat);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ name: PreventStabby
version: ${project.version}
main: me.youhavetrouble.preventstabby.PreventStabby
authors: [YouHaveTrouble]
api-version: 1.20
api-version: 1.21
folia-supported: true
description: Stop people from getting stabbed!
soft-depend: