blob: 083fd66a5555f27cc29d32bd761fee0e3974323a (
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
package com.earth2me.essentials.spawn;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextPager;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class EssentialsSpawnPlayerListener implements Listener
{
private final transient IEssentials ess;
private final transient SpawnStorage spawns;
private static final Logger LOGGER = Bukkit.getLogger();
public EssentialsSpawnPlayerListener(final IEssentials ess, final SpawnStorage spawns)
{
super();
this.ess = ess;
this.spawns = spawns;
}
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (ess.getSettings().getRespawnAtHome())
{
Location home;
final Location bed = user.getBedSpawnLocation();
if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
{
home = bed;
}
else
{
home = user.getHome(user.getLocation());
}
if (home != null)
{
event.setRespawnLocation(home);
return;
}
}
final Location spawn = spawns.getSpawn(user.getGroup());
if (spawn != null)
{
event.setRespawnLocation(spawn);
}
}
public void onPlayerJoin(final PlayerJoinEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (user.hasPlayedBefore())
{
LOGGER.log(Level.FINE, "Old player join");
return;
}
if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
{
ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
}
if (ess.getSettings().getAnnounceNewPlayers())
{
final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
final SimpleTextPager pager = new SimpleTextPager(output);
ess.broadcastMessage(user, pager.getString(0));
}
LOGGER.log(Level.FINE, "New player join");
}
private class NewPlayerTeleport implements Runnable
{
private final transient User user;
public NewPlayerTeleport(final User user)
{
this.user = user;
}
@Override
public void run()
{
if (user.getBase() instanceof OfflinePlayer)
{
return;
}
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);
}
}
}
}
|