Advertisement
Guest User

Main

a guest
Jul 29th, 2015
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. package com.sosoh.essentials;
  2.  
  3. import org.slf4j.Logger;
  4. import org.spongepowered.api.Game;
  5. import org.spongepowered.api.entity.player.Player;
  6. import org.spongepowered.api.event.Subscribe;
  7. import org.spongepowered.api.event.entity.player.PlayerJoinEvent;
  8. import org.spongepowered.api.event.entity.player.PlayerQuitEvent;
  9. import org.spongepowered.api.event.state.InitializationEvent;
  10. import org.spongepowered.api.event.state.ServerStartedEvent;
  11. import org.spongepowered.api.plugin.Plugin;
  12. import org.spongepowered.api.text.Texts;
  13. import org.spongepowered.api.text.action.TextActions;
  14. import org.spongepowered.api.text.format.TextColors;
  15. import org.spongepowered.api.text.format.TextStyles;
  16. import org.spongepowered.api.text.title.Title;
  17. import org.spongepowered.api.util.command.args.GenericArguments;
  18. import org.spongepowered.api.util.command.spec.CommandSpec;
  19.  
  20. import com.google.inject.Inject;
  21. import com.sosoh.essentials.commands.MenuCommand;
  22. import com.sosoh.essentials.commands.SetSpawnCommand;
  23. import com.sosoh.essentials.commands.SpawnCommand;
  24. import com.sosoh.essentials.commands.TeleportPlayerHereCommand;
  25. import com.sosoh.essentials.commands.TeleportToPlayerCommand;
  26. import com.sosoh.essentials.commands.TimeCommand;
  27. import com.sosoh.essentials.commands.TimeGetCommand;
  28. import com.sosoh.essentials.commands.TimeSetCommand;
  29. import com.sosoh.essentials.commands.economy.BalanceCommand;
  30. import com.sosoh.essentials.services.EconomyService;
  31. import com.sosoh.essentials.services.SimpleEconomyService;
  32.  
  33. @Plugin(id = "essentials", name = "Essentials Plugin", version = "0.1")
  34. public class Main {
  35.  
  36. public static Main access;
  37. public EconomyService economy;
  38.  
  39. @Inject
  40. private Logger logger;
  41. private Game game;
  42.  
  43. public Logger getLogger() {
  44. return logger;
  45. }
  46.  
  47. public Game getGame() {
  48. return game;
  49. }
  50.  
  51. @Subscribe
  52. public void onServerStart(ServerStartedEvent event) {
  53. getLogger().info("[Essentials] Plugin Initialized");
  54. }
  55.  
  56. @Subscribe
  57. public void Initalization(InitializationEvent event) {
  58.  
  59. this.game = event.getGame();
  60. //Commands
  61.  
  62. CommandSpec spawn = CommandSpec.builder()
  63. .description(Texts.of("Teleport the player to the spawn."))
  64. .permission("essentials.command.spawn.use")
  65. .executor(new SpawnCommand())
  66. .build();
  67.  
  68. CommandSpec setspawn = CommandSpec.builder()
  69. .description(Texts.of("Set the new spawnpoint."))
  70. .permission("essentials.command.spawn.set")
  71. .executor(new SetSpawnCommand())
  72. .build();
  73.  
  74. CommandSpec timeget = CommandSpec.builder()
  75. .description(Texts.of("Reply the in game time."))
  76. .permission("essentials.command.time.get")
  77. .executor(new TimeGetCommand())
  78. .build();
  79.  
  80. CommandSpec timeset = CommandSpec.builder()
  81. .description(Texts.of("Set the in game time."))
  82. .permission("essentials.command.time.set")
  83. .arguments(GenericArguments.onlyOne(GenericArguments.integer(Texts.of("Value"))))
  84. .executor(new TimeSetCommand())
  85. .build();
  86.  
  87. CommandSpec time = CommandSpec.builder()
  88. .description(Texts.of("Time Administration."))
  89. .permission("essentials.command.time")
  90. .executor(new TimeCommand())
  91. .child(timeget, "get")
  92. .child(timeset, "set")
  93. .build();
  94.  
  95. CommandSpec tpplayer = CommandSpec.builder()
  96. .description(Texts.of("Teleport the player to an other player."))
  97. .permission("essentials.command.tp.player.to")
  98. .executor(new TeleportToPlayerCommand())
  99. .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
  100. .build();
  101.  
  102. CommandSpec tpplayerhere = CommandSpec.builder()
  103. .description(Texts.of("Teleport the player to an other player."))
  104. .permission("essentials.command.tp.player.here")
  105. .executor(new TeleportPlayerHereCommand())
  106. .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
  107. .build();
  108.  
  109. CommandSpec menu = CommandSpec.builder()
  110. .description(Texts.of("Open the menu."))
  111. .permission("essentials.command.menu.open")
  112. .executor(new MenuCommand())
  113. .build();
  114.  
  115. CommandSpec balance = CommandSpec.builder()
  116. .description(Texts.of("Tell the player his balance."))
  117. .permission("essentials.command.economy.balance")
  118. .executor(new BalanceCommand())
  119. .build();
  120.  
  121. game.getCommandDispatcher().register(this, spawn, "spawn");
  122. game.getCommandDispatcher().register(this, setspawn, "setspawn");
  123. game.getCommandDispatcher().register(this, time, "time");
  124. game.getCommandDispatcher().register(this, tpplayer, "tp");
  125. game.getCommandDispatcher().register(this, tpplayerhere, "tphere");
  126. game.getCommandDispatcher().register(this, menu, "menu");
  127. game.getCommandDispatcher().register(this, balance, "balance");
  128.  
  129. try
  130. {
  131. game.getServiceManager().setProvider(this, EconomyService.class, new SimpleEconomyService());
  132. getLogger().info("Economy Service has been registred !");
  133. } catch (Exception e){
  134. e.printStackTrace();
  135. }
  136. economy = getGame().getServiceManager().provide(EconomyService.class).get();
  137.  
  138. }
  139.  
  140. @Subscribe
  141. public void playerJoinEvent(PlayerJoinEvent event){
  142. Player player = event.getEntity();
  143. economy.setBalance(player, 500);
  144. event.setNewMessage(Texts.builder("[+] ").color(TextColors.DARK_GREEN)
  145. .append(Texts.builder(player.getName()).color(TextColors.GREEN)
  146. .append(Texts.builder(" [+]").color(TextColors.DARK_GREEN)
  147. .build())
  148. .build())
  149. .onHover(TextActions.showText(Texts.builder("Click to say hi to him !")
  150. .color(TextColors.GREEN)
  151. .build()))
  152. .onClick(TextActions.suggestCommand("/tell "+player.getName()))
  153. .build());
  154. player.sendTitle(new Title(null, null, null, null, null, false, false).builder()
  155. .title(Texts.builder("Welcome Back !").color(TextColors.DARK_GREEN).build())
  156. .subtitle(Texts.builder(player.getName()).color(TextColors.GREEN).style(TextStyles.BOLD).build())
  157. .stay(80)
  158. .build());
  159. }
  160.  
  161. @Subscribe
  162. public void playerQuitEvent(PlayerQuitEvent event){
  163. Player player = event.getEntity();
  164. event.setNewMessage(Texts.builder("[-] ").color(TextColors.DARK_RED)
  165. .append(Texts.builder(player.getName()).color(TextColors.RED)
  166. .append(Texts.builder(" [-]").color(TextColors.DARK_RED)
  167. .build())
  168. .build())
  169. .build());
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement