コード例 #1
0
  @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()));
      }
    }
  }
コード例 #2
0
 @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());
   }
 }
コード例 #3
0
	@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);
			}
		}
	}
コード例 #4
0
 @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);
   }
 }
コード例 #5
0
 @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();
 }
コード例 #6
0
  @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);
  }