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