Minor cleanup to player events.

This commit is contained in:
KHobbits 2012-03-30 21:44:14 +01:00
parent 17058c220c
commit c6f25c0df6
4 changed files with 40 additions and 21 deletions

View File

@ -227,14 +227,21 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event) public void onPlayerTeleport(final PlayerTeleportEvent event)
{ {
//TODO: Don't fetch user unless one of these features are enabled. boolean backListener = ess.getSettings().registerBackInListener();
final User user = ess.getUser(event.getPlayer()); boolean teleportInvulnerability = ess.getSettings().isTeleportInvulnerability();
//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports. if (backListener || teleportInvulnerability)
if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && ess.getSettings().registerBackInListener())
{ {
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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -309,8 +316,6 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(final PlayerInteractEvent event) public void onPlayerInteract(final PlayerInteractEvent event)
{ {
final User user = ess.getUser(event.getPlayer());
user.updateActivity(true);
switch (event.getAction()) switch (event.getAction())
{ {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
@ -323,11 +328,15 @@ public class EssentialsPlayerListener implements Listener
event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation()); event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
} }
break; break;
case LEFT_CLICK_BLOCK:
case LEFT_CLICK_AIR: 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; break;
default: 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); final List<String> commandList = user.getPowertool(id);
if (commandList == null || commandList.isEmpty()) if (commandList == null || commandList.isEmpty())
{ {
@ -351,9 +355,8 @@ public class EssentialsPlayerListener implements Listener
// We need to loop through each command and execute // We need to loop through each command and execute
for (final String command : commandList) for (final String command : commandList)
{ {
if (command.matches(".*\\{player\\}.*")) if (command.contains("{player}"))
{ {
//user.sendMessage("Click a player to use this command");
continue; continue;
} }
else if (command.startsWith("c:")) else if (command.startsWith("c:"))

View File

@ -170,5 +170,7 @@ public interface ISettings extends IConf
void setMetricsEnabled(boolean metricsEnabled); void setMetricsEnabled(boolean metricsEnabled);
public long getTeleportInvulnerability(); long getTeleportInvulnerability();
boolean isTeleportInvulnerability();
} }

View File

@ -382,6 +382,7 @@ public class Settings implements ISettings
config.load(); config.load();
noGodWorlds = new HashSet<String>(config.getStringList("no-god-in-worlds")); noGodWorlds = new HashSet<String>(config.getStringList("no-god-in-worlds"));
enabledSigns = _getEnabledSigns(); enabledSigns = _getEnabledSigns();
teleportInvulnerability = _isTeleportInvulnerability();
itemSpawnBl = _getItemSpawnBlacklist(); itemSpawnBl = _getItemSpawnBlacklist();
kits = _getKits(); kits = _getKits();
chatFormats.clear(); chatFormats.clear();
@ -746,9 +747,22 @@ public class Settings implements ISettings
this.metricsEnabled = metricsEnabled; this.metricsEnabled = metricsEnabled;
} }
private boolean teleportInvulnerability;
@Override @Override
public long getTeleportInvulnerability() public long getTeleportInvulnerability()
{ {
return config.getLong("teleport-invulnerability", 0) * 1000; return config.getLong("teleport-invulnerability", 0) * 1000;
} }
private boolean _isTeleportInvulnerability()
{
return (config.getLong("teleport-invulnerability", 0) > 0);
}
@Override
public boolean isTeleportInvulnerability()
{
return teleportInvulnerability;
}
} }