Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
~ Move Core and Platform to own interface classes
~ Rename Logger to ProxyLogger
~ Remove unused getInt method from ConfigHandler
  • Loading branch information
Andre601 committed Nov 7, 2020
1 parent 06f087e commit f875c00
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 79 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>2.0.1</version>
<version>2.1.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
import com.andre601.oneversionremake.bungee.listener.LoginListener;
import com.andre601.oneversionremake.bungee.listener.PingListener;
import com.andre601.oneversionremake.bungee.logger.BungeeLogger;
import com.andre601.oneversionremake.core.ConfigHandler;
import com.andre601.oneversionremake.core.Logger;
import com.andre601.oneversionremake.core.OneVersionRemake;
import com.andre601.oneversionremake.core.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;

import java.nio.file.Path;
import java.util.List;

public class BungeeCore extends Plugin implements OneVersionRemake.Core{
public class BungeeCore extends Plugin implements PluginCore{

private OneVersionRemake core;
private final Logger logger = new BungeeLogger(getLogger());
private final ProxyLogger logger = new BungeeLogger(getLogger());

private ConfigHandler configHandler = null;

Expand Down Expand Up @@ -74,17 +72,17 @@ public Path getPath(){
}

@Override
public OneVersionRemake.Platform getPlatform(){
public ProxyPlatform getProxyPlatform(){
try{
Class.forName("io.github.waterfallmc.waterfall.conf.WaterfallConfiguration");
return OneVersionRemake.Platform.WATERFALL;
return ProxyPlatform.WATERFALL;
}catch(ClassNotFoundException ex){
return OneVersionRemake.Platform.BUNGEE;
return ProxyPlatform.BUNGEECORD;
}
}

@Override
public Logger getProxyLogger(){
public ProxyLogger getProxyLogger(){
return logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class PingListener implements Listener{

private BungeeCore core;
private final BungeeCore core;

public PingListener(BungeeCore core){
this.core = core;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

package com.andre601.oneversionremake.bungee.logger;

import com.andre601.oneversionremake.core.Logger;
import com.andre601.oneversionremake.core.ProxyLogger;

import java.util.logging.Level;
import java.util.logging.Logger;

public class BungeeLogger implements Logger{
public class BungeeLogger implements ProxyLogger{

private final java.util.logging.Logger logger;
private final Logger logger;

public BungeeLogger(java.util.logging.Logger logger){
public BungeeLogger(Logger logger){
this.logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ public ConfigurationNode getNode(){
return node;
}

public int getInt(Object... path){
ConfigurationNode node = fromPath(path);

return node.getInt(-1);
}

public boolean getBoolean(boolean def, Object... path){
ConfigurationNode node = fromPath(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,29 @@

package com.andre601.oneversionremake.core;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class OneVersionRemake{

private final Core core;
private final PluginCore core;
private final ConfigHandler configHandler;

private final String version = getClass().getPackage().getImplementationVersion();

public OneVersionRemake(Core core){
public OneVersionRemake(PluginCore core){
this.core = core;
this.configHandler = new ConfigHandler(this, core.getPath());

start();
}

public Logger getLogger(){
public ProxyLogger getLogger(){
return core.getProxyLogger();
}

private void start(){
Logger logger = core.getProxyLogger();
ProxyLogger logger = core.getProxyLogger();

logger.info("");
logger.info(" ____ _ ______");
Expand All @@ -52,7 +51,7 @@ private void start(){
logger.info("");
logger.info("OneVersionRemake v" + getVersion());
logger.info("");
logger.info("Platform: " + core.getPlatform().getString());
logger.info("Platform: " + core.getProxyPlatform().getName());
logger.info("");

if(configHandler.loadConfig()){
Expand Down Expand Up @@ -92,40 +91,8 @@ public String getVersion(){
return version;
}

public interface Core{

void enable();

void setConfigHandler(ConfigHandler configHandler);

boolean reloadConfig();

Path getPath();

Platform getPlatform();

Logger getProxyLogger();

ConfigHandler getConfigHandler();
}

public enum Platform{
BUNGEE ("BungeeCord"),
WATERFALL("BungeeCord - [Waterfall]"),
VELOCITY ("Velocity");

private final String platform;

Platform(String platform){
this.platform = platform;
}

public String getString(){
return platform;
}
}

public enum Versions{
MC_1_16_4(754, "1.16.4"),
MC_1_16_3(753, "1.16.3"),
MC_1_16_2(751, "1.16.2"),
MC_1_16_1(736, "1.16.1"),
Expand Down Expand Up @@ -179,11 +146,10 @@ public static String getFriendlyName(int protocol){
}

public static String getFriendlyName(List<Integer> protocols){
List<String> friendlyNames = new ArrayList<>();
for(int i : protocols)
friendlyNames.add(getFriendlyName(i));

return String.join(", ", friendlyNames);
return protocols.stream()
.sorted()
.map(Versions::getFriendlyName)
.collect(Collectors.joining(", "));
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/andre601/oneversionremake/core/PluginCore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2020 Andre601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.andre601.oneversionremake.core;

import java.nio.file.Path;

public interface PluginCore{

void enable();

void setConfigHandler(ConfigHandler configHandler);

boolean reloadConfig();

Path getPath();

ProxyPlatform getProxyPlatform();

ProxyLogger getProxyLogger();

ConfigHandler getConfigHandler();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.andre601.oneversionremake.core;

public interface Logger{
public interface ProxyLogger{

void info(String msg);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020 Andre601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.andre601.oneversionremake.core;

public enum ProxyPlatform{

BUNGEECORD("BungeeCord"),
WATERFALL ("Waterfall"),
VELOCITY ("Velocity");

private final String name;

ProxyPlatform(String name){
this.name = name;
}

public String getName(){
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

package com.andre601.oneversionremake.velocity;

import com.andre601.oneversionremake.core.ConfigHandler;
import com.andre601.oneversionremake.core.Logger;
import com.andre601.oneversionremake.core.OneVersionRemake;
import com.andre601.oneversionremake.core.*;
import com.andre601.oneversionremake.velocity.commands.CmdOneVersionRemake;
import com.andre601.oneversionremake.velocity.listener.LoginListener;
import com.andre601.oneversionremake.velocity.listener.PingListener;
Expand All @@ -43,8 +41,8 @@
name = "OneVersionRemake",
authors = {"Andre_601"}
)
public class VelocityCore implements OneVersionRemake.Core{
private final Logger logger;
public class VelocityCore implements PluginCore{
private final ProxyLogger logger;
private final ProxyServer proxy;
private final Path pluginFolder;

Expand Down Expand Up @@ -94,12 +92,12 @@ public Path getPath(){
}

@Override
public OneVersionRemake.Platform getPlatform(){
return OneVersionRemake.Platform.VELOCITY;
public ProxyPlatform getProxyPlatform(){
return ProxyPlatform.VELOCITY;
}

@Override
public Logger getProxyLogger(){
public ProxyLogger getProxyLogger(){
return logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package com.andre601.oneversionremake.velocity.logger;

import com.andre601.oneversionremake.core.Logger;
import com.andre601.oneversionremake.core.ProxyLogger;
import org.slf4j.Logger;

public class VelocityLogger implements Logger{
public class VelocityLogger implements ProxyLogger{

private final org.slf4j.Logger logger;
private final Logger logger;

public VelocityLogger(org.slf4j.Logger logger){
public VelocityLogger(Logger logger){
this.logger = logger;
}

Expand Down

0 comments on commit f875c00

Please sign in to comment.