From 66870ee42e7567a3856b824c0568d073d2166fc8 Mon Sep 17 00:00:00 2001 From: DaemonicKing Date: Sun, 10 May 2020 15:14:04 +0800 Subject: [PATCH] added reload config command --- .../java/net/teamonster/tealimit/Main.java | 28 ++++++++++++++++++- src/main/resources/plugin.yml | 6 +++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/teamonster/tealimit/Main.java b/src/main/java/net/teamonster/tealimit/Main.java index 25aa725..e490858 100644 --- a/src/main/java/net/teamonster/tealimit/Main.java +++ b/src/main/java/net/teamonster/tealimit/Main.java @@ -1,7 +1,11 @@ package net.teamonster.tealimit; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; @@ -12,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.Collection; import java.util.List; -public class Main extends JavaPlugin implements Listener +public class Main extends JavaPlugin implements Listener, CommandExecutor { private int breedLimit; private int naturalLimit; @@ -23,9 +27,11 @@ public class Main extends JavaPlugin implements Listener @Override public void onEnable() { + Bukkit.getConsoleSender().sendMessage("TeaLimit Enabled"); getServer().getPluginManager().registerEvents(this, this); getConfig().options().copyDefaults(true); saveConfig(); + getCommand("tealimit").setExecutor(this); this.breedLimit = getConfig().getInt("breed-limit"); this.naturalLimit = getConfig().getInt("natural-limit"); @@ -34,6 +40,10 @@ public class Main extends JavaPlugin implements Listener this.spawnerLimit = getConfig().getInt("spawner-limit"); } + public void onDisable(){ + Bukkit.getConsoleSender().sendMessage("TeaLimit Disabled"); + } + @EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { @@ -136,4 +146,20 @@ public class Main extends JavaPlugin implements Listener return count > limit; } + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ + if(cmd.getName().equalsIgnoreCase("tealimit")){ + if(args.length == 0){ + sender.sendMessage("Invalid argument!"); + return false; + } + if(args.length == 1 && args[0].equalsIgnoreCase("reload")){ + sender.sendMessage("Reloading Configuration"); + reloadConfig(); + sender.sendMessage("Configuration Reloaded"); + return true; + } + } + return false; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d9d28c5..537e4e0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,4 +3,8 @@ main: net.teamonster.tealimit.Main version: ${project.version} api-version: 1.15 authors: [TeaMaster, Artuto] -description: Limit entity spawns \ No newline at end of file +description: Limit entity spawns + +commands: + tealimit: + description: Basic Command