summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-03-30 21:44:14 +0100
committerKHobbits <rob@khobbits.co.uk>2012-03-30 21:44:14 +0100
commitadf976490eab2b8f7b94ffdab998c77100159c2b (patch)
tree5ca3b4edd7cf4aee647dc83574279fa7157c1eb0
parent9fa68e9fd4dce75d47b070ca28517d8cb37d62bc (diff)
downloadEssentials-adf976490eab2b8f7b94ffdab998c77100159c2b.tar
Essentials-adf976490eab2b8f7b94ffdab998c77100159c2b.tar.gz
Essentials-adf976490eab2b8f7b94ffdab998c77100159c2b.tar.lz
Essentials-adf976490eab2b8f7b94ffdab998c77100159c2b.tar.xz
Essentials-adf976490eab2b8f7b94ffdab998c77100159c2b.zip
Minor cleanup to player events.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java41
-rw-r--r--Essentials/src/com/earth2me/essentials/ISettings.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java2
4 files changed, 40 insertions, 21 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 36adf37e2..992c3875b 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -227,14 +227,21 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
- //TODO: Don't fetch user unless one of these features are enabled.
- final User user = ess.getUser(event.getPlayer());
- //There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
- if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && ess.getSettings().registerBackInListener())
+ boolean backListener = ess.getSettings().registerBackInListener();
+ boolean teleportInvulnerability = ess.getSettings().isTeleportInvulnerability();
+ if (backListener || teleportInvulnerability)
{
- user.setLastLocation();
+ 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();
+ }
}
- user.enableInvulnerabilityAfterTeleport();
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@@ -309,8 +316,6 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(final PlayerInteractEvent event)
{
- final User user = ess.getUser(event.getPlayer());
- user.updateActivity(true);
switch (event.getAction())
{
case RIGHT_CLICK_BLOCK:
@@ -323,11 +328,15 @@ public class EssentialsPlayerListener implements Listener
event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
}
break;
- case LEFT_CLICK_BLOCK:
case LEFT_CLICK_AIR:
- if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem()))
+ case LEFT_CLICK_BLOCK:
+ if (event.getItem() != null && event.getMaterial() != Material.AIR)
{
- event.setCancelled(true);
+ final User user = ess.getUser(event.getPlayer());
+ if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId()))
+ {
+ event.setCancelled(true);
+ }
}
break;
default:
@@ -335,13 +344,8 @@ public class EssentialsPlayerListener implements Listener
}
}
- private boolean usePowertools(final User user, final ItemStack is)
+ private boolean usePowertools(final User user, final int id)
{
- int id;
- if (is == null || (id = is.getTypeId()) == 0)
- {
- return false;
- }
final List<String> commandList = user.getPowertool(id);
if (commandList == null || commandList.isEmpty())
{
@@ -351,9 +355,8 @@ public class EssentialsPlayerListener implements Listener
// We need to loop through each command and execute
for (final String command : commandList)
{
- if (command.matches(".*\\{player\\}.*"))
+ if (command.contains("{player}"))
{
- //user.sendMessage("Click a player to use this command");
continue;
}
else if (command.startsWith("c:"))
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java
index 74942640e..2c07ccd58 100644
--- a/Essentials/src/com/earth2me/essentials/ISettings.java
+++ b/Essentials/src/com/earth2me/essentials/ISettings.java
@@ -170,5 +170,7 @@ public interface ISettings extends IConf
void setMetricsEnabled(boolean metricsEnabled);
- public long getTeleportInvulnerability();
+ long getTeleportInvulnerability();
+
+ boolean isTeleportInvulnerability();
}
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 9dee4e990..f63bdd335 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -382,6 +382,7 @@ public class Settings implements ISettings
config.load();
noGodWorlds = new HashSet<String>(config.getStringList("no-god-in-worlds"));
enabledSigns = _getEnabledSigns();
+ teleportInvulnerability = _isTeleportInvulnerability();
itemSpawnBl = _getItemSpawnBlacklist();
kits = _getKits();
chatFormats.clear();
@@ -745,10 +746,23 @@ public class Settings implements ISettings
{
this.metricsEnabled = metricsEnabled;
}
+
+ private boolean teleportInvulnerability;
@Override
public long getTeleportInvulnerability()
{
return config.getLong("teleport-invulnerability", 0) * 1000;
}
+
+ private boolean _isTeleportInvulnerability()
+ {
+ return (config.getLong("teleport-invulnerability", 0) > 0);
+ }
+
+ @Override
+ public boolean isTeleportInvulnerability()
+ {
+ return teleportInvulnerability;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index f931b07d9..6e9ffdf82 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -626,7 +626,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
teleportInvulnerabilityTimestamp = 0;
}
}
-
+
public boolean hasInvulnerabilityAfterTeleport()
{
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();