Skip to content

Commit

Permalink
Merge pull request #109 from Andre601/feature/move-versions.json
Browse files Browse the repository at this point in the history
Version 3.9.0
  • Loading branch information
Andre601 authored Oct 30, 2021
2 parents 4d9bc3c + b7f67ee commit e2357a9
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public void onLogin(PreLoginEvent event){
event.setCancelled(true);

if(plugin.getConfigHandler().getBoolean(true, "Protocol", "LogDenial")){
plugin.getProxyLogger().info(String.format(
"Denied login for Player %s with MC version %s (Protocol Version %d)",
plugin.getProxyLogger().infoFormat(
"Denied login for Player %s with MC version %s (Protocol version: %d)",
event.getConnection().getName(),
plugin.getProtocolVersionResolver().getFriendlyName(userProtocol),
userProtocol
));
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ public void info(String msg){
logger.log(Level.INFO, msg);
}

@Override
public void infoFormat(String msg, Object... args){
info(String.format(msg, args));
}

@Override
public void warn(String msg){
logger.log(Level.WARNING, msg);
}

@Override
public void warnFormat(String msg, Object... args){
warn(String.format(msg, args));
}

@Override
public void warn(String msg, Throwable throwable){
logger.log(Level.WARNING, msg, throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

public class OneVersionRemake{

private static final String DEF_VERSIONS_URL = "https://www.andre601.ch/oneversionremake/versions.json";

private final PluginCore pluginCore;
private final ConfigHandler configHandler;
private final CommandHandler commandHandler;
Expand Down Expand Up @@ -140,7 +142,9 @@ private void load(){
}

if(!getProtocolVersionResolver().hasFile() || getConfigHandler().getBoolean(true, "Settings", "UpdateVersions")){
if(getProtocolVersionResolver().loadFile()){
String url = getConfigHandler().getString(DEF_VERSIONS_URL, "Settings", "VersionsUrl");

if(getProtocolVersionResolver().loadFile(url)){
getProxyLogger().info("Updated versions.json!");
enable();
}else{
Expand Down Expand Up @@ -197,8 +201,8 @@ private void printBanner(){
getProxyLogger().info("/ /_/ /| |/ / _, _/");
getProxyLogger().info("\\____/ |___/_/ |_|");
getProxyLogger().info("");
getProxyLogger().info("OneVersionRemake v" + getVersion());
getProxyLogger().info("Platform: " + pluginCore.getProxyPlatform().getName() + " v" + pluginCore.getProxyVersion());
getProxyLogger().infoFormat("OneVersionRemake v%s", getVersion());
getProxyLogger().infoFormat("Platform: %s v%s", pluginCore.getProxyPlatform().getName(), pluginCore.getProxyVersion());
getProxyLogger().info("");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public interface ProxyLogger{

void info(String msg);

void infoFormat(String msg, Object... args);

void warn(String msg);

void warnFormat(String msg, Object... args);

void warn(String msg, Throwable throwable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public boolean hasFile(){
return file.toFile().exists();
}

public boolean loadFile(){
public boolean loadFile(String url){
if(!path.toFile().isDirectory() && !path.toFile().mkdirs()){
logger.warn("Could not create folder for plugin!");
return false;
}

return updateCache();
return updateCache(url);
}

public boolean setupConfigurate(){
Expand All @@ -81,8 +81,7 @@ public boolean setupConfigurate(){
return true;
}

public boolean updateCache(){
String url = "https://raw.githubusercontent.com/Andre601/OneVersionRemake/master/versions.json";
public boolean updateCache(String url){
Request request = new Request.Builder()
.url(url)
.addHeader("User-Agent", "OneVersionRemake")
Expand All @@ -97,30 +96,36 @@ public boolean updateCache(){
));
switch(response.code()){
case 404:
logger.warn(String.format(
"The requested site (%s) does not exist. Please report this to the developer on Discord!",
logger.warnFormat(
"The requested url (%s) does not exist. Please check that the URL is valid!",
url
));
);
break;

case 429:
logger.warn("Encountered a Rate Limit. Please delay any future Proxy Restarts to avoid this.");
break;

case 500:
logger.warn("The Site (GitHub.com) encountered an error when handling the request. Try again later...");
logger.warnFormat(
"The Website (%s) encountered an error when handling the request. Try again later...",
url
);
break;

default:
logger.warn("This is an unknown error by the plugin! Please report this to the developer on Discord!");
logger.warnFormat(
"The plugin received a not known HTTPS status code %d. Please report this to the Developer!",
response.code()
);
break;
}
return false;
}

ResponseBody body = response.body();
if(body == null){
logger.warn("GitHub.com returned an invalid/empty body!");
logger.warnFormat("Received empty/null body from '%s'", url);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public enum ProxyPlatform{
WATERFALL ("Waterfall"),

// Velocity
VELOCITY ("Velocity 3"),
VELOCITY_LEGACY("Velocity");
VELOCITY ("Velocity");

private final String name;

Expand Down
137 changes: 72 additions & 65 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,95 +15,102 @@
#
# Created with Version ${project.version}
#
# +---------------------------------------------------------------------------+
# | Main Settings |
# | |
# | Main Settings for the plugin. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#settings |
# +---------------------------------------------------------------------------+
# +----------------------------------------------------------------------------+
# | Main Settings |
# | |
# | Main Settings for the plugin. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#settings |
# +----------------------------------------------------------------------------+
Settings:
# +-------------------------------------------------------------------------+
# | Whether OneVersionRemake should download the latest versions.json on |
# | Proxy (re)start. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#updateversions |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Whether OneVersionRemake should download the latest versions.json on |
# | Proxy (re)start. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#updateversions |
# +--------------------------------------------------------------------------+
UpdateVersions: true
# +--------------------------------------------------------------------------+
# | URL pointing to the file that contains the different Protocols OVR |
# | should use. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#versionsurl |
# +--------------------------------------------------------------------------+
VersionsUrl: 'https://www.andre601.ch/oneversionremake/versions.json'

# +---------------------------------------------------------------------------+
# | Protocol Settings |
# | |
# | Protocol Settings for the plugin. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#protocol |
# +---------------------------------------------------------------------------+
# +----------------------------------------------------------------------------+
# | Protocol Settings |
# | |
# | Protocol Settings for the plugin. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#protocol |
# +----------------------------------------------------------------------------+
Protocol:
# +-------------------------------------------------------------------------+
# | The Protocol Versions that should be allowed to join the network. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#versions |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | The Protocol Versions that should be allowed to join the network. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#versions |
# +--------------------------------------------------------------------------+
Versions: []

# +-------------------------------------------------------------------------+
# | Should OneVersionRemake log denied Logins in the console? |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#logdenial |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Should OneVersionRemake log denied Logins in the console? |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#logdenial |
# +--------------------------------------------------------------------------+
LogDenial: true

# +-------------------------------------------------------------------------+
# | Should the {version} placeholder only show major MC versions? |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#majoronly |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Should the {version} placeholder only show major MC versions? |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#majoronly |
# +--------------------------------------------------------------------------+
MajorOnly: false

# +---------------------------------------------------------------------------+
# | Messages |
# | |
# | This section contains all the messages that you can configure. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#messages |
# +---------------------------------------------------------------------------+
# +----------------------------------------------------------------------------+
# | Messages |
# | |
# | This section contains all the messages that you can configure. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#messages |
# +----------------------------------------------------------------------------+
Messages:
# +-------------------------------------------------------------------------+
# | Message to display instead of the Player count (<online>/<max>) next to |
# | the ping icon. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#playercount |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Message to display instead of the Player count (<online>/<max>) next to |
# | the ping icon. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#playercount |
# +--------------------------------------------------------------------------+
PlayerCount: '<red>Minecraft {version}'

# +-------------------------------------------------------------------------+
# | Reason to display, when the player gets kicked for using a unsupported |
# | Minecraft Version. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#kick |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Reason to display, when the player gets kicked for using a unsupported |
# | Minecraft Version. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#kick |
# +--------------------------------------------------------------------------+
Kick:
- '<red>You are using an unsupported version of Minecraft ({userVersion})!'
- '<red>This server supports the following Versions:'
- '<gray>{version}'
- ''
- '<red>Please change your Version and try again.'

# +-------------------------------------------------------------------------+
# | Message to show when the player hovers over the player count with his |
# | cursor. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#hover |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Message to show when the player hovers over the player count with his |
# | cursor. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#hover |
# +--------------------------------------------------------------------------+
Hover:
- '<red>You are using an unsupported version of Minecraft ({userVersion})!'
- '<red>Please change your version to {version}.'

# +-------------------------------------------------------------------------+
# | Message to display in the MOTD of the server. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#motd |
# +-------------------------------------------------------------------------+
# +--------------------------------------------------------------------------+
# | Message to display in the MOTD of the server. |
# | |
# | https://github.com/Andre601/OneVersionRemake/wiki/Config#motd |
# +--------------------------------------------------------------------------+
Motd:
- '<red>Unsupported Minecraft Version {userVersion}'
- '<red>Please use <gray>{version}</gray>.'
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<plugin.version>3.8.3</plugin.version>
<plugin.version>3.9.0</plugin.version>
<plugin.description>Only allow specific client versions on your Network.</plugin.description>

<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void onPreLogin(PreLoginEvent event){
event.setResult(result);

if(plugin.getConfigHandler().getBoolean(true, "Protocol", "LogDenial")){
plugin.getProxyLogger().info(String.format(
"Denied login for Player %s with MC version %s (Protocol Version %d)",
plugin.getProxyLogger().infoFormat(
"Denied login for Player %s with MC version %s (Protocol version: %d)",
event.getUsername(),
plugin.getProtocolVersionResolver().getFriendlyName(userProtocol),
userProtocol
));
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ public void info(String msg){
logger.info(msg);
}

@Override
public void infoFormat(String msg, Object... args){
info(String.format(msg, args));
}

@Override
public void warn(String msg){
logger.warn(msg);
}

@Override
public void warnFormat(String msg, Object... args){
warn(String.format(msg, args));
}

@Override
public void warn(String msg, Throwable throwable){
logger.warn(msg, throwable);
Expand Down
Loading

0 comments on commit e2357a9

Please sign in to comment.