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;
|
2011-10-25 16:21:56 +01:00
|
|
|
import java.util.logging.Logger;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.entity.Entity;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-10-24 15:37:44 +01:00
|
|
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.event.entity.*;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class EssentialsEntityListener extends EntityListener
|
|
|
|
{
|
2011-10-25 16:21:56 +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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityDamage(EntityDamageEvent event)
|
|
|
|
{
|
2011-04-04 01:26:45 +00:00
|
|
|
if (event instanceof EntityDamageByEntityEvent)
|
|
|
|
{
|
|
|
|
EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
|
|
|
|
Entity eAttack = edEvent.getDamager();
|
|
|
|
Entity eDefend = edEvent.getEntity();
|
|
|
|
if (eDefend instanceof Player && eAttack instanceof Player)
|
|
|
|
{
|
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
|
|
|
User defender = ess.getUser(eDefend);
|
|
|
|
User attacker = ess.getUser(eAttack);
|
2011-10-23 21:51:38 +01:00
|
|
|
attacker.updateActivity(true);
|
2011-04-04 01:26:45 +00:00
|
|
|
ItemStack is = attacker.getItemInHand();
|
2011-08-21 19:02:01 +01:00
|
|
|
List<String> commandList = attacker.getPowertool(is);
|
2011-08-24 03:09:27 +01:00
|
|
|
if (commandList != null && !commandList.isEmpty())
|
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
|
|
|
{
|
2011-08-24 03:09:27 +01:00
|
|
|
for (String command : commandList)
|
2011-08-21 19:02:01 +01:00
|
|
|
{
|
2011-08-24 03:09:27 +01:00
|
|
|
|
|
|
|
if (command != null && !command.isEmpty())
|
|
|
|
{
|
|
|
|
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-21 19:02:01 +01:00
|
|
|
}
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityCombust(EntityCombustEvent event)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-10-09 20:59:06 +02:00
|
|
|
public void onEntityDeath(final EntityDeathEvent event)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-10-09 20:59:06 +02:00
|
|
|
if (event instanceof PlayerDeathEvent)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-10-09 20:59:06 +02:00
|
|
|
final PlayerDeathEvent pdevent = (PlayerDeathEvent)event;
|
|
|
|
final User user = ess.getUser(pdevent.getEntity());
|
2011-05-08 23:38:40 +00:00
|
|
|
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back"))
|
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
|
|
|
user.setLastLocation();
|
2011-11-21 02:55:26 +01:00
|
|
|
user.sendMessage(_("backAfterDeath"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2011-10-09 20:59:06 +02:00
|
|
|
if (!ess.getSettings().areDeathMessagesEnabled())
|
|
|
|
{
|
|
|
|
pdevent.setDeathMessage("");
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-22 10:47:39 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFoodLevelChange(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
|
|
|
|
2011-10-24 17:46:53 +01:00
|
|
|
@Override
|
|
|
|
public void onEntityRegainHealth(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
|
|
|
}
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|