Search in sources :

Example 1 with RenameRegionEvent

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

the class RPCommands method handleRename.

private static void handleRename(Player p, String newName) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "rename", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        // region name conform
        newName = newName.replace("/", "|");
        if (RedProtect.get().rm.getRegion(newName, p.getWorld()) != null) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.already");
            return;
        }
        if (newName.length() < 2 || newName.length() > 16) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.invalid");
            return;
        }
        if (newName.contains(" ")) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.spaces");
            return;
        }
        if (newName.contains("@")) {
            p.sendMessage(RPLang.get("regionbuilder.regionname.invalid.charac").replace("{charac}", "@"));
            return;
        }
        RenameRegionEvent event = new RenameRegionEvent(r, newName, r.getName(), p);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        String oldname = event.getOldName();
        newName = event.getNewName();
        RedProtect.get().rm.renameRegion(newName, r);
        RPLang.sendMessage(p, RPLang.get("cmdmanager.region.rename.newname") + " " + newName);
        RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " RENAMED region " + oldname + " to " + newName);
    } else {
        RPLang.sendMessage(p, "no.permission");
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.events.RenameRegionEvent)

Example 2 with RenameRegionEvent

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

the class RPCommands method handleRename.

private static void handleRename(Player p, String newName) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "rename", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        // region name conform
        newName = newName.replace("/", "|");
        if (RedProtect.get().rm.getRegion(newName, p.getWorld()) != null) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.already");
            return;
        }
        if (newName.length() < 2 || newName.length() > 16) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.invalid");
            return;
        }
        if (newName.contains(" ")) {
            RPLang.sendMessage(p, "cmdmanager.region.rename.spaces");
            return;
        }
        if (newName.contains("@")) {
            p.sendMessage(RPUtil.toText(RPLang.get("regionbuilder.regionname.invalid.charac").replace("{charac}", "@")));
            return;
        }
        RenameRegionEvent event = new RenameRegionEvent(r, newName, r.getName(), p);
        if (Sponge.getEventManager().post(event)) {
            return;
        }
        String oldname = event.getOldName();
        newName = event.getNewName();
        RedProtect.get().rm.renameRegion(newName, r);
        RPLang.sendMessage(p, RPLang.get("cmdmanager.region.rename.newname") + " " + newName);
        RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " RENAMED region " + oldname + " to " + newName);
    } else {
        RPLang.sendMessage(p, "no.permission");
    }
}
Also used : RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.RenameRegionEvent)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 RenameRegionEvent (br.net.fabiozumbi12.RedProtect.Bukkit.events.RenameRegionEvent)1 RenameRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.RenameRegionEvent)1