001 package org.bukkit; 002 003 import java.awt.image.BufferedImage; 004 import java.io.File; 005 import java.util.Collection; 006 import java.util.Iterator; 007 import java.util.List; 008 import java.util.Map; 009 import java.util.Set; 010 import java.util.UUID; 011 import java.util.logging.Logger; 012 013 import org.bukkit.Warning.WarningState; 014 import org.bukkit.command.CommandException; 015 import org.bukkit.command.CommandSender; 016 import org.bukkit.command.ConsoleCommandSender; 017 import org.bukkit.command.PluginCommand; 018 import org.bukkit.entity.Player; 019 import org.bukkit.event.inventory.InventoryType; 020 import org.bukkit.help.HelpMap; 021 import org.bukkit.inventory.ItemStack; 022 import org.bukkit.inventory.Inventory; 023 import org.bukkit.inventory.InventoryHolder; 024 import org.bukkit.inventory.ItemFactory; 025 import org.bukkit.inventory.Recipe; 026 import org.bukkit.map.MapView; 027 import org.bukkit.plugin.PluginManager; 028 import org.bukkit.plugin.ServicesManager; 029 import org.bukkit.plugin.messaging.Messenger; 030 import org.bukkit.scheduler.BukkitScheduler; 031 import org.bukkit.scoreboard.ScoreboardManager; 032 import org.bukkit.util.CachedServerIcon; 033 034 import com.avaje.ebean.config.ServerConfig; 035 036 /** 037 * Represents the Bukkit core, for version and Server singleton handling 038 */ 039 public final class Bukkit { 040 private static Server server; 041 042 /** 043 * Static class cannot be initialized. 044 */ 045 private Bukkit() {} 046 047 /** 048 * Gets the current {@link Server} singleton 049 * 050 * @return Server instance being ran 051 */ 052 public static Server getServer() { 053 return server; 054 } 055 056 /** 057 * Attempts to set the {@link Server} singleton. 058 * <p> 059 * This cannot be done if the Server is already set. 060 * 061 * @param server Server instance 062 */ 063 public static void setServer(Server server) { 064 if (Bukkit.server != null) { 065 throw new UnsupportedOperationException("Cannot redefine singleton Server"); 066 } 067 068 Bukkit.server = server; 069 server.getLogger().info("This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ")"); 070 } 071 072 /** 073 * @see Server#getName() 074 */ 075 public static String getName() { 076 return server.getName(); 077 } 078 079 /** 080 * @see Server#getVersion() 081 */ 082 public static String getVersion() { 083 return server.getVersion(); 084 } 085 086 /** 087 * @see Server#getBukkitVersion() 088 */ 089 public static String getBukkitVersion() { 090 return server.getBukkitVersion(); 091 } 092 093 /** 094 * This method exists for legacy reasons to provide backwards 095 * compatibility. It will not exist at runtime and should not be used 096 * under any circumstances. 097 * 098 * @Deprecated 099 * @see Server#_INVALID_getOnlinePlayers() 100 */ 101 @Deprecated 102 public static Player[] _INVALID_getOnlinePlayers() { 103 return server._INVALID_getOnlinePlayers(); 104 } 105 106 /** 107 * @see Server#getOnlinePlayers() 108 */ 109 public static Collection<? extends Player> getOnlinePlayers() { 110 return server.getOnlinePlayers(); 111 } 112 113 /** 114 * @see Server#getMaxPlayers() 115 */ 116 public static int getMaxPlayers() { 117 return server.getMaxPlayers(); 118 } 119 120 /** 121 * @see Server#getPort() 122 */ 123 public static int getPort() { 124 return server.getPort(); 125 } 126 127 /** 128 * @see Server#getViewDistance() 129 */ 130 public static int getViewDistance() { 131 return server.getViewDistance(); 132 } 133 134 /** 135 * @see Server#getIp() 136 */ 137 public static String getIp() { 138 return server.getIp(); 139 } 140 141 /** 142 * @see Server#getServerName() 143 */ 144 public static String getServerName() { 145 return server.getServerName(); 146 } 147 148 /** 149 * @see Server#getServerId() 150 */ 151 public static String getServerId() { 152 return server.getServerId(); 153 } 154 155 /** 156 * @see Server#getWorldType() 157 */ 158 public static String getWorldType() { 159 return server.getWorldType(); 160 } 161 162 /** 163 * @see Server#getGenerateStructures() 164 */ 165 public static boolean getGenerateStructures() { 166 return server.getGenerateStructures(); 167 } 168 169 /** 170 * @see Server#getAllowNether() 171 */ 172 public static boolean getAllowNether() { 173 return server.getAllowNether(); 174 } 175 176 /** 177 * @see Server#hasWhitelist() 178 */ 179 public static boolean hasWhitelist() { 180 return server.hasWhitelist(); 181 } 182 183 /** 184 * @see Server#broadcastMessage(String message) 185 */ 186 public static int broadcastMessage(String message) { 187 return server.broadcastMessage(message); 188 } 189 190 /** 191 * @see Server#getUpdateFolder() 192 */ 193 public static String getUpdateFolder() { 194 return server.getUpdateFolder(); 195 } 196 197 /** 198 * @see Server#getPlayer(String name) 199 */ 200 @Deprecated 201 public static Player getPlayer(String name) { 202 return server.getPlayer(name); 203 } 204 205 /** 206 * @see Server#matchPlayer(String name) 207 */ 208 @Deprecated 209 public static List<Player> matchPlayer(String name) { 210 return server.matchPlayer(name); 211 } 212 213 /** 214 * @see Server#getPlayer(java.util.UUID) 215 */ 216 public static Player getPlayer(UUID id) { 217 return server.getPlayer(id); 218 } 219 220 /** 221 * @see Server#getPluginManager() 222 */ 223 public static PluginManager getPluginManager() { 224 return server.getPluginManager(); 225 } 226 227 /** 228 * @see Server#getScheduler() 229 */ 230 public static BukkitScheduler getScheduler() { 231 return server.getScheduler(); 232 } 233 234 /** 235 * @see Server#getServicesManager() 236 */ 237 public static ServicesManager getServicesManager() { 238 return server.getServicesManager(); 239 } 240 241 /** 242 * @see Server#getWorlds() 243 */ 244 public static List<World> getWorlds() { 245 return server.getWorlds(); 246 } 247 248 /** 249 * @see Server#createWorld(WorldCreator options) 250 */ 251 public static World createWorld(WorldCreator options) { 252 return server.createWorld(options); 253 } 254 255 /** 256 * @see Server#unloadWorld(String name, boolean save) 257 */ 258 public static boolean unloadWorld(String name, boolean save) { 259 return server.unloadWorld(name, save); 260 } 261 262 /** 263 * @see Server#unloadWorld(World world, boolean save) 264 */ 265 public static boolean unloadWorld(World world, boolean save) { 266 return server.unloadWorld(world, save); 267 } 268 269 /** 270 * @see Server#getWorld(String name) 271 */ 272 public static World getWorld(String name) { 273 return server.getWorld(name); 274 } 275 276 /** 277 * @see Server#getWorld(UUID uid) 278 */ 279 public static World getWorld(UUID uid) { 280 return server.getWorld(uid); 281 } 282 283 /** 284 * @see Server#getMap(short id) 285 * @deprecated Magic value 286 */ 287 @Deprecated 288 public static MapView getMap(short id) { 289 return server.getMap(id); 290 } 291 292 /** 293 * @see Server#createMap(World world) 294 */ 295 public static MapView createMap(World world) { 296 return server.createMap(world); 297 } 298 299 /** 300 * @see Server#reload() 301 */ 302 public static void reload() { 303 server.reload(); 304 } 305 306 /** 307 * @see Server#getLogger() 308 */ 309 public static Logger getLogger() { 310 return server.getLogger(); 311 } 312 313 /** 314 * @see Server#getPluginCommand(String name) 315 */ 316 public static PluginCommand getPluginCommand(String name) { 317 return server.getPluginCommand(name); 318 } 319 320 /** 321 * @see Server#savePlayers() 322 */ 323 public static void savePlayers() { 324 server.savePlayers(); 325 } 326 327 /** 328 * @see Server#dispatchCommand(CommandSender sender, String commandLine) 329 */ 330 public static boolean dispatchCommand(CommandSender sender, String commandLine) throws CommandException { 331 return server.dispatchCommand(sender, commandLine); 332 } 333 334 /** 335 * @see Server#configureDbConfig(ServerConfig config) 336 */ 337 public static void configureDbConfig(ServerConfig config) { 338 server.configureDbConfig(config); 339 } 340 341 /** 342 * @see Server#addRecipe(Recipe recipe) 343 */ 344 public static boolean addRecipe(Recipe recipe) { 345 return server.addRecipe(recipe); 346 } 347 348 /** 349 * @see Server#getRecipesFor(ItemStack result) 350 */ 351 public static List<Recipe> getRecipesFor(ItemStack result) { 352 return server.getRecipesFor(result); 353 } 354 355 /** 356 * @see Server#recipeIterator() 357 */ 358 public static Iterator<Recipe> recipeIterator() { 359 return server.recipeIterator(); 360 } 361 362 /** 363 * @see Server#clearRecipes() 364 */ 365 public static void clearRecipes() { 366 server.clearRecipes(); 367 } 368 369 /** 370 * @see Server#resetRecipes() 371 */ 372 public static void resetRecipes() { 373 server.resetRecipes(); 374 } 375 376 /** 377 * @see Server#getCommandAliases() 378 */ 379 public static Map<String, String[]> getCommandAliases() { 380 return server.getCommandAliases(); 381 } 382 383 /** 384 * @see Server#getSpawnRadius() 385 */ 386 public static int getSpawnRadius() { 387 return server.getSpawnRadius(); 388 } 389 390 /** 391 * @see Server#setSpawnRadius(int value) 392 */ 393 public static void setSpawnRadius(int value) { 394 server.setSpawnRadius(value); 395 } 396 397 /** 398 * @see Server#getOnlineMode() 399 */ 400 public static boolean getOnlineMode() { 401 return server.getOnlineMode(); 402 } 403 404 /** 405 * @see Server#getAllowFlight() 406 */ 407 public static boolean getAllowFlight() { 408 return server.getAllowFlight(); 409 } 410 411 /** 412 * @see Server#isHardcore() 413 */ 414 public static boolean isHardcore() { 415 return server.isHardcore(); 416 } 417 418 /** 419 * @see Server#shutdown() 420 */ 421 public static void shutdown() { 422 server.shutdown(); 423 } 424 425 /** 426 * @see Server#broadcast(String message, String permission) 427 */ 428 public static int broadcast(String message, String permission) { 429 return server.broadcast(message, permission); 430 } 431 432 /** 433 * @see Server#getOfflinePlayer(String name) 434 */ 435 @Deprecated 436 public static OfflinePlayer getOfflinePlayer(String name) { 437 return server.getOfflinePlayer(name); 438 } 439 440 /** 441 * @see Server#getOfflinePlayer(java.util.UUID) 442 */ 443 public static OfflinePlayer getOfflinePlayer(UUID id) { 444 return server.getOfflinePlayer(id); 445 } 446 447 /** 448 * @see Server#getPlayerExact(String name) 449 */ 450 @Deprecated 451 public static Player getPlayerExact(String name) { 452 return server.getPlayerExact(name); 453 } 454 455 /** 456 * @see Server#getIPBans() 457 */ 458 public static Set<String> getIPBans() { 459 return server.getIPBans(); 460 } 461 462 /** 463 * @see Server#banIP(String address) 464 */ 465 public static void banIP(String address) { 466 server.banIP(address); 467 } 468 469 /** 470 * @see Server#unbanIP(String address) 471 */ 472 public static void unbanIP(String address) { 473 server.unbanIP(address); 474 } 475 476 /** 477 * @see Server#getBannedPlayers() 478 */ 479 public static Set<OfflinePlayer> getBannedPlayers() { 480 return server.getBannedPlayers(); 481 } 482 483 /** 484 * @see Server#getBanList(BanList.Type) 485 */ 486 public static BanList getBanList(BanList.Type type){ 487 return server.getBanList(type); 488 } 489 490 /** 491 * @see Server#setWhitelist(boolean value) 492 */ 493 public static void setWhitelist(boolean value) { 494 server.setWhitelist(value); 495 } 496 497 /** 498 * @see Server#getWhitelistedPlayers() 499 */ 500 public static Set<OfflinePlayer> getWhitelistedPlayers() { 501 return server.getWhitelistedPlayers(); 502 } 503 504 /** 505 * @see Server#reloadWhitelist() 506 */ 507 public static void reloadWhitelist() { 508 server.reloadWhitelist(); 509 } 510 511 /** 512 * @see Server#getConsoleSender() 513 */ 514 public static ConsoleCommandSender getConsoleSender() { 515 return server.getConsoleSender(); 516 } 517 518 /** 519 * @see Server#getOperators() 520 */ 521 public static Set<OfflinePlayer> getOperators() { 522 return server.getOperators(); 523 } 524 525 /** 526 * @see Server#getWorldContainer() 527 */ 528 public static File getWorldContainer() { 529 return server.getWorldContainer(); 530 } 531 532 /** 533 * @see Server#getMessenger() 534 */ 535 public static Messenger getMessenger() { 536 return server.getMessenger(); 537 } 538 539 /** 540 * @see Server#getAllowEnd() 541 */ 542 public static boolean getAllowEnd() { 543 return server.getAllowEnd(); 544 } 545 546 /** 547 * @see Server#getUpdateFolderFile() 548 */ 549 public static File getUpdateFolderFile() { 550 return server.getUpdateFolderFile(); 551 } 552 553 /** 554 * @see Server#getConnectionThrottle() 555 */ 556 public static long getConnectionThrottle() { 557 return server.getConnectionThrottle(); 558 } 559 560 /** 561 * @see Server#getTicksPerAnimalSpawns() 562 */ 563 public static int getTicksPerAnimalSpawns() { 564 return server.getTicksPerAnimalSpawns(); 565 } 566 567 /** 568 * @see Server#getTicksPerMonsterSpawns() 569 */ 570 public static int getTicksPerMonsterSpawns() { 571 return server.getTicksPerMonsterSpawns(); 572 } 573 574 /** 575 * @see Server#useExactLoginLocation() 576 */ 577 public static boolean useExactLoginLocation() { 578 return server.useExactLoginLocation(); 579 } 580 581 /** 582 * @see Server#getDefaultGameMode() 583 */ 584 public static GameMode getDefaultGameMode() { 585 return server.getDefaultGameMode(); 586 } 587 588 /** 589 * @see Server#setDefaultGameMode(GameMode mode) 590 */ 591 public static void setDefaultGameMode(GameMode mode) { 592 server.setDefaultGameMode(mode); 593 } 594 595 /** 596 * @see Server#getOfflinePlayers() 597 */ 598 public static OfflinePlayer[] getOfflinePlayers() { 599 return server.getOfflinePlayers(); 600 } 601 602 /** 603 * @see Server#createInventory(InventoryHolder owner, InventoryType type) 604 */ 605 public static Inventory createInventory(InventoryHolder owner, InventoryType type) { 606 return server.createInventory(owner, type); 607 } 608 609 /** 610 * @see Server#createInventory(InventoryHolder owner, InventoryType type, String title) 611 */ 612 public static Inventory createInventory(InventoryHolder owner, InventoryType type, String title) { 613 return server.createInventory(owner, type, title); 614 } 615 616 /** 617 * @see Server#createInventory(InventoryHolder owner, int size) 618 */ 619 public static Inventory createInventory(InventoryHolder owner, int size) throws IllegalArgumentException { 620 return server.createInventory(owner, size); 621 } 622 623 /** 624 * @see Server#createInventory(InventoryHolder owner, int size, String 625 * title) 626 */ 627 public static Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException { 628 return server.createInventory(owner, size, title); 629 } 630 631 /** 632 * @see Server#getHelpMap() 633 */ 634 public static HelpMap getHelpMap() { 635 return server.getHelpMap(); 636 } 637 638 /** 639 * @see Server#getMonsterSpawnLimit() 640 */ 641 public static int getMonsterSpawnLimit() { 642 return server.getMonsterSpawnLimit(); 643 } 644 645 /** 646 * @see Server#getAnimalSpawnLimit() 647 */ 648 public static int getAnimalSpawnLimit() { 649 return server.getAnimalSpawnLimit(); 650 } 651 652 /** 653 * @see Server#getWaterAnimalSpawnLimit() 654 */ 655 public static int getWaterAnimalSpawnLimit() { 656 return server.getWaterAnimalSpawnLimit(); 657 } 658 659 /** 660 * @see Server#getAmbientSpawnLimit() 661 */ 662 public static int getAmbientSpawnLimit() { 663 return server.getAmbientSpawnLimit(); 664 } 665 666 /** 667 * @see Server#isPrimaryThread() 668 */ 669 public static boolean isPrimaryThread() { 670 return server.isPrimaryThread(); 671 } 672 673 /** 674 * @see Server#getMotd() 675 */ 676 public static String getMotd() { 677 return server.getMotd(); 678 } 679 680 /** 681 * @see Server#getShutdownMessage() 682 */ 683 public static String getShutdownMessage() { 684 return server.getShutdownMessage(); 685 } 686 687 /** 688 * @see Server#getWarningState() 689 */ 690 public static WarningState getWarningState() { 691 return server.getWarningState(); 692 } 693 694 /** 695 * @see Server#getItemFactory() 696 */ 697 public static ItemFactory getItemFactory() { 698 return server.getItemFactory(); 699 } 700 701 /** 702 * @see Server#getScoreboardManager() 703 */ 704 public static ScoreboardManager getScoreboardManager() { 705 return server.getScoreboardManager(); 706 } 707 708 /** 709 * @see Server#getServerIcon() 710 */ 711 public static CachedServerIcon getServerIcon() { 712 return server.getServerIcon(); 713 } 714 715 /** 716 * @see Server#loadServerIcon(File) 717 */ 718 public static CachedServerIcon loadServerIcon(File file) throws IllegalArgumentException, Exception { 719 return server.loadServerIcon(file); 720 } 721 722 /** 723 * @see Server#loadServerIcon(BufferedImage) 724 */ 725 public static CachedServerIcon loadServerIcon(BufferedImage image) throws IllegalArgumentException, Exception { 726 return server.loadServerIcon(image); 727 } 728 729 /** 730 * @see Server#setIdleTimeout(int) 731 */ 732 public static void setIdleTimeout(int threshold) { 733 server.setIdleTimeout(threshold); 734 } 735 736 /** 737 * @see Server#getIdleTimeout() 738 */ 739 public static int getIdleTimeout() { 740 return server.getIdleTimeout(); 741 } 742 743 /** 744 * @see Server#getUnsafe() 745 */ 746 @Deprecated 747 public static UnsafeValues getUnsafe() { 748 return server.getUnsafe(); 749 } 750 }