From e293bde96f5d69d7818e33ed3bec402e763e11bb Mon Sep 17 00:00:00 2001 From: Josh Shippam Date: Mon, 20 Mar 2023 23:35:25 +0000 Subject: [PATCH] Misc Changes (#633) * Fix Weight Calculation For Add/Remove Item In ItemAssistant * Re-Add Simple Stuck Command That Logs To Discord To Prevent Abuse * Update Discord Log Chanel Var * Fix int/interface Command * Add World ID Check To DiscordBot Link Command * Fix Java Warnings in DiscordBot Link Command --- .../main/java/com/rs2/game/items/ItemAssistant.java | 8 ++++---- .../src/main/java/com/rs2/game/items/Weight.java | 8 ++++---- .../main/java/com/rs2/game/shops/ShopAssistant.java | 3 --- .../java/com/rs2/integrations/discord/JavaCord.java | 1 + .../com/rs2/integrations/discord/commands/Link.java | 10 +++++++--- .../main/java/com/rs2/net/packets/impl/Commands.java | 9 ++++++++- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/2006Scape Server/src/main/java/com/rs2/game/items/ItemAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/items/ItemAssistant.java index 2fdc4dfd..eca6d634 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/items/ItemAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/items/ItemAssistant.java @@ -515,7 +515,7 @@ public class ItemAssistant { player.flushOutStream(); } i = 30; - Weight.calcWeight(player, item, "additem"); + Weight.updateWeight(player); return true; } } @@ -533,7 +533,7 @@ public class ItemAssistant { } resetItems(3214); i = 30; - Weight.calcWeight(player, item, "additem"); + Weight.updateWeight(player); return true; } } @@ -2338,7 +2338,7 @@ public class ItemAssistant { } } resetItems(3214); - Weight.calcWeight(player, id, "deleteitem"); + Weight.updateWeight(player); } public void deleteItem(int id, int slot, int amount) { @@ -2353,7 +2353,7 @@ public class ItemAssistant { player.playerItems[slot] = 0; } resetItems(3214); - Weight.calcWeight(player, id, "deleteitem"); + Weight.updateWeight(player); } } diff --git a/2006Scape Server/src/main/java/com/rs2/game/items/Weight.java b/2006Scape Server/src/main/java/com/rs2/game/items/Weight.java index e9564f13..ea1f6399 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/items/Weight.java +++ b/2006Scape Server/src/main/java/com/rs2/game/items/Weight.java @@ -13,11 +13,11 @@ public class Weight { * @param c * @param item * @param action - * - deleteitem, additem, equip, unequip. + * - deleteItem, addItem. */ public static void calcWeight(Player c, int item, String action) { double weight = ItemDefinitions.getWeight(item); - if (action.equalsIgnoreCase("deleteitem")) { + if (action.equalsIgnoreCase("deleteItem")) { if (weight > 99.20) { c.weight -= weight / 100; if (c.weight < 0) { @@ -31,7 +31,7 @@ public class Weight { c.weight = 0.0; } c.getPacketSender().writeWeight((int) c.weight); - } else if (action.equalsIgnoreCase("additem")) { + } else if (action.equalsIgnoreCase("addItem")) { if (weight > 99.20) { c.weight += weight / 100; c.getPacketSender().writeWeight((int) c.weight); @@ -56,7 +56,7 @@ public class Weight { calcWeight(player, playerItem, "addItem"); } } - // Equiped items + // Equipped items for (int element : player.playerEquipment) { if (element > -1) {// equipment if (element == 88) { diff --git a/2006Scape Server/src/main/java/com/rs2/game/shops/ShopAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/shops/ShopAssistant.java index 37e124e5..a6a27b9b 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/shops/ShopAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/shops/ShopAssistant.java @@ -1,7 +1,6 @@ package com.rs2.game.shops; import com.rs2.Constants; -import com.rs2.game.items.Weight; import org.apollo.cache.def.ItemDefinition; import com.rs2.game.bots.BotHandler; @@ -451,7 +450,6 @@ public class ShopAssistant { // Add item to the shop addShopItem(unNotedItemID, amount); player.getItemAssistant().resetItems(3823); - Weight.updateWeight(player); resetShop(player.shopId); updatePlayerShop(); return true; @@ -613,7 +611,6 @@ public class ShopAssistant { GameLogger.writeLog(player.playerName, "shopbuying", player.playerName + " bought " + amount + " " + itemName + " for " + totalValue + " " + currencyName + " from store " + shopID + "."); } player.getItemAssistant().resetItems(3823); - Weight.updateWeight(player); resetShop(player.shopId); updatePlayerShop(); return true; //return TRUE / FALSE Update = shop&Inventory / Doesnt Update diff --git a/2006Scape Server/src/main/java/com/rs2/integrations/discord/JavaCord.java b/2006Scape Server/src/main/java/com/rs2/integrations/discord/JavaCord.java index 0ba5fc88..7e93f63b 100644 --- a/2006Scape Server/src/main/java/com/rs2/integrations/discord/JavaCord.java +++ b/2006Scape Server/src/main/java/com/rs2/integrations/discord/JavaCord.java @@ -21,6 +21,7 @@ public class JavaCord { public static String commandPrefix = "::w" + Constants.WORLD; public static String token; public static DiscordApi api = null; + public static String logChannelId = "1083146780507656294"; public static void init() throws IOException { if (token != null && !token.equals("")) { //If the token was loaded by loadSettings: diff --git a/2006Scape Server/src/main/java/com/rs2/integrations/discord/commands/Link.java b/2006Scape Server/src/main/java/com/rs2/integrations/discord/commands/Link.java index 273b689b..ff8534a3 100644 --- a/2006Scape Server/src/main/java/com/rs2/integrations/discord/commands/Link.java +++ b/2006Scape Server/src/main/java/com/rs2/integrations/discord/commands/Link.java @@ -1,7 +1,7 @@ package com.rs2.integrations.discord.commands; +import com.rs2.Constants; import org.javacord.api.entity.message.Message; -import org.javacord.api.entity.user.User; import org.javacord.api.event.message.MessageCreateEvent; import org.javacord.api.listener.message.MessageCreateListener; @@ -10,8 +10,12 @@ public class Link implements MessageCreateListener { public void onMessageCreate(MessageCreateEvent event) { Message message = event.getMessage(); if (message.getContent().equalsIgnoreCase("::link")) { - event.getChannel().sendMessage(message.getAuthor().asUser().get().getMentionTag() + ", Please check your DM's to continue."); - message.getAuthor().asUser().get().sendMessage("Please copy/paste the following in-game to link your Discord account: \n ```::link " + message.getAuthor().asUser().get().getIdAsString() + "```"); + if (Constants.WORLD == 1) { + if (message.getAuthor().asUser().isPresent()) { + event.getChannel().sendMessage(message.getAuthor().asUser().get().getMentionTag() + ", Please check your DM's to continue."); + message.getAuthor().asUser().get().sendMessage("Please copy/paste the following in-game to link your Discord account: \n ```::link " + message.getAuthor().asUser().get().getIdAsString() + "```"); + } + } } } } \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index 95223b84..72ff7975 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -11,6 +11,7 @@ import com.rs2.game.bots.BotHandler; import com.rs2.game.npcs.NpcHandler; import com.rs2.game.players.*; import com.rs2.game.players.antimacro.AntiSpam; +import com.rs2.integrations.discord.JavaCord; import com.rs2.net.Packet; import com.rs2.net.packets.PacketType; import com.rs2.util.Misc; @@ -45,6 +46,12 @@ public class Commands implements PacketType { public static void playerCommands(Player player, String playerCommand, String[] arguments) { switch (playerCommand.toLowerCase()) { + case "stuck": + if(JavaCord.token != null) { + if (JavaCord.api.getTextChannelById(JavaCord.logChannelId).isPresent()) + JavaCord.api.getTextChannelById(JavaCord.logChannelId).get().sendMessage(player.playerName + " used ::stuck at X/Y: " + player.absX + "/" + player.absY); + } + player.getPlayerAssistant().spellTeleport(Constants.RESPAWN_X, Constants.RESPAWN_Y, 0); case "link": player.setDiscordCode(arguments[0]); player.getPacketSender().sendMessage("Your Account has now been linked with Discord User ID:"); @@ -619,7 +626,7 @@ public class Commands implements PacketType { int interface2 = Integer.parseInt(arguments[1]); player.getPacketSender().sendFrame248(interface1, interface2); return; - } else if (arguments.length == 2) { + } else if (arguments.length == 3) { int interface1 = Integer.parseInt(arguments[0]); int interface2 = Integer.parseInt(arguments[1]); int interface3 = Integer.parseInt(arguments[2]);