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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
package net.ess3.bukkit;
import java.io.File;
import java.util.logging.Level;
import net.ess3.Essentials;
import static net.ess3.I18n._;
import net.ess3.api.IEssentials;
import net.ess3.api.IPlugin;
import net.ess3.listener.EssentialsBlockListener;
import net.ess3.listener.EssentialsEntityListener;
import net.ess3.listener.EssentialsPlayerListener;
import net.ess3.listener.EssentialsPluginListener;
import net.ess3.metrics.MetricsListener;
import net.ess3.metrics.MetricsStarter;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
public class BukkitPlugin extends JavaPlugin implements IPlugin
{
private Essentials ess;
@Override
public void onEnable()
{
final PluginManager pm = this.getServer().getPluginManager();
//pm.registerEvents(getServer(), this);
ess = new Essentials(getServer(), getLogger(), this);
if (VersionCheck.checkVersion(this))
{
try
{
ess.onEnable();
}
catch (RuntimeException ex)
{
if (pm.getPlugin("EssentialsUpdate") == null)
{
getLogger().log(Level.SEVERE, _("essentialsHelp1"));
}
else
{
getLogger().log(Level.SEVERE, _("essentialsHelp2"));
}
getLogger().log(Level.SEVERE, ex.toString());
pm.registerEvents(new Listener()
{
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event)
{
event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
}
}, this);
for (Player player : getServer().getOnlinePlayers())
{
player.sendMessage("Essentials failed to load, read the log file.");
}
this.setEnabled(false);
return;
}
}
else
{
this.setEnabled(false);
return;
}
final EssentialsPluginListener serverListener = new EssentialsPluginListener(ess);
pm.registerEvents(serverListener, this);
ess.addReloadListener(serverListener);
final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(ess);
pm.registerEvents(playerListener, this);
final EssentialsBlockListener blockListener = new EssentialsBlockListener(ess);
pm.registerEvents(blockListener, this);
final EssentialsEntityListener entityListener = new EssentialsEntityListener(ess);
pm.registerEvents(entityListener, this);
final MetricsStarter metricsStarter = new MetricsStarter(ess);
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
{
getServer().getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
}
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
{
final MetricsListener metricsListener = new MetricsListener(ess, metricsStarter);
pm.registerEvents(metricsListener, this);
}
}
@Override
public void onDisable()
{
if (ess != null)
{
ess.onDisable();
}
}
@Override
public boolean onCommand(final org.bukkit.command.CommandSender sender, final Command command, final String label, final String[] args)
{
return ess.getCommandHandler().handleCommand(sender, command, label, args);
}
@Override
public int scheduleAsyncDelayedTask(final Runnable run)
{
return getServer().getScheduler().scheduleAsyncDelayedTask(this, run);
}
@Override
public int scheduleSyncDelayedTask(final Runnable run)
{
return getServer().getScheduler().scheduleSyncDelayedTask(this, run);
}
@Override
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
{
return getServer().getScheduler().scheduleSyncDelayedTask(this, run, delay);
}
@Override
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
{
return getServer().getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
}
@Override
public int scheduleAsyncRepeatingTask(final Runnable run, final long delay, final long period)
{
return getServer().getScheduler().scheduleAsyncRepeatingTask(this, run, delay, period);
}
@Override
public File getRootFolder()
{
return getDataFolder().getParentFile().getParentFile();
}
@Override
public void cancelTask(final int taskId)
{
getServer().getScheduler().cancelTask(taskId);
}
@Override
public String getVersion()
{
return getDescription().getVersion();
}
@Override
public Class getClassByName(final String name)
{
final JavaPluginLoader jpl = (JavaPluginLoader)this.getPluginLoader();
return jpl.getClassByName(name);
}
@Override
public Location callRespawnEvent(Player player, Location loc, boolean bedSpawn)
{
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, loc, bedSpawn);
getServer().getPluginManager().callEvent(pre);
return pre.getRespawnLocation();
}
@Override
public void callSuicideEvent(Player player)
{
EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
getServer().getPluginManager().callEvent(ede);
}
@Override
public IEssentials getEssentials()
{
return ess;
}
}
|