From 4262f3bb47fbb78f5d33cac31660bb15bff20e83 Mon Sep 17 00:00:00 2001 From: SaegusaMayumi1234 <69360824+SaegusaMayumi1234@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:45:30 +0700 Subject: [PATCH 1/5] Adding new method to prevent coop-add --- CoopProtect/configfile.js | 36 +++++++------- CoopProtect/index.js | 100 ++++++++++++++++++++++++++------------ CoopProtect/metadata.json | 14 +++--- 3 files changed, 94 insertions(+), 56 deletions(-) diff --git a/CoopProtect/configfile.js b/CoopProtect/configfile.js index 4c34a94..d0ed0e1 100644 --- a/CoopProtect/configfile.js +++ b/CoopProtect/configfile.js @@ -1,19 +1,19 @@ -import { @Vigilant, @SwitchProperty} from 'Vigilance'; - -@Vigilant("CoopProtect") -class Settings { - - @SwitchProperty({ - name: "Module Toggle", - description: "Should the module protect you", - category: "Module Settings", - }) - toggle = true - - constructor() { - this.initialize(this); - this.setCategoryDescription("Module Settings", "CoopProtect by MisterCheezeCake") - } -} - +import { @Vigilant, @SwitchProperty} from 'Vigilance'; + +@Vigilant("CoopProtect") +class Settings { + + @SwitchProperty({ + name: "Module Toggle", + description: "Should the module protect you", + category: "Module Settings", + }) + toggle = true + + constructor() { + this.initialize(this); + this.setCategoryDescription("Module Settings", "CoopProtect by MisterCheezeCake and IcarusPhantom") + } +} + export default new Settings; \ No newline at end of file diff --git a/CoopProtect/index.js b/CoopProtect/index.js index 80cf557..ecc671a 100644 --- a/CoopProtect/index.js +++ b/CoopProtect/index.js @@ -1,31 +1,69 @@ -/// -/// -import Settings from "./configfile"; -import {Changelog} from '../ChangelogApi' -const cl = new Changelog('CoopProtect', '&e1.1.0', '&aOverhauled the module adding Vigilance and changing the internals completly') -cl.writeChangelog() -register("command", (arg1) => { - if (arg1 === 'settings' || arg1 === 'config' || arg1 === undefined) { - Settings.openGUI(); - } else if (arg1 === 'on' || arg1 === 'enable') { - Settings.toggle = true; - ChatLib.chat('&aCoopProtect enabled') - } else if (arg1 === 'off' || arg1 === 'disable') { - Settings.toggle = false; - ChatLib.chat('&cCoopProtect disabled') - } else if (arg1 === 'toggle') { - if (Settings.toggle) { - ChatLib.chat('&cCoopProtect disabled') - } else { - ChatLib.chat('&aCoopProtect enabled') - } - Settings.toggle = !Settings.toggle - } -}).setTabCompletions(["settings", "toggle", "on", "off"]).setName('coopprotect') -register("MessageSent", (message, event) => { - if (!Settings.toggle) return; - if (message.toLowerCase().includes('coopadd')) { - ChatLib.chat('&cCoopProtect protected you from this action'); - cancel(event); - } -}) \ No newline at end of file +/// +/// +import Settings from "./configfile"; + +import Changelog from "../ChangelogLib"; + +const cl = new Changelog("CoopProtect", "1.3.0", "Updated module to not allowing clicking coop-add in profile viewer") +cl.writeChangelog({ + changelog: "&b", + name: "&e", + version: "&e" +}) + +register("command", arg1 => { + if (arg1 === 'settings' || arg1 === 'config' || arg1 === undefined) { + Settings.openGUI(); + } else if (arg1 === 'on' || arg1 === 'enable') { + Settings.toggle = true; + ChatLib.chat('&aCoopProtect enabled') + } else if (arg1 === 'off' || arg1 === 'disable') { + Settings.toggle = false; + ChatLib.chat('&cCoopProtect disabled') + } else if (arg1 === 'toggle') { + if (Settings.toggle) { + ChatLib.chat('&cCoopProtect disabled') + } else { + ChatLib.chat('&aCoopProtect enabled') + } + Settings.toggle = !Settings.toggle + } +}).setTabCompletions(["settings", "toggle", "on", "off"]).setName('coopprotect') + +register("MessageSent", (message, event) => { + if (!Settings.toggle) return; + if (message.toLowerCase().includes('coopadd')) { + ChatLib.chat('&cCoopProtect protected you from this action'); + cancel(event); + } +}) + +//IcarusPhantom was here :D +register("guiMouseClick", (x, y, button, gui, event) => { + if (!Settings.toggle) return; + if (Player.getPlayer() === null || Player.getContainer().getClassName() !== 'ContainerChest') return; + const items = Player.getContainer().getItems(); + if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number + cancel(event); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + } +}) + +register('guiKey', (char, keyCode, gui, event) => { + if (!Settings.toggle) return; + if (Player.getPlayer() === null || Player.getContainer().getClassName() !== 'ContainerChest') return; + const items = Player.getContainer().getItems(); + if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number + if (keyCode === Client.getMinecraft().field_71474_y.field_74316_C.func_151463_i()) { // Getting drop keybind + cancel(event); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + } else { + Client.getMinecraft().field_71474_y.field_151456_ac.forEach((keybind) => { // Getting hotkey keybind + if (keybind.func_151463_i() === keyCode) { + cancel(event); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + } + }) + } + } +}) diff --git a/CoopProtect/metadata.json b/CoopProtect/metadata.json index 3a9ecb3..a9dd4ef 100644 --- a/CoopProtect/metadata.json +++ b/CoopProtect/metadata.json @@ -1,8 +1,8 @@ -{ - "name": "CoopProtect", - "author": "MisterCheezeCake", - "description": "Prevents you from running the command /coopadd", - "entry": "index.js", - "version": "1.1.0", - "requires": ["Vigilance", "ChangelogAPI"] +{ + "name": "CoopProtect", + "author": "MisterCheezeCake", + "description": "Prevents you from running the command /coopadd", + "entry": "index.js", + "version": "1.3.0", + "requires": ["Vigilance", "ChangelogLib"] } \ No newline at end of file From 07c26beee78f0b0ab7af459455b2ecfcaf628224 Mon Sep 17 00:00:00 2001 From: SaegusaMayumi1234 <69360824+SaegusaMayumi1234@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:47:33 +0700 Subject: [PATCH 2/5] Update index.js --- CoopProtect/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoopProtect/index.js b/CoopProtect/index.js index ecc671a..c88d6af 100644 --- a/CoopProtect/index.js +++ b/CoopProtect/index.js @@ -4,7 +4,7 @@ import Settings from "./configfile"; import Changelog from "../ChangelogLib"; -const cl = new Changelog("CoopProtect", "1.3.0", "Updated module to not allowing clicking coop-add in profile viewer") +const cl = new Changelog("CoopProtect", "1.3.0", "Updated module to not allowing clicking coop-add in profile viewer from IcarusPhantom") cl.writeChangelog({ changelog: "&b", name: "&e", From 2b908fcecae238e4ad450818951355f11bb8386a Mon Sep 17 00:00:00 2001 From: SaegusaMayumi1234 <69360824+SaegusaMayumi1234@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:55:11 +0700 Subject: [PATCH 3/5] Adding help message for coopprotect command --- CoopProtect/index.js | 8 ++++---- CoopProtect/metadata.json | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CoopProtect/index.js b/CoopProtect/index.js index c88d6af..e721fa1 100644 --- a/CoopProtect/index.js +++ b/CoopProtect/index.js @@ -33,7 +33,7 @@ register("command", arg1 => { register("MessageSent", (message, event) => { if (!Settings.toggle) return; if (message.toLowerCase().includes('coopadd')) { - ChatLib.chat('&cCoopProtect protected you from this action'); + ChatLib.chat('&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this'); cancel(event); } }) @@ -45,7 +45,7 @@ register("guiMouseClick", (x, y, button, gui, event) => { const items = Player.getContainer().getItems(); if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); } }) @@ -56,12 +56,12 @@ register('guiKey', (char, keyCode, gui, event) => { if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number if (keyCode === Client.getMinecraft().field_71474_y.field_74316_C.func_151463_i()) { // Getting drop keybind cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); } else { Client.getMinecraft().field_71474_y.field_151456_ac.forEach((keybind) => { // Getting hotkey keybind if (keybind.func_151463_i() === keyCode) { cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add"); + ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); } }) } diff --git a/CoopProtect/metadata.json b/CoopProtect/metadata.json index a9dd4ef..22ba637 100644 --- a/CoopProtect/metadata.json +++ b/CoopProtect/metadata.json @@ -2,6 +2,7 @@ "name": "CoopProtect", "author": "MisterCheezeCake", "description": "Prevents you from running the command /coopadd", + "helpMessage": "&aThanks for downloading CoopProtect! Created by MisterCheezeCake and IcarusPhantom. do &e/coopprotect &afor toggle the module!", "entry": "index.js", "version": "1.3.0", "requires": ["Vigilance", "ChangelogLib"] From c73134515a84d918d26f76dcb277d4d20d23619b Mon Sep 17 00:00:00 2001 From: SaegusaMayumi1234 <69360824+SaegusaMayumi1234@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:57:07 +0700 Subject: [PATCH 4/5] Matching the message --- CoopProtect/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CoopProtect/index.js b/CoopProtect/index.js index e721fa1..47c79d3 100644 --- a/CoopProtect/index.js +++ b/CoopProtect/index.js @@ -33,7 +33,7 @@ register("command", arg1 => { register("MessageSent", (message, event) => { if (!Settings.toggle) return; if (message.toLowerCase().includes('coopadd')) { - ChatLib.chat('&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this'); + ChatLib.chat('&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this.'); cancel(event); } }) @@ -45,7 +45,7 @@ register("guiMouseClick", (x, y, button, gui, event) => { const items = Player.getContainer().getItems(); if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); + ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); } }) @@ -56,12 +56,12 @@ register('guiKey', (char, keyCode, gui, event) => { if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number if (keyCode === Client.getMinecraft().field_71474_y.field_74316_C.func_151463_i()) { // Getting drop keybind cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); + ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); } else { Client.getMinecraft().field_71474_y.field_151456_ac.forEach((keybind) => { // Getting hotkey keybind if (keybind.func_151463_i() === keyCode) { cancel(event); - ChatLib.chat("&cCoopProtect Prevented you to clicking coop-add! do &e/coopprotect &cto disable this"); + ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); } }) } From abd1a85d62dc93da4a87a3c3d56c294d26d8dcd0 Mon Sep 17 00:00:00 2001 From: SaegusaMayumi1234 <69360824+SaegusaMayumi1234@users.noreply.github.com> Date: Wed, 29 Jun 2022 00:34:11 +0700 Subject: [PATCH 5/5] Added second method getting slot number --- CoopProtect/index.js | 66 +++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/CoopProtect/index.js b/CoopProtect/index.js index 47c79d3..09e3d69 100644 --- a/CoopProtect/index.js +++ b/CoopProtect/index.js @@ -1,51 +1,60 @@ /// /// import Settings from "./configfile"; - import Changelog from "../ChangelogLib"; -const cl = new Changelog("CoopProtect", "1.3.0", "Updated module to not allowing clicking coop-add in profile viewer from IcarusPhantom") +const cl = new Changelog("CoopProtect", "1.3.0", "Updated module to not allowing clicking coop-add in profile viewer from IcarusPhantom"); cl.writeChangelog({ changelog: "&b", name: "&e", version: "&e" -}) +}); register("command", arg1 => { if (arg1 === 'settings' || arg1 === 'config' || arg1 === undefined) { Settings.openGUI(); } else if (arg1 === 'on' || arg1 === 'enable') { Settings.toggle = true; - ChatLib.chat('&aCoopProtect enabled') + ChatLib.chat('&aCoopProtect enabled'); } else if (arg1 === 'off' || arg1 === 'disable') { Settings.toggle = false; - ChatLib.chat('&cCoopProtect disabled') + ChatLib.chat('&cCoopProtect disabled'); } else if (arg1 === 'toggle') { if (Settings.toggle) { - ChatLib.chat('&cCoopProtect disabled') + ChatLib.chat('&cCoopProtect disabled'); } else { - ChatLib.chat('&aCoopProtect enabled') + ChatLib.chat('&aCoopProtect enabled'); } - Settings.toggle = !Settings.toggle + Settings.toggle = !Settings.toggle; } -}).setTabCompletions(["settings", "toggle", "on", "off"]).setName('coopprotect') +}).setTabCompletions(["settings", "toggle", "on", "off"]).setName('coopprotect'); register("MessageSent", (message, event) => { if (!Settings.toggle) return; if (message.toLowerCase().includes('coopadd')) { - ChatLib.chat('&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this.'); cancel(event); + ChatLib.chat('&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this.'); } }) //IcarusPhantom was here :D -register("guiMouseClick", (x, y, button, gui, event) => { + +let mouseCacheX = null; +let mouseCacheY = null; + +register("guiRender", (mouseX, mouseY, gui) => { + mouseCacheX = mouseX; + mouseCacheY = mouseY; +}) + +register("guiMouseClick", (mouseX, mouseY, button, gui, event) => { if (!Settings.toggle) return; if (Player.getPlayer() === null || Player.getContainer().getClassName() !== 'ContainerChest') return; const items = Player.getContainer().getItems(); - if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number + const slot = getSlotUnderMouse(gui, mouseX, mouseY); + if (slot !== null && slot === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') === 'Co-op Request') { cancel(event); - ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); + ChatLib.chat("&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this."); } }) @@ -53,17 +62,42 @@ register('guiKey', (char, keyCode, gui, event) => { if (!Settings.toggle) return; if (Player.getPlayer() === null || Player.getContainer().getClassName() !== 'ContainerChest') return; const items = Player.getContainer().getItems(); - if (gui.getSlotUnderMouse() !== null && gui.getSlotUnderMouse().field_75222_d === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { // field_75222_d: getting slot number + const slot = getSlotUnderMouse(gui, null, null); + if (slot !== null && slot === 25 && ChatLib.removeFormatting(items[25]?.getName() || '') == 'Co-op Request') { if (keyCode === Client.getMinecraft().field_71474_y.field_74316_C.func_151463_i()) { // Getting drop keybind cancel(event); - ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); + ChatLib.chat("&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this."); } else { Client.getMinecraft().field_71474_y.field_151456_ac.forEach((keybind) => { // Getting hotkey keybind if (keybind.func_151463_i() === keyCode) { cancel(event); - ChatLib.chat("&cCoopProtect protected you from clicking coop-add! do &e/coopprotect &cto disable this."); + ChatLib.chat("&cCoopProtect protected you from this action! do &e/coopprotect &cto disable this."); } }) } } }) + +function getSlotUnderMouse(gui, mouseX, mouseY) { + if (mouseX === null) mouseX = mouseCacheX; + if (mouseY === null) mouseY = mouseCacheY; + let slot = null; + try { + if (gui.getSlotUnderMouse() === null) { return null; } + slot = gui.getSlotUnderMouse().field_75222_d; // Getting slot number + } catch (e) { + slot = 0; + while (slot < Player.getContainer().getSize() - 1) { + const x = slot % 9; + const y = Math.floor(slot / 9); + const renderX = Renderer.screen.getWidth() / 2 + ((x - 4) * 18); + const renderY = (Renderer.screen.getHeight() + 10) / 2 + ((y - Player.getContainer().getSize() / 18) * 18); + if (mouseX > renderX - 10 && mouseX < renderX + 10 + && mouseY > renderY - 10 && mouseY < renderY + 10) { + break; + } + slot++; + } + } + return slot; +} \ No newline at end of file