mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-26 11:07:55 +01:00
Minor cleanup to player events.
This commit is contained in:
parent
17058c220c
commit
c6f25c0df6
@ -227,15 +227,22 @@ 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();
|
||||||
|
boolean teleportInvulnerability = ess.getSettings().isTeleportInvulnerability();
|
||||||
|
if (backListener || teleportInvulnerability)
|
||||||
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
//There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports.
|
//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())
|
if (backListener && (event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND))
|
||||||
{
|
{
|
||||||
user.setLastLocation();
|
user.setLastLocation();
|
||||||
}
|
}
|
||||||
|
if (teleportInvulnerability)
|
||||||
|
{
|
||||||
user.enableInvulnerabilityAfterTeleport();
|
user.enableInvulnerabilityAfterTeleport();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
||||||
@ -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,25 +328,24 @@ 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)
|
||||||
|
{
|
||||||
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId()))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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:"))
|
||||||
|
@ -170,5 +170,7 @@ public interface ISettings extends IConf
|
|||||||
|
|
||||||
void setMetricsEnabled(boolean metricsEnabled);
|
void setMetricsEnabled(boolean metricsEnabled);
|
||||||
|
|
||||||
public long getTeleportInvulnerability();
|
long getTeleportInvulnerability();
|
||||||
|
|
||||||
|
boolean isTeleportInvulnerability();
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user