Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser into serv…
Browse files Browse the repository at this point in the history
…er-inventory
  • Loading branch information
Camotoy committed Jan 17, 2021
2 parents 4ee3143 + 2d9baf1 commit f7822e0
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 159 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t

Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have now joined us here!

### Currently supporting Minecraft Bedrock v1.16.100 - v1.16.201 and Minecraft Java v1.16.4.
### Currently supporting Minecraft Bedrock v1.16.100 - v1.16.201 and Minecraft Java v1.16.4 - v1.16.5.

## Setting Up
Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set up Geyser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,52 @@
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;

import java.util.ArrayList;
import java.util.Arrays;

public class GeyserBungeeCommandExecutor extends Command implements TabExecutor {

private final CommandExecutor commandExecutor;
private final GeyserConnector connector;

public GeyserBungeeCommandExecutor(GeyserConnector connector) {
super("geyser");

this.commandExecutor = new CommandExecutor(connector);
this.connector = connector;
}

@Override
public void execute(CommandSender sender, String[] args) {
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
GeyserCommand command = this.commandExecutor.getCommand(args[0]);
if (command != null) {
BungeeCommandSender commandSender = new BungeeCommandSender(sender);
if (!sender.hasPermission(command.getPermission())) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());

commandSender.sendMessage(ChatColor.RED + message);
return;
}
getCommand(args[0]).execute(new BungeeCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = this.commandExecutor.getGeyserSession(commandSender);
if (session == null) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale());

commandSender.sendMessage(ChatColor.RED + message);
return;
}
}
command.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
}
} else {
getCommand("help").execute(new BungeeCommandSender(sender), new String[0]);
this.commandExecutor.getCommand("help").execute(null, new BungeeCommandSender(sender), new String[0]);
}
}

Expand All @@ -71,8 +86,4 @@ public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
}
return new ArrayList<>();
}

private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,51 @@

package org.geysermc.platform.spigot.command;

import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@AllArgsConstructor
public class GeyserSpigotCommandExecutor implements TabExecutor {
public class GeyserSpigotCommandExecutor extends CommandExecutor implements TabExecutor {

private final GeyserConnector connector;
public GeyserSpigotCommandExecutor(GeyserConnector connector) {
super(connector);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!sender.hasPermission(getCommand(args[0]).getPermission())) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());;
GeyserCommand geyserCommand = getCommand(args[0]);
if (geyserCommand != null) {
SpigotCommandSender commandSender = new SpigotCommandSender(sender);
if (!sender.hasPermission(geyserCommand.getPermission())) {
String message = LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", commandSender.getLocale());

commandSender.sendMessage(ChatColor.RED + message);
return true;
}
getCommand(args[0]).execute(new SpigotCommandSender(sender), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (geyserCommand.isBedrockOnly()) {
session = getGeyserSession(commandSender);
if (session == null) {
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", commandSender.getLocale()));
return true;
}
}
geyserCommand.execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
return true;
}
} else {
getCommand("help").execute(new SpigotCommandSender(sender), new String[0]);
getCommand("help").execute(null, new SpigotCommandSender(sender), new String[0]);
return true;
}
return true;
Expand All @@ -71,8 +82,4 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}
return new ArrayList<>();
}

private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

package org.geysermc.platform.sponge.command;

import lombok.AllArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.ChatColor;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
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;
Expand All @@ -44,25 +46,36 @@
import java.util.List;
import java.util.Optional;

@AllArgsConstructor
public class GeyserSpongeCommandExecutor implements CommandCallable {
public class GeyserSpongeCommandExecutor extends CommandExecutor implements CommandCallable {

private GeyserConnector connector;
public GeyserSpongeCommandExecutor(GeyserConnector connector) {
super(connector);
}

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
public CommandResult process(CommandSource source, String arguments) {
String[] args = arguments.split(" ");
if (args.length > 0) {
if (getCommand(args[0]) != null) {
if (!source.hasPermission(getCommand(args[0]).getPermission())) {
GeyserCommand command = getCommand(args[0]);
if (command != null) {
CommandSender commandSender = new SpongeCommandSender(source);
if (!source.hasPermission(command.getPermission())) {
// Not ideal to use log here but we dont get a session
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
return CommandResult.success();
}
getCommand(args[0]).execute(new SpongeCommandSender(source), args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = getGeyserSession(commandSender);
if (session == null) {
source.sendMessage(Text.of(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.bedrock_only")));
return CommandResult.success();
}
}
getCommand(args[0]).execute(session, commandSender, args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0]);
}
} else {
getCommand("help").execute(new SpongeCommandSender(source), new String[0]);
getCommand("help").execute(null, new SpongeCommandSender(source), new String[0]);
}
return CommandResult.success();
}
Expand Down Expand Up @@ -94,8 +107,4 @@ public Optional<Text> getHelp(CommandSource source) {
public Text getUsage(CommandSource source) {
return Text.of("/geyser help");
}

private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,17 @@ public void setupInterface(GeyserStandaloneLogger geyserStandaloneLogger, Geyser
JMenuItem commandButton = hasSubCommands ? new JMenu(command.getValue().getName()) : new JMenuItem(command.getValue().getName());
commandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription());
if (!hasSubCommands) {
commandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ }));
commandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ }));
} else {
// Add a submenu that's the same name as the menu can't be pressed
JMenuItem otherCommandButton = new JMenuItem(command.getValue().getName());
otherCommandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription());
otherCommandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ }));
otherCommandButton.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{ }));
commandButton.add(otherCommandButton);
// Add a menu option for all possible subcommands
for (String subCommandName : command.getValue().getSubCommands()) {
JMenuItem item = new JMenuItem(subCommandName);
item.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{subCommandName}));
item.addActionListener(e -> command.getValue().execute(null, geyserStandaloneLogger, new String[]{subCommandName}));
commandButton.add(item);
}
}
Expand Down
11 changes: 9 additions & 2 deletions bootstrap/velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
<shadedPattern>org.geysermc.platform.velocity.shaded.dom4j</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>org.geysermc.platform.velocity.shaded.kyori</shadedPattern>
<pattern>net.kyori.adventure.text.serializer.gson.legacyimpl</pattern>
<shadedPattern>org.geysermc.platform.velocity.shaded.kyori.legacyimpl</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand All @@ -105,6 +105,13 @@
<exclude>io.netty:netty-codec:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
<!-- Exclude all Kyori dependencies except the legacy NBT serializer -->
<exclude>net.kyori:adventure-api:*</exclude>
<exclude>net.kyori:examination-api:*</exclude>
<exclude>net.kyori:examination-string:*</exclude>
<exclude>net.kyori:adventure-text-serializer-gson:*</exclude>
<exclude>net.kyori:adventure-text-serializer-legacy:*</exclude>
<exclude>net.kyori:adventure-nbt:*</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.AllArgsConstructor;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.geysermc.connector.common.ping.GeyserPingInfo;
import org.geysermc.connector.ping.IGeyserPingPassthrough;

import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
Expand All @@ -50,13 +49,13 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
ProxyPingEvent event;
try {
event = server.getEventManager().fire(new ProxyPingEvent(new GeyserInboundConnection(inetSocketAddress), ServerPing.builder()
.description(server.getConfiguration().getMotdComponent()).onlinePlayers(server.getPlayerCount())
.description(server.getConfiguration().getMotd()).onlinePlayers(server.getPlayerCount())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get();
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(
LegacyComponentSerializer.legacy().serialize(event.getPing().getDescription(), '§'),
LegacyComponentSerializer.legacy('§').serialize(event.getPing().getDescriptionComponent()),
new GeyserPingInfo.Players(
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getMax(),
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getOnline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,47 @@

package org.geysermc.platform.velocity.command;

import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import lombok.AllArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandExecutor;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.common.ChatColor;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.LanguageUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@AllArgsConstructor
public class GeyserVelocityCommandExecutor implements SimpleCommand {
public class GeyserVelocityCommandExecutor extends CommandExecutor implements SimpleCommand {

private final GeyserConnector connector;
public GeyserVelocityCommandExecutor(GeyserConnector connector) {
super(connector);
}

@Override
public void execute(Invocation invocation) {
if (invocation.arguments().length > 0) {
if (getCommand(invocation.arguments()[0]) != null) {
GeyserCommand command = getCommand(invocation.arguments()[0]);
if (command != null) {
CommandSender sender = new VelocityCommandSender(invocation.source());
if (!invocation.source().hasPermission(getCommand(invocation.arguments()[0]).getPermission())) {
CommandSender sender = new VelocityCommandSender(invocation.source());
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.permission_fail", sender.getLocale()));
return;
}
getCommand(invocation.arguments()[0]).execute(new VelocityCommandSender(invocation.source()), invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
GeyserSession session = null;
if (command.isBedrockOnly()) {
session = getGeyserSession(sender);
if (session == null) {
sender.sendMessage(ChatColor.RED + LanguageUtils.getPlayerLocaleString("geyser.bootstrap.command.bedrock_only", sender.getLocale()));
return;
}
}
command.execute(session, sender, invocation.arguments().length > 1 ? Arrays.copyOfRange(invocation.arguments(), 1, invocation.arguments().length) : new String[0]);
}
} else {
getCommand("help").execute(new VelocityCommandSender(invocation.source()), new String[0]);
getCommand("help").execute(null, new VelocityCommandSender(invocation.source()), new String[0]);
}
}

Expand All @@ -66,8 +76,4 @@ public List<String> suggest(Invocation invocation) {
}
return new ArrayList<>();
}

private GeyserCommand getCommand(String label) {
return connector.getCommandManager().getCommands().get(label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class GeyserConnector {
public static final String NAME = "Geyser";
public static final String GIT_VERSION = "DEV"; // A fallback for running in IDEs
public static final String VERSION = "DEV"; // A fallback for running in IDEs
public static final String MINECRAFT_VERSION = "1.16.4 - 1.16.5";

/**
* Oauth client ID for Microsoft authentication
Expand Down
Loading

0 comments on commit f7822e0

Please sign in to comment.