From 62303184033ebad752f6407affd1d670277e42f6 Mon Sep 17 00:00:00 2001 From: "Reichenbach, Michael" Date: Fri, 21 Jan 2022 08:26:48 +0100 Subject: [PATCH] chore: cleanup old src --- .../java/net/silthus/template/Constants.java | 7 -- .../net/silthus/template/TemplatePlugin.java | 93 ------------------- .../template/commands/TemplateCommands.java | 49 ---------- src/main/resources/config.yml | 1 - src/main/resources/lang_en.yaml | 5 - .../silthus/template/TemplatePluginTests.java | 14 --- .../java/net/silthus/template/TestBase.java | 34 ------- .../commands/TemplateCommandsTests.java | 32 ------- .../integrations/vault/VaultProviderTest.java | 29 ------ 9 files changed, 264 deletions(-) delete mode 100644 src/main/java/net/silthus/template/Constants.java delete mode 100644 src/main/java/net/silthus/template/TemplatePlugin.java delete mode 100644 src/main/java/net/silthus/template/commands/TemplateCommands.java delete mode 100644 src/main/resources/config.yml delete mode 100644 src/main/resources/lang_en.yaml delete mode 100644 src/test/java/net/silthus/template/TemplatePluginTests.java delete mode 100644 src/test/java/net/silthus/template/TestBase.java delete mode 100644 src/test/java/net/silthus/template/commands/TemplateCommandsTests.java delete mode 100644 src/test/java/net/silthus/template/integrations/vault/VaultProviderTest.java diff --git a/src/main/java/net/silthus/template/Constants.java b/src/main/java/net/silthus/template/Constants.java deleted file mode 100644 index 19cbf58..0000000 --- a/src/main/java/net/silthus/template/Constants.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.silthus.template; - -public final class Constants { - - public static final String ACF_BASE_KEY = "commands"; - public static final String INFO_CMD_PERMISSION = "stemplate.admin.info"; -} diff --git a/src/main/java/net/silthus/template/TemplatePlugin.java b/src/main/java/net/silthus/template/TemplatePlugin.java deleted file mode 100644 index d27793a..0000000 --- a/src/main/java/net/silthus/template/TemplatePlugin.java +++ /dev/null @@ -1,93 +0,0 @@ -package net.silthus.template; - -import co.aikar.commands.PaperCommandManager; -import kr.entree.spigradle.annotations.PluginMain; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.milkbowl.vault.chat.Chat; -import net.milkbowl.vault.economy.Economy; -import net.silthus.template.commands.TemplateCommands; -import net.silthus.template.integrations.vault.VaultProvider; -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.plugin.java.JavaPluginLoader; - -import java.io.File; -import java.io.IOException; -import java.util.Locale; -import java.util.Objects; - -@PluginMain -public class TemplatePlugin extends JavaPlugin implements Listener { - - @Getter - @Accessors(fluent = true) - private static TemplatePlugin instance; - @Getter - @Setter(AccessLevel.PACKAGE) - private VaultProvider vault; - private PaperCommandManager commandManager; - - public TemplatePlugin() { - instance = this; - } - - public TemplatePlugin( - JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { - super(loader, description, dataFolder, file); - instance = this; - } - - @Override - public void onEnable() { - saveDefaultConfig(); - - setupVaultIntegration(); - setupCommands(); - - getServer().getPluginManager().registerEvents(this, this); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - getLogger().info("Player joined."); - } - - private void setupVaultIntegration() { - if (Bukkit.getPluginManager().isPluginEnabled("Vault")) { - vault = new VaultProvider(Objects.requireNonNull(getServer().getServicesManager().getRegistration(Economy.class)).getProvider()); - } else { - vault = new VaultProvider(); - } - } - - private void setupCommands() { - commandManager = new PaperCommandManager(this); - commandManager.enableUnstableAPI("help"); - - loadCommandLocales(commandManager); - - commandManager.registerCommand(new TemplateCommands()); - } - - // see https://github.com/aikar/commands/wiki/Locales - private void loadCommandLocales(PaperCommandManager commandManager) { - try { - saveResource("lang_en.yaml", true); - commandManager.getLocales().setDefaultLocale(Locale.ENGLISH); - commandManager.getLocales().loadYamlLanguageFile("lang_en.yaml", Locale.ENGLISH); - // this will detect the client locale and use it where possible - commandManager.usePerIssuerLocale(true); - } catch (IOException | InvalidConfigurationException e) { - getLogger().severe("Failed to load language config 'lang_en.yaml': " + e.getMessage()); - e.printStackTrace(); - } - } -} diff --git a/src/main/java/net/silthus/template/commands/TemplateCommands.java b/src/main/java/net/silthus/template/commands/TemplateCommands.java deleted file mode 100644 index c7bfa9d..0000000 --- a/src/main/java/net/silthus/template/commands/TemplateCommands.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.silthus.template.commands; - -import co.aikar.commands.BaseCommand; -import co.aikar.commands.CommandHelp; -import co.aikar.commands.MessageType; -import co.aikar.commands.annotation.*; -import co.aikar.locales.MessageKey; -import org.bukkit.Statistic; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import static net.silthus.template.Constants.ACF_BASE_KEY; -import static net.silthus.template.Constants.INFO_CMD_PERMISSION; - -@CommandAlias("stemplate") -public class TemplateCommands extends BaseCommand { - - // see https://github.com/aikar/commands/wiki/Locales - static MessageKey key(String key) { - return MessageKey.of(ACF_BASE_KEY + "." + key); - } - - // see https://github.com/aikar/commands/wiki/Command-Help - @HelpCommand - @Subcommand("help") - public void showHelp(CommandSender sender, CommandHelp help) { - help.showHelp(); - } - - @Subcommand("info|i") - @CommandAlias("info") - @Description("{@@commands.descriptions.info}") - @CommandCompletion("@players") - @CommandPermission(INFO_CMD_PERMISSION) - public void info(@Flags("self") Player player) { - success("info", - "{player}", player.getName(), - "{play_time}", player.getStatistic(Statistic.PLAY_ONE_MINUTE) + " Minutes" - ); - } - - private void success(String key, String... replacements) { - getCurrentCommandIssuer().sendMessage(MessageType.INFO, key(key), replacements); - } - - private void error(String key, String... replacements) { - getCurrentCommandIssuer().sendMessage(MessageType.ERROR, key(key), replacements); - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index 293cbf8..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1 +0,0 @@ -# add your configuration properties here \ No newline at end of file diff --git a/src/main/resources/lang_en.yaml b/src/main/resources/lang_en.yaml deleted file mode 100644 index 1c0103e..0000000 --- a/src/main/resources/lang_en.yaml +++ /dev/null @@ -1,5 +0,0 @@ -# See https://github.com/aikar/commands/wiki/Locales -commands: - descriptions: - info: 'Prints out the players name and play time.' - info: 'Your name is: {player}. Playtime: {play_time}.' \ No newline at end of file diff --git a/src/test/java/net/silthus/template/TemplatePluginTests.java b/src/test/java/net/silthus/template/TemplatePluginTests.java deleted file mode 100644 index faf64d1..0000000 --- a/src/test/java/net/silthus/template/TemplatePluginTests.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.silthus.template; - -import org.bukkit.event.player.PlayerJoinEvent; -import org.junit.jupiter.api.Test; - -public class TemplatePluginTests extends TestBase { - - @Test - public void shouldFirePlayerJoinEvent() { - server.addPlayer(); - - server.getPluginManager().assertEventFired(PlayerJoinEvent.class); - } -} diff --git a/src/test/java/net/silthus/template/TestBase.java b/src/test/java/net/silthus/template/TestBase.java deleted file mode 100644 index e79190e..0000000 --- a/src/test/java/net/silthus/template/TestBase.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.silthus.template; - -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import net.milkbowl.vault.economy.Economy; -import net.silthus.template.integrations.vault.VaultProvider; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; - -import static org.mockito.Mockito.mock; - -public abstract class TestBase { - - protected ServerMock server; - protected TemplatePlugin plugin; - protected Economy economy; - - @BeforeEach - public void setUp() { - server = MockBukkit.mock(); - plugin = MockBukkit.load(TemplatePlugin.class); - mockVaultEconomy(); - } - - private void mockVaultEconomy() { - economy = mock(Economy.class); - plugin.setVault(new VaultProvider(economy)); - } - - @AfterEach - public void tearDown() { - MockBukkit.unmock(); - } -} diff --git a/src/test/java/net/silthus/template/commands/TemplateCommandsTests.java b/src/test/java/net/silthus/template/commands/TemplateCommandsTests.java deleted file mode 100644 index 0e00735..0000000 --- a/src/test/java/net/silthus/template/commands/TemplateCommandsTests.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.silthus.template.commands; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import net.silthus.template.Constants; -import net.silthus.template.TestBase; -import org.bukkit.Statistic; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TemplateCommandsTests extends TestBase { - - private PlayerMock player; - - @Override - @BeforeEach - public void setUp() { - super.setUp(); - - player = server.addPlayer(); - player.addAttachment(plugin, Constants.INFO_CMD_PERMISSION, true); - } - - @Test - void info_forSelf_printsOwnPlayerName() { - player.performCommand("stemplate info"); - - int minutesPlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE); - assertThat(player.nextMessage()).contains("Your name is: Player0. Playtime: " + minutesPlayed); - } -} diff --git a/src/test/java/net/silthus/template/integrations/vault/VaultProviderTest.java b/src/test/java/net/silthus/template/integrations/vault/VaultProviderTest.java deleted file mode 100644 index 810bd71..0000000 --- a/src/test/java/net/silthus/template/integrations/vault/VaultProviderTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.silthus.template.integrations.vault; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import net.silthus.template.TestBase; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -class VaultProviderTest extends TestBase { - - private PlayerMock player; - - @Override - @BeforeEach - public void setUp() { - super.setUp(); - - player = server.addPlayer(); - } - - @Test - void getPlayerBalance_returnsVaultBalance() { - when(economy.getBalance(player)).thenReturn(100D); - - assertThat(plugin.getVault().getBalance(player)).isEqualTo(100D); - } -} \ No newline at end of file