added reload config command

This commit is contained in:
DaemonicKing 2020-05-10 15:14:04 +08:00
parent 938db166ee
commit b2ac9006c8
2 changed files with 32 additions and 2 deletions

View File

@ -1,7 +1,11 @@
package net.teamonster.tealimit; package net.teamonster.tealimit;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location; 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.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
public class Main extends JavaPlugin implements Listener public class Main extends JavaPlugin implements Listener, CommandExecutor
{ {
private int breedLimit; private int breedLimit;
private int naturalLimit; private int naturalLimit;
@ -23,9 +27,11 @@ public class Main extends JavaPlugin implements Listener
@Override @Override
public void onEnable() public void onEnable()
{ {
Bukkit.getConsoleSender().sendMessage("TeaLimit Enabled");
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
getConfig().options().copyDefaults(true); getConfig().options().copyDefaults(true);
saveConfig(); saveConfig();
getCommand("tealimit").setExecutor(this);
this.breedLimit = getConfig().getInt("breed-limit"); this.breedLimit = getConfig().getInt("breed-limit");
this.naturalLimit = getConfig().getInt("natural-limit"); this.naturalLimit = getConfig().getInt("natural-limit");
@ -34,6 +40,10 @@ public class Main extends JavaPlugin implements Listener
this.spawnerLimit = getConfig().getInt("spawner-limit"); this.spawnerLimit = getConfig().getInt("spawner-limit");
} }
public void onDisable(){
Bukkit.getConsoleSender().sendMessage("TeaLimit Disabled");
}
@EventHandler @EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) public void onCreatureSpawn(CreatureSpawnEvent event)
{ {
@ -136,4 +146,20 @@ public class Main extends JavaPlugin implements Listener
return count > limit; 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;
}
} }

View File

@ -4,3 +4,7 @@ version: ${project.version}
api-version: 1.15 api-version: 1.15
authors: [TeaMaster, Artuto] authors: [TeaMaster, Artuto]
description: Limit entity spawns description: Limit entity spawns
commands:
tealimit:
description: Basic Command