Compare commits

..

7 Commits

5 changed files with 50 additions and 23 deletions
+11 -4
View File
@@ -6,14 +6,14 @@
<groupId>me.youhavetrouble</groupId> <groupId>me.youhavetrouble</groupId>
<artifactId>PreventStabby</artifactId> <artifactId>PreventStabby</artifactId>
<version>2.0.0-pre-2</version> <version>2.0.0-pre-4</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>PreventStabby</name> <name>PreventStabby</name>
<description>Stop people from getting stabbed!</description> <description>Stop people from getting stabbed!</description>
<properties> <properties>
<java.version>17</java.version> <java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
@@ -31,7 +31,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -46,6 +46,13 @@
<shadedPattern>me.youhavetrouble.preventstabby.bstats</shadedPattern> <shadedPattern>me.youhavetrouble.preventstabby.bstats</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
</manifestEntries>
</transformer>
</transformers>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@@ -78,7 +85,7 @@
<dependency> <dependency>
<groupId>io.papermc.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version> <version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -7,10 +7,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ConfigCache { public class ConfigCache {
@@ -66,12 +63,14 @@ public class ConfigCache {
List.of("Should killing of a player that logged out of combat be announced?") 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", "settings.block_in_combat.commands",
List.of("spawn", "tpa", "home"), List.of("spawn", "tpa", "home"),
List.of("Commands to block when player is in combat") 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( this.block_teleports_in_combat = getBoolean(
"settings.block_in_combat.teleports", "settings.block_in_combat.teleports",
@@ -126,6 +125,8 @@ public class ConfigCache {
List.of("Distance from the player where placing dangerous blocks will be disallowed") List.of("Distance from the player where placing dangerous blocks will be disallowed")
); );
// Messages // Messages
this.pvp_enabled = getString("messages.pvp_enabled", "<red>You enabled PvP!"); this.pvp_enabled = getString("messages.pvp_enabled", "<red>You enabled PvP!");
this.pvp_disabled = getString("messages.pvp_disabled", "<red>You disabled PvP!"); this.pvp_disabled = getString("messages.pvp_disabled", "<red>You disabled PvP!");
@@ -31,7 +31,7 @@ public class EnvironmentalListener implements Listener {
dangerousBuckets.add(Material.POWDER_SNOW_BUCKET); dangerousBuckets.add(Material.POWDER_SNOW_BUCKET);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onDangerousBucketDump(PlayerBucketEmptyEvent event) { public void onDangerousBucketDump(PlayerBucketEmptyEvent event) {
ConfigCache config = plugin.getConfigCache(); ConfigCache config = plugin.getConfigCache();
if (!config.bucket_stopper_enabled) return; 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) { public void onBlockIgnite(BlockIgniteEvent event) {
ConfigCache config = plugin.getConfigCache(); ConfigCache config = plugin.getConfigCache();
if (!config.fire_stopper_enabled) return; if (!config.fire_stopper_enabled) return;
@@ -77,7 +77,7 @@ public class EnvironmentalListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockIgnite(BlockPlaceEvent event) { public void onBlockIgnite(BlockPlaceEvent event) {
ConfigCache config = plugin.getConfigCache(); ConfigCache config = plugin.getConfigCache();
if (!config.block_stopper_enabled) return; if (!config.block_stopper_enabled) return;
@@ -2,19 +2,20 @@ package me.youhavetrouble.preventstabby.listeners;
import me.youhavetrouble.preventstabby.PreventStabby; import me.youhavetrouble.preventstabby.PreventStabby;
import me.youhavetrouble.preventstabby.data.DamageCheckResult; import me.youhavetrouble.preventstabby.data.DamageCheckResult;
import org.bukkit.entity.Entity; import org.bukkit.entity.*;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.Locale;
public class PvpListener implements Listener { public class PvpListener implements Listener {
@@ -24,7 +25,7 @@ public class PvpListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(EntityDamageByEntityEvent event) { public void onEntityDamage(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
Entity victim = event.getEntity(); Entity victim = event.getEntity();
@@ -36,7 +37,7 @@ public class PvpListener implements Listener {
plugin.getPlayerManager().handleDamageCheck(result); plugin.getPlayerManager().handleDamageCheck(result);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) { public void onPotionSplash(PotionSplashEvent event) {
if (!(event.getEntity().getShooter() instanceof Player thrower)) return; if (!(event.getEntity().getShooter() instanceof Player thrower)) return;
boolean harmful = false; 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) { public void onPotionCloudEffectApply(AreaEffectCloudApplyEvent event) {
if (!(event.getEntity().getSource() instanceof Player thrower)) return; if (!(event.getEntity().getSource() instanceof Player thrower)) return;
boolean harmful = false; 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; if (!PotionEffectType.Category.HARMFUL.equals(effect.getType().getEffectCategory())) continue;
harmful = true; harmful = true;
break; 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) { public void onFish(PlayerFishEvent event) {
if (event.getCaught() instanceof Item) return; if (event.getCaught() instanceof Item) return;
if (plugin.getConfigCache().allow_fishing_rod_pull) return; if (plugin.getConfigCache().allow_fishing_rod_pull) return;
@@ -93,4 +97,19 @@ public class PvpListener implements Listener {
plugin.getPlayerManager().handleDamageCheck(result); 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} version: ${project.version}
main: me.youhavetrouble.preventstabby.PreventStabby main: me.youhavetrouble.preventstabby.PreventStabby
authors: [YouHaveTrouble] authors: [YouHaveTrouble]
api-version: 1.20 api-version: 1.21
folia-supported: true folia-supported: true
description: Stop people from getting stabbed! description: Stop people from getting stabbed!
soft-depend: soft-depend: