Advertisement
drummersbrother

Plugin Source Code

May 18th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.36 KB | None | 0 0
  1. FILENAME:
  2.     FugoCraft_Main.class:
  3.     package FugoCraft.SpongePlugin;
  4.  
  5.     import org.slf4j.Logger;
  6.     import org.spongepowered.api.Game;
  7.     import org.spongepowered.api.event.Subscribe;
  8.     import org.spongepowered.api.event.state.PreInitializationEvent;
  9.     import org.spongepowered.api.event.state.ServerStartedEvent;
  10.     import org.spongepowered.api.event.state.ServerStoppingEvent;
  11.     import org.spongepowered.api.plugin.Plugin;
  12.     import com.google.inject.Inject;
  13.    
  14.     @Plugin(id = "fugocraftmain", name = "FugoCraft Serverside Plugin", version = "1.0")
  15.     public class FugoCraft_Main {
  16.        
  17.         @Inject
  18.         public Logger logger;
  19.         @Inject
  20.         public Game game;
  21.        
  22.         public Logger getLogger(){
  23.             return logger;
  24.         }
  25.        
  26.         public Game getGame(){
  27.             return game;
  28.         }
  29.        
  30.         @Subscribe
  31.         public void onInit(PreInitializationEvent event) {
  32.             // TODO -> start plugin: load config, assign variables
  33.             commandRegister.commandHealReg(game);
  34.         }
  35.        
  36.         @Subscribe
  37.         public void OnStart(ServerStartedEvent event) {
  38.             logger.info("FugoCraft Sponge ServerSide Plugin Initializing...");
  39.            
  40.            
  41.             logger.info("FugoCraft Sponge ServerSide Plugin Done Loading!");
  42.         }
  43.         @Subscribe
  44.         public void onStop(ServerStoppingEvent event) {
  45.             // TODO -> stop plugin: save config (if changed), clean up
  46.             logger.info("FugoCraft Sponge ServerSide Plugin Stopping...");
  47.            
  48.            
  49.             logger.info("FugoCraft Sponge ServerSide Plugin Now Stopped!");
  50.         }
  51.     }
  52. FILENAME:
  53.     commandExeHeal:
  54.     package FugoCraft.SpongePlugin;
  55.  
  56.     import org.spongepowered.api.entity.player.Player;
  57.     import org.spongepowered.api.text.Texts;
  58.     import org.spongepowered.api.text.format.TextColors;
  59.     import org.spongepowered.api.util.command.CommandException;
  60.     import org.spongepowered.api.util.command.CommandResult;
  61.     import org.spongepowered.api.util.command.CommandSource;
  62.     import org.spongepowered.api.util.command.args.CommandContext;
  63.     import org.spongepowered.api.util.command.source.ConsoleSource;
  64.     import org.spongepowered.api.util.command.spec.CommandExecutor;
  65.    
  66.     public class commandExeHeal implements CommandExecutor {
  67.    
  68.        
  69.         public CommandResult execute(CommandSource src, CommandContext args)
  70.                 throws CommandException {
  71.             // Store the command target
  72.             Player target = args.<Player> getOne("target").get();
  73.    
  74.             // Store the target's hp before they are healed
  75.             double HealthBefore = target.getHealthData().getHealth();
  76.    
  77.             // Heal the target
  78.             target.getHealthData().setHealth(target.getHealthData().getMaxHealth());
  79.    
  80.             // Store the target's hp after they are healed
  81.             double HealthAfter = target.getHealthData().getHealth();
  82.    
  83.             if (src instanceof Player) {
  84.                 // Store the source as a player
  85.                 Player source = (Player) src;
  86.    
  87.                 // Tells the target that they have been healed
  88.                 target.sendMessage(Texts
  89.                     .of(TextColors.GREEN, "You have been healed by ")
  90.                     .builder()
  91.                     .append(Texts.of(TextColors.GOLD, source
  92.                         .getDisplayNameData().getDisplayName()))
  93.                     .append(Texts.of(TextColors.GREEN, " from "))
  94.                     .append(Texts.of(TextColors.RED, HealthBefore))
  95.                     .append(Texts.of(TextColors.GREEN, "hp to "))
  96.                     .append(Texts.of(TextColors.RED, HealthAfter))
  97.                     .append(Texts.of(TextColors.GREEN, "hp!")).build());
  98.    
  99.                 // Tells the player that they have healed the target
  100.                 source.sendMessage(Texts
  101.                     .of(TextColors.GREEN, "You have healed ")
  102.                     .builder()
  103.                     .append(Texts.of(TextColors.GOLD, target
  104.                         .getDisplayNameData().getDisplayName()))
  105.                     .append(Texts.of(TextColors.GREEN, " from "))  
  106.                     .append(Texts.of(TextColors.RED, HealthBefore))
  107.                     .append(Texts.of(TextColors.GREEN, "hp to "))
  108.                     .append(Texts.of(TextColors.RED, HealthAfter))
  109.                     .append(Texts.of(TextColors.GREEN, "hp!")).build());
  110.  
  111.             } else {
  112.                 // Tells the target that they have been healed by
  113.                 // "an unknown source of great power"
  114.                 target.sendMessage(Texts
  115.                         .of(TextColors.GREEN,
  116.                                 "You have been healed by an unknown source of great power!"));
  117.    
  118.                 src.sendMessage(Texts.of("You have healed "
  119.                         + target.getDisplayNameData().getDisplayName() + " from "
  120.                         + HealthBefore + "hp to " + HealthAfter + "hp."));
  121.                 if (!(src instanceof ConsoleSource)) {
  122.                     FugoCraft_Main.getLogger().info(
  123.                             "A non-player object has healed " + target.getName()
  124.                                     + " from " + HealthBefore + "hp to "
  125.                                     + HealthAfter + "hp.");
  126.                 }
  127.             }
  128.             return CommandResult.success();
  129.         }
  130.     }
  131. FILENAME:
  132.     commandRegister:
  133.     package FugoCraft.SpongePlugin;
  134.    
  135.     import org.spongepowered.api.Game;
  136.     import org.spongepowered.api.text.Texts;
  137.     import org.spongepowered.api.util.command.args.GenericArguments;
  138.     import org.spongepowered.api.util.command.spec.CommandSpec;
  139.    
  140.     public class commandRegister {
  141.            
  142.         public static void commandHealReg(Game game) {
  143.             CommandSpec healCommandSpec = CommandSpec
  144.                     .builder()
  145.                     .setDescription(Texts.of("Heals a target player."))
  146.                     .setExtendedDescription(
  147.                             Texts.of(" If no target player is specified it will heal the commmand           excecutor."))
  148.                     .setExecutor(new commandExeHeal())
  149.                     .setArguments(GenericArguments.onlyOne(
  150.                             GenericArguments.playerOrSource(
  151.                                     Texts.of("target"), game)))            
  152.                     .build();
  153.    
  154.             game.getCommandDispatcher().register(/**Not sure how to insert plugin here...**/, healCommandSpec,  "heal");   
  155.         }
  156.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement