blob: da8c165cb60f8e706312a28f6d7134a8314fb3b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package com.earth2me.essentials;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class JailPlayerListener extends PlayerListener
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final IEssentials ess;
public JailPlayerListener(IEssentials parent)
{
this.ess = parent;
}
@Override
public void onPlayerInteract(PlayerInteractEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (user.isJailed())
{
event.setCancelled(true);
}
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
{
try
{
event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
}
}
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
{
return;
}
try
{
event.setTo(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
LOGGER.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
}
user.sendMessage(Util.i18n("jailMessage"));
}
@Override
public void onPlayerJoin(final PlayerJoinEvent event)
{
User u = ess.getUser(event.getPlayer());
if (u.isJailed())
{
try
{
ess.getJail().sendToJail(u, u.getJail());
}
catch (Exception ex)
{
LOGGER.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
}
u.sendMessage(Util.i18n("jailMessage"));
}
}
}
|