/** Load all the classes in the current jar file so it can be overwritten */ private void loadAllClasses() { LWC lwc = LWC.getInstance(); try { // Load the jar JarFile jar = new JarFile(lwc.getPlugin().getFile()); // Walk through all of the entries Enumeration<JarEntry> enumeration = jar.entries(); while (enumeration.hasMoreElements()) { JarEntry entry = enumeration.nextElement(); String name = entry.getName(); // is it a class file? if (name.endsWith(".class")) { // convert to package String path = name.replaceAll("/", "."); path = path.substring(0, path.length() - ".class".length()); // Load it this.getClass().getClassLoader().loadClass(path); } } } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
@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(); Player player = event.getPlayer(); Action action = lwc.getMemoryDatabase().getAction("forceowner", player.getName()); String newOwner = action.getData(); protection.setOwner(newOwner); protection.save(); lwc.sendLocale(player, "protection.interact.forceowner.finalize", "player", newOwner); lwc.removeModes(player); event.setResult(Result.CANCEL); return; }
@Override public void load(LWC lwc) { configuration = Configuration.load("doors.yml"); doors = new LinkedList<DoorAction>(); enabled = configuration.getBoolean("doors.enabled", true); String action = configuration.getString("doors.action"); if (action == null) { this.action = Action.NULL; return; } if (action.equalsIgnoreCase("openAndClose")) { this.action = Action.OPEN_AND_CLOSE; this.interval = configuration.getInt("doors.interval", 3); } else if (action.equalsIgnoreCase("toggle")) { this.action = Action.TOGGLE; } // start the task DoorTask doorTask = new DoorTask(); lwc.getPlugin() .getServer() .getScheduler() .scheduleSyncRepeatingTask(lwc.getPlugin(), doorTask, 20, 20); }
@Override public void onBlockInteract(LWCBlockInteractEvent event) { Player player = event.getPlayer(); Set<String> actions = event.getActions(); if (!actions.contains("dropTransferSelect")) { return; } lwc.sendLocale(player, "protection.interact.dropxfer.notprotected"); lwc.removeModes(player); }
@Override public void onRegisterProtection(LWCProtectionRegisterEvent event) { if (event.isCancelled()) { return; } LWC lwc = event.getLWC(); Player player = event.getPlayer(); Block block = event.getBlock(); if (hasReachedLimit(player, block.getType())) { lwc.sendLocale(player, "protection.exceeded"); event.setCancelled(true); } }
public static boolean protectBlock(Block block, String name) { boolean protect = false; if (lwc != null) { lwc.getPhysicalDatabase() .registerProtection( block.getTypeId(), ProtectionTypes.PRIVATE, block.getWorld().getName(), name, "", block.getX(), block.getY(), block.getZ()); protect = true; TDebug.debug( DebugDetailLevel.EVERYTHING, block.getType().name() + " block protected for " + name + ". (" + block.getX() + ", " + block.getY() + ", " + block.getZ() + ")"); } return protect; }
@Override @SuppressWarnings("deprecation") public void onDropItem(LWCDropItemEvent event) { Player bPlayer = event.getPlayer(); Item item = event.getEvent().getItemDrop(); ItemStack itemStack = item.getItemStack(); LWCPlayer player = lwc.wrapPlayer(bPlayer); int protectionId = getPlayerDropTransferTarget(player); if (protectionId == -1) { return; } if (!isPlayerDropTransferring(player)) { return; } Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId); if (protection == null) { lwc.sendLocale(player, "lwc.nolongerexists"); player.disableMode(player.getMode("dropTransfer")); return; } // load the world and the inventory World world = player.getServer().getWorld(protection.getWorld()); if (world == null) { lwc.sendLocale(player, "lwc.invalidworld"); player.disableMode(player.getMode("dropTransfer")); return; } // Don't allow them to transfer items across worlds if (bPlayer.getWorld() != world && !lwc.getConfiguration().getBoolean("modes.droptransfer.crossWorld", false)) { lwc.sendLocale(player, "lwc.dropxfer.acrossworlds"); player.disableMode(player.getMode("dropTransfer")); return; } Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ()); Map<Integer, ItemStack> remaining = lwc.depositItems(block, itemStack); if (remaining.size() > 0) { lwc.sendLocale(player, "lwc.dropxfer.chestfull"); for (ItemStack temp : remaining.values()) { bPlayer.getInventory().addItem(temp); } } bPlayer.updateInventory(); // if they're in the chest and dropping items, this is required item.remove(); }
public Database() { currentType = DefaultType; prefix = LWC.getInstance().getConfiguration().getString("database.prefix", ""); if (prefix == null) { prefix = ""; } }
@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.getOwner(), "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); }
@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); }
@Override public void onCommand(LWCCommandEvent event) { if (event.isCancelled()) { return; } if (!event.hasFlag("i", "info")) { return; } LWC lwc = event.getLWC(); CommandSender sender = event.getSender(); String[] args = event.getArgs(); if (!(sender instanceof Player)) { return; } event.setCancelled(true); if (!lwc.hasPlayerPermission(sender, "lwc.info")) { lwc.sendLocale(sender, "protection.accessdenied"); return; } LWCPlayer player = lwc.wrapPlayer(sender); String type = "info"; if (args.length > 0) { type = args[0].toLowerCase(); } if (type.equals("info")) { Action action = new Action(); action.setName("info"); action.setPlayer(player); player.removeAllActions(); player.addAction(action); lwc.sendLocale(player, "protection.info.finalize"); } }
/** * Sends the list of limits to the player * * @param sender the commandsender to send the limits to * @param target the player limits are being shown for, can be null * @param limits */ public void sendLimits(CommandSender sender, Player target, List<Limit> limits) { LWC lwc = LWC.getInstance(); for (Limit limit : limits) { if (limit == null) { continue; } String stringLimit = limit.getLimit() == UNLIMITED ? "Unlimited" : Integer.toString(limit.getLimit()); String colour = Colors.Yellow; if (target != null) { boolean reachedLimit = hasReachedLimit( target, ((limit instanceof BlockLimit) ? ((BlockLimit) limit).getMaterial() : null)); colour = reachedLimit ? Colors.Red : Colors.Green; } if (limit instanceof DefaultLimit) { String currentProtected = target != null ? (Integer.toString(limit.getProtectionCount(target, null)) + "/") : ""; sender.sendMessage("Default: " + colour + currentProtected + stringLimit); } else if (limit instanceof BlockLimit) { BlockLimit blockLimit = (BlockLimit) limit; String currentProtected = target != null ? (Integer.toString(limit.getProtectionCount(target, blockLimit.getMaterial())) + "/") : ""; sender.sendMessage( lwc.materialToString(blockLimit.getMaterial()) + ": " + colour + currentProtected + stringLimit); } else { sender.sendMessage(limit.getClass().getSimpleName() + ": " + Colors.Yellow + stringLimit); } } }
@Override public void onCommand(LWCCommandEvent event) { if (event.isCancelled()) { return; } if (!event.hasFlag("limits")) { return; } LWC lwc = event.getLWC(); CommandSender sender = event.getSender(); String[] args = event.getArgs(); event.setCancelled(true); if (args.length == 0 && !(sender instanceof Player)) { sender.sendMessage(Colors.Red + "Unsupported"); return; } String playerName; if (args.length == 0) { playerName = sender.getName(); } else { if (lwc.isAdmin(sender)) { playerName = args[0]; } else { lwc.sendLocale(sender, "protection.accessdenied"); return; } } Player player = lwc.getPlugin().getServer().getPlayer(playerName); if (player == null) { return; } // send their limits to them sendLimits(player, player, getPlayerLimits(player)); }
/** * Gets the list of limits that may apply to the player. For group limits, it uses the highest one * found. * * @param player * @return */ public List<Limit> getPlayerLimits(Player player) { LWC lwc = LWC.getInstance(); List<Limit> limits = new LinkedList<Limit>(); // get all of their own limits String playerName = player.getName().toLowerCase(); if (playerLimits.containsKey(playerName)) { limits.addAll(playerLimits.get(playerName)); } // Look over the group limits for (String group : lwc.getPermissions().getGroups(player)) { if (groupLimits.containsKey(group)) { for (Limit limit : groupLimits.get(group)) { // try to match one already inside what we found Limit matched = findLimit(limits, limit); if (matched != null) { // Is our limit better? if (limit.getLimit() > matched.getLimit()) { limits.remove(matched); limits.add(limit); } } else { limits.add(limit); } } } } // Look at the default limits for (Limit limit : defaultLimits) { // try to match one already inside what we found Limit matched = findLimit(limits, limit); if (matched == null) { limits.add(limit); } } return limits; }
public boolean lwcProtected(Block block) { if (lwc == null) { return false; } Protection protection = lwc.findProtection(block); // also accepts x, y, z if (protection != null) { return true; } return false; }
public void init() { LWC lwc = LWC.getInstance(); updateBranch = UpdateBranch.match(lwc.getConfiguration().getString("updater.branch", "STABLE")); updateMethod = UpdateMethod.match(lwc.getConfiguration().getString("updater.method", "MANUAL")); if (updateMethod == UpdateMethod.AUTOMATIC) { this.loadVersions( true, new Runnable() { public void run() { tryAutoUpdate(false); logger.info("LWC: Latest version: " + latestVersion); } }); } // verify we have local files (e.g sqlite.jar, etc) this.verifyFiles(); this.downloadFiles(); }
@Override public Result onCommand(LWC lwc, CommandSender sender, String command, String[] args) { if (!StringUtils.hasFlag(command, "a") && !StringUtils.hasFlag(command, "admin")) { return DEFAULT; } if (args.length == 0) { if (lwc.isAdmin(sender)) { lwc.sendLocale(sender, "help.admin"); } return CANCEL; } else if (args.length > 0) { // check for permissions if (!lwc.hasAdminPermission(sender, "lwc.admin." + args[0])) { return CANCEL; } } return DEFAULT; }
/** @return the path where the database file should be saved */ public String getDatabasePath() { Configuration lwcConfiguration = LWC.getInstance().getConfiguration(); if (currentType == Type.MySQL) { return "//" + lwcConfiguration.getString("database.host") + "/" + lwcConfiguration.getString("database.database"); } return lwcConfiguration.getString("database.path"); }
@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 (protection.getBlockId() != Material.CHEST.getId()) { 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 }
@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(); if (protection.isOwner(player)) { lwc.sendLocale( player, "protection.interact.error.alreadyregistered", "block", LWC.materialToString(protection.getBlockId())); } else { lwc.sendLocale( player, "protection.interact.error.notowner", "block", LWC.materialToString(protection.getBlockId())); } lwc.removeModes(player); event.setResult(Result.CANCEL); }
@Override public Result onDestroyProtection( LWC lwc, Player player, Protection protection, Block block, boolean canAccess, boolean canAdmin) { boolean isOwner = protection.isOwner(player); if (isOwner) { protection.remove(); lwc.sendLocale( player, "protection.unregistered", "block", LWC.materialToString(protection.getBlockId())); return ALLOW; } return CANCEL; }
@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("forceowner")) { return; } // we have the right command event.setCancelled(true); if (args.length < 2) { lwc.sendSimpleUsage(sender, "/lwc admin forceowner <player>"); return; } if (!(sender instanceof Player)) { lwc.sendLocale(sender, "protection.admin.noconsole"); return; } Player player = (Player) sender; String newOwner = args[1]; lwc.getMemoryDatabase().registerAction("forceowner", player.getName(), newOwner); lwc.sendLocale(sender, "protection.admin.forceowner.finalize", "player", newOwner); return; }
@Override public Result onCommand(LWC lwc, CommandSender sender, String command, String[] args) { if (!StringUtils.hasFlag(command, "a") && !StringUtils.hasFlag(command, "admin")) { return DEFAULT; } if (!args[0].equals("cmd")) { return DEFAULT; } sender.sendMessage(Colors.Green + "Flushing Update Thread.."); lwc.getUpdateThread().flush(); sender.sendMessage(Colors.Green + "Done."); return CANCEL; }
public void onDestroyProtection(LWCProtectionDestroyEvent event) { if (event.isCancelled()) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); Player player = event.getPlayer(); boolean isOwner = protection.isOwner(player); if (isOwner) { protection.remove(); lwc.sendLocale( player, "protection.unregistered", "block", LWC.materialToString(protection.getBlockId())); return; } event.setCancelled(true); return; }
public static boolean isProtected(Block chest) { if (lwc != null) { Protection lwcProt = lwc.findProtection(chest); if (lwcProt != null) { return true; } } if (lockette != null) { boolean lockProt = Lockette.isProtected(chest); if (lockProt) { return true; } } return false; }
public static String protectedByWho(Block chest) { if (chest == null) { return null; } String name = ""; if (lwc != null) { Protection prot = lwc.findProtection(chest); if (prot != null) { name = prot.getOwner(); } } if (lockette != null) { name = Lockette.getProtectedOwner(chest); } return name; }
@Override public void execute(LWC lwc, CommandSender sender, String[] args) { if (args.length < 2) { lwc.sendSimpleUsage(sender, "/lwc -u <Password>"); return; } Player player = (Player) sender; String password = join(args, 1); password = encrypt(password); if (!lwc.getMemoryDatabase().hasPendingUnlock(player.getName())) { player.sendMessage(Colors.Red + "Nothing selected. Open a locked protection first."); return; } else { int chestID = lwc.getMemoryDatabase().getUnlockID(player.getName()); if (chestID == -1) { lwc.sendLocale(player, "protection.internalerror", "id", "ulock"); return; } Protection entity = lwc.getPhysicalDatabase().loadProtection(chestID); if (entity.getType() != ProtectionTypes.PASSWORD) { lwc.sendLocale(player, "protection.unlock.notpassword"); return; } if (entity.getData().equals(password)) { lwc.getMemoryDatabase().unregisterUnlock(player.getName()); lwc.getMemoryDatabase().registerPlayer(player.getName(), chestID); lwc.sendLocale(player, "protection.unlock.password.valid"); } else { lwc.sendLocale(player, "protection.unlock.password.invalid"); } } }
/** * Checks if a player has reached their protection limit * * @param player * @param material the material type the player has interacted with * @return */ public boolean hasReachedLimit(Player player, Material material) { LWC lwc = LWC.getInstance(); Limit limit = getEffectiveLimit(player, material); // if they don't have a limit it's not possible to reach it ^^ // ... but if it's null, what the hell did the server owner do? if (limit == null) { return false; } // Get the effective limit placed upon them int neverPassThisNumber = limit.getLimit(); // get the amount of protections the player has int protections = limit.getProtectionCount(player, material); return protections >= neverPassThisNumber; }
public static List<Protection> loadProtections( String arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) { if (lwcPlugin == null) { loadPlugin(); } if (lwcPlugin != null) { List<com.griefcraft.model.Protection> loadProtections = lwcPlugin.getPhysicalDatabase().loadProtections(arg0, arg1, arg2, arg3, arg4, arg5, arg6); List<Protection> protections = null; if (loadProtections != null) { protections = new ArrayList<Protection>(); for (com.griefcraft.model.Protection loadProtection : loadProtections) { protections.add(new Protection(loadProtection)); } } return protections; } return null; }
@Override public void onBlockInteract(LWCBlockInteractEvent event) { if (event.getResult() != Result.DEFAULT) { return; } if (!event.hasAction("create")) { return; } LWC lwc = event.getLWC(); Block block = event.getBlock(); LWCPlayer player = lwc.wrapPlayer(event.getPlayer()); if (!lwc.isProtectable(block)) { return; } PhysDB physDb = lwc.getPhysicalDatabase(); Action action = player.getAction("create"); String actionData = action.getData(); String[] split = actionData.split(" "); String protectionType = split[0].toLowerCase(); String protectionData = StringUtil.join(split, 1); // check permissions again (DID THE LITTLE SHIT MOVE WORLDS??!?!?!?!?!?) if (!lwc.hasPermission( event.getPlayer(), "lwc.create." + protectionType, "lwc.create", "lwc.protect")) { lwc.sendLocale(player, "protection.accessdenied"); lwc.removeModes(player); event.setResult(Result.CANCEL); return; } // misc data we'll use later String playerName = player.getName(); String worldName = block.getWorld().getName(); int blockX = block.getX(); int blockY = block.getY(); int blockZ = block.getZ(); lwc.removeModes(player); LWCProtectionRegisterEvent evt = new LWCProtectionRegisterEvent(player.getBukkitPlayer(), block); lwc.getModuleLoader().dispatchEvent(evt); // another plugin cancelled the registration if (evt.isCancelled()) { return; } // The created protection Protection protection = null; if (protectionType.equals("public")) { protection = physDb.registerProtection( block.getTypeId(), Protection.Type.PUBLIC, worldName, player.getUniqueId().toString(), "", blockX, blockY, blockZ); lwc.sendLocale(player, "protection.interact.create.finalize"); } else if (protectionType.equals("password")) { String password = lwc.encrypt(protectionData); protection = physDb.registerProtection( block.getTypeId(), Protection.Type.PASSWORD, worldName, player.getUniqueId().toString(), password, blockX, blockY, blockZ); player.addAccessibleProtection(protection); lwc.sendLocale(player, "protection.interact.create.finalize"); lwc.sendLocale(player, "protection.interact.create.password"); } else if (protectionType.equals("private") || protectionType.equals("donation")) { String[] rights = protectionData.split(" "); protection = physDb.registerProtection( block.getTypeId(), Protection.Type.matchType(protectionType), worldName, player.getUniqueId().toString(), "", blockX, blockY, blockZ); lwc.sendLocale(player, "protection.interact.create.finalize"); lwc.processRightsModifications(player, protection, rights); } // tell the modules that a protection was registered if (protection != null) { // Fix the blocks that match it protection.removeCache(); LWC.getInstance().getProtectionCache().addProtection(protection); lwc.getModuleLoader().dispatchEvent(new LWCProtectionRegistrationPostEvent(protection)); } event.setResult(Result.CANCEL); }