Skip to content

Commit ed0f738

Browse files
committed
Add ApolloPlayerUseItemBucketEvent API
1 parent eb38139 commit ed0f738

File tree

11 files changed

+391
-3
lines changed

11 files changed

+391
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
fi
4242
4343
- name: Gradle Publish
44-
if: "${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/version/') }}"
44+
if: "${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/version/') || github.ref == 'refs/heads/feature/bucket-desync' }}"
4545
run: ./gradlew publish
4646

4747
- name: Gradle Release
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.event.packetenrichment.world;
25+
26+
import com.lunarclient.apollo.event.Event;
27+
import com.lunarclient.apollo.module.packetenrichment.PlayerInfo;
28+
import com.lunarclient.apollo.module.packetenrichment.raytrace.RayTraceResult;
29+
import com.lunarclient.apollo.player.ApolloPlayer;
30+
import lombok.Value;
31+
32+
/**
33+
* Represents an event that is fired when a player uses a bucket (1.7 and 1.8).
34+
*
35+
* @since 1.2.2
36+
*/
37+
@Value
38+
public class ApolloPlayerUseItemBucketEvent implements Event {
39+
40+
/**
41+
* The player that sent the packet.
42+
*
43+
* @return the player
44+
* @since 1.2.2
45+
*/
46+
ApolloPlayer player;
47+
48+
/**
49+
* The {@code long} representing the unix timestamp
50+
* when the packet was created.
51+
*
52+
* @return the unix timestamp
53+
* @since 1.2.2
54+
*/
55+
long instantiationTimeMs;
56+
57+
/**
58+
* The player's {@link PlayerInfo} information.
59+
*
60+
* @return the player info
61+
* @since 1.2.2
62+
*/
63+
PlayerInfo playerInfo;
64+
65+
/**
66+
* The player's {@link RayTraceResult}.
67+
*
68+
* @return the ray trace result
69+
* @since 1.2.2
70+
*/
71+
RayTraceResult rayTraceResult;
72+
73+
}

api/src/main/java/com/lunarclient/apollo/event/packetenrichment/world/ApolloPlayerUseItemEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import lombok.Value;
3030

3131
/**
32-
* Represents an event that is when a player uses an item (1.16.1+).
32+
* Represents an event that is fired when a player uses an item (1.16.1+).
3333
*
3434
* @since 1.0.7
3535
*/
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.packetenrichment.raytrace;
25+
26+
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
27+
import com.lunarclient.apollo.common.location.ApolloLocation;
28+
import lombok.Builder;
29+
import lombok.Getter;
30+
31+
/**
32+
* Represents the block hit ray trace result.
33+
*
34+
* @since 1.2.2
35+
*/
36+
@Getter
37+
@Builder
38+
public class BlockHitResult extends RayTraceResult {
39+
40+
/**
41+
* The exact hit {@link ApolloLocation} of the ray on the block.
42+
*
43+
* @return the hit location
44+
* @since 1.2.2
45+
*/
46+
ApolloLocation hitLocation;
47+
48+
/**
49+
* The {@link ApolloBlockLocation} of the block that was hit.
50+
*
51+
* @return the block location
52+
* @since 1.2.2
53+
*/
54+
ApolloBlockLocation blockLocation;
55+
56+
/**
57+
* The {@link Direction} from which the block was hit.
58+
*
59+
* @return the direction
60+
* @since 1.2.2
61+
*/
62+
Direction direction;
63+
64+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.packetenrichment.raytrace;
25+
26+
/**
27+
* Represents a direction in which a block was hit.
28+
*
29+
* @since 1.2.2
30+
*/
31+
public enum Direction {
32+
DOWN,
33+
UP,
34+
NORTH,
35+
SOUTH,
36+
WEST,
37+
EAST
38+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.packetenrichment.raytrace;
25+
26+
import com.lunarclient.apollo.common.ApolloEntity;
27+
import com.lunarclient.apollo.common.location.ApolloLocation;
28+
import lombok.Builder;
29+
import lombok.Getter;
30+
31+
/**
32+
* Represents the entity hit ray trace result.
33+
*
34+
* @since 1.2.2
35+
*/
36+
@Getter
37+
@Builder
38+
public class EntityHitResult extends RayTraceResult {
39+
40+
/**
41+
* The exact hit {@link ApolloLocation} of the ray on the entity.
42+
*
43+
* @return the hit location
44+
* @since 1.2.2
45+
*/
46+
ApolloLocation hitLocation;
47+
48+
/**
49+
* The {@link ApolloEntity} that was hit.
50+
*
51+
* @return the entity ID
52+
* @since 1.2.2
53+
*/
54+
ApolloEntity entityId;
55+
56+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.packetenrichment.raytrace;
25+
26+
/**
27+
* Represents the missed ray trace result.
28+
*
29+
* @since 1.2.2
30+
*/
31+
public class MissResult extends RayTraceResult {
32+
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.packetenrichment.raytrace;
25+
26+
/**
27+
* The abstract base class for ray trace results.
28+
*
29+
* @since 1.2.2
30+
*/
31+
public abstract class RayTraceResult {
32+
33+
}

common/src/main/java/com/lunarclient/apollo/module/packetenrichment/PacketEnrichmentImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import com.lunarclient.apollo.event.packetenrichment.chat.ApolloPlayerChatCloseEvent;
2929
import com.lunarclient.apollo.event.packetenrichment.chat.ApolloPlayerChatOpenEvent;
3030
import com.lunarclient.apollo.event.packetenrichment.melee.ApolloPlayerAttackEvent;
31+
import com.lunarclient.apollo.event.packetenrichment.world.ApolloPlayerUseItemBucketEvent;
3132
import com.lunarclient.apollo.event.packetenrichment.world.ApolloPlayerUseItemEvent;
3233
import com.lunarclient.apollo.network.NetworkTypes;
3334
import com.lunarclient.apollo.packetenrichment.v1.PlayerAttackMessage;
3435
import com.lunarclient.apollo.packetenrichment.v1.PlayerChatCloseMessage;
3536
import com.lunarclient.apollo.packetenrichment.v1.PlayerChatOpenMessage;
37+
import com.lunarclient.apollo.packetenrichment.v1.PlayerUseItemBucketMessage;
3638
import com.lunarclient.apollo.packetenrichment.v1.PlayerUseItemMessage;
3739

3840
/**
@@ -109,6 +111,21 @@ private void onReceivePacket(ApolloReceivePacketEvent event) {
109111
throwable.printStackTrace();
110112
}
111113
});
114+
115+
event.unpack(PlayerUseItemBucketMessage.class).ifPresent(packet -> {
116+
ApolloPlayerUseItemBucketEvent playerUseItemBucketEvent = new ApolloPlayerUseItemBucketEvent(
117+
event.getPlayer(),
118+
NetworkTypes.fromProtobuf(packet.getPacketInfo().getInstantiationTime()),
119+
NetworkTypes.fromProtobuf(packet.getPlayerInfo()),
120+
NetworkTypes.fromProtobuf(packet.getRayTraceResult())
121+
);
122+
123+
EventBus.EventResult<ApolloPlayerUseItemBucketEvent> result = EventBus.getBus().post(playerUseItemBucketEvent);
124+
125+
for (Throwable throwable : result.getThrowing()) {
126+
throwable.printStackTrace();
127+
}
128+
});
112129
}
113130

114131
}

0 commit comments

Comments
 (0)