Ghaz-ranka

Untitled

Jun 4th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. package zorg.esinia.server;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Path;
  5. import org.slf4j.Logger;
  6. import org.spongepowered.api.CatalogTypes;
  7. import org.spongepowered.api.Game;
  8. import org.spongepowered.api.Sponge;
  9. import org.spongepowered.api.command.args.GenericArguments;
  10. import org.spongepowered.api.command.spec.CommandSpec;
  11. import org.spongepowered.api.config.DefaultConfig;
  12. import org.spongepowered.api.event.Listener;
  13. import org.spongepowered.api.event.game.state.GameInitializationEvent;
  14. import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
  15. import org.spongepowered.api.event.game.state.GameStartedServerEvent;
  16. import org.spongepowered.api.plugin.Plugin;
  17. import org.spongepowered.api.text.Text;
  18.  
  19. import com.google.common.collect.Lists;
  20. import com.google.inject.Inject;
  21.  
  22. import ninja.leaping.configurate.ConfigurationNode;
  23. import ninja.leaping.configurate.commented.CommentedConfigurationNode;
  24. import ninja.leaping.configurate.loader.ConfigurationLoader;
  25. import ninja.leaping.configurate.objectmapping.ObjectMappingException;
  26. import zorg.esinia.server.anvils.AnvilStone;
  27. import zorg.esinia.server.commands.EsiniaCoreExecutor;
  28. import zorg.esinia.server.commands.EsiniaCoreItemNamer;
  29. import zorg.esinia.server.commands.EsiniaCoreItemTyper;
  30. import zorg.esinia.server.commands.EsiniaCoreLoreNamer;
  31. import zorg.esinia.server.craftingtables.CraftingTablesRudimentary;
  32. import zorg.esinia.server.events.EventBlockBreak;
  33. import zorg.esinia.server.events.EventBlockPlace;
  34. import zorg.esinia.server.events.EventDecay;
  35. import zorg.esinia.server.events.EventInventoryClick;
  36. import zorg.esinia.server.events.EventInventoryOpen;
  37. import zorg.esinia.server.events.EventItemDrop;
  38. import zorg.esinia.server.events.EventPlayerJoin;
  39. import zorg.esinia.server.events.EventRightClick;
  40. import zorg.esinia.server.events.EventSpawnEntity;
  41. import zorg.esinia.server.invintories.craftingtables.CraftingTablesRudimentaryInventory;
  42.  
  43.  
  44.  
  45. @Plugin(id = "esiniacore", name = "Esinia Core", version = "1.0", authors = "Ghaz-ranka, " + "pie_flavor, " + "Kanelives, " + "Kodiacbear")
  46. public class Esinia {
  47.  
  48. @Inject
  49. Game game;
  50.  
  51. @Inject
  52. @DefaultConfig(sharedRoot = true)
  53. private Path path;
  54.  
  55. @DefaultConfig(sharedRoot = true)
  56. public ConfigurationNode root;
  57.  
  58. @Inject
  59. @DefaultConfig(sharedRoot = true)
  60. ConfigurationLoader<CommentedConfigurationNode> loader;
  61. public Config config;
  62.  
  63. @Inject
  64. private Logger logger;
  65. public Logger getLogger(){
  66. return logger;
  67. }
  68.  
  69. @SuppressWarnings("unchecked")
  70. public static <T extends Throwable, V> V rethrow(Throwable t) throws T {
  71. throw (T) t;
  72. }
  73.  
  74. public void saveConfig() {
  75. try {
  76. loader.save(root);
  77. } catch (IOException ex) {
  78. rethrow(ex);
  79. }
  80. }
  81.  
  82. @Listener
  83. public void onPreInit(GamePreInitializationEvent event) throws IOException, ObjectMappingException {
  84. logger.info("Loading Esinia Server Core...");
  85. root = loader.load();
  86. config = root.getValue(Config.type);
  87. }
  88.  
  89. @Listener
  90. public void onInit(GameInitializationEvent event){
  91. this.getLogger().info("Loading...");
  92.  
  93. CommandSpec esiniaCommandSpec = CommandSpec.builder()
  94. .description(Text.of("Says different things based on the source"))
  95. .executor(new EsiniaCoreExecutor())
  96. .build();
  97.  
  98. CommandSpec esiniaItemTyperCommandSpec = CommandSpec.builder()
  99. .description(Text.of("Says the item type of held item"))
  100. .executor(new EsiniaCoreItemTyper())
  101. .build();
  102.  
  103. CommandSpec esiniaitemnamerCommandSpec = CommandSpec.builder()
  104. .description(Text.of("Changes the name of player's held item."))
  105. .arguments(
  106. GenericArguments.catalogedElement(Text.of("color"), CatalogTypes.TEXT_COLOR),
  107. GenericArguments.remainingJoinedStrings(Text.of("name")))
  108. .executor(new EsiniaCoreItemNamer())
  109. .build();
  110.  
  111. CommandSpec esinialorenamerCommandSpec = CommandSpec.builder()
  112. .description(Text.of("Changes the lore of player's held item."))
  113. .arguments(
  114. GenericArguments.allOf(GenericArguments.string(Text.of("lore"))))
  115. .executor(new EsiniaCoreLoreNamer())
  116. .build();
  117. //Commands
  118. Sponge.getCommandManager().register(this, esiniaCommandSpec, Lists.newArrayList("Esinia"));
  119. Sponge.getCommandManager().register(this, esiniaItemTyperCommandSpec, Lists.newArrayList("ItemTyper"));
  120. Sponge.getCommandManager().register(this, esiniaitemnamerCommandSpec, Lists.newArrayList("ItemNamer"));
  121. Sponge.getCommandManager().register(this, esinialorenamerCommandSpec, Lists.newArrayList("LoreNamer"));
  122. }
  123.  
  124. @Listener
  125. public void onServerStart(GameStartedServerEvent event) {
  126. this.getLogger().info("Loading...");
  127. //Events
  128. game.getEventManager().registerListeners(this, new EventBlockBreak());
  129. game.getEventManager().registerListeners(this, new EventBlockPlace());
  130. game.getEventManager().registerListeners(this, new EventDecay());
  131. game.getEventManager().registerListeners(this, new EventItemDrop());
  132. game.getEventManager().registerListeners(this, new EventSpawnEntity());
  133. game.getEventManager().registerListeners(this, new EventRightClick());
  134. game.getEventManager().registerListeners(this, new EventInventoryClick());
  135. game.getEventManager().registerListeners(this, new EventInventoryOpen());
  136. //Anvils
  137. game.getEventManager().registerListeners(this, new AnvilStone(this));
  138. //Crafting Tables
  139. game.getEventManager().registerListeners(this, new CraftingTablesRudimentary());
  140. //Crafting Table Inventories
  141. game.getEventManager().registerListeners(this, new CraftingTablesRudimentaryInventory());
  142. //Other
  143. game.getEventManager().registerListeners(this, new EventPlayerJoin(this));
  144.  
  145. this.getLogger().info("Loading Complete");
  146. }
  147. }
Add Comment
Please, Sign In to add comment