From bf36d49e5ce95724433fa24ab356ba962a7ac77b Mon Sep 17 00:00:00 2001 From: Silthus Date: Sun, 17 Oct 2021 16:50:12 +0200 Subject: [PATCH] fix: add default config.yml fix #128 --- .../net/silthus/template/TemplatePlugin.java | 37 ++++++++++++------- src/main/resources/config.yml | 1 + .../silthus/template/TemplatePluginTests.java | 30 +++++++-------- 3 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/net/silthus/template/TemplatePlugin.java b/src/main/java/net/silthus/template/TemplatePlugin.java index 7dbab7c..48843c4 100644 --- a/src/main/java/net/silthus/template/TemplatePlugin.java +++ b/src/main/java/net/silthus/template/TemplatePlugin.java @@ -1,6 +1,8 @@ package net.silthus.template; import kr.entree.spigradle.annotations.PluginMain; +import lombok.Getter; +import lombok.experimental.Accessors; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -13,21 +15,30 @@ @PluginMain public class TemplatePlugin extends JavaPlugin implements Listener { - public TemplatePlugin() {} + @Getter + @Accessors(fluent = true) + private static TemplatePlugin instance; - public TemplatePlugin( - JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { - super(loader, description, dataFolder, file); - } + public TemplatePlugin() { + instance = this; + } - @Override - public void onEnable() { + public TemplatePlugin( + JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { + super(loader, description, dataFolder, file); + instance = this; + } - getServer().getPluginManager().registerEvents(this, this); - } + @Override + public void onEnable() { - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - getLogger().info("Player joined."); - } + saveDefaultConfig(); + + getServer().getPluginManager().registerEvents(this, this); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + getLogger().info("Player joined."); + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..c8f1922 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1 @@ +# add your default configuration properties here \ 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 index 1e8f08e..693d5e4 100644 --- a/src/test/java/net/silthus/template/TemplatePluginTests.java +++ b/src/test/java/net/silthus/template/TemplatePluginTests.java @@ -9,24 +9,24 @@ public class TemplatePluginTests { - private ServerMock server; + private ServerMock server; - @BeforeEach - public void setUp() { - server = MockBukkit.mock(); - MockBukkit.load(TemplatePlugin.class); - } + @BeforeEach + public void setUp() { + server = MockBukkit.mock(); + MockBukkit.load(TemplatePlugin.class); + } - @Test - public void shouldFirePlayerJoinEvent() { + @Test + public void shouldFirePlayerJoinEvent() { - server.addPlayer(); + server.addPlayer(); - server.getPluginManager().assertEventFired(PlayerJoinEvent.class); - } + server.getPluginManager().assertEventFired(PlayerJoinEvent.class); + } - @AfterEach - public void tearDown() { - MockBukkit.unmock(); - } + @AfterEach + public void tearDown() { + MockBukkit.unmock(); + } }