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 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 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, ignoreCancelled = true)
	public void onEntityCombust(final EntityCombustEvent event)
	{
		if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
		{
			event.setCancelled(true);
		}
	}
 @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 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();
   }
 }
Exemple #8
0
	@Deprecated
	public boolean isIgnoredPlayer(final String userName)
	{
		final IUser user = ess.getUser(userName);
		if (user == null || !user.isOnline())
		{
			return false;
		}
		return isIgnoredPlayer(user);
	}
	@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);
		}
	}
 @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);
 }
 @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());
   }
 }
 @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 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);
			}
		}
	}
	@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("");
		}
	}
 @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 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) {
      }
    }
  }
  @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);
  }
	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 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();
 }
  @Override
  public void onPlayerMove(final PlayerMoveEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final User user = ess.getUser(event.getPlayer());

    if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) {
      final Location from = event.getFrom();
      final Location to = event.getTo().clone();
      to.setX(from.getX());
      to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY());
      to.setZ(from.getZ());
      event.setTo(to);
      return;
    }

    Location afk = user.getAfkPosition();
    if (afk == null
        || !event.getTo().getWorld().equals(afk.getWorld())
        || afk.distanceSquared(event.getTo()) > 9) {
      user.updateActivity(true);
    }

    if (!ess.getSettings().getNetherPortalsEnabled()) {
      return;
    }

    final Block block =
        event
            .getPlayer()
            .getWorld()
            .getBlockAt(
                event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
    final List<World> worlds = server.getWorlds();

    if (block.getType() == Material.PORTAL
        && worlds.size() > 1
        && user.isAuthorized("essentials.portal")) {
      if (user.getJustPortaled()) {
        return;
      }

      World nether = server.getWorld(ess.getSettings().getNetherName());
      if (nether == null) {
        for (World world : worlds) {
          if (world.getEnvironment() == World.Environment.NETHER) {
            nether = world;
            break;
          }
        }
        if (nether == null) {
          return;
        }
      }
      final World world = user.getWorld() == nether ? worlds.get(0) : nether;

      double factor;
      if (user.getWorld().getEnvironment() == World.Environment.NETHER
          && world.getEnvironment() == World.Environment.NORMAL) {
        factor = ess.getSettings().getNetherRatio();
      } else if (user.getWorld().getEnvironment() == World.Environment.NORMAL
          && world.getEnvironment() == World.Environment.NETHER) {
        factor = 1.0 / ess.getSettings().getNetherRatio();
      } else {
        factor = 1.0;
      }

      Location loc = event.getTo();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();

      if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) {
        z--;
      }
      if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) {
        x--;
      }

      x = (int) (x * factor);
      z = (int) (z * factor);
      loc = new Location(world, x + .5, y, z + .5);

      Block dest = world.getBlockAt(x, y, z);
      NetherPortal portal = NetherPortal.findPortal(dest);
      if (portal == null) {
        if (world.getEnvironment() == World.Environment.NETHER
            || ess.getSettings().getGenerateExitPortals()) {
          portal = NetherPortal.createPortal(dest);
          LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
          user.sendMessage(Util.i18n("generatingPortal"));
          loc = portal.getSpawn();
        }
      } else {
        LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
        user.sendMessage(Util.i18n("usingPortal"));
        loc = portal.getSpawn();
      }

      event.setFrom(loc);
      event.setTo(loc);
      try {
        user.getTeleport().now(loc, new Trade("portal", ess));
      } catch (Exception ex) {
        user.sendMessage(ex.getMessage());
      }
      user.setJustPortaled(true);
      user.sendMessage(Util.i18n("teleportingPortal"));

      event.setCancelled(true);
      return;
    }

    user.setJustPortaled(false);
  }