Dateien nach "MAIN/src/main/java/com/trafalcraft/anti_redstone_clock/util" hochladen
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.trafalcraft.anti_redstone_clock.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.trafalcraft.anti_redstone_clock.Main;
|
||||
|
||||
public class CheckTPS {
|
||||
|
||||
private static long lastPoll = System.currentTimeMillis();
|
||||
private static boolean tpsIsOK = true;
|
||||
private static int repeatingTaskID = -1;
|
||||
private static long tps = 20;
|
||||
|
||||
public static boolean isTpsOK() {
|
||||
return tpsIsOK;
|
||||
}
|
||||
|
||||
public static long getTPS() {
|
||||
return tps;
|
||||
}
|
||||
|
||||
public static void initCheckTPS(int minimumTPS, int maximumTPS, int interval) {
|
||||
if (repeatingTaskID != -1) {
|
||||
Bukkit.getScheduler().cancelTask(repeatingTaskID);
|
||||
tpsIsOK = true;
|
||||
}
|
||||
if (minimumTPS > 0 || maximumTPS > 0) {
|
||||
repeatingTaskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), () -> {
|
||||
long now = System.currentTimeMillis();
|
||||
long timeSpent = (now - lastPoll) / 1000;
|
||||
if (timeSpent == 0){
|
||||
timeSpent = 1;
|
||||
}
|
||||
tps = (20*interval / timeSpent);
|
||||
if (minimumTPS < 0) {
|
||||
tpsIsOK = tps <= maximumTPS;
|
||||
} else if (maximumTPS < 0) {
|
||||
tpsIsOK = tps >= minimumTPS;
|
||||
} else {
|
||||
tpsIsOK = tps >= minimumTPS && tps <= maximumTPS;
|
||||
}
|
||||
lastPoll = now;
|
||||
}, 0, 20*interval);
|
||||
} else {
|
||||
tpsIsOK = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
package com.trafalcraft.anti_redstone_clock.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.trafalcraft.anti_redstone_clock.Main;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum Msg {
|
||||
|
||||
PREFIX("&bAntiRedstoneClock &9&l> &r&b "),
|
||||
ERROR("&4AntiRedstoneClock &l> &r&c "),
|
||||
NO_PERMISSIONS("&4ERROR &9&l> &r&bYou don't have permission to do that!"),
|
||||
COMMAND_USE("&4AntiRedstoneClock &l> &r&cCommand usage: &6/arc $command"),
|
||||
|
||||
//Msg
|
||||
MSG_TO_ADMIN("Redstone clock disable in x:$X y:$Y Z:$Z. In the world $World"),
|
||||
RELOAD_SUCCESS("Reload Success! Redstone listener and third party plugin are not affected!!!"),
|
||||
UNKNOWN_CMD("Unknown command. Type \"/help\" for help."),
|
||||
NEW_VALUE_IN_CONFIG("The new value of $setting is $value"),
|
||||
RED_STONE_CLOCK_LIST_HEADER("RedstoneClockList: $page"),
|
||||
RED_STONE_CLOCK_LIST_FOOTER(""),
|
||||
//Exception
|
||||
DUPLICATE_OBJECT("This list already contains this redstone");
|
||||
|
||||
static final JavaPlugin plugin = Main.getInstance();
|
||||
|
||||
public static void getHelp(CommandSender sender) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("§3§l-------------AntiRedstoneClock-------------");
|
||||
sender.sendMessage("§3/arc checkList <Page number> §b- display the active redstoneclock.");
|
||||
sender.sendMessage("§3/arc setMaxPulses <number> §b- Change the \"MaxPulses\" setting.");
|
||||
sender.sendMessage("§3/arc setDelay <number> §b- Change the \"Delay\" setting.");
|
||||
sender.sendMessage("§3/arc notifyAdmin <true/false> §b- change the \"NotifyAdmin\" setting.");
|
||||
sender.sendMessage(
|
||||
"§3/arc autoRemoveDetectedClock <true/false> §b- change the \"AutoRemoveDetectedClock\" setting.");
|
||||
sender.sendMessage(
|
||||
"§3/arc createSignWhenClockIsBreak <true/false> §b- change the \"CreateSignWhenClockIsBreak\" setting.");
|
||||
sender.sendMessage("§3/arc reload §b- To Reload the config file. (doesn't work redstone listener and third party support)");
|
||||
sender.sendMessage(" §3Version: §6" + plugin.getDescription().getVersion());
|
||||
sender.sendMessage("§3------------------------------------------------");
|
||||
sender.sendMessage("");
|
||||
}
|
||||
|
||||
private String value;
|
||||
|
||||
Msg(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private void replaceBy(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
PREFIX.replaceBy(config.getString("Msg.default.prefix").replace("&", "§"));
|
||||
ERROR.replaceBy(config.getString("Msg.default.error").replace("&", "§"));
|
||||
NO_PERMISSIONS.replaceBy(config.getString("Msg.default.no_permission").replace("&", "§"));
|
||||
COMMAND_USE.replaceBy(config.getString("Msg.default.command_use").replace("&", "§"));
|
||||
|
||||
MSG_TO_ADMIN.replaceBy(config.getString("Msg.message.MsgToAdmin").replace("&", "§"));
|
||||
RELOAD_SUCCESS.replaceBy(config.getString("Msg.message.reloadSuccess").replace("&", "§"));
|
||||
UNKNOWN_CMD.replaceBy(config.getString("Msg.message.unknownCmd").replace("&", "§"));
|
||||
NEW_VALUE_IN_CONFIG.replaceBy(config.getString("Msg.message.newValueInConfig").replace("&", "§"));
|
||||
RED_STONE_CLOCK_LIST_HEADER.replaceBy(
|
||||
config.getString("Msg.message.RedStoneClockListHeader").replace("&", "§"));
|
||||
RED_STONE_CLOCK_LIST_FOOTER.replaceBy(
|
||||
config.getString("Msg.message.RedStoneClockListFooter").replace("&", "§"));
|
||||
|
||||
DUPLICATE_OBJECT.replaceBy(config.getString("Msg.Exception.duplicate_object").replace("&", "§"));
|
||||
|
||||
String sIgnoreWorld = config.getString("IgnoreWorlds");
|
||||
Main.getIgnoredWorlds().addAll(Arrays.asList(sIgnoreWorld.split("/")));
|
||||
String sIgnoreRegion = config.getString("IgnoreRegions");
|
||||
Main.getIgnoredRegions().addAll(Arrays.asList(sIgnoreRegion.split("/")));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user