Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Dec 19, 2019
1 parent 80303a5 commit 3a03e23
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 100 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.andre601</groupId>
<artifactId>OneVersionRemake</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
64 changes: 42 additions & 22 deletions src/main/java/com/andre601/oneversionremake/OneVersionRemake.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import com.andre601.oneversionremake.listener.LoginListener;
import com.andre601.oneversionremake.listener.PingListener;
import com.andre601.oneversionremake.util.Versions;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
Expand All @@ -34,46 +36,57 @@
public class OneVersionRemake extends Plugin{
private File file = null;
private Configuration config;
private CommandSender sender;

@Override
public void onEnable(){
getLogger().info("Enabling OneVersionRemake v" + this.getDescription().getVersion());
getLogger().info("Attempting to load Config.yml...");
sender = getProxy().getConsole();
sendMessage(String.format(
"&fEnabling OneVersionRemake v%s...",
getDescription().getVersion()
));

sendMessage("&fAttempting to load config.yml...");
saveDefaultConfig();

try{
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
}catch(IOException ex){
getLogger().severe("Unable to load config! Listeners won't be loaded.");
sendMessage("&cUnable to load config! Plugin won't be enabled.");
return;
}
getLogger().info("Config.yml loaded!");
sendMessage("&fConfig.yml loaded!");

sendMessage("&fLoading Protocol version from the config...");

getLogger().info("Loading Protocol version...");
int protocol = config.getInt("Protocol.Version", -1);
/*
* We check if the config option "Protocol" is -1
* In such a case will we print this warning and return to not load the listeners, preventing possible issues.
*/
if(config.getInt("Protocol", -1) == -1){
getLogger().warning("================================================================================");
getLogger().warning("WARNING!");
getLogger().warning("The config option \"Protocol\" is set to -1!");
getLogger().warning("Because of that will OneVersionRemake not work properly.");
getLogger().warning("Listeners WON'T be loaded because of this!");
getLogger().warning("");
getLogger().warning("Please change the Protocol version to a supported one:");
getLogger().warning("https://github.com/andre601/OneVersionRemake/wiki/Supported-Protocols");
getLogger().warning("================================================================================");
if(protocol == -1){
sendMessage("&c================================================================================");
sendMessage("&cWARNING!");
sendMessage("&cThe config option \"Version\" is set to -1!");
sendMessage("&cThe plugin won't be fully loaded to prevent any issues.");
sendMessage("&c");
sendMessage("&cPlease change the Version to a supported one listed here:");
sendMessage("&chttps://github.com/Andre601/OneVersionRemake/wiki/Supported-Protocols");
sendMessage("&c================================================================================");
return;
}
getLogger().info("Loaded protocol " + config.getInt("Protocol") + " (MC " +
Versions.getFriendlyName(config.getInt("Protocol")) + ")!");

getLogger().info("Loading listeners...");
sendMessage(String.format(
"&fLoaded protocol %d (MC %s)!",
protocol,
Versions.getFriendlyName(protocol)
));

sendMessage("&fLoading listeners...");
this.getProxy().getPluginManager().registerListener(this, new PingListener(this));
this.getProxy().getPluginManager().registerListener(this, new LoginListener(this));
getLogger().info("Loaded listeners!");
getLogger().info("Plugin OneVersionRemake is ready to use!");
sendMessage("&fLoaded listeners!");

sendMessage("&aStartup complete! OneVersionRemake is ready to use!");
}

public Configuration getConfig(){
Expand All @@ -91,11 +104,18 @@ private void saveDefaultConfig(){
try(InputStream is = getResourceAsStream("config.yml")){
Files.copy(is, file.toPath());
}catch(IOException ex){
getLogger().warning("Couldn't create config.yml! Reason: " + ex.getMessage());
sendMessage(String.format(
"&cCould not create config.yml! Reason: %s",
ex.getMessage()
));
}
}
}

private void sendMessage(String text){
sender.sendMessage(new TextComponent(ChatColor.translateAlternateColorCodes('&', text)));
}

public TextComponent getText(List<String> list, int protocol){
String text = ChatColor.translateAlternateColorCodes('&', String.join("\n", list)
.replace("{version}", Versions.getFriendlyName(protocol)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@ public LoginListener(OneVersionRemake plugin){

@EventHandler(priority = EventPriority.LOWEST)
public void onLogin(PreLoginEvent event){
int protocol = plugin.getConfig().getInt("Protocol", -1);
List<String> message = plugin.getConfig().getStringList("KickMessage");
int protocol = plugin.getConfig().getInt("Protocol.Version", -1);
int clientProtocol = event.getConnection().getVersion();
List<String> message = plugin.getConfig().getStringList("Messages.Kick");
boolean isExact = plugin.getConfig().getBoolean("Protocol.Exact", false);

if(event.getConnection().getVersion() < protocol){
if(message.isEmpty())
message = Collections.singletonList("&cOutdated Client version! The Server is on {version}.");

event.setCancelReason(plugin.getText(message, protocol));
event.setCancelled(true);
if(isExact){
if(clientProtocol != protocol){
if(message.isEmpty())
message = Collections.singletonList("&cOutdated Client version! This network is on {version}.");

event.setCancelReason(plugin.getText(message, protocol));
event.setCancelled(true);
}
}else{
if(clientProtocol < protocol){
if(message.isEmpty())
message = Collections.singletonList("&cOutdated Client version! This network is on {version}.");

event.setCancelReason(plugin.getText(message, protocol));
event.setCancelled(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.andre601.oneversionremake.listener;

import com.andre601.oneversionremake.OneVersionRemake;
import com.andre601.oneversionremake.Versions;
import com.andre601.oneversionremake.util.Versions;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.event.ProxyPingEvent;
Expand All @@ -42,26 +42,45 @@ public PingListener(OneVersionRemake plugin){
public void onPing(ProxyPingEvent event){
ServerPing ping = event.getResponse();
ServerPing.Protocol protocol = ping.getVersion();
String protocolName = ChatColor.translateAlternateColorCodes(
'&', plugin.getConfig().getString("Messages.PlayerCount")
);
int protocolId = plugin.getConfig().getInt("Protocol.Version");
List<String> hoverList = plugin.getConfig().getStringList("Messages.Hover");
boolean isExact = plugin.getConfig().getBoolean("Protocol.Exact", false);

String protocolName = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("ProtocolName"));
int protocolId = plugin.getConfig().getInt("Protocol");
List<String> hoverList = plugin.getConfig().getStringList("HoverMessage");
if(isExact){
if(protocol.getProtocol() != protocolId){
protocol.setProtocol(protocolId);

if(!hoverList.isEmpty())
ping.getPlayers().setSample(new ServerPing.PlayerInfo[]{
new ServerPing.PlayerInfo(
ChatColor.translateAlternateColorCodes('&', String.join("\n", hoverList))
.replace("{version}", Versions.getFriendlyName(protocolId)),
UUID.fromString("0-0-0-0-0")
)
});

if(!protocolName.isEmpty())
protocol.setName(protocolName.replace("{version}", Versions.getFriendlyName(protocolId)));
}
}else{
if(protocol.getProtocol() < protocolId){
protocol.setProtocol(protocolId);

if(!hoverList.isEmpty())
ping.getPlayers().setSample(new ServerPing.PlayerInfo[]{
new ServerPing.PlayerInfo(
ChatColor.translateAlternateColorCodes('&', String.join("\n", hoverList))
.replace("{version}", Versions.getFriendlyName(protocolId)),
UUID.fromString("0-0-0-0-0")
)
});

if(protocol.getProtocol() < protocolId){
protocol.setProtocol(protocolId);

if(!hoverList.isEmpty()){
ping.getPlayers().setSample(new ServerPing.PlayerInfo[]{
new ServerPing.PlayerInfo(
ChatColor.translateAlternateColorCodes('&', String.join("\n", hoverList))
.replace("{version}", Versions.getFriendlyName(protocolId)),
UUID.fromString("0-0-0-0-0")
)
});
if(!protocolName.isEmpty())
protocol.setName(protocolName.replace("{version}", Versions.getFriendlyName(protocolId)));
}
if(!protocolName.isEmpty())
protocol.setName(protocolName.replace("{version}", Versions.getFriendlyName(protocolId)));
}

ping.setVersion(protocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.andre601.oneversionremake;
package com.andre601.oneversionremake.util;

/*
* This enum class contains all main (supported) versions to display.
* If, for example, ID 573 is used will {version} be changed to 1.15
*/
public enum Versions{
MC_1_15_1(575, "1.15.1"),
MC_1_15 (573, "1.15"),
MC_1_14_4(498, "1.14.4"),
MC_1_14_3(490, "1.14.3"),
Expand Down
121 changes: 70 additions & 51 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
#######################################################
# ____ _ ______ #
# / __ \ | / / __ \ OneVersionRemake #
# / / / / | / / /_/ / by Andre_601 #
# / /_/ /| |/ / _, _/ #
# \____/ |___/_/ |_| #
# #
# GitHub: #
# https://github.com/Andre601/OneVersionRemake #
# #
# Spigot: #
# https://spigotmc.org/resources/71727/ #
#######################################################
##########################################################
# ____ _ ______ #
# / __ \ | / / __ \ OneVersionRemake #
# / / / / | / / /_/ / by Andre_601 #
# / /_/ /| |/ / _, _/ #
# \____/ |___/_/ |_| #
# #
# GitHub: #
# https://github.com/Andre601/OneVersionRemake #
# #
# Spigot: #
# https://spigotmc.org/resources/71727/ #
##########################################################
#
# The protocol (version) number to decide what Minecraft version is running on the Network.
# Go to https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite for all available versions.
# Setting for what protocol version should be used and how OVR should handle joining players.
#
Protocol: -1
Protocol:
#
# Set if players need to have this exact protocol version to join the network.
# Setting this to false (default) will allow players with newer versions to join your network.
# For example may players with 1.15 join your network, if the set protocol corresponds to 1.14
#
Exact: false
#
# The protocol version that should be used.
# Depending on the above options would players need to either have the same version when joining, or at least a
# newer one.
#
# A list of all supported protocols for the plugin can be found here:
# https://github.com/andre601/OneVersionRemake/wiki/Supported-Protocols
#
Version: -1

#
# This changes the message that is usually shown when you ping the network with an unsupported (outdated) client.
# The default text is "[Proxy type] [versions]" e.g. "BungeeCord 1.8.x 1.9.x ..."
# The various messages you can change.
#
# Set this to an empty String ('') to not change the text.
#
# Placeholder:
# {version} -> The version used from the above set protocol (e.g. 1.14.4)
# See https://github.com/Andre601/OneVersionRemake/wiki/Supported-Protocols for a list of supported
# protocols.
#
ProtocolName: '&cUnsupported client! Please use {version}!'

#
# Set the kick message here that is used when the player joins with an unsupported version.
#
# Placeholder:
# {version} -> The version used from the above set protocol (e.g. 1.14.4)
# See https://github.com/Andre601/OneVersionRemake/wiki/Supported-Protocols for a list of supported
# protocols.
#
KickMessage:
- '&cYou are using an unsupported version of Minecraft!'
- '&cPlease change your version to {version} and try again.'

#
# Changes the players that are normally shown when hovering over the player count (x/x).
# Set to an empty list (HoverMessage: []) to disable.
#
# Placeholder:
# {version} -> The version used from the above set protocol (e.g. 1.14.4)
# See https://github.com/Andre601/OneVersionRemake/wiki/Supported-Protocols for a list of supported
# protocols.
#
HoverMessage:
- '&cYou are using an unsupported version of Minecraft!'
- '&cPlease change your version to {version} and try again.'
Messages:
#
# This message would be shown where usually the current player count is displayed.
# Color and formatting codes are supported.
#
# Set this to an empty String ('') to disable.
#
# Placeholder:
# {version} -> Displays the version a player needs to join
# The displayed version is set through the above Protocol number (e.g. 573 becomes 1.15)
#
# PlayerCount: '' # Uncomment this and comment out the below option, to disable this.
PlayerCount: '&cUnsupported client! Use {version} instead!'
#
# Message shown when the player gets kicked while using an unsupported version.
# Color and formatting codes are supported.
#
# Placeholder:
# {version} -> Displays the version a player needs to join
# The displayed version is set through the above Protocol number (e.g. 573 becomes 1.15)
#
Kick:
- '&cYou are using an unsupported version of Minecraft!'
- '&cPlease change your version to {version} and try again.'
#
# This text is shown when the cursor of the player hovers over the player count, which normally displays the current
# online players.
# Color and formatting codes are supported.
#
# Change this to "Hover: []" to disable
#
# Placeholder:
# {version} -> Displays the version a player needs to join
# The displayed version is set through the above Protocol number (e.g. 573 becomes 1.15)
#
# Hover: [] # uncomment this and comment out the below lines to disable this option.
Hover:
- '&cYou are using an unsupported version of Minecraft!'
- '&cPlease change your version to {version}.'

0 comments on commit 3a03e23

Please sign in to comment.