2011-09-29 01:38:56 +02:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2013-07-13 11:14:39 -04:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-12-01 13:42:39 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-11-18 04:18:03 +01: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;
|
2013-06-08 22:31:19 +01:00
|
|
|
import com.earth2me.essentials.utils.DateUtil;
|
|
|
|
import com.earth2me.essentials.utils.LocationUtil;
|
2011-11-18 04:18:03 +01:00
|
|
|
import java.io.IOException;
|
2011-09-29 01:38:56 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2011-11-21 02:55:26 +01:00
|
|
|
import java.util.Locale;
|
2011-09-29 01:38:56 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2012-09-10 01:13:30 +01:00
|
|
|
import org.bukkit.GameMode;
|
2011-09-29 01:38:56 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2013-01-01 22:00:53 +00:00
|
|
|
import org.bukkit.World;
|
2012-06-03 16:34:27 +01:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
2011-09-29 01:38:56 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2012-01-20 05:20:37 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2012-03-25 02:33:52 +01:00
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryType;
|
2012-11-11 11:43:10 -05:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
2013-03-16 09:16:33 +00:00
|
|
|
import org.bukkit.event.player.*;
|
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 16:34:27 +01:00
|
|
|
import org.bukkit.inventory.InventoryHolder;
|
2011-09-29 01:38:56 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
public class EssentialsPlayerListener implements Listener
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
|
|
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
|
|
|
private final transient IEssentials ess;
|
2012-04-15 23:13:34 +01:00
|
|
|
private static final int AIR = Material.AIR.getId();
|
|
|
|
private static final int BED = Material.BED_BLOCK.getId();
|
2011-09-29 01:38:56 +02:00
|
|
|
|
|
|
|
public EssentialsPlayerListener(final IEssentials parent)
|
|
|
|
{
|
|
|
|
this.ess = parent;
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-09-29 01:38:56 +02: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();
|
2013-07-17 23:26:26 +01:00
|
|
|
|
2013-06-08 21:06:33 +01:00
|
|
|
if (ess.getSettings().isTeleportInvulnerability())
|
|
|
|
{
|
|
|
|
user.enableInvulnerabilityAfterTeleport();
|
|
|
|
}
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2012-08-04 09:25:54 +01:00
|
|
|
public void onPlayerChat(final AsyncPlayerChatEvent event)
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.isMuted())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2013-07-12 16:17:30 +03:00
|
|
|
user.sendMessage(_("voiceSilenced"));
|
2011-11-21 02:55:26 +01:00
|
|
|
LOGGER.info(_("mutedUserSpeaks", user.getName()));
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
2013-07-17 23:26:26 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
final Iterator<Player> it = event.getRecipients().iterator();
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
final User u = ess.getUser(it.next());
|
|
|
|
if (u.isIgnoredPlayer(user))
|
|
|
|
{
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (UnsupportedOperationException ex)
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2013-07-17 23:26:26 +01:00
|
|
|
if (ess.getSettings().isDebug())
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2013-07-17 23:26:26 +01:00
|
|
|
ess.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ess.getLogger().info("Ignore could not block chat due to custom chat plugin event.");
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-11 16:37:21 +01:00
|
|
|
|
2011-09-29 01:38:56 +02:00
|
|
|
user.updateActivity(true);
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-29 01:38:56 +02:00
|
|
|
public void onPlayerMove(final PlayerMoveEvent event)
|
|
|
|
{
|
2013-05-12 20:41:40 +01:00
|
|
|
if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
|
|
|
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()
|
|
|
|
&& event.getFrom().getBlockY() == event.getTo().getBlockY())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2012-03-25 16:30:22 +01:00
|
|
|
|
2011-09-29 01:38:56 +02:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-04-26 10:41:24 +02:00
|
|
|
if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers())
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-04-26 10:41:24 +02:00
|
|
|
final Location from = event.getFrom();
|
2012-08-28 02:50:59 +01:00
|
|
|
final Location origTo = event.getTo();
|
|
|
|
final Location to = origTo.clone();
|
2012-08-31 00:47:53 +01:00
|
|
|
if (ess.getSettings().cancelAfkOnMove() && origTo.getY() >= from.getBlockY() + 1)
|
|
|
|
{
|
2012-08-28 02:50:59 +01:00
|
|
|
user.updateActivity(true);
|
|
|
|
return;
|
|
|
|
}
|
2012-04-26 10:41:24 +02:00
|
|
|
to.setX(from.getX());
|
|
|
|
to.setY(from.getY());
|
|
|
|
to.setZ(from.getZ());
|
|
|
|
try
|
2011-10-09 23:45:46 +02:00
|
|
|
{
|
2013-06-08 22:31:19 +01:00
|
|
|
event.setTo(LocationUtil.getSafeDestination(to));
|
2011-10-09 23:45:46 +02:00
|
|
|
}
|
2012-04-26 10:41:24 +02:00
|
|
|
catch (Exception ex)
|
2011-10-09 23:45:46 +02:00
|
|
|
{
|
2012-04-26 10:41:24 +02:00
|
|
|
event.setTo(to);
|
2011-10-09 23:45:46 +02:00
|
|
|
}
|
2012-04-26 10:41:24 +02: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-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-09-29 01:38:56 +02:00
|
|
|
public void onPlayerQuit(final PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
|
|
|
|
{
|
2012-06-10 19:20:24 +01:00
|
|
|
user.setGodModeEnabled(false);
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
2012-06-11 09:17:19 +10:00
|
|
|
if (user.isVanished())
|
|
|
|
{
|
2013-06-02 17:45:56 +01:00
|
|
|
user.setVanished(false);
|
2012-06-11 09:17:19 +10:00
|
|
|
}
|
2013-02-08 21:22:35 +01:00
|
|
|
user.setLogoutLocation();
|
2012-12-29 06:55:48 +00:00
|
|
|
if (user.isRecipeSee())
|
|
|
|
{
|
2013-07-07 12:11:57 +01:00
|
|
|
user.getBase().getOpenInventory().getTopInventory().clear();
|
2012-12-29 06:55:48 +00:00
|
|
|
}
|
2011-09-29 01:38:56 +02:00
|
|
|
user.updateActivity(false);
|
|
|
|
user.dispose();
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-09-29 01:38:56 +02:00
|
|
|
public void onPlayerJoin(final PlayerJoinEvent event)
|
|
|
|
{
|
2013-01-31 14:16:09 -05:00
|
|
|
ess.runTaskAsynchronously(new Runnable()
|
2012-04-06 19:19:08 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
delayedJoin(event.getPlayer());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-03-25 17:27:06 +01:00
|
|
|
|
2012-04-06 19:19:08 +01:00
|
|
|
public void delayedJoin(final Player player)
|
|
|
|
{
|
2012-06-16 17:31:33 +01:00
|
|
|
if (!player.isOnline())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-02-11 23:11:37 +00:00
|
|
|
|
2012-04-06 19:19:08 +01:00
|
|
|
ess.getBackup().onPlayerJoin();
|
|
|
|
final User user = ess.getUser(player);
|
2013-02-11 23:11:37 +00:00
|
|
|
|
|
|
|
if (user.isNPC())
|
|
|
|
{
|
|
|
|
user.setNPC(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
final long currentTime = System.currentTimeMillis();
|
|
|
|
user.checkMuteTimeout(currentTime);
|
2011-09-29 01:38:56 +02:00
|
|
|
user.updateActivity(false);
|
2013-01-29 23:51:42 +00:00
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
ess.scheduleSyncDelayedTask(new Runnable()
|
2012-05-21 15:13:01 +10:00
|
|
|
{
|
2013-01-30 00:26:50 +01:00
|
|
|
@Override
|
|
|
|
public void run()
|
2012-05-21 15:13:01 +10:00
|
|
|
{
|
2013-03-21 22:30:02 +00:00
|
|
|
if (!user.isOnline())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-11 23:11:37 +00:00
|
|
|
user.setLastLogin(currentTime);
|
2013-01-29 23:51:42 +00:00
|
|
|
user.setDisplayNick();
|
|
|
|
updateCompass(user);
|
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see"))
|
2012-11-08 18:57:44 +11:00
|
|
|
{
|
2013-01-30 00:26:50 +01:00
|
|
|
for (String p : ess.getVanishedPlayers())
|
|
|
|
{
|
|
|
|
Player toVanish = ess.getServer().getPlayerExact(p);
|
|
|
|
if (toVanish != null && toVanish.isOnline())
|
|
|
|
{
|
|
|
|
user.hidePlayer(toVanish);
|
|
|
|
}
|
|
|
|
}
|
2012-09-09 20:13:03 +01:00
|
|
|
}
|
2012-05-21 15:13:01 +10:00
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
if (user.isAuthorized("essentials.sleepingignored"))
|
2012-11-08 18:57:44 +11:00
|
|
|
{
|
|
|
|
user.setSleepingIgnored(true);
|
|
|
|
}
|
2011-09-29 01:38:56 +02:00
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
2011-11-27 09:07:15 +01:00
|
|
|
{
|
2013-01-30 00:26:50 +01:00
|
|
|
try
|
|
|
|
{
|
2013-07-07 13:02:40 +01:00
|
|
|
final IText input = new TextInput(user.getBase(), "motd", true, ess);
|
|
|
|
final IText output = new KeywordReplacer(input, user.getBase(), ess);
|
2013-01-30 00:26:50 +01:00
|
|
|
final TextPager pager = new TextPager(output, true);
|
2013-07-07 13:02:40 +01:00
|
|
|
pager.showPage("1", null, "motd", user.getBase());
|
2013-01-30 00:26:50 +01:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2011-11-27 09:07:15 +01:00
|
|
|
}
|
2011-09-29 01:38:56 +02:00
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
2012-11-04 22:34:47 +01:00
|
|
|
{
|
2013-01-30 00:26:50 +01:00
|
|
|
final List<String> mail = user.getMails();
|
|
|
|
if (mail.isEmpty())
|
|
|
|
{
|
2013-07-13 18:46:26 +01:00
|
|
|
user.sendMessage(_("noNewMail"));
|
2013-01-30 00:26:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.sendMessage(_("youHaveNewMail", mail.size()));
|
|
|
|
}
|
2012-11-04 22:34:47 +01:00
|
|
|
}
|
2013-01-29 23:51:42 +00:00
|
|
|
|
2013-01-30 00:26:50 +01:00
|
|
|
if (user.isAuthorized("essentials.fly.safelogin"))
|
|
|
|
{
|
2013-08-11 22:42:29 +01:00
|
|
|
if (LocationUtil.shouldFly(user.getLocation()))
|
2013-01-30 00:26:50 +01:00
|
|
|
{
|
|
|
|
user.setAllowFlight(true);
|
|
|
|
user.setFlying(true);
|
|
|
|
user.sendMessage(_("flyMode", _("enabled"), user.getDisplayName()));
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 22:55:00 +00:00
|
|
|
user.setFlySpeed(0.1f);
|
|
|
|
user.setWalkSpeed(0.2f);
|
2013-03-21 22:30:02 +00:00
|
|
|
|
2013-01-01 22:00:53 +00:00
|
|
|
}
|
2013-01-30 00:26:50 +01:00
|
|
|
});
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
|
2012-10-22 12:27:01 +02:00
|
|
|
// Makes the compass item ingame always point to the first essentials home. #EasterEgg
|
2012-04-06 19:19:08 +01: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 19:19:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2011-09-29 01:38:56 +02: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 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-29 01:38:56 +02:00
|
|
|
}
|
2012-03-03 05:27:02 +00:00
|
|
|
|
2012-04-14 15:07:10 +10:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2011-09-29 01:38:56 +02:00
|
|
|
|
2013-02-11 23:11:37 +00:00
|
|
|
if (event.getResult() == Result.KICK_BANNED || user.isBanned())
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2013-02-11 23:11:37 +00:00
|
|
|
final boolean banExpired = user.checkBanTimeout(System.currentTimeMillis());
|
|
|
|
if (!banExpired)
|
2013-01-09 20:59:27 +00:00
|
|
|
{
|
2013-02-11 23:11:37 +00:00
|
|
|
String banReason = user.getBanReason();
|
|
|
|
if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban"))
|
|
|
|
{
|
|
|
|
banReason = _("defaultBanReason");
|
|
|
|
}
|
|
|
|
if (user.getBanTimeout() > 0)
|
|
|
|
{
|
|
|
|
//TODO: TL This
|
2013-06-08 22:31:19 +01:00
|
|
|
banReason += "\n\n" + "Expires in " + DateUtil.formatDateDiff(user.getBanTimeout());
|
2013-02-11 23:11:37 +00:00
|
|
|
}
|
|
|
|
event.disallow(Result.KICK_BANNED, banReason);
|
|
|
|
return;
|
2013-01-09 20:59:27 +00:00
|
|
|
}
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 16:46:36 +01:00
|
|
|
if (event.getResult() == Result.KICK_FULL && !user.isAuthorized("essentials.joinfullserver"))
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
event.disallow(Result.KICK_FULL, _("serverFull"));
|
2011-09-29 01:38:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.allow();
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2012-01-20 05:20:37 +01:00
|
|
|
public void onPlayerTeleport(final PlayerTeleportEvent event)
|
2011-12-07 12:10:41 +01:00
|
|
|
{
|
2012-04-14 15:07:10 +10:00
|
|
|
final boolean backListener = ess.getSettings().registerBackInListener();
|
|
|
|
final boolean teleportInvulnerability = ess.getSettings().isTeleportInvulnerability();
|
2012-03-30 21:44:14 +01:00
|
|
|
if (backListener || teleportInvulnerability)
|
2011-12-06 22:56:38 +00:00
|
|
|
{
|
2012-03-30 21:44:14 +01: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-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-29 01:38:56 +02:00
|
|
|
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-01-20 05:20:37 +01:00
|
|
|
final ItemStack stack = new ItemStack(Material.EGG, 1);
|
|
|
|
if (user.hasUnlimited(stack))
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-01-20 05:20:37 +01:00
|
|
|
user.getInventory().addItem(stack);
|
2011-09-29 01:38:56 +02:00
|
|
|
user.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2011-09-29 01:38:56 +02: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-29 01:38:56 +02:00
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
user.updateInventory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:42:46 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
2011-09-29 01:38:56 +02:00
|
|
|
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2012-04-17 01:14:07 +01:00
|
|
|
final Player player = event.getPlayer();
|
2011-11-21 02:55:26 +01:00
|
|
|
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
2012-12-20 23:07:22 +01:00
|
|
|
if (ess.getSettings().getSocialSpyCommands().contains(cmd))
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-04-17 01:14:07 +01:00
|
|
|
for (Player onlinePlayer : ess.getServer().getOnlinePlayers())
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-04-17 01:14:07 +01:00
|
|
|
final User spyer = ess.getUser(onlinePlayer);
|
|
|
|
if (spyer.isSocialSpyEnabled() && !player.equals(onlinePlayer))
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-04-17 01:14:07 +01:00
|
|
|
onlinePlayer.sendMessage(player.getDisplayName() + " : " + event.getMessage());
|
2011-09-29 01:38:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 01:14:07 +01:00
|
|
|
else if (!cmd.equalsIgnoreCase("afk"))
|
2011-09-29 01:38:56 +02:00
|
|
|
{
|
2012-04-17 01:14:07 +01:00
|
|
|
final User user = ess.getUser(player);
|
2011-09-29 01:38:56 +02:00
|
|
|
user.updateActivity(true);
|
|
|
|
}
|
|
|
|
}
|
2012-08-31 00:47:53 +01:00
|
|
|
|
2013-02-05 13:16:27 -06:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2013-03-19 22:55:00 +00:00
|
|
|
public void onPlayerChangedWorldFlyReset(final PlayerChangedWorldEvent event)
|
2012-08-30 23:13:50 +01:00
|
|
|
{
|
2013-02-05 13:16:27 -06:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.getGameMode() != GameMode.CREATIVE && !user.isAuthorized("essentials.fly"))
|
2012-11-08 18:57:44 +11:00
|
|
|
{
|
|
|
|
user.setAllowFlight(false);
|
|
|
|
}
|
2012-08-30 23:13:50 +01:00
|
|
|
user.setFlySpeed(0.1f);
|
|
|
|
user.setWalkSpeed(0.2f);
|
|
|
|
}
|
2011-11-25 07:12:21 +01:00
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2011-11-26 22:30:40 +01:00
|
|
|
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event)
|
2011-11-25 07:12:21 +01:00
|
|
|
{
|
2012-04-14 15:07:10 +10:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-04-12 21:26:19 +01: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 15:07:10 +10:00
|
|
|
if (ess.getSettings().getNoGodWorlds().contains(newWorld) && user.isGodModeEnabledRaw())
|
2011-11-27 09:07:15 +01:00
|
|
|
{
|
2012-04-14 15:07:10 +10:00
|
|
|
user.sendMessage(_("noGodWorldWarning"));
|
2011-11-25 07:12:21 +01:00
|
|
|
}
|
2012-04-14 15:07:10 +10:00
|
|
|
|
2013-01-27 16:39:50 +00:00
|
|
|
if (!user.getWorld().getName().equals(newWorld))
|
2012-04-12 21:26:19 +01: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 09:07:15 +01:00
|
|
|
}
|
2011-11-30 02:51:02 +01:00
|
|
|
|
2012-03-02 16:33:20 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2011-11-30 02:51:02 +01:00
|
|
|
public void onPlayerInteract(final PlayerInteractEvent event)
|
|
|
|
{
|
2012-02-22 00:11:21 +00:00
|
|
|
switch (event.getAction())
|
2011-11-30 02:51:02 +01:00
|
|
|
{
|
2012-02-22 00:11:21 +00:00
|
|
|
case RIGHT_CLICK_BLOCK:
|
2012-04-15 23:13:34 +01: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());
|
2013-02-07 08:48:34 +02:00
|
|
|
player.sendMessage(_("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
|
2013-01-10 22:36:38 +00:00
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-03-29 03:06:52 +01:00
|
|
|
case LEFT_CLICK_AIR:
|
2012-09-09 20:13:03 +01:00
|
|
|
if (event.getPlayer().isFlying())
|
2012-08-31 00:47:53 +01:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
if (user.isFlyClickJump())
|
|
|
|
{
|
|
|
|
useFlyClickJump(user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 21:44:14 +01:00
|
|
|
case LEFT_CLICK_BLOCK:
|
2012-04-15 23:13:34 +01:00
|
|
|
if (event.getItem() != null && event.getItem().getTypeId() != AIR)
|
2012-02-22 00:11:21 +00:00
|
|
|
{
|
2012-03-30 21:44:14 +01:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-12-03 09:08:56 +00:00
|
|
|
user.updateActivity(true);
|
2012-03-30 21:44:14 +01: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 02:51:02 +01:00
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 03:31:34 +01:00
|
|
|
// This method allows the /jump lock feature to work, allows teleporting while flying #EasterEgg
|
2012-08-31 00:47:53 +01:00
|
|
|
private void useFlyClickJump(final User user)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-07-07 12:11:57 +01:00
|
|
|
final Location otarget = LocationUtil.getTarget(user.getBase());
|
2012-08-31 00:47:53 +01:00
|
|
|
|
|
|
|
ess.scheduleSyncDelayedTask(
|
|
|
|
new Runnable()
|
2013-07-17 23:26:26 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
Location loc = user.getLocation();
|
|
|
|
loc.setX(otarget.getX());
|
|
|
|
loc.setZ(otarget.getZ());
|
|
|
|
while (LocationUtil.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()))
|
2012-08-31 00:47:53 +01:00
|
|
|
{
|
2013-07-17 23:26:26 +01:00
|
|
|
loc.setY(loc.getY() + 1d);
|
|
|
|
}
|
|
|
|
user.getBase().teleport(loc, TeleportCause.PLUGIN);
|
|
|
|
}
|
|
|
|
});
|
2012-08-31 00:47:53 +01:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:44:14 +01: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 02:51:02 +01: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 21:44:14 +01: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()
|
2013-07-17 23:26:26 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
user.getServer().dispatchCommand(user.getBase(), command);
|
|
|
|
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command));
|
|
|
|
}
|
|
|
|
});
|
2012-02-22 00:11:21 +00:00
|
|
|
}
|
2011-11-30 02:51:02 +01:00
|
|
|
}
|
2012-02-22 00:11:21 +00:00
|
|
|
return used;
|
2011-11-30 02:51:02 +01:00
|
|
|
}
|
2011-12-07 12:10:41 +01: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 12:10:41 +01:00
|
|
|
{
|
2012-04-14 15:07:10 +10:00
|
|
|
if (ess.getSettings().getDisableItemPickupWhileAfk())
|
2011-12-07 12:10:41 +01:00
|
|
|
{
|
2012-04-14 15:07:10 +10:00
|
|
|
if (ess.getUser(event.getPlayer()).isAfk())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-12-07 12:10:41 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-25 02:33:52 +01:00
|
|
|
|
2012-09-20 20:21:45 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
2012-03-25 02:33:52 +01: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 02:33:52 +01:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getWhoClicked());
|
2013-01-01 18:39:23 +00:00
|
|
|
final InventoryHolder invHolder = top.getHolder();
|
2012-06-03 16:34:27 +01:00
|
|
|
if (invHolder != null && invHolder instanceof HumanEntity)
|
2012-03-25 02:33:52 +01:00
|
|
|
{
|
2012-06-03 16:34:27 +01: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 16:34:27 +01:00
|
|
|
}
|
2012-03-25 02:33:52 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.ENDER_CHEST)
|
2012-08-21 20:02:20 +01: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 14:57:12 +11: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 02:33:52 +01:00
|
|
|
}
|
2012-03-25 16:30:22 +01:00
|
|
|
|
2012-03-25 02:33:52 +01: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 02:33:52 +01:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-03-25 16:30:22 +01:00
|
|
|
user.setInvSee(false);
|
2013-05-26 18:21:19 +01:00
|
|
|
user.updateInventory();
|
2012-03-25 02:33:52 +01:00
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.ENDER_CHEST)
|
2012-08-21 20:02:20 +01:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
|
|
|
user.setEnderSee(false);
|
2013-05-26 18:21:19 +01:00
|
|
|
user.updateInventory();
|
2012-08-21 20:02:20 +01:00
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
else if (type == InventoryType.WORKBENCH)
|
2012-12-19 14:57:12 +11:00
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2012-12-29 06:55:48 +00:00
|
|
|
if (user.isRecipeSee())
|
2012-12-19 14:57:12 +11:00
|
|
|
{
|
|
|
|
user.setRecipeSee(false);
|
|
|
|
event.getView().getTopInventory().clear();
|
2013-05-26 18:21:19 +01:00
|
|
|
user.updateInventory();
|
2012-12-19 14:57:12 +11:00
|
|
|
}
|
|
|
|
}
|
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-05-26 18:21:19 +01:00
|
|
|
user.updateInventory();
|
2013-01-01 19:34:32 +00:00
|
|
|
}
|
2013-01-01 18:39:23 +00:00
|
|
|
}
|
2012-03-25 02:33:52 +01:00
|
|
|
}
|
2012-12-19 14:57:12 +11:00
|
|
|
|
2012-11-11 11:43:10 -05: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 18:03:04 +02:00
|
|
|
}
|