mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 05:16:55 +00:00
added combat command blocker and teleport blocker
This commit is contained in:
@@ -5,19 +5,25 @@ import io.github.thatsmusic99.configurationmaster.CMFile;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ConfigCache {
|
public class ConfigCache {
|
||||||
|
|
||||||
private final TogglePvp plugin = TogglePvp.getPlugin();
|
private final TogglePvp plugin = TogglePvp.getPlugin();
|
||||||
|
|
||||||
@Getter private final boolean pvp_enabled_by_default, lava_and_fire_stopper_enabled, channeling_enchant_disabled,
|
@Getter private final boolean pvp_enabled_by_default, lava_and_fire_stopper_enabled, channeling_enchant_disabled,
|
||||||
punish_for_combat_logout, punish_for_combat_logout_announce, only_owner_can_interact_with_pet,
|
punish_for_combat_logout, punish_for_combat_logout_announce, only_owner_can_interact_with_pet,
|
||||||
snowballs_knockback, egg_knockback;
|
snowballs_knockback, egg_knockback, block_commands_in_combat, block_teleports_in_combat;
|
||||||
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
||||||
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
||||||
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
||||||
cant_do_that_during_combat;
|
cant_do_that_during_combat;
|
||||||
@Getter private final double lava_and_fire_stopper_radius;
|
@Getter private final double lava_and_fire_stopper_radius;
|
||||||
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||||
|
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||||
|
|
||||||
public ConfigCache() {
|
public ConfigCache() {
|
||||||
|
|
||||||
@@ -50,6 +56,15 @@ public class ConfigCache {
|
|||||||
|
|
||||||
addDefault("settings.eggs_do_knockback", false, "Set to true if eggs should cause knockback to players");
|
addDefault("settings.eggs_do_knockback", false, "Set to true if eggs should cause knockback to players");
|
||||||
|
|
||||||
|
addComment("settings.block_in_combat", "Set what actions should be blocked while in combat");
|
||||||
|
addDefault("settings.block_in_combat.block_commands.enabled", true);
|
||||||
|
List<String> defaultCommandsBlocked = new ArrayList<>();
|
||||||
|
defaultCommandsBlocked.add("spawn");
|
||||||
|
defaultCommandsBlocked.add("tpa");
|
||||||
|
defaultCommandsBlocked.add("home");
|
||||||
|
addDefault("settings.block_in_combat.block_commands.commands", defaultCommandsBlocked);
|
||||||
|
addDefault("settings.block_in_combat.block_teleports", true, "Set if players should be denied teleportation attempts while in combat");
|
||||||
|
|
||||||
addDefault("settings.cache_time", 30, "Time (in seconds) to keep player data in memory when players goes offline.\nThis is used for checking if offline players pvp state.\nAdjust only if you know what you're doing. NEVER set to less than 6.");
|
addDefault("settings.cache_time", 30, "Time (in seconds) to keep player data in memory when players goes offline.\nThis is used for checking if offline players pvp state.\nAdjust only if you know what you're doing. NEVER set to less than 6.");
|
||||||
|
|
||||||
addDefault("messages.pvp_enabled", "&cYou enabled PvP!");
|
addDefault("messages.pvp_enabled", "&cYou enabled PvP!");
|
||||||
@@ -91,6 +106,11 @@ public class ConfigCache {
|
|||||||
|
|
||||||
this.snowballs_knockback = config.getBoolean("settings.snowballs_do_knockback", false);
|
this.snowballs_knockback = config.getBoolean("settings.snowballs_do_knockback", false);
|
||||||
this.egg_knockback = config.getBoolean("settings.eggs_do_knockback", false);
|
this.egg_knockback = config.getBoolean("settings.eggs_do_knockback", false);
|
||||||
|
this.block_commands_in_combat = config.getBoolean("settings.block_in_combat.block_commands", true);
|
||||||
|
if (block_commands_in_combat) {
|
||||||
|
this.combatBlockedCommands.addAll(config.getStringList("settings.block_in_combat.block_commands.commands"));
|
||||||
|
}
|
||||||
|
this.block_teleports_in_combat = config.getBoolean("settings.block_in_combat.block_teleports", true);
|
||||||
|
|
||||||
this.cache_time = config.getLong("settings.cache_time", 30L);
|
this.cache_time = config.getLong("settings.cache_time", 30L);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package eu.endermite.togglepvp.listeners.toggles;
|
||||||
|
|
||||||
|
import eu.endermite.togglepvp.TogglePvp;
|
||||||
|
import eu.endermite.togglepvp.players.PlayerManager;
|
||||||
|
import eu.endermite.togglepvp.util.PluginMessages;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
@eu.endermite.togglepvp.util.Listener
|
||||||
|
public class CombatCommandListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerCommandInCombat(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||||
|
|
||||||
|
if (!TogglePvp.getPlugin().getConfigCache().isBlock_commands_in_combat())
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlayerManager playerManager = TogglePvp.getPlugin().getPlayerManager();
|
||||||
|
|
||||||
|
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
||||||
|
return;
|
||||||
|
|
||||||
|
String command = event.getMessage().replaceFirst("/", "");
|
||||||
|
|
||||||
|
if (!TogglePvp.getPlugin().getConfigCache().getCombatBlockedCommands().contains(command))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.getPlayer().hasPermission("toglepvp.combatcommandblock.bypass"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
PluginMessages.sendMessage(event.getPlayer(), TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.endermite.togglepvp.listeners.toggles;
|
||||||
|
|
||||||
|
import eu.endermite.togglepvp.TogglePvp;
|
||||||
|
import eu.endermite.togglepvp.players.PlayerManager;
|
||||||
|
import eu.endermite.togglepvp.util.PluginMessages;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
@eu.endermite.togglepvp.util.Listener
|
||||||
|
public class PlayerTeleportInCombatListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerTeleportInCombat(org.bukkit.event.player.PlayerTeleportEvent event) {
|
||||||
|
|
||||||
|
if (!TogglePvp.getPlugin().getConfigCache().isBlock_teleports_in_combat())
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlayerManager playerManager = TogglePvp.getPlugin().getPlayerManager();
|
||||||
|
|
||||||
|
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.getPlayer().hasPermission("toglepvp.combatteleportblock.bypass"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
PluginMessages.sendMessage(event.getPlayer(), TogglePvp.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,6 +17,11 @@ public class PluginMessages {
|
|||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendMessage(Player player, String message) {
|
||||||
|
String parsedMessage = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
player.sendMessage(parsedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendActionBar(Player player, String message) {
|
public static void sendActionBar(Player player, String message) {
|
||||||
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
||||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ commands:
|
|||||||
pvp:
|
pvp:
|
||||||
usage: /pvp [args]
|
usage: /pvp [args]
|
||||||
permissions:
|
permissions:
|
||||||
|
toglepvp.combatcommandblock.bypass:
|
||||||
|
default: op
|
||||||
|
description: Allows to bypass combat command blocker
|
||||||
|
toglepvp.combatteleportblock.bypass:
|
||||||
|
default: op
|
||||||
|
description: Allows to bypass combat teleport blocker
|
||||||
togglepvp.command:
|
togglepvp.command:
|
||||||
default: true
|
default: true
|
||||||
description: Allows usage of /pvp command
|
description: Allows usage of /pvp command
|
||||||
|
|||||||
Reference in New Issue
Block a user