feat: added WrapperPlayClientCraftRecipeRequest and WrapperPlayServerCraftRecipeResponse wrapper classes

With this pull request users can use two new wrappers that work fine - I think there is nothing more to explain.
It was tested with the server versions: 1.8.8, 1.12.2, 1.13, 1.13.2, 1.14.4, 1.15.2, 1.16.5 and 1.18.2
Client-Versions: 1.18.2, 1.16.5, 1.13
This commit is contained in:
NoJokeFNA committed 2022-05-09 21:54:10 +02:00
1 parent c4798df9dc
commit 1f15d0ba20
5 files changed
+201 -2

No files matched your search

@@ -0,0 +1,98 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.wrapper.play.client;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
public class WrapperPlayClientCraftRecipeRequest extends PacketWrapper<WrapperPlayClientCraftRecipeRequest> {
private int windowId;
private Object recipe;
private boolean makeAll;
public WrapperPlayClientCraftRecipeRequest(PacketReceiveEvent event) {
super(event);
}
public WrapperPlayClientCraftRecipeRequest(int windowId, Object recipe, boolean makeAll) {
super(PacketType.Play.Client.CRAFT_RECIPE_REQUEST);
this.windowId = windowId;
this.recipe = recipe;
this.makeAll = makeAll;
}
@Override
public void read() {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12)) {
this.windowId = readByte();
if (serverVersion.isNewerThan(ServerVersion.V_1_12_2)) {
this.recipe = readString();
} else {
this.recipe = readVarInt();
}
this.makeAll = readBoolean();
}
}
@Override
public void copy(WrapperPlayClientCraftRecipeRequest wrapper) {
this.windowId = wrapper.windowId;
this.recipe = wrapper.recipe;
this.makeAll = wrapper.makeAll;
}
@Override
public void write() {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12)) {
writeByte(this.windowId);
if (serverVersion.isNewerThan(ServerVersion.V_1_12_2)) {
writeString((String) this.recipe);
} else {
writeVarInt((Integer) this.recipe);
}
writeBoolean(this.makeAll);
}
}
public int getWindowId() {
return this.windowId;
}
public void setWindowId(int windowId) {
this.windowId = windowId;
}
public Object getRecipe() {
return recipe;
}
public void setRecipe(Object recipe) {
this.recipe = recipe;
}
public boolean isMakeAll() {
return makeAll;
}
public void setMakeAll(boolean makeAll) {
this.makeAll = makeAll;
}
}
@@ -0,0 +1,85 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2021 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.retrooper.packetevents.wrapper.play.server;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
public class WrapperPlayServerCraftRecipeResponse extends PacketWrapper<WrapperPlayServerCraftRecipeResponse> {
private int windowId;
private Object recipe;
public WrapperPlayServerCraftRecipeResponse(PacketSendEvent event) {
super(event);
}
public WrapperPlayServerCraftRecipeResponse(int windowId, String recipe) {
super(PacketType.Play.Server.CRAFT_RECIPE_RESPONSE);
this.windowId = windowId;
this.recipe = recipe;
}
@Override
public void read() {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12)) {
this.windowId = readByte();
if (serverVersion.isNewerThan(ServerVersion.V_1_12_2)) {
this.recipe = readString();
} else {
this.recipe = readVarInt();
}
}
}
@Override
public void copy(WrapperPlayServerCraftRecipeResponse wrapper) {
this.windowId = wrapper.windowId;
this.recipe = wrapper.recipe;
}
@Override
public void write() {
if (serverVersion.isNewerThanOrEquals(ServerVersion.V_1_12)) {
writeByte(this.windowId);
if (serverVersion.isNewerThan(ServerVersion.V_1_12_2)) {
writeString((String) this.recipe);
} else {
writeVarInt((Integer) this.recipe);
}
}
}
public int getWindowId() {
return this.windowId;
}
public void setWindowId(int windowId) {
this.windowId = windowId;
}
public Object getRecipe() {
return recipe;
}
public void setRecipe(Object recipe) {
this.recipe = recipe;
}
}
+1
View File
@@ -5,6 +5,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0' apply(false)
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
wrapper {
gradleVersion = "7.3.1"
+2
View File
@@ -5,6 +5,8 @@ repositories {
maven { url 'https://repo.viaversion.com/' }
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
shadowJar {
relocate 'net.kyori.adventure.text.serializer', 'io.github.retrooper.packetevents.adventure.serializer'
@@ -189,6 +189,13 @@ public class PacketEventsPlugin extends JavaPlugin {
float forward = steerVehicle.getForward();
user.sendMessage(ChatColor.GOLD + "Sideways: " + sideways + ", forward: " + forward);
break;
case CRAFT_RECIPE_REQUEST:
WrapperPlayClientCraftRecipeRequest wrapper = new WrapperPlayClientCraftRecipeRequest(event);
int windowId = wrapper.getWindowId();
Object recipe = wrapper.getRecipe();
boolean makeAll = wrapper.isMakeAll();
user.sendMessage(ChatColor.GOLD + "WindowId: " + windowId + ", recipe: " + recipe + ", makeAll: " + makeAll);
break;
default:
break;
}
@@ -216,7 +223,7 @@ public class PacketEventsPlugin extends JavaPlugin {
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(event.getChannel(), copy);
System.out.println("Delayed " + chatMessage.getChatComponentJson());*/
event.getPostTasks().add(() -> {
user.sendTitle("Post chat message", "Pretty much", 10, 10, 10);
user.sendTitle("Post chat message", "Pretty much", 10, 10, 10);
});
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_EFFECT) {
WrapperPlayServerEntityEffect effect = new WrapperPlayServerEntityEffect(event);
@@ -224,6 +231,11 @@ public class PacketEventsPlugin extends JavaPlugin {
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_LIVING_ENTITY) {
WrapperPlayServerSpawnLivingEntity spawnLivingEntity = new WrapperPlayServerSpawnLivingEntity(event);
EntityType type = spawnLivingEntity.getEntityType();
} else if (event.getPacketType() == PacketType.Play.Server.CRAFT_RECIPE_RESPONSE) {
WrapperPlayServerCraftRecipeResponse wrapper = new WrapperPlayServerCraftRecipeResponse(event);
int windowId = wrapper.getWindowId();
Object recipe = wrapper.getRecipe();
user.sendMessage(ChatColor.GOLD + "WindowId: " + windowId + ", recipe: " + recipe);
}
}
@@ -243,7 +255,8 @@ public class PacketEventsPlugin extends JavaPlugin {
System.out.println("User: (host-name) " + event.getUser().getAddress().getHostString() + " disconnected...");
}
};
//PacketEvents.getAPI().getEventManager().registerListener(listener);
PacketEvents.getAPI().getEventManager().registerListener(listener);
}
@Override