Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FILENAME:
- FugoCraft_Main.class:
- package FugoCraft.SpongePlugin;
- import org.slf4j.Logger;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.event.Subscribe;
- import org.spongepowered.api.event.state.PreInitializationEvent;
- import org.spongepowered.api.event.state.ServerStartedEvent;
- import org.spongepowered.api.event.state.ServerStoppingEvent;
- import org.spongepowered.api.plugin.Plugin;
- import com.google.inject.Inject;
- @Plugin(id = "fugocraftmain", name = "FugoCraft Serverside Plugin", version = "1.0")
- public class FugoCraft_Main {
- @Inject
- public Logger logger;
- @Inject
- public Game game;
- public Logger getLogger(){
- return logger;
- }
- public Game getGame(){
- return game;
- }
- @Subscribe
- public void onInit(PreInitializationEvent event) {
- // TODO -> start plugin: load config, assign variables
- commandRegister.commandHealReg(game);
- }
- @Subscribe
- public void OnStart(ServerStartedEvent event) {
- logger.info("FugoCraft Sponge ServerSide Plugin Initializing...");
- logger.info("FugoCraft Sponge ServerSide Plugin Done Loading!");
- }
- @Subscribe
- public void onStop(ServerStoppingEvent event) {
- // TODO -> stop plugin: save config (if changed), clean up
- logger.info("FugoCraft Sponge ServerSide Plugin Stopping...");
- logger.info("FugoCraft Sponge ServerSide Plugin Now Stopped!");
- }
- }
- FILENAME:
- commandExeHeal:
- package FugoCraft.SpongePlugin;
- import org.spongepowered.api.entity.player.Player;
- import org.spongepowered.api.text.Texts;
- import org.spongepowered.api.text.format.TextColors;
- import org.spongepowered.api.util.command.CommandException;
- import org.spongepowered.api.util.command.CommandResult;
- import org.spongepowered.api.util.command.CommandSource;
- import org.spongepowered.api.util.command.args.CommandContext;
- import org.spongepowered.api.util.command.source.ConsoleSource;
- import org.spongepowered.api.util.command.spec.CommandExecutor;
- public class commandExeHeal implements CommandExecutor {
- public CommandResult execute(CommandSource src, CommandContext args)
- throws CommandException {
- // Store the command target
- Player target = args.<Player> getOne("target").get();
- // Store the target's hp before they are healed
- double HealthBefore = target.getHealthData().getHealth();
- // Heal the target
- target.getHealthData().setHealth(target.getHealthData().getMaxHealth());
- // Store the target's hp after they are healed
- double HealthAfter = target.getHealthData().getHealth();
- if (src instanceof Player) {
- // Store the source as a player
- Player source = (Player) src;
- // Tells the target that they have been healed
- target.sendMessage(Texts
- .of(TextColors.GREEN, "You have been healed by ")
- .builder()
- .append(Texts.of(TextColors.GOLD, source
- .getDisplayNameData().getDisplayName()))
- .append(Texts.of(TextColors.GREEN, " from "))
- .append(Texts.of(TextColors.RED, HealthBefore))
- .append(Texts.of(TextColors.GREEN, "hp to "))
- .append(Texts.of(TextColors.RED, HealthAfter))
- .append(Texts.of(TextColors.GREEN, "hp!")).build());
- // Tells the player that they have healed the target
- source.sendMessage(Texts
- .of(TextColors.GREEN, "You have healed ")
- .builder()
- .append(Texts.of(TextColors.GOLD, target
- .getDisplayNameData().getDisplayName()))
- .append(Texts.of(TextColors.GREEN, " from "))
- .append(Texts.of(TextColors.RED, HealthBefore))
- .append(Texts.of(TextColors.GREEN, "hp to "))
- .append(Texts.of(TextColors.RED, HealthAfter))
- .append(Texts.of(TextColors.GREEN, "hp!")).build());
- } else {
- // Tells the target that they have been healed by
- // "an unknown source of great power"
- target.sendMessage(Texts
- .of(TextColors.GREEN,
- "You have been healed by an unknown source of great power!"));
- src.sendMessage(Texts.of("You have healed "
- + target.getDisplayNameData().getDisplayName() + " from "
- + HealthBefore + "hp to " + HealthAfter + "hp."));
- if (!(src instanceof ConsoleSource)) {
- FugoCraft_Main.getLogger().info(
- "A non-player object has healed " + target.getName()
- + " from " + HealthBefore + "hp to "
- + HealthAfter + "hp.");
- }
- }
- return CommandResult.success();
- }
- }
- FILENAME:
- commandRegister:
- package FugoCraft.SpongePlugin;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.text.Texts;
- import org.spongepowered.api.util.command.args.GenericArguments;
- import org.spongepowered.api.util.command.spec.CommandSpec;
- public class commandRegister {
- public static void commandHealReg(Game game) {
- CommandSpec healCommandSpec = CommandSpec
- .builder()
- .setDescription(Texts.of("Heals a target player."))
- .setExtendedDescription(
- Texts.of(" If no target player is specified it will heal the commmand excecutor."))
- .setExecutor(new commandExeHeal())
- .setArguments(GenericArguments.onlyOne(
- GenericArguments.playerOrSource(
- Texts.of("target"), game)))
- .build();
- game.getCommandDispatcher().register(/**Not sure how to insert plugin here...**/, healCommandSpec, "heal");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement