use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class RedProtect method onEnable.
public void onEnable() {
try {
plugin = this;
ph = new PermissionHandler();
rm = new RegionManager();
// Init schematic
schematic = new RPSchematics();
// Init config, lang, listeners and flags
startLoad();
logger.info("Loading API...");
this.redProtectAPI = new RedProtectAPI();
logger.info("API Loaded!");
logger.clear("&4 _ _ _ &c _ _ _ _ _ _ _ _ _ __");
logger.clear("&4|_| |_ | \\ &c|_| |_| | | | |_ | | /");
logger.clear("&4| \\ |_ |_/ &c| | \\ |_| | |_ |_ | /");
logger.clear("&a» " + getDescription().getFullName() + " enabled");
logger.clear("");
} catch (Exception e) {
CoreUtil.printJarVersion();
e.printStackTrace();
getServer().setWhitelist(true);
getServer().getOnlinePlayers().forEach(p -> p.kickPlayer("The server has been whitelisted due to an error while loading plugins!"));
this.setEnabled(false);
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 PlayerListener method onPlayerCommand.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerCommand(SendCommandEvent e, @First Player p) {
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.tpcancelled");
}
String cmd = e.getCommand();
if (RedProtect.get().getConfigManager().configRoot().server_protection.deny_commands_on_worlds.getOrDefault(p.getWorld().getName(), new ArrayList<>()).contains(cmd) && !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(cmd) && !cmd.equals(".")) {
double min = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).min_range;
double max = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).max_range;
String mesg = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).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 (cmd.startsWith("back") || cmd.startsWith("home")) {
PlayerCmd.put(p, cmd);
}
Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation(), this.getClass().getName());
if (r != null) {
if (!r.AllowCommands(p, cmd)) {
if (cmd.startsWith("rp") || cmd.startsWith("redprotect")) {
return;
}
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantcommand");
e.setCancelled(true);
return;
}
if (!r.DenyCommands(p, cmd)) {
if (cmd.startsWith("rp") || cmd.startsWith("redprotect")) {
return;
}
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantcommand");
e.setCancelled(true);
return;
}
if (cmd.startsWith("home") && !r.AllowHome(p)) {
RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.canthome");
e.setCancelled(true);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect 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.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class RedProtect method initVars.
private void initVars() throws Exception {
container = Sponge.getPluginManager().getPlugin("redprotect").get();
serv = Sponge.getServer();
cmdService = game.getCommandManager();
cfgs = new RPConfig();
RPLang.init();
WE = checkWE();
ph = new RPPermHandler();
rm = new RegionManager();
}
use of br.net.fabiozumbi12.RedProtect.Sponge.RedProtect in project RedProtect by FabioZumbi12.
the class RPPlayerListener method PlayerLogin.
@EventHandler
public void PlayerLogin(PlayerJoinEvent e) {
Player p = e.getPlayer();
// Adjust inside region
p.teleport(new Location(p.getWorld(), p.getLocation().getBlockX(), p.getLocation().getBlockY() + 0.1, p.getLocation().getBlockZ()));
if (p.hasPermission("redprotect.update") && RedProtect.get().Update && !RPConfig.getBool("update-check.auto-update")) {
RPLang.sendMessage(p, ChatColor.AQUA + "An update is available for RedProtect: " + RedProtect.get().UptVersion);
RPLang.sendMessage(p, ChatColor.AQUA + "Use /rp update to download and automatically install this update.");
}
if (RPConfig.getString("region-settings.record-player-visit-method").equalsIgnoreCase("ON-LOGIN")) {
String uuid = p.getUniqueId().toString();
if (!RedProtect.get().OnlineMode) {
uuid = p.getName().toLowerCase();
}
for (Region r : RedProtect.get().rm.getMemberRegions(uuid)) {
if (r.getDate() == null || !r.getDate().equals(RPUtil.DateNow())) {
r.setDate(RPUtil.DateNow());
}
}
}
String worldneeded = RPConfig.getString("server-protection.teleport-player.on-join.need-world-to-teleport");
if (RPConfig.getBool("server-protection.teleport-player.on-join.enable") && (worldneeded.equals("none") || worldneeded.equals(p.getWorld().getName()))) {
String[] loc = RPConfig.getString("server-protection.teleport-player.on-join.location").split(",");
e.getPlayer().teleport(new Location(Bukkit.getWorld(loc[0]), Double.parseDouble(loc[1]) + 0.500, Double.parseDouble(loc[2]), Double.parseDouble(loc[3]) + 0.500));
}
// Pvp check on join
if (RedProtect.get().PvPm) {
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (!p.hasPermission("redprotect.forcepvp.bypass") && r != null && r.flagExists("forcepvp")) {
PvPlayer pvpp = PvPlayer.get(p);
if (r.forcePVP() != pvpp.hasPvPEnabled()) {
PvPState.put(p.getName(), pvpp.hasPvPEnabled());
pvpp.setPvP(r.forcePVP());
}
}
}
}
Aggregations