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

The following examples show how to use com.griefcraft.lwc.LWC#sendSimpleUsage() . 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: AdminClear.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("clear")) {
        return;
    }

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

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

    String toClear = args[1].toLowerCase();

    if (toClear.equals("protections")) {
        lwc.getPhysicalDatabase().removeAllProtections();
    }

    lwc.sendLocale(sender, "protection.admin.clear." + toClear);
}
 
Example 2
Source File: AdminPurge.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("purge")) {
        return;
    }

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

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

    boolean shouldRemoveBlocks = args[1].endsWith("remove");
    String players = StringUtil.join(args, shouldRemoveBlocks ? 2 : 1);

    for (String toRemove : players.split(" ")) {
        if (toRemove.contains("'")) continue; // bad me

        // Remove all of them
        lwc.fastRemoveProtectionsByPlayer(sender, toRemove, shouldRemoveBlocks);
        lwc.sendLocale(sender, "protection.admin.purge.finalize", "player", toRemove);
    }

    // reload the cache!
    LWC.getInstance().getPhysicalDatabase().precache();
}
 
Example 3
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 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: OwnersModule.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("o", "owner", "owners")) {
        return;
    }

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

    event.setCancelled(true);

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

    LWCPlayer player = lwc.wrapPlayer(sender);
    int page = 1;

    if (args.length > 0) {
        try {
            page = Integer.parseInt(args[0]);
        } catch (Exception e) {
            lwc.sendSimpleUsage(sender, "/lwc -owners [page]");
            return;
        }
    }

    Action action = new Action();
    action.setName("owners");
    action.setPlayer(player);
    action.setData(page + "");

    player.removeAllActions();
    player.addAction(action);

    lwc.sendLocale(sender, "protection.owners.finalize");
}
 
Example 6
Source File: DatabaseSetupModule.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("s", "setup")) {
        return;
    }

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

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

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

    if (args.length < 2) {
        lwc.sendSimpleUsage(sender, "/lwc setup database <DatabaseType> [args]");
        return;
    }

    // attempt to match the database
    Database.Type databaseType = Database.Type.matchType(args[1]);
    Database.DefaultType = databaseType;

    if (databaseType == null) {
        lwc.sendLocale(sender, "lwc.setup.database.invalid");
        return;
    }

    // Immediately convert
    DatabaseMigrator migrator = new DatabaseMigrator();
    PhysDB fromDatabase = lwc.getPhysicalDatabase();
    lwc.reloadDatabase();

    if (migrator.migrate(fromDatabase, lwc.getPhysicalDatabase())) {
        lwc.sendLocale(sender, "lwc.setup.database.success", "type", databaseType.toString());
    } else {
        lwc.sendLocale(sender, "lwc.setup.database.failure", "type", databaseType.toString());
        return;
    }

    // Should have succeeded - set the database type to the new one
    lwc.getConfiguration().setProperty("database.adapter", databaseType.toString().toLowerCase());
    lwc.getConfiguration().save();

    // immediately move to the new database
    lwc.reloadDatabase();
}
 
Example 7
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 8
Source File: AdminFind.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("find")) {
        return;
    }

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

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

    final int perPage = 7; // listings per page

    String player = args[1];
    int page = 1;

    if (args.length > 2) {
        try {
            page = Integer.parseInt(args[2]);
        } catch (Exception e) {
            lwc.sendLocale(sender, "protection.find.invalidpage");
            return;
        }
    }

    int start = (page - 1) * perPage;

    List<Protection> protections = lwc.getPhysicalDatabase().loadProtectionsByPlayer(player, start, perPage);
    int results = lwc.getPhysicalDatabase().getProtectionCount(player);
    int max = protections.size(); // may not be the full perPage
    int ceil = start + max;

    lwc.sendLocale(sender, "protection.find.currentpage", "page", page);

    if (results != max) {
        lwc.sendLocale(sender, "protection.find.nextpage", "player", player, "page", page + 1);
    }

    lwc.sendLocale(sender, "protection.find.showing", "start", start, "ceil", ceil, "results", results);

    for (Protection protection : protections) {
        sender.sendMessage(protection.toString());
    }
}
 
Example 9
Source File: AdminExpire.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("expire")) {
        return;
    }

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

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

    boolean shouldRemoveBlocks = args[1].endsWith("remove");
    String toParse = StringUtil.join(args, shouldRemoveBlocks ? 2 : 1);
    long time = TimeUtil.parseTime(toParse);

    if (time == 0L) {
        lwc.sendLocale(sender, "protection.admin.expire.invalidtime");
        return;
    }

    int threshold = (int) ((System.currentTimeMillis() / 1000L) - time);

    // remove the protections
    int completed = lwc.fastRemoveProtections(sender, "last_accessed <= " + threshold + " AND last_accessed >= 0", shouldRemoveBlocks);

    // reset the cache
    if (completed > 0) {
        LWC.getInstance().getPhysicalDatabase().precache();
    }

    lwc.sendLocale(sender, "protection.admin.expire.removed", "count", completed);

}
 
Example 10
Source File: AdminBackup.java    From Modern-LWC with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
        return;
    }

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

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

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

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

    if (args.length == 1) {
        lwc.sendSimpleUsage(sender, "/lwc admin backup <action>");
        return;
    }

    // The action they want to perform
    String action = args[1].toLowerCase();

    if (action.equals("create")) {
        lwc.getBackupManager().createBackup();
        sender.sendMessage("Backup is being created now.");
    } else if (action.equals("restore")) {
        if (args.length < 3) {
            lwc.sendSimpleUsage(sender, "/lwc admin backup restore <BackupName>");
            return;
        }

        final String backupName = StringUtil.join(args, 2);
        sender.sendMessage("Restoring backup " + backupName);

        lwc.getPlugin().getServer().getScheduler().scheduleAsyncDelayedTask(lwc.getPlugin(), new Runnable() {
            public void run() {
                BackupManager.Result result = lwc.getBackupManager().restoreBackup(backupName);
                sender.sendMessage("Result: " + result);
            }
        });
    }
}
 
Example 11
Source File: AdminRemove.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("remove")) {
        return;
    }

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

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

    int protectionId;

    try {
        protectionId = Integer.parseInt(args[1]);
    } catch (Exception e) {
        lwc.sendLocale(sender, "protection.admin.remove.invalidid");
        return;
    }

    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection != null) {
        protection.remove();
    }

    lwc.sendLocale(sender, "protection.admin.remove.finalize");
}
 
Example 12
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);
}
 
Example 13
Source File: UnlockModule.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("u", "unlock")) {
        return;
    }

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

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

    if (!lwc.hasPlayerPermission(sender, "lwc.unlock")) {
        lwc.sendLocale(sender, "protection.accessdenied");
        return;
    }

    if (args.length < 1) {
        lwc.sendSimpleUsage(sender, "/lwc -u <Password>");
        return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);
    String password = join(args, 0);
    password = encrypt(password);

    // see if they have the protection interaction action
    Action action = player.getAction("interacted");

    if (action == null) {
        lwc.sendLocale(sender, "lwc.unlock.noselection");
    } else {
        Protection protection = action.getProtection();

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

        if (protection.getType() != Protection.Type.PASSWORD) {
            lwc.sendLocale(player, "protection.unlock.notpassword");
            return;
        }

        if (protection.getPassword().equals(password)) {
            player.addAccessibleProtection(protection);
            player.removeAction(action);
            lwc.sendLocale(player, "protection.unlock.password.valid");
        } else {
            lwc.sendLocale(player, "protection.unlock.password.invalid");
        }
    }
}
 
Example 14
Source File: CreateModule.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("c", "create")) {
        return;
    }

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

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

    if (args.length == 0) {
        lwc.sendLocale(sender, "help.creation");
        return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);

    String full = StringUtil.join(args, 0).trim();
    String type = args[0].toLowerCase();
    String data = StringUtil.join(args, 1);
    event.setCancelled(true);

    /**
     * Allow individual enforcements with e.g lwc.create.private, or just the
     * umbrella lwc.create for all
     */
    if (!lwc.hasPermission(sender, "lwc.create." + type, "lwc.create", "lwc.protect")) {
        lwc.sendLocale(sender, "protection.accessdenied");
        return;
    }

    try {
        switch (Protection.Type.matchType(type)) {
            case PASSWORD:
                if (args.length < 2) {
                    lwc.sendSimpleUsage(player, "/lwc -c password <Password>");
                    return;
                }

                String hiddenPass = StringUtil.transform(data, '*');
                lwc.sendLocale(player, "protection.create.password", "password", hiddenPass);
                break;
            default:
                break;
        }
    } catch (IllegalArgumentException e) {
        // Invalid protection type!
        lwc.sendLocale(player, "help.creation");
        return;
    }

    Action action = new Action();
    action.setName("create");
    action.setPlayer(player);
    action.setData(full);

    player.removeAllActions();
    player.addAction(action);

    lwc.sendLocale(player, "protection.create.finalize", "type",
            lwc.getPlugin().getMessageParser().parseMessage(type));
}
 
Example 15
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);
}