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