2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-08-21 18:02:01 +00:00
|
|
|
import java.util.List;
|
2012-08-31 17:52:40 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-11-25 04:49:57 +00:00
|
|
|
import org.bukkit.Material;
|
2012-04-24 10:30:31 +00:00
|
|
|
import org.bukkit.entity.Ageable;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.entity.Entity;
|
2012-09-28 19:35:13 +00:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2011-03-19 22:39:51 +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-05-22 00:29:47 +00:00
|
|
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
2012-09-08 13:55:37 +00:00
|
|
|
import org.bukkit.event.entity.*;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-09-28 19:35:13 +00:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
|
2012-01-20 04:20:37 +00:00
|
|
|
public class EssentialsEntityListener implements Listener
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2012-08-31 17:52:40 +00: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 17:33:07 +00: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 20:02:28 +00:00
|
|
|
|
|
|
|
if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
|
|
|
|
&& (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
|
2012-05-22 00:29:47 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-05-22 20:02:28 +00:00
|
|
|
|
2012-04-16 09:18:18 +00:00
|
|
|
if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
|
|
|
|
{
|
2012-03-27 19:14:38 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-09-28 19:45:56 +00:00
|
|
|
|
2012-09-08 13:51:03 +00:00
|
|
|
if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2012-05-22 20:02:28 +00: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 09:18:18 +00: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 18:02:01 +00:00
|
|
|
{
|
2012-04-16 09:18:18 +00:00
|
|
|
ess.scheduleSyncDelayedTask(
|
|
|
|
new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
attacker.getServer().dispatchCommand(attacker.getBase(), command.replaceAll("\\{player\\}", defender.getName()));
|
2012-08-31 17:52:40 +00:00
|
|
|
LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
|
2012-04-16 09:18:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-02 16:54:12 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
2011-08-21 18:02:01 +00:00
|
|
|
}
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-02 16:54:12 +00:00
|
|
|
}
|
2012-08-28 01:24:01 +00:00
|
|
|
else if (eAttack instanceof Player)
|
2012-03-02 16:54:12 +00:00
|
|
|
{
|
2012-08-28 01:24:01 +00:00
|
|
|
final User player = ess.getUser(eAttack);
|
|
|
|
player.updateActivity(true);
|
|
|
|
if (eDefend instanceof Ageable)
|
2011-11-25 04:49:57 +00:00
|
|
|
{
|
2012-08-28 01:24:01 +00: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 04:49:57 +00:00
|
|
|
}
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
2012-03-02 16:54:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 17:33:07 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityDamage(final EntityDamageEvent event)
|
|
|
|
{
|
2011-08-27 18:39:54 +00:00
|
|
|
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-08-27 18:39:54 +00: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 17:33:07 +00: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 04:20:37 +00: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 20:40:22 +00:00
|
|
|
|
2012-07-29 16:15:44 +00: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 17:33:07 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onFoodLevelChange(final FoodLevelChangeEvent event)
|
2011-10-09 18:59:06 +00:00
|
|
|
{
|
2011-09-22 08:47:39 +00:00
|
|
|
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
2011-10-09 18:59:06 +00:00
|
|
|
{
|
2011-10-04 08:05:04 +00:00
|
|
|
event.setCancelled(true);
|
2011-09-22 08:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-24 14:37:44 +00:00
|
|
|
|
2012-06-10 17:33:07 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2012-03-02 16:54:12 +00:00
|
|
|
public void onEntityRegainHealth(final EntityRegainHealthEvent event)
|
2011-10-24 14:37:44 +00:00
|
|
|
{
|
2011-10-25 15:21:56 +00:00
|
|
|
if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player
|
|
|
|
&& ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers())
|
2011-10-24 14:37:44 +00:00
|
|
|
{
|
2011-10-25 15:21:56 +00:00
|
|
|
event.setCancelled(true);
|
2011-10-24 14:37:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 19:35:13 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onPotionSplashEvent(final PotionSplashEvent event)
|
|
|
|
{
|
2012-09-28 19:45:56 +00:00
|
|
|
for (LivingEntity entity : event.getAffectedEntities())
|
2012-09-28 19:35:13 +00:00
|
|
|
{
|
2012-09-28 19:45:56 +00:00
|
|
|
if (entity instanceof Player)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(entity);
|
|
|
|
if (user.isGodModeEnabled())
|
|
|
|
{
|
|
|
|
event.setIntensity(entity, 0d);
|
|
|
|
}
|
|
|
|
}
|
2012-09-28 19:35:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 19:45:56 +00:00
|
|
|
}
|