Commit 416ec535 authored by Kaisar Arkhan's avatar Kaisar Arkhan
Browse files

Merge branch 'release/7.0'

parents 11238a99 dce1cc5c
......@@ -4,6 +4,13 @@
*.iws
.idea/
### Eclipse ###
.project
.classpath
.project/
.settings/
bin/
### Package Files ###
*.jar
*.war
......@@ -12,3 +19,4 @@
### Gradle ###
.gradle/
build/
*.class
......@@ -2,15 +2,18 @@
## What you should use
* Google's Java Style
* Maven
* Gradle
* Git Flow
## What we recommend to use
* IntelliJ IDEA CE
* IntelliJ IDEA
* Eclipse
## Commit Message Format ##
`[<Module / Server (Bungee/Common/Project-Z/Nations)>/<Module/Part>] <Changes>`
## What you shouldn't do
* Use JAR files as an dependency ( request Kaisar Arkhan to add it to Nucleus's Repo )
* Confusing Code ( Every Code should be readable and can be understood by other people )
* Multiple Changes in one commit
## Know your limits
* Project-Z uses 1.7.10 as a Backend with Protocol Hack and 1.8 Items / Blocks / Mobs Support
\ No newline at end of file
* Not Branching-out for changes ( This is why you should use Git Flow )
\ No newline at end of file
......@@ -8,3 +8,5 @@ dependencies {
Please review and delete this closure when resolved. */
}
}
shadowJar {}
\ No newline at end of file
......@@ -30,152 +30,151 @@ import java.sql.SQLException;
import java.util.logging.Logger;
public class NuBungee extends Plugin {
private static NuBungee instance;
private static NuBungee instance;
private final Class[] moduleClasses =
new Class[]{ModuleGlobalChat.class, ModuleAntiBot.class, ModuleConnectMessage.class,
ModulePrivateMessage.class, ModuleSlashServer.class, ModuleFun.class,
ModuleAntiSteve.class};
private final Class[] moduleClasses = new Class[] {ModuleGlobalChat.class, ModuleAntiBot.class,
ModuleConnectMessage.class, ModulePrivateMessage.class, ModuleSlashServer.class,
ModuleFun.class, ModuleAntiSteve.class};
private final Class[] listenerClasses =
new Class[]{ModuleCommandsListener.class};
private final Class[] listenerClasses = new Class[] {ModuleCommandsListener.class};
private Logger logger = getLogger();
private Logger logger = getLogger();
private Configuration config;
private Connection conn;
private Configuration config;
private Connection conn;
public static NuBungee getInstance() {
return instance;
}
public static NuBungee getInstance() {
return instance;
}
@Override
public void onEnable() {
instance = this;
@Override
public void onEnable() {
instance = this;
logger = this.getLogger();
logger = this.getLogger();
logger.info("--- Enabling NuBungee --- ");
logger.info("--- Enabling NuBungee --- ");
logger.info(">> Loading Configuration File ...");
loadConfig();
logger.info(">> Loading Configuration File ...");
loadConfig();
logger.info(">> Starting SQL Connection ...");
if (!startDatabaseConnection())
return;
logger.info(">> Starting SQL Connection ...");
if (!startDatabaseConnection())
return;
logger.info(">> Loading Modules ...");
ModuleManager.loadModules(moduleClasses);
logger.info(">> Loading Modules ...");
ModuleManager.loadModules(moduleClasses);
logger.info(">> Enabling Modules ...");
ModuleManager.enableAllModules();
logger.info(">> Enabling Modules ...");
ModuleManager.enableAllModules();
logger.info(">> Registering Listeners ...");
registerListeners();
}
logger.info(">> Registering Listeners ...");
registerListeners();
}
@Override
public void onDisable() {
logger.info("--- Disabling NuBungee ---");
@Override
public void onDisable() {
logger.info("--- Disabling NuBungee ---");
logger.info(">> Unloading Modules ...");
ModuleManager.unloadAllModules();
logger.info(">> Unloading Modules ...");
ModuleManager.unloadAllModules();
logger.info(">> Closing SQL Connection ...");
stopDatabaseConnection();
logger.info(">> Closing SQL Connection ...");
stopDatabaseConnection();
logger.info("--- NuBungee Disabled ---");
}
logger.info("--- NuBungee Disabled ---");
}
public Configuration getConfig() {
return config;
}
public Configuration getConfig() {
return config;
}
private void loadConfig() {
if (!this.getDataFolder().exists())
this.getDataFolder().mkdir();
File configFile = new File(getDataFolder(), "config.yml");
if (!configFile.exists()) {
try {
configFile.createNewFile();
try (InputStream in = getResourceAsStream("config.yml");
OutputStream out = new FileOutputStream(configFile)) {
ByteStreams.copy(in, out);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create configuration file ", e);
}
}
private void loadConfig() {
if (!this.getDataFolder().exists())
this.getDataFolder().mkdir();
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (IOException e) {
throw new RuntimeException("Unable to load configuration file", e);
}
}
File configFile = new File(getDataFolder(), "config.yml");
// TODO: Change to a proper Plugin Disable Mechanic
private boolean startDatabaseConnection() {
if (config.getBoolean("mysql.use", false)) {
// Use MySQL
try {
Class.forName("org.mysql.JDBC");
} catch (ClassNotFoundException e) {
logger.severe("Database driver error: " + e.getMessage());
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://" + config.getString("mysql.host") + ":"
+ config.getInt("mysql.port") + "/" + config.getString("mysql.database"),
config.getString("mysql.username"), config.getString("mysql.password"));
return true;
} catch (SQLException e) {
logger.severe("Error while starting Database Connection! SUICIDE IN PROGRESS !!");
e.printStackTrace();
}
} else {
// Use SQLite
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
logger.severe("Database driver error:" + e.getMessage());
}
File dbFile = new File(getDataFolder(), "database.db");
try {
conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath());
return true;
} catch (SQLException e) {
logger.severe("Error while starting Database Connection! SUiCIDE IN PROGRESS !!");
e.printStackTrace();
}
if (!configFile.exists()) {
try {
configFile.createNewFile();
try (InputStream in = getResourceAsStream("config.yml");
OutputStream out = new FileOutputStream(configFile)) {
ByteStreams.copy(in, out);
}
return false;
} catch (IOException e) {
throw new RuntimeException("Unable to create configuration file ", e);
}
}
private void stopDatabaseConnection() {
try {
conn.close();
} catch (SQLException ignored) {
}
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (IOException e) {
throw new RuntimeException("Unable to load configuration file", e);
}
}
// TODO: Change to a proper Plugin Disable Mechanic
private boolean startDatabaseConnection() {
if (config.getBoolean("mysql.use", false)) {
// Use MySQL
try {
Class.forName("org.mysql.JDBC");
} catch (ClassNotFoundException e) {
logger.severe("Database driver error: " + e.getMessage());
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port")
+ "/" + config.getString("mysql.database"),
config.getString("mysql.username"), config.getString("mysql.password"));
return true;
} catch (SQLException e) {
logger.severe("Error while starting Database Connection! SUICIDE IN PROGRESS !!");
e.printStackTrace();
}
} else {
// Use SQLite
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
logger.severe("Database driver error:" + e.getMessage());
}
File dbFile = new File(getDataFolder(), "database.db");
try {
conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath());
return true;
} catch (SQLException e) {
logger.severe("Error while starting Database Connection! SUiCIDE IN PROGRESS !!");
e.printStackTrace();
}
}
private void registerListeners() {
for (Class<Listener> listenerClass : listenerClasses) {
try {
ProxyServer.getInstance().getPluginManager().registerListener(this, listenerClass.newInstance());
} catch (Exception e) {
logger.severe("An Exception occured while registering a listener " + e);
e.printStackTrace();
}
}
return false;
}
private void stopDatabaseConnection() {
try {
conn.close();
} catch (SQLException ignored) {
}
}
private void registerListeners() {
for (Class<Listener> listenerClass : listenerClasses) {
try {
ProxyServer.getInstance().getPluginManager().registerListener(this,
listenerClass.newInstance());
} catch (Exception e) {
logger.severe("An Exception occured while registering a listener " + e);
e.printStackTrace();
}
}
}
}
......@@ -3,15 +3,15 @@ package com.nucleus.id.bungee.formats;
import net.md_5.bungee.api.ChatColor;
public class ChatFormats {
public static ChatColor baseColor = ChatColor.GRAY;
public static ChatColor accentColor = ChatColor.RED;
public static ChatColor baseColor = ChatColor.GRAY;
public static ChatColor accentColor = ChatColor.RED;
public static String prefixFormat(String s) {
return accentColor + s + baseColor + "> ";
}
public static String prefixFormat(String s) {
return accentColor + s + baseColor + "> ";
}
public static String line() {
return baseColor + "" + ChatColor.STRIKETHROUGH
+ "-----------------------------------------------------";
}
public static String line() {
return baseColor + "" + ChatColor.STRIKETHROUGH
+ "-----------------------------------------------------";
}
}
......@@ -21,37 +21,37 @@ import java.util.List;
public class ModuleCommandsListener implements Listener {
@EventHandler
public void onCommand(ChatEvent e) {
if (!e.getMessage().startsWith("/"))
return;
String[] messages = e.getMessage().split(" ");
List<String> argList = new ArrayList<>(Arrays.asList(messages));
argList.remove(0);
String[] args = argList.toArray(new String[argList.size()]);
for (Module module : ModuleManager.getEnabledModules()) {
for (String command : module.getCommands()) {
if (command.equalsIgnoreCase(messages[0].substring(1))) {
ProxiedPlayer p = (ProxiedPlayer) e.getSender();
try {
module.onCommand(p, command, args);
} catch (Exception ex) {
ex.printStackTrace();
p.sendMessage(new TextComponent(
ChatFormats.prefixFormat("NuBungee")
+ ChatFormats.accentColor + "An Error has occured while running this command. Please report to the Administator."));
}
e.setCancelled(true);
return;
}
}
@EventHandler
public void onCommand(ChatEvent e) {
if (!e.getMessage().startsWith("/"))
return;
String[] messages = e.getMessage().split(" ");
List<String> argList = new ArrayList<>(Arrays.asList(messages));
argList.remove(0);
String[] args = argList.toArray(new String[argList.size()]);
for (Module module : ModuleManager.getEnabledModules()) {
for (String command : module.getCommands()) {
if (command.equalsIgnoreCase(messages[0].substring(1))) {
ProxiedPlayer p = (ProxiedPlayer) e.getSender();
try {
module.onCommand(p, command, args);
} catch (Exception ex) {
ex.printStackTrace();
p.sendMessage(new TextComponent(ChatFormats.prefixFormat("NuBungee")
+ ChatFormats.accentColor
+ "An Error has occured while running this command. Please report to the Administator."));
}
e.setCancelled(true);
return;
}
}
}
}
}
/*
* Copyright (C) Nucleus Server Team - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential Written by Kaisar Arkhan
* Copyright (C) Nucleus Server Team - All Rights Reserved Unauthorized copying of this file, via
* any medium is strictly prohibited Proprietary and confidential Written by Kaisar Arkhan
* <yuki@airmail.cc>, June 2015
*/
package com.nucleus.id.bungee.managers;
......@@ -15,202 +14,202 @@ import java.util.Iterator;
public class ModuleManager {
private static ArrayList<Module> modules = new ArrayList<Module>();
private static NuBungee plugin = NuBungee.getInstance();
private static ArrayList<Module> modules = new ArrayList<Module>();
private static NuBungee plugin = NuBungee.getInstance();
public static void loadModule(Module m) {
modules.add(m);
}
public static void loadModule(Module m) {
modules.add(m);
}
public static void loadModule(Class<Module> moduleClass) {
try {
Module module = moduleClass.newInstance();
loadModule(module);
} catch (Exception e) {
logSevere("Error occured while loading a module! " + e);
return;
}
public static void loadModule(Class<Module> moduleClass) {
try {
Module module = moduleClass.newInstance();
loadModule(module);
} catch (Exception e) {
logSevere("Error occured while loading a module! " + e);
return;
}
}
public static void loadModules(Class<Module>[] moduleClasses) {
for (Class<Module> c : moduleClasses) {
loadModule(c);
}
public static void loadModules(Class<Module>[] moduleClasses) {
for (Class<Module> c : moduleClasses) {
loadModule(c);
}
}
public static Module getModule(String moduleName) {
for (Module module : modules) {
if (module.getName().equalsIgnoreCase(moduleName)) {
return module;
}
}
return null;
public static Module getModule(String moduleName) {
for (Module module : modules) {
if (module.getName().equalsIgnoreCase(moduleName)) {
return module;
}
}
public static Module getModule(Class<Module> moduleClass) {
for (Module module : modules) {
if (module.getClass().equals(moduleClass)) {
return module;
}
}
return null;
}
return null;
public static Module getModule(Class<Module> moduleClass) {
for (Module module : modules) {
if (module.getClass().equals(moduleClass)) {
return module;
}
}
public static void unloadModule(Module module) {
if (module.isEnabled()) {
disableModule(module);
}
return null;
}
modules.remove(module);
public static void unloadModule(Module module) {
if (module.isEnabled()) {
disableModule(module);
}
public static void unloadModule(String moduleName) throws NullPointerException {
Module module = getModule(moduleName);
modules.remove(module);
}
if (module == null) {
throw new NullPointerException("Module does not exist or not loaded!");
}
public static void unloadModule(String moduleName) throws NullPointerException {
Module module = getModule(moduleName);
unloadModule(module);
if (module == null) {
throw new NullPointerException("Module does not exist or not loaded!");
}
public static void unloadModule(Class<Module> moduleClass) throws NullPointerException {
Module module = getModule(moduleClass);
unloadModule(module);
}
if (module == null) {
throw new NullPointerException("Module does not exist or not loaded!");
}
public static void unloadModule(Class<Module> moduleClass) throws NullPointerException {
Module module = getModule(moduleClass);
unloadModule(module);
if (module == null) {
throw new NullPointerException("Module does not exist or not loaded!");
}
public static void unloadAllModules() {
Iterator<Module> it = modules.iterator();
unloadModule(module);
}
while (it.hasNext()) {
Module m = it.next();
public static void unloadAllModules() {
Iterator<Module> it = modules.iterator();
if (m.isEnabled()) {
disableModule(m);
}
it.remove();
}
}
while (it.hasNext()) {
Module m = it.next();
public static void enableModule(Module module) {
if (module.isEnabled()) {
return;
}
if (m.isEnabled()) {
disableModule(m);
}
module.onEnable();
module.setEnabled(true);
it.remove();
}
}