use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.
the class CommandHandler method onCommand.
@Listener(order = Order.EARLY)
public void onCommand(SendCommandEvent e, @First CommandSource source) {
String[] args = e.getArguments().split(" ");
StringBuilder commandArgsAbr = new StringBuilder();
Arrays.stream(args).forEach(arg -> commandArgsAbr.append(arg).append(" "));
String commandArgs = commandArgsAbr.substring(0, commandArgsAbr.length() - 1);
if (args.length >= 1 && (e.getCommand().equals("redprotect") || e.getCommand().equals("rp"))) {
List<String> conditions = RedProtect.get().getConfigManager().configRoot().command_confirm;
conditions.addAll(Arrays.asList(getCmd("yes"), getCmd("no")));
if (conditions.stream().anyMatch(cmd -> checkCmd(args[0], cmd))) {
String cmd = conditions.stream().filter(c -> checkCmd(args[0], c)).findFirst().get();
if (!cmdConfirm.containsKey(source.getName()) && !checkCmd(cmd, "yes") && !checkCmd(cmd, "no")) {
// Segure delete command
if (source instanceof Player && cmd.equalsIgnoreCase("delete") && commandArgs.split(" ").length == 2) {
if (RedProtect.get().getRegionManager().getTopRegion(((Player) source).getLocation(), CommandHandler.class.getName()) == null)
return;
Region r = RedProtect.get().getRegionManager().getTopRegion(((Player) source).getLocation(), CommandHandler.class.getName());
commandArgs = commandArgs + " " + r.getName() + " " + r.getWorld();
}
cmdConfirm.put(source.getName(), commandArgs);
RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + e.getCommand() + " " + cmd), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
e.setCancelled(true);
}
}
if (cmdConfirm.containsKey(source.getName())) {
if (checkCmd(args[0], "yes")) {
String cmd1 = cmdConfirm.get(source.getName());
e.setArguments(cmd1);
cmdConfirm.remove(source.getName());
} else if (checkCmd(args[0], "no")) {
cmdConfirm.remove(source.getName());
RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.usagecancelled");
e.setCancelled(true);
} else {
RedProtect.get().getLanguageManager().sendMessage(source, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + e.getCommand() + " " + cmdConfirm.get(source.getName())), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
e.setCancelled(true);
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.
the class CommandHandlers method handleKillWorld.
public static void handleKillWorld(CommandSource sender, World world, EntityType type) {
int killed = 0;
int total = 0;
int living = 0;
for (Entity e : world.getEntities().stream().filter(entity -> !(entity instanceof Player) && ((entity instanceof Living && type == null) || entity.getType().equals(type))).collect(Collectors.toList())) {
total++;
if (RedProtect.get().getRegionManager().getTopRegion(e.getLocation(), CommandHandlers.class.getName()) == null) {
e.remove();
killed++;
} else if (e instanceof Living && type == null) {
living++;
} else if (e.getType().equals(type)) {
living++;
}
}
RedProtect.get().getLanguageManager().sendMessage(sender, "cmdmanager.kill", new Replacer[] { new Replacer("{total}", String.valueOf(total)), new Replacer("{living}", String.valueOf(living)), new Replacer("{killed}", String.valueOf(killed)), new Replacer("{world}", world.getName()) });
}
use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.
the class CommandHandler method onPreCommand.
@EventHandler
public void onPreCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
String[] args = e.getMessage().split(" ");
StringBuilder commandArgsAbr = new StringBuilder();
Arrays.stream(args).forEach(arg -> commandArgsAbr.append(arg).append(" "));
String commandArgs = commandArgsAbr.substring(1, commandArgsAbr.length() - 1);
if (args.length >= 2 && (args[0].equals("/redprotect") || args[0].equals("/rp"))) {
// Check perms
if (hasCommand(args[1]) && !RedProtect.get().getPermissionHandler().hasCommandPerm(e.getPlayer(), getCmdFromAlias(args[1]))) {
RedProtect.get().getLanguageManager().sendMessage(e.getPlayer(), "no.permission");
e.setCancelled(true);
return;
}
List<String> conditions = RedProtect.get().getConfigManager().configRoot().command_confirm;
conditions.addAll(Arrays.asList(getCmd("yes"), getCmd("no")));
if (conditions.stream().anyMatch(cmd -> checkCmd(args[1], cmd))) {
String cmd = conditions.stream().filter(c -> checkCmd(args[1], c)).findFirst().get();
if (!cmdConfirm.containsKey(p.getName()) && !checkCmd(cmd, "yes") && !checkCmd(cmd, "no")) {
// Secure delete command
if (cmd.equalsIgnoreCase("delete") && commandArgs.split(" ").length == 2) {
if (RedProtect.get().getRegionManager().getTopRegion(p.getLocation()) == null)
return;
Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation());
commandArgs = commandArgs + " " + r.getName() + " " + r.getWorld();
}
cmdConfirm.put(p.getName(), commandArgs);
RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + args[0] + " " + cmd), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
e.setCancelled(true);
}
}
if (cmdConfirm.containsKey(p.getName())) {
if (checkCmd(args[1], "yes")) {
String cmd1 = cmdConfirm.get(p.getName());
e.setMessage("/" + cmd1);
cmdConfirm.remove(p.getName());
} else if (checkCmd(args[1], "no")) {
cmdConfirm.remove(p.getName());
RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.usagecancelled");
e.setCancelled(true);
} else {
RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.confirm", new Replacer[] { new Replacer("{cmd}", "/" + cmdConfirm.get(p.getName())), new Replacer("{cmd-yes}", getCmd("yes")), new Replacer("{cmd-no}", getCmd("no")) });
e.setCancelled(true);
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.
the class FlagGui method open.
public void open() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.getOpenInventory().getTopInventory().equals(this.inv)) {
Region r = RedProtect.get().getRegionManager().getTopRegion(player.getLocation());
if (r != null && r.equals(this.region) && !player.equals(this.player)) {
RedProtect.get().getLanguageManager().sendMessage(this.player, "cmdmanager.region.rpgui-other", new Replacer[] { new Replacer("{player}", player.getName()) });
return;
}
}
}
// Register Listener
RedProtect.get().getServer().getPluginManager().registerEvents(this, RedProtect.get());
this.inv = Bukkit.createInventory(player, this.size, this.name);
inv.setContents(this.guiItems);
player.openInventory(inv);
}
use of br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer in project RedProtect by FabioZumbi12.
the class CommandHandlers method handleKillWorld.
public static void handleKillWorld(CommandSender sender, World world, EntityType type) {
int killed = 0;
int total = 0;
int living = 0;
for (Entity e : world.getEntities().stream().filter(entity -> !(entity instanceof Player) && ((entity instanceof LivingEntity && type == null) || entity.getType().equals(type))).collect(Collectors.toList())) {
total++;
if (RedProtect.get().getRegionManager().getTopRegion(e.getLocation()) == null) {
e.remove();
killed++;
} else if (e instanceof LivingEntity && type == null) {
living++;
} else if (e.getType().equals(type)) {
living++;
}
}
RedProtect.get().getLanguageManager().sendMessage(sender, "cmdmanager.kill", new Replacer[] { new Replacer("{total}", String.valueOf(total)), new Replacer("{living}", String.valueOf(living)), new Replacer("{killed}", String.valueOf(killed)), new Replacer("{world}", world.getName()) });
}
Aggregations