Dateien nach "MAIN/src/main/java/com/trafalcraft/anti_redstone_clock/commands" hochladen

This commit is contained in:
2025-08-15 16:11:08 +00:00
parent e0b404e19e
commit e6a1c220be
8 changed files with 335 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class AutoRemoveDetectedClock {
private static final AutoRemoveDetectedClock ourInstance = new AutoRemoveDetectedClock();
public static AutoRemoveDetectedClock getInstance() {
return ourInstance;
}
private AutoRemoveDetectedClock() {
}
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("AutomaticallyBreakDetectedClock"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "AutomaticallyBreakDetectedClock <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("AutomaticallyBreakDetectedClock", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", String.valueOf(newValue)));
}
}

View File

@@ -0,0 +1,91 @@
package com.trafalcraft.anti_redstone_clock.commands;
import java.util.Collection;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.object.RedstoneClockController;
import com.trafalcraft.anti_redstone_clock.util.CheckTPS;
import com.trafalcraft.anti_redstone_clock.util.Msg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
public class CheckList {
private static final CheckList ourInstance = new CheckList();
public static CheckList getInstance() {
return ourInstance;
}
private CheckList() {
}
public void performCMD(CommandSender sender, String... args) {
try {
int page = 1;
if (args.length > 1) {
page = Integer.parseInt(args[1]);
if (page == -1) {
sender.sendMessage("§2TPS is " + CheckTPS.isTpsOK() + " §4TPS:" + CheckTPS.getTPS()
+ " §emin" + Main.getInstance().getConfig().getInt("checkTPS.minimumTPS")
+ " §amax" + Main.getInstance().getConfig().getInt("checkTPS.maximumTPS"));
return;
}
}
Collection<Location> allLocation = RedstoneClockController.getAllLoc();
int totalPage = (int) Math.ceil(allLocation.size() / 5.0);
sender.sendMessage(Msg.RED_STONE_CLOCK_LIST_HEADER.toString().replace("$page",
"(" + page + "/" + totalPage + ")"));
int i = 1;
int minElements = 5 * (page - 1);
int maxElements = 5 * page;
String teleportCMD = Main.getInstance().getConfig().getString("teleportCMD", "tp $x $y $z");
int maxPulses = Main.getInstance().getConfig().getInt("MaxPulses");
for (Location loc : allLocation) {
if (i > minElements && i <= maxElements) {
int clock = RedstoneClockController.getRedstoneClock(loc).getNumberOfClock();
String color = "§2"; //Dark_Green
if (clock > maxPulses * 0.75) {
color = "§4"; //Dark_Red
} else if (clock > maxPulses * 0.5) {
color = "§e"; //yellow
} else if (clock > maxPulses * 0.250) {
color = "§a"; // green
}
TextComponent textComponent = new TextComponent(color + "RedStoneClock> §fWorld:" + loc.getWorld().getName()
+ ",X:" + loc.getX()
+ ",Y:" + loc.getY()
+ ",Z:" + loc.getZ()
+ " b:" + clock + "/" + maxPulses);
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + teleportCMD
.replace("$x", String.format("%.0f", loc.getX()))
.replace("$y", String.format("%.0f", loc.getY()))
.replace("$z", String.format("%.0f", loc.getZ()))
.replace("$world", loc.getWorld().getName())
.replace("$player", sender.getName())));
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("Click to teleport you to the redstoneclock")));
sendFormatedMessageToPlayer(sender, textComponent);
}
i++;
}
sender.sendMessage(Msg.RED_STONE_CLOCK_LIST_FOOTER.toString());
} catch (NumberFormatException e) {
sender.sendMessage(Msg.COMMAND_USE.toString().replace("$command", "checkList <number>"));
}
}
private void sendFormatedMessageToPlayer(CommandSender sender, TextComponent textComponent) {
try {
sender.getClass().getDeclaredMethod("spigot");
sender.spigot().sendMessage(textComponent);
} catch (NoSuchMethodException e) {
sender.sendMessage(textComponent.getText());
}
}
}

View File

@@ -0,0 +1,40 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class CreateSignWhenClockIsBreak {
private static final CreateSignWhenClockIsBreak ourInstance = new CreateSignWhenClockIsBreak();
public static CreateSignWhenClockIsBreak getInstance() {
return ourInstance;
}
private CreateSignWhenClockIsBreak() {
}
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("CreateSignWhenClockIsBreak"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "CreateSignWhenClockIsBreak <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("CreateSignWhenClockIsBreak", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", String.valueOf(newValue)));
}
}

View File

@@ -0,0 +1,29 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class DisableRedstoneClockCheckAbove {
private static final DisableRedstoneClockCheckAbove ourInstance = new DisableRedstoneClockCheckAbove();
public static DisableRedstoneClockCheckAbove getInstance() {
return ourInstance;
}
private DisableRedstoneClockCheckAbove() {
}
public void performCMD(CommandSender sender, String... args) {
try {
Main.getInstance().getConfig().set("disableRedstoneClockCheckAbove", Integer.parseInt(args[1]));
Main.getInstance().saveConfig();
sender.sendMessage(
Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString().replace("$setting", "\"disableRedstoneClockCheckAbove\"")
.replace("$value", args[1]));
} catch (NumberFormatException e) {
sender.sendMessage(Msg.COMMAND_USE.toString().replace("$command", "disableRedstoneClockCheckAbove <number>"));
}
}
}

View File

@@ -0,0 +1,40 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class NotifyAdmin {
private static final NotifyAdmin ourInstance = new NotifyAdmin();
public static NotifyAdmin getInstance() {
return ourInstance;
}
private NotifyAdmin() {
}
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("NotifyAdmins"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "NotifyAdmins <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("NotifyAdmins", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"NotifyAdmins\"")
.replace("$value", String.valueOf(newValue)));
}
}

View File

@@ -0,0 +1,38 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.yaml.snakeyaml.error.YAMLException;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.CheckTPS;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class Reload {
private static final Reload ourInstance = new Reload();
public static Reload getInstance() {
return ourInstance;
}
private Reload() {
}
public void performCMD(CommandSender sender) {
try {
Main.getInstance().reloadConfig();
Main.getIgnoredWorlds().clear();
Main.getIgnoredRegions().clear();
CheckTPS.initCheckTPS(Main.getInstance().getConfig().getInt("checkTPS.minimumTPS")
,Main.getInstance().getConfig().getInt("checkTPS.maximumTPS")
,Main.getInstance().getConfig().getInt("checkTPS.intervalInSecond"));
Msg.load();
sender.sendMessage(Msg.PREFIX + Msg.RELOAD_SUCCESS.toString());
} catch (YAMLException e) {
if (sender instanceof Player) {
sender.sendMessage(Msg.ERROR + "An error as occurred in the config.yml please check the log!");
}
Main.getInstance().getLogger().severe("An error as occurred in the config.yml please fix it!\n" + e);
}
}
}

View File

@@ -0,0 +1,29 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class SetDelay {
private static final SetDelay ourInstance = new SetDelay();
public static SetDelay getInstance() {
return ourInstance;
}
private SetDelay() {
}
public void performCMD(CommandSender sender, String... args) {
try {
Main.getInstance().getConfig().set("Delay", Integer.parseInt(args[1]));
Main.getInstance().saveConfig();
sender.sendMessage(
Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString().replace("$setting", "\"Delay\"")
.replace("$value", args[1]));
} catch (NumberFormatException e) {
sender.sendMessage(Msg.COMMAND_USE.toString().replace("$command", "SetDelay <number>"));
}
}
}

View File

@@ -0,0 +1,28 @@
package com.trafalcraft.anti_redstone_clock.commands;
import org.bukkit.command.CommandSender;
import com.trafalcraft.anti_redstone_clock.Main;
import com.trafalcraft.anti_redstone_clock.util.Msg;
public class SetMaxPulses {
private static final SetMaxPulses ourInstance = new SetMaxPulses();
public static SetMaxPulses getInstance() {
return ourInstance;
}
private SetMaxPulses() {
}
public void performCMD(CommandSender sender, String... args) {
try {
Main.getInstance().getConfig().set("MaxPulses", Integer.parseInt(args[1]));
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString().replace("$setting", "\"MaxPulses\"")
.replace("$value", args[1]));
} catch (NumberFormatException e) {
sender.sendMessage(Msg.COMMAND_USE.toString().replace("$command", "setMaxPulses <number>"));
}
}
}