2011-09-28 23:38:56 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-12-01 13:42:39 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-11-18 03:18:03 +00:00
|
|
|
import com.earth2me.essentials.textreader.IText;
|
|
|
|
import com.earth2me.essentials.textreader.KeywordReplacer;
|
|
|
|
import com.earth2me.essentials.textreader.TextInput;
|
|
|
|
import com.earth2me.essentials.textreader.TextPager;
|
|
|
|
import java.io.IOException;
|
2011-09-28 23:38:56 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-09-28 23:38:56 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2012-09-10 00:13:30 +00:00
|
|
|
import org.bukkit.GameMode;
|
2011-09-28 23:38:56 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2013-01-01 22:00:53 +00:00
|
|
|
import org.bukkit.World;
|
2012-06-03 15:34:27 +00:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
2011-09-28 23:38:56 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2012-01-20 04:20:37 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2012-03-25 01:33:52 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryType;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.event.player.*;
|
2012-11-11 16:43:10 +00:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
2011-12-06 22:56:38 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2013-01-01 18:39:23 +00:00
|
|
|
import org.bukkit.inventory.Inventory;
|
2012-06-03 15:34:27 +00:00
|
|
|
import org.bukkit.inventory.InventoryHolder;
|
2011-09-28 23:38:56 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
public class EssentialsPlayerListener implements Listener
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
|
|
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
|
|
|
private final transient IEssentials ess;
|
2012-04-15 22:13:34 +00:00
|
|
|
private static final int AIR = Material.AIR.getId();
|
|
|
|
private static final int BED = Material.BED_BLOCK.getId();
|
2011-09-28 23:38:56 +00:00
|
|
|
|
|
|
|
public EssentialsPlayerListener(final IEssentials parent)
|
|
|
|
{
|
|
|
|
this.ess = parent;
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerRespawn(final PlayerRespawnEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
updateCompass(user);
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2012-08-04 08:25:54 +00:00
|
|
|
public void onPlayerChat(final AsyncPlayerChatEvent event)
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.isMuted())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("playerMuted"));
|
|
|
|
LOGGER.info(_("mutedUserSpeaks", user.getName()));
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
final Iterator<Player> it = event.getRecipients().iterator();
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
final User u = ess.getUser(it.next());
|
2012-06-16 15:22:51 +00:00
|
|
|
if (u.isIgnoredPlayer(user))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.updateActivity(true);
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerMove(final PlayerMoveEvent event)
|
|
|
|
{
|
2012-12-31 05:44:20 +00:00
|
|
|
if (!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
|
|
|
{
|
2012-12-31 12:15:51 +00:00
|
|
|
event.getHandlers().unregister(this);
|
2012-12-31 05:44:20 +00:00
|
|
|
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.INFO, "Unregistering move listener");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
|
|
|
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
|
|
|
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
2012-03-25 15:30:22 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:38:56 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-04-26 08:41:24 +00:00
|
|
|
if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers())
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-04-26 08:41:24 +00:00
|
|
|
final Location from = event.getFrom();
|
2012-08-28 01:50:59 +00:00
|
|
|
final Location origTo = event.getTo();
|
|
|
|
final Location to = origTo.clone();
|
2012-08-30 23:47:53 +00:00
|
|
|
if (ess.getSettings().cancelAfkOnMove() && origTo.getY() >= from.getBlockY() + 1)
|
|
|
|
{
|
2012-08-28 01:50:59 +00:00
|
|
|
user.updateActivity(true);
|
|
|
|
return;
|
|
|
|
}
|
2012-04-26 08:41:24 +00:00
|
|
|
to.setX(from.getX());
|
|
|
|
to.setY(from.getY());
|
|
|
|
to.setZ(from.getZ());
|
|
|
|
try
|
2011-10-09 21:45:46 +00:00
|
|
|
{
|
2012-04-26 08:41:24 +00:00
|
|
|
event.setTo(Util.getSafeDestination(to));
|
2011-10-09 21:45:46 +00:00
|
|
|
}
|
2012-04-26 08:41:24 +00:00
|
|
|
catch (Exception ex)
|
2011-10-09 21:45:46 +00:00
|
|
|
{
|
2012-04-26 08:41:24 +00:00
|
|
|
event.setTo(to);
|
2011-10-09 21:45:46 +00:00
|
|
|
}
|
2012-04-26 08:41:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Location afk = user.getAfkPosition();
|
|
|
|
if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9)
|
|
|
|
{
|
|
|
|
user.updateActivity(true);
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerQuit(final PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
|
|
|
|
{
|
2012-06-10 18:20:24 +00:00
|
|
|
user.setGodModeEnabled(false);
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
2012-06-10 23:17:19 +00:00
|
|
|
if (user.isVanished())
|
|
|
|
{
|
|
|
|
user.toggleVanished();
|
|
|
|
}
|
2013-02-08 20:22:35 +00:00
|
|
|
user.setLogoutLocation();
|
2012-12-29 06:55:48 +00:00
|
|
|
if (user.isRecipeSee())
|
|
|
|
{
|
|
|
|
user.getPlayer().getOpenInventory().getTopInventory().clear();
|
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
user.updateActivity(false);
|
|
|
|
user.dispose();
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerJoin(final PlayerJoinEvent event)
|
|
|
|
{
|
2013-01-31 19:16:09 +00:00
|
|
|
ess.runTaskAsynchronously(new Runnable()
|
2012-04-06 18:19:08 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
delayedJoin(event.getPlayer());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-03-25 16:27:06 +00:00
|
|
|
|
2012-04-06 18:19:08 +00:00
|
|
|
public void delayedJoin(final Player player)
|
|
|
|
{
|
2012-06-16 16:31:33 +00:00
|
|
|
if (!player.isOnline())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-04-06 18:19:08 +00:00
|
|
|
ess.getBackup().onPlayerJoin();
|
|
|
|
final User user = ess.getUser(player);
|
2012-03-25 16:27:06 +00:00
|
|
|
user.setLastLogin(System.currentTimeMillis());
|
2011-09-28 23:38:56 +00:00
|
|
|
user.updateActivity(false);
|
2013-01-29 23:51:42 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
ess.scheduleSyncDelayedTask(new Runnable()
|
2012-05-21 05:13:01 +00:00
|
|
|
{
|
2013-01-29 23:26:50 +00:00
|
|
|
@Override
|
|
|
|
public void run()
|
2012-05-21 05:13:01 +00:00
|
|
|
{
|
2013-01-29 23:51:42 +00:00
|
|
|
user.setDisplayNick();
|
|
|
|
updateCompass(user);
|
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see"))
|
2012-11-08 07:57:44 +00:00
|
|
|
{
|
2013-01-29 23:26:50 +00:00
|
|
|
for (String p : ess.getVanishedPlayers())
|
|
|
|
{
|
|
|
|
Player toVanish = ess.getServer().getPlayerExact(p);
|
|
|
|
if (toVanish != null && toVanish.isOnline())
|
|
|
|
{
|
|
|
|
user.hidePlayer(toVanish);
|
|
|
|
}
|
|
|
|
}
|
2012-09-09 19:13:03 +00:00
|
|
|
}
|
2012-05-21 05:13:01 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (user.isAuthorized("essentials.sleepingignored"))
|
2012-11-08 07:57:44 +00:00
|
|
|
{
|
|
|
|
user.setSleepingIgnored(true);
|
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
2011-11-27 08:07:15 +00:00
|
|
|
{
|
2013-01-29 23:26:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
final IText input = new TextInput(user, "motd", true, ess);
|
|
|
|
final IText output = new KeywordReplacer(input, user, ess);
|
|
|
|
final TextPager pager = new TextPager(output, true);
|
|
|
|
pager.showPage("1", null, "motd", user);
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2011-11-27 08:07:15 +00:00
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
2012-11-04 21:34:47 +00:00
|
|
|
{
|
2013-01-29 23:26:50 +00:00
|
|
|
final List<String> mail = user.getMails();
|
|
|
|
if (mail.isEmpty())
|
|
|
|
{
|
|
|
|
final String msg = _("noNewMail");
|
|
|
|
if (!msg.isEmpty())
|
|
|
|
{
|
|
|
|
user.sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.sendMessage(_("youHaveNewMail", mail.size()));
|
|
|
|
}
|
2012-11-04 21:34:47 +00:00
|
|
|
}
|
2013-01-29 23:51:42 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (user.isAuthorized("essentials.fly.safelogin"))
|
|
|
|
{
|
|
|
|
final World world = user.getLocation().getWorld();
|
|
|
|
final int x = user.getLocation().getBlockX();
|
|
|
|
int y = user.getLocation().getBlockY();
|
|
|
|
final int z = user.getLocation().getBlockZ();
|
|
|
|
while (Util.isBlockUnsafe(world, x, y, z) && y > -1)
|
|
|
|
{
|
|
|
|
y--;
|
|
|
|
}
|
2013-01-01 22:00:53 +00:00
|
|
|
|
2013-01-29 23:26:50 +00:00
|
|
|
if (user.getLocation().getBlockY() - y > 1 || y < 0)
|
|
|
|
{
|
|
|
|
user.setAllowFlight(true);
|
|
|
|
user.setFlying(true);
|
|
|
|
user.sendMessage(_("flyMode", _("enabled"), user.getDisplayName()));
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 22:00:53 +00:00
|
|
|
}
|
2013-01-29 23:26:50 +00:00
|
|
|
});
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 10:27:01 +00:00
|
|
|
// Makes the compass item ingame always point to the first essentials home. #EasterEgg
|
2012-04-06 18:19:08 +00:00
|
|
|
private void updateCompass(final User user)
|
|
|
|
{
|
|
|
|
Location loc = user.getHome(user.getLocation());
|
|
|
|
if (loc == null)
|
|
|
|
{
|
|
|
|
loc = user.getBedSpawnLocation();
|
|
|
|
}
|
|
|
|
if (loc != null)
|
|
|
|
{
|
|
|
|
final Location updateLoc = loc;
|
2013-01-29 23:51:42 +00:00
|
|
|
user.setCompassTarget(updateLoc);
|
2012-04-06 18:19:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerLogin(final PlayerLoginEvent event)
|
|
|
|
{
|
2012-03-03 05:27:02 +00:00
|
|
|
switch (event.getResult())
|
|
|
|
{
|
2012-03-03 05:09:03 +00:00
|
|
|
case ALLOWED:
|
|
|
|
case KICK_FULL:
|
2012-03-03 05:27:02 +00:00
|
|
|
case KICK_BANNED:
|
2012-03-03 05:09:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-03-03 05:27:02 +00:00
|
|
|
return;
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
2012-03-03 05:27:02 +00:00
|
|
|
|
2012-04-14 05:07:10 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-03-25 16:27:06 +00:00
|
|
|
if (user.isNPC())
|
|
|
|
{
|
|
|
|
user.setNPC(false);
|
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
|
|
|
|
final long currentTime = System.currentTimeMillis();
|
2011-11-04 15:28:51 +00:00
|
|
|
final boolean banExpired = user.checkBanTimeout(currentTime);
|
2011-09-28 23:38:56 +00:00
|
|
|
user.checkMuteTimeout(currentTime);
|
|
|
|
user.checkJailTimeout(currentTime);
|
|
|
|
|
2012-03-03 05:27:02 +00:00
|
|
|
if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2013-01-09 20:59:27 +00:00
|
|
|
String banReason = user.getBanReason();
|
|
|
|
if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban"))
|
|
|
|
{
|
|
|
|
banReason = _("defaultBanReason");
|
|
|
|
}
|
|
|
|
if (user.getBanTimeout() > 0)
|
|
|
|
{
|
|
|
|
//TODO: TL This
|
|
|
|
banReason += "\n\n" + "Expires in " + Util.formatDateDiff(user.getBanTimeout());
|
|
|
|
}
|
|
|
|
event.disallow(Result.KICK_BANNED, banReason);
|
2011-09-28 23:38:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-25 15:46:36 +00:00
|
|
|
if (event.getResult() == Result.KICK_FULL && !user.isAuthorized("essentials.joinfullserver"))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
event.disallow(Result.KICK_FULL, _("serverFull"));
|
2011-09-28 23:38:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.allow();
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2012-01-20 04:20:37 +00:00
|
|
|
public void onPlayerTeleport(final PlayerTeleportEvent event)
|
2011-12-07 11:10:41 +00:00
|
|
|
{
|
2012-04-14 05:07:10 +00:00
|
|
|
final boolean backListener = ess.getSettings().registerBackInListener();
|
|
|
|
final boolean teleportInvulnerability = ess.getSettings().isTeleportInvulnerability();
|
2012-03-30 20:44:14 +00:00
|
|
|
if (backListener || teleportInvulnerability)
|
2011-12-06 22:56:38 +00:00
|
|
|
{
|
2012-03-30 20:44:14 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
|
|
|
|
if (backListener && (event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND))
|
|
|
|
{
|
|
|
|
user.setLastLocation();
|
|
|
|
}
|
|
|
|
if (teleportInvulnerability)
|
|
|
|
{
|
|
|
|
user.enableInvulnerabilityAfterTeleport();
|
|
|
|
}
|
2011-12-06 22:56:38 +00:00
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-01-20 04:20:37 +00:00
|
|
|
final ItemStack stack = new ItemStack(Material.EGG, 1);
|
|
|
|
if (user.hasUnlimited(stack))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-01-20 04:20:37 +00:00
|
|
|
user.getInventory().addItem(stack);
|
2011-09-28 23:38:56 +00:00
|
|
|
user.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-28 23:38:56 +00:00
|
|
|
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()
|
|
|
|
{
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-09-28 23:38:56 +00:00
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
user.updateInventory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2012-04-17 00:14:07 +00:00
|
|
|
final Player player = event.getPlayer();
|
2011-11-21 01:55:26 +00:00
|
|
|
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
2012-12-20 22:07:22 +00:00
|
|
|
if (ess.getSettings().getSocialSpyCommands().contains(cmd))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-04-17 00:14:07 +00:00
|
|
|
for (Player onlinePlayer : ess.getServer().getOnlinePlayers())
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-04-17 00:14:07 +00:00
|
|
|
final User spyer = ess.getUser(onlinePlayer);
|
|
|
|
if (spyer.isSocialSpyEnabled() && !player.equals(onlinePlayer))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-04-17 00:14:07 +00:00
|
|
|
onlinePlayer.sendMessage(player.getDisplayName() + " : " + event.getMessage());
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 00:14:07 +00:00
|
|
|
else if (!cmd.equalsIgnoreCase("afk"))
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2012-04-17 00:14:07 +00:00
|
|
|
final User user = ess.getUser(player);
|
2011-09-28 23:38:56 +00:00
|
|
|
user.updateActivity(true);
|
|
|
|
}
|
|
|
|
}
|
2012-08-30 23:47:53 +00:00
|
|
|
|
2013-02-05 19:16:27 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2012-08-30 22:13:50 +00:00
|
|
|
public void onPlayerChangedWorldHack(final PlayerChangedWorldEvent event)
|
|
|
|
{
|
2013-02-05 19:16:27 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.getGameMode() != GameMode.CREATIVE && !user.isAuthorized("essentials.fly"))
|
2012-11-08 07:57:44 +00:00
|
|
|
{
|
|
|
|
user.setAllowFlight(false);
|
|
|
|
}
|
2012-08-30 22:13:50 +00:00
|
|
|
user.setFlySpeed(0.1f);
|
|
|
|
user.setWalkSpeed(0.2f);
|
|
|
|
}
|
2011-11-25 06:12:21 +00:00
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-11-26 21:30:40 +00:00
|
|
|
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
|
2011-11-25 06:12:21 +00:00
|
|
|
{
|
2012-04-14 05:07:10 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-04-12 20:26:19 +00:00
|
|
|
final String newWorld = event.getPlayer().getLocation().getWorld().getName();
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2012-03-02 19:05:30 +00:00
|
|
|
updateCompass(user);
|
2012-04-14 05:07:10 +00:00
|
|
|
if (ess.getSettings().getNoGodWorlds().contains(newWorld) && user.isGodModeEnabledRaw())
|
2011-11-27 08:07:15 +00:00
|
|
|
{
|
2012-04-14 05:07:10 +00:00
|
|
|
user.sendMessage(_("noGodWorldWarning"));
|
2011-11-25 06:12:21 +00:00
|
|
|
}
|
2012-04-14 05:07:10 +00:00
|
|
|
|
2013-01-27 16:39:50 +00:00
|
|
|
if (!user.getWorld().getName().equals(newWorld))
|
2012-04-12 20:26:19 +00:00
|
|
|
{
|
|
|
|
user.sendMessage(_("currentWorld", newWorld));
|
|
|
|
}
|
2013-01-27 16:39:50 +00:00
|
|
|
if (user.isVanished())
|
|
|
|
{
|
|
|
|
user.setVanished(user.isAuthorized("essentials.vanish"));
|
|
|
|
}
|
2011-11-27 08:07:15 +00:00
|
|
|
}
|
2011-11-30 01:51:02 +00:00
|
|
|
|
2012-03-02 16:33:20 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-11-30 01:51:02 +00:00
|
|
|
public void onPlayerInteract(final PlayerInteractEvent event)
|
|
|
|
{
|
2012-02-22 00:11:21 +00:00
|
|
|
switch (event.getAction())
|
2011-11-30 01:51:02 +00:00
|
|
|
{
|
2012-02-22 00:11:21 +00:00
|
|
|
case RIGHT_CLICK_BLOCK:
|
2012-04-15 22:13:34 +00:00
|
|
|
if (!event.isCancelled() && event.getClickedBlock().getTypeId() == BED && ess.getSettings().getUpdateBedAtDaytime())
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
2013-01-10 22:36:38 +00:00
|
|
|
User player = ess.getUser(event.getPlayer());
|
|
|
|
if (player.isAuthorized("essentials.sethome.bed"))
|
|
|
|
{
|
|
|
|
player.setBedSpawnLocation(event.getClickedBlock().getLocation());
|
|
|
|
player.sendMessage(_("homeSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
|
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-03-29 02:06:52 +00:00
|
|
|
case LEFT_CLICK_AIR:
|
2012-09-09 19:13:03 +00:00
|
|
|
if (event.getPlayer().isFlying())
|
2012-08-30 23:47:53 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.isFlyClickJump())
|
|
|
|
{
|
|
|
|
useFlyClickJump(user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 20:44:14 +00:00
|
|
|
case LEFT_CLICK_BLOCK:
|
2012-04-15 22:13:34 +00:00
|
|
|
if (event.getItem() != null && event.getItem().getTypeId() != AIR)
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
2012-03-30 20:44:14 +00:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-12-03 09:08:56 +00:00
|
|
|
user.updateActivity(true);
|
2012-03-30 20:44:14 +00:00
|
|
|
if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2011-11-30 01:51:02 +00:00
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 02:31:34 +00:00
|
|
|
// This method allows the /jump lock feature to work, allows teleporting while flying #EasterEgg
|
2012-08-30 23:47:53 +00:00
|
|
|
private void useFlyClickJump(final User user)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Location otarget = Util.getTarget(user);
|
|
|
|
|
|
|
|
ess.scheduleSyncDelayedTask(
|
|
|
|
new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
Location loc = user.getLocation();
|
|
|
|
loc.setX(otarget.getX());
|
|
|
|
loc.setZ(otarget.getZ());
|
2012-09-09 19:13:03 +00:00
|
|
|
while (Util.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()))
|
|
|
|
{
|
2012-08-30 23:47:53 +00:00
|
|
|
loc.setY(loc.getY() + 1d);
|
|
|
|
}
|
|
|
|
user.getBase().teleport(loc, TeleportCause.PLUGIN);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 20:44:14 +00:00
|
|
|
private boolean usePowertools(final User user, final int id)
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
|
|
|
final List<String> commandList = user.getPowertool(id);
|
|
|
|
if (commandList == null || commandList.isEmpty())
|
2011-11-30 01:51:02 +00:00
|
|
|
{
|
2012-02-22 00:11:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
boolean used = false;
|
|
|
|
// We need to loop through each command and execute
|
2012-02-22 00:22:22 +00:00
|
|
|
for (final String command : commandList)
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
2012-03-30 20:44:14 +00:00
|
|
|
if (command.contains("{player}"))
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (command.startsWith("c:"))
|
|
|
|
{
|
|
|
|
used = true;
|
|
|
|
user.chat(command.substring(2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
used = true;
|
2012-02-22 00:22:22 +00:00
|
|
|
ess.scheduleSyncDelayedTask(
|
|
|
|
new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
user.getServer().dispatchCommand(user.getBase(), command);
|
2012-08-31 17:52:40 +00:00
|
|
|
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command));
|
2012-02-22 00:22:22 +00:00
|
|
|
}
|
|
|
|
});
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
2011-11-30 01:51:02 +00:00
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
return used;
|
2011-11-30 01:51:02 +00:00
|
|
|
}
|
2011-12-07 11:10:41 +00:00
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-03 05:27:02 +00:00
|
|
|
public void onPlayerPickupItem(final PlayerPickupItemEvent event)
|
2011-12-07 11:10:41 +00:00
|
|
|
{
|
2012-04-14 05:07:10 +00:00
|
|
|
if (ess.getSettings().getDisableItemPickupWhileAfk())
|
2011-12-07 11:10:41 +00:00
|
|
|
{
|
2012-04-14 05:07:10 +00:00
|
|
|
if (ess.getUser(event.getPlayer()).isAfk())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-12-07 11:10:41 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-25 01:33:52 +00:00
|
|
|
|
2012-09-20 19:21:45 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
2012-03-25 01:33:52 +00:00
|
|
|
public void onInventoryClickEvent(final InventoryClickEvent event)
|
|
|
|
{
|
2013-01-01 18:39:23 +00:00
|
|
|
final Inventory top = event.getView().getTopInventory();
|
|
|
|
final InventoryType type = top.getType();
|
|
|
|
|
|
|
|
if (type == InventoryType.PLAYER)
|
2012-03-25 01:33:52 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getWhoClicked());
|
2013-01-01 18:39:23 +00:00
|
|
|
final InventoryHolder invHolder = top.getHolder();
|
2012-06-03 15:34:27 +00:00
|
|
|
if (invHolder != null && invHolder instanceof HumanEntity)
|
2012-03-25 01:33:52 +00:00
|
|
|
{
|
2012-06-03 15:34:27 +00:00
|
|
|
final User invOwner = ess.getUser((HumanEntity)invHolder);
|
|
|
|
if (user.isInvSee() && (!user.isAuthorized("essentials.invsee.modify")
|
|
|
|
|| invOwner.isAuthorized("essentials.invsee.preventmodify")
|
|
|
|
|| !invOwner.isOnline()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2013-01-01 19:34:32 +00:00
|
|
|
user.updateInventory();
|
2012-06-03 15:34:27 +00:00
|
|
|
}
|
2012-03-25 01:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.ENDER_CHEST)
|
2012-08-21 19:02:20 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getWhoClicked());
|
|
|
|
if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify")))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.WORKBENCH)
|
2012-12-19 03:57:12 +00:00
|
|
|
{
|
|
|
|
User user = ess.getUser(event.getWhoClicked());
|
|
|
|
if (user.isRecipeSee())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.CHEST && top.getSize() == 9)
|
|
|
|
{
|
2013-01-01 19:34:32 +00:00
|
|
|
final User user = ess.getUser(event.getWhoClicked());
|
|
|
|
final InventoryHolder invHolder = top.getHolder();
|
2013-01-01 19:48:08 +00:00
|
|
|
if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee())
|
2013-01-01 18:39:23 +00:00
|
|
|
{
|
2013-01-01 19:48:08 +00:00
|
|
|
event.setCancelled(true);
|
2013-01-01 18:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-25 01:33:52 +00:00
|
|
|
}
|
2012-03-25 15:30:22 +00:00
|
|
|
|
2012-03-25 01:33:52 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onInventoryCloseEvent(final InventoryCloseEvent event)
|
|
|
|
{
|
2013-01-01 18:39:23 +00:00
|
|
|
final Inventory top = event.getView().getTopInventory();
|
|
|
|
final InventoryType type = top.getType();
|
|
|
|
if (type == InventoryType.PLAYER)
|
2012-03-25 01:33:52 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-03-25 15:30:22 +00:00
|
|
|
user.setInvSee(false);
|
2012-03-25 01:33:52 +00:00
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.ENDER_CHEST)
|
2012-08-21 19:02:20 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
user.setEnderSee(false);
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.WORKBENCH)
|
2012-12-19 03:57:12 +00:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-12-29 06:55:48 +00:00
|
|
|
if (user.isRecipeSee())
|
2012-12-19 03:57:12 +00:00
|
|
|
{
|
|
|
|
user.setRecipeSee(false);
|
|
|
|
event.getView().getTopInventory().clear();
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.CHEST && top.getSize() == 9)
|
|
|
|
{
|
2013-01-01 19:34:32 +00:00
|
|
|
final InventoryHolder invHolder = top.getHolder();
|
|
|
|
if (invHolder != null && invHolder instanceof HumanEntity)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
user.setInvSee(false);
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
}
|
2012-03-25 01:33:52 +00:00
|
|
|
}
|
2012-12-19 03:57:12 +00:00
|
|
|
|
2012-11-11 16:43:10 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onPlayerFishEvent(final PlayerFishEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
user.updateActivity(true);
|
|
|
|
}
|
2012-12-16 16:03:04 +00:00
|
|
|
}
|