Skip to content

Commit a83a9f8

Browse files
committed
Added SafeTPA Here
1 parent 352888d commit a83a9f8

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ I have no other experience in the field of Minecraft and have never used any oth
192192
### SafeTP
193193
- Combines Blink, your desired teleport command and a timer into a single function
194194
- Allows you to teleport without worrying about the movement restrictions during the countdown
195+
- Safe TPA Here option: Allows you to auto activate blink when a player accepts your TPA Here request and then auto deactivates when they arrive.
195196

196197
## What’s changed or improved in this fork?
197198

src/main/java/net/wurstclient/hacks/SafeTpHack.java

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
package net.wurstclient.hacks;
99

1010
import net.minecraft.client.network.ClientPlayNetworkHandler;
11+
import net.minecraft.util.math.BlockPos;
1112
import net.wurstclient.Category;
1213
import net.wurstclient.SearchTags;
14+
import net.wurstclient.events.ChatInputListener;
15+
import net.wurstclient.events.ChatInputListener.ChatInputEvent;
1316
import net.wurstclient.events.UpdateListener;
1417
import net.wurstclient.hack.Hack;
1518
import net.wurstclient.settings.SliderSetting;
1619
import net.wurstclient.settings.SliderSetting.ValueDisplay;
1720
import net.wurstclient.settings.TextFieldSetting;
21+
import net.wurstclient.settings.CheckboxSetting;
22+
import net.wurstclient.util.text.WText;
1823
import net.wurstclient.util.ChatUtils;
1924

2025
@SearchTags({"safe tp", "safe teleport"})
21-
public final class SafeTpHack extends Hack implements UpdateListener
26+
public final class SafeTpHack extends Hack
27+
implements UpdateListener, ChatInputListener
2228
{
2329
private final TextFieldSetting command = new TextFieldSetting("Command",
2430
"description.wurst.setting.safetp.command", "/t spawn",
@@ -30,12 +36,33 @@ public final class SafeTpHack extends Hack implements UpdateListener
3036
private int ticksRemaining;
3137
private boolean weActivatedBlink;
3238

39+
private final CheckboxSetting saferTpaHere = new CheckboxSetting(
40+
"Safer TPA Here",
41+
WText.literal(
42+
"When enabled, automatically enable Blink when your TPA is accepted and release it when the player arrives. Useful to safely accept TPAs without exposing your position."),
43+
false);
44+
45+
private final SliderSetting tpaTimeout = new SliderSetting("TPA timeout",
46+
"How long to wait for the arriving player before releasing Blink.", 6.0,
47+
1, 30, 0.25, ValueDisplay.DECIMAL.withSuffix("s"));
48+
49+
private BlockPos trapPos = null;
50+
private boolean weActivatedBlinkForTpa = false;
51+
private int tpaTicksRemaining = 0;
52+
private boolean tpaUpdateRegistered = false;
53+
3354
public SafeTpHack()
3455
{
3556
super("SafeTP");
3657
setCategory(Category.OTHER);
3758
addSetting(command);
3859
addSetting(waitTime);
60+
addSetting(saferTpaHere);
61+
addSetting(tpaTimeout);
62+
63+
// Always listen for TPA accept messages so the Safer TPA Here toggle
64+
// works independently of SafeTP being enabled.
65+
EVENTS.add(ChatInputListener.class, this);
3966
}
4067

4168
@Override
@@ -119,12 +146,128 @@ protected void onDisable()
119146
if(weActivatedBlink && blinkHack.isEnabled())
120147
blinkHack.cancel();
121148

149+
if(weActivatedBlinkForTpa && blinkHack.isEnabled())
150+
blinkHack.setEnabled(false);
151+
122152
weActivatedBlink = false;
153+
weActivatedBlinkForTpa = false;
154+
trapPos = null;
155+
tpaTicksRemaining = 0;
156+
}
157+
158+
@Override
159+
public void onReceivedMessage(ChatInputEvent event)
160+
{
161+
if(!saferTpaHere.isChecked())
162+
return;
163+
164+
String message = event.getComponent().getString().toLowerCase();
165+
if(message.startsWith("\u00a7c[\u00a76wurst\u00a7c]"))
166+
return;
167+
168+
if((message.contains("accepted") && message.contains("teleport"))
169+
|| (message.contains("accepted") && message.contains("request"))
170+
|| (message.contains("akzeptiert") && message.contains("anfrage")))
171+
{
172+
ChatUtils.message("SaferTPAHere: TPA acceptance detected.");
173+
if(MC.player == null || MC.getNetworkHandler() == null)
174+
return;
175+
176+
trapPos = BlockPos.ofFloored(MC.player.getEntityPos());
177+
178+
BlinkHack blinkHack = WURST.getHax().blinkHack;
179+
boolean blinkAlready = blinkHack.isEnabled();
180+
if(!blinkAlready)
181+
{
182+
blinkHack.setEnabled(true);
183+
if(!blinkHack.isEnabled())
184+
{
185+
ChatUtils.error("SaferTPAHere could not enable Blink.");
186+
trapPos = null;
187+
return;
188+
}
189+
190+
weActivatedBlinkForTpa = true;
191+
ChatUtils.message("SaferTPAHere: Blink enabled for TPA.");
192+
}
193+
194+
ChatUtils.message(
195+
"SaferTPAHere: Blink enabled. Waiting for arriving player at "
196+
+ trapPos.toShortString());
197+
198+
// start timeout for arrival
199+
tpaTicksRemaining =
200+
Math.max((int)Math.ceil(tpaTimeout.getValue() * 20), 1);
201+
202+
// ensure we receive onUpdate even when SafeTP hack itself is
203+
// disabled
204+
if(!isEnabled() && !tpaUpdateRegistered)
205+
{
206+
EVENTS.add(UpdateListener.class, this);
207+
tpaUpdateRegistered = true;
208+
}
209+
}
123210
}
124211

125212
@Override
126213
public void onUpdate()
127214
{
215+
if(trapPos != null)
216+
{
217+
for(net.minecraft.entity.player.PlayerEntity p : MC.world
218+
.getPlayers())
219+
{
220+
if(p == MC.player)
221+
continue;
222+
if(p instanceof net.wurstclient.util.FakePlayerEntity)
223+
continue;
224+
225+
BlockPos pPos = p.getBlockPos();
226+
if(pPos.equals(trapPos)
227+
|| p.squaredDistanceTo(trapPos.getX() + 0.5, trapPos.getY(),
228+
trapPos.getZ() + 0.5) < 1.5)
229+
{
230+
BlinkHack blinkHack = WURST.getHax().blinkHack;
231+
if(weActivatedBlinkForTpa && blinkHack.isEnabled())
232+
{
233+
blinkHack.setEnabled(false);
234+
ChatUtils.message("SaferTPAHere: Detected arrival of "
235+
+ p.getName().getString() + ". Blink released.");
236+
}
237+
238+
trapPos = null;
239+
weActivatedBlinkForTpa = false;
240+
if(tpaUpdateRegistered)
241+
{
242+
EVENTS.remove(UpdateListener.class, this);
243+
tpaUpdateRegistered = false;
244+
}
245+
return;
246+
}
247+
}
248+
249+
// decrement TPA timeout
250+
tpaTicksRemaining--;
251+
if(tpaTicksRemaining <= 0)
252+
{
253+
BlinkHack blinkHack = WURST.getHax().blinkHack;
254+
if(weActivatedBlinkForTpa && blinkHack.isEnabled())
255+
{
256+
blinkHack.setEnabled(false);
257+
ChatUtils.message(
258+
"SaferTPAHere: Timeout waiting for arrival. Blink released.");
259+
}
260+
trapPos = null;
261+
weActivatedBlinkForTpa = false;
262+
if(tpaUpdateRegistered)
263+
{
264+
EVENTS.remove(UpdateListener.class, this);
265+
tpaUpdateRegistered = false;
266+
}
267+
return;
268+
}
269+
}
270+
128271
if(MC.player == null || MC.getNetworkHandler() == null)
129272
{
130273
setEnabled(false);

0 commit comments

Comments
 (0)