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

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

    if (!(event.getSender() instanceof Player)) {
        return;
    }

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

    LWC lwc = event.getLWC();
    LWCPlayer player = lwc.wrapPlayer(event.getSender());

    // create the action
    com.griefcraft.model.Action action = new com.griefcraft.model.Action();
    action.setName("fix");
    action.setPlayer(player);

    player.addAction(action);
    lwc.sendLocale(player, "lwc.fix.clickblock");
    event.setCancelled(true);
}
 
Example 3
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 4
Source File: NoSpamModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
@Override
public void onSendLocale(LWCSendLocaleEvent event) {
    LWC lwc = event.getLWC();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());
    String locale = event.getLocale();

    // they don't intrigue us
    if (!player.hasMode("nospam")) {
        return;
    }

    // hide all of the creation messages
    if ((locale.endsWith("create.finalize") && !locale.equals("protection.create.finalize")) || locale.endsWith("notice.protected") || locale.endsWith("protection.unregistered")) {
        event.setCancelled(true);
    }
}
 
Example 5
Source File: ConfirmModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (!event.hasFlag("yes", "confirm", "accept")) {
        return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();

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

    // We only want players
    if (!(sender instanceof Player)) {
        return;
    }

    // Get the LWCPlayer
    LWCPlayer lwcPlayer = lwc.wrapPlayer(sender);

    // Is the player waiting for /lwc confirm?
    Action action = lwcPlayer.getAction("confirm");

    // They were!
    if (action instanceof ConfirmAction) {
        ((ConfirmAction) action).onConfirm();
    }
}
 
Example 6
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 7
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 8
Source File: EconomyModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Get the amount of protections the player purchased for  the given discount price
 *
 * @param lwc
 * @param player
 * @param discountPrice
 * @param discountId
 * @param onlyCountActiveTransactions
 * @return
 */
private int countDiscountedProtections(LWC lwc, Player player, double discountPrice, String discountId, boolean onlyCountActiveTransactions) {
    LWCPlayer lwcPlayer = lwc.wrapPlayer(player);
    List<History> related = lwcPlayer.getRelatedHistory(History.Type.TRANSACTION);

    int amount = 0;

    for (History history : related) {
        if (!history.getBoolean("discount"))
            continue;

        // Check the other discount id
        if (discountId != null)
            if (!history.hasKey("discountId") || !history.getString("discountId").equals(discountId))
                continue;

        // Are we only looking for valid transactions?
        if (onlyCountActiveTransactions && history.getStatus() == History.Status.INACTIVE)
            continue;

        // obtain the charge
        double charge = history.getDouble("charge");

        if (charge == discountPrice)
            amount++;
    }

    return amount;
}
 
Example 9
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 10
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 11
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 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: 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 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: ModifyModule.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("m", "modify")) {
        return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();
    String full = join(args, 0).trim();
    event.setCancelled(true);

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

    if (args.length < 1) {
        lwc.sendLocale(sender, "help.modify");
        return;
    }

    // Check for ID parameter
    Matcher matcher = ID_MATCHER.matcher(full);
    if (matcher.matches()) {
        int protectionId = Integer.parseInt(matcher.group(1));

        // load the protection
        Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

        // Does it even exist?
        if (protection == null) {
            lwc.sendLocale(sender, "lwc.protectionnotfound");
            return;
        }

        // Can they admin it? (if they're console, they can!)
        if (sender instanceof Player) {
            if (!lwc.canAdminProtection((Player) sender, protection)) {
                lwc.sendLocale(sender, "protection.accessdenied");
                return;
            }
        }

        // process it
        lwc.processRightsModifications(sender, protection, args);
        return;
    }

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

    LWCPlayer player = lwc.wrapPlayer(sender);

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

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

    lwc.sendLocale(sender, "protection.modify.finalize");
}
 
Example 16
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 17
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 18
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");
}