blob: 4c4a60997557ef721cb26c681947419a1577babd (
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.earth2me.essentials.spawn;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class EssentialsSpawnPlayerListener extends PlayerListener
{
private final transient IEssentials ess;
private final transient SpawnStorage spawns;
public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns)
{
super();
this.ess = ess;
this.spawns = spawns;
}
@Override
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
final IUser user = ess.getUser(event.getPlayer());
if (ess.getSettings().getRespawnAtHome())
{
Location home = user.getHome(user.getLocation());
if (home == null)
{
home = user.getBedSpawnLocation();
}
if (home != null)
{
event.setRespawnLocation(home);
return;
}
}
final Location spawn = spawns.getSpawn(user.getGroup());
if (spawn != null)
{
event.setRespawnLocation(spawn);
}
}
@Override
public void onPlayerJoin(final PlayerJoinEvent event)
{
final IUser user = ess.getUser(event.getPlayer());
if (!user.isNew() || user.getBedSpawnLocation() != null)
{
return;
}
user.setNew(false);
if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
{
ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user));
}
if (ess.getSettings().getAnnounceNewPlayers())
{
ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
}
}
private class NewPlayerTeleport implements Runnable
{
private final transient IUser user;
public NewPlayerTeleport(final IUser user)
{
this.user = user;
}
@Override
public void run()
{
try
{
Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn());
if (spawn != null)
{
user.getTeleport().now(spawn, false, TeleportCause.PLUGIN);
}
}
catch (Exception ex)
{
Bukkit.getLogger().log(Level.WARNING, _("teleportNewPlayerError"), ex);
}
}
}
}
|