diff --git a/SECURITY.md b/SECURITY.md index 878b5f3..c3f2186 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -9,10 +9,10 @@ Using any older version will get your support request ignored. ### Platforms -As of writing this (29th of April, 2022) are only the following platforms officially supported: +As of writing this (29th of April 2022) are only the following platforms officially supported: | Platform | Supported Version | -| ------------- | ------------------------------------ | +|---------------|--------------------------------------| | BungeeCord | Any 1.18.x builds | | Waterfall[^1] | Any 1.18.x builds | | FlameCord[^2] | Any 1.18.x builds | diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java index e9b98e5..149bf45 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java @@ -136,8 +136,8 @@ public String getProxyVersion(){ return String.format("%s (Build #%s)", version[2], version[4]); } - public ServerPing.PlayerInfo[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ - return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly) + public ServerPing.PlayerInfo[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ + return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly, blacklist) .toArray(new ServerPing.PlayerInfo[0]); } diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java index a774190..4a1d93d 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java @@ -43,16 +43,18 @@ public void onLogin(PreLoginEvent event){ List kickMessage = plugin.getConfigHandler().getStringList(false, "Messages", "Kick"); boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly"); + boolean blacklist = plugin.getConfigHandler().getBoolean(false, "Protocol", "Blacklist"); + int userProtocol = event.getConnection().getVersion(); if(serverProtocols.isEmpty()) return; - if(!serverProtocols.contains(userProtocol)){ + if((blacklist && serverProtocols.contains(userProtocol)) || (!blacklist && !serverProtocols.contains(userProtocol))){ if(kickMessage.isEmpty()) kickMessage = Collections.singletonList("This Server is running MC {version}! Please change your client version."); event.setCancelReason(BungeeComponentSerializer.get().serialize( - plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly) + plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly, blacklist) )); event.setCancelled(true); diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java index cb56f6d..2d8fabb 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java @@ -57,23 +57,24 @@ public void onProxyPing(ProxyPingEvent event){ serverProtocols.sort(Comparator.reverseOrder()); boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly"); + boolean blacklist = plugin.getConfigHandler().getBoolean(false, "Protocol", "Blacklist"); String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount"); List motd = plugin.getConfigHandler().getStringList(true, "Messages", "Motd"); - if(!serverProtocols.contains(userProtocol)){ + if((blacklist && serverProtocols.contains(userProtocol)) || (!blacklist && !serverProtocols.contains(userProtocol))){ if(!hoverMessage.isEmpty()){ - ServerPing.PlayerInfo[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly); + ServerPing.PlayerInfo[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly, blacklist); if(players != null) ping.getPlayers().setSample(players); } if(!playerCount.isEmpty()) - protocol.setName(plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly)); + protocol.setName(plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly, blacklist)); if(!motd.isEmpty()){ TextComponent component = new TextComponent(BungeeComponentSerializer.get().serialize( - plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly) + plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly, blacklist) )); ping.setDescriptionComponent(component); @@ -81,7 +82,7 @@ public void onProxyPing(ProxyPingEvent event){ ping.setFavicon(ping.getFaviconObject()); - protocol.setProtocol(serverProtocols.get(0)); + protocol.setProtocol(-1); ping.setVersion(protocol); event.setResponse(ping); diff --git a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java index c9e648d..b4ba162 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java @@ -113,7 +113,7 @@ public Map> getPieMap(){ return map; } - public List getPlayers(Class clazz, List lines, List serverProtocols, int userProtocol, boolean majorOnly){ + public List getPlayers(Class clazz, List lines, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ try{ final List players = new ArrayList<>(lines.size()); final Constructor constructor = clazz.getDeclaredConstructor(String.class, UUID.class); @@ -121,7 +121,7 @@ public List getPlayers(Class clazz, List lines, List for(String line : lines){ players.add(constructor.newInstance( - getComponentParser().toString(line, serverProtocols, userProtocol, majorOnly), UUID.randomUUID() + getComponentParser().toString(line, serverProtocols, userProtocol, majorOnly, blacklist), UUID.randomUUID() )); } @@ -184,7 +184,7 @@ private void enable(){ versionsSet = false; }else{ getProxyLogger().info("Loaded the following Protocol Version(s):"); - getProxyLogger().info(getProtocolVersionResolver().getVersions().getFriendlyNames(protocols, false)); + getProxyLogger().info(getProtocolVersionResolver().getVersions().getFriendlyNames(protocols, false, false)); versionsSet = true; } diff --git a/core/src/main/java/com/andre601/oneversionremake/core/Parser.java b/core/src/main/java/com/andre601/oneversionremake/core/Parser.java index 0cde8c0..eab797f 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/Parser.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/Parser.java @@ -32,22 +32,22 @@ public Parser(OneVersionRemake core){ this.core = core; } - public Component toComponent(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ - return toComponent(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly)); + public Component toComponent(List lines, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ + return toComponent(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly, blacklist)); } public Component toComponent(String text){ return MiniMessage.miniMessage().deserialize(text); } - public String toString(String text, List serverProtocols, int userProtocol, boolean majorOnly){ + public String toString(String text, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ Component component = MiniMessage.miniMessage() - .deserialize(parse(text, serverProtocols, userProtocol, majorOnly)); + .deserialize(parse(text, serverProtocols, userProtocol, majorOnly, blacklist)); return LegacyComponentSerializer.legacySection().serialize(component); } - private String parse(String text, List serverProtocols, int userProtocol, boolean majorOnly){ - return text.replace("{version}", core.getProtocolVersionResolver().getVersions().getFriendlyNames(serverProtocols, majorOnly)) + private String parse(String text, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ + return text.replace("{version}", core.getProtocolVersionResolver().getVersions().getFriendlyNames(serverProtocols, majorOnly, blacklist)) .replace("{userVersion}", core.getProtocolVersionResolver().getVersions().getFriendlyName(userProtocol)); } diff --git a/core/src/main/java/com/andre601/oneversionremake/core/commands/CommandHandler.java b/core/src/main/java/com/andre601/oneversionremake/core/commands/CommandHandler.java index 960e997..2a0453a 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/commands/CommandHandler.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/commands/CommandHandler.java @@ -66,7 +66,7 @@ public void handle(CmdSender sender, String[] args){ if(protocols.isEmpty()){ sender.sendMsg(NamedTextColor.RED, "None"); }else{ - sender.sendMsg(NamedTextColor.GRAY, core.getProtocolVersionResolver().getVersions().getFriendlyNames(protocols, false)); + sender.sendMsg(NamedTextColor.GRAY, core.getProtocolVersionResolver().getVersions().getFriendlyNames(protocols, false, false)); } sender.sendMsg(); diff --git a/core/src/main/java/com/andre601/oneversionremake/core/proxy/VersionsFile.java b/core/src/main/java/com/andre601/oneversionremake/core/proxy/VersionsFile.java index 0040024..bdca25b 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/proxy/VersionsFile.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/proxy/VersionsFile.java @@ -20,6 +20,7 @@ import com.google.gson.annotations.SerializedName; +import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -36,9 +37,18 @@ public int getFileVersion(){ return fileVersion; } - public String getFriendlyNames(List protocols, boolean majorOnly){ - Stream stream = protocols.stream() - .sorted(Comparator.reverseOrder()); + public String getFriendlyNames(List protocols, boolean majorOnly, boolean blacklist){ + Stream stream; + + if(blacklist){ + stream = Arrays.stream(protocolInfos) + .map(ProtocolInfo::getProtocol) + .filter(protocol -> !protocols.contains(protocol)) + .sorted(Comparator.reverseOrder()); + }else{ + stream = protocols.stream() + .sorted(Comparator.reverseOrder()); + } if(majorOnly){ return stream.map(this::getMajor) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index dacc569..59b3153 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -66,6 +66,13 @@ Protocol: # | https://github.com/Andre601/OneVersionRemake/wiki/Config#majoronly | # +--------------------------------------------------------------------------+ MajorOnly: false + # +--------------------------------------------------------------------------+ + # | Should the list of protocols be treated as a Blacklist? | + # | If set to true, only protocol versions NOT in the list will be allowed. | + # | | + # | https://github.com/Andre601/OneVersionRemake/wiki/Config#blacklist | + # +--------------------------------------------------------------------------+ + Blacklist: false # +----------------------------------------------------------------------------+ # | Messages | diff --git a/pom.xml b/pom.xml index 7e41250..d0f7041 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 - 3.11.3 + 3.12.0 Only allow specific client versions on your Network. 11 diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java index 6048e11..67e2f21 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java @@ -143,8 +143,8 @@ public ProxyServer getProxy(){ return proxy; } - public ServerPing.SamplePlayer[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ - return core.getPlayers(ServerPing.SamplePlayer.class, lines, serverProtocols, userProtocol, majorOnly) + public ServerPing.SamplePlayer[] getPlayers(List lines, List serverProtocols, int userProtocol, boolean majorOnly, boolean blacklist){ + return core.getPlayers(ServerPing.SamplePlayer.class, lines, serverProtocols, userProtocol, majorOnly, blacklist) .toArray(new ServerPing.SamplePlayer[0]); } } diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java index f12b158..60ccfc3 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java @@ -41,16 +41,18 @@ public void onPreLogin(PreLoginEvent event){ List kickMessage = plugin.getConfigHandler().getStringList(false, "Messages", "Kick"); boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly"); + boolean blacklist = plugin.getConfigHandler().getBoolean(false, "Protocol", "Blacklist"); + int userProtocol = event.getConnection().getProtocolVersion().getProtocol(); if(serverProtocols.isEmpty()) return; - if(!serverProtocols.contains(userProtocol)){ + if((blacklist && serverProtocols.contains(userProtocol)) || (!blacklist && !serverProtocols.contains(userProtocol))){ if(kickMessage.isEmpty()) kickMessage = Collections.singletonList("&cThis Server is running MC {version}! Please change your client version."); PreLoginEvent.PreLoginComponentResult result = PreLoginEvent.PreLoginComponentResult - .denied(plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly)); + .denied(plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly, blacklist)); event.setResult(result); diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java index 804d75d..0fb92ae 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java @@ -53,28 +53,29 @@ public void onProxyPing(ProxyPingEvent event){ serverProtocols.sort(Comparator.reverseOrder()); boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly"); + boolean blacklist = plugin.getConfigHandler().getBoolean(false, "Protocol", "Blacklist"); String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount"); List motd = plugin.getConfigHandler().getStringList(true, "Messages", "Motd"); List hoverMessage = plugin.getConfigHandler().getStringList(false, "Messages", "Hover"); - if(!serverProtocols.contains(userProtocol)){ + if((blacklist && serverProtocols.contains(userProtocol)) || (!blacklist && !serverProtocols.contains(userProtocol))){ ServerPing.Builder builder = ping.asBuilder(); if(!hoverMessage.isEmpty()){ - ServerPing.SamplePlayer[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly); + ServerPing.SamplePlayer[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly, blacklist); if(players != null) builder.samplePlayers(players); } if(!playerCount.isEmpty()){ - playerCount = plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly); + playerCount = plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly, blacklist); - builder.version(new ServerPing.Version(serverProtocols.get(0), playerCount)); + builder.version(new ServerPing.Version(-1, playerCount)); } if(!motd.isEmpty()){ - builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly)); + builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly, blacklist)); } event.setPing(builder.build()); diff --git a/versions.json b/versions.json index b4eb643..758a041 100644 --- a/versions.json +++ b/versions.json @@ -1,8 +1,8 @@ { "note": [ "This file is no longer updated and used by the latest OneVersionRemake version.", - "The latest version can be found at https://github.com/Andre601/andre601.github.io under", - "/site/oneversionremake/protocol_versions.json", + "The latest version can be found at https://codeberg.org/Andre601/website under", + "/docs/oneversionremake/protocol_versions.json", "", "This file will no longer receive updates." ], diff --git a/wiki/Config.md b/wiki/Config.md index c3a76aa..eb56592 100644 --- a/wiki/Config.md +++ b/wiki/Config.md @@ -26,6 +26,7 @@ This page tries to explain each option as detailed as possible! - [Versions](#versions) - [LogDenial](#logdenial) - [MajorOnly](#majoronly) + - [Blacklist](#blacklist) - [Messages](#messages) - [Formatting](#formatting) - [Basic Formatting](#basic-formatting) @@ -136,6 +137,15 @@ When this option is set to true, will the `{version}` placeholder only display t 1.14.x, 1.15.x, 1.16.x ``` +### Blacklist +> **Type**: `Boolean` +> **Default**: +> ```yaml +> Blacklist: false +> ``` + +When this option is set to true, will OneVersionRemake treat the [Protocol List](#versions) as a blacklist, meaning only players **not** having any of the listed versions may join. + ## Messages The `Messages` section allows you to define the different messages displayed when a player either joins or views a server with an unsupported version. @@ -148,7 +158,7 @@ Depending on the config option are either only [basic](#basic-formatting) or [ad ##### Colors | Option 1 | Option 2 | - | ----------------------------------------------- | ----------------------------------------------------------- | + |-------------------------------------------------|-------------------------------------------------------------| | [``][colors] | [``][colors] | | [``][colors] | [``][colors] | | [``][colors] | [``][colors] | @@ -169,7 +179,7 @@ Depending on the config option are either only [basic](#basic-formatting) or [ad ##### Formatting | Name | Alias | - | ------------------------------- | --------------------- | + |---------------------------------|-----------------------| | [``][formatting] | [``][formatting] | | [``][formatting] | [``][formatting] | | | [``][formatting] | @@ -182,7 +192,7 @@ Depending on the config option are either only [basic](#basic-formatting) or [ad Includes [Basic Formatting](#basic-formatting) but also some more advanced options: | Option | Format | - | -------------- | ---------------------------------------------- | + |----------------|------------------------------------------------| | RGB Colors | [`<#rrggbb>`][colors] | | | [``][colorsVerbose] | | Gradients* | [``][gradient] | diff --git a/wiki/Supported-Protocols.md b/wiki/Supported-Protocols.md index 739b988..5f69253 100644 --- a/wiki/Supported-Protocols.md +++ b/wiki/Supported-Protocols.md @@ -1,5 +1,5 @@ -[protocol_versions.json source]: https://github.com/Andre601/andre601.github.io/blob/development/site/oneversionremake/protocol_versions.json -[versions.json source]: https://github.com/Andre601/andre601.github.io/blob/development/site/oneversionremake/versions.json +[protocol_versions.json source]: https://codeberg.org/Andre601/website/src/branch/main/docs/oneversionremake/protocol_versions.json +[versions.json source]: https://codeberg.org/Andre601/website/src/branch/main/docs/oneversionremake/versions.json [old versions.json source]: https://github.com/Andre601/OneVersionRemake/blob/master/versions.json Due to BungeeCord not providing a way to obtain the MC version from a protocol does OneVersionRemake utilize a separate JSON file containing the MC versions and their major versions for the `{version}` and `{userVersion}` placeholders. @@ -19,36 +19,41 @@ Here is a complete list of all currently supported protocol versions based on th | Protocol: | Displayed version: | |:---------:|:------------------:| -| 760 | 1.19.2 | -| 759 | 1.19 | -| 758 | 1.18.2 | -| 757 | 1.18.1 | -| 756 | 1.17.1 | -| 755 | 1.17 | -| 754 | 1.16.5 | -| 753 | 1.16.3 | -| 751 | 1.16.2 | -| 736 | 1.16.1 | -| 735 | 1.16 | -| 578 | 1.15.2 | -| 575 | 1.15.1 | -| 573 | 1.15 | -| 498 | 1.14.4 | -| 490 | 1.14.3 | -| 485 | 1.14.2 | -| 480 | 1.14.1 | -| 477 | 1.14 | -| 404 | 1.13.2 | -| 401 | 1.13.1 | -| 393 | 1.13 | -| 340 | 1.12.2 | -| 338 | 1.12.1 | -| 335 | 1.12 | -| 316 | 1.11.2 | -| 315 | 1.11 | -| 210 | 1.10.2 | -| 110 | 1.9.4 | -| 109 | 1.9.2 | -| 108 | 1.9.1 | -| 107 | 1.9 | -| 47 | 1.8.9 | +| 765 | 1.20.4 | +| 764 | 1.20.2 | +| 763 | 1.20.1 | +| 762 | 1.19.4 | +| 761 | 1.19.3 | +| 760 | 1.19.2 | +| 759 | 1.19 | +| 758 | 1.18.2 | +| 757 | 1.18.1 | +| 756 | 1.17.1 | +| 755 | 1.17 | +| 754 | 1.16.5 | +| 753 | 1.16.3 | +| 751 | 1.16.2 | +| 736 | 1.16.1 | +| 735 | 1.16 | +| 578 | 1.15.2 | +| 575 | 1.15.1 | +| 573 | 1.15 | +| 498 | 1.14.4 | +| 490 | 1.14.3 | +| 485 | 1.14.2 | +| 480 | 1.14.1 | +| 477 | 1.14 | +| 404 | 1.13.2 | +| 401 | 1.13.1 | +| 393 | 1.13 | +| 340 | 1.12.2 | +| 338 | 1.12.1 | +| 335 | 1.12 | +| 316 | 1.11.2 | +| 315 | 1.11 | +| 210 | 1.10.2 | +| 110 | 1.9.4 | +| 109 | 1.9.2 | +| 108 | 1.9.1 | +| 107 | 1.9 | +| 47 | 1.8.9 |