Merge pull request #1 from DaemonicKing/master

added reload config command
This commit is contained in:
Govindas 2020-05-12 16:30:59 +03:00
commit 9fbf1c778b
2 changed files with 41 additions and 2 deletions

View File

@ -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,27 @@ 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(sender.hasPermission("tealimit.admin")){
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;
}
}
else{
sender.sendMessage("Insufficient Permission!");
return false;
}
}
return false;
}
}

View File

@ -4,3 +4,9 @@ version: ${project.version}
api-version: 1.15
authors: [TeaMaster, Artuto]
description: Limit entity spawns
commands:
tealimit:
permission: tealimit.admin
description: Basic Command
usage: /<command> - usage