2016-04-13 05:52:53 +02:00
|
|
|
package eu.univento.core;
|
|
|
|
|
2016-04-29 12:54:03 +02:00
|
|
|
import eu.univento.core.antihack.AntiHack;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.Config;
|
2016-07-09 13:14:19 +02:00
|
|
|
import eu.univento.core.api.database.DatabaseManager;
|
2016-07-28 20:17:25 +02:00
|
|
|
import eu.univento.core.api.effects.Blackscreen;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.events.MoveEventFilter;
|
|
|
|
import eu.univento.core.api.player.CustomPlayer;
|
2016-06-25 15:42:06 +02:00
|
|
|
import eu.univento.core.api.server.NetworkData;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.server.ServerSettings;
|
2016-07-28 20:17:25 +02:00
|
|
|
import eu.univento.core.api.utils.NettyInjection;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.commands.*;
|
|
|
|
import eu.univento.core.listeners.*;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
2016-07-28 20:17:25 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2016-04-13 05:52:53 +02:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2016-07-28 20:17:25 +02:00
|
|
|
import java.nio.channels.Channel;
|
2016-04-13 05:52:53 +02:00
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
2016-07-28 20:17:25 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2016-04-13 05:52:53 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* main class
|
2016-07-28 20:17:25 +02:00
|
|
|
*
|
2016-04-13 05:52:53 +02:00
|
|
|
* @author joethei
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
2016-07-28 20:17:25 +02:00
|
|
|
public class Core extends JavaPlugin implements NettyInjection.PacketHandler {
|
|
|
|
|
|
|
|
//TODO: rewrite database operations from sync MongoDB to async MongoDB
|
|
|
|
|
|
|
|
/**
|
|
|
|
* plugin instance
|
|
|
|
*/
|
|
|
|
private static Core instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return plugin instance
|
|
|
|
*/
|
|
|
|
public static Core getInstance() {
|
|
|
|
return instance;
|
2016-07-09 13:14:19 +02:00
|
|
|
}
|
2016-07-28 20:17:25 +02:00
|
|
|
|
|
|
|
private ArrayList<String> registeredPlugins = new ArrayList<>();
|
|
|
|
|
|
|
|
public void registerPlugin(Plugin plugin) {
|
|
|
|
registeredPlugins.add(plugin.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unregisterPlugin(Plugin plugin) {
|
|
|
|
if (registeredPlugins.contains(plugin.getName())) registeredPlugins.remove(plugin.getName());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
private NettyInjection injection;
|
|
|
|
private static List<CustomPlayer> timeout = new ArrayList<>();
|
|
|
|
public static List<CustomPlayer> getTimeout() {
|
|
|
|
return timeout;
|
2016-07-09 13:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static DatabaseManager databaseManager;
|
2016-07-28 20:17:25 +02:00
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
public static DatabaseManager getDatabaseManager() {
|
|
|
|
return databaseManager;
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
private static final Logger log = Bukkit.getLogger();
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
public static Collection<CustomPlayer> getOnlinePlayers() {
|
|
|
|
Collection<CustomPlayer> list = new LinkedList<>();
|
|
|
|
for (Player players : Bukkit.getOnlinePlayers()) {
|
2016-04-13 05:52:53 +02:00
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(players);
|
|
|
|
list.add(p);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
public static void broadcast(String key) {
|
|
|
|
for(CustomPlayer players : getOnlinePlayers()) {
|
|
|
|
players.sendMessage(players.getMessage(key));
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
2016-07-28 20:17:25 +02:00
|
|
|
}
|
2016-05-08 10:45:34 +02:00
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
/**
|
|
|
|
* @param level Log level
|
|
|
|
* @param string String
|
|
|
|
*/
|
|
|
|
public static void log(Level level, String string) {
|
|
|
|
if (ServerSettings.isDebug()) {
|
|
|
|
log.log(level, "[univento Core] " + string);
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2016-06-25 15:42:06 +02:00
|
|
|
log(Level.INFO, "\n" +
|
|
|
|
"\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" _ _ _ \n" +
|
|
|
|
" | | | | (_) \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___| |_ __ _ _ __| |_ _ _ __ __ _ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / __| __/ _` | '__| __| | '_ \\ / _` |\n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | \\__ \\ || (_| | | | |_| | | | | (_| |\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| |___/\\__\\__,_|_| \\__|_|_| |_|\\__, |\n" +
|
|
|
|
" __/ |\n" +
|
|
|
|
" |___/ \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\n");
|
2016-07-28 20:17:25 +02:00
|
|
|
try {
|
|
|
|
Config.writeDefault();
|
|
|
|
} catch (IOException | ClassNotFoundException | SQLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
instance = this;
|
|
|
|
PluginManager pm = Bukkit.getPluginManager();
|
|
|
|
pm.registerEvents(new Commands(), this);
|
|
|
|
pm.registerEvents(new JoinQuit(), this);
|
|
|
|
pm.registerEvents(new Chat(), this);
|
|
|
|
pm.registerEvents(new Events(), this);
|
|
|
|
pm.registerEvents(new WeaponEvents(), this);
|
|
|
|
pm.registerEvents(new SpectatorEvents(), this);
|
|
|
|
pm.registerEvents(new MoveEventFilter(getServer()), this);
|
|
|
|
|
|
|
|
if (ServerSettings.isBuild()) {
|
|
|
|
new Build(this, "build", "enables/disables the build mode", "b");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ServerSettings.isGame()) {
|
|
|
|
new Fix(this, "fix", "fix your self or other players");
|
|
|
|
new Nick(this, "nick", "nick/unnick your self");
|
|
|
|
}
|
|
|
|
AntiHack.registerListeners();
|
|
|
|
|
|
|
|
new RunAs(this, "RunAs", "run command as other player");
|
|
|
|
new SystemInfo(this, "SystemInfo", "gives info about the server system");
|
|
|
|
new Vanish(this, "vanish", "vanish/unvanish your self");
|
|
|
|
new GameMode(this, "gamemode", "sets your gamemode", "gm");
|
|
|
|
new SetRank(this, "setrank", "sets the rank for other players", "sr");
|
|
|
|
new GlobalMute(this, "globalmute", "mutes the server");
|
|
|
|
new ChatClear(this, "chatclear", "clears the chat", "cc");
|
|
|
|
new Timeout(this, "timeout", "timeout other players");
|
|
|
|
|
|
|
|
PluginMessenger pluginMessenger = new PluginMessenger();
|
|
|
|
NetworkData networkData = new NetworkData();
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "5zig_Set");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "5zig_Set", pluginMessenger);
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", networkData);
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", pluginMessenger);
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "WDL|CONTROL");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "WDL|REQUEST", pluginMessenger);
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "PERMISSIONSREPL", pluginMessenger);
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "schematica");
|
|
|
|
|
|
|
|
Blackscreen.setupUtil(getInstance());
|
|
|
|
databaseManager = new DatabaseManager(getInstance());
|
2016-06-25 15:42:06 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> log(Level.INFO, "\n" +
|
|
|
|
"\n" +
|
|
|
|
"\n" +
|
|
|
|
" _ _ \n" +
|
|
|
|
" | (_) \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___ _ __ | |_ _ __ ___ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / _ \\| '_ \\| | | '_ \\ / _ \\\n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | | (_) | | | | | | | | | __/\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| \\___/|_| |_|_|_|_| |_|\\___|\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\n"), 0L);
|
2016-07-28 20:17:25 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
|
|
|
for (Plugin plugin : pm.getPlugins()) {
|
|
|
|
if (!plugin.getName().equalsIgnoreCase("WorldEdit") && !plugin.getName().equalsIgnoreCase("VoxelSniper") && !registeredPlugins.contains(plugin.getName())) {
|
|
|
|
log(Level.WARNING, "§cDas Plugin " + plugin.getName() + " ist nicht für den Server zugelassen.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 5L);
|
|
|
|
|
|
|
|
this.injection = new NettyInjection(this, this.getName());
|
|
|
|
this.injection.addHandler("TIMEOUT", new NettyInjection.PacketHandler() {
|
|
|
|
public Object onPacketIn(Player sender, Channel channel, Object packet) {
|
|
|
|
if (timeout.contains(CustomPlayer.getPlayer(sender)))
|
|
|
|
return null;
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2016-07-09 13:14:19 +02:00
|
|
|
databaseManager.closeConnections();
|
2016-07-28 20:17:25 +02:00
|
|
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(this);
|
|
|
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this);
|
2016-05-08 10:45:34 +02:00
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
this.injection.disable();
|
|
|
|
|
|
|
|
log(Level.INFO, "\n" +
|
2016-06-25 15:42:06 +02:00
|
|
|
"\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" _ _ _ \n" +
|
|
|
|
" | | | | | | \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___| |__ _ _| |_ __| | _____ ___ __ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / __| '_ \\| | | | __/ _` |/ _ \\ \\ /\\ / / '_ \\ \n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | \\__ \\ | | | |_| | || (_| | (_) \\ V V /| | | |\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| |___/_| |_|\\__,_|\\__\\__,_|\\___/ \\_/\\_/ |_| |_|\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\nd");
|
2016-07-28 20:17:25 +02:00
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
}
|