Search in sources :

Example 11 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class GameServerTest method setUp.

@BeforeEach
public void setUp() throws IllegalAccessException {
    GlowServer.logger.addHandler(handler);
    glowServer = mock(GlowServer.class, Answers.RETURNS_SMART_NULLS);
    CountDownLatch latch = new CountDownLatch(1);
    ProtocolProvider protocolProvider = new ProtocolProvider(mock(HandshakeProtocol.class), mock(StatusProtocol.class), mock(LoginProtocol.class), mock(PlayProtocol.class));
    gameServer = new GameServer(glowServer, protocolProvider, latch);
    latch.countDown();
}
Also used : StatusProtocol(net.glowstone.net.protocol.StatusProtocol) HandshakeProtocol(net.glowstone.net.protocol.HandshakeProtocol) ProtocolProvider(net.glowstone.net.protocol.ProtocolProvider) GlowServer(net.glowstone.GlowServer) CountDownLatch(java.util.concurrent.CountDownLatch) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) LoginProtocol(net.glowstone.net.protocol.LoginProtocol) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class StatusRequestHandler method handle.

@Override
@SuppressWarnings("unchecked")
public void handle(GlowSession session, StatusRequestMessage message) {
    // create and call the event
    GlowServer server = session.getServer();
    StatusEvent event = new StatusEvent(new GlowStatusClient(session), server.getMotd(), server.getOnlinePlayers().size(), server.getMaxPlayers(), GlowServer.GAME_VERSION, GlowServer.PROTOCOL_VERSION, server.getServerIcon());
    event.serverType = server.getServerType();
    event.clientModsAllowed = server.getAllowClientMods();
    choosePlayerSample(server, event);
    EventFactory.getInstance().callEvent(event);
    // Disconnect immediately if event is cancelled
    if (event.isCancelled()) {
        session.getChannel().close();
        return;
    }
    // build the json
    JSONObject json = new JSONObject();
    JSONObject version = new JSONObject();
    version.put("name", event.getVersion());
    version.put("protocol", event.getProtocolVersion());
    json.put("version", version);
    if (!event.shouldHidePlayers()) {
        JSONObject players = new JSONObject();
        players.put("max", event.getMaxPlayers());
        players.put("online", event.getNumPlayers());
        JSONArray playersSample = new JSONArray();
        for (PlayerProfile profile : event.getPlayerSample()) {
            JSONObject p = new JSONObject();
            p.put("name", Strings.nullToEmpty(profile.getName()));
            p.put("id", UuidUtils.toString(MoreObjects.firstNonNull(profile.getId(), BLANK_UUID)));
            playersSample.add(p);
        }
        players.put("sample", playersSample);
        json.put("players", players);
    }
    JSONObject description = new JSONObject();
    description.put("text", event.getMotd());
    json.put("description", description);
    if (event.getServerIcon() != null) {
        json.put("favicon", event.getServerIcon().getData());
    }
    // Mod list must be included but can be empty
    // TODO: support adding GS-ported Forge server-side mods?
    JSONArray modList = new JSONArray();
    JSONObject modinfo = new JSONObject();
    modinfo.put("type", event.serverType);
    modinfo.put("modList", modList);
    if (!event.clientModsAllowed) {
        modinfo.put("clientModsAllowed", false);
    }
    json.put("modinfo", modinfo);
    // send it off
    session.send(new StatusResponseMessage(json));
}
Also used : JSONObject(org.json.simple.JSONObject) PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) JSONArray(org.json.simple.JSONArray) StatusResponseMessage(net.glowstone.net.message.status.StatusResponseMessage) GlowServer(net.glowstone.GlowServer) GlowStatusClient(net.glowstone.net.GlowStatusClient)

Example 13 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class BanCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    final ResourceBundle resourceBundle = commandMessages.getResourceBundle();
    if (args.length > 0) {
        String name = args[0];
        GlowServer server = (GlowServer) ServerProvider.getServer();
        // asynchronously lookup player
        server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
            if (ex != null) {
                new LocalizedStringImpl("ban.exception", resourceBundle).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
                return;
            }
            if (player == null) {
                commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
                return;
            }
            if (args.length == 1) {
                Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), null, null, null);
            } else {
                StringBuilder reason = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                    reason.append(args[i]).append(" ");
                }
                Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), null, null);
            }
            new LocalizedStringImpl("ban.done", resourceBundle).send(sender, player.getName());
        });
        // todo: asynchronous command callbacks?
        return true;
    }
    sendUsageMessage(sender, commandMessages);
    return false;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ResourceBundle(java.util.ResourceBundle) GlowServer(net.glowstone.GlowServer)

Example 14 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class WhitelistCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length == 0) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String subcommand = args[0];
    GlowServer server = (GlowServer) ServerProvider.getServer();
    if (subcommand.equals("on")) {
        sender.getServer().setWhitelist(true);
        sender.sendMessage("Turned on the whitelist");
        return true;
    }
    if (subcommand.equals("off")) {
        sender.getServer().setWhitelist(false);
        sender.sendMessage("Turned off the whitelist");
        return true;
    }
    if (subcommand.equals("list")) {
        Set<OfflinePlayer> whitelistedPlayers = sender.getServer().getWhitelistedPlayers();
        String[] names = new String[whitelistedPlayers.size()];
        int i = 0;
        for (OfflinePlayer p : whitelistedPlayers) {
            names[i++] = p.getName();
        }
        sender.sendMessage("There are " + names.length + " whitelisted players:");
        sender.sendMessage(commandMessages.joinList(names));
        return true;
    }
    if (subcommand.equals("add")) {
        if (args.length != 2) {
            sender.sendMessage(ChatColor.RED + "Usage: /whitelist add <player>");
            return false;
        }
        String name = args[1];
        server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
            if (ex != null) {
                sender.sendMessage(ChatColor.RED + "Failed to add " + name + " to the whitelist: " + ex.getMessage());
                ex.printStackTrace();
                return;
            }
            player.setWhitelisted(true);
            sender.sendMessage("Added " + player.getName() + " to the whitelist");
        });
        return true;
    }
    if (subcommand.equals("remove")) {
        if (args.length != 2) {
            sender.sendMessage(ChatColor.RED + "Usage: /whitelist remove <player>");
            return false;
        }
        String name = args[1];
        server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
            if (ex != null) {
                sender.sendMessage(ChatColor.RED + "Failed to remove " + name + " from the whitelist: " + ex.getMessage());
                ex.printStackTrace();
                return;
            }
            player.setWhitelisted(false);
            sender.sendMessage("Removed " + player.getName() + " from the whitelist");
        });
        return true;
    }
    if (subcommand.equals("reload")) {
        sender.getServer().reloadWhitelist();
        sender.sendMessage("Reloaded the whitelist");
        return true;
    }
    sendUsageMessage(sender, commandMessages);
    return false;
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) GlowServer(net.glowstone.GlowServer)

Example 15 with GlowServer

use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.

the class OpCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length != 1) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String name = args[0];
    GlowServer server = (GlowServer) ServerProvider.getServer();
    // asynchronously lookup player
    server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
        if (ex != null) {
            new LocalizedStringImpl("op.failed", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
            ConsoleMessages.Error.Command.OP_FAILED.log(ex, name);
            return;
        }
        player.setOp(true);
        new LocalizedStringImpl("op.done", commandMessages.getResourceBundle()).send(sender, name);
    });
    // todo: asynchronous command callbacks?
    return true;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowServer(net.glowstone.GlowServer)

Aggregations

GlowServer (net.glowstone.GlowServer)29 BlockDataManager (net.glowstone.block.data.BlockDataManager)8 Vector (org.bukkit.util.Vector)5 RecipeManager (net.glowstone.datapack.RecipeManager)4 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)4 ByteBuf (io.netty.buffer.ByteBuf)3 GlowChunk (net.glowstone.chunk.GlowChunk)3 FuelManager (net.glowstone.datapack.FuelManager)3 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)3 Material (org.bukkit.Material)3 ItemStack (org.bukkit.inventory.ItemStack)3 DatagramPacket (io.netty.channel.socket.DatagramPacket)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 HandshakeProtocol (net.glowstone.net.protocol.HandshakeProtocol)2 LoginProtocol (net.glowstone.net.protocol.LoginProtocol)2 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)2 ProtocolProvider (net.glowstone.net.protocol.ProtocolProvider)2 StatusProtocol (net.glowstone.net.protocol.StatusProtocol)2