Java Code Examples for com.griefcraft.lwc.LWC#removeModes()

The following examples show how to use com.griefcraft.lwc.LWC#removeModes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfoModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("info")) {
        return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    lwc.sendLocale(player, "protection.interact.error.notregistered", "block", LWC.materialToString(block));
    lwc.removeModes(player);
}
 
Example 2
Source File: OwnersModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("owners")) {
        return;
    }

    LWC lwc = event.getLWC();
    Player player = event.getPlayer();
    Block block = event.getBlock();

    lwc.sendLocale(player, "protection.interact.error.notregistered", "block", LWC.materialToString(block));
    lwc.removeModes(player);
}
 
Example 3
Source File: AdminForceOwner.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("forceowner")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());

    Action action = player.getAction("forceowner");
    String newOwner = action.getData();

    protection.setOwner(newOwner);
    protection.save();

    lwc.sendLocale(player, "protection.interact.forceowner.finalize", "player", protection.getFormattedOwnerPlayerName());
    lwc.removeModes(player);
    event.setResult(Result.CANCEL);

}
 
Example 4
Source File: AdminForceOwner.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("forceowner")) {
        return;
    }

    LWC lwc = event.getLWC();
    Player player = event.getPlayer();

    lwc.sendLocale(player, "protection.interact.error.notregistered", "block", LWC.materialToString(event.getBlock()));
    lwc.removeModes(player);
    event.setResult(Result.CANCEL);
}
 
Example 5
Source File: ModifyModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("modify")) {
        return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    lwc.sendLocale(player, "protection.interact.error.notregistered", "block", LWC.materialToString(block));
    lwc.removeModes(player);
}
 
Example 6
Source File: CreateModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("create")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();

    BlockCache blockCache = BlockCache.getInstance();
    if (protection.isOwner(player)) {
        lwc.sendLocale(player, "protection.interact.error.alreadyregistered", "block",
                LWC.materialToString(blockCache.getBlockType(protection.getBlockId())));
    } else {
        lwc.sendLocale(player, "protection.interact.error.notowner", "block",
                LWC.materialToString(blockCache.getBlockType(protection.getBlockId())));
    }

    lwc.removeModes(player);
    event.setResult(Result.CANCEL);
}
 
Example 7
Source File: HistoryModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * History tool
 */
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != DEFAULT) {
        return;
    }

    if (!event.hasAction("history")) {
        return;
    }

    LWC lwc = event.getLWC();
    Player player = event.getPlayer();
    Protection protection = event.getProtection();

    historyTool(lwc, player, protection.getX(), protection.getY(), protection.getZ());
    event.setResult(Result.CANCEL);
    lwc.removeModes(player);
}
 
Example 8
Source File: HistoryModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != DEFAULT) {
        return;
    }

    if (!event.hasAction("history")) {
        return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    Player player = event.getPlayer();

    historyTool(lwc, player, block.getX(), block.getY(), block.getZ());
    event.setResult(Result.CANCEL);
    lwc.removeModes(player);
}
 
Example 9
Source File: ModifyModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("modify")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());
    Player bPlayer = event.getPlayer();
    event.setResult(Result.CANCEL);

    if (!lwc.isAdmin(bPlayer) && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-modify"))) {
        lwc.sendLocale(player, "protection.accessdenied");
        return;
    }

    if (lwc.canAdminProtection(player.getBukkitPlayer(), protection)) {
        Action action = player.getAction("modify");

        String data = action.getData();
        String[] rights = new String[0];

        if (data.length() > 0) {
            rights = data.split(" ");
        }

        lwc.removeModes(player);
        lwc.processRightsModifications(player, protection, rights);
    } else {
        lwc.sendLocale(player, "protection.interact.error.notowner", "block",
                LWC.materialToString(BlockCache.getInstance().getBlockType(protection.getBlockId())));
        lwc.removeModes(player);
    }

}
 
Example 10
Source File: FreeModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onBlockInteract(LWCBlockInteractEvent event) {
    if (!event.hasAction("free")) {
        return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    lwc.sendLocale(player, "protection.interact.error.notregistered", "block", LWC.materialToString(block));
    lwc.removeModes(player);
}
 
Example 11
Source File: InfoModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("info")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    String type = lwc.getPlugin().getMessageParser().parseMessage(protection.typeToString().toLowerCase());

    lwc.sendLocale(player, "lwc.info", "owner", protection.getFormattedOwnerPlayerName(), "type", type);

    if (event.canAdmin()) {
        if (protection.getType() == Protection.Type.PRIVATE || protection.getType() == Protection.Type.DONATION) {
            lwc.sendLocale(player, "lwc.acl", "size", protection.getPermissions().size());
            int index = 0;
            for (Permission permission : protection.getPermissions()) {
                if (index >= 9) {
                    break;
                }

                player.sendMessage(permission.toString());
                index++;
            }

            if (index == 0) {
                lwc.sendLocale(player, "lwc.acl.empty");
            } else if (index >= 9) {
                lwc.sendLocale(player, "lwc.acl.limitreached");
            }

            player.sendMessage("");
        }
    }

    if (lwc.isAdmin(player)) {
        lwc.sendLocale(player, "protection.interact.info.raw", "raw", protection.toString());
    }

    lwc.removeModes(player);
}
 
Example 12
Source File: OwnersModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("owners")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());
    event.setResult(Result.CANCEL);

    Action action = player.getAction("owners");
    int accessPage = Integer.parseInt(action.getData());

    // Calculate range
    int start = (accessPage - 1) * RESULTS_PER_PAGE;
    int max = start + RESULTS_PER_PAGE;

    List<Permission> permissions = protection.getPermissions();
    int numRights = permissions.size();

    // May have only been 2 rows left, or something. Get the real max
    int realMax = start + permissions.size();

    lwc.sendLocale(player, "lwc.owners.results", "start", start, "max", realMax, "total", numRights);

    for (int index = 0; index < max; index++) {
        if ((start + index) >= numRights) {
            break;
        }

        Permission permission = permissions.get(start + index);
        player.sendMessage(permission.toString());
    }

    lwc.removeModes(player);
}
 
Example 13
Source File: AdminOwnerAll.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (!event.hasFlag("a", "admin")) {
        return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    if (!args[0].equals("forceownerall")) {
        return;
    }

    if (args.length < 2) {
        lwc.sendSimpleUsage(sender,
                "/lwc admin forceownerall <OldPlayer> <NewPlayer>");
        return;
    }

    UUID oldOwner = UUIDRegistry.getUUID(args[2]);

    if (!(sender instanceof Player)) {
        lwc.sendLocale(sender, "protection.admin.noconsole");
        return;
    }

    String owner;

    if (oldOwner != null) {
        owner = oldOwner.toString();
    } else {
        owner = UUIDRegistry.getName(oldOwner);
    }

    UUID uuid = UUIDRegistry.getUUID(args[1]);
    List<Protection> protection;
    if (uuid != null) {
        protection = lwc.getPhysicalDatabase().loadProtectionsByPlayer(
                uuid.toString());
    } else {
        protection = lwc.getPhysicalDatabase().loadProtectionsByPlayer(
                args[1]);
    }

    LWCPlayer player = lwc.wrapPlayer(sender);
    for (Protection prot : protection) {
        prot.setOwner(owner);
        lwc.getPhysicalDatabase().saveProtection(prot);
        lwc.removeModes(player);
        lwc.log(prot.getOwner() + " Changed");
        lwc.sendLocale(player, "protection.interact.forceowner.finalize",
                "player", prot.getFormattedOwnerPlayerName());
    }
}
 
Example 14
Source File: BaseFlagModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (!event.hasAction("flag")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());

    Action action = player.getAction("flag");
    String data = action.getData();
    event.setResult(Result.CANCEL);

    if (!event.canAdmin()) {
        lwc.sendLocale(player, "protection.accessdenied");
        return;
    }

    boolean shouldAdd = data.substring(0, 1).equals("+");
    String flagName = data.substring(1);

    Flag.Type type = null;

    for (Flag.Type tmp : Flag.Type.values()) {
        if (tmp.toString().equalsIgnoreCase(flagName)) {
            type = tmp;
            break;
        }
    }

    if (type == null) {
        lwc.sendLocale(player, "protection.internalerror", "id", "flg");
        return;
    }

    //////// FIXME - needs to allow data somehow
    Flag flag = protection.getFlag(type);

    if (flag == null) {
        flag = new Flag(type);
    }

    if (shouldAdd) {
        protection.addFlag(flag);
        lwc.sendLocale(player, "protection.interact.flag.add", "flag", StringUtil.capitalizeFirstLetter(flagName));
    } else {
        protection.removeFlag(flag);
        lwc.sendLocale(player, "protection.interact.flag.remove", "flag", StringUtil.capitalizeFirstLetter(flagName));
    }

    protection.save();
    lwc.removeModes(player);
}
 
Example 15
Source File: FreeModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("free")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    /* Due to treating entities as blocks some issues are triggered
     *  such as when clicking an armor stand the block is air.
     *  I feel there is something better to be done here but this works */
    if (protection.getBlock().getType() == Material.AIR) {
        if (!protection.toString().contains("ARMOR_STAND")) {
            return;
        }
    }

    if (!lwc.isAdmin(player)
            && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-remove"))) {
        lwc.sendLocale(player, "protection.accessdenied");
        return;
    }

    if (lwc.hasAdminPermission(player, "lwc.admin.remove") || protection.isOwner(player)) {
        LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection,
                LWCProtectionDestroyEvent.Method.COMMAND, true, true);
        lwc.getModuleLoader().dispatchEvent(evt);

        if (!evt.isCancelled()) {
            // bind the player of destroyed the protection
            // We don't need to save the history we modify because it will
            // be saved anyway immediately after this
            for (History history : protection.getRelatedHistory(History.Type.TRANSACTION)) {
                if (history.getStatus() != History.Status.ACTIVE) {
                    continue;
                }

                history.addMetaData("destroyer=" + player.getName());
                history.addMetaData("destroyerTime=" + System.currentTimeMillis() / 1000L);
            }

            protection.remove();
            if (protection.getBlock() instanceof EntityBlock) {
                lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block",
                        EntityBlock.getEntity().getType().name());
            } else {
                lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block",
                        !protection.toString().contains("ARMOR_STAND") ?
                                LWC.materialToString(protection.getBlock()) : "ARMOR_STAND");
            }
        }

        lwc.removeModes(player);
    } else {
        if (protection.getBlock() instanceof EntityBlock) {
            lwc.sendLocale(player, "protection.interact.error.notowner", "block",
                    EntityBlock.getEntity().getType().name());
        } else {
            lwc.sendLocale(player, "protection.interact.error.notowner", "block",
                    LWC.materialToString(protection.getBlock()));
        }
        lwc.removeModes(player);
    }
}
 
Example 16
Source File: FreeModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onEntityInteractProtection(LWCProtectionInteractEntityEvent event) {
    if (event.getResult() != Result.DEFAULT) {
        return;
    }

    if (!event.hasAction("free")) {
        return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    if (protection.getBlock().getType() != Material.AIR) {
        return;
    }

    if (!lwc.isAdmin(player)
            && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-remove"))) {
        lwc.sendLocale(player, "protection.accessdenied");
        return;
    }

    if (lwc.hasAdminPermission(player, "lwc.admin.remove") || protection.isOwner(player)) {
        LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection,
                LWCProtectionDestroyEvent.Method.COMMAND, true, true);
        lwc.getModuleLoader().dispatchEvent(evt);

        if (!evt.isCancelled()) {
            // bind the player of destroyed the protection
            // We don't need to save the history we modify because it will
            // be saved anyway immediately after this
            for (History history : protection.getRelatedHistory(History.Type.TRANSACTION)) {
                if (history.getStatus() != History.Status.ACTIVE) {
                    continue;
                }

                history.addMetaData("destroyer=" + player.getName());
                history.addMetaData("destroyerTime=" + System.currentTimeMillis() / 1000L);
            }

            protection.remove();
            lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block",
                    event.getEvent().getRightClicked().getType().name());
        }

        lwc.removeModes(player);
    } else {
        lwc.sendLocale(player, "protection.interact.error.notowner", "block",
                event.getEvent().getRightClicked().getType().name());
        lwc.removeModes(player);
    }
}