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

The following examples show how to use com.griefcraft.lwc.LWC#isAdmin() . 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: BaseSetupModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (!event.hasFlag("s", "setup")) {
        return;
    }

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

    if (!lwc.isAdmin(sender)) {
        lwc.sendLocale(sender, "protection.accessdenied");
        event.setCancelled(true);
        return;
    }

    if (args.length == 0) {
        if (lwc.isAdmin(sender)) {
            // lwc.sendLocale(sender, "help.setup");
        }

        event.setCancelled(true);
    }
}
 
Example 2
Source File: BaseAdminModule.java    From Modern-LWC with MIT License 5 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.length == 0) {
        if (lwc.isAdmin(sender)) {
            lwc.sendLocale(sender, "help.admin");
        }

        event.setCancelled(true);
    } else if (args.length > 0) {
        // check for permissions
        if (!lwc.hasAdminPermission(sender, "lwc.admin." + args[0].toLowerCase())) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
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 4
Source File: BaseModeModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onCommand(LWCCommandEvent event) {
    if (!event.hasFlag("p", "mode")) {
        return;
    }

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

    event.setCancelled(true);

    if (args.length == 0) {
        lwc.sendSimpleUsage(sender, "/lwc mode <mode>");
        return;
    }

    if (!(sender instanceof Player)) {
        return;
    }

    String mode = args[0].toLowerCase();
    Player player = (Player) sender;

    if (!lwc.isModeWhitelisted(player, mode)) {
        if (!lwc.isAdmin(sender) && !lwc.isModeEnabled(mode)) {
            lwc.sendLocale(player, "protection.modes.disabled");
            return;
        }
    }

    event.setCancelled(false);
}
 
Example 5
Source File: Protection.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Check if a player has owner access to the protection
 *
 * @param player
 * @return
 */
public boolean isOwner(Player player) {
    LWC lwc = LWC.getInstance();

    if (isRealOwner(player)) {
        return true;
    } else {
        return lwc.isAdmin(player);
    }
}
 
Example 6
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 7
Source File: LimitsV2.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onCommand(LWCCommandEvent event) {
    if (!enabled || event.isCancelled()) {
        return;
    }

    if (!event.hasFlag("limits")) {
        return;
    }

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

    String playerName;

    if (args.length == 0) {
        if (args.length == 0 && !(sender instanceof Player)) {
            sender.sendMessage(Colors.Dark_Red + "You are not a player!");
            return;
        }

        playerName = sender.getName();
    } else {
        if (lwc.isAdmin(sender)) {
            playerName = args[0];
        } else {
            lwc.sendLocale(sender, "protection.accessdenied");
            return;
        }
    }

    @SuppressWarnings("deprecation")
    Player player = lwc.getPlugin().getServer().getPlayer(playerName);

    if (player == null) {
        sender.sendMessage(Colors.Dark_Red + "That player is not online!");
        return;
    }

    // send their limits to them
    sendLimits(sender, player, getPlayerLimits(player));
}
 
Example 8
Source File: DestroyModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onDestroyProtection(LWCProtectionDestroyEvent event) {

    if (event.isCancelled()) {
        return;
    }

    if (event.getMethod() != LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION &&
            event.getMethod() != LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION) {
        return;
    }

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

    boolean isOwner = protection.isOwner(player);

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

        // 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 (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "quiet"))) {
            BlockCache blockCache = BlockCache.getInstance();
            lwc.sendLocaleToActionBar(player, "protection.unregistered", "block",
                    LWC.materialToString(blockCache.getBlockType(protection.getBlockId())));
        }
        return;
    }

    event.setCancelled(true);
}
 
Example 9
Source File: HistoryModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
/**
 * History tool logic
 *
 * @param player
 * @param x
 * @param y
 * @param z
 */
private void historyTool(LWC lwc, Player player, int x, int y, int z) {
    LWCPlayer lwcPlayer = lwc.wrapPlayer(player);
    Action action = lwcPlayer.getAction("history");

    if (action == null) {
        player.sendMessage(Colors.Dark_Red + "History action is null!");
        return;
    }

    // the current "page"
    int page = Integer.parseInt(action.getData());

    // load the history objects for the protection
    List<History> relatedHistory = null;

    if (lwc.isAdmin(player)) {
        relatedHistory = lwc.getPhysicalDatabase().loadHistory(x, y, z);
    } else {
        relatedHistory = lwc.getPhysicalDatabase().loadHistory(player.getName(), x, y, z);
    }

    if (page < 0 || page >= relatedHistory.size()) {
        page = 0;
    }

    // No results
    if (relatedHistory.size() == 0) {
        lwc.sendLocale(player, "lwc.noresults");
        return;
    }

    // The relevent history object
    History history = relatedHistory.get(page);

    // Uh-oh! This normally will not happen (?)
    if (history == null) {
        lwcPlayer.removeAllActions();
        lwcPlayer.sendMessage("Refusing to send null history object");
        return;
    }

    // Make sure they can access it
    if (!lwc.isAdmin(player) && !history.getPlayer().equals(player.getName())) {
        return;
    }

    // Send the header
    lwcPlayer.sendMessage("History tool: Page " + (page + 1) + "/" + relatedHistory.size());

    // Send the details
    sendDetails(player, history);

    // increment the page
    if (page >= relatedHistory.size()) {
        // rewind
        action.setData("0");
    } else {
        action.setData(Integer.toString(page + 1));
    }
}
 
Example 10
Source File: HistoryModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
/**
 * Called when /lwc details or /lwc d is used.
 *
 * @param event
 */
private void doDetailsCommand(LWCCommandEvent event) {
    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();
    event.setCancelled(true);

    // We MUST have an argument ..!
    if (args.length < 1) {
        lwc.sendSimpleUsage(sender, "/lwc details <HistoryId>");
        return;
    }

    // Load it ..
    int historyId;

    try {
        historyId = Integer.parseInt(args[0]);
    } catch (NumberFormatException e) {
        lwc.sendLocale(sender, "lwc.noresults");
        return;
    }

    // Try and load the history object
    History history = lwc.getPhysicalDatabase().loadHistory(historyId);

    if (history == null) {
        lwc.sendLocale(sender, "lwc.noresults");
        return;
    }

    // Can they access it?
    if (!lwc.isAdmin(sender)) {
        if (sender instanceof Player) {
            // verify they actually OWN the history object
            if (!history.getPlayer().equalsIgnoreCase(((Player) sender).getName())) {
                // Make them think no results were found
                lwc.sendLocale(sender, "lwc.noresults");
                return;
            }
        }
    }

    // Tell them about it!
    sendDetails(sender, history);
}
 
Example 11
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 12
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);
    }
}