Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sosoh.essentials;
- import org.slf4j.Logger;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.entity.player.Player;
- import org.spongepowered.api.event.Subscribe;
- import org.spongepowered.api.event.entity.player.PlayerJoinEvent;
- import org.spongepowered.api.event.entity.player.PlayerQuitEvent;
- import org.spongepowered.api.event.state.InitializationEvent;
- import org.spongepowered.api.event.state.ServerStartedEvent;
- import org.spongepowered.api.plugin.Plugin;
- import org.spongepowered.api.text.Texts;
- import org.spongepowered.api.text.action.TextActions;
- import org.spongepowered.api.text.format.TextColors;
- import org.spongepowered.api.text.format.TextStyles;
- import org.spongepowered.api.text.title.Title;
- import org.spongepowered.api.util.command.args.GenericArguments;
- import org.spongepowered.api.util.command.spec.CommandSpec;
- import com.google.inject.Inject;
- import com.sosoh.essentials.commands.MenuCommand;
- import com.sosoh.essentials.commands.SetSpawnCommand;
- import com.sosoh.essentials.commands.SpawnCommand;
- import com.sosoh.essentials.commands.TeleportPlayerHereCommand;
- import com.sosoh.essentials.commands.TeleportToPlayerCommand;
- import com.sosoh.essentials.commands.TimeCommand;
- import com.sosoh.essentials.commands.TimeGetCommand;
- import com.sosoh.essentials.commands.TimeSetCommand;
- import com.sosoh.essentials.commands.economy.BalanceCommand;
- import com.sosoh.essentials.services.EconomyService;
- import com.sosoh.essentials.services.SimpleEconomyService;
- @Plugin(id = "essentials", name = "Essentials Plugin", version = "0.1")
- public class Main {
- public static Main access;
- public EconomyService economy;
- @Inject
- private Logger logger;
- private Game game;
- public Logger getLogger() {
- return logger;
- }
- public Game getGame() {
- return game;
- }
- @Subscribe
- public void onServerStart(ServerStartedEvent event) {
- getLogger().info("[Essentials] Plugin Initialized");
- }
- @Subscribe
- public void Initalization(InitializationEvent event) {
- this.game = event.getGame();
- try
- {
- game.getServiceManager().setProvider(this, EconomyService.class, new SimpleEconomyService());
- getLogger().info("Economy Service has been registred !");
- } catch (Exception e){
- e.printStackTrace();
- }
- economy = getGame().getServiceManager().provide(EconomyService.class).get();
- //Commands
- CommandSpec spawn = CommandSpec.builder()
- .description(Texts.of("Teleport the player to the spawn."))
- .permission("essentials.command.spawn.use")
- .executor(new SpawnCommand())
- .build();
- CommandSpec setspawn = CommandSpec.builder()
- .description(Texts.of("Set the new spawnpoint."))
- .permission("essentials.command.spawn.set")
- .executor(new SetSpawnCommand())
- .build();
- CommandSpec timeget = CommandSpec.builder()
- .description(Texts.of("Reply the in game time."))
- .permission("essentials.command.time.get")
- .executor(new TimeGetCommand())
- .build();
- CommandSpec timeset = CommandSpec.builder()
- .description(Texts.of("Set the in game time."))
- .permission("essentials.command.time.set")
- .arguments(GenericArguments.onlyOne(GenericArguments.integer(Texts.of("Value"))))
- .executor(new TimeSetCommand())
- .build();
- CommandSpec time = CommandSpec.builder()
- .description(Texts.of("Time Administration."))
- .permission("essentials.command.time")
- .executor(new TimeCommand())
- .child(timeget, "get")
- .child(timeset, "set")
- .build();
- CommandSpec tpplayer = CommandSpec.builder()
- .description(Texts.of("Teleport the player to an other player."))
- .permission("essentials.command.tp.player.to")
- .executor(new TeleportToPlayerCommand())
- .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
- .build();
- CommandSpec tpplayerhere = CommandSpec.builder()
- .description(Texts.of("Teleport the player to an other player."))
- .permission("essentials.command.tp.player.here")
- .executor(new TeleportPlayerHereCommand())
- .arguments(GenericArguments.onlyOne(GenericArguments.player(Texts.of("Player"), getGame())))
- .build();
- CommandSpec menu = CommandSpec.builder()
- .description(Texts.of("Open the menu."))
- .permission("essentials.command.menu.open")
- .executor(new MenuCommand())
- .build();
- CommandSpec balance = CommandSpec.builder()
- .description(Texts.of("Tell the player his balance."))
- .permission("essentials.command.economy.balance")
- .executor(new BalanceCommand())
- .build();
- game.getCommandDispatcher().register(this, spawn, "spawn");
- game.getCommandDispatcher().register(this, setspawn, "setspawn");
- game.getCommandDispatcher().register(this, time, "time");
- game.getCommandDispatcher().register(this, tpplayer, "tp");
- game.getCommandDispatcher().register(this, tpplayerhere, "tphere");
- game.getCommandDispatcher().register(this, menu, "menu");
- game.getCommandDispatcher().register(this, balance, "balance");
- }
- @Subscribe
- public void playerJoinEvent(PlayerJoinEvent event){
- Player player = event.getEntity();
- economy.setBalance(player, 500);
- event.setNewMessage(Texts.builder("[+] ").color(TextColors.DARK_GREEN)
- .append(Texts.builder(player.getName()).color(TextColors.GREEN)
- .append(Texts.builder(" [+]").color(TextColors.DARK_GREEN)
- .build())
- .build())
- .onHover(TextActions.showText(Texts.builder("Click to say hi to him !")
- .color(TextColors.GREEN)
- .build()))
- .onClick(TextActions.suggestCommand("/tell "+player.getName()))
- .build());
- player.sendTitle(new Title(null, null, null, null, null, false, false).builder()
- .title(Texts.builder("Welcome Back !").color(TextColors.DARK_GREEN).build())
- .subtitle(Texts.builder(player.getName()).color(TextColors.GREEN).style(TextStyles.BOLD).build())
- .stay(80)
- .build());
- }
- @Subscribe
- public void playerQuitEvent(PlayerQuitEvent event){
- Player player = event.getEntity();
- event.setNewMessage(Texts.builder("[-] ").color(TextColors.DARK_RED)
- .append(Texts.builder(player.getName()).color(TextColors.RED)
- .append(Texts.builder(" [-]").color(TextColors.DARK_RED)
- .build())
- .build())
- .build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement