/Essentials/test/com/earth2me/essentials/FakeServer.java

https://github.com/speedycuban/Essentials · Java · 448 lines · 375 code · 73 blank · 0 comment · 7 complexity · 69d0adc2ac0a1f5da857364fdc080d90 MD5 · raw file

  1. package com.earth2me.essentials;
  2. import com.avaje.ebean.config.ServerConfig;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import java.util.UUID;
  8. import java.util.concurrent.Callable;
  9. import java.util.concurrent.Future;
  10. import java.util.logging.Logger;
  11. import org.bukkit.Location;
  12. import org.bukkit.Server;
  13. import org.bukkit.World;
  14. import org.bukkit.World.Environment;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.command.PluginCommand;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.generator.ChunkGenerator;
  19. import org.bukkit.inventory.Recipe;
  20. import org.bukkit.map.MapView;
  21. import org.bukkit.plugin.Plugin;
  22. import org.bukkit.plugin.PluginManager;
  23. import org.bukkit.plugin.ServicesManager;
  24. import org.bukkit.scheduler.BukkitScheduler;
  25. import org.bukkit.scheduler.BukkitTask;
  26. import org.bukkit.scheduler.BukkitWorker;
  27. public class FakeServer implements Server
  28. {
  29. private List<Player> players = new ArrayList<Player>();
  30. private final List<World> worlds = new ArrayList<World>();
  31. public String getName()
  32. {
  33. return "Test Server";
  34. }
  35. public String getVersion()
  36. {
  37. return "1.0";
  38. }
  39. public Player[] getOnlinePlayers()
  40. {
  41. return players.toArray(new Player[0]);
  42. }
  43. public void setOnlinePlayers(List<Player> players)
  44. {
  45. this.players = players;
  46. }
  47. public int getMaxPlayers()
  48. {
  49. return 100;
  50. }
  51. public int getPort()
  52. {
  53. return 25565;
  54. }
  55. public String getIp()
  56. {
  57. return "127.0.0.1";
  58. }
  59. public String getServerName()
  60. {
  61. return "Test Server";
  62. }
  63. public String getServerId()
  64. {
  65. return "Test Server";
  66. }
  67. public int broadcastMessage(String string)
  68. {
  69. int i = 0;
  70. for (Player player : players)
  71. {
  72. player.sendMessage(string);
  73. i++;
  74. }
  75. return i;
  76. }
  77. public String getUpdateFolder()
  78. {
  79. return "update";
  80. }
  81. public Player getPlayer(String string)
  82. {
  83. for (Player player : players)
  84. {
  85. if (player.getName().equalsIgnoreCase(string))
  86. {
  87. return player;
  88. }
  89. }
  90. return null;
  91. }
  92. public List<Player> matchPlayer(String string)
  93. {
  94. List<Player> matches = new ArrayList<Player>();
  95. for (Player player : players)
  96. {
  97. if (player.getName().substring(0, Math.min(player.getName().length(), string.length())).equalsIgnoreCase(string))
  98. {
  99. matches.add(player);
  100. }
  101. }
  102. return matches;
  103. }
  104. public PluginManager getPluginManager()
  105. {
  106. throw new UnsupportedOperationException("Not supported yet.");
  107. }
  108. public BukkitScheduler getScheduler()
  109. {
  110. return new BukkitScheduler() {
  111. @Override
  112. public int scheduleSyncDelayedTask(Plugin plugin, Runnable r, long l)
  113. {
  114. throw new UnsupportedOperationException("Not supported yet.");
  115. }
  116. @Override
  117. public int scheduleSyncDelayedTask(Plugin plugin, Runnable r)
  118. {
  119. throw new UnsupportedOperationException("Not supported yet.");
  120. }
  121. @Override
  122. public int scheduleSyncRepeatingTask(Plugin plugin, Runnable r, long l, long l1)
  123. {
  124. throw new UnsupportedOperationException("Not supported yet.");
  125. }
  126. @Override
  127. public int scheduleAsyncDelayedTask(Plugin plugin, Runnable r, long l)
  128. {
  129. throw new UnsupportedOperationException("Not supported yet.");
  130. }
  131. @Override
  132. public int scheduleAsyncDelayedTask(Plugin plugin, Runnable r)
  133. {
  134. r.run();
  135. return 0;
  136. }
  137. @Override
  138. public int scheduleAsyncRepeatingTask(Plugin plugin, Runnable r, long l, long l1)
  139. {
  140. throw new UnsupportedOperationException("Not supported yet.");
  141. }
  142. @Override
  143. public <T> Future<T> callSyncMethod(Plugin plugin, Callable<T> clbl)
  144. {
  145. throw new UnsupportedOperationException("Not supported yet.");
  146. }
  147. @Override
  148. public void cancelTask(int i)
  149. {
  150. throw new UnsupportedOperationException("Not supported yet.");
  151. }
  152. @Override
  153. public void cancelTasks(Plugin plugin)
  154. {
  155. throw new UnsupportedOperationException("Not supported yet.");
  156. }
  157. @Override
  158. public void cancelAllTasks()
  159. {
  160. throw new UnsupportedOperationException("Not supported yet.");
  161. }
  162. @Override
  163. public boolean isCurrentlyRunning(int i)
  164. {
  165. throw new UnsupportedOperationException("Not supported yet.");
  166. }
  167. @Override
  168. public boolean isQueued(int i)
  169. {
  170. throw new UnsupportedOperationException("Not supported yet.");
  171. }
  172. @Override
  173. public List<BukkitWorker> getActiveWorkers()
  174. {
  175. throw new UnsupportedOperationException("Not supported yet.");
  176. }
  177. @Override
  178. public List<BukkitTask> getPendingTasks()
  179. {
  180. throw new UnsupportedOperationException("Not supported yet.");
  181. }
  182. };
  183. }
  184. public ServicesManager getServicesManager()
  185. {
  186. throw new UnsupportedOperationException("Not supported yet.");
  187. }
  188. public List<World> getWorlds()
  189. {
  190. return worlds;
  191. }
  192. public World createWorld(String string, Environment e)
  193. {
  194. World w = new FakeWorld(string, e);
  195. worlds.add(w);
  196. return w;
  197. }
  198. public World createWorld(String string, Environment e, long l)
  199. {
  200. World w = new FakeWorld(string, e);
  201. worlds.add(w);
  202. return w;
  203. }
  204. public World getWorld(String string)
  205. {
  206. for (World world : worlds)
  207. {
  208. if (world.getName().equalsIgnoreCase(string)) {
  209. return world;
  210. }
  211. }
  212. return null;
  213. }
  214. public void reload()
  215. {
  216. }
  217. public Logger getLogger()
  218. {
  219. return Logger.getLogger("Minecraft");
  220. }
  221. public PluginCommand getPluginCommand(String string)
  222. {
  223. throw new UnsupportedOperationException("Not supported yet.");
  224. }
  225. public void savePlayers()
  226. {
  227. }
  228. public boolean dispatchCommand(CommandSender cs, String string)
  229. {
  230. throw new UnsupportedOperationException("Not supported yet.");
  231. }
  232. public void configureDbConfig(ServerConfig sc)
  233. {
  234. throw new UnsupportedOperationException("Not supported yet.");
  235. }
  236. public boolean addRecipe(Recipe recipe)
  237. {
  238. throw new UnsupportedOperationException("Not supported yet.");
  239. }
  240. public void addPlayer(Player base1)
  241. {
  242. players.add(base1);
  243. }
  244. public OfflinePlayer createPlayer(String name, IEssentials ess)
  245. {
  246. OfflinePlayer player = new OfflinePlayer(name, ess);
  247. player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0));
  248. return player;
  249. }
  250. public World createWorld(String string, Environment e, ChunkGenerator cg)
  251. {
  252. throw new UnsupportedOperationException("Not supported yet.");
  253. }
  254. public World createWorld(String string, Environment e, long l, ChunkGenerator cg)
  255. {
  256. throw new UnsupportedOperationException("Not supported yet.");
  257. }
  258. public boolean unloadWorld(String string, boolean bln)
  259. {
  260. throw new UnsupportedOperationException("Not supported yet.");
  261. }
  262. public boolean unloadWorld(World world, boolean bln)
  263. {
  264. throw new UnsupportedOperationException("Not supported yet.");
  265. }
  266. public Map<String, String[]> getCommandAliases()
  267. {
  268. throw new UnsupportedOperationException("Not supported yet.");
  269. }
  270. public int getSpawnRadius()
  271. {
  272. throw new UnsupportedOperationException("Not supported yet.");
  273. }
  274. public void setSpawnRadius(int i)
  275. {
  276. throw new UnsupportedOperationException("Not supported yet.");
  277. }
  278. public boolean getOnlineMode()
  279. {
  280. throw new UnsupportedOperationException("Not supported yet.");
  281. }
  282. public World getWorld(long l)
  283. {
  284. throw new UnsupportedOperationException("Not supported yet.");
  285. }
  286. public World getWorld(UUID uuid)
  287. {
  288. throw new UnsupportedOperationException("Not supported yet.");
  289. }
  290. @Override
  291. public int getViewDistance()
  292. {
  293. throw new UnsupportedOperationException("Not supported yet.");
  294. }
  295. @Override
  296. public boolean getAllowNether()
  297. {
  298. throw new UnsupportedOperationException("Not supported yet.");
  299. }
  300. @Override
  301. public boolean hasWhitelist()
  302. {
  303. throw new UnsupportedOperationException("Not supported yet.");
  304. }
  305. @Override
  306. public MapView getMap(short s)
  307. {
  308. throw new UnsupportedOperationException("Not supported yet.");
  309. }
  310. @Override
  311. public MapView createMap(World world)
  312. {
  313. throw new UnsupportedOperationException("Not supported yet.");
  314. }
  315. @Override
  316. public boolean getAllowFlight()
  317. {
  318. throw new UnsupportedOperationException("Not supported yet.");
  319. }
  320. @Override
  321. public void setWhitelist(boolean bln)
  322. {
  323. throw new UnsupportedOperationException("Not supported yet.");
  324. }
  325. @Override
  326. public Set<org.bukkit.OfflinePlayer> getWhitelistedPlayers()
  327. {
  328. throw new UnsupportedOperationException("Not supported yet.");
  329. }
  330. @Override
  331. public void reloadWhitelist()
  332. {
  333. throw new UnsupportedOperationException("Not supported yet.");
  334. }
  335. @Override
  336. public Player getPlayerExact(String string)
  337. {
  338. throw new UnsupportedOperationException("Not supported yet.");
  339. }
  340. @Override
  341. public void shutdown()
  342. {
  343. throw new UnsupportedOperationException("Not supported yet.");
  344. }
  345. @Override
  346. public int broadcast(String string, String string1)
  347. {
  348. throw new UnsupportedOperationException("Not supported yet.");
  349. }
  350. @Override
  351. public org.bukkit.OfflinePlayer getOfflinePlayer(String string)
  352. {
  353. return null;
  354. }
  355. @Override
  356. public Set<String> getIPBans()
  357. {
  358. throw new UnsupportedOperationException("Not supported yet.");
  359. }
  360. @Override
  361. public void banIP(String string)
  362. {
  363. throw new UnsupportedOperationException("Not supported yet.");
  364. }
  365. @Override
  366. public void unbanIP(String string)
  367. {
  368. throw new UnsupportedOperationException("Not supported yet.");
  369. }
  370. @Override
  371. public Set<org.bukkit.OfflinePlayer> getBannedPlayers()
  372. {
  373. throw new UnsupportedOperationException("Not supported yet.");
  374. }
  375. }