com.griefcraft.lwc.LWC Java Examples
The following examples show how to use
com.griefcraft.lwc.LWC.
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: FixModule.java From Modern-LWC with MIT License | 6 votes |
@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 #2
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityChangeBlock(EntityChangeBlockEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = LWC.getInstance(); Block block = event.getBlock(); if (!lwc.isProtectable(block)) { return; } Protection protection = lwc.findProtection(block); if (protection != null) { event.setCancelled(true); } }
Example #3
Source File: AdminFlush.java From Modern-LWC with MIT License | 6 votes |
@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("flush")) { return; } // we have the right command event.setCancelled(true); sender.sendMessage(Colors.Dark_Green + "Flushing Update Thread.."); lwc.getDatabaseThread().flush(); sender.sendMessage(Colors.Dark_Green + "Done."); }
Example #4
Source File: LimitsModule.java From Modern-LWC with MIT License | 6 votes |
/** * Resolve a configuration node for a player. Tries nodes in this order: * <pre> * players.PLAYERNAME.node * groups.GROUPNAME.node * master.node * </pre> * * @param player * @param node * @return */ private String resolveString(Player player, String node) { LWC lwc = LWC.getInstance(); // resolve the limits type String value; // try the player value = configuration.getString("players." + player.getName() + "." + node); // try the player's groups if (value == null) { for (String groupName : lwc.getPermissions().getGroups(player)) { if (groupName != null && !groupName.isEmpty() && value == null) { value = map("groups." + groupName + "." + node); } } } // if all else fails, use master if (value == null) { value = map("master." + node); } return value != null && !value.isEmpty() ? value : null; }
Example #5
Source File: PhysDB.java From Modern-LWC with MIT License | 6 votes |
/** * Load all protection history that has the given history id * * @param historyId * @return */ public History loadHistory(int historyId) { if (!LWC.getInstance().isHistoryEnabled()) { return null; } try { statement = prepare("SELECT * FROM " + prefix + "history WHERE id = ?"); statement.setInt(1, historyId); ResultSet set = statement.executeQuery(); if (set.next()) { History history = resolveHistory(new History(), set); set.close(); return history; } set.close(); } catch (SQLException e) { printException(e); } return null; }
Example #6
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBlockExplode(BlockExplodeEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); for (Block block : event.blockList()) { Protection protection = plugin.getLWC().findProtection(block.getLocation()); if (protection != null) { boolean ignoreExplosions = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions")); if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) { event.setCancelled(true); } } } }
Example #7
Source File: CreateModule.java From Modern-LWC with MIT License | 6 votes |
@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 #8
Source File: MagnetModule.java From Modern-LWC with MIT License | 6 votes |
@Override public void load(LWC lwc) { enabled = configuration.getBoolean("magnet.enabled", false); itemBlacklist = new ArrayList<Material>(); radius = configuration.getInt("magnet.radius", 3); perSweep = configuration.getInt("magnet.perSweep", 20); if (!enabled) { return; } // get the item blacklist List<String> temp = configuration.getStringList("magnet.blacklist", new ArrayList<String>()); for (String item : temp) { Material material = Material.matchMaterial(item); if (material != null) { itemBlacklist.add(material); } } // register our search thread schedule MagnetTask searchThread = new MagnetTask(); lwc.getPlugin().getServer().getScheduler().scheduleSyncRepeatingTask(lwc.getPlugin(), searchThread, 50, 50); }
Example #9
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent e) { Entity entity = e.getRightClicked(); if (plugin.getLWC().isProtectable(e.getRightClicked().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); Player p = e.getPlayer(); boolean canAccess = lwc.canAccessProtection(p, protection); if (onPlayerEntityInteract(p, entity, e.isCancelled())) { e.setCancelled(true); } if (protection != null) { if (canAccess) return; e.setCancelled(true); } } }
Example #10
Source File: EconomyModule.java From Modern-LWC with MIT License | 6 votes |
/** * Resolve a configuration node for a player. Tries nodes in this order: * 1. players.PLAYERNAME.node * 2. groups.GROUPNAME.node * 3. Economy.node * * @param player * @param node * @return */ private String resolveValue(Player player, String node) { LWC lwc = LWC.getInstance(); // resolve the limits type String value; // try the player value = configuration.getString("players." + player.getName() + "." + node, null); // try permissions if (value == null) for (String groupName : lwc.getPermissions().getGroups(player)) if (groupName != null && !groupName.isEmpty() && value == null) value = map("groups." + groupName + "." + node, null); // if all else fails, use master if (value == null) value = map("Economy." + node, null); return value != null && !value.isEmpty() ? value : ""; }
Example #11
Source File: Updater.java From Modern-LWC with MIT License | 6 votes |
@SuppressWarnings("deprecation") public void init() { final LWC lwc = LWC.getInstance(); if (lwc.getConfiguration().getBoolean("core.updateNotifier", true)) { lwc.getPlugin().getServer().getScheduler().scheduleAsyncDelayedTask(lwc.getPlugin(), new Runnable() { public void run() { Object[] updates = Updater.getLastUpdate(); if (updates.length == 2) { lwc.log("[ModernLWC] New update avaible:"); lwc.log("New version: " + updates[0]); lwc.log( "Your version: " + LWC.getInstance().getPlugin().getDescription().getVersion()); lwc.log("What's new: " + updates[1]); } } }); } }
Example #12
Source File: Towny.java From Modern-LWC with MIT License | 6 votes |
public void unclaimTowny(TownUnclaimEvent event) throws NotRegisteredException, TownyException { if (towny == null) { return; } List<WorldCoord> wcl = AreaSelectionUtil.selectWorldCoordArea(event.getTown(), event.getWorldCoord(), new String[]{"auto"}); wcl = AreaSelectionUtil.filterOwnedBlocks(event.getTown(), wcl); for (WorldCoord wc : wcl) { PlotBlockData pbd = new PlotBlockData(wc.getTownBlock()); for (int z = 0; z < pbd.getSize(); z++) for (int x = 0; x < pbd.getSize(); x++) for (int y = pbd.getHeight(); y > 0; y--) { Block b = event.getWorldCoord().getBukkitWorld().getBlockAt((pbd.getX() * pbd.getSize()) + x, y, (pbd.getZ() * pbd.getSize()) + z); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase() .loadProtection(event.getWorldCoord().getWorldName(), b.getX(), b.getY(), b.getZ()); if (protection != null) { protection.remove(); } } } }
Example #13
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void hangingBreak(HangingBreakEvent event) { Entity entity = event.getEntity(); if (plugin.getLWC().isProtectable(event.getEntity().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if (protection != null) { if (event.getCause() == RemoveCause.PHYSICS || event.getCause() == RemoveCause.EXPLOSION || event.getCause() == RemoveCause.OBSTRUCTION) { event.setCancelled(true); } } } }
Example #14
Source File: Protection.java From Modern-LWC with MIT License | 6 votes |
/** * Force a protection update to the live database */ public void saveNow() { if (removed) { return; } // encode JSON objects encodeRights(); encodeFlags(); // only save the protection if it was modified if (modified && !removing) { LWC.getInstance().getPhysicalDatabase().saveProtection(this); } // check the cache for history updates checkAndSaveHistory(); }
Example #15
Source File: InfoModule.java From Modern-LWC with MIT License | 6 votes |
@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); }
Example #16
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onBlockRedstoneChange(BlockRedstoneEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = plugin.getLWC(); Block block = event.getBlock(); if (block == null) { return; } Protection protection = lwc.findProtection(block.getLocation()); if (protection == null) { return; } LWCRedstoneEvent evt = new LWCRedstoneEvent(event, protection); lwc.getModuleLoader().dispatchEvent(evt); if (evt.isCancelled()) { event.setNewCurrent(event.getOldCurrent()); } }
Example #17
Source File: FixModule.java From Modern-LWC with MIT License | 6 votes |
@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 #18
Source File: Database.java From Modern-LWC with MIT License | 5 votes |
/** * Get the path to the LWC database file or if we're using MySQL what the MySQL URI is. * * @return path/address to database as a {@code String} */ 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"); }
Example #19
Source File: WorldGuard.java From Modern-LWC with MIT License | 5 votes |
@Override public void load(LWC lwc) { Plugin plugin = lwc.getPlugin().getServer().getPluginManager() .getPlugin("WorldGuard"); if (plugin != null) { if (plugin.getDescription().getAPIVersion() != null) { worldGuardPlugin = (WorldGuardPlugin) plugin; } else if (configuration.getBoolean("worldguard.enabled", false)) { lwc.log("An outdated version of WorldGuard has been detected."); lwc.log("Please update it if you wish to use WorldGuard with LWC."); } } }
Example #20
Source File: LWCServerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void onPluginDisable(PluginDisableEvent event) { if (!LWC.ENABLED) { return; } Plugin disabled = event.getPlugin(); // Removes any modules registered by the disabled plugin plugin.getLWC().getModuleLoader().removeModules(disabled); }
Example #21
Source File: BaseModeModule.java From Modern-LWC with MIT License | 5 votes |
@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 #22
Source File: DropTransferModule.java From Modern-LWC with MIT License | 5 votes |
@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 #23
Source File: BaseAdminModule.java From Modern-LWC with MIT License | 5 votes |
@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 #24
Source File: PhysDB.java From Modern-LWC with MIT License | 5 votes |
/** * Load all of the history at the given location * * @param player * @param x * @param y * @param z * @return */ public List<History> loadHistory(String player, int x, int y, int z) { List<History> temp = new ArrayList<History>(); if (!LWC.getInstance().isHistoryEnabled()) { return temp; } UUID uuid = UUIDRegistry.getUUID(player); if (uuid != null) { player = uuid.toString(); } try { PreparedStatement statement = prepare( "SELECT * FROM " + prefix + "history WHERE LOWER(player) = LOWER(?) AND x = ? AND y = ? AND z = ?"); statement.setString(1, player); statement.setInt(2, x); statement.setInt(3, y); statement.setInt(4, z); ResultSet set = statement.executeQuery(); while (set.next()) { History history = resolveHistory(new History(), set); if (history != null) { // seems ok temp.add(history); } } set.close(); } catch (SQLException e) { printException(e); } return temp; }
Example #25
Source File: PhysDB.java From Modern-LWC with MIT License | 5 votes |
/** * Load all protection history * * @return */ public List<History> loadHistory() { List<History> temp = new ArrayList<History>(); if (!LWC.getInstance().isHistoryEnabled()) { return temp; } try { PreparedStatement statement = prepare("SELECT * FROM " + prefix + "history ORDER BY id DESC"); ResultSet set = statement.executeQuery(); while (set.next()) { History history = resolveHistory(new History(), set); if (history != null) { // seems ok temp.add(history); } } set.close(); } catch (SQLException e) { printException(e); } return temp; }
Example #26
Source File: VaultPermissions.java From Modern-LWC with MIT License | 5 votes |
@Override public List<String> getGroups(Player player) { RegisteredServiceProvider<Permission> serviceProvider = Bukkit.getServer().getServicesManager() .getRegistration(Permission.class); groupPrefix = LWC.getInstance().getConfiguration().getString("core.groupPrefix", "group."); if (serviceProvider == null) { return super.getGroups(player); } Permission perm = serviceProvider.getProvider(); try { // the player's groups String[] groups = perm.getPlayerGroups(player); // fallback to superperms if it appears that they have no groups if (groups == null || groups.length == 0) { return super.getGroups(player); } List<String> groupss = Arrays.asList(groups); for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) { if (pai.getPermission().startsWith(groupPrefix)) { groupss.add(pai.getPermission().substring(groupPrefix.length())); } } return groupss; } catch (UnsupportedOperationException e) { // Can be thrown by vault or asList. Thrown by Vault when using SuperPerms - // getPlayerGroups() will throw it :-( return super.getGroups(player); } }
Example #27
Source File: FreeModule.java From Modern-LWC with MIT License | 5 votes |
@Override public void onBlockInteract(LWCBlockInteractEvent event) { if (!event.hasAction("free")) { 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); }
Example #28
Source File: ConfigUpdater.java From Modern-LWC with MIT License | 5 votes |
/** * Load the reference config files in the local jar file. The key in the map is the * file name * * @return */ @SuppressWarnings("resource") private Map<String, Configuration> loadReferenceConfigFiles() throws IOException { if (referenceConfigFileCache.size() > 0) { return referenceConfigFileCache; } // Load our jar file ZipFile jarFile = new ZipFile(URLDecoder.decode(LWC.getInstance().getPlugin().getFile().getPath(), "UTF-8")); // Begin loading the files Enumeration<? extends ZipEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { ZipEntry file = (ZipEntry) entries.nextElement(); String name = file.getName(); // We only want config dir if (!name.startsWith("config/") || !name.endsWith(".yml")) { continue; } // Get just the name String realName = name.substring(name.indexOf('/') + 1); // Insert it Configuration configuration = new Configuration(null); configuration.load(jarFile.getInputStream(file)); referenceConfigFileCache.put(realName, configuration); } return referenceConfigFileCache; }
Example #29
Source File: PhysDB.java From Modern-LWC with MIT License | 5 votes |
/** * Load all protection history that the given player created * * @param player * @return */ public List<History> loadHistory(String player) { List<History> temp = new ArrayList<History>(); if (!LWC.getInstance().isHistoryEnabled()) { return temp; } UUID uuid = UUIDRegistry.getUUID(player); if (uuid == null) { uuid = UUID.fromString(player); } if (uuid != null) { player = uuid.toString(); } try { statement = prepare("SELECT * FROM " + prefix + "history WHERE LOWER(player) = LOWER(?) ORDER BY id DESC"); statement.setString(1, player); ResultSet set = statement.executeQuery(); while (set.next()) { History history = resolveHistory(new History(), set); if (history != null) { // seems ok temp.add(history); } } set.close(); } catch (SQLException e) { printException(e); } return temp; }
Example #30
Source File: LimitsV2.java From Modern-LWC with MIT License | 5 votes |
@Override public int getProtectionCount(Player player, Material material) { LWC lwc = LWC.getInstance(); BlockCache blockCache = BlockCache.getInstance(); int signCount = 0; for (Material sign : SIGNS) { signCount += lwc.getPhysicalDatabase().getProtectionCount(player.getName(), blockCache.getBlockId(sign)); } return signCount; }