Search in sources :

Example 6 with DeleteRegionEvent

use of br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent in project RedProtect by FabioZumbi12.

the class CommandHandlers method handleDeleteName.

public static void handleDeleteName(Player p, String rname, String world) {
    Region r = RedProtect.get().getRegionManager().getRegion(rname, p.getWorld().getName());
    if (!world.equals("")) {
        if (Sponge.getServer().getWorld(world).isPresent()) {
            r = RedProtect.get().getRegionManager().getRegion(rname, world);
        } else {
            RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.invalidworld");
            return;
        }
    }
    if (RedProtect.get().getPermissionHandler().hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.doesntexist") + ": " + rname);
            return;
        }
        int claims = RedProtect.get().getConfigManager().configRoot().region_settings.can_delete_first_home_after_claims;
        if (!r.canDelete() && (claims == -1 || RedProtect.get().getRegionManager().getPlayerRegions(p.getName(), p.getWorld().getName()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }
        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        if (Sponge.getEventManager().post(event)) {
            return;
        }
        RedProtect.get().getRegionManager().remove(r, r.getWorld());
        RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + world + ") Player " + p.getName() + " REMOVED region " + rname);
    } else {
        RedProtect.get().getLanguageManager().sendMessage(p, "no.permission");
    }
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region)

Example 7 with DeleteRegionEvent

use of br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent in project RedProtect by FabioZumbi12.

the class CommandHandlers method handleDeleteName.

public static void handleDeleteName(Player p, String rname, String world) {
    Region r = RedProtect.get().getRegionManager().getRegion(rname, p.getWorld().getName());
    if (!world.equals("")) {
        if (Bukkit.getWorld(world) != null) {
            r = RedProtect.get().getRegionManager().getRegion(rname, world);
        } else {
            RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.invalidworld");
            return;
        }
    }
    if (RedProtect.get().getPermissionHandler().hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.doesntexist") + ": " + rname);
            return;
        }
        int claims = RedProtect.get().getConfigManager().configRoot().region_settings.can_delete_first_home_after_claims;
        if (!r.canDelete() && (claims == -1 || RedProtect.get().getRegionManager().getPlayerRegions(p.getUniqueId().toString(), p.getWorld().getName()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }
        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        RedProtect.get().getRegionManager().remove(r, r.getWorld());
        RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + world + ") Player " + p.getName() + " REMOVED region " + rname);
        // Handle money
        handleDeleteRegionEconomy(r, p);
    } else {
        RedProtect.get().getLanguageManager().sendMessage(p, "no.permission");
    }
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Example 8 with DeleteRegionEvent

use of br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent in project RedProtect by FabioZumbi12.

the class CommandHandlers method handleDelete.

public static void handleDelete(Player p) {
    Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation());
    if (RedProtect.get().getPermissionHandler().hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
        int claims = RedProtect.get().getConfigManager().configRoot().region_settings.can_delete_first_home_after_claims;
        if (!r.canDelete() && (claims == -1 || RedProtect.get().getRegionManager().getPlayerRegions(p.getUniqueId().toString(), p.getWorld().getName()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }
        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        String rname = r.getName();
        String w = r.getWorld();
        RedProtect.get().getRegionManager().remove(r, w);
        RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + w + ") Player " + p.getName() + " REMOVED region " + rname);
        // Handle money
        handleDeleteRegionEconomy(r, p);
    } else {
        RedProtect.get().getLanguageManager().sendMessage(p, "no.permission");
    }
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 DeleteRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent)4 DeleteRegionEvent (br.net.fabiozumbi12.RedProtect.Bukkit.API.events.DeleteRegionEvent)2 DeleteRegionEvent (br.net.fabiozumbi12.RedProtect.Bukkit.events.DeleteRegionEvent)2 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)2 UniqueAccount (org.spongepowered.api.service.economy.account.UniqueAccount)1