@Override public void run() { if (!active.compareAndSet(false, true)) { return; } final ISettings settings = ess.getSettings(); final net.ess3.settings.Backup backupSettings = settings.getData().getGeneral().getBackup(); String backupCommand = backupSettings.getCommand() == null || backupSettings.getCommand().isEmpty() ? ("NORUN") : backupSettings.getCommand(); /*if (backupCommand.equals("NORUN")) { TODO: Un-comment if you do not want commands to be run if there is no backup command return; }*/ ess.getLogger().log(Level.INFO, _("backupStarted")); if (!backupSettings.getCommandsBeforeBackup().isEmpty()) { final CommandSender consoleSender = server.getConsoleSender(); for (String command : backupSettings.getCommandsBeforeBackup()) { server.dispatchCommand(consoleSender, command); } } ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(backupCommand)); }
public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess) { final ISign sign = new EventSign(event); final IUser user = ess.getUserMap().getUser(event.getPlayer()); if (!SignsPermissions.CREATE.isAuthorized(user, signName)) { // Return true, so other plugins can use the same sign title, just hope // they won't change it to §1[Signname] return true; } sign.setLine(0, _("[{0}]", this.signName)); try { final boolean ret = onSignCreate(sign, user, getUsername(user), ess); if (ret) { sign.setLine(0, getSuccessName()); } return ret; } catch (ChargeException ex) { ess.getCommandHandler().showCommandError(user, signName, ex); } catch (SignException ex) { ess.getCommandHandler().showCommandError(user, signName, ex); } // Return true, so the player sees the wrong sign. return true; }
public void trackUUID(final UUID uuid, final String name, boolean replace) { if (uuid != null) { keys.add(uuid); if (name != null && name.length() > 0) { final String keyName = StringUtil.safeString(name); if (!names.containsKey(keyName)) { names.put(keyName, uuid); uuidMap.writeUUIDMap(); } else if (!names.get(keyName).equals(uuid)) { if (replace) { ess.getLogger() .info( "Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); names.put(keyName, uuid); uuidMap.writeUUIDMap(); } else { if (ess.getSettings().isDebug()) { ess.getLogger() .info( "Found old UUID for " + name + " (" + uuid.toString() + "). Not adding to usermap."); } } } } } }
public EssentialsPlayerListener(final IEssentials parent) { super(); this.ess = parent; userMap = ess.getUserMap(); this.server = parent.getServer(); }
@Override public void onEnable() { instance = this; final PluginManager pluginManager = getServer().getPluginManager(); final IPlugin plugin = (IPlugin)pluginManager.getPlugin("Essentials-3"); ess = plugin.getEssentials(); if (!this.getDescription().getVersion().equals(plugin.getDescription().getVersion())) { LOGGER.log(Level.WARNING, _("versionMismatchAll")); } if (!plugin.isEnabled()) { this.setEnabled(false); return; } final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess); pluginManager.registerEvents(playerListener, this); users = new UserManager(this.getDataFolder()); xmpp = new XMPPManager(this); ess.addReloadListener(users); ess.addReloadListener(xmpp); commandHandler = new EssentialsCommandHandler(EssentialsXMPP.class.getClassLoader(), "net.ess3.xmpp.Command", "essentials.", ess); }
public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess) { final IUser user = ess.getUserMap().getUser(player); try { return onBlockBreak(block, user, getUsername(user), ess); } catch (SignException ex) { ess.getCommandHandler().showCommandError(user, signName, ex); } return false; }
@EventHandler(priority = EventPriority.MONITOR) public void onPluginDisable(final PluginDisableEvent event) { if (event.getPlugin().getName().equals("EssentialsChat")) { ess.getSettings().setEssentialsChatActive(false); } ess.getAlternativeCommandsHandler().removePlugin(event.getPlugin()); // Check to see if the plugin thats being disabled is the one we are using if (ess.getPaymentMethod() != null && Methods.hasMethod() && Methods.checkDisabled(event.getPlugin())) { Methods.reset(); ess.getLogger().log(Level.INFO, "Payment method was disabled. No longer accepting payments."); } }
public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess) { final ISign sign = new BlockSign(block); final IUser user = ess.getUserMap().getUser(player); try { return SignsPermissions.BREAK.isAuthorized(user, signName) && onSignBreak(sign, user, getUsername(user), ess); } catch (SignException ex) { ess.getCommandHandler().showCommandError(user, signName, ex); return false; } }
@Override public final void startTask() { if (running.compareAndSet(false, true)) { final ISettings settings = ess.getSettings(); final long interval = settings.getData().getGeneral().getBackup().getInterval() * 1200; // minutes -> ticks if (interval < 1200) { running.set(false); return; } taskId = ess.getPlugin().scheduleSyncRepeatingTask(this, interval, interval); } }
private void loadAllUsersAsync(final IEssentials ess) { ess.runTaskAsynchronously( new Runnable() { @Override public void run() { synchronized (users) { final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { return; } keys.clear(); users.invalidateAll(); for (String string : userdir.list()) { if (!string.endsWith(".yml")) { continue; } final String name = string.substring(0, string.length() - 4); try { keys.add(UUID.fromString(name)); } catch (IllegalArgumentException ex) { // Ignore these users till they rejoin. } } uuidMap.loadAllUsers(names, history); } } }); }
// TODO: Convert this to use one of the new text classes? public static String listKits(final IEssentials ess, final User user) throws Exception { try { final ConfigurationSection kits = ess.getSettings().getKits(); final StringBuilder list = new StringBuilder(); for (String kitItem : kits.getKeys(false)) { if (user == null) { list.append(" ").append(capitalCase(kitItem)); } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) { String cost = ""; String name = capitalCase(kitItem); BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user); if (costPrice.signum() > 0) { cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess)); } Kit kit = new Kit(kitItem, ess); if (kit.getNextUse(user) != 0) { name = tl("kitDelay", name); } list.append(" ").append(name).append(cost); } } return list.toString().trim(); } catch (Exception ex) { throw new Exception(tl("kitError"), ex); } }
/** * Sets the balance of a user * * @param name Name of the user * @param balance The balance you want to set * @throws UserDoesNotExistException If a user by that name does not exists * @throws net.ess3.api.NoLoanPermittedException If the user is not allowed to have a negative * balance */ public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException { if (ess == null) { throw new RuntimeException(noCallBeforeLoad); } ess.getEconomy().setMoney(name, balance); }
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) { final ISettings settings = ess.getSettings(); final IUser user = userMap.getUser(event.getPlayer()); if (settings.getData().getChat().getChangeDisplayname()) { user.updateDisplayName(); } if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !Permissions.NOGOD_OVERRIDE.isAuthorized( user)) { if (user.getData().isGodmode()) { user.sendMessage(_("§4Warning! God mode in this world disabled.")); } } if (settings.getData().getCommands().getTeleport().isCancelRequestsOnWorldChange()) { if (user.getTeleportRequester() != null) { user.requestTeleport(null, false); user.sendMessage(_("teleportRequestsCancelledWorldChange")); } } if (settings.getData().getGeneral().isPtClearOnWorldChange()) { user.getData().clearAllPowertools(); user.queueSave(); user.sendMessage(_("§6All powertool commands have been cleared.")); } }
public static String shortCurrency(final double value, final IEssentials ess) { @Cleanup final ISettings settings = ess.getSettings(); settings.acquireReadLock(); return settings.getData().getEconomy().getCurrencySymbol() + formatAsCurrency(value); }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerInteract(final PlayerInteractEvent event) { final IUser user = userMap.getUser(event.getPlayer()); user.updateActivity(true); switch (event.getAction()) { case RIGHT_CLICK_BLOCK: if (event.isCancelled()) { return; } final ISettings settings = ess.getSettings(); if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK) { event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation()); } break; case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: if (user.getData().hasPowerTools() && user.getData().isPowerToolsEnabled()) { if (usePowertools(user)) { event.setCancelled(true); } } break; default: break; } }
/** * Resets the balance of a user to the starting balance * * @param name Name of the user * @throws UserDoesNotExistException If a user by that name does not exists * @throws NoLoanPermittedException If the user is not allowed to have a negative balance */ public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException { if (ess == null) { throw new RuntimeException(noCallBeforeLoad); } ess.getEconomy().resetBalance(name); }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent event) { final IUser user = userMap.getUser(event.getPlayer()); final ISettings settings = ess.getSettings(); if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers()) { final Location from = event.getFrom(); final Location to = event.getTo().clone(); to.setX(from.getX()); to.setY(from.getY()); to.setZ(from.getZ()); try { event.setTo(LocationUtil.getSafeDestination(to)); } catch (Exception ex) { event.setTo(to); } return; } final Location afk = user.getAfkPosition(); if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) { user.updateActivity(true); } }
public final void addPlugin(final Plugin plugin) { if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) { return; } final List<Command> commands = PluginCommandYamlParser.parse(plugin); final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH); for (Command command : commands) { final PluginCommand pc = (PluginCommand)command; final List<String> labels = new ArrayList<String>(pc.getAliases()); labels.add(pc.getName()); PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH)); if (reg == null) { reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH)); } if (reg == null || !reg.getPlugin().equals(plugin)) { continue; } for (String label : labels) { List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH)); if (plugincommands == null) { plugincommands = new ArrayList<PluginCommand>(); altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands); } boolean found = false; for (PluginCommand pc2 : plugincommands) { if (pc2.getPlugin().equals(plugin)) { found = true; } } if (!found) { plugincommands.add(reg); } } } }
public void executed(final String label, final String otherLabel) { if (ess.getSettings().isDebug()) { LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + otherLabel); } disabledList.put(label, otherLabel); }
public Backup(final IEssentials ess) { this.ess = ess; server = ess.getServer(); if (!server.getOnlinePlayers().isEmpty()) { startTask(); } }
public Backup(final IEssentials ess) { this.ess = ess; server = ess.getServer(); if (server.getOnlinePlayers().length > 0) { startTask(); } }
@Override public void showCommandError(final CommandSender sender, final String commandLabel, final Throwable exception) { sender.sendMessage(_("errorWithMessage", exception.getMessage())); if (ess.getSettings().isDebug()) { LOGGER.log(Level.WARNING, _("errorCallingCommand", commandLabel), exception); } }
public Kit(final String kitName, final IEssentials ess) throws Exception { this.kitName = kitName; this.ess = ess; this.kit = ess.getSettings().getKit(kitName); this.charge = new Trade("kit-" + kitName, new Trade("kit-kit", ess), ess); if (kit == null) { throw new Exception(tl("kitNotFound")); } }
public User getUser(final String name) { try { final String sanitizedName = StringUtil.safeString(name); if (names.containsKey(sanitizedName)) { final UUID uuid = names.get(sanitizedName); return getUser(uuid); } final File userFile = getUserFileFromString(sanitizedName); if (userFile.exists()) { ess.getLogger().info("Importing user " + name + " to usermap."); User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); trackUUID(user.getBase().getUniqueId(), user.getName(), true); return user; } return null; } catch (UncheckedExecutionException ex) { return null; } }
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(final PlayerQuitEvent event) { final String quitMessage = ess.getSettings().getData().getGeneral().getLeaveMessage(); if (quitMessage != null) { final IText itOutput = new KeywordReplacer(new SimpleTextInput(quitMessage), userMap.getUser(event.getPlayer()), ess); final SimpleTextPager stPager = new SimpleTextPager(itOutput); event.setQuitMessage(FormatUtil.replaceFormat(stPager.getString(0))); } else { event.setQuitMessage(null); } final IUser user = userMap.getUser(event.getPlayer()); final ISettings settings = ess.getSettings(); if (settings.getData().getCommands().getGod().isRemoveOnDisconnect() && user.isGodModeEnabled()) { user.setGodModeEnabled(false); } if (user.isVanished()) { user.toggleVanished(); } if (user.getData().getInventory() != null) { user.getPlayer().getInventory().setContents(user.getData().getInventory().getBukkitInventory()); user.getData().setInventory(null); } user.updateActivity(false); //user.getPlayer().dispose(); if (settings.getData().getGeneral().isPtClearOnQuit()) { user.getData().clearAllPowertools(); user.queueSave(); user.sendMessage(_("§6All powertool commands have been cleared.")); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { final IUser user = userMap.getUser(event.getPlayer()); final String cmd = spaceSplit.split(event.getMessage().toLowerCase(Locale.ENGLISH))[0].replace("/", "").toLowerCase(Locale.ENGLISH); if (ess.getSettings().getData().getCommands().getSocialspy().getSocialspyCommands().contains(cmd)) { for (Player player : ess.getServer().getOnlinePlayers()) { IUser spyer = userMap.getUser(player); if (spyer.getData().isSocialspy() && !user.equals(spyer)) { player.sendMessage(user.getPlayer().getDisplayName() + " : " + event.getMessage()); } } } if (!cmd.equalsIgnoreCase("afk")) { user.updateActivity(true); } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerTeleport(final PlayerTeleportEvent event) { final ISettings settings = ess.getSettings(); //There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports. if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && settings.getData().getCommands().getBack().isRegisterBackInListener()) { final IUser user = userMap.getUser(event.getPlayer()); user.setLastLocation(); } }
@Override public void run() { if (!active.compareAndSet(false, true)) { return; } @Cleanup final ISettings settings = ess.getSettings(); settings.acquireReadLock(); final String command = settings.getData().getGeneral().getBackup().getCommand(); if (command == null || command.isEmpty()) { return; } ess.getLogger().log(Level.INFO, _("backupStarted")); final CommandSender consoleSender = server.getConsoleSender(); server.dispatchCommand(consoleSender, "save-all"); server.dispatchCommand(consoleSender, "save-off"); ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(command)); }
protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException { try { final ItemStack item = ess.getItemDb().get(itemName); item.setAmount(quantity); return item; } catch (Exception ex) { throw new SignException(ex.getMessage(), ex); } }
public UserMap(final IEssentials ess) { super(); this.ess = ess; uuidMap = new UUIDMap(ess); // RemovalListener<UUID, User> remListener = new UserMapRemovalListener(); // users = // CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().removalListener(remListener).build(this); users = CacheBuilder.newBuilder() .maximumSize(ess.getSettings().getMaxUserCacheCount()) .softValues() .build(this); }