|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2026 Wurst-Imperium and contributors. |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the GNU General Public |
| 5 | + * License, version 3. If a copy of the GPL was not distributed with this |
| 6 | + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt |
| 7 | + */ |
| 8 | +package net.wurstclient.commands; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | +import net.minecraft.core.BlockPos; |
| 12 | +import net.wurstclient.DontBlock; |
| 13 | +import net.wurstclient.command.CmdError; |
| 14 | +import net.wurstclient.command.CmdException; |
| 15 | +import net.wurstclient.command.CmdSyntaxError; |
| 16 | +import net.wurstclient.command.Command; |
| 17 | +import net.wurstclient.hacks.NoGoZoneHack; |
| 18 | +import net.wurstclient.hacks.NoGoZoneHack.NoGoZone; |
| 19 | +import net.wurstclient.util.ChatUtils; |
| 20 | + |
| 21 | +@DontBlock |
| 22 | +public final class NoGoZoneCmd extends Command |
| 23 | +{ |
| 24 | + public NoGoZoneCmd() |
| 25 | + { |
| 26 | + super("nogozone", |
| 27 | + "Manages NoGoZones - areas you cannot re-enter after leaving.\n" |
| 28 | + + "Use when NoGoZone hack is enabled.", |
| 29 | + ".nogozone add", ".nogozone list", ".nogozone remove <id>", |
| 30 | + ".nogozone clear"); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public void call(String[] args) throws CmdException |
| 35 | + { |
| 36 | + if(args.length < 1) |
| 37 | + throw new CmdSyntaxError(); |
| 38 | + |
| 39 | + switch(args[0].toLowerCase()) |
| 40 | + { |
| 41 | + case "add": |
| 42 | + addZone(); |
| 43 | + break; |
| 44 | + |
| 45 | + case "list": |
| 46 | + listZones(); |
| 47 | + break; |
| 48 | + |
| 49 | + case "remove": |
| 50 | + if(args.length < 2) |
| 51 | + throw new CmdSyntaxError("No zone ID specified."); |
| 52 | + removeZone(args[1]); |
| 53 | + break; |
| 54 | + |
| 55 | + case "clear": |
| 56 | + clearZones(); |
| 57 | + break; |
| 58 | + |
| 59 | + default: |
| 60 | + throw new CmdSyntaxError("Unknown subcommand: " + args[0]); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private void addZone() |
| 65 | + { |
| 66 | + if(MC.player == null) |
| 67 | + { |
| 68 | + ChatUtils.error("You must be in a world to add a NoGoZone."); |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + // Read the effective render distance (capped by server view distance) |
| 73 | + int renderDistance = MC.options.getEffectiveRenderDistance(); |
| 74 | + // Add +1 as specified |
| 75 | + int chunkRadius = renderDistance + 1; |
| 76 | + |
| 77 | + BlockPos playerPos = MC.player.blockPosition(); |
| 78 | + int id = NoGoZoneHack.addZone(playerPos, chunkRadius); |
| 79 | + WURST.getHax().noGoZoneHack.setEnabled(true); |
| 80 | + |
| 81 | + int blockRadius = chunkRadius * 16; |
| 82 | + ChatUtils.message("NoGoZone #" + id + " created at " + playerPos.getX() |
| 83 | + + " " + playerPos.getY() + " " + playerPos.getZ() + " with radius " |
| 84 | + + blockRadius + " blocks (" + chunkRadius + " chunks)."); |
| 85 | + } |
| 86 | + |
| 87 | + private void listZones() |
| 88 | + { |
| 89 | + List<NoGoZone> zones = NoGoZoneHack.getZones(); |
| 90 | + |
| 91 | + if(zones.isEmpty()) |
| 92 | + { |
| 93 | + ChatUtils.message("No NoGoZones active."); |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + ChatUtils.message("=== NoGoZones (" + zones.size() + " total) ==="); |
| 98 | + for(NoGoZone zone : zones) |
| 99 | + { |
| 100 | + ChatUtils.message(" #" + zone.id + " | XYZ: " + zone.center.getX() |
| 101 | + + " " + zone.center.getY() + " " + zone.center.getZ() |
| 102 | + + " | Radius: " + zone.getBlockRadius() + " blocks (" |
| 103 | + + zone.chunkRadius + " chunks)"); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + private void removeZone(String idStr) throws CmdError |
| 108 | + { |
| 109 | + int id; |
| 110 | + try |
| 111 | + { |
| 112 | + id = Integer.parseInt(idStr); |
| 113 | + }catch(NumberFormatException e) |
| 114 | + { |
| 115 | + throw new CmdError("Invalid zone ID: " + idStr); |
| 116 | + } |
| 117 | + |
| 118 | + boolean removed = NoGoZoneHack.removeZone(id); |
| 119 | + if(removed) |
| 120 | + ChatUtils.message("NoGoZone #" + id + " removed."); |
| 121 | + else |
| 122 | + throw new CmdError("NoGoZone #" + id + " not found."); |
| 123 | + } |
| 124 | + |
| 125 | + private void clearZones() |
| 126 | + { |
| 127 | + int count = NoGoZoneHack.getZones().size(); |
| 128 | + NoGoZoneHack.clearAllZones(); |
| 129 | + ChatUtils.message("Cleared " + count + " NoGoZone(s)."); |
| 130 | + } |
| 131 | +} |
0 commit comments