Search in sources :

Example 6 with RedProtect

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.");
    }
}
Also used : PermissionHandler(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.PermissionHandler) HandlerList(org.bukkit.event.HandlerList) java.util(java.util) Player(org.bukkit.entity.Player) Bukkit.listeners(br.net.fabiozumbi12.RedProtect.Bukkit.listeners) CoreUtil(br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil) VersionHelper(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper) Location(org.bukkit.Location) Metrics(br.net.fabiozumbi12.RedProtect.Bukkit.metrics.Metrics) RegionManager(br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager) LangManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.LangManager) LogLevel(br.net.fabiozumbi12.RedProtect.Core.helpers.LogLevel) RedProtectUtil(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectUtil) LangGuiManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.LangGuiManager) Bukkit(org.bukkit.Bukkit) Economy(net.milkbowl.vault.economy.Economy) SpigetUpdater(br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater) RPSchematics(br.net.fabiozumbi12.RedProtect.Bukkit.schematics.RPSchematics) CommandHandler(br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandler) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) HooksManager(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.HooksManager) RedProtectLogger(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectLogger) RedProtectAPI(br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI) ConfigManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.ConfigManager) BlockConfig(br.net.fabiozumbi12.RedProtect.Bukkit.config.BlockConfig) Permission(net.milkbowl.vault.permission.Permission) RedProtectAPI(br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI) PermissionHandler(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.PermissionHandler) RPSchematics(br.net.fabiozumbi12.RedProtect.Bukkit.schematics.RPSchematics) RegionManager(br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 7 with RedProtect

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);
        }
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Listener(org.spongepowered.api.event.Listener)

Example 8 with RedProtect

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);
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) Listener(org.spongepowered.api.event.Listener)

Example 9 with RedProtect

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();
}
Also used : RPConfig(br.net.fabiozumbi12.RedProtect.Sponge.config.RPConfig)

Example 10 with RedProtect

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());
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PvPlayer(me.NoChance.PvPManager.PvPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Player (org.bukkit.entity.Player)7 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)6 PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)4 RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)3 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)3 Location (org.bukkit.Location)3 EventHandler (org.bukkit.event.EventHandler)3 Listener (org.spongepowered.api.event.Listener)3 CommandHandler (br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandler)2 BlockConfig (br.net.fabiozumbi12.RedProtect.Bukkit.config.BlockConfig)2 ConfigManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.ConfigManager)2 LangGuiManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangGuiManager)2 LangManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangManager)2 RedProtectUtil (br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectUtil)2 Metrics (br.net.fabiozumbi12.RedProtect.Bukkit.metrics.Metrics)2 RegionManager (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager)2 SpigetUpdater (br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater)2