mirror of
https://github.com/Elecast2/EntityTrackerFixer.git
synced 2024-11-25 19:35:13 +01:00
Added reload command
This commit is contained in:
parent
762414b495
commit
1c344bd691
@ -1,7 +1,18 @@
|
||||
name: EntityTrackerFixer
|
||||
main: net.minemora.entitytrackerfixer.EntityTrackerFixer
|
||||
version: 1.2.7
|
||||
version: 1.3
|
||||
softdepend: [Vault]
|
||||
api-version: 1.14
|
||||
author: Esmorall
|
||||
description: Untrack entities that are not used at all by the server.
|
||||
commands:
|
||||
entitytrackerfixer:
|
||||
aliases: [etf]
|
||||
description: Main Command of EntityTrackerFixer
|
||||
usage: /etf
|
||||
permissions:
|
||||
entitytrackerfixer.*:
|
||||
children:
|
||||
- entitytrackerfixer.reload
|
||||
entitytrackerfixer.reload:
|
||||
default: op
|
@ -1,20 +1,45 @@
|
||||
package net.minemora.entitytrackerfixer;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import net.minemora.entitytrackerfixer.commands.CommandETF;
|
||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||
import net.minemora.entitytrackerfixer.nms.NMSCheck;
|
||||
import net.minemora.entitytrackerfixer.vault.VaultManager;
|
||||
|
||||
public class EntityTrackerFixer extends JavaPlugin {
|
||||
|
||||
public static EntityTrackerFixer plugin;
|
||||
|
||||
private NMS nms;
|
||||
|
||||
private BukkitTask untrackerTask;
|
||||
private BukkitTask checkTask;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
ConfigMain.getInstance().setup(this);
|
||||
NMS nms = NMSCheck.getNMS(this);
|
||||
nms.startTasks(this);
|
||||
nms = NMSCheck.getNMS(this);
|
||||
untrackerTask = nms.startUntrackerTask(this);
|
||||
checkTask = nms.startUCheckTask(this);
|
||||
VaultManager.setup(this);
|
||||
this.getCommand("entitytrackerfixer").setExecutor(new CommandETF());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
untrackerTask.cancel();
|
||||
checkTask.cancel();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
untrackerTask.cancel();
|
||||
checkTask.cancel();
|
||||
ConfigMain.getInstance().setup(this);
|
||||
untrackerTask = nms.startUntrackerTask(this);
|
||||
checkTask = nms.startUCheckTask(this);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package net.minemora.entitytrackerfixer.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
||||
import net.minemora.entitytrackerfixer.vault.VaultManager;
|
||||
|
||||
public class CommandETF implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
|
||||
if(args.length == 0) {
|
||||
return true;
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("reload")) {
|
||||
if(commandSender instanceof Player) {
|
||||
if (!VaultManager.hasPermission((Player) commandSender, "entitytrackerfixer.reload")) {
|
||||
commandSender.sendMessage(ChatColor.RED + "You don't have permission to use that command.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
EntityTrackerFixer.plugin.reload();
|
||||
commandSender.sendMessage(ChatColor.GREEN + "The config has been reloaded sucessfully!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -5,6 +5,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import net.minemora.entitytrackerfixer.EntityTrackerFixer;
|
||||
|
||||
public final class ConfigMain extends Config {
|
||||
|
||||
private static ConfigMain instance;
|
||||
@ -24,12 +26,21 @@ public final class ConfigMain extends Config {
|
||||
@Override
|
||||
public void load(boolean firstCreate) {
|
||||
untrackTicks = getConfig().getInt("untrack-ticks", 1000);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting untrack ticks to: " + untrackTicks);
|
||||
checkFrequency = getConfig().getInt("check-untracked-entities-frequency", 60);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting check frequency to: " + checkFrequency);
|
||||
trackingRange = getConfig().getInt("tracking-range", 25);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting tracking range to: " + trackingRange);
|
||||
minTps = getConfig().getDouble("tps-limit", 18.5);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting minmun TPS to: " + minTps);
|
||||
worlds = getConfig().getStringList("worlds");
|
||||
for(String world : worlds) {
|
||||
EntityTrackerFixer.plugin.getLogger().info("Adding world: " + world);
|
||||
}
|
||||
logToConsole = getConfig().getBoolean("log-to-console", true);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting log to console to: " + logToConsole);
|
||||
disableTickUntracked = getConfig().getBoolean("disable-tick-for-untracked-entities", true);
|
||||
EntityTrackerFixer.plugin.getLogger().info("Setting disable tick for untracked to: " + disableTickUntracked);
|
||||
}
|
||||
|
||||
public static FileConfiguration get() {
|
||||
|
@ -1,8 +1,12 @@
|
||||
package net.minemora.entitytrackerfixer.nms;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public interface NMS {
|
||||
|
||||
public void startTasks(Plugin plugin);
|
||||
public BukkitTask startUntrackerTask(Plugin plugin);
|
||||
|
||||
public BukkitTask startUCheckTask(Plugin plugin);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minemora.entitytrackerfixer.v1_14_R1;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||
@ -10,9 +11,13 @@ import net.minemora.entitytrackerfixer.v1_14_R1.tasks.UntrackerTask;
|
||||
public class NMSHandler implements NMS {
|
||||
|
||||
@Override
|
||||
public void startTasks(Plugin plugin) {
|
||||
new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
public BukkitTask startUntrackerTask(Plugin plugin) {
|
||||
return new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask startUCheckTask(Plugin plugin) {
|
||||
return new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minemora.entitytrackerfixer.v1_15_R1;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||
@ -10,9 +11,13 @@ import net.minemora.entitytrackerfixer.v1_15_R1.tasks.UntrackerTask;
|
||||
public class NMSHandler implements NMS {
|
||||
|
||||
@Override
|
||||
public void startTasks(Plugin plugin) {
|
||||
new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
public BukkitTask startUntrackerTask(Plugin plugin) {
|
||||
return new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask startUCheckTask(Plugin plugin) {
|
||||
return new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minemora.entitytrackerfixer.v1_16_R1;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import net.minemora.entitytrackerfixer.config.ConfigMain;
|
||||
import net.minemora.entitytrackerfixer.nms.NMS;
|
||||
@ -10,8 +11,13 @@ import net.minemora.entitytrackerfixer.v1_16_R1.tasks.UntrackerTask;
|
||||
public class NMSHandler implements NMS {
|
||||
|
||||
@Override
|
||||
public void startTasks(Plugin plugin) {
|
||||
new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
public BukkitTask startUntrackerTask(Plugin plugin) {
|
||||
return new UntrackerTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks(), ConfigMain.getUntrackTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask startUCheckTask(Plugin plugin) {
|
||||
return new CheckTask().runTaskTimer(plugin, ConfigMain.getUntrackTicks() + 1, ConfigMain.getCheckFrequency());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package net.minemora.entitytrackerfixer.vault;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public final class VaultManager {
|
||||
|
||||
private static boolean enabled = true;
|
||||
|
||||
private static Permission perms = null;
|
||||
|
||||
private VaultManager() {}
|
||||
|
||||
public static void setup(Plugin plugin) {
|
||||
if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
enabled = false;
|
||||
plugin.getLogger().info("Vault not found! using default permission system...");
|
||||
return;
|
||||
}
|
||||
setupPermissions(plugin);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player player, String permission) {
|
||||
if(enabled) {
|
||||
return getPermissions().has(player, permission);
|
||||
}
|
||||
else {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean setupPermissions(Plugin plugin) {
|
||||
RegisteredServiceProvider<Permission> rsp = plugin.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
perms = rsp.getProvider();
|
||||
return perms != null;
|
||||
}
|
||||
|
||||
public static Permission getPermissions() {
|
||||
return perms;
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user