diff options
Diffstat (limited to 'src/main/java/de/hype/bbsentials/client')
6 files changed, 370 insertions, 168 deletions
diff --git a/src/main/java/de/hype/bbsentials/client/BBsentials.java b/src/main/java/de/hype/bbsentials/client/BBsentials.java index 66807a0..2317a18 100644 --- a/src/main/java/de/hype/bbsentials/client/BBsentials.java +++ b/src/main/java/de/hype/bbsentials/client/BBsentials.java @@ -21,6 +21,9 @@ import org.lwjgl.glfw.GLFW; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import static de.hype.bbsentials.chat.Chat.*; @@ -29,7 +32,7 @@ public class BBsentials implements ClientModInitializer { public static Config config; public static BBsentialConnection bbserver; public static CommandsOLD coms; - + public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000); /** * Runs the mod initializer on the client environment. */ @@ -122,7 +125,7 @@ public class BBsentials implements ClientModInitializer { String variableName = StringArgumentType.getString(context, "variableName"); String variableValue = StringArgumentType.getString(context, "variableValue"); try { - if (!variableName.contains("dev")||config.bbsentialsRoles.contains("dev")){ + if (!variableName.toLowerCase().contains("dev")||config.hasBBRoles("dev")){ setVariableValue(getConfig(), variableName, variableValue);} getConfig().save(); } catch (ClassNotFoundException | NoSuchFieldException | @@ -166,6 +169,7 @@ public class BBsentials implements ClientModInitializer { }))) ); }); //bbi} + executionService.scheduleAtFixedRate(new DebugThread(),0,20, TimeUnit.SECONDS); } public static void refreshCommands() { diff --git a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java index 10b3037..e1f3141 100644 --- a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java +++ b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java @@ -1,29 +1,41 @@ package de.hype.bbsentials.client.Commands; +import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; +import de.hype.bbsentials.chat.Chat; import de.hype.bbsentials.client.BBsentials; -import de.hype.bbsentials.communication.BBsentialConnection; +import de.hype.bbsentials.constants.enviromentShared.ChChestItems; +import de.hype.bbsentials.constants.enviromentShared.Islands; +import de.hype.bbsentials.constants.enviromentShared.MiningEvents; +import de.hype.bbsentials.packets.AbstractPacket; +import de.hype.bbsentials.packets.packets.*; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.fabricmc.fabric.api.event.Event; import net.minecraft.command.CommandSource; +import java.util.ArrayList; +import java.util.List; + import static de.hype.bbsentials.client.BBsentials.*; public class CommandsOLD { public CommandsOLD() { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("warp").then(ClientCommandManager.argument("destination", StringArgumentType.string()).suggests((context, builder) -> { - // Provide tab-completion options for menu subfolder - return CommandSource.suggestMatching(new String[]{"desert", "hub", "dhub", "nether", "isle", "wizard", "portal", "mines", "forge", "ch", "crystals", "nucleus", "end", "drag", "void", "castle", "howl", "park", "jungle", "nest", "arachne", "spider", "deep", "barn", "home", "kuurda", "wasteland", "dragontail", "scarleton", "smold", "garden", "da", "crypt", "museum", "trapper", "dungeon_hub"}, builder); - }).executes((context) -> { - // Handle "variableName" and "variableValue" logic here - String destination = StringArgumentType.getString(context, "destination"); - getConfig().sender.addSendTask("/warp " + destination, 0); - return 1; - }))); - }); //warp test - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + Event<ClientCommandRegistrationCallback> event = ClientCommandRegistrationCallback.EVENT; +// event.register((dispatcher, registryAccess) -> { +// dispatcher.register(ClientCommandManager.literal("warp").then(ClientCommandManager.argument("destination", StringArgumentType.string()).suggests((context, builder) -> { +// // Provide tab-completion options for menu subfolder +// return CommandSource.suggestMatching(new String[]{"desert", "hub", "dhub", "nether", "isle", "wizard", "portal", "mines", "forge", "ch", "crystals", "nucleus", "end", "drag", "void", "castle", "howl", "park", "jungle", "nest", "arachne", "spider", "deep", "barn", "home", "kuurda", "wasteland", "dragontail", "scarleton", "smold", "garden", "da", "crypt", "museum", "trapper", "dungeon_hub"}, builder); +// }).executes((context) -> { +// // Handle "variableName" and "variableValue" logic here +// String destination = StringArgumentType.getString(context, "destination"); +// getConfig().sender.addSendTask("/warp " + destination, 0); +// return 1; +// }))); +// }); //warp test + event.register((dispatcher, registryAccess) -> { dispatcher.register(ClientCommandManager.literal("creport") .then(ClientCommandManager.argument("Player_Name", StringArgumentType.string()) .executes((context) -> { @@ -33,145 +45,128 @@ public class CommandsOLD { return 1; }))); });//creport helper → no double report during same launch - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("hp").then(ClientCommandManager.literal("accept").then(ClientCommandManager.argument("player", StringArgumentType.string()).executes((context) -> { - String player = StringArgumentType.getString(context, "player"); - getConfig().sender.addImmediateSendTask("/party accept " + player); - return 1; - }))).then(ClientCommandManager.literal("chat").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party chat"); - return 1; - })).then(ClientCommandManager.literal("demote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { - // Provide tab-completion options for menu subfolder - return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); - }).executes((context) -> { - String player = StringArgumentType.getString(context, "player"); - getConfig().sender.addImmediateSendTask("/party demote " + player); - return 1; - }))).then(ClientCommandManager.literal("disband").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party disband"); - return 1; - })).then(ClientCommandManager.literal("kick").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { - // Provide tab-completion options for menu subfolder - return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); - }).executes((context) -> { - String player = StringArgumentType.getString(context, "player"); - getConfig().sender.addImmediateSendTask("/party kick " + player); - return 1; - }))).then(ClientCommandManager.literal("kickoffline").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party kickoffline"); - return 1; - })).then(ClientCommandManager.literal("leave").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party leave"); - return 1; - })).then(ClientCommandManager.literal("list").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party list"); - return 1; - })).then(ClientCommandManager.literal("mute").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party mute"); - return 1; - })).then(ClientCommandManager.literal("poll").then(ClientCommandManager.argument("question/answer/answer/answer", StringArgumentType.greedyString()).executes((context) -> { - String questionAndAnswers = StringArgumentType.getString(context, "question answer answer (answer)"); - getConfig().sender.addImmediateSendTask("/party poll " + questionAndAnswers); - return 1; - }))).then(ClientCommandManager.literal("private").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party private"); - return 1; - })).then(ClientCommandManager.literal("promote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { - // Provide tab-completion options for menu subfolder - return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); - }).executes((context) -> { - String player = StringArgumentType.getString(context, "player"); - getConfig().sender.addImmediateSendTask("/party promote " + player); - return 1; - }))).then(ClientCommandManager.literal("setting").then(ClientCommandManager.literal("allinvite")).executes((context) -> { - String setting = StringArgumentType.getString(context, "setting"); - getConfig().sender.addImmediateSendTask("/party setting " + setting); - return 1; - }) - - ).then(ClientCommandManager.literal("transfer").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { - // Provide tab-completion options for menu subfolder - return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); - }).executes((context) -> { - String player = StringArgumentType.getString(context, "player"); - getConfig().sender.addImmediateSendTask("/party transfer " + player); - return 1; - }))).then(ClientCommandManager.literal("warp").executes((context) -> { - getConfig().sender.addImmediateSendTask("/party warp"); - return 1; - })).executes(context -> { - getConfig().sender.addImmediateSendTask("/p"); - return 1; - })); - }); //party test - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register( - ClientCommandManager.literal("goblinraid") - .executes((context) -> { - bbserver.sendMessage("?dwevent goblinraid"); - return 1; - }) - ); +// event.register((dispatcher, registryAccess) -> { +// dispatcher.register(ClientCommandManager.literal("hp").then(ClientCommandManager.literal("accept").then(ClientCommandManager.argument("player", StringArgumentType.string()).executes((context) -> { +// String player = StringArgumentType.getString(context, "player"); +// getConfig().sender.addImmediateSendTask("/party accept " + player); +// return 1; +// }))).then(ClientCommandManager.literal("chat").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party chat"); +// return 1; +// })).then(ClientCommandManager.literal("demote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { +// // Provide tab-completion options for menu subfolder +// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); +// }).executes((context) -> { +// String player = StringArgumentType.getString(context, "player"); +// getConfig().sender.addImmediateSendTask("/party demote " + player); +// return 1; +// }))).then(ClientCommandManager.literal("disband").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party disband"); +// return 1; +// })).then(ClientCommandManager.literal("kick").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { +// // Provide tab-completion options for menu subfolder +// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); +// }).executes((context) -> { +// String player = StringArgumentType.getString(context, "player"); +// getConfig().sender.addImmediateSendTask("/party kick " + player); +// return 1; +// }))).then(ClientCommandManager.literal("kickoffline").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party kickoffline"); +// return 1; +// })).then(ClientCommandManager.literal("leave").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party leave"); +// return 1; +// })).then(ClientCommandManager.literal("list").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party list"); +// return 1; +// })).then(ClientCommandManager.literal("mute").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party mute"); +// return 1; +// })).then(ClientCommandManager.literal("poll").then(ClientCommandManager.argument("question/answer/answer/answer", StringArgumentType.greedyString()).executes((context) -> { +// String questionAndAnswers = StringArgumentType.getString(context, "question answer answer (answer)"); +// getConfig().sender.addImmediateSendTask("/party poll " + questionAndAnswers); +// return 1; +// }))).then(ClientCommandManager.literal("private").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party private"); +// return 1; +// })).then(ClientCommandManager.literal("promote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { +// // Provide tab-completion options for menu subfolder +// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); +// }).executes((context) -> { +// String player = StringArgumentType.getString(context, "player"); +// getConfig().sender.addImmediateSendTask("/party promote " + player); +// return 1; +// }))).then(ClientCommandManager.literal("setting").then(ClientCommandManager.literal("allinvite")).executes((context) -> { +// String setting = StringArgumentType.getString(context, "setting"); +// getConfig().sender.addImmediateSendTask("/party setting " + setting); +// return 1; +// }) +// +// ).then(ClientCommandManager.literal("transfer").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { +// // Provide tab-completion options for menu subfolder +// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); +// }).executes((context) -> { +// String player = StringArgumentType.getString(context, "player"); +// getConfig().sender.addImmediateSendTask("/party transfer " + player); +// return 1; +// }))).then(ClientCommandManager.literal("warp").executes((context) -> { +// getConfig().sender.addImmediateSendTask("/party warp"); +// return 1; +// })).executes(context -> { +// getConfig().sender.addImmediateSendTask("/p"); +// return 1; +// })); +// }); //party test + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "goblinraid", MiningEvents.GOBLIN_RAID); });/*goblinraid*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register( - ClientCommandManager.literal("2xpowder") - .executes((context) -> { - bbserver.sendMessage("?dwevent 2xpowder"); - return 1; - }) - ); + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "2xpowder", MiningEvents.DOUBLE_POWDER); });/*2xpowder*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register( - ClientCommandManager.literal("bettertogether") - .executes((context) -> { - bbserver.sendMessage("?dwevent bettertogether"); - return 1; - }) - ); + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "bettertogether", MiningEvents.BETTER_TOGETHER); });/*b2g*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register( - ClientCommandManager.literal("raffle") - .executes((context) -> { - bbserver.sendMessage("?dwevent raffle"); - return 1; - }) - ); + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "raffle", MiningEvents.RAFFLE); });/*raffle*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register( - ClientCommandManager.literal("gonewiththewind") - .executes((context) -> { - bbserver.sendMessage("?dwevent gonewiththewind"); - return 1; - }) - ); + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "gonewiththewind", MiningEvents.GONE_WITH_THE_WIND); + });/*gonewiththewind*/ + event.register((dispatcher, registryAccess) -> { + miningEvent(dispatcher, "mithrilgourmand", MiningEvents.MITHRIL_GOURMAND); });/*gonewiththewind*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register(ClientCommandManager.literal("chchest") .then(ClientCommandManager.argument("Item", StringArgumentType.string()) .suggests((context, builder) -> { - return CommandSource.suggestMatching(new String[]{"PrehistoricEgg", "Pickonimbus2000", "ElectronTransmitter", "FTX3070", "RobotronReflector", "ControlSwitch", "SyntheticHeart", "SuperliteMotor", "BlueGoblinEgg", "YellowGoblinEgg", "FlawlessAmberGemstone", "FlawlessJadeGemstone", "FlawlessSapphireGemstone", "FlawlessRubyGemstone", "FlawlessAmethystGemstone", "JungleHeart", "FlawlessTopazGemstone", "FlawlessJasperGemstone"}, builder); + String[] items = new String[]{"PrehistoricEgg", "Pickonimbus2000", "ElectronTransmitter", "FTX3070", "RobotronReflector", "ControlSwitch", "SyntheticHeart", "SuperliteMotor", "BlueGoblinEgg", "YellowGoblinEgg", "FlawlessAmberGemstone", "FlawlessJadeGemstone", "FlawlessSapphireGemstone", "FlawlessRubyGemstone", "FlawlessAmethystGemstone", "JungleHeart", "FlawlessTopazGemstone", "FlawlessJasperGemstone"}; + String input = builder.getRemaining().toLowerCase(); + int lastSemicolonIndex = input.lastIndexOf(";"); + List<String> suggestions = new ArrayList<>(); + if (lastSemicolonIndex >= 0) { + String inputBeforeSemicolon = input.substring(0, lastSemicolonIndex + 1); // Include the semicolon + + for (String item : items) { + suggestions.add(inputBeforeSemicolon + item); + } + } + return CommandSource.suggestMatching(suggestions, builder); }) .then(ClientCommandManager.argument("X", IntegerArgumentType.integer()) .then(ClientCommandManager.argument("Y", IntegerArgumentType.integer()) .then(ClientCommandManager.argument("Z", IntegerArgumentType.integer()) - .then(ClientCommandManager.argument("ContactWay", StringArgumentType.greedyString()) + .then(ClientCommandManager.argument("ContactWay", StringArgumentType.string()) .suggests(((context, builder) -> { return CommandSource.suggestMatching(new String[]{"/msg " + getConfig().getUsername() + " bb:party me", "/p join " + config.getUsername()}, builder); })) .executes((context) -> { - String destination = StringArgumentType.getString(context, "Item"); + String item = StringArgumentType.getString(context, "Item"); int x = IntegerArgumentType.getInteger(context, "X"); int y = IntegerArgumentType.getInteger(context, "Y"); int z = IntegerArgumentType.getInteger(context, "Z"); String contactWay = StringArgumentType.getString(context, "ContactWay"); - String combinedString = "?chchest " + destination + " " + x + " " + y + " " + z + " " + contactWay; - bbserver.sendMessage(combinedString); + bbserver.sendPacket(new ChChestPackage("", ChChestItems.getItem(item.split(";")), x + "" + y + "" + z, contactWay, "")); return 1; } ) @@ -182,7 +177,7 @@ public class CommandsOLD { ) ); }); /*chchest*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bbserver") .then(ClientCommandManager.argument("Message", StringArgumentType.greedyString()) @@ -190,7 +185,8 @@ public class CommandsOLD { String message = StringArgumentType.getString(context, "Message"); if (message.equals("bb:reconnect")) { BBsentials.connectToBBserver(); - } else { + } + else { BBsentials.bbserver.sendMessage(message); } return 1; @@ -198,33 +194,33 @@ public class CommandsOLD { ) ); });/*BBserver*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bc") .then(ClientCommandManager.argument("Message to Bingo Chat", StringArgumentType.greedyString()) .executes((context) -> { String message = StringArgumentType.getString(context, "Message to Bingo Chat"); - sendCommand("?bingochat " + message); + sendPacket(new BingoChatMessagePacket("", "", message, 0)); return 1; }) ) ); });/*BincoChatShort*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bingochat") .then(ClientCommandManager.argument("Message to Bingo Chat", StringArgumentType.greedyString()) .executes((context) -> { String message = StringArgumentType.getString(context, "Message to Bingo Chat"); - sendCommand("?bingochat " + message); + sendPacket(new BingoChatMessagePacket("", "", message, 0)); return 1; }) ) ); });/*BingoChatLong*/ if (getConfig().bbsentialsRoles != null) { - if (getConfig().bbsentialsRoles.contains("mod")) { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + if (getConfig().hasBBRoles("mod")) { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bannounce") .then(ClientCommandManager.argument("message", StringArgumentType.greedyString()) @@ -236,7 +232,7 @@ public class CommandsOLD { ) ); });/*bAnnounce*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bmute") .then(ClientCommandManager.argument("message", StringArgumentType.greedyString()) @@ -248,7 +244,7 @@ public class CommandsOLD { ) ); });/*bmute*/ - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("bban") .then(ClientCommandManager.argument("message", StringArgumentType.greedyString()) @@ -261,47 +257,84 @@ public class CommandsOLD { ); });/*bmute*/ } - if (getConfig().bbsentialsRoles.contains("splasher")) { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { + if (getConfig().hasBBRoles("splasher")) { + event.register((dispatcher, registryAccess) -> { dispatcher.register( ClientCommandManager.literal("splashAnnounce") .then(ClientCommandManager.argument("Hub", IntegerArgumentType.integer(1, 28)) .then(ClientCommandManager.argument("location", StringArgumentType.string()) .suggests((context, builder) -> { - return CommandSource.suggestMatching(new String[]{"kat","bea","guild-house"}, builder); + return CommandSource.suggestMatching(new String[]{"kat", "bea", "guild-house"}, builder); }) - .then(ClientCommandManager.argument("extramessage", StringArgumentType.greedyString()) + .then(ClientCommandManager.argument("lasswaste", StringArgumentType.string()) + .suggests((context, builder) -> { + return CommandSource.suggestMatching(new String[]{"true", "false"}, builder); + }) + .then(ClientCommandManager.argument("extramessage", StringArgumentType.greedyString()) + .executes((context) -> { + int hub = IntegerArgumentType.getInteger(context, "Hub"); + String extramessage = StringArgumentType.getString(context, "extramessage"); + String location = StringArgumentType.getString(context, "location"); + boolean lessWaste = Boolean.parseBoolean(StringArgumentType.getString(context, "lasswaste")); + sendPacket(new SplashNotifyPacket(hub, config.getUsername(), location, Islands.HUB, extramessage, lessWaste)); + return 1; + }) + ) .executes((context) -> { - int hub_Number = IntegerArgumentType.getInteger(context, "Hub"); - String extramessage = StringArgumentType.getString(context, "extramessage"); - String location = StringArgumentType.getString(context, "location"); - sendCommand("?splash " + hub_Number + " " + location+" "+extramessage); + int hub = IntegerArgumentType.getInteger(context, "Hub"); + String location = "bea"; + boolean lessWaste = Boolean.parseBoolean(StringArgumentType.getString(context, "lasswaste")); + sendPacket(new SplashNotifyPacket(hub, config.getUsername(), location, Islands.HUB, "", lessWaste)); return 1; }) - ) - .executes((context) -> { - int hub_Number = IntegerArgumentType.getInteger(context, "Hub"); - String message = ""; - String location = "bea"; - sendCommand("?splash " + hub_Number + " "+location+" " + message); - return 1; - }) - ) + )) .executes((context) -> { - int hub_Number = IntegerArgumentType.getInteger(context, "Hub"); - String message = ""; + int hub = IntegerArgumentType.getInteger(context, "Hub"); String location = StringArgumentType.getString(context, "location"); - sendCommand("?splash " + hub_Number + " "+location+" " + message); + sendPacket(new SplashNotifyPacket(hub, config.getUsername(), location, Islands.HUB, "", true)); return 1; }) + ) ); });/*SplashAnnounce*/ - } else { + } + else { } } } - public void sendCommand(String message){ + + private static void simpleCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, String commandName, String[] parameters) { + dispatcher.register( + ClientCommandManager.literal(commandName) + .executes((context) -> { + BBsentials.bbserver.sendPacket(new InternalCommandPacket(commandName, parameters)); + return 1; + }) + ); + } + + private static void miningEvent(CommandDispatcher<FabricClientCommandSource> dispatcher, String commandName, MiningEvents event) { + dispatcher.register( + ClientCommandManager.literal(commandName) + .executes((context) -> { + try { + BBsentials.bbserver.sendPacket(new MiningEventPacket(event,//TODO get the island + config.getUsername(), Islands.HUB)); + } catch (Exception e) { + Chat.sendPrivateMessageToSelf("§c" + e.getMessage()); + } + return 1; + }) + ); + } + + + public void sendCommand(String message) { BBsentials.bbserver.sendCommand(message); } + + public <E extends AbstractPacket> void sendPacket(E packet) { + BBsentials.bbserver.sendPacket(packet); + } }
\ No newline at end of file diff --git a/src/main/java/de/hype/bbsentials/client/Config.java b/src/main/java/de/hype/bbsentials/client/Config.java index 35ba61f..131b067 100644 --- a/src/main/java/de/hype/bbsentials/client/Config.java +++ b/src/main/java/de/hype/bbsentials/client/Config.java @@ -15,6 +15,7 @@ import java.util.ArrayList; public class Config implements Serializable { // Helper class for sending chat messages + public int version = 1; public transient final Sender sender = new Sender(); public transient boolean highlightitem = false; @@ -28,13 +29,14 @@ public class Config implements Serializable { private transient boolean isLeader; private transient String alreadyReported = ""; private String bbServerURL = "static.204.177.34.188.clients.your-server.de"; - public String bbsentialsRoles = ""; + public String[] bbsentialsRoles = {""}; public static ArrayList<String> partyMembers = new ArrayList<>(); // Set via load / default private String bbsentialsCommandPrefix = "."; private String apiKey = ""; private boolean leaveDungeonAutomatically; + public boolean showBingoChat = true; private boolean allowBBinviteMe = true; private boolean leaveKuudraAutomatically; private boolean devMode = false; @@ -42,6 +44,8 @@ public class Config implements Serializable { private boolean acceptReparty; private String nickname; private String getNotifForParty; + private final int apiVersion = 1; + public transient ToDisplayConfig toDisplayConfig = ToDisplayConfig.loadFromFile(); // Set default attribute values private void setDefaults() { @@ -146,16 +150,22 @@ public class Config implements Serializable { } catch (IOException e) { e.printStackTrace(); settings = new Config(); // Use default values if loading fails + settings.save(); + }catch (IllegalStateException e){ + System.out.println("Error loading config. Resetting it."); + settings = new Config(); + settings.save(); } } else { settings = new Config(); // Use default values if the file doesn't exist settings.username = MinecraftClient.getInstance().player.getName().getString(); } - if (!settings.bbsentialsRoles.contains("dev")) { + if (!settings.hasBBRoles("dev")) { settings.detailedDevMode = false; settings.devMode = false; } + settings.save(); return settings; } @@ -244,7 +254,7 @@ public class Config implements Serializable { return isBefore || isInRange; } - public boolean overrideBingoTime() { + public boolean overrideBingoTime() { return overrideBingoTime; } @@ -263,4 +273,21 @@ public class Config implements Serializable { public void setLastChatPromptAnswer(String lastChatPromptAnswer) { this.lastChatPromptAnswer = lastChatPromptAnswer; } + + public int getVersion() { + return version; + } + + public boolean hasBBRoles(String roleName) { + for (String role : bbsentialsRoles) { + if (role.equalsIgnoreCase(roleName)) { + return true; + } + } + return false; + } + + public int getApiVersion() { + return apiVersion; + } } diff --git a/src/main/java/de/hype/bbsentials/client/CustomGson.java b/src/main/java/de/hype/bbsentials/client/CustomGson.java new file mode 100644 index 0000000..e9a41da --- /dev/null +++ b/src/main/java/de/hype/bbsentials/client/CustomGson.java @@ -0,0 +1,28 @@ +package de.hype.bbsentials.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class CustomGson { + public static Gson create() { + return new GsonBuilder() +// .registerTypeHierarchyAdapter(BBDisplayNameProvider.class, new BBDisplayNameProviderSerializer()) + .create(); + + } + +// private static class BBDisplayNameProviderSerializer implements JsonSerializer<BBDisplayNameProvider>, JsonDeserializer<BBDisplayNameProvider> { +// @Override +// public JsonElement serialize(BBDisplayNameProvider src, Type typeOfSrc, JsonSerializationContext context) { +// return new JsonPrimitive(src.serialize()); // Serialize using the provided method +// } +// +// @Override +// public BBDisplayNameProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { +// String serializedValue = json.getAsString(); +// +// // Deserialize using the provided method (you need to implement this) +// return BBDisplayNameProvider.deserialize(serializedValue); +// } +// } +} diff --git a/src/main/java/de/hype/bbsentials/client/DebugThread.java b/src/main/java/de/hype/bbsentials/client/DebugThread.java new file mode 100644 index 0000000..b10cad4 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/client/DebugThread.java @@ -0,0 +1,13 @@ +package de.hype.bbsentials.client; + +public class DebugThread implements Runnable { + @Override + public void run() { + loop(); + //place a breakpoint for only this thread here. + } + + public void loop() { + + } +} diff --git a/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java b/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java new file mode 100644 index 0000000..2c513d0 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java @@ -0,0 +1,97 @@ +package de.hype.bbsentials.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; + +public class ToDisplayConfig { + private boolean disableAll = true; + private boolean prehistoricEgg = true; + private boolean pickonimbus2000 = true; + private boolean controlSwitch = true; + private boolean electronTransmitter = true; + private boolean ftx3070 = true; + private boolean robotronReflector = true; + private boolean superliteMotor = true; + private boolean syntheticHeart = true; + private boolean flawlessGemstone = true; + private boolean allRoboPartCustomChChestItem = true; + private boolean allChChestItem = true; + private boolean dwBetterTogether = true; + private boolean dwDoublePowder = true; + private boolean dwGoneWithTheWind = true; + private boolean dwGoblinRaid = true; + private boolean dwMithrilGourmand = true; + private boolean dwRaffle = true; + private boolean dwEvents = true; + private boolean chBetterTogether = true; + private boolean chDoublePowder = true; + private boolean chGoneWithTheWind = true; + private boolean chEvents = true; + private boolean allBetterTogether = true; + private boolean allDoublePowder = true; + private boolean allGoneWithTheWind = true; + private boolean allEvents = true; + + // Serialize the object to JSON and save to file + public void saveToFile() { + File configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "BBsentials_display_Config.json"); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + try (FileWriter writer = new FileWriter(configFile)) { + gson.toJson(this, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Deserialize the object from JSON file + public static ToDisplayConfig loadFromFile() { + File configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "BBsentials_display_Config.json"); + Gson gson = new Gson(); + + try (FileReader reader = new FileReader(configFile)) { + return gson.fromJson(reader, ToDisplayConfig.class); + } catch (IOException e) { + e.printStackTrace(); + } + + // If file doesn't exist or there's an error, return a new instance + return new ToDisplayConfig(); + } + + public void setValueAndSave(String propertyName, Object newValue) { + String lowerCasePropertyName = propertyName.toLowerCase(); + + try { + Field field = getClass().getDeclaredField(lowerCasePropertyName); + field.setAccessible(true); + + field.set(this, newValue); + saveToFile(); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + // Method to get a value based on property name + public boolean getValue(String propertyName) { + if (disableAll) return false; + String lowerCasePropertyName = propertyName.toLowerCase(); + try { + Field field = getClass().getDeclaredField(lowerCasePropertyName); + field.setAccessible(true); + return field.getBoolean(this); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + + return false; + } +} |