Advertisement
Guest User

Main Updated

a guest
Jul 29th, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.93 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.        
  61.         try
  62.         {
  63.             game.getServiceManager().setProvider(this, EconomyService.class, new SimpleEconomyService());
  64.             getLogger().info("Economy Service has been registred !");  
  65.         } catch (Exception e){
  66.             e.printStackTrace();
  67.         }
  68.         economy = getGame().getServiceManager().provide(EconomyService.class).get();
  69.         //Commands
  70.        
  71.         CommandSpec spawn = CommandSpec.builder()
  72.                 .description(Texts.of("Teleport the player to the spawn."))
  73.                 .permission("essentials.command.spawn.use")
  74.                 .executor(new SpawnCommand())
  75.                 .build();
  76.        
  77.         CommandSpec setspawn = CommandSpec.builder()
  78.                 .description(Texts.of("Set the new spawnpoint."))
  79.                 .permission("essentials.command.spawn.set")
  80.                 .executor(new SetSpawnCommand())
  81.                 .build();
  82.  
  83.         CommandSpec timeget = CommandSpec.builder()
  84.                 .description(Texts.of("Reply the in game time."))
  85.                 .permission("essentials.command.time.get")
  86.                 .executor(new TimeGetCommand())
  87.                 .build();
  88.        
  89.         CommandSpec timeset = CommandSpec.builder()
  90.                 .description(Texts.of("Set the in game time."))
  91.                 .permission("essentials.command.time.set")
  92.                 .arguments(GenericArguments.onlyOne(GenericArguments.integer(Texts.of("Value"))))
  93.                 .executor(new TimeSetCommand())
  94.                 .build();
  95.        
  96.         CommandSpec time = CommandSpec.builder()
  97.                 .description(Texts.of("Time Administration."))
  98.                 .permission("essentials.command.time")
  99.                 .executor(new TimeCommand())
  100.                 .child(timeget, "get")             
  101.                 .child(timeset, "set")
  102.                 .build();
  103.        
  104.         CommandSpec tpplayer = CommandSpec.builder()
  105.                 .description(Texts.of("Teleport the player to an other player."))
  106.                 .permission("essentials.command.tp.player.to")
  107.                 .executor(new TeleportToPlayerCommand())
  108.                 .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
  109.                 .build();
  110.        
  111.         CommandSpec tpplayerhere = CommandSpec.builder()
  112.                 .description(Texts.of("Teleport the player to an other player."))
  113.                 .permission("essentials.command.tp.player.here")
  114.                 .executor(new TeleportPlayerHereCommand())
  115.                 .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
  116.                 .build();
  117.        
  118.         CommandSpec menu = CommandSpec.builder()
  119.                 .description(Texts.of("Open the menu."))
  120.                 .permission("essentials.command.menu.open")
  121.                 .executor(new MenuCommand())
  122.                 .build();
  123.        
  124.         CommandSpec balance = CommandSpec.builder()
  125.                 .description(Texts.of("Tell the player his balance."))
  126.                 .permission("essentials.command.economy.balance")
  127.                 .executor(new BalanceCommand())
  128.                 .build();
  129.        
  130.         game.getCommandDispatcher().register(this, spawn, "spawn");
  131.         game.getCommandDispatcher().register(this, setspawn, "setspawn");
  132.         game.getCommandDispatcher().register(this, time, "time");
  133.         game.getCommandDispatcher().register(this, tpplayer, "tp");
  134.         game.getCommandDispatcher().register(this, tpplayerhere, "tphere");
  135.         game.getCommandDispatcher().register(this, menu, "menu");    
  136.         game.getCommandDispatcher().register(this, balance, "balance");  
  137.        
  138.        
  139.        
  140.     }
  141.    
  142.     @Subscribe
  143.     public void playerJoinEvent(PlayerJoinEvent event){
  144.         Player player = event.getEntity();
  145.             economy.setBalance(player, 500);
  146.             event.setNewMessage(Texts.builder("[+] ").color(TextColors.DARK_GREEN)
  147.                     .append(Texts.builder(player.getName()).color(TextColors.GREEN)
  148.                             .append(Texts.builder(" [+]").color(TextColors.DARK_GREEN)
  149.                                     .build())
  150.                             .build())
  151.                     .onHover(TextActions.showText(Texts.builder("Click to say hi to him !")
  152.                             .color(TextColors.GREEN)
  153.                             .build()))
  154.                     .onClick(TextActions.suggestCommand("/tell "+player.getName()))
  155.                     .build());
  156.             player.sendTitle(new Title(null, null, null, null, null, false, false).builder()
  157.                     .title(Texts.builder("Welcome Back !").color(TextColors.DARK_GREEN).build())
  158.                     .subtitle(Texts.builder(player.getName()).color(TextColors.GREEN).style(TextStyles.BOLD).build())
  159.                     .stay(80)
  160.                     .build());
  161.     }
  162.    
  163.     @Subscribe
  164.     public void playerQuitEvent(PlayerQuitEvent event){
  165.         Player player = event.getEntity();
  166.         event.setNewMessage(Texts.builder("[-] ").color(TextColors.DARK_RED)
  167.                 .append(Texts.builder(player.getName()).color(TextColors.RED)
  168.                         .append(Texts.builder(" [-]").color(TextColors.DARK_RED)
  169.                                 .build())
  170.                         .build())
  171.                 .build());
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement