Ghaz-ranka

Untitled

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