From a0ea79c73306b792b0fc40ae0a1039c65ff8346c Mon Sep 17 00:00:00 2001
From: Andre601 <11576465+Andre601@users.noreply.github.com>
Date: Mon, 15 Jun 2020 03:06:05 +0200
Subject: [PATCH] Version 1.4.0
~ Minor changes to console logs
~ Added LogDenial config option to log denied logins
---
pom.xml | 2 +-
.../oneversionremake/OneVersionRemake.java | 68 ++++++++++---------
.../listener/LoginListener.java | 20 +++++-
.../listener/PingListener.java | 3 +-
.../oneversionremake/util/Versions.java | 4 +-
src/main/resources/config.yml | 5 ++
6 files changed, 64 insertions(+), 38 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9f67922..07cbc07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.andre601
OneVersionRemake
- 1.3.0
+ 1.4.0
UTF-8
diff --git a/src/main/java/com/andre601/oneversionremake/OneVersionRemake.java b/src/main/java/com/andre601/oneversionremake/OneVersionRemake.java
index cdae4eb..336d13c 100644
--- a/src/main/java/com/andre601/oneversionremake/OneVersionRemake.java
+++ b/src/main/java/com/andre601/oneversionremake/OneVersionRemake.java
@@ -41,52 +41,45 @@ public class OneVersionRemake extends Plugin{
@Override
public void onEnable(){
sender = getProxy().getConsole();
- sendMessage(String.format(
- "§7[§fStartup§7] Enabling OneVersionRemake v%s...",
- getDescription().getVersion()
- ));
+ info("Enabling OneVersionRemake v%s...", getDescription().getVersion());
- sendMessage("§7[§fStartup - Config§7] Attempting to load config.yml...");
+ info("Loading config.yml...");
saveDefaultConfig();
try{
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
}catch(IOException ex){
- sendMessage("§7[§fStartup - §cConfig§7] §cUnable to load config! Plugin won't be enabled.");
+ error("§cCouldn't load config.yml (%s)! Plugin won't be enabled.", ex.getMessage());
return;
}
- sendMessage("§7[§fStartup - §aConfig§7] Config.yml loaded!");
+ info("Loaded config.yml successfully!");
- sendMessage("§7[§fStartup - Protocol§7] Loading Protocol version from the config...");
+ info("Loading Protocol Version from config...");
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(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================================================================================");
+ if(protocol < 47){
+ error("§c================================================================================");
+ error("§cWARNING!");
+ error("§cThe config option \"Version\" is set to less than 47 (MC 1.8.9)!");
+ error("§cThe plugin won't be fully loaded to prevent any issues.");
+ error("§c");
+ error("§cPlease change the Version to a supported one listed here:");
+ error("§chttps://github.com/Andre601/OneVersionRemake/wiki/Supported-Protocols");
+ error("§c================================================================================");
return;
}
- sendMessage(String.format(
- "§7[§fStartup - §aProtocol§7] Loaded protocol %d (MC %s)!",
- protocol,
- Versions.getFriendlyName(protocol)
- ));
+ info("Loaded Protocol %d (MC %s)!", protocol, Versions.getFriendlyName(protocol));
- sendMessage("§7[§fStartup - Listener§7] Loading listeners...");
- this.getProxy().getPluginManager().registerListener(this, new PingListener(this));
- this.getProxy().getPluginManager().registerListener(this, new LoginListener(this));
- sendMessage("§7[§fStartup - §aListener§7] Loaded listeners!");
+ info("Loading listeners...");
+ new PingListener(this);
+ new LoginListener(this);
+ info("Loaded listeners!");
- sendMessage("§7[§aStartup§7] §aStartup complete! OneVersionRemake is ready to use!");
+ info("§aStartup complete! OneVersionRemake is ready to use!");
}
public Configuration getConfig(){
@@ -104,16 +97,25 @@ private void saveDefaultConfig(){
try(InputStream is = getResourceAsStream("config.yml")){
Files.copy(is, file.toPath());
}catch(IOException ex){
- sendMessage(String.format(
- "§7[§fStartup - §cConfig§7] Could not create config.yml! Reason: %s",
- ex.getMessage()
- ));
+ error("§cCouldn't create config.yml! Reason: %s", ex.getMessage());
}
}
}
- private void sendMessage(String text){
- sender.sendMessage(new TextComponent("§7[OneVersionRemake] " + text));
+ public void info(String text, Object... args){
+ sendMessage("§7[§fOneVersionRemake§7] " + text, args);
+ }
+
+ private void error(String text, Object... args){
+ sendMessage("§7[§cOneVersionRemake§7] " + text, args);
+ }
+
+ private void sendMessage(String text, Object... args){
+
+ sender.sendMessage(new TextComponent(String.format(
+ text,
+ args
+ )));
}
public TextComponent getTextComponent(List list, int serverProtocol, int userProtocol){
diff --git a/src/main/java/com/andre601/oneversionremake/listener/LoginListener.java b/src/main/java/com/andre601/oneversionremake/listener/LoginListener.java
index 390595d..48a4e3b 100644
--- a/src/main/java/com/andre601/oneversionremake/listener/LoginListener.java
+++ b/src/main/java/com/andre601/oneversionremake/listener/LoginListener.java
@@ -19,6 +19,7 @@
package com.andre601.oneversionremake.listener;
import com.andre601.oneversionremake.OneVersionRemake;
+import com.andre601.oneversionremake.util.Versions;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
@@ -28,10 +29,11 @@
import java.util.List;
public class LoginListener implements Listener{
- private OneVersionRemake plugin;
+ private final OneVersionRemake plugin;
public LoginListener(OneVersionRemake plugin){
this.plugin = plugin;
+ plugin.getProxy().getPluginManager().registerListener(plugin, this);
}
@EventHandler(priority = EventPriority.LOWEST)
@@ -48,6 +50,14 @@ public void onLogin(PreLoginEvent event){
event.setCancelReason(plugin.getTextComponent(message, protocol, clientProtocol));
event.setCancelled(true);
+
+ if(plugin.getConfig().getBoolean("Protocol.LogDenial", true))
+ plugin.info(
+ "Denied login for Player %s with Protocol %d (MC %s)",
+ event.getConnection().getName(),
+ clientProtocol,
+ Versions.getFriendlyName(clientProtocol)
+ );
}
}else{
if(clientProtocol < protocol){
@@ -56,6 +66,14 @@ public void onLogin(PreLoginEvent event){
event.setCancelReason(plugin.getTextComponent(message, protocol, clientProtocol));
event.setCancelled(true);
+
+ if(plugin.getConfig().getBoolean("Protocol.LogDenial", true))
+ plugin.info(
+ "Denied login for Player %s with Protocol %d (MC %s)",
+ event.getConnection().getName(),
+ clientProtocol,
+ Versions.getFriendlyName(clientProtocol)
+ );
}
}
}
diff --git a/src/main/java/com/andre601/oneversionremake/listener/PingListener.java b/src/main/java/com/andre601/oneversionremake/listener/PingListener.java
index ce5df30..e4f281b 100644
--- a/src/main/java/com/andre601/oneversionremake/listener/PingListener.java
+++ b/src/main/java/com/andre601/oneversionremake/listener/PingListener.java
@@ -30,10 +30,11 @@
public class PingListener implements Listener{
- private OneVersionRemake plugin;
+ private final OneVersionRemake plugin;
public PingListener(OneVersionRemake plugin){
this.plugin = plugin;
+ plugin.getProxy().getPluginManager().registerListener(plugin, this);
}
@EventHandler(priority = EventPriority.LOWEST)
diff --git a/src/main/java/com/andre601/oneversionremake/util/Versions.java b/src/main/java/com/andre601/oneversionremake/util/Versions.java
index fae2c4d..e0a4b15 100644
--- a/src/main/java/com/andre601/oneversionremake/util/Versions.java
+++ b/src/main/java/com/andre601/oneversionremake/util/Versions.java
@@ -47,8 +47,8 @@ public enum Versions{
MC_1_8_9 (47, "1.8.9"),
UNKNOWN (0, "?");
- private int protocol;
- private String name;
+ private final int protocol;
+ private final String name;
Versions(int protocol, String name){
this.protocol = protocol;
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index b7e5c32..a8a1196 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -30,6 +30,11 @@ Protocol:
# https://github.com/andre601/OneVersionRemake/wiki/Supported-Protocols
#
Version: -1
+ #
+ # Should OneVersionRemake log any denied Login attempts in the console?
+ # The message will contain the version the player tried to join with.
+ #
+ LogDenial: true
#
# The various messages you can change.