3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

slight code changes for PR

Dieser Commit ist enthalten in:
RaphiMC 2020-08-12 17:16:50 +02:00
Ursprung 70d08dfc6f
Commit acfdbc5494
4 geänderte Dateien mit 99 neuen und 69 gelöschten Zeilen

Datei anzeigen

@ -22,52 +22,57 @@ public class TranslateRewriter {
@Override @Override
protected void handleHoverEvent(JsonObject hoverEvent) { protected void handleHoverEvent(JsonObject hoverEvent) {
String action = hoverEvent.getAsJsonPrimitive("action").getAsString(); String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
if (action.equals("show_achievement")) { if (!action.equals("show_achievement")) {
String value = hoverEvent.getAsJsonPrimitive("value").getAsString(); super.handleHoverEvent(hoverEvent);
if (AchievementTranslationMapping.get(value) != null) { return;
try { }
JsonObject newLine = new JsonObject();
newLine.addProperty("text", "\n"); String value = hoverEvent.getAsJsonPrimitive("value").getAsString();
JsonArray baseArray = new JsonArray(); if (AchievementTranslationMapping.get(value) == null) {
baseArray.add(""); JsonObject invalidText = new JsonObject();
JsonObject namePart = new JsonObject(); invalidText.addProperty("text", "Invalid statistic/achievement!");
JsonObject typePart = new JsonObject(); invalidText.addProperty("color", "red");
baseArray.add(namePart); hoverEvent.addProperty("action", "show_text");
baseArray.add(newLine); hoverEvent.add("value", invalidText);
baseArray.add(typePart); super.handleHoverEvent(hoverEvent);
if (value.startsWith("achievement")) { return;
namePart.addProperty("translate", value); }
namePart.addProperty("color", AchievementTranslationMapping.isSpecial(value) ? "dark_purple" : "green");
typePart.addProperty("translate", "stats.tooltip.type.achievement"); try {
JsonObject description = new JsonObject(); JsonObject newLine = new JsonObject();
typePart.addProperty("italic", true); newLine.addProperty("text", "\n");
description.addProperty("translate", value + ".desc"); JsonArray baseArray = new JsonArray();
baseArray.add(newLine); baseArray.add("");
baseArray.add(description); JsonObject namePart = new JsonObject();
} else if (value.startsWith("stat")) { JsonObject typePart = new JsonObject();
namePart.addProperty("translate", value); baseArray.add(namePart);
namePart.addProperty("color", "gray"); baseArray.add(newLine);
typePart.addProperty("translate", "stats.tooltip.type.statistic"); baseArray.add(typePart);
typePart.addProperty("italic", true); if (value.startsWith("achievement")) {
} namePart.addProperty("translate", value);
hoverEvent.addProperty("action", "show_text"); namePart.addProperty("color", AchievementTranslationMapping.isSpecial(value) ? "dark_purple" : "green");
hoverEvent.add("value", baseArray); typePart.addProperty("translate", "stats.tooltip.type.achievement");
} catch (Exception e) { JsonObject description = new JsonObject();
Via.getPlatform().getLogger().warning("Error rewriting show_achievement: " + hoverEvent); typePart.addProperty("italic", true);
e.printStackTrace(); description.addProperty("translate", value + ".desc");
JsonObject invalidText = new JsonObject(); baseArray.add(newLine);
invalidText.addProperty("text", "Invalid statistic/achievement!"); baseArray.add(description);
invalidText.addProperty("color", "red"); } else if (value.startsWith("stat")) {
hoverEvent.addProperty("action", "show_text"); namePart.addProperty("translate", value);
hoverEvent.add("value", invalidText); namePart.addProperty("color", "gray");
} typePart.addProperty("translate", "stats.tooltip.type.statistic");
} else { typePart.addProperty("italic", true);
JsonObject invalidText = new JsonObject();
invalidText.addProperty("text", "Invalid statistic/achievement!");
invalidText.addProperty("color", "red");
hoverEvent.addProperty("action", "show_text");
hoverEvent.add("value", invalidText);
} }
hoverEvent.addProperty("action", "show_text");
hoverEvent.add("value", baseArray);
} catch (Exception e) {
Via.getPlatform().getLogger().warning("Error rewriting show_achievement: " + hoverEvent);
e.printStackTrace();
JsonObject invalidText = new JsonObject();
invalidText.addProperty("text", "Invalid statistic/achievement!");
invalidText.addProperty("color", "red");
hoverEvent.addProperty("action", "show_text");
hoverEvent.add("value", invalidText);
} }
super.handleHoverEvent(hoverEvent); super.handleHoverEvent(hoverEvent);
} }

Datei anzeigen

@ -1,12 +1,14 @@
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.data; package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.data;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.HashSet;
import java.util.Set;
public class AchievementTranslationMapping { public class AchievementTranslationMapping {
private static final Object2ObjectOpenHashMap<String, String> ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150, 1.0f); private static final Object2ObjectOpenHashMap<String, String> ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150, 1.0f);
private static final ObjectArrayList<String> SPECIAL_ACHIEVEMENTS = new ObjectArrayList<>(10); private static final Set<String> SPECIAL_ACHIEVEMENTS = new HashSet<>(10);
static { static {
add("chat.type.achievement", "%s has just earned the achievement %s"); add("chat.type.achievement", "%s has just earned the achievement %s");
@ -111,11 +113,11 @@ public class AchievementTranslationMapping {
add("achievement.bakeCake.desc", "Wheat, sugar, milk and eggs!"); add("achievement.bakeCake.desc", "Wheat, sugar, milk and eggs!");
add("achievement.buildBetterPickaxe", "Getting an Upgrade"); add("achievement.buildBetterPickaxe", "Getting an Upgrade");
add("achievement.buildBetterPickaxe.desc", "Construct a better pickaxe"); add("achievement.buildBetterPickaxe.desc", "Construct a better pickaxe");
add("achievement.overpowered", "Overpowered", true); addSpecial("achievement.overpowered", "Overpowered");
add("achievement.overpowered.desc", "Eat a Notch apple"); add("achievement.overpowered.desc", "Eat a Notch apple");
add("achievement.cookFish", "Delicious Fish"); add("achievement.cookFish", "Delicious Fish");
add("achievement.cookFish.desc", "Catch and cook fish!"); add("achievement.cookFish.desc", "Catch and cook fish!");
add("achievement.onARail", "On A Rail", true); addSpecial("achievement.onARail", "On A Rail");
add("achievement.onARail.desc", "Travel by minecart at least 1 km from where you started"); add("achievement.onARail.desc", "Travel by minecart at least 1 km from where you started");
add("achievement.buildSword", "Time to Strike!"); add("achievement.buildSword", "Time to Strike!");
add("achievement.buildSword.desc", "Use planks and sticks to make a sword"); add("achievement.buildSword.desc", "Use planks and sticks to make a sword");
@ -125,9 +127,9 @@ public class AchievementTranslationMapping {
add("achievement.killCow.desc", "Harvest some leather"); add("achievement.killCow.desc", "Harvest some leather");
add("achievement.breedCow", "Repopulation"); add("achievement.breedCow", "Repopulation");
add("achievement.breedCow.desc", "Breed two cows with wheat"); add("achievement.breedCow.desc", "Breed two cows with wheat");
add("achievement.flyPig", "When Pigs Fly", true); addSpecial("achievement.flyPig", "When Pigs Fly");
add("achievement.flyPig.desc", "Fly a pig off a cliff"); add("achievement.flyPig.desc", "Fly a pig off a cliff");
add("achievement.snipeSkeleton", "Sniper Duel", true); addSpecial("achievement.snipeSkeleton", "Sniper Duel");
add("achievement.snipeSkeleton.desc", "Kill a skeleton with an arrow from more than 50 meters"); add("achievement.snipeSkeleton.desc", "Kill a skeleton with an arrow from more than 50 meters");
add("achievement.diamonds", "DIAMONDS!"); add("achievement.diamonds", "DIAMONDS!");
add("achievement.diamonds.desc", "Acquire diamonds with your iron tools"); add("achievement.diamonds.desc", "Acquire diamonds with your iron tools");
@ -135,27 +137,27 @@ public class AchievementTranslationMapping {
add("achievement.diamondsToYou.desc", "Throw diamonds at another player"); add("achievement.diamondsToYou.desc", "Throw diamonds at another player");
add("achievement.portal", "We Need to Go Deeper"); add("achievement.portal", "We Need to Go Deeper");
add("achievement.portal.desc", "Build a portal to the Nether"); add("achievement.portal.desc", "Build a portal to the Nether");
add("achievement.ghast", "Return to Sender", true); addSpecial("achievement.ghast", "Return to Sender");
add("achievement.ghast.desc", "Destroy a Ghast with a fireball"); add("achievement.ghast.desc", "Destroy a Ghast with a fireball");
add("achievement.blazeRod", "Into Fire"); add("achievement.blazeRod", "Into Fire");
add("achievement.blazeRod.desc", "Relieve a Blaze of its rod"); add("achievement.blazeRod.desc", "Relieve a Blaze of its rod");
add("achievement.potion", "Local Brewery"); add("achievement.potion", "Local Brewery");
add("achievement.potion.desc", "Brew a potion"); add("achievement.potion.desc", "Brew a potion");
add("achievement.theEnd", "The End?", true); addSpecial("achievement.theEnd", "The End?");
add("achievement.theEnd.desc", "Locate the End"); add("achievement.theEnd.desc", "Locate the End");
add("achievement.theEnd2", "The End.", true); addSpecial("achievement.theEnd2", "The End.");
add("achievement.theEnd2.desc", "Defeat the Ender Dragon"); add("achievement.theEnd2.desc", "Defeat the Ender Dragon");
add("achievement.spawnWither", "The Beginning?"); add("achievement.spawnWither", "The Beginning?");
add("achievement.spawnWither.desc", "Spawn the Wither"); add("achievement.spawnWither.desc", "Spawn the Wither");
add("achievement.killWither", "The Beginning."); add("achievement.killWither", "The Beginning.");
add("achievement.killWither.desc", "Kill the Wither"); add("achievement.killWither.desc", "Kill the Wither");
add("achievement.fullBeacon", "Beaconator", true); addSpecial("achievement.fullBeacon", "Beaconator");
add("achievement.fullBeacon.desc", "Create a full beacon"); add("achievement.fullBeacon.desc", "Create a full beacon");
add("achievement.exploreAllBiomes", "Adventuring Time", true); addSpecial("achievement.exploreAllBiomes", "Adventuring Time");
add("achievement.exploreAllBiomes.desc", "Discover all biomes"); add("achievement.exploreAllBiomes.desc", "Discover all biomes");
add("achievement.enchantments", "Enchanter"); add("achievement.enchantments", "Enchanter");
add("achievement.enchantments.desc", "Use a book, obsidian and diamonds to construct an enchantment table"); add("achievement.enchantments.desc", "Use a book, obsidian and diamonds to construct an enchantment table");
add("achievement.overkill", "Overkill", true); addSpecial("achievement.overkill", "Overkill");
add("achievement.overkill.desc", "Deal nine hearts of damage in a single hit"); add("achievement.overkill.desc", "Deal nine hearts of damage in a single hit");
add("achievement.bookcase", "Librarian"); add("achievement.bookcase", "Librarian");
add("achievement.bookcase.desc", "Build some bookshelves to improve your enchantment table"); add("achievement.bookcase.desc", "Build some bookshelves to improve your enchantment table");
@ -165,7 +167,7 @@ public class AchievementTranslationMapping {
ACHIEVEMENTS.put(key, value); ACHIEVEMENTS.put(key, value);
} }
private static void add(String key, String value, boolean special) { private static void addSpecial(String key, String value) {
add(key, value); add(key, value);
SPECIAL_ACHIEVEMENTS.add(key); SPECIAL_ACHIEVEMENTS.add(key);
} }

Datei anzeigen

@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Triple;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_13Types;
@ -25,10 +24,7 @@ import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.*;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticMappings;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
@ -189,7 +185,7 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int size = wrapper.read(Type.VAR_INT); int size = wrapper.read(Type.VAR_INT);
List<Triple<Integer, Integer, Integer>> remappedStats = new ArrayList<>(); List<StatisticData> remappedStats = new ArrayList<>();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
String name = wrapper.read(Type.STRING); String name = wrapper.read(Type.STRING);
String[] split = name.split("\\."); String[] split = name.split("\\.");
@ -236,14 +232,14 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
} }
} }
if (newId != -1) if (newId != -1)
remappedStats.add(new Triple<>(categoryId, newId, value)); remappedStats.add(new StatisticData(categoryId, newId, value));
} }
wrapper.write(Type.VAR_INT, remappedStats.size()); // size wrapper.write(Type.VAR_INT, remappedStats.size()); // size
for (Triple<Integer, Integer, Integer> stat : remappedStats) { for (StatisticData stat : remappedStats) {
wrapper.write(Type.VAR_INT, stat.getFirst()); // category id wrapper.write(Type.VAR_INT, stat.getCategoryId()); // category id
wrapper.write(Type.VAR_INT, stat.getSecond()); // statistics id wrapper.write(Type.VAR_INT, stat.getNewId()); // statistics id
wrapper.write(Type.VAR_INT, stat.getThird()); // value wrapper.write(Type.VAR_INT, stat.getValue()); // value
} }
} }
}); });

Datei anzeigen

@ -0,0 +1,27 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
public class StatisticData {
private final int categoryId;
private final int newId;
private final int value;
public StatisticData(int categoryId, int newId, int value) {
this.categoryId = categoryId;
this.newId = newId;
this.value = value;
}
public int getCategoryId() {
return categoryId;
}
public int getNewId() {
return newId;
}
public int getValue() {
return value;
}
}