1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
|
4 |
import java.net.InetSocketAddress; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
import java.util.logging.Level; |
8 |
|
9 |
import org.bukkit.plugin.PluginManager; |
10 |
import org.bukkit.plugin.java.JavaPlugin; |
11 |
|
12 |
import com.sun.net.httpserver.HttpServer; |
13 |
|
14 |
import dk.thoerup.bukkit.hoeruputils.chests.AdvancedChest; |
15 |
import dk.thoerup.bukkit.hoeruputils.chests.ChestBean; |
16 |
import dk.thoerup.bukkit.hoeruputils.creative.GeneralContractorCommands; |
17 |
import dk.thoerup.bukkit.hoeruputils.message.MessageBean; |
18 |
import dk.thoerup.bukkit.hoeruputils.message.MessageWrapper; |
19 |
import dk.thoerup.bukkit.hoeruputils.secretdoor.DoorBlockListener; |
20 |
import dk.thoerup.bukkit.hoeruputils.web.BanListener; |
21 |
import dk.thoerup.bukkit.hoeruputils.web.StatusListener; |
22 |
import dk.thoerup.bukkit.hoeruputils.web.WebUser; |
23 |
import dk.thoerup.bukkit.hoeruputils.web.WebUserCommand; |
24 |
import io.ebean.Ebean; |
25 |
|
26 |
@SuppressWarnings("restriction") |
27 |
public class HoerupUtilsPlugin extends JavaPlugin { |
28 |
|
29 |
@Override |
30 |
public void onDisable() { |
31 |
if ( server != null ) { |
32 |
server.stop( 0 ); |
33 |
} |
34 |
} |
35 |
|
36 |
MessageWrapper messageWrapper; |
37 |
HttpServer server = null; |
38 |
|
39 |
|
40 |
@Override |
41 |
public void onEnable() { |
42 |
System.out.println("Loading HoerupUtils plugin"); |
43 |
|
44 |
Ebean.getDefaultServer(); |
45 |
|
46 |
getCommand("whereis").setExecutor(new WhereisCommand(getServer())); |
47 |
//getCommand("mapgen").setExecutor(new MapgenCommand(this)); |
48 |
getCommand("eternalday").setExecutor(new EternalDayCommand(this)); |
49 |
getCommand("getpos").setExecutor( new GetposCommand() ); |
50 |
getCommand("msg").setExecutor( new MsgCommand( this ) ); |
51 |
// getCommand("tp").setExecutor( new TeleportCommand() ); |
52 |
|
53 |
getCommand("wall").setExecutor( new WallCommand() ); |
54 |
getCommand("weather").setExecutor( new WeatherCommand() ); |
55 |
|
56 |
getCommand("gc").setExecutor( new GcCommand() ); |
57 |
|
58 |
|
59 |
HomeCommand home = new HomeCommand(this); |
60 |
getCommand("home").setExecutor( home ); |
61 |
getCommand("sethome").setExecutor( home ); |
62 |
getCommand("ophome").setExecutor( home ); |
63 |
|
64 |
DiverCommand diver = new DiverCommand(this ); |
65 |
getCommand("diver").setExecutor( diver ); |
66 |
|
67 |
getCommand("opkill").setExecutor( new OpkillCommand() ); |
68 |
|
69 |
GeneralContractorCommands generalContractor = new GeneralContractorCommands(); |
70 |
getCommand("replay").setExecutor( generalContractor ); |
71 |
getCommand("levelarea").setExecutor( generalContractor ); |
72 |
getCommand("fillarea").setExecutor( generalContractor ); |
73 |
getCommand("levelandfillarea").setExecutor( generalContractor ); |
74 |
|
75 |
getCommand("slopearea").setExecutor( generalContractor ); |
76 |
getCommand("setsurface").setExecutor( generalContractor ); |
77 |
getCommand("platform").setExecutor( generalContractor ); |
78 |
getCommand("cylinder").setExecutor( generalContractor ); |
79 |
getCommand("createcave").setExecutor( generalContractor ); |
80 |
getCommand("spawn").setExecutor( new SpawnCommand() ); |
81 |
|
82 |
getCommand("template").setExecutor( new TemplateCommand(this) ); |
83 |
getCommand("regenerate").setExecutor( new RegenerateCommand() ); |
84 |
|
85 |
|
86 |
LogintimeHandler logintimeHandler = new LogintimeHandler( this.getDataFolder() ); |
87 |
|
88 |
|
89 |
PluginManager pm = getServer().getPluginManager(); |
90 |
|
91 |
|
92 |
MotdHandler motd = new MotdHandler(this); |
93 |
getCommand("motd").setExecutor( motd ); |
94 |
pm.registerEvents( motd, this); |
95 |
|
96 |
WayPoint wp = new WayPoint(this); |
97 |
getCommand("waypoint").setExecutor( wp ); |
98 |
getCommand("setwaypoint").setExecutor( wp ); |
99 |
pm.registerEvents( wp, this); |
100 |
|
101 |
|
102 |
pm.registerEvents(logintimeHandler, this); |
103 |
pm.registerEvents(logintimeHandler, this); |
104 |
|
105 |
|
106 |
pm.registerEvents(diver, this); |
107 |
|
108 |
pm.registerEvents(new EndermanStopper(), this); |
109 |
|
110 |
Jail jail = new Jail(this); |
111 |
pm.registerEvents(jail, this); |
112 |
getCommand("jail").setExecutor( jail ); |
113 |
|
114 |
StickyChunk chunks = new StickyChunk(); |
115 |
pm.registerEvents(chunks, this); |
116 |
getCommand("stickychunk").setExecutor(chunks); |
117 |
|
118 |
Mute mute = new Mute(this); |
119 |
pm.registerEvents(mute, this); |
120 |
getCommand("mute").setExecutor(mute); |
121 |
getCommand("unmute").setExecutor(mute); |
122 |
|
123 |
|
124 |
|
125 |
messageWrapper = new MessageWrapper(this); |
126 |
pm.registerEvents( messageWrapper, this); |
127 |
|
128 |
AdvancedChest locked = new AdvancedChest(this); |
129 |
getCommand("chest").setExecutor(locked); |
130 |
pm.registerEvents( locked, this); |
131 |
|
132 |
|
133 |
getCommand("webuser").setExecutor( new WebUserCommand(this) ); |
134 |
|
135 |
|
136 |
//register web plugins |
137 |
//pm.registerEvent(Event.Type.CUSTOM_EVENT, new StatusListener(getServer(), logintimeHandler.getConfig(), home.getConfig() ), Priority.Normal, this); |
138 |
//pm.registerEvent(Event.Type.CUSTOM_EVENT, new MessageListener(getServer()), Priority.Normal, this); |
139 |
|
140 |
/*try { |
141 |
try { |
142 |
//først probes om klassen i det hele taget findes |
143 |
Class.forName("de.codeinfection.quickwango.ApiBukkit.ApiServer.ApiController"); //if it fails it throws an exception |
144 |
WebLoader.getInstance().load(this, logintimeHandler.getConfig(), home.getConfig()); |
145 |
|
146 |
getLogger().info("ApiBukkit found, status listener registered"); |
147 |
|
148 |
} catch (ClassNotFoundException e) { |
149 |
getLogger().warning("Could not find ApiBukkit - web status is disabled" ); |
150 |
} |
151 |
} catch (Throwable e) { //instead of ClassNotFoundException + NoSuchMethodException + InvocationTargetException + IllegalAccessException |
152 |
getLogger().warning("Could not find ApiBukkit - web status is disabled (" + e.getClass().getName() + ":" + e.getMessage() + ")" ); |
153 |
}*/ |
154 |
|
155 |
try { |
156 |
InetSocketAddress adr = new InetSocketAddress("127.0.0.1", 9999); |
157 |
server = HttpServer.create(adr, 20); |
158 |
server.createContext("/bans", new BanListener(this, getServer()) ); |
159 |
server.createContext("/webstatus", new StatusListener(this, getServer(),logintimeHandler.getConfig(), home.getConfig()) ); |
160 |
server.start(); |
161 |
|
162 |
} catch(Exception e) { |
163 |
getLogger().log(Level.SEVERE, "Error loading webserver", e); |
164 |
|
165 |
} |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
DoorBlockListener secretDoor = new DoorBlockListener(this); |
171 |
pm.registerEvents(secretDoor, this); |
172 |
pm.registerEvents(secretDoor.getPlayerListener(), this); |
173 |
} |
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
public MessageWrapper getMessageWrapper() { |
180 |
return messageWrapper; |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
/* |
187 |
private void deprecated() { |
188 |
|
189 |
getCommand("stoner").setExecutor( new StonerCommand() ); |
190 |
getCommand("spawn").setExecutor( new SpawnCommand() ); |
191 |
getCommand("boom").setExecutor( new BoomCommand(this) ); |
192 |
getCommand("grass").setExecutor(new GrassCommand()); |
193 |
|
194 |
getCommand("zapme").setExecutor( new ZapmeCommand() ); |
195 |
getCommand("zap").setExecutor( new ZapCommand() ); |
196 |
|
197 |
|
198 |
PowerMiner powerMiner = new PowerMiner(); |
199 |
pm.registerEvent(Event.Type.BLOCK_DAMAGE, powerMiner, Priority.Normal, this); |
200 |
pm.registerEvent(Event.Type.PLAYER_QUIT, powerMiner.getPlayerQuitListener(), Priority.Normal, this); |
201 |
getCommand("powerminer").setExecutor(powerMiner); |
202 |
|
203 |
SuperMiner superMiner = new SuperMiner(); |
204 |
pm.registerEvent(Event.Type.BLOCK_DAMAGE, superMiner, Priority.Normal, this); |
205 |
pm.registerEvent(Event.Type.PLAYER_QUIT, superMiner.getPlayerQuitListener(), Priority.Normal, this); |
206 |
getCommand("superminer").setExecutor(superMiner); |
207 |
|
208 |
|
209 |
//pm.registerEvent(Event.Type.PROJECTILE_HIT, new ExplosiveSnowballs(), Priority.Normal, this); |
210 |
|
211 |
//pm.registerEvent(Event.Type.PLAYER_RESPAWN, new RespawnHandler(this), Priority.Normal, this); |
212 |
//pm.registerEvent(Event.Type.ENTITY_DEATH, new RespawnHandler.PlayerDeathListener(this.getDataFolder()), Priority.Normal, this); |
213 |
|
214 |
|
215 |
} |
216 |
*/ |
217 |
|
218 |
} |