use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class PlayerListener method onPlayerCommand.
@EventHandler(ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.tpcancelled");
}
String msg = e.getMessage();
String cmds = msg.split(" ")[0].toLowerCase().replace("/", "");
if (RedProtect.get().getConfigManager().configRoot().server_protection.deny_commands_on_worlds.getOrDefault(p.getWorld().getName(), new ArrayList<>()).contains(cmds) && !p.hasPermission("redprotect.bypass")) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.command-notallowed");
e.setCancelled(true);
return;
}
if (RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.containsKey(cmds.toLowerCase().replace("/", "")) && !cmds.equals(".")) {
double min = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).min_range;
double max = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).max_range;
String mesg = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).message;
double py = p.getLocation().getY();
if (py < min || py > max) {
if (mesg != null && !mesg.equals("")) {
RedProtect.get().getLanguageManager().sendMessage(p, mesg);
}
e.setCancelled(true);
return;
}
}
if (cmds.startsWith("back") || cmds.startsWith("home") || cmds.contains(":back") || cmds.contains(":home")) {
PlayerCmd.put(p.getName(), msg);
}
Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation());
if (r != null) {
if ((cmds.equalsIgnoreCase("petc") || cmds.equalsIgnoreCase("petcall") || cmds.contains(":petc") || cmds.contains(":petcall")) && RedProtect.get().hooks.checkMyPet() && !r.canPet(p)) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantpet");
e.setCancelled(true);
return;
}
if (!r.isCmdAllowed(msg)) {
if (cmds.equalsIgnoreCase("rp") || cmds.equalsIgnoreCase("redprotect")) {
return;
}
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantcommand");
e.setCancelled(true);
return;
}
if (!r.isCmdDenied(msg)) {
for (String alias : RedProtect.get().getCommand("RedProtect").getAliases()) {
if (cmds.equalsIgnoreCase(alias)) {
return;
}
}
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantcommand");
e.setCancelled(true);
return;
}
if ((cmds.equalsIgnoreCase("sethome") || cmds.contains(":sethome")) && !r.isHomeAllowed(p)) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.canthome");
e.setCancelled(true);
return;
}
// Pvp check
if ((cmds.equalsIgnoreCase("pvp") || cmds.contains(":pvp")) && RedProtect.get().hooks.checkPvPm()) {
if (r.isPvPArena() && !PvPlayer.get(p).hasPvPEnabled() && !r.canBuild(p)) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.pvpenabled");
RedProtect.get().getServer().dispatchCommand(RedProtect.get().getServer().getConsoleSender(), RedProtect.get().getConfigManager().configRoot().flags_configuration.pvparena_nopvp_kick_cmd.replace("{player}", p.getName()));
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class RedProtect method onServerStart.
@Listener
public void onServerStart(GameStartedServerEvent event) {
try {
String v = Sponge.getGame().getPlatform().getContainer(Component.API).getVersion().orElse("0");
instance = this;
commandManager = Sponge.getGame().getCommandManager();
ph = new PermissionHandler();
rm = new RegionManager();
// Init schematic
schematic = new RPSchematics();
// Init config, lang, listeners and flags
startLoad();
if (v.startsWith("7")) {
rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.VersionHelper7").newInstance();
Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener7").newInstance());
} else /*else if (v.startsWith("8")) {
Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener8").newInstance());
rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.VersionHelper8").newInstance();
}*/
{
Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.BlockListenerCompat56").newInstance());
rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.helpers.VersionHelper56").newInstance();
}
logger.info("Loading API...");
this.redProtectAPI = new RedProtectAPI();
logger.info("API Loaded!");
logger.info("Sponge version: " + v);
logger.clear("\n" + "&4 _ _ _ &c _ _ _ _ _ _ _ _ _ __\n" + "&4|_| |_ | \\ &c|_| |_| | | | |_ | | / \n" + "&4| \\ |_ |_/ &c| | \\ |_| | |_ |_ | /\n" + "&a¯ Redprotect " + container.getVersion().get() + " enabled\n" + "");
} catch (Exception e) {
CoreUtil.printJarVersion();
e.printStackTrace();
Sponge.getGame().getServer().setHasWhitelist(true);
Sponge.getGame().getServer().getOnlinePlayers().forEach(Player::kick);
logger.severe("Error enabling RedProtect, plugin will shut down.");
logger.severe("Due to an error in RedProtect loading, the whitelist has been turned on and every player has been kicked.");
logger.severe("DO NOT LET ANYONE ENTER before fixing the problem, otherwise you risk losing protected regions.");
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect 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.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class CommandHandler method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0 && hasCommand(args[0])) {
CommandExecutor executor = this.getCommandSubCommand(args[0]);
return executor.onCommand(sender, command, label, Arrays_copyOfRange(args, args.length));
} else {
if (args.length == 0 || !RedProtect.get().getPermissionHandler().hasCommandPerm(sender, "admin")) {
HandleHelpPage(sender, 1);
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("debug-item")) {
if (sender instanceof Player) {
ItemStack hand = ((Player) sender).getItemInHand();
plugin.getLanguageManager().sendMessage(sender, "&aMaterial name: " + hand.getType().name());
} else {
plugin.getLanguageManager().sendMessage(sender, "&cThis command can be used only by online players holding an item!");
}
return true;
}
if (args[0].equalsIgnoreCase("update")) {
if (plugin.getUpdater() == null) {
plugin.getLanguageManager().sendMessage(sender, "&aPlugin updates is disabled on config.");
return true;
}
if (plugin.getUpdater().getUpdateAvailable() == SpigetUpdater.UpdateStatus.AVAILABLE)
plugin.getUpdater().downloadAndUpdateJar(sender);
else if (plugin.getUpdater().getUpdateAvailable() == SpigetUpdater.UpdateStatus.RESTART_NEEDED)
plugin.getLanguageManager().sendMessage(sender, "&aPlugin updated. Restart server to complete the update.");
else
plugin.getUpdater().checkForUpdate(sender, false);
return true;
}
if (args[0].equalsIgnoreCase("reset-uuids")) {
final boolean[] save = { false };
// Reset uuids
RedProtect.get().getRegionManager().getAllRegions().forEach(r -> {
r.getLeaders().forEach(rp -> {
if (RedProtect.get().getUtil().isUUIDs(rp.getUUID())) {
rp.setUUID(rp.getPlayerName());
save[0] = true;
}
});
r.getAdmins().forEach(rp -> {
if (RedProtect.get().getUtil().isUUIDs(rp.getUUID())) {
rp.setUUID(rp.getPlayerName());
save[0] = true;
}
});
r.getMembers().forEach(rp -> {
if (RedProtect.get().getUtil().isUUIDs(rp.getUUID())) {
rp.setUUID(rp.getPlayerName());
save[0] = true;
}
});
// Set uudis for online players
Bukkit.getOnlinePlayers().forEach(p -> {
if (RedProtect.get().getConfigManager().configRoot().online_mode) {
// Update player names based on uuids
r.getLeaders().forEach(rp -> {
if (rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString()) && !rp.getPlayerName().equalsIgnoreCase(p.getName())) {
rp.setPlayerName(p.getName().toLowerCase());
r.setToSave(true);
}
});
r.getAdmins().forEach(rp -> {
if (rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString()) && !rp.getPlayerName().equalsIgnoreCase(p.getName())) {
rp.setPlayerName(p.getName().toLowerCase());
r.setToSave(true);
}
});
r.getMembers().forEach(rp -> {
if (rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString()) && !rp.getPlayerName().equalsIgnoreCase(p.getName())) {
rp.setPlayerName(p.getName().toLowerCase());
r.setToSave(true);
}
});
} else {
// Update uuids based on player names
r.getLeaders().forEach(rp -> {
if (rp.getPlayerName().equalsIgnoreCase(p.getName()) && !rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString())) {
rp.setUUID(p.getUniqueId().toString());
r.setToSave(true);
}
});
r.getAdmins().forEach(rp -> {
if (rp.getPlayerName().equalsIgnoreCase(p.getName()) && !rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString())) {
rp.setUUID(p.getUniqueId().toString());
r.setToSave(true);
}
});
r.getMembers().forEach(rp -> {
if (rp.getPlayerName().equalsIgnoreCase(p.getName()) && !rp.getUUID().equalsIgnoreCase(p.getUniqueId().toString())) {
rp.setUUID(p.getUniqueId().toString());
r.setToSave(true);
}
});
}
});
});
if (save[0]) {
RedProtect.get().getRegionManager().saveAll(true);
RedProtect.get().logger.success("Fixed some online players uuids!");
} else {
RedProtect.get().logger.success("No uuids fixed!");
}
return true;
}
if (args[0].equalsIgnoreCase("clear-kicks")) {
RedProtect.get().denyEnter.clear();
RedProtect.get().logger.success("All region kicks was clear");
return true;
}
if (args[0].equalsIgnoreCase("single-to-files")) {
RedProtect.get().logger.success("[" + RedProtect.get().getUtil().SingleToFiles() + "]" + " regions converted to your own files with success");
return true;
}
if (args[0].equalsIgnoreCase("files-to-single")) {
RedProtect.get().logger.success("[" + RedProtect.get().getUtil().FilesToSingle() + "]" + " regions converted to unified database file with success");
return true;
}
if (args[0].equalsIgnoreCase("fileToMysql")) {
try {
if (!RedProtect.get().getUtil().fileToMysql()) {
RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'file' before convert from FILE to Mysql.");
return true;
} else {
RedProtect.get().getConfig().set("file-type", "mysql");
RedProtect.get().saveConfig();
RedProtect.get().getServer().getPluginManager().disablePlugin(RedProtect.get());
RedProtect.get().getServer().getPluginManager().enablePlugin(RedProtect.get());
RedProtect.get().logger.success("RedProtect reloaded with Mysql as database! Ready to use!");
return true;
}
} catch (Exception e) {
CoreUtil.printJarVersion();
e.printStackTrace();
return true;
}
}
if (args[0].equalsIgnoreCase("mysqlToFile")) {
try {
if (!RedProtect.get().getUtil().mysqlToFile()) {
RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'mysql' before convert from MYSQL to FILE.");
return true;
} else {
RedProtect.get().getConfig().set("file-type", "file");
RedProtect.get().saveConfig();
RedProtect.get().getServer().getPluginManager().disablePlugin(RedProtect.get());
RedProtect.get().getServer().getPluginManager().enablePlugin(RedProtect.get());
RedProtect.get().logger.success("RedProtect reloaded with File as database! Ready to use!");
return true;
}
} catch (Exception e) {
CoreUtil.printJarVersion();
e.printStackTrace();
return true;
}
}
if (args[0].equalsIgnoreCase("gpTorp")) {
if (!RedProtect.get().hooks.checkGriefPrev()) {
RedProtect.get().logger.success("The plugin GriefPrevention is not installed or is disabled");
return true;
}
if (RedProtect.get().getUtil().convertFromGP() == 0) {
RedProtect.get().logger.severe("No region converted from GriefPrevention.");
return true;
} else {
RedProtect.get().getRegionManager().saveAll(true);
RedProtect.get().logger.info(ChatColor.AQUA + "[" + RedProtect.get().getUtil().convertFromGP() + "] regions converted from GriefPrevention with success");
RedProtect.get().getServer().getPluginManager().disablePlugin(RedProtect.get());
RedProtect.get().getServer().getPluginManager().enablePlugin(RedProtect.get());
return true;
}
}
if (args[0].equalsIgnoreCase("list-all")) {
int total = 0;
for (Region r : RedProtect.get().getRegionManager().getAllRegions()) {
RedProtect.get().logger.info(ChatColor.GREEN + "[" + total + "]" + "Region: " + r.getName() + ChatColor.RESET + " | " + ChatColor.AQUA + "World: " + r.getWorld() + ChatColor.RESET);
total++;
}
RedProtect.get().logger.success(total + " regions for " + Bukkit.getWorlds().size() + " worlds.");
return true;
}
if (args[0].equalsIgnoreCase("mychunktorp")) {
RedProtect.get().logger.success("...converting MyChunk database");
if (handleMyChunk()) {
RedProtect.get().getRegionManager().saveAll(true);
RedProtect.get().getServer().getPluginManager().disablePlugin(RedProtect.get());
RedProtect.get().getServer().getPluginManager().enablePlugin(RedProtect.get());
return true;
} else {
RedProtect.get().logger.success("The plugin MyChunk is not installed or no regions found");
return true;
}
}
if (args[0].equalsIgnoreCase("wgtorp")) {
RedProtect.get().logger.success("...converting WorldGuard database");
if (handleWGRegions()) {
RedProtect.get().getRegionManager().saveAll(true);
RedProtect.get().getServer().getPluginManager().disablePlugin(RedProtect.get());
RedProtect.get().getServer().getPluginManager().enablePlugin(RedProtect.get());
return true;
} else {
RedProtect.get().logger.success("The plugin WorldGuard is not installed or no regions found");
return true;
}
}
if (args[0].equalsIgnoreCase("load-all")) {
RedProtect.get().getRegionManager().clearDB();
try {
RedProtect.get().getRegionManager().loadAll();
RedProtect.get().getUtil().ReadAllDB(RedProtect.get().getRegionManager().getAllRegions());
} catch (Exception e) {
RedProtect.get().logger.severe("Error on load all regions from database files:");
CoreUtil.printJarVersion();
e.printStackTrace();
}
RedProtect.get().logger.success(RedProtect.get().getRegionManager().getAllRegions().size() + " regions has been loaded from database files!");
return true;
}
if (checkCmd(args[0], "reload")) {
RedProtect.get().reload();
RedProtect.get().getLanguageManager().sendMessage(sender, "RedProtect Plus reloaded!");
return true;
}
if (args[0].equalsIgnoreCase("reload-config")) {
RedProtect.get().reloadConfigs();
RedProtect.get().getLanguageManager().sendMessage(sender, "RedProtect configs reloaded!");
return true;
}
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("test-uuid")) {
try {
String name = MojangUUIDs.getUUID(args[1]);
RedProtect.get().logger.warning("Leader from: " + args[1]);
RedProtect.get().logger.warning("UUID To name: " + name);
} catch (Exception e) {
CoreUtil.printJarVersion();
e.printStackTrace();
}
return true;
}
// rp regen stop
if (checkCmd(args[0], "regenall") && args[1].equalsIgnoreCase("stop")) {
if (!RedProtect.get().hooks.checkWe()) {
return true;
}
RedProtect.get().getUtil().stopRegen = true;
RedProtect.get().getLanguageManager().sendMessage(sender, "&aRegen will stop now. To continue reload the plugin!");
return true;
}
if (args[0].equalsIgnoreCase("setconfig") && args[1].equalsIgnoreCase("list")) {
RedProtect.get().getLanguageManager().sendMessage(sender, ChatColor.AQUA + "=========== Config Sections: ===========");
for (String section : RedProtect.get().getConfig().getValues(false).keySet()) {
if (section.contains("debug-messages") || section.contains("file-type") || section.contains("language")) {
sender.sendMessage(ChatColor.GOLD + section + " : " + ChatColor.GREEN + RedProtect.get().getConfig().get(section).toString());
}
}
sender.sendMessage(ChatColor.AQUA + "====================================");
return true;
}
// rp limit player
if (checkCmd(args[0], "blocklimit")) {
Player offp = RedProtect.get().getServer().getOfflinePlayer(args[1]).getPlayer();
if (offp == null) {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
return true;
}
int limit = RedProtect.get().getPermissionHandler().getPlayerBlockLimit(offp);
if (limit < 0 || RedProtect.get().getPermissionHandler().hasPerm(offp, "redprotect.limits.blocks.unlimited")) {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.nolimit"));
return true;
}
int currentUsed = RedProtect.get().getRegionManager().getTotalRegionSize(offp.getUniqueId().toString(), offp.getWorld().getName());
ChatColor color = currentUsed >= limit ? ChatColor.RED : ChatColor.GOLD;
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.yourarea") + color + currentUsed + RedProtect.get().getLanguageManager().get("general.color") + "/" + color + limit + RedProtect.get().getLanguageManager().get("general.color"));
return true;
}
}
if (args.length == 3) {
// rp undo <region> <database>
if (args[0].equalsIgnoreCase("undo")) {
if (!RedProtect.get().hooks.checkWe()) {
return true;
}
World w = RedProtect.get().getServer().getWorld(args[2]);
if (w == null) {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.region.invalidworld"));
return true;
}
Region r = RedProtect.get().getRegionManager().getRegion(args[1], w.getName());
if (r == null) {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("correct.usage") + " " + ChatColor.YELLOW + "Invalid region: " + args[1]);
return true;
}
if (WEHook.undo(r.getID())) {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.regen.undo.sucess").replace("{region}", r.getName()));
} else {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.regen.undo.none").replace("{region}", r.getName()));
}
return true;
}
if (args[0].equalsIgnoreCase("setconfig")) {
if (args[1].equals("debug-messages") || args[1].equals("file-type") || args[1].equals("language")) {
Object from = RedProtect.get().getConfig().get(args[1]);
if (args[2].equals("true") || args[2].equals("false")) {
RedProtect.get().getConfig().set(args[1], Boolean.parseBoolean(args[2]));
} else {
try {
int value = Integer.parseInt(args[2]);
RedProtect.get().getConfig().set(args[1], value);
} catch (NumberFormatException ex) {
RedProtect.get().getConfig().set(args[1], args[2]);
}
}
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.configset") + " " + from.toString() + " > " + args[2]);
RedProtect.get().getConfigManager().save();
return true;
} else {
RedProtect.get().getLanguageManager().sendMessage(sender, RedProtect.get().getLanguageManager().get("cmdmanager.confignotset") + " " + args[1]);
}
return true;
}
}
if (args[0].equalsIgnoreCase("list-areas")) {
int Page = 1;
if (args.length == 2) {
try {
Page = Integer.parseInt(args[1]);
} catch (Exception ignored) {
}
}
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "-------------------------------------------------");
int regionsPage = RedProtect.get().getConfigManager().configRoot().region_settings.region_list.region_per_page;
int total = 0;
int last = 0;
for (World w : Bukkit.getWorlds()) {
boolean first = true;
if (Page == 0) {
Page = 1;
}
int max = (regionsPage * Page);
int min = max - regionsPage;
int count;
Set<Region> wregions = new HashSet<>();
for (Region r : RedProtect.get().getRegionManager().getRegionsByWorld(w.getName())) {
SimpleDateFormat dateformat = new SimpleDateFormat(RedProtect.get().getConfigManager().configRoot().region_settings.date_format);
Date now = null;
try {
now = dateformat.parse(RedProtect.get().getUtil().dateNow());
} catch (ParseException e1) {
RedProtect.get().logger.severe("The 'date-format' don't match with date 'now'!!");
}
Date regiondate = null;
try {
regiondate = dateformat.parse(r.getDate());
} catch (ParseException e) {
RedProtect.get().logger.severe("The 'date-format' don't match with region date!!");
CoreUtil.printJarVersion();
e.printStackTrace();
}
long days = TimeUnit.DAYS.convert(now.getTime() - regiondate.getTime(), TimeUnit.MILLISECONDS);
for (String play : RedProtect.get().getConfigManager().configRoot().purge.ignore_regions_from_players) {
if (r.isLeader(play) || r.isAdmin(play)) {
break;
}
}
if (!r.isLeader(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader) && days > RedProtect.get().getConfigManager().configRoot().purge.remove_oldest && r.getArea() >= RedProtect.get().getConfigManager().configRoot().purge.regen.max_area_regen) {
wregions.add(r);
}
}
if (wregions.size() == 0) {
continue;
}
String colorChar = ChatColor.translateAlternateColorCodes('&', RedProtect.get().getConfigManager().configRoot().region_settings.world_colors.get(w.getName()));
int totalLocal = wregions.size();
total += totalLocal;
int lastLocal = 0;
if (wregions.size() > 0) {
List<Region> it = new ArrayList<>(wregions);
if (min > totalLocal) {
int diff = (totalLocal / regionsPage);
min = regionsPage * diff;
max = (regionsPage * diff) + regionsPage;
}
if (max > it.size())
max = (it.size() - 1);
// -------------
if (RedProtect.get().getConfigManager().configRoot().region_settings.region_list.hover_and_click_teleport && RedProtect.get().getPermissionHandler().hasRegionPermAdmin(sender, "teleport", null)) {
UltimateFancy fancy = new UltimateFancy(RedProtect.get());
for (int i = min; i <= max; i++) {
count = i;
Region r = it.get(i);
String rname = RedProtect.get().getLanguageManager().get("general.color") + ", " + ChatColor.GRAY + r.getName() + "(" + r.getArea() + ")";
if (first) {
rname = rname.substring(3);
first = false;
}
if (count == max) {
rname = rname + RedProtect.get().getLanguageManager().get("general.color") + ".";
}
fancy.text(rname).hoverShowText(RedProtect.get().getLanguageManager().get("cmdmanager.list.hover").replace("{region}", r.getName())).clickRunCmd("/rp " + getCmd("teleport") + " " + r.getName() + " " + r.getWorld()).next();
lastLocal = count;
}
last += lastLocal + 1;
sender.sendMessage("-----");
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + RedProtect.get().getLanguageManager().get("region.world").replace(":", "") + " " + colorChar + w.getName() + "[" + (min + 1) + "-" + (max + 1) + "/" + wregions.size() + "]" + ChatColor.RESET + ": ");
fancy.send(sender);
} else {
StringBuilder worldregions = new StringBuilder();
for (int i = min; i <= max; i++) {
count = i;
Region r = it.get(i);
worldregions.append(RedProtect.get().getLanguageManager().get("general.color")).append(", ").append(ChatColor.GRAY).append(r.getName()).append(r.getArea());
lastLocal = count;
}
last += lastLocal + 1;
sender.sendMessage("-----");
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + RedProtect.get().getLanguageManager().get("region.world").replace(":", "") + " " + colorChar + w.getName() + "[" + (min + 1) + "-" + (max + 1) + "/" + wregions.size() + "]" + ChatColor.RESET + ": ");
sender.sendMessage(worldregions.substring(3) + RedProtect.get().getLanguageManager().get("general.color") + ".");
}
// -----------
}
}
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "---------------- " + last + "/" + total + " -----------------");
if (last < total) {
sender.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.region.listpage.more").replace("{player}", "" + (Page + 1)));
} else {
if (Page != 1) {
sender.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.region.listpage.nomore"));
}
}
return true;
}
if (args[0].equalsIgnoreCase("save-all")) {
RedProtect.get().logger.saveLogs();
RedProtect.get().logger.success(RedProtect.get().getRegionManager().saveAll(args.length == 2 && args[1].equalsIgnoreCase("-f")) + " regions saved with success!");
return true;
}
HandleHelpPage(sender, 1);
return true;
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class CommandHandlers method HandleHelpPage.
public static void HandleHelpPage(CommandSender sender, int page) {
sender.sendMessage(RedProtect.get().getLanguageManager().get("_redprotect.prefix") + " " + RedProtect.get().getLanguageManager().get("cmdmanager.available.cmds"));
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "------------------------------------");
sender.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.helpheader.alias"));
if (sender instanceof Player) {
Player player = (Player) sender;
int i = 0;
for (String key : RedProtect.get().getLanguageManager().getHelpStrings()) {
if (RedProtect.get().getPermissionHandler().hasCommandPerm(player, key) || ((key.equals("pos1") || key.equals("pos2")) && RedProtect.get().getPermissionHandler().hasCommandPerm(player, "redefine"))) {
if (key.equalsIgnoreCase("flaggui")) {
continue;
}
i++;
if (i > (page * 10) - 10 && i <= page * 10) {
player.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.help." + key).replace("{cmd}", getCmd(key)).replace("{alias}", getCmdAlias(key)));
}
if (i > page * 10) {
player.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "------------------------------------");
player.sendMessage(RedProtect.get().getLanguageManager().get("cmdmanager.page").replace("{page}", "" + (page + 1)));
break;
}
}
}
} else {
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "kick " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Kick a player from a region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "clear-kicks " + ChatColor.DARK_AQUA + "- Clear all pendent kicks");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "info " + ChatColor.GOLD + "<region> <world> " + ChatColor.DARK_AQUA + "- Info about a region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "flag " + ChatColor.GOLD + "<regionName> <Flag> <Value> <World> " + ChatColor.DARK_AQUA + "- Set a flag on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "flag " + ChatColor.GOLD + "info <region> <world> " + ChatColor.DARK_AQUA + "- Flag info for region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "addmember " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Add player as member on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "addadmin " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Add player as admin on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "addleader " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Add player as leader on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "removemember " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Remove a player as member on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "removeadmin " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Remove a player as admin on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "removeleader " + ChatColor.GOLD + "<player> <region> <world> " + ChatColor.DARK_AQUA + "- Remove a player as leader on region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "teleport " + ChatColor.GOLD + "<playerName> <regionName> <World> " + ChatColor.DARK_AQUA + "- Teleport player to a region");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "blocklimit " + ChatColor.GOLD + "<playerName> " + ChatColor.DARK_AQUA + "- Area limit for player");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "claimlimit " + ChatColor.GOLD + "<playerName> [world] " + ChatColor.DARK_AQUA + "- Claim limit for player");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "list-areas " + ChatColor.DARK_AQUA + "- List All regions exceeding regen limit");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "list-all " + ChatColor.DARK_AQUA + "- List All regions");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "list " + ChatColor.GOLD + "<player> [page] " + ChatColor.DARK_AQUA + "- List All regions from player");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "fileTomysql " + ChatColor.DARK_AQUA + "- Convert from File to Mysql");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "kill [world] " + ChatColor.DARK_AQUA + "- Kill all entities in a world outside protected regions");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "mychunktorp " + ChatColor.DARK_AQUA + "- Convert from MyChunk to RedProtect");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "single-to-files " + ChatColor.DARK_AQUA + "- Convert single world files to regions files");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "files-to-single " + ChatColor.DARK_AQUA + "- Convert regions files to single world files");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "gpTorp " + ChatColor.DARK_AQUA + "- Convert from GriefPrevention to RedProtect");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "save-all " + ChatColor.GOLD + "[-f]" + ChatColor.DARK_AQUA + "- Save all regions to database");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "load-all " + ChatColor.DARK_AQUA + "- Load all regions from database");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "reload-config " + ChatColor.DARK_AQUA + "- Reload only the configs");
sender.sendMessage(ChatColor.GOLD + "rp " + ChatColor.RED + "reload " + ChatColor.DARK_AQUA + "- Reload the plugin");
}
sender.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "------------------------------------");
if (RedProtect.get().getPermissionHandler().hasPerm(sender, "")) {
String jarversion = new java.io.File(RedProtect.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&o- Full version: " + jarversion));
}
}
Aggregations