public void onPlayerRespawn(final PlayerRespawnEvent event)
	{
		final User user = ess.getUser(event.getPlayer());

		if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
		{
			return;
		}

		if (ess.getSettings().getRespawnAtHome())
		{
			Location home;
			final Location bed = user.getBedSpawnLocation();
			if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
			{
				home = bed;
			}
			else
			{
				home = user.getHome(user.getLocation());
			}
			if (home != null)
			{
				event.setRespawnLocation(home);
				return;
			}
		}
		final Location spawn = spawns.getSpawn(user.getGroup());
		if (spawn != null)
		{
			event.setRespawnLocation(spawn);
		}
	}
 @Override
 public void onPlayerRespawn(final PlayerRespawnEvent event) {
   final User user = ess.getUser(event.getPlayer());
   user.setDisplayName(user.getNick());
   updateCompass(user);
   if (ess.getSettings().changeDisplayName()) {
     user.setDisplayName(user.getNick());
   }
 }
	@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
	public void onEntityRegainHealth(final EntityRegainHealthEvent event)
	{
		if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player
			&& ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers())
		{
			event.setCancelled(true);
		}
	}
 @Override
 public void onPlayerTeleport(PlayerTeleportEvent event) {
   if (event.isCancelled()) {
     return;
   }
   final User user = ess.getUser(event.getPlayer());
   if (ess.getSettings().changeDisplayName()) {
     user.setDisplayName(user.getNick());
   }
   updateCompass(user);
 }
Example #5
0
		@EventHandler(priority = EventPriority.LOW)
		public void onWorldUnload(final WorldUnloadEvent event)
		{
			ess.getJails().onReload();
			ess.getWarps().reloadConfig();
			for (IConf iConf : ((Essentials)ess).confList)
			{
				if (iConf instanceof IEssentialsModule)
				{
					iConf.reloadConfig();
				}
			}
		}
 @Override
 public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) {
   final User user = ess.getUser(event.getPlayer());
   if (user.hasUnlimited(new ItemStack(event.getBucket()))) {
     event.getItemStack().setType(event.getBucket());
     ess.scheduleSyncDelayedTask(
         new Runnable() {
           public void run() {
             user.updateInventory();
           }
         });
   }
 }
	@EventHandler(priority = EventPriority.LOWEST)
	public void onPlayerDeathEvent(final PlayerDeathEvent event)
	{
		final User user = ess.getUser(event.getEntity());
		if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back"))
		{
			user.setLastLocation();
			user.sendMessage(_("backAfterDeath"));
		}
		if (!ess.getSettings().areDeathMessagesEnabled())
		{
			event.setDeathMessage("");
		}
	}
  private void usePowertools(final PlayerAnimationEvent event) {
    if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
      return;
    }
    final User user = ess.getUser(event.getPlayer());
    final ItemStack is = user.getItemInHand();
    if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) {
      return;
    }
    final List<String> commandList = user.getPowertool(is);
    if (commandList == null || commandList.isEmpty()) {
      return;
    }

    // We need to loop through each command and execute
    for (String command : commandList) {
      if (command.matches(".*\\{player\\}.*")) {
        // user.sendMessage("Click a player to use this command");
        continue;
      } else if (command.startsWith("c:")) {
        for (Player p : server.getOnlinePlayers()) {
          p.sendMessage(user.getDisplayName() + ":" + command.substring(2));
        }
      } else {
        user.getServer().dispatchCommand(event.getPlayer(), command);
      }
    }
  }
	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);
	}
	@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
	public void onEntityCombust(final EntityCombustEvent event)
	{
		if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
		{
			event.setCancelled(true);
		}
	}
 @Override
 public void onPlayerEggThrow(final PlayerEggThrowEvent event) {
   final User user = ess.getUser(event.getPlayer());
   final ItemStack is = new ItemStack(Material.EGG, 1);
   if (user.hasUnlimited(is)) {
     user.getInventory().addItem(is);
     user.updateInventory();
   }
 }
	@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);
		}
	}
Example #14
0
	@Deprecated
	public boolean isIgnoredPlayer(final String userName)
	{
		final IUser user = ess.getUser(userName);
		if (user == null || !user.isOnline())
		{
			return false;
		}
		return isIgnoredPlayer(user);
	}
  @Override
  public void onPlayerInteract(final PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
      return;
    }

    if (ess.getSettings().getBedSetsHome()
        && event.getClickedBlock().getType() == Material.BED_BLOCK) {
      try {
        final User user = ess.getUser(event.getPlayer());
        user.setHome();
        user.sendMessage(Util.i18n("homeSetToBed"));
      } catch (Throwable ex) {
      }
    }
  }
	@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
	public void onEntityDamage(final EntityDamageEvent event)
	{
		if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
		{
			final Player player = (Player)event.getEntity();
			player.setFireTicks(0);
			player.setRemainingAir(player.getMaximumAir());
			event.setCancelled(true);
		}
	}
Example #17
0
	private BigDecimal _getMoney()
	{
		BigDecimal result = ess.getSettings().getStartingBalance();
		BigDecimal maxMoney = ess.getSettings().getMaxMoney();
		BigDecimal minMoney = ess.getSettings().getMinMoney();

		if (config.hasProperty("money"))
		{
			result = config.getBigDecimal("money", result);
		}
		if (result.compareTo(maxMoney) > 0)
		{
			result = maxMoney;
		}
		if (result.compareTo(minMoney) < 0)
		{
			result = minMoney;
		}
		return result;
	}
 @Override
 public void onPlayerChat(final PlayerChatEvent event) {
   final User user = ess.getUser(event.getPlayer());
   if (user.isMuted()) {
     event.setCancelled(true);
     user.sendMessage(Util.i18n("playerMuted"));
     LOGGER.info(Util.format("mutedUserSpeaks", user.getName()));
   }
   final Iterator<Player> it = event.getRecipients().iterator();
   while (it.hasNext()) {
     final User u = ess.getUser(it.next());
     if (u.isIgnoredPlayer(user.getName())) {
       it.remove();
     }
   }
   user.updateActivity(true);
   if (ess.getSettings().changeDisplayName()) {
     user.setDisplayName(user.getNick());
   }
 }
Example #19
0
	protected UserData(Player base, IEssentials ess)
	{
		super(base);
		this.ess = ess;
		folder = new File(ess.getDataFolder(), "userdata");
		if (!folder.exists())
		{
			folder.mkdirs();
		}
		config = new EssentialsConf(new File(folder, StringUtil.sanitizeFileName(base.getName()) + ".yml"));
		reloadConfig();
	}
  @Override
  public void onPlayerJoin(final PlayerJoinEvent event) {
    ess.getBackup().onPlayerJoin();
    final User user = ess.getUser(event.getPlayer());

    if (ess.getSettings().changeDisplayName()) {
      user.setDisplayName(user.getNick());
    }
    user.updateActivity(false);
    if (user.isAuthorized("essentials.sleepingignored")) {
      user.setSleepingIgnored(true);
    }

    if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) {
      for (String m : ess.getMotd(user, null)) {
        if (m == null) {
          continue;
        }
        user.sendMessage(m);
      }
    }

    if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
      final List<String> mail = user.getMails();
      if (mail.isEmpty()) {
        user.sendMessage(Util.i18n("noNewMail"));
      } else {
        user.sendMessage(Util.format("youHaveNewMail", mail.size()));
      }
    }
  }
	@EventHandler(priority = EventPriority.LOWEST)
	public void onEntityDamage(final EntityDamageByEntityEvent event)
	{
		final Entity eAttack = event.getDamager();
		final Entity eDefend = event.getEntity();
		if (eDefend instanceof Player && eAttack instanceof Player)
		{
			final User defender = ess.getUser(eDefend);
			final User attacker = ess.getUser(eAttack);
			attacker.updateActivity(true);
			final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
			if (commandList != null && !commandList.isEmpty())
			{
				for (String command : commandList)
				{
					if (command != null && !command.isEmpty())
					{
						attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
						event.setCancelled(true);
						return;
					}
				}
			}
		}
		else if (eDefend instanceof Animals && eAttack instanceof Player)
		{
			final User player = ess.getUser(eAttack);
			final ItemStack hand = player.getItemInHand();
			if (hand != null && hand.getType() == Material.MILK_BUCKET)
			{
				((Animals)eDefend).setAge(-24000);
				hand.setType(Material.BUCKET);
				player.setItemInHand(hand);
				player.updateInventory();
				event.setCancelled(true);
			}
		}
	}
 @Override
 public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
   if (event.isCancelled()) {
     return;
   }
   final User user = ess.getUser(event.getPlayer());
   final String cmd =
       event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase();
   final List<String> commands =
       Arrays.asList(
           "msg", "r", "mail", "m", "t", "emsg", "tell", "er", "reply", "ereply", "email");
   if (commands.contains(cmd)) {
     for (Player player : ess.getServer().getOnlinePlayers()) {
       User spyer = ess.getUser(player);
       if (spyer.isSocialSpyEnabled() && !user.equals(spyer)) {
         player.sendMessage(user.getDisplayName() + " : " + event.getMessage());
       }
     }
   }
   if (!cmd.equalsIgnoreCase("afk")) {
     user.updateActivity(true);
   }
 }
 @Override
 public void onPlayerQuit(final PlayerQuitEvent event) {
   final User user = ess.getUser(event.getPlayer());
   if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) {
     user.toggleGodModeEnabled();
   }
   if (user.getSavedInventory() != null) {
     user.getInventory().setContents(user.getSavedInventory());
     user.setSavedInventory(null);
   }
   user.updateActivity(false);
   user.dispose();
   if (!ess.getSettings().getReclaimSetting()) {
     return;
   }
   final Thread thread =
       new Thread(
           new Runnable() {
             public void run() {
               try {
                 Thread.sleep(1000);
                 Runtime rt = Runtime.getRuntime();
                 double mem = rt.freeMemory();
                 rt.runFinalization();
                 rt.gc();
                 mem = rt.freeMemory() - mem;
                 mem /= 1024 * 1024;
                 LOGGER.log(Level.INFO, Util.format("freedMemory", mem));
               } catch (InterruptedException ex) {
                 return;
               }
             }
           });
   thread.setPriority(Thread.MIN_PRIORITY);
   thread.start();
 }
	public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module, IEssentials ess)
	{
		this.classLoader = classLoader;
		this.commandPath = commandPath;
		this.permissionPrefix = permissionPrefix;
		this.module = module;
		this.ess = ess;
		for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
		{
			if (plugin.isEnabled())
			{
				addPlugin(plugin);
			}
		}
	}
Example #25
0
	public void setMoney(BigDecimal value)
	{
		money = value;
		BigDecimal maxMoney = ess.getSettings().getMaxMoney();
		BigDecimal minMoney = ess.getSettings().getMinMoney();
		if (money.compareTo(maxMoney) > 0)
		{
			money = maxMoney;
		}
		if (money.compareTo(minMoney) < 0)
		{
			money = minMoney;
		}
		config.setProperty("money", money);
		config.save();
	}
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		if (event.getPlayer().hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}

		final User user = ess.getUser(event.getPlayer());

		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
			final SimpleTextPager pager = new SimpleTextPager(output);
			ess.broadcastMessage(user, pager.getString(0));
		}

		final String kitName = ess.getSettings().getNewPlayerKit();
		if (!kitName.isEmpty())
		{
			try
			{
				final Map<String, Object> kit = ess.getSettings().getKit(kitName.toLowerCase(Locale.ENGLISH));
				final List<String> items = Kit.getItems(user, kit);
				Kit.expandItems(ess, user, items);
			}
			catch (Exception ex)
			{
				LOGGER.log(Level.WARNING, ex.getMessage());
			}
		}

		LOGGER.log(Level.FINE, "New player join");
	}
  @Override
  public void onPlayerLogin(final PlayerLoginEvent event) {
    if (event.getResult() != Result.ALLOWED
        && event.getResult() != Result.KICK_FULL
        && event.getResult() != Result.KICK_BANNED) {
      LOGGER.log(
          Level.INFO,
          "Disconnecting user "
              + event.getPlayer().toString()
              + " due to "
              + event.getResult().toString());
      return;
    }
    User user = ess.getUser(event.getPlayer());
    user.setNPC(false);

    final long currentTime = System.currentTimeMillis();
    boolean banExpired = user.checkBanTimeout(currentTime);
    user.checkMuteTimeout(currentTime);
    user.checkJailTimeout(currentTime);

    if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) {
      final String banReason = user.getBanReason();
      event.disallow(
          Result.KICK_BANNED,
          banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban")
              ? banReason
              : Util.i18n("defaultBanReason"));
      return;
    }

    if (server.getOnlinePlayers().length >= server.getMaxPlayers()
        && !user.isAuthorized("essentials.joinfullserver")) {
      event.disallow(Result.KICK_FULL, Util.i18n("serverFull"));
      return;
    }
    event.allow();

    user.setLastLogin(System.currentTimeMillis());
    updateCompass(user);
  }
Example #28
0
	//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 kiteItem : kits.getKeys(false))
			{
				if (user.isAuthorized("essentials.kit." + kiteItem.toLowerCase(Locale.ENGLISH)))
				{
					list.append(" ").append(capitalCase(kiteItem));
				}
			}
			return list.toString().trim();
		}
		catch (Exception ex)
		{
			throw new Exception(_("kitError"));
		}

	}
Example #29
0
 public OfflinePlayer(final String name, final IEssentials ess) {
   this.ess = ess;
   this.world = ess.getServer().getWorlds().get(0);
   this.base = ess.getServer().getOfflinePlayer(name);
 }
Example #30
0
 public Server getServer() {
   return ess == null ? null : ess.getServer();
 }