-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
282 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rc/main/java/com/viaversion/viabackwards/api/rewriters/text/JsonNBTComponentRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards | ||
* Copyright (C) 2016-2025 ViaVersion 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.viaversion.viabackwards.api.rewriters.text; | ||
|
||
import com.viaversion.nbt.tag.CompoundTag; | ||
import com.viaversion.nbt.tag.StringTag; | ||
import com.viaversion.viabackwards.api.BackwardsProtocol; | ||
import com.viaversion.viabackwards.api.data.TranslatableMappings; | ||
import com.viaversion.viaversion.api.connection.UserConnection; | ||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; | ||
import com.viaversion.viaversion.libs.gson.JsonObject; | ||
import java.util.Map; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class JsonNBTComponentRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.text.JsonNBTComponentRewriter<C> implements TranslatableRewriter { | ||
|
||
private final Map<String, String> translatables; | ||
|
||
public JsonNBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type) { | ||
super(protocol, type); | ||
this.translatables = TranslatableMappings.translatablesFor(protocol); | ||
} | ||
|
||
public JsonNBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String version) { | ||
super(protocol, type); | ||
this.translatables = TranslatableMappings.translatablesFor(version); | ||
} | ||
|
||
@Override | ||
protected void handleTranslate(final JsonObject root, final String translate) { | ||
final String newTranslate = mappedTranslationKey(translate); | ||
if (newTranslate != null) { | ||
root.addProperty("translate", newTranslate); | ||
} | ||
} | ||
|
||
@Override | ||
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) { | ||
final String newTranslate = mappedTranslationKey(translateTag.getValue()); | ||
if (newTranslate != null) { | ||
parentTag.put("translate", new StringTag(newTranslate)); | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable String mappedTranslationKey(final String translationKey) { | ||
return translatables.get(translationKey); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...on/src/main/java/com/viaversion/viabackwards/api/rewriters/text/NBTComponentRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards | ||
* Copyright (C) 2016-2025 ViaVersion 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.viaversion.viabackwards.api.rewriters.text; | ||
|
||
import com.viaversion.nbt.tag.CompoundTag; | ||
import com.viaversion.nbt.tag.StringTag; | ||
import com.viaversion.viabackwards.api.BackwardsProtocol; | ||
import com.viaversion.viabackwards.api.data.TranslatableMappings; | ||
import com.viaversion.viaversion.api.connection.UserConnection; | ||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; | ||
import com.viaversion.viaversion.libs.gson.JsonObject; | ||
import java.util.Map; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class NBTComponentRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.text.NBTComponentRewriter<C> implements TranslatableRewriter { | ||
|
||
private final Map<String, String> translatables; | ||
|
||
public NBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol) { | ||
super(protocol); | ||
this.translatables = TranslatableMappings.translatablesFor(protocol); | ||
} | ||
|
||
public NBTComponentRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final String version) { | ||
super(protocol); | ||
this.translatables = TranslatableMappings.translatablesFor(version); | ||
} | ||
|
||
@Override | ||
protected void handleTranslate(final JsonObject root, final String translate) { | ||
final String newTranslate = mappedTranslationKey(translate); | ||
if (newTranslate != null) { | ||
root.addProperty("translate", newTranslate); | ||
} | ||
} | ||
|
||
@Override | ||
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) { | ||
final String newTranslate = mappedTranslationKey(translateTag.getValue()); | ||
if (newTranslate != null) { | ||
parentTag.put("translate", new StringTag(newTranslate)); | ||
} | ||
} | ||
|
||
@Override | ||
public @Nullable String mappedTranslationKey(final String translationKey) { | ||
return translatables.get(translationKey); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...on/src/main/java/com/viaversion/viabackwards/api/rewriters/text/TranslatableRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards | ||
* Copyright (C) 2016-2025 ViaVersion 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.viaversion.viabackwards.api.rewriters.text; | ||
|
||
import com.viaversion.viaversion.api.rewriter.ComponentRewriter; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public interface TranslatableRewriter extends ComponentRewriter { | ||
|
||
@Nullable | ||
String mappedTranslationKey(String translationKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.