@@ -8,16 +8,14 @@ namespace MinecraftClient.ChatBots
8
8
/// <summary>
9
9
/// This bot sends a command every 60 seconds in order to stay non-afk.
10
10
/// </summary>
11
-
12
11
public class AntiAFK : ChatBot
13
12
{
14
13
public static Configs Config = new ( ) ;
15
14
16
15
[ TomlDoNotInlineObject ]
17
16
public class Configs
18
17
{
19
- [ NonSerialized ]
20
- private const string BotName = "AntiAFK" ;
18
+ [ NonSerialized ] private const string BotName = "AntiAFK" ;
21
19
22
20
public bool Enabled = false ;
23
21
@@ -99,32 +97,36 @@ public override void Initialize()
99
97
{
100
98
LogToConsole ( Translations . bot_antiafk_not_using_terrain_handling ) ;
101
99
}
100
+ else
101
+ {
102
+ var movementLock = BotMovementLock . Instance ;
103
+ if ( movementLock is { IsLocked : true } )
104
+ LogToConsole (
105
+ $ "§§6§1§0{ string . Format ( Translations . bot_antiafk_may_not_move , movementLock . LockedBy ) } ") ;
106
+ }
102
107
}
103
108
}
104
109
105
110
public override void Update ( )
106
111
{
107
112
count ++ ;
108
113
109
- if ( count >= nextrun )
110
- {
111
- DoAntiAfkStuff ( ) ;
112
- count = 0 ;
113
- nextrun = random . Next ( Settings . DoubleToTick ( Config . Delay . min ) , Settings . DoubleToTick ( Config . Delay . max ) ) ;
114
- }
115
-
114
+ if ( count < nextrun ) return ;
115
+ DoAntiAfkStuff ( ) ;
116
+ count = 0 ;
117
+ nextrun = random . Next ( Settings . DoubleToTick ( Config . Delay . min ) , Settings . DoubleToTick ( Config . Delay . max ) ) ;
116
118
}
117
119
118
120
private void DoAntiAfkStuff ( )
119
121
{
120
- if ( Config . Use_Terrain_Handling && GetTerrainEnabled ( ) )
122
+ var isMovementLocked = BotMovementLock . Instance ;
123
+ if ( Config . Use_Terrain_Handling && GetTerrainEnabled ( ) && isMovementLocked is { IsLocked : false } )
121
124
{
122
- Location currentLocation = GetCurrentLocation ( ) ;
123
- Location goal ;
125
+ var currentLocation = GetCurrentLocation ( ) ;
124
126
125
- bool moved = false ;
126
- bool useAlternativeMethod = false ;
127
- int triesCounter = 0 ;
127
+ var moved = false ;
128
+ var useAlternativeMethod = false ;
129
+ var triesCounter = 0 ;
128
130
129
131
while ( ! moved )
130
132
{
@@ -134,10 +136,11 @@ private void DoAntiAfkStuff()
134
136
break ;
135
137
}
136
138
137
- goal = GetRandomLocationWithinRangeXZ ( currentLocation , Config . Walk_Range ) ;
139
+ var goal = GetRandomLocationWithinRangeXZ ( currentLocation , Config . Walk_Range ) ;
138
140
139
141
// Prevent getting the same location
140
- while ( ( currentLocation . X == goal . X ) && ( currentLocation . Y == goal . Y ) && ( currentLocation . Z == goal . Z ) )
142
+ while ( ( currentLocation . X == goal . X ) && ( currentLocation . Y == goal . Y ) &&
143
+ ( currentLocation . Z == goal . Z ) )
141
144
{
142
145
LogToConsole ( "Same location!, generating new one" ) ;
143
146
goal = GetRandomLocationWithinRangeXZ ( currentLocation , Config . Walk_Range ) ;
@@ -148,10 +151,8 @@ private void DoAntiAfkStuff()
148
151
useAlternativeMethod = true ;
149
152
break ;
150
153
}
151
- else
152
- {
153
- moved = MoveToLocation ( goal , allowUnsafe : false , allowDirectTeleport : false ) ;
154
- }
154
+
155
+ moved = MoveToLocation ( goal , allowUnsafe : false , allowDirectTeleport : false ) ;
155
156
}
156
157
157
158
if ( ! useAlternativeMethod && Config . Use_Sneak )
@@ -169,12 +170,14 @@ private void DoAntiAfkStuff()
169
170
Sneak ( previousSneakState ) ;
170
171
previousSneakState = ! previousSneakState ;
171
172
}
173
+
172
174
count = 0 ;
173
175
}
174
176
175
177
private Location GetRandomLocationWithinRangeXZ ( Location currentLocation , int range )
176
178
{
177
- return new Location ( currentLocation . X + random . Next ( range * - 1 , range ) , currentLocation . Y , currentLocation . Z + random . Next ( range * - 1 , range ) ) ;
179
+ return new Location ( currentLocation . X + random . Next ( range * - 1 , range ) , currentLocation . Y ,
180
+ currentLocation . Z + random . Next ( range * - 1 , range ) ) ;
178
181
}
179
182
}
180
- }
183
+ }
0 commit comments