Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 08:30:10 +01:00
Minor cleanup
Dieser Commit ist enthalten in:
Ursprung
446f46db83
Commit
d4a76b0ff5
@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.viaversion.libs.gson.JsonElement;
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
import us.myles.viaversion.libs.gson.JsonObject;
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
import us.myles.viaversion.libs.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,7 +18,6 @@ import java.util.Map;
|
|||||||
public class TranslatableRewriter {
|
public class TranslatableRewriter {
|
||||||
|
|
||||||
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
||||||
protected static final JsonParser JSON_PARSER = new JsonParser();
|
|
||||||
protected final BackwardsProtocol protocol;
|
protected final BackwardsProtocol protocol;
|
||||||
protected final Map<String, String> newTranslatables;
|
protected final Map<String, String> newTranslatables;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonArray;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonPrimitive;
|
||||||
|
|
||||||
public class ChatItemRewriter {
|
public class ChatItemRewriter {
|
||||||
|
|
||||||
|
@ -10,19 +10,17 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import nl.matsv.viabackwards.ViaBackwards;
|
import nl.matsv.viabackwards.ViaBackwards;
|
||||||
import nl.matsv.viabackwards.api.rewriters.Rewriter;
|
import nl.matsv.viabackwards.api.rewriters.Rewriter;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations;
|
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -41,12 +39,9 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
|||||||
map(Type.STRING); // 0 - Json Data
|
map(Type.STRING); // 0 - Json Data
|
||||||
map(Type.BYTE); // 1 - Position
|
map(Type.BYTE); // 1 - Position
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(wrapper -> {
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
JsonParser parser = new JsonParser();
|
|
||||||
try {
|
try {
|
||||||
JsonObject object = parser.parse(wrapper.get(Type.STRING, 0)).getAsJsonObject();
|
JsonObject object = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0)).getAsJsonObject();
|
||||||
|
|
||||||
// Skip if the root doesn't contain translate
|
// Skip if the root doesn't contain translate
|
||||||
if (object.has("translate"))
|
if (object.has("translate"))
|
||||||
@ -61,7 +56,6 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.chat;
|
|||||||
|
|
||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
|
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
|
||||||
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
import us.myles.viaversion.libs.gson.JsonArray;
|
import us.myles.viaversion.libs.gson.JsonArray;
|
||||||
import us.myles.viaversion.libs.gson.JsonElement;
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
import us.myles.viaversion.libs.gson.JsonObject;
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
@ -34,7 +35,7 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String processTranslate(String value) {
|
public String processTranslate(String value) {
|
||||||
JsonElement root = JSON_PARSER.parse(value);
|
JsonElement root = GsonUtil.getJsonParser().parse(value);
|
||||||
if (!root.isJsonObject()) {
|
if (!root.isJsonObject()) {
|
||||||
return super.processTranslate(value);
|
return super.processTranslate(value);
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Matsv
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package nl.matsv.viabackwards.utils;
|
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
|
||||||
|
|
||||||
public class ItemUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets all the data of the item into the original item.
|
|
||||||
*
|
|
||||||
* @param original item to be modified
|
|
||||||
* @param item item to replicate the data from
|
|
||||||
* @return modified original item
|
|
||||||
*/
|
|
||||||
public static void copyItem(Item original, Item item) {
|
|
||||||
original.setIdentifier(item.getIdentifier());
|
|
||||||
original.setAmount(item.getAmount());
|
|
||||||
original.setData(item.getData());
|
|
||||||
original.setTag(item.getTag() != null ? item.getTag().clone() : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new item object with the same data as the given one.
|
|
||||||
*
|
|
||||||
* @param item item to be copied
|
|
||||||
* @return a new copy of the item
|
|
||||||
*/
|
|
||||||
public static Item copyItem(Item item) {
|
|
||||||
if (item == null) return null;
|
|
||||||
return new Item(item.getIdentifier(), item.getAmount(), item.getData(), item.getTag() != null ? item.getTag().clone() : null);
|
|
||||||
}
|
|
||||||
}
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren