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

Fix NPE for items with missing mappings (Closes #24)

Dieser Commit ist enthalten in:
RednedEpic 2019-08-09 16:09:47 -05:00
Ursprung 33c4c115ab
Commit 7dae4cbd0f
4 geänderte Dateien mit 18 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -119,10 +119,6 @@ public class GeyserConnector implements Connector {
shutdown(); shutdown();
} }
metrics = new Metrics("GeyserMC", instance.getConfig().getUUID(), true, java.util.logging.Logger.getLogger(""));
addMetrics(metrics);
logger.setDebug(config.isDebugMode()); logger.setDebug(config.isDebugMode());
Toolbox.CACHED_PALLETE.array(); Toolbox.CACHED_PALLETE.array();
@ -151,6 +147,10 @@ public class GeyserConnector implements Connector {
throwable.printStackTrace(); throwable.printStackTrace();
} }
}).join(); }).join();
metrics = new Metrics("GeyserMC", instance.getConfig().getUUID(), true, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount));
} }
public Collection<Player> getConnectedPlayers() { public Collection<Player> getConnectedPlayers() {
@ -179,9 +179,4 @@ public class GeyserConnector implements Connector {
players.remove(player.getAuthenticationData().getName()); players.remove(player.getAuthenticationData().getName());
players.remove(player.getAuthenticationData().getUUID()); players.remove(player.getAuthenticationData().getUUID());
} }
private static void addMetrics(Metrics m) {
m.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
m.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount));
}
} }

Datei anzeigen

@ -32,6 +32,8 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public class BedrockItem { public class BedrockItem {
public static BedrockItem AIR = new BedrockItem("minecraft:air", 0, 0);
private String identifier; private String identifier;
private int id; private int id;
private int data; private int data;

Datei anzeigen

@ -42,6 +42,7 @@ import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.data.ItemData;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.Remapper; import org.geysermc.connector.utils.Remapper;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
@ -78,11 +79,20 @@ public class ItemTranslator {
public static BedrockItem getBedrockItem(ItemStack stack) { public static BedrockItem getBedrockItem(ItemStack stack) {
Map<String, Object> m = Remapper.JAVA_TO_BEDROCK.get(stack.getId()); Map<String, Object> m = Remapper.JAVA_TO_BEDROCK.get(stack.getId());
if (m == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for java item " + stack.getId());
return BedrockItem.AIR;
}
return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data")); return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
} }
public static JavaItem getJavaItem(ItemData data) { public static JavaItem getJavaItem(ItemData data) {
Map<String, Object> m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage()); Map<String, Object> m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage());
if (m == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
return JavaItem.AIR;
}
return new JavaItem((String) m.get("name"), (Integer) m.get("id")); return new JavaItem((String) m.get("name"), (Integer) m.get("id"));
} }

Datei anzeigen

@ -32,6 +32,8 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public class JavaItem { public class JavaItem {
public static JavaItem AIR = new JavaItem("minecraft:air", 0);
private String identifier; private String identifier;
private int id; private int id;