3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Add Advanced Tooltips command (#2632)

Co-authored-by: YHDiamond <47502993+yehudahrrs@users.noreply.github.com>
Dieser Commit ist enthalten in:
YHDiamond 2021-11-26 10:49:28 -05:00 committet von GitHub
Ursprung 798f8da573
Commit 720045a03f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 107 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,9 @@ permissions:
geyser.command.advancements: geyser.command.advancements:
description: Shows the advancements of the player on the server. description: Shows the advancements of the player on the server.
default: true default: true
geyser.command.tooltips:
description: Toggles showing advanced tooltips on your items.
default: true
geyser.command.statistics: geyser.command.statistics:
description: Shows the statistics of the player on the server. description: Shows the statistics of the player on the server.
default: true default: true
@ -36,4 +39,4 @@ permissions:
default: false default: false
geyser.command.version: geyser.command.version:
description: Shows the current Geyser version and checks for updates. description: Shows the current Geyser version and checks for updates.
default: op default: op

Datei anzeigen

@ -54,6 +54,7 @@ public abstract class CommandManager {
registerCommand(new SettingsCommand(connector, "settings", "geyser.commands.settings.desc", "geyser.command.settings")); registerCommand(new SettingsCommand(connector, "settings", "geyser.commands.settings.desc", "geyser.command.settings"));
registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics")); registerCommand(new StatisticsCommand(connector, "statistics", "geyser.commands.statistics.desc", "geyser.command.statistics"));
registerCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements")); registerCommand(new AdvancementsCommand("advancements", "geyser.commands.advancements.desc", "geyser.command.advancements"));
registerCommand(new AdvancedTooltipsCommand("tooltips", "geyser.commands.advancedtooltips.desc", "geyser.command.tooltips"));
if (GeyserConnector.getInstance().getPlatformType() == PlatformType.STANDALONE) { if (GeyserConnector.getInstance().getPlatformType() == PlatformType.STANDALONE) {
registerCommand(new StopCommand(connector, "stop", "geyser.commands.stop.desc", "geyser.command.stop")); registerCommand(new StopCommand(connector, "stop", "geyser.commands.stop.desc", "geyser.command.stop"));
} }

Datei anzeigen

@ -0,0 +1,57 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* 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.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.command.defaults;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LocaleUtils;
public class AdvancedTooltipsCommand extends GeyserCommand {
public AdvancedTooltipsCommand(String name, String description, String permission) {
super(name, description, permission);
}
@Override
public void execute(GeyserSession session, CommandSender sender, String[] args) {
if (session != null) {
String onOrOff = session.isAdvancedTooltips() ? "off" : "on";
session.setAdvancedTooltips(!session.isAdvancedTooltips());
session.sendMessage("§l§e" + LocaleUtils.getLocaleString("debug.prefix", session.getLocale()) + " §r" + LocaleUtils.getLocaleString("debug.advanced_tooltips." + onOrOff, session.getLocale()));
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
}
}
@Override
public boolean isExecutableOnConsole() {
return false;
}
@Override
public boolean isBedrockOnly() {
return true;
}
}

Datei anzeigen

@ -450,6 +450,12 @@ public class GeyserSession implements CommandSender {
private MinecraftProtocol protocol; private MinecraftProtocol protocol;
/**
* Whether advanced tooltips will be added to the player's items.
*/
@Setter
private boolean advancedTooltips = false;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession, EventLoop eventLoop) { public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
this.connector = connector; this.connector = connector;
this.upstream = new UpstreamSession(bedrockServerSession); this.upstream = new UpstreamSession(bedrockServerSession);

Datei anzeigen

@ -155,6 +155,9 @@ public abstract class ItemTranslator {
} }
nbt = translateDisplayProperties(session, nbt, bedrockItem); nbt = translateDisplayProperties(session, nbt, bedrockItem);
if (session.isAdvancedTooltips()) {
nbt = addAdvancedTooltips(nbt, session.getItemMappings().getMapping(stack), session.getLocale());
}
ItemStack itemStack = new ItemStack(stack.getId(), stack.getAmount(), nbt); ItemStack itemStack = new ItemStack(stack.getId(), stack.getAmount(), nbt);
@ -184,6 +187,41 @@ public abstract class ItemTranslator {
return builder.build(); return builder.build();
} }
private static CompoundTag addAdvancedTooltips(CompoundTag nbt, ItemMapping mapping, String language) {
CompoundTag newNbt = nbt;
if (newNbt == null) {
newNbt = new CompoundTag("nbt");
CompoundTag display = new CompoundTag("display");
display.put(new ListTag("Lore"));
newNbt.put(display);
}
CompoundTag compoundTag = newNbt.get("display");
if (compoundTag == null) {
compoundTag = new CompoundTag("display");
}
ListTag listTag = compoundTag.get("Lore");
if (listTag == null) {
listTag = new ListTag("Lore");
}
int maxDurability = mapping.getMaxDamage();
if (maxDurability != 0) {
int durability = maxDurability - ((IntTag) newNbt.get("Damage")).getValue();
if (durability != maxDurability) {
listTag.add(new StringTag("", "§r§f" + String.format(MessageTranslator.convertMessage("item.durability", language), durability, maxDurability)));
}
}
listTag.add(new StringTag("", "§r§8" + mapping.getJavaIdentifier()));
if (nbt != null) {
listTag.add(new StringTag("", "§r§8" + String.format(MessageTranslator.convertMessage("item.nbt_tags", language), nbt.size())));
}
compoundTag.put(listTag);
newNbt.put(compoundTag);
return newNbt;
}
/** /**
* Translates the Java NBT of canDestroy and canPlaceOn to its Bedrock counterparts. * Translates the Java NBT of canDestroy and canPlaceOn to its Bedrock counterparts.
* In Java, this is treated as normal NBT, but in Bedrock, these arguments are extra parts of the item data itself. * In Java, this is treated as normal NBT, but in Bedrock, these arguments are extra parts of the item data itself.

@ -1 +1 @@
Subproject commit d12420771ea5e13083b3556552298d164767aae9 Subproject commit 1a50238c1c743579a1dbd93c57d02b5da3be14fa