Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
Clean up a bunch
Mostly checked with IntelliJ, but manually performed. The only issue I possibly anticipate is item name/lore issues, but the new method should be technically better.
Dieser Commit ist enthalten in:
Ursprung
683ac1c763
Commit
3a2cff7864
@ -32,17 +32,16 @@ import org.geysermc.connector.common.serializer.AsteriskSerializer;
|
||||
import org.geysermc.connector.dump.BootstrapDumpInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class GeyserBungeeDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
private boolean onlineMode;
|
||||
private List<ListenerInfo> listeners;
|
||||
private List<PluginInfo> plugins;
|
||||
private final String platformName;
|
||||
private final String platformVersion;
|
||||
private final boolean onlineMode;
|
||||
private final List<ListenerInfo> listeners;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
||||
GeyserBungeeDumpInfo(ProxyServer proxy) {
|
||||
super();
|
||||
@ -63,7 +62,7 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo {
|
||||
}
|
||||
|
||||
for (Plugin plugin : proxy.getPluginManager().getPlugins()) {
|
||||
this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Arrays.asList(plugin.getDescription().getAuthor())));
|
||||
this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Collections.singletonList(plugin.getDescription().getAuthor())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import org.geysermc.connector.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Arrays;
|
||||
@ -64,9 +63,8 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
|
||||
new GeyserPingInfo.Version(response.getVersion().getName(), response.getVersion().getProtocol())
|
||||
);
|
||||
if (event.getResponse().getPlayers().getSample() != null) {
|
||||
Arrays.stream(event.getResponse().getPlayers().getSample()).forEach(proxiedPlayer -> {
|
||||
geyserPingInfo.getPlayerList().add(proxiedPlayer.getName());
|
||||
});
|
||||
Arrays.stream(event.getResponse().getPlayers().getSample()).forEach(proxiedPlayer ->
|
||||
geyserPingInfo.getPlayerList().add(proxiedPlayer.getName()));
|
||||
}
|
||||
return geyserPingInfo;
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ import java.util.List;
|
||||
@Getter
|
||||
public class GeyserSpigotDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
private String platformAPIVersion;
|
||||
private boolean onlineMode;
|
||||
private String serverIP;
|
||||
private int serverPort;
|
||||
private List<PluginInfo> plugins;
|
||||
private final String platformName;
|
||||
private final String platformVersion;
|
||||
private final String platformAPIVersion;
|
||||
private final boolean onlineMode;
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
||||
GeyserSpigotDumpInfo() {
|
||||
super();
|
||||
|
@ -34,6 +34,7 @@ import org.bukkit.util.CachedServerIcon;
|
||||
import org.geysermc.connector.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
@ -72,9 +73,10 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
|
||||
public void setServerIcon(CachedServerIcon icon) throws IllegalArgumentException, UnsupportedOperationException {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Iterator<Player> iterator() throws UnsupportedOperationException {
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||
this.geyserSpigotPingPassthrough = new GeyserSpigotPingPassthrough(geyserLogger);
|
||||
}
|
||||
|
||||
this.geyserCommandManager = new GeyserSpigotCommandManager(this, connector);
|
||||
this.geyserCommandManager = new GeyserSpigotCommandManager(connector);
|
||||
|
||||
boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
||||
if (isViaVersion) {
|
||||
|
@ -30,7 +30,6 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
import org.geysermc.platform.spigot.GeyserSpigotPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@ -48,12 +47,8 @@ public class GeyserSpigotCommandManager extends CommandManager {
|
||||
}
|
||||
}
|
||||
|
||||
private GeyserSpigotPlugin plugin;
|
||||
|
||||
public GeyserSpigotCommandManager(GeyserSpigotPlugin plugin, GeyserConnector connector) {
|
||||
public GeyserSpigotCommandManager(GeyserConnector connector) {
|
||||
super(connector);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +93,6 @@ public class GeyserSpigot1_12WorldManager extends GeyserSpigotWorldManager {
|
||||
* @param z Z coordinate of block
|
||||
* @return the block state updated to the latest Minecraft version
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getLegacyBlock(BlockStorage storage, int blockId, int x, int y, int z) {
|
||||
// Convert block state from old version (1.12.2) -> 1.13 -> 1.13.1 -> 1.14 -> 1.15 -> 1.16 -> 1.16.2
|
||||
blockId = mappingData1_12to1_13.getNewBlockId(blockId);
|
||||
|
@ -36,13 +36,12 @@ import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class GeyserSpongeDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
private boolean onlineMode;
|
||||
private String serverIP;
|
||||
private int serverPort;
|
||||
private List<PluginInfo> plugins;
|
||||
private final String platformName;
|
||||
private final String platformVersion;
|
||||
private final boolean onlineMode;
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
||||
GeyserSpongeDumpInfo() {
|
||||
super();
|
||||
|
@ -33,7 +33,6 @@ import org.geysermc.connector.common.ChatColor;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.utils.LanguageUtils;
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
@ -81,7 +80,7 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException {
|
||||
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) {
|
||||
if (arguments.split(" ").length == 1) {
|
||||
return connector.getCommandManager().getCommandNames();
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ import org.spongepowered.api.command.CommandMapping;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
public class GeyserSpongeCommandManager extends CommandManager {
|
||||
|
||||
private org.spongepowered.api.command.CommandManager handle;
|
||||
private final org.spongepowered.api.command.CommandManager handle;
|
||||
|
||||
public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserConnector connector) {
|
||||
super(connector);
|
||||
@ -43,6 +42,8 @@ public class GeyserSpongeCommandManager extends CommandManager {
|
||||
|
||||
@Override
|
||||
public String getDescription(String command) {
|
||||
return handle.get(command).map(CommandMapping::getCallable).map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY)).orElse(Text.EMPTY).toPlain();
|
||||
return handle.get(command).map(CommandMapping::getCallable)
|
||||
.map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY))
|
||||
.orElse(Text.EMPTY).toPlain();
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,7 @@ import org.geysermc.connector.dump.BootstrapDumpInfo;
|
||||
|
||||
@Getter
|
||||
public class GeyserStandaloneDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private boolean isGui;
|
||||
private final boolean isGui;
|
||||
|
||||
GeyserStandaloneDumpInfo(GeyserStandaloneBootstrap bootstrap) {
|
||||
super();
|
||||
|
@ -30,7 +30,6 @@ import org.geysermc.connector.utils.LanguageUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class LoopbackUtil {
|
||||
@ -54,7 +53,7 @@ public class LoopbackUtil {
|
||||
String result = sb.toString();
|
||||
|
||||
if (!result.contains("minecraftuwp")) {
|
||||
Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes(), new OpenOption[0]);
|
||||
Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes());
|
||||
Runtime.getRuntime().exec(startScript);
|
||||
|
||||
geyserLogger.info(ChatColor.AQUA + LanguageUtils.getLocaleStringLog("geyser.bootstrap.loopback.added"));
|
||||
|
@ -60,8 +60,8 @@ public class ColorPane extends JTextPane {
|
||||
*/
|
||||
public void appendANSI(String s) { // convert ANSI color codes first
|
||||
int aPos = 0; // current char position in addString
|
||||
int aIndex = 0; // index of next Escape sequence
|
||||
int mIndex = 0; // index of "m" terminating Escape sequence
|
||||
int aIndex; // index of next Escape sequence
|
||||
int mIndex; // index of "m" terminating Escape sequence
|
||||
String tmpString = "";
|
||||
boolean stillSearching = true; // true until no more Escape sequences
|
||||
String addString = remaining + s;
|
||||
@ -83,7 +83,6 @@ public class ColorPane extends JTextPane {
|
||||
|
||||
|
||||
// while there's text in the input buffer
|
||||
stillSearching = true;
|
||||
while (stillSearching) {
|
||||
mIndex = addString.indexOf("m", aPos); // find the end of the escape sequence
|
||||
if (mIndex < 0) { // the buffer ends halfway through the ansi string!
|
||||
|
@ -46,7 +46,7 @@ public final class GraphPanel extends JPanel {
|
||||
private final static Color pointColor = new Color(100, 100, 100, 255);
|
||||
private final static Color gridColor = new Color(200, 200, 200, 255);
|
||||
private static final Stroke graphStroke = new BasicStroke(2f);
|
||||
private List<Integer> values = new ArrayList<>(10);
|
||||
private final List<Integer> values = new ArrayList<>(10);
|
||||
|
||||
@Setter
|
||||
private String xLabel = "";
|
||||
@ -172,6 +172,7 @@ public final class GraphPanel extends JPanel {
|
||||
for (Point graphPoint : graphPoints) {
|
||||
final int x = graphPoint.x - pointWidth / 2;
|
||||
final int y = graphPoint.y - pointWidth / 2;
|
||||
//noinspection SuspiciousNameCombination
|
||||
g.fillOval(x, y, pointWidth, pointWidth);
|
||||
}
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ import java.util.List;
|
||||
@Getter
|
||||
public class GeyserVelocityDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
private String platformVendor;
|
||||
private boolean onlineMode;
|
||||
private String serverIP;
|
||||
private int serverPort;
|
||||
private List<PluginInfo> plugins;
|
||||
private final String platformName;
|
||||
private final String platformVersion;
|
||||
private final String platformVendor;
|
||||
private final boolean onlineMode;
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
||||
GeyserVelocityDumpInfo(ProxyServer proxy) {
|
||||
super();
|
||||
|
@ -38,8 +38,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HelpCommand extends GeyserCommand {
|
||||
|
||||
public GeyserConnector connector;
|
||||
private final GeyserConnector connector;
|
||||
|
||||
public HelpCommand(GeyserConnector connector, String name, String description, String permission) {
|
||||
super(name, description, permission);
|
||||
|
@ -45,8 +45,7 @@ public class ListCommand extends GeyserCommand {
|
||||
|
||||
@Override
|
||||
public void execute(GeyserSession session, CommandSender sender, String[] args) {
|
||||
String message = "";
|
||||
message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(),
|
||||
String message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(),
|
||||
connector.getPlayers().size(),
|
||||
connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" ")));
|
||||
|
||||
|
@ -84,7 +84,8 @@ public class IGeyserMain {
|
||||
Class<?> graphicsEnvironment = Class.forName("java.awt.GraphicsEnvironment");
|
||||
Method isHeadless = graphicsEnvironment.getDeclaredMethod("isHeadless");
|
||||
return (Boolean)isHeadless.invoke(null);
|
||||
} catch (Exception ex) { }
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -135,22 +135,27 @@ public class FireworkEntity extends Entity {
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
builder.put("Fireworks", fireworksBuilder.build());
|
||||
metadata.put(EntityData.DISPLAY_ITEM, builder.build());
|
||||
} else if (entityMetadata.getId() == 9 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) {
|
||||
//Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too.
|
||||
PlayerEntity entity = session.getPlayerEntity();
|
||||
float yaw = entity.getRotation().getX();
|
||||
float pitch = entity.getRotation().getY();
|
||||
//Uses math from NukkitX
|
||||
entity.setMotion(Vector3f.from(
|
||||
-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2,
|
||||
-Math.sin(Math.toRadians(pitch)) * 2,
|
||||
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
|
||||
//Need to update the EntityMotionPacket or else the player won't boost
|
||||
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
|
||||
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
entityMotionPacket.setMotion(entity.getMotion());
|
||||
} else if (entityMetadata.getId() == 9) {
|
||||
OptionalInt optional = (OptionalInt) entityMetadata.getValue();
|
||||
// Checks if the firework has an entity ID (used when a player is gliding)
|
||||
// and checks to make sure the player that is gliding is the one getting sent the packet
|
||||
// or else every player near the gliding player will boost too.
|
||||
if (optional.isPresent() && optional.getAsInt() == session.getPlayerEntity().getEntityId()) {
|
||||
PlayerEntity entity = session.getPlayerEntity();
|
||||
float yaw = entity.getRotation().getX();
|
||||
float pitch = entity.getRotation().getY();
|
||||
// Uses math from NukkitX
|
||||
entity.setMotion(Vector3f.from(
|
||||
-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2,
|
||||
-Math.sin(Math.toRadians(pitch)) * 2,
|
||||
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2));
|
||||
// Need to update the EntityMotionPacket or else the player won't boost
|
||||
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
|
||||
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
entityMotionPacket.setMotion(entity.getMotion());
|
||||
|
||||
session.sendUpstreamPacket(entityMotionPacket);
|
||||
session.sendUpstreamPacket(entityMotionPacket);
|
||||
}
|
||||
}
|
||||
|
||||
super.updateBedrockMetadata(entityMetadata, session);
|
||||
|
@ -53,7 +53,7 @@ public class Inventory {
|
||||
@Setter
|
||||
protected String title;
|
||||
|
||||
protected GeyserItemStack[] items;
|
||||
protected final GeyserItemStack[] items;
|
||||
|
||||
/**
|
||||
* The location of the inventory block. Will either be a fake block above the player's head, or the actual block location
|
||||
|
@ -38,9 +38,8 @@ import org.geysermc.connector.network.session.GeyserSession;
|
||||
* packets of interest and limit boilerplate code.
|
||||
*/
|
||||
public class LoggingPacketHandler implements BedrockPacketHandler {
|
||||
|
||||
protected GeyserConnector connector;
|
||||
protected GeyserSession session;
|
||||
protected final GeyserConnector connector;
|
||||
protected final GeyserSession session;
|
||||
|
||||
LoggingPacketHandler(GeyserConnector connector, GeyserSession session) {
|
||||
this.connector = connector;
|
||||
@ -759,9 +758,6 @@ public class LoggingPacketHandler implements BedrockPacketHandler {
|
||||
return defaultHandler(packet);
|
||||
}
|
||||
|
||||
// I question if God exists because of this packet - God does not exist if I find out there's a built-in dab
|
||||
// TODO for the future: redirect this as a /me command
|
||||
// TODO for the far future: should we have a client mod that handles skins, handle these too
|
||||
@Override
|
||||
public boolean handle(EmoteListPacket packet) {
|
||||
return defaultHandler(packet);
|
||||
|
@ -83,7 +83,7 @@ public class QueryPacketHandler {
|
||||
* @return if the packet is a query packet
|
||||
*/
|
||||
private boolean isQueryPacket(ByteBuf buffer) {
|
||||
return (buffer.readableBytes() >= 2) ? buffer.readUnsignedShort() == 0xFEFD : false;
|
||||
return buffer.readableBytes() >= 2 && buffer.readUnsignedShort() == 0xFEFD;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,15 +37,14 @@ import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BossBar {
|
||||
private final GeyserSession session;
|
||||
|
||||
private GeyserSession session;
|
||||
|
||||
private long entityId;
|
||||
private final long entityId;
|
||||
private Component title;
|
||||
private float health;
|
||||
private int color;
|
||||
private int overlay;
|
||||
private int darkenSky;
|
||||
private final int color;
|
||||
private final int overlay;
|
||||
private final int darkenSky;
|
||||
|
||||
public void addBossBar() {
|
||||
addBossEntity();
|
||||
|
@ -39,16 +39,13 @@ public class BedrockMapInfoRequestTranslator extends PacketTranslator<MapInfoReq
|
||||
|
||||
@Override
|
||||
public void translate(MapInfoRequestPacket packet, GeyserSession session) {
|
||||
long mapID = packet.getUniqueMapId();
|
||||
long mapId = packet.getUniqueMapId();
|
||||
|
||||
if (session.getStoredMaps().containsKey(mapID)) {
|
||||
ClientboundMapItemDataPacket mapPacket = session.getStoredMaps().remove(mapId);
|
||||
if (mapPacket != null) {
|
||||
// Delay the packet 100ms to prevent the client from ignoring the packet
|
||||
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
|
||||
ClientboundMapItemDataPacket mapPacket = session.getStoredMaps().remove(mapID);
|
||||
if (mapPacket != null) {
|
||||
session.sendUpstreamPacket(mapPacket);
|
||||
}
|
||||
}, 100, TimeUnit.MILLISECONDS);
|
||||
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> session.sendUpstreamPacket(mapPacket),
|
||||
100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.connector.utils.LocaleUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
@ -42,7 +43,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class MinecraftTranslationRegistry implements Translator {
|
||||
@Override
|
||||
public @NonNull Key name() {
|
||||
public @Nonnull Key name() {
|
||||
return Key.key("geyser", "minecraft_translations");
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package org.geysermc.connector.network.translators.collision;
|
||||
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
|
@ -34,8 +34,7 @@ import org.geysermc.connector.network.translators.world.block.BlockTranslator1_1
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class ItemEntry {
|
||||
|
||||
public static ItemEntry AIR = new ItemEntry("minecraft:air", "minecraft:air", 0, 0, 0,
|
||||
public static final ItemEntry AIR = new ItemEntry("minecraft:air", "minecraft:air", 0, 0, 0,
|
||||
BlockTranslator1_17_0.INSTANCE.getBedrockAirId(), 64);
|
||||
|
||||
private final String javaIdentifier;
|
||||
|
@ -296,7 +296,7 @@ public abstract class ItemTranslator {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
|
||||
List<Object> tagList = new ArrayList<>();
|
||||
for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) {
|
||||
for (Tag value : listTag) {
|
||||
tagList.add(translateToBedrockNBT(value));
|
||||
}
|
||||
NbtType<?> type = NbtType.COMPOUND;
|
||||
|
@ -131,8 +131,8 @@ public class BannerTranslator extends ItemTranslator {
|
||||
*/
|
||||
public static ListTag convertBannerPattern(List<NbtMap> patterns) {
|
||||
List<Tag> tagsList = new ArrayList<>();
|
||||
for (Object patternTag : patterns) {
|
||||
tagsList.add(getJavaBannerPattern((NbtMap) patternTag));
|
||||
for (NbtMap patternTag : patterns) {
|
||||
tagsList.add(getJavaBannerPattern(patternTag));
|
||||
}
|
||||
|
||||
return new ListTag("Patterns", tagsList);
|
||||
|
@ -29,12 +29,9 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.ItemRemapper;
|
||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
|
||||
|
||||
@ -46,27 +43,17 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (!itemTag.contains("display")) {
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag == null) {
|
||||
return;
|
||||
}
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag.contains("Name")) {
|
||||
StringTag nameTag = displayTag.get("Name");
|
||||
try {
|
||||
displayTag.put(new StringTag("Name", toBedrockMessage(nameTag)));
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (displayTag.contains("Lore")) {
|
||||
ListTag loreTag = displayTag.get("Lore");
|
||||
ListTag loreTag = displayTag.get("Lore");
|
||||
if (loreTag != null) {
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
for (Tag tag : loreTag.getValue()) {
|
||||
if (!(tag instanceof StringTag)) return;
|
||||
try {
|
||||
lore.add(new StringTag("", toBedrockMessage((StringTag) tag)));
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
if (!(tag instanceof StringTag)) continue;
|
||||
lore.add(new StringTag("", MessageTranslator.convertMessageLenient(((StringTag) tag).getValue(), session.getLocale())));
|
||||
}
|
||||
displayTag.put(new ListTag("Lore", lore));
|
||||
}
|
||||
@ -74,54 +61,24 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (!itemTag.contains("display")) {
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag == null) {
|
||||
return;
|
||||
}
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
|
||||
if (displayTag.contains("Name")) {
|
||||
StringTag nameTag = displayTag.get("Name");
|
||||
displayTag.put(new StringTag("Name", toJavaMessage(nameTag)));
|
||||
displayTag.put(new StringTag("Name", MessageTranslator.convertToJavaMessage(nameTag.getValue())));
|
||||
}
|
||||
|
||||
if (displayTag.contains("Lore")) {
|
||||
ListTag loreTag = displayTag.get("Lore");
|
||||
List<Tag> lore = new ArrayList<>();
|
||||
for (Tag tag : loreTag.getValue()) {
|
||||
if (!(tag instanceof StringTag)) return;
|
||||
lore.add(new StringTag("", "§r" + toJavaMessage((StringTag) tag)));
|
||||
if (!(tag instanceof StringTag)) continue;
|
||||
lore.add(new StringTag("", MessageTranslator.convertToJavaMessage(((StringTag) tag).getValue())));
|
||||
}
|
||||
displayTag.put(new ListTag("Lore", lore));
|
||||
}
|
||||
}
|
||||
|
||||
private String toJavaMessage(StringTag tag) {
|
||||
String message = tag.getValue();
|
||||
if (message == null) return null;
|
||||
if (message.startsWith("§r")) {
|
||||
message = message.replaceFirst("§r", "");
|
||||
}
|
||||
Component component = Component.text(message);
|
||||
return GsonComponentSerializer.gson().serialize(component);
|
||||
}
|
||||
|
||||
private String toBedrockMessage(StringTag tag) {
|
||||
String message = tag.getValue();
|
||||
if (message == null) return null;
|
||||
TextComponent component = (TextComponent) GsonComponentSerializer.gson().deserialize(message);
|
||||
String legacy = LegacyComponentSerializer.legacySection().serialize(component);
|
||||
if (hasFormatting(LegacyComponentSerializer.legacySection().deserialize(legacy))) {
|
||||
return "§r" + legacy;
|
||||
}
|
||||
return legacy;
|
||||
}
|
||||
|
||||
private boolean hasFormatting(Component component) {
|
||||
if (component.hasStyling()) return true;
|
||||
for (Component child : component.children()) {
|
||||
if (hasFormatting(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
||||
case UPDATE_STYLE:
|
||||
case UPDATE_FLAGS:
|
||||
//todo
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.UpdatedTileType;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
@ -47,7 +48,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
|
||||
public void translate(ServerUpdateTileEntityPacket packet, GeyserSession session) {
|
||||
String id = BlockEntityUtils.getBedrockBlockEntityId(packet.getType().name());
|
||||
if (packet.getNbt().isEmpty()) { // Fixes errors in servers sending empty NBT
|
||||
BlockEntityUtils.updateBlockEntity(session, null, packet.getPosition());
|
||||
BlockEntityUtils.updateBlockEntity(session, NbtMap.EMPTY, packet.getPosition());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@ import org.geysermc.connector.utils.ChunkUtils;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
|
||||
|
||||
@Translator(packet = ServerUpdateViewPositionPacket.class)
|
||||
public class JavaUpdateViewPositionTranslator extends PacketTranslator<ServerUpdateViewPositionPacket> {
|
||||
|
@ -70,7 +70,7 @@ public class SoundRegistry {
|
||||
brMap.has("playsound_mapping") && brMap.get("playsound_mapping").isTextual() ? brMap.get("playsound_mapping").asText() : null,
|
||||
brMap.has("extra_data") && brMap.get("extra_data").isInt() ? brMap.get("extra_data").asInt() : -1,
|
||||
brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null,
|
||||
brMap.has("level_event") && brMap.get("level_event").isBoolean() ? brMap.get("level_event").asBoolean() : false
|
||||
brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
||||
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||
import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler;
|
||||
import org.geysermc.connector.network.translators.sound.SoundHandler;
|
||||
|
||||
|
@ -43,8 +43,7 @@ import java.net.SocketTimeoutException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runnable {
|
||||
|
||||
private GeyserConnector connector;
|
||||
private final GeyserConnector connector;
|
||||
|
||||
public GeyserLegacyPingPassthrough(GeyserConnector connector) {
|
||||
this.connector = connector;
|
||||
|
@ -58,22 +58,17 @@ public enum BedrockMapIcon {
|
||||
|
||||
private static final BedrockMapIcon[] VALUES = values();
|
||||
|
||||
private MapIconType iconType;
|
||||
private final MapIconType iconType;
|
||||
|
||||
@Getter
|
||||
private int iconID;
|
||||
private final int iconID;
|
||||
|
||||
private int red;
|
||||
private int green;
|
||||
private int blue;
|
||||
private final int red;
|
||||
private final int green;
|
||||
private final int blue;
|
||||
|
||||
BedrockMapIcon(MapIconType iconType, int iconID) {
|
||||
this.iconType = iconType;
|
||||
this.iconID = iconID;
|
||||
|
||||
this.red = 255;
|
||||
this.green = 255;
|
||||
this.blue = 255;
|
||||
this(iconType, iconID, 255, 255, 255);
|
||||
}
|
||||
|
||||
BedrockMapIcon(MapIconType iconType, int iconID, int red, int green, int blue) {
|
||||
@ -107,11 +102,11 @@ public enum BedrockMapIcon {
|
||||
* @return ARGB as an int
|
||||
*/
|
||||
public int toARGB() {
|
||||
int alpha = 255;
|
||||
final int alpha = 255;
|
||||
|
||||
return ((alpha & 0xFF) << 24) |
|
||||
((red & 0xFF) << 16) |
|
||||
((green & 0xFF) << 8) |
|
||||
((blue & 0xFF) << 0);
|
||||
(blue & 0xFF);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BlockEntityUtils {
|
||||
private static final BlockEntityTranslator EMPTY_TRANSLATOR = BlockEntityTranslator.BLOCK_ENTITY_TRANSLATORS.get("Empty");
|
||||
|
||||
@ -66,11 +68,11 @@ public class BlockEntityUtils {
|
||||
return EMPTY_TRANSLATOR;
|
||||
}
|
||||
|
||||
public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Position position) {
|
||||
public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Position position) {
|
||||
updateBlockEntity(session, blockEntity, Vector3i.from(position.getX(), position.getY(), position.getZ()));
|
||||
}
|
||||
|
||||
public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Vector3i position) {
|
||||
public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Vector3i position) {
|
||||
BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
|
||||
blockEntityPacket.setBlockPosition(position);
|
||||
blockEntityPacket.setData(blockEntity);
|
||||
|
@ -205,7 +205,8 @@ public class FileUtils {
|
||||
URL resource = FileUtils.class.getClassLoader().getResource("META-INF/reflections/" + path + "-reflections.xml");
|
||||
try (InputStream inputStream = resource.openConnection().getInputStream()) {
|
||||
reflections.merge(serializer.read(inputStream));
|
||||
} catch (IOException e) { }
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
||||
return reflections;
|
||||
}
|
||||
|
@ -71,13 +71,13 @@ public enum GameRule {
|
||||
private static final GameRule[] VALUES = values();
|
||||
|
||||
@Getter
|
||||
private String javaID;
|
||||
private final String javaID;
|
||||
|
||||
@Getter
|
||||
private Class<?> type;
|
||||
private final Class<?> type;
|
||||
|
||||
@Getter
|
||||
private Object defaultValue;
|
||||
private final Object defaultValue;
|
||||
|
||||
GameRule(String javaID, Class<?> type) {
|
||||
this(javaID, type, null);
|
||||
|
@ -136,7 +136,7 @@ public class LocaleUtils {
|
||||
// Check if we have already downloaded the locale file
|
||||
if (localeFile.exists()) {
|
||||
String curHash = "";
|
||||
String targetHash = "";
|
||||
String targetHash;
|
||||
|
||||
if (locale.equals("en_us")) {
|
||||
try {
|
||||
|
@ -287,6 +287,6 @@ public enum MapColor {
|
||||
return ((alpha & 0xFF) << 24) |
|
||||
((blue & 0xFF) << 16) |
|
||||
((green & 0xFF) << 8) |
|
||||
((red & 0xFF) << 0);
|
||||
(red & 0xFF);
|
||||
}
|
||||
}
|
@ -34,8 +34,6 @@ import org.geysermc.cumulus.CustomForm;
|
||||
import org.geysermc.cumulus.component.DropdownComponent;
|
||||
import org.geysermc.cumulus.response.CustomFormResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsUtils {
|
||||
/**
|
||||
* Build a settings form for the given session and store it for later
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren