Skip to content

Commit

Permalink
Version 1.4.0
Browse files Browse the repository at this point in the history
~ Minor changes to console logs
~ Added LogDenial config option to log denied logins
  • Loading branch information
Andre601 committed Jun 15, 2020
1 parent d2d9e67 commit a0ea79c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 38 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.3.0</version>
<version>1.4.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
68 changes: 35 additions & 33 deletions src/main/java/com/andre601/oneversionremake/OneVersionRemake.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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<String> list, int serverProtocol, int userProtocol){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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){
Expand All @@ -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)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a0ea79c

Please sign in to comment.