Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions proxy-api/proxy-api.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.logging.Logger;

public class BedWarsProxy extends JavaPlugin{
public class BedWarsProxy extends JavaPlugin {

private static BedWarsProxy plugin;
private static BedWars api;
public static BedWarsConfig config;
private static Database remoteDatabase = null;
private static Database remoteDatabase;
private static StatsCache statsCache;

private static SoundSupport soundAdapter;
Expand All @@ -52,100 +53,146 @@ public class BedWarsProxy extends JavaPlugin{
private static Party party;
private static Level levelManager;

private static final Logger LOGGER = Logger.getLogger("BedWarsProxy");

@Override
public void onLoad() {
plugin = this;
api = new API();
Bukkit.getServicesManager().register(BedWars.class, api, this, ServicePriority.Highest);
// Setup languages
}

@Override
public void onEnable() {
loadSupportAdapters();
LanguageManager.init();

config = new BedWarsConfig();
initDatabase();

statsCache = new StatsCache();
setupSocketCommunication();

registerListeners(
new LangListeners(),
new ArenaSelectorListener(),
new CacheListener()
);

new SoundsConfig();
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getScheduler().runTaskTimer(this, new TimeOutTask(), 20L, 10L);

setupParties();
levelManager = new InternalLevel();
Bukkit.getPluginManager().registerEvents(new LevelListeners(), this);

registerCommands();
registerPlaceholders();
setupMetrics();
SignManager.init();
}

@Override
public void onDisable() {
ServerSocketTask.stopTasks();
Bukkit.getScheduler().cancelTasks(this);
}

private void loadSupportAdapters() {
soundAdapter = SoundSupport.SupportBuilder.load();
materialAdapter = MaterialSupport.SupportBuilder.load();
blockAdapter = BlockSupport.SupportBuilder.load();
itemAdapter = ItemStackSupport.SupportBuilder.load();

if (null == soundAdapter) {
if (soundAdapter == null) {
soundAdapter = new sound_v1_18_R1();
}
}

LanguageManager.init();
config = new BedWarsConfig();
private void initDatabase() {
if (config.getBoolean("database.enable")) {
Bukkit.getScheduler().runTaskAsynchronously(this, () -> remoteDatabase = new MySQL());
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
LOGGER.info("Connecting to MySQL database...");
remoteDatabase = new MySQL();
if (remoteDatabase instanceof NoDatabase) {
LOGGER.warning("Failed to connect to MySQL. Using NoDatabase fallback.");
} else {
LOGGER.info("Successfully connected to MySQL.");
}
});
} else {
LOGGER.info("Database is disabled in config. Using NoDatabase.");
remoteDatabase = new NoDatabase();
}
statsCache = new StatsCache();
}

if (!ServerSocketTask.init(config.getInt(ConfigPath.GENERAL_CONFIGURATION_PORT))) {
getLogger().severe("Could not register port: " + config.getInt(ConfigPath.GENERAL_CONFIGURATION_PORT));
getLogger().severe("Please change it in config! Port already in use!");
private void setupSocketCommunication() {
int port = config.getInt(ConfigPath.GENERAL_CONFIGURATION_PORT);
if (!ServerSocketTask.init(port)) {
LOGGER.severe("Could not register port: " + port);
LOGGER.severe("Please change it in config! Port already in use!");
} else {
LOGGER.info("Listening for BedWars1058 arenas on port: " + port);
}
}

getLogger().info("Listening for BedWars1058 arenas on port: " + config.getInt(ConfigPath.GENERAL_CONFIGURATION_PORT));

registerListeners(new LangListeners(), new ArenaSelectorListener(), new CacheListener());
//noinspection InstantiationOfUtilityClass
new SoundsConfig();

Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");

Bukkit.getScheduler().runTaskTimer(this, new TimeOutTask(), 20L, 10L);

//Party support
if (config.getYml().getBoolean(ConfigPath.GENERAL_CONFIGURATION_ALLOW_PARTIES)) {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Parties")) {
getLogger().info("Hook into Parties (by AlessioDP) support!");
party = new Parties();
} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) {
getLogger().info("Hook into Party and Friends Extended Edition for BungeeCord (by Simonsator) support!");
party = new PAFBungeeCordParty();
} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("PartyAndFriends")) {
getLogger().info("Hook into Party and Friends for Spigot (by Simonsator) support!");
party = new PAF();
}
}
if (party == null) {
private void setupParties() {
if (!config.getYml().getBoolean(ConfigPath.GENERAL_CONFIGURATION_ALLOW_PARTIES)) {
party = new Internal();
getLogger().info("Loading internal Party system. /party");
LOGGER.info("Parties disabled. Using internal Party system.");
return;
}

levelManager = new InternalLevel();
Bukkit.getPluginManager().registerEvents(new LevelListeners(), this);
if (Bukkit.getPluginManager().isPluginEnabled("Parties")) {
LOGGER.info("Hooked into Parties (by AlessioDP).");
party = new Parties();
} else if (Bukkit.getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) {
LOGGER.info("Hooked into Party and Friends Extended Edition for BungeeCord.");
party = new PAFBungeeCordParty();
} else if (Bukkit.getPluginManager().isPluginEnabled("PartyAndFriends")) {
LOGGER.info("Hooked into Party and Friends for Spigot.");
party = new PAF();
} else {
party = new Internal();
LOGGER.info("No external party plugin found. Using internal Party system.");
}
}

private void registerCommands() {
try {
Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
commandMap.register("bw", new MainCommand("bw"));
commandMap.register("rejoin", new RejoinCommand("rejoin"));

if (config.getBoolean(ConfigPath.GENERAL_ENABLE_PARTY_CMD)) {
commandMap.register("party", new PartyCommand("party"));
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
LOGGER.log(java.util.logging.Level.SEVERE, "Failed to register commands.", e);
}
}

/* PlaceholderAPI Support */
private void registerPlaceholders() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
getLogger().info("Hook into PlaceholderAPI support!");
LOGGER.info("Hooked into PlaceholderAPI.");
new SupportPAPI().register();
}
}

Metrics m = new Metrics(this, 6036);
m.addCustomChart(new SimplePie("default_language", () -> LanguageManager.get().getDefaultLanguage().getIso()));
m.addCustomChart(new SimplePie("party_adapter", () -> getParty().getClass().getName()));
m.addCustomChart(new SimplePie("level_adapter", () -> getLevelManager().getClass().getName()));
SignManager.init();
private void setupMetrics() {
Metrics metrics = new Metrics(this, 6036);
metrics.addCustomChart(new SimplePie("default_language", () -> LanguageManager.get().getDefaultLanguage().getIso()));
metrics.addCustomChart(new SimplePie("party_adapter", () -> getParty().getClass().getName()));
metrics.addCustomChart(new SimplePie("level_adapter", () -> getLevelManager().getClass().getName()));
}

@Override
public void onDisable() {
ServerSocketTask.stopTasks();
Bukkit.getScheduler().cancelTasks(this);
private static void registerListeners(@NotNull Listener... listeners) {
for (Listener listener : listeners) {
Bukkit.getPluginManager().registerEvents(listener, getPlugin());
}
}

public static Plugin getPlugin() {
Expand All @@ -164,7 +211,6 @@ public static MaterialSupport getMaterialAdapter() {
return materialAdapter;
}

@SuppressWarnings("unused")
public static BlockSupport getBlockAdapter() {
return blockAdapter;
}
Expand All @@ -177,12 +223,6 @@ public static SoundSupport getSoundAdapter() {
return soundAdapter;
}

private static void registerListeners(@NotNull Listener... listeners) {
for (Listener listener : listeners) {
Bukkit.getPluginManager().registerEvents(listener, getPlugin());
}
}

public static Party getParty() {
return party;
}
Expand All @@ -195,18 +235,17 @@ public static Level getLevelManager() {
* Create a text component.
*/
@NotNull
public static TextComponent createTC(String text, String suggest, String shot_text) {
public static TextComponent createTC(String text, String suggest, String hoverText) {
TextComponent tx = new TextComponent(text);
tx.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
tx.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(shot_text).create()));
tx.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hoverText).create()));
return tx;
}

public static void setRemoteDatabase(Database remoteDatabase) {
BedWarsProxy.remoteDatabase = remoteDatabase;
}


public static BedWars getAPI() {
return api;
}
Expand Down
Loading