2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-11-21 02:55:26 +01:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-08-21 19:02:01 +01:00
|
|
|
import java.util.List;
|
2012-08-31 18:52:40 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-11-25 05:49:57 +01:00
|
|
|
import org.bukkit.Material;
|
2012-04-24 20:30:31 +10:00
|
|
|
import org.bukkit.entity.Ageable;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.entity.Entity;
|
2012-09-28 20:35:13 +01:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2011-03-19 22:39:51 +00: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-05-22 01:29:47 +01:00
|
|
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
2012-09-08 14:55:37 +01:00
|
|
|
import org.bukkit.event.entity.*;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-09-28 20:35:13 +01:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
public class EssentialsEntityListener implements Listener
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2012-08-31 18:52:40 +01:00
|
|
|
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
2011-06-01 10:40:12 +00:00
|
|
|
private final IEssentials ess;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2011-06-01 10:40:12 +00:00
|
|
|
public EssentialsEntityListener(IEssentials ess)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
this.ess = ess;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 18:33:07 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityDamage(final EntityDamageByEntityEvent event)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2012-03-02 16:54:12 +00:00
|
|
|
final Entity eAttack = event.getDamager();
|
|
|
|
final Entity eDefend = event.getEntity();
|
|
|
|
if (eDefend instanceof Player && eAttack instanceof Player)
|
2011-04-04 01:26:45 +00:00
|
|
|
{
|
2012-03-02 16:54:12 +00:00
|
|
|
final User defender = ess.getUser(eDefend);
|
|
|
|
final User attacker = ess.getUser(eAttack);
|
2012-05-22 21:02:28 +01:00
|
|
|
|
|
|
|
if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
|
|
|
|
&& (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
|
2012-05-22 01:29:47 +01:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-05-22 21:02:28 +01:00
|
|
|
|
2012-04-16 10:18:18 +01:00
|
|
|
if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
|
|
|
|
{
|
2012-03-27 21:14:38 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-09-28 20:45:56 +01:00
|
|
|
|
2012-09-08 14:51:03 +01:00
|
|
|
if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-05-22 21:02:28 +01:00
|
|
|
|
2012-03-02 16:54:12 +00:00
|
|
|
attacker.updateActivity(true);
|
|
|
|
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
|
|
|
|
if (commandList != null && !commandList.isEmpty())
|
2011-04-04 01:26:45 +00:00
|
|
|
{
|
2012-04-16 10:18:18 +01:00
|
|
|
for (final String command : commandList)
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
{
|
2012-03-02 16:54:12 +00:00
|
|
|
if (command != null && !command.isEmpty())
|
2011-08-21 19:02:01 +01:00
|
|
|
{
|
2012-04-16 10:18:18 +01:00
|
|
|
ess.scheduleSyncDelayedTask(
|
|
|
|
new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
attacker.getServer().dispatchCommand(attacker.getBase(), command.replaceAll("\\{player\\}", defender.getName()));
|
2012-08-31 18:52:40 +01:00
|
|
|
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
|
2012-04-16 10:18:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-02 16:54:12 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
2011-08-21 19:02:01 +01:00
|
|
|
}
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-02 16:54:12 +00:00
|
|
|
}
|
2012-08-28 02:24:01 +01:00
|
|
|
else if (eAttack instanceof Player)
|
2012-03-02 16:54:12 +00:00
|
|
|
{
|
2012-08-28 02:24:01 +01:00
|
|
|
final User player = ess.getUser(eAttack);
|
|
|
|
player.updateActivity(true);
|
|
|
|
if (eDefend instanceof Ageable)
|
2011-11-25 05:49:57 +01:00
|
|
|
{
|
2012-08-28 02:24:01 +01:00
|
|
|
final ItemStack hand = player.getItemInHand();
|
|
|
|
if (hand != null && hand.getType() == Material.MILK_BUCKET)
|
|
|
|
{
|
|
|
|
((Ageable)eDefend).setBaby();
|
|
|
|
hand.setType(Material.BUCKET);
|
|
|
|
player.setItemInHand(hand);
|
|
|
|
player.updateInventory();
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2011-11-25 05:49:57 +01:00
|
|
|
}
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
2012-03-02 16:54:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 18:33:07 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityDamage(final EntityDamageEvent event)
|
|
|
|
{
|
2011-08-27 20:39:54 +02:00
|
|
|
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-08-27 20:39:54 +02:00
|
|
|
final Player player = (Player)event.getEntity();
|
|
|
|
player.setFireTicks(0);
|
|
|
|
player.setRemainingAir(player.getMaximumAir());
|
|
|
|
event.setCancelled(true);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 18:33:07 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityCombust(final EntityCombustEvent event)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onPlayerDeathEvent(final PlayerDeathEvent event)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2012-03-02 16:54:12 +00:00
|
|
|
final User user = ess.getUser(event.getEntity());
|
|
|
|
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back"))
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2012-03-02 16:54:12 +00:00
|
|
|
user.setLastLocation();
|
|
|
|
user.sendMessage(_("backAfterDeath"));
|
|
|
|
}
|
|
|
|
if (!ess.getSettings().areDeathMessagesEnabled())
|
|
|
|
{
|
|
|
|
event.setDeathMessage("");
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-25 21:40:22 +01:00
|
|
|
|
2012-07-29 17:15:44 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onPlayerDeathExpEvent(final PlayerDeathEvent event)
|
|
|
|
{
|
|
|
|
final User user = ess.getUser(event.getEntity());
|
|
|
|
if (user.isAuthorized("essentials.keepxp"))
|
|
|
|
{
|
|
|
|
event.setKeepLevel(true);
|
|
|
|
event.setDroppedExp(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 18:33:07 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onFoodLevelChange(final FoodLevelChangeEvent event)
|
2011-10-09 20:59:06 +02:00
|
|
|
{
|
2011-09-22 10:47:39 +02:00
|
|
|
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
2011-10-09 20:59:06 +02:00
|
|
|
{
|
2011-10-04 09:05:04 +01:00
|
|
|
event.setCancelled(true);
|
2011-09-22 10:47:39 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-24 15:37:44 +01:00
|
|
|
|
2012-06-10 18:33:07 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityRegainHealth(final EntityRegainHealthEvent event)
|
2011-10-24 15:37:44 +01:00
|
|
|
{
|
2011-10-25 16:21:56 +01:00
|
|
|
if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player
|
|
|
|
&& ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers())
|
2011-10-24 15:37:44 +01:00
|
|
|
{
|
2011-10-25 16:21:56 +01:00
|
|
|
event.setCancelled(true);
|
2011-10-24 15:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 20:35:13 +01:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onPotionSplashEvent(final PotionSplashEvent event)
|
|
|
|
{
|
2012-09-28 20:45:56 +01:00
|
|
|
for (LivingEntity entity : event.getAffectedEntities())
|
2012-09-28 20:35:13 +01:00
|
|
|
{
|
2012-09-28 20:45:56 +01:00
|
|
|
if (entity instanceof Player)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(entity);
|
|
|
|
if (user.isGodModeEnabled())
|
|
|
|
{
|
|
|
|
event.setIntensity(entity, 0d);
|
|
|
|
}
|
|
|
|
}
|
2012-09-28 20:35:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 20:45:56 +01:00
|
|
|
}
|