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

The following examples show how to use com.griefcraft.lwc.LWC#sendLocale() . 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: 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 2
Source File: FixModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() == Result.CANCEL) {
        return;
    }

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

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

    if (!lwc.canAdminProtection(event.getPlayer(), protection)) {
        return;
    }

    // Should we fix orientation?
    if (DoubleChestMatcher.PROTECTABLES_CHESTS.contains(block.getType()) || block.getType() == Material.FURNACE || block.getType() == Material.DISPENSER) {
        lwc.adjustChestDirection(block, event.getEvent().getBlockFace());
        lwc.sendLocale(player, "lwc.fix.fixed", "block", block.getType().toString().toLowerCase());
        player.removeAction(player.getAction("fix"));
    }
}
 
Example 3
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 4
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 5
Source File: NoSpamModule.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;
    }

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

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

    LWCPlayer player = lwc.wrapPlayer(sender);
    String mode = args[0].toLowerCase();

    if (!mode.equals("nospam")) {
        return;
    }

    if (!player.hasMode(mode)) {
        Mode temp = new Mode();
        temp.setName(mode);
        temp.setPlayer(player.getBukkitPlayer());

        player.enableMode(temp);
        lwc.sendLocale(player, "protection.modes.nospam.finalize");
    } else {
        player.disableMode(player.getMode(mode));
        lwc.sendLocale(player, "protection.modes.nospam.off");
    }

    event.setCancelled(true);
}
 
Example 6
Source File: PersistModule.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;
    }

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

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

    LWCPlayer player = lwc.wrapPlayer(sender);
    String mode = args[0].toLowerCase();

    if (!mode.equals("persist")) {
        return;
    }

    if (!player.hasMode(mode)) {
        Mode temp = new Mode();
        temp.setName(mode);
        temp.setPlayer(player.getBukkitPlayer());

        player.enableMode(temp);
        lwc.sendLocale(player, "protection.modes.persist.finalize");
    } else {
        player.disableMode(player.getMode(mode));
        lwc.sendLocale(player, "protection.modes.persist.off");
    }

    event.setCancelled(true);
}
 
Example 7
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 8
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 9
Source File: AdminCleanup.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[0].equals("cleanup")) {
        return;
    }

    // we have the right command
    event.setCancelled(true);

    // if we shouldn't output
    boolean silent = false;

    if (args.length > 1 && args[1].equalsIgnoreCase("silent")) {
        silent = true;
    }

    lwc.sendLocale(sender, "protection.admin.cleanup.start", "count",
            lwc.getPhysicalDatabase().getProtectionCount());

    // do the work in a separate thread so we don't fully lock the server
    new Thread(new Admin_Cleanup_Thread(lwc, sender, silent)).start();
}
 
Example 10
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 11
Source File: DropTransferModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onProtectionInteract(LWCProtectionInteractEvent event) {
    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Set<String> actions = event.getActions();
    boolean canAccess = event.canAccess();

    Player bPlayer = event.getPlayer();
    LWCPlayer player = lwc.wrapPlayer(bPlayer);

    if (!actions.contains("dropTransferSelect")) {
        return;
    }

    if (!canAccess) {
        lwc.sendLocale(player, "protection.interact.dropxfer.noaccess");
    } else {
        if (event.getEvent().getClickedBlock() instanceof Container) {
            lwc.sendLocale(player, "protection.interact.dropxfer.notchest");
            player.removeAllActions();
            event.setResult(Result.CANCEL);

            return;
        }

        Mode mode = new Mode();
        mode.setName("dropTransfer");
        mode.setData(protection.getId() + "");
        mode.setPlayer(bPlayer);
        player.enableMode(mode);
        mode = new Mode();
        mode.setName("+dropTransfer");
        mode.setPlayer(bPlayer);
        player.enableMode(mode);

        lwc.sendLocale(player, "protection.interact.dropxfer.finalize");
    }

    player.removeAllActions(); // ignore the persist mode
}
 
Example 12
Source File: AdminLocale.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[0].equals("locale")) {
        return;
    }

    // we have the right command
    event.setCancelled(true);

    if (args.length < 2) {
        lwc.sendSimpleUsage(sender, "/lwc admin locale <key> [args]");
        return;
    }

    String locale = args[1];
    String[] localeArgs = new String[0];

    if (args.length > 3) {
        localeArgs = StringUtil.join(args, 3).split(" ");
    }

    if (localeArgs.length > 0) {
        lwc.sendLocale(sender, locale, (Object[]) localeArgs);
    } else {
        lwc.sendLocale(sender, locale);
    }

}
 
Example 13
Source File: LimitsModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void onRegisterProtection(LWCProtectionRegisterEvent event) {
    if (!enabled || event.isCancelled()) {
        return;
    }

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

    if (hasReachedLimit(player, block)) {
        lwc.sendLocale(player, "protection.exceeded");
        event.setCancelled(true);
    }
}
 
Example 14
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 15
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 16
Source File: WorldGuard.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public void onRegisterProtection(LWCProtectionRegisterEvent event) {
    if (worldGuardPlugin == null) {
        return;
    }

    if (!configuration.getBoolean("worldguard.enabled", false)) {
        return;
    }

    LWC lwc = event.getLWC();
    Player player = event.getPlayer();
    Block block = event.getBlock();
    // Load the region manager for the world
    RegionManager regionManager = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(block.getWorld()));

    // Are we enforcing building?
    if (block.getType() == null) {
        return;
    }
    if (configuration.getBoolean("worldguard.requireBuildRights", true)) {
        if (!canBuild(player, block)) {
            lwc.sendLocale(player, "lwc.worldguard.needbuildrights");
            event.setCancelled(true);
            return;
        }
    }

    // Create a vector for the region
    BlockVector3 vector = BukkitAdapter.asBlockVector(block.getLocation());

    // Load the regions the block encompasses
    List<String> regions = regionManager.getApplicableRegionsIDs(vector);

    // Are they not in a region, and it's blocked there?
    if (regions.size() == 0) {
        if (!configuration.getBoolean(
                "worldguard.allowProtectionsOutsideRegions", true)) {
            lwc.sendLocale(player, "lwc.worldguard.notallowed");
            event.setCancelled(true);
        }
    } else {
        // check each region
        for (String region : regions) {
            // Should we deny them?
            // we don't need to explicitly call isRegionAllowed because
            // isRegionBlacklisted checks that as well
            if (isRegionBlacklisted(region)) {
                lwc.sendLocale(player, "lwc.worldguard.blacklisted");
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
Example 17
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 18
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 19
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);
    }
}
 
Example 20
Source File: AdminView.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("view")) {
        return;
    }

    // we have the right command
    event.setCancelled(true);

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

    Player player = (Player) sender;
    World world = player.getWorld();

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

    int protectionId = Integer.parseInt(args[1]);
    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection == null) {
        lwc.sendLocale(sender, "protection.admin.view.noexist");
        return;
    }

    Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ());

    if (!(block.getState() instanceof InventoryHolder)) {
        lwc.sendLocale(sender, "protection.admin.view.noinventory");
        return;
    }

    player.openInventory(((InventoryHolder) block.getState()).getInventory());

    lwc.sendLocale(sender, "protection.admin.view.viewing", "id", protectionId);
}