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.Arrays;
|
|
|
|
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;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
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-09-28 23:38:56 +00:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.event.player.*;
|
2011-12-06 22:56:38 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
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)
|
2011-09-28 23:38:56 +00:00
|
|
|
public void onPlayerChat(final PlayerChatEvent event)
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
if (u.isIgnoredPlayer(user.getName()))
|
|
|
|
{
|
|
|
|
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-05-06 22:38:04 +00:00
|
|
|
if ((!ess.getSettings().cancelAfkOnMove() && !ess.getSettings().getFreezeAfkPlayers())
|
|
|
|
|| 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();
|
|
|
|
final Location to = event.getTo().clone();
|
|
|
|
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-05-21 05:13:01 +00:00
|
|
|
ess.getVanishedPlayers().remove(user.getName());
|
2012-04-14 14:57:47 +00:00
|
|
|
user.setLastLocation();
|
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)
|
|
|
|
{
|
2012-04-06 18:19:08 +00:00
|
|
|
ess.scheduleAsyncDelayedTask(new Runnable()
|
|
|
|
{
|
|
|
|
@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)
|
|
|
|
{
|
|
|
|
ess.getBackup().onPlayerJoin();
|
|
|
|
final User user = ess.getUser(player);
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2012-04-06 18:19:08 +00:00
|
|
|
updateCompass(user);
|
2012-03-25 16:27:06 +00:00
|
|
|
user.setLastLogin(System.currentTimeMillis());
|
2011-09-28 23:38:56 +00:00
|
|
|
user.updateActivity(false);
|
2012-04-06 18:19:08 +00:00
|
|
|
|
2012-05-21 05:13:01 +00:00
|
|
|
for (String p : ess.getVanishedPlayers())
|
|
|
|
{
|
|
|
|
if (!user.isAuthorized("essentials.vanish.see"))
|
|
|
|
{
|
2012-06-10 22:45:15 +00:00
|
|
|
user.hidePlayer(ess.getUser(p).getBase());
|
2012-05-21 05:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:38:56 +00:00
|
|
|
if (user.isAuthorized("essentials.sleepingignored"))
|
|
|
|
{
|
|
|
|
user.setSleepingIgnored(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
|
|
|
{
|
2011-11-18 03:18:03 +00:00
|
|
|
try
|
2011-09-28 23:38:56 +00:00
|
|
|
{
|
2011-11-18 03:18:03 +00:00
|
|
|
final IText input = new TextInput(user, "motd", true, ess);
|
|
|
|
final IText output = new KeywordReplacer(input, user, ess);
|
2011-11-24 04:57:01 +00:00
|
|
|
final TextPager pager = new TextPager(output, true);
|
2011-11-28 19:52:15 +00:00
|
|
|
pager.showPage("1", null, "motd", user);
|
2011-11-18 03:18:03 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2011-11-27 08:07:15 +00:00
|
|
|
if (ess.getSettings().isDebug())
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGGER.log(Level.WARNING, ex.getMessage());
|
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
|
|
|
{
|
|
|
|
final List<String> mail = user.getMails();
|
|
|
|
if (mail.isEmpty())
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("noNewMail"));
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("youHaveNewMail", mail.size()));
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
ess.scheduleSyncDelayedTask(new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
user.setCompassTarget(updateLoc);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
final String banReason = user.getBanReason();
|
2011-11-21 01:55:26 +00:00
|
|
|
event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : _("defaultBanReason"));
|
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-05-06 15:11:16 +00:00
|
|
|
private final static List<String> COMMANDS = Arrays.asList("msg", "r", "mail", "m", "t", "whisper", "emsg", "tell", "er", "reply", "ereply", "email");
|
2011-09-28 23:38:56 +00:00
|
|
|
|
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-04-17 00:14:07 +00:00
|
|
|
if (COMMANDS.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);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (!event.getPlayer().getWorld().getName().equals(newWorld))
|
2012-04-12 20:26:19 +00:00
|
|
|
{
|
|
|
|
user.sendMessage(_("currentWorld", newWorld));
|
|
|
|
}
|
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
|
|
|
{
|
2012-05-06 23:08:01 +00:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
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-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());
|
|
|
|
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-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-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-03-25 01:55:19 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2012-03-25 01:33:52 +00:00
|
|
|
public void onInventoryClickEvent(final InventoryClickEvent event)
|
|
|
|
{
|
|
|
|
if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getWhoClicked());
|
2012-06-03 15:34:27 +00:00
|
|
|
final InventoryHolder invHolder = event.getView().getTopInventory().getHolder();
|
|
|
|
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);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2011-09-28 23:38:56 +00:00
|
|
|
}
|