Search in sources :

Example 1 with RenameRegionEvent

use of br.net.fabiozumbi12.RedProtect.Bukkit.API.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.API.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)

Example 3 with RenameRegionEvent

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

the class CommandHandlers method handleRename.

public static void handleRename(Player p, String newName) {
    Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation(), CommandHandlers.class.getName());
    if (RedProtect.get().getPermissionHandler().hasRegionPermLeader(p, "rename", r)) {
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
        // filter name
        newName = RedProtect.get().getUtil().fixRegionName(p, newName);
        if (newName == null)
            return;
        RenameRegionEvent event = new RenameRegionEvent(r, newName, r.getName(), p);
        if (Sponge.getEventManager().post(event)) {
            return;
        }
        String oldName = event.getOldName();
        newName = event.getNewName();
        Region newRegion = RedProtect.get().getRegionManager().renameRegion(newName, r);
        RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.rename.newname") + " " + newRegion.getName());
        RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " RENAMED region " + oldName + " to " + newRegion.getName());
    } else {
        RedProtect.get().getLanguageManager().sendMessage(p, "no.permission");
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.RenameRegionEvent)

Example 4 with RenameRegionEvent

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

the class CommandHandlers method handleRename.

public static void handleRename(Player p, String newName) {
    Region r = RedProtect.get().getRegionManager().getTopRegion(p.getLocation());
    if (RedProtect.get().getPermissionHandler().hasRegionPermLeader(p, "rename", r)) {
        if (r == null) {
            RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }
        // filter name
        newName = RedProtect.get().getUtil().fixRegionName(p, newName);
        if (newName == null)
            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();
        Region newRegion = RedProtect.get().getRegionManager().renameRegion(newName, r);
        RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.rename.newname") + " " + newRegion.getName());
        RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " RENAMED region " + oldname + " to " + newRegion.getName());
    } else {
        RedProtect.get().getLanguageManager().sendMessage(p, "no.permission");
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) RenameRegionEvent(br.net.fabiozumbi12.RedProtect.Bukkit.API.events.RenameRegionEvent)

Aggregations

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