mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-11 21:06:55 +00:00
stop specified commands from being able to execute in combat
This commit is contained in:
@@ -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!");
|
||||||
|
|||||||
@@ -12,10 +12,13 @@ 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 java.util.Locale;
|
||||||
|
|
||||||
public class PvpListener implements Listener {
|
public class PvpListener implements Listener {
|
||||||
|
|
||||||
private final PreventStabby plugin;
|
private final PreventStabby plugin;
|
||||||
@@ -93,4 +96,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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user