|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2025 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.hacks; |
| 9 | + |
| 10 | +import net.minecraft.client.network.ClientPlayNetworkHandler; |
| 11 | +import net.wurstclient.Category; |
| 12 | +import net.wurstclient.SearchTags; |
| 13 | +import net.wurstclient.events.UpdateListener; |
| 14 | +import net.wurstclient.hack.Hack; |
| 15 | +import net.wurstclient.settings.SliderSetting; |
| 16 | +import net.wurstclient.settings.SliderSetting.ValueDisplay; |
| 17 | +import net.wurstclient.settings.TextFieldSetting; |
| 18 | +import net.wurstclient.util.ChatUtils; |
| 19 | + |
| 20 | +@SearchTags({"safe tp", "safe teleport"}) |
| 21 | +public final class SafeTpHack extends Hack implements UpdateListener |
| 22 | +{ |
| 23 | + private final TextFieldSetting command = new TextFieldSetting("Command", |
| 24 | + "description.wurst.setting.safetp.command", "/t spawn", |
| 25 | + value -> value != null && !value.trim().isEmpty()); |
| 26 | + private final SliderSetting waitTime = new SliderSetting("Wait time", |
| 27 | + "description.wurst.setting.safetp.wait_time", 5.5, 1, 15, 0.25, |
| 28 | + ValueDisplay.DECIMAL.withSuffix("s")); |
| 29 | + |
| 30 | + private int ticksRemaining; |
| 31 | + private boolean weActivatedBlink; |
| 32 | + |
| 33 | + public SafeTpHack() |
| 34 | + { |
| 35 | + super("SafeTP"); |
| 36 | + setCategory(Category.OTHER); |
| 37 | + addSetting(command); |
| 38 | + addSetting(waitTime); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public String getRenderName() |
| 43 | + { |
| 44 | + if(isEnabled()) |
| 45 | + { |
| 46 | + int secondsLeft = |
| 47 | + Math.max((int)Math.ceil(ticksRemaining / 20.0), 0); |
| 48 | + return getName() + " [" + secondsLeft + "s]"; |
| 49 | + } |
| 50 | + |
| 51 | + return super.getRenderName(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void onEnable() |
| 56 | + { |
| 57 | + if(MC.player == null) |
| 58 | + { |
| 59 | + setEnabled(false); |
| 60 | + return; |
| 61 | + } |
| 62 | + |
| 63 | + ClientPlayNetworkHandler netHandler = MC.getNetworkHandler(); |
| 64 | + if(netHandler == null) |
| 65 | + { |
| 66 | + setEnabled(false); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + String value = command.getValue().trim(); |
| 71 | + if(value.isEmpty()) |
| 72 | + { |
| 73 | + ChatUtils.error("SafeTP command cannot be empty."); |
| 74 | + setEnabled(false); |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + BlinkHack blinkHack = WURST.getHax().blinkHack; |
| 79 | + boolean blinkAlreadyEnabled = blinkHack.isEnabled(); |
| 80 | + weActivatedBlink = false; |
| 81 | + |
| 82 | + if(!blinkAlreadyEnabled) |
| 83 | + { |
| 84 | + blinkHack.setEnabled(true); |
| 85 | + if(!blinkHack.isEnabled()) |
| 86 | + { |
| 87 | + ChatUtils.error("SafeTP could not enable Blink."); |
| 88 | + setEnabled(false); |
| 89 | + return; |
| 90 | + } |
| 91 | + |
| 92 | + weActivatedBlink = true; |
| 93 | + } |
| 94 | + |
| 95 | + ticksRemaining = Math.max((int)Math.ceil(waitTime.getValue() * 20), 1); |
| 96 | + |
| 97 | + String commandToSend = |
| 98 | + value.startsWith("/") ? value.substring(1) : value; |
| 99 | + commandToSend = commandToSend.trim(); |
| 100 | + if(commandToSend.isEmpty()) |
| 101 | + { |
| 102 | + ChatUtils.error("SafeTP command cannot be empty."); |
| 103 | + setEnabled(false); |
| 104 | + return; |
| 105 | + } |
| 106 | + |
| 107 | + netHandler.sendChatCommand(commandToSend); |
| 108 | + |
| 109 | + EVENTS.add(UpdateListener.class, this); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + protected void onDisable() |
| 114 | + { |
| 115 | + EVENTS.remove(UpdateListener.class, this); |
| 116 | + ticksRemaining = 0; |
| 117 | + |
| 118 | + BlinkHack blinkHack = WURST.getHax().blinkHack; |
| 119 | + if(weActivatedBlink && blinkHack.isEnabled()) |
| 120 | + blinkHack.cancel(); |
| 121 | + |
| 122 | + weActivatedBlink = false; |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public void onUpdate() |
| 127 | + { |
| 128 | + if(MC.player == null || MC.getNetworkHandler() == null) |
| 129 | + { |
| 130 | + setEnabled(false); |
| 131 | + return; |
| 132 | + } |
| 133 | + |
| 134 | + BlinkHack blinkHack = WURST.getHax().blinkHack; |
| 135 | + if(!blinkHack.isEnabled()) |
| 136 | + { |
| 137 | + setEnabled(false); |
| 138 | + return; |
| 139 | + } |
| 140 | + |
| 141 | + if(ticksRemaining <= 0) |
| 142 | + { |
| 143 | + setEnabled(false); |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + ticksRemaining--; |
| 148 | + |
| 149 | + if(ticksRemaining <= 0) |
| 150 | + setEnabled(false); |
| 151 | + } |
| 152 | +} |
0 commit comments