mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 05:16:55 +00:00
comand work
This commit is contained in:
@@ -38,8 +38,34 @@ public class PvpToggleCommand {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Try /pvp toggle <player>");
|
sender.sendMessage("Try /pvp toggle <player>");
|
||||||
}
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (!sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
String message = TogglePvP.getPlugin().getConfigCache().getNo_permission();
|
||||||
|
BaseComponent[] component = TextComponent.fromLegacyText(message);
|
||||||
|
sender.spigot().sendMessage(component);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Player player = Bukkit.getPlayer(args[1]);
|
||||||
|
boolean currentState = TogglePvP.getPlugin().getPlayerManager().togglePlayerPvpState(player);
|
||||||
|
String message;
|
||||||
|
if (currentState) {
|
||||||
|
message = TogglePvP.getPlugin().getConfigCache().getPvp_enabled_other();
|
||||||
|
} else {
|
||||||
|
message = TogglePvP.getPlugin().getConfigCache().getPvp_disabled_other();
|
||||||
|
}
|
||||||
|
sender.sendMessage(PluginMessages.parsePlayerName(player, message));
|
||||||
|
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
sender.sendMessage(PluginMessages.parseMessage("&cPlayer offline."));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
sender.sendMessage("Try /pvp toggle <player>");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Try /pvp toggle");
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +86,27 @@ public class PvpToggleCommand {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Try /pvp enable <player>");
|
sender.sendMessage("Try /pvp enable <player>");
|
||||||
}
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (!sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
String message = TogglePvP.getPlugin().getConfigCache().getNo_permission();
|
||||||
|
BaseComponent[] component = TextComponent.fromLegacyText(message);
|
||||||
|
sender.spigot().sendMessage(component);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Player player = Bukkit.getPlayer(args[1]);
|
||||||
|
String message = TogglePvP.getPlugin().getConfigCache().getPvp_enabled_other();
|
||||||
|
sender.sendMessage(PluginMessages.parsePlayerName(player, message));
|
||||||
|
TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player, true);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
sender.sendMessage(PluginMessages.parseMessage("&cPlayer offline."));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
sender.sendMessage("Try /pvp enable <player>");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Try /pvp enable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +127,27 @@ public class PvpToggleCommand {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Try /pvp disable <player>");
|
sender.sendMessage("Try /pvp disable <player>");
|
||||||
}
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (!sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
String message = TogglePvP.getPlugin().getConfigCache().getNo_permission();
|
||||||
|
BaseComponent[] component = TextComponent.fromLegacyText(message);
|
||||||
|
sender.spigot().sendMessage(component);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Player player = Bukkit.getPlayer(args[1]);
|
||||||
|
String message = TogglePvP.getPlugin().getConfigCache().getPvp_disabled_other();
|
||||||
|
sender.sendMessage(PluginMessages.parsePlayerName(player, message));
|
||||||
|
TogglePvP.getPlugin().getPlayerManager().setPlayerPvpState(player, true);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
sender.sendMessage(PluginMessages.parseMessage("&cPlayer offline."));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sender.hasPermission("togglepvp.command.toggle.others")) {
|
||||||
|
sender.sendMessage("Try /pvp disable <player>");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Try /pvp disable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,14 @@ import org.bukkit.configuration.Configuration;
|
|||||||
public class ConfigCache {
|
public class ConfigCache {
|
||||||
|
|
||||||
@Getter private final boolean pvp_enabled_by_default, lava_and_fire_stopper_enabled;
|
@Getter private final boolean pvp_enabled_by_default, lava_and_fire_stopper_enabled;
|
||||||
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker, no_permission, no_such_command;
|
@Getter private final String pvp_enabled;
|
||||||
|
@Getter private final String pvp_disabled;
|
||||||
|
@Getter private final String cannot_attack_victim;
|
||||||
|
@Getter private final String cannot_attack_attacker;
|
||||||
|
@Getter private final String no_permission;
|
||||||
|
@Getter private final String no_such_command;
|
||||||
|
@Getter private final String pvp_enabled_other;
|
||||||
|
@Getter private final String pvp_disabled_other;
|
||||||
@Getter private final double lava_and_fire_stopper_radius;
|
@Getter private final double lava_and_fire_stopper_radius;
|
||||||
|
|
||||||
public ConfigCache() {
|
public ConfigCache() {
|
||||||
@@ -27,5 +34,7 @@ public class ConfigCache {
|
|||||||
this.cannot_attack_attacker = config.getString("messages.cannot_attack_attacker", "&cYou can't attack players while you have PvP turned off!");
|
this.cannot_attack_attacker = config.getString("messages.cannot_attack_attacker", "&cYou can't attack players while you have PvP turned off!");
|
||||||
this.no_permission = config.getString("messages.no_permission", "&cYou don't have permission to use that.");
|
this.no_permission = config.getString("messages.no_permission", "&cYou don't have permission to use that.");
|
||||||
this.no_such_command = config.getString("messages.no_such_command", "&cNo such command.");
|
this.no_such_command = config.getString("messages.no_such_command", "&cNo such command.");
|
||||||
|
this.pvp_enabled_other = config.getString("messages.pvp_enabled_others", "&cYou've enabled %player%'s PvP.");
|
||||||
|
this.pvp_disabled_other =config.getString("messages.pvp_disabled_others", "&cYou've disabled %player%'s PvP.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,9 @@ public class PluginMessages {
|
|||||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String parsePlayerName(Player player, String message) {
|
||||||
|
message = message.replaceAll("%player%", player.getDisplayName());
|
||||||
|
return parseMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,3 +14,5 @@ messages:
|
|||||||
cannot_attack_attacker: "&cYou can't attack players while you have PvP turned off!"
|
cannot_attack_attacker: "&cYou can't attack players while you have PvP turned off!"
|
||||||
no_permission: "&cYou don't have permission to use that."
|
no_permission: "&cYou don't have permission to use that."
|
||||||
no_such_command: "&cNo such command."
|
no_such_command: "&cNo such command."
|
||||||
|
pvp_enabled_others: "&cYou've enabled %player%'s PvP."
|
||||||
|
pvp_disabled_others: "&cYou've disabled %player%'s PvP."
|
||||||
|
|||||||
Reference in New Issue
Block a user