Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei1058 committed Nov 21, 2023
2 parents cf8f820 + e9b3c21 commit a6bd4a4
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public static void setupCustomStatsMessages() {
if (l == null) continue;
if (l.getYml() == null) continue;
/* save messages for stats gui items if custom items added */
if (api.getConfigs().getMainConfig().getYml().get("ConfigPath.GENERAL_CONFIGURATION_STATS_PATH") == null)
if (api.getConfigs().getMainConfig().getYml().get(ConfigPath.GENERAL_CONFIGURATION_STATS_PATH) == null)
return;
for (String item : api.getConfigs().getMainConfig().getYml().getConfigurationSection(ConfigPath.GENERAL_CONFIGURATION_STATS_PATH).getKeys(false)) {
if (ConfigPath.GENERAL_CONFIGURATION_STATS_GUI_SIZE.contains(item)) continue;
Expand Down
127 changes: 28 additions & 99 deletions bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
import com.andrei1058.bedwars.lobbysocket.LoadedUsersCleaner;
import com.andrei1058.bedwars.lobbysocket.SendTask;
import com.andrei1058.bedwars.maprestore.internal.InternalAdapter;
import com.andrei1058.bedwars.metrics.MetricsManager;
import com.andrei1058.bedwars.money.internal.MoneyListeners;
import com.andrei1058.bedwars.shop.ShopManager;
import com.andrei1058.bedwars.sidebar.*;
import com.andrei1058.bedwars.sidebar.thread.*;
import com.andrei1058.bedwars.stats.StatsManager;
import com.andrei1058.bedwars.support.citizens.CitizensListener;
import com.andrei1058.bedwars.support.citizens.JoinNPC;
Expand All @@ -81,8 +81,6 @@
import com.andrei1058.bedwars.support.vipfeatures.VipListeners;
import com.andrei1058.vipfeatures.api.IVipFeatures;
import com.andrei1058.vipfeatures.api.MiniGameAlreadyRegistered;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -105,7 +103,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.*;

@SuppressWarnings("WeakerAccess")
@SuppressWarnings({"WeakerAccess", "CallToPrintStackTrace"})
public class BedWars extends JavaPlugin {

private static ServerType serverType = ServerType.MULTIARENA;
Expand Down Expand Up @@ -238,9 +236,12 @@ public void onEnable() {
/* Setup plugin messaging channel */
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");

// define logger
var out = plugin.getLogger();

/* Check if lobby location is set. Required for non Bungee servers */
if (config.getLobbyWorldName().isEmpty() && serverType != ServerType.BUNGEE) {
plugin.getLogger().log(java.util.logging.Level.WARNING, "Lobby location is not set!");
out.log(java.util.logging.Level.WARNING, "Lobby location is not set!");
}

/* Load lobby world if not main level
Expand Down Expand Up @@ -323,19 +324,19 @@ public void onEnable() {
if (config.getYml().getBoolean(ConfigPath.GENERAL_CONFIGURATION_ALLOW_PARTIES)) {

if (getServer().getPluginManager().isPluginEnabled("Parties")) {
getLogger().info("Hook into Parties (by AlessioDP) support!");
out.info("Hook into Parties (by AlessioDP) support!");
party = new PartiesAdapter();
} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("PartyAndFriends")) {
getLogger().info("Hook into Party and Friends for Spigot (by Simonsator) support!");
out.info("Hook into Party and Friends for Spigot (by Simonsator) support!");
party = new PAF();
} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) {
getLogger().info("Hook into Spigot Party API for Party and Friends Extended (by Simonsator) support!");
out.info("Hook into Spigot Party API for Party and Friends Extended (by Simonsator) support!");
party = new PAFBungeecordRedisApi();
}

if (party instanceof NoParty) {
party = new com.andrei1058.bedwars.support.party.Internal();
getLogger().info("Loading internal Party system. /party");
out.info("Loading internal Party system. /party");
}
} else {
party = new NoParty();
Expand Down Expand Up @@ -381,7 +382,7 @@ public void onEnable() {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (this.getServer().getPluginManager().getPlugin("Citizens") != null) {
JoinNPC.setCitizensSupport(true);
getLogger().info("Hook into Citizens support. /bw npc");
out.info("Hook into Citizens support. /bw npc");
registerEvents(new CitizensListener());
}

Expand All @@ -392,20 +393,14 @@ public void onEnable() {
this.getLogger().severe("Could not spawn CmdJoin NPCs. Make sure you have right version of Citizens for your server!");
JoinNPC.setCitizensSupport(false);
}
/*if (getServerType() == ServerType.BUNGEE) {
if (Arena.getArenas().size() > 0) {
ArenaSocket.sendMessage(Arena.getArenas().get(0));
}
}*/
}, 5L);

/* Save messages for stats gui items if custom items added, for each language */
Language.setupCustomStatsMessages();


/* PlaceholderAPI Support */
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
getLogger().info("Hooked into PlaceholderAPI support!");
out.info("Hooked into PlaceholderAPI support!");
new PAPISupport().register();
SupportPAPI.setSupportPAPI(new SupportPAPI.withPAPI());
}
Expand Down Expand Up @@ -484,120 +479,54 @@ public void onEnable() {
MoneyConfig.init();

// bStats metrics
Metrics metrics = new Metrics(this, 1885);
metrics.addCustomChart(new SimplePie("server_type", () -> getServerType().toString()));
metrics.addCustomChart(new SimplePie("default_language", () -> Language.getDefaultLanguage().getIso()));
metrics.addCustomChart(new SimplePie("auto_scale", () -> String.valueOf(autoscale)));
metrics.addCustomChart(new SimplePie("party_adapter", () -> party.getClass().getName()));
metrics.addCustomChart(new SimplePie("chat_adapter", () -> chat.getClass().getName()));
metrics.addCustomChart(new SimplePie("level_adapter", () -> getLevelSupport().getClass().getName()));
metrics.addCustomChart(new SimplePie("db_adapter", () -> getRemoteDatabase().getClass().getName()));
metrics.addCustomChart(new SimplePie("map_adapter", () -> String.valueOf(getAPI().getRestoreAdapter().getOwner().getName())));
MetricsManager.initService(this);

if (Bukkit.getPluginManager().getPlugin("VipFeatures") != null) {
try {
IVipFeatures vf = Bukkit.getServicesManager().getRegistration(IVipFeatures.class).getProvider();
vf.registerMiniGame(new VipFeatures(this));
registerEvents(new VipListeners(vf));
getLogger().log(java.util.logging.Level.INFO, "Hook into VipFeatures support.");
out.log(java.util.logging.Level.INFO, "Hook into VipFeatures support.");
} catch (Exception e) {
getLogger().warning("Could not load support for VipFeatures.");
out.warning("Could not load support for VipFeatures.");
} catch (MiniGameAlreadyRegistered miniGameAlreadyRegistered) {
miniGameAlreadyRegistered.printStackTrace();
}
}

Bukkit.getScheduler().runTaskLater(this, () -> getLogger().info("This server is running in " + getServerType().toString() + " with auto-scale " + autoscale), 100L);
Bukkit.getScheduler().runTaskLater(this,
() -> out.info("This server is running in " + getServerType() + " with auto-scale " + autoscale),
100L
);

// Initialize team upgrades
com.andrei1058.bedwars.upgrades.UpgradesManager.init();

// Initialize sidebar manager
if (SidebarService.init()) {
this.getLogger().info("Initializing SidebarLib by andrei1058");
if (SidebarService.init(this)) {
out.info("Initializing SidebarLib by andrei1058");
} else {
this.getLogger().severe("SidebarLib by andrei1058 does not support your server version");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

int playerListRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_LIST_REFRESH);
if (playerListRefreshInterval < 1) {
Bukkit.getLogger().info("Scoreboard names list refresh is disabled. (It is set to " + playerListRefreshInterval + ").");
} else {
if (playerListRefreshInterval < 20) {
Bukkit.getLogger().warning("Scoreboard names list refresh interval is set to: " + playerListRefreshInterval);
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimer(this, new RefreshPlayerListTask(), 1L, playerListRefreshInterval);
}

int placeholdersRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_PLACEHOLDERS_REFRESH_INTERVAL);
if (placeholdersRefreshInterval < 1) {
Bukkit.getLogger().info("Scoreboard placeholders refresh is disabled. (It is set to " + placeholdersRefreshInterval + ").");
} else {
if (placeholdersRefreshInterval < 20) {
Bukkit.getLogger().warning("Scoreboard placeholders refresh interval is set to: " + placeholdersRefreshInterval);
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimer(this, new RefreshPlaceholdersTask(), 1L, placeholdersRefreshInterval);
}

int titleRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_TITLE_REFRESH_INTERVAL);
if (titleRefreshInterval < 1) {
Bukkit.getLogger().info("Scoreboard title refresh is disabled. (It is set to " + titleRefreshInterval + ").");
} else {
if (titleRefreshInterval < 4) {
Bukkit.getLogger().warning("Scoreboard title refresh interval is set to: " + titleRefreshInterval);
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RefreshTitleTask(), 1L, titleRefreshInterval);
}

int healthAnimationInterval = config.getInt(ConfigPath.SB_CONFIG_SIDEBAR_HEALTH_REFRESH);
if (healthAnimationInterval < 1) {
Bukkit.getLogger().info("Scoreboard health animation refresh is disabled. (It is set to " + healthAnimationInterval + ").");
} else {
if (healthAnimationInterval < 20) {
Bukkit.getLogger().warning("Scoreboard health animation refresh interval is set to: " + healthAnimationInterval);
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new RefreshLifeTask(), 1L, healthAnimationInterval);
}

int tabHeaderFooterRefreshInterval = config.getInt(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_REFRESH_INTERVAL);
if (tabHeaderFooterRefreshInterval < 1 || !config.getBoolean(ConfigPath.SB_CONFIG_TAB_HEADER_FOOTER_ENABLE)) {
Bukkit.getLogger().info("Scoreboard Tab header-footer refresh is disabled.");
} else {
if (tabHeaderFooterRefreshInterval < 20) {
Bukkit.getLogger().warning("Scoreboard tab header-footer refresh interval is set to: " + tabHeaderFooterRefreshInterval);
Bukkit.getLogger().warning("It is not recommended to use a value under 20 ticks.");
Bukkit.getLogger().warning("If you expect performance issues please increase its timer.");
}
Bukkit.getScheduler().runTaskTimer(this, new RefreshTabHeaderFooterTask(), 1L, tabHeaderFooterRefreshInterval);
}

registerEvents(new ScoreboardListener());

if (config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_ENABLE_HALLOWEEN)) {
// Halloween Special
HalloweenSpecial.init();
}
// Halloween Special
HalloweenSpecial.init();

// TNT Spoil Feature
SpoilPlayerTNTFeature.init();
}

/**
* Try loading custom adapter support.
*
* @return true when custom adapter was registered.
*/
private boolean handleWorldAdapter() {
Plugin swmPlugin = Bukkit.getPluginManager().getPlugin("SlimeWorldManager");

if (null == swmPlugin){
if (null == swmPlugin) {
return false;
}
PluginDescriptionFile pluginDescription = swmPlugin.getDescription();
Expand Down Expand Up @@ -625,11 +554,11 @@ private boolean handleWorldAdapter() {
}

Constructor<?> constructor = Class.forName(adapterPath).getConstructor(Plugin.class);
getLogger().info("Loading restore adapter: "+adapterPath+" ...");
getLogger().info("Loading restore adapter: " + adapterPath + " ...");

RestoreAdapter candidate = (RestoreAdapter) constructor.newInstance(this);
api.setRestoreAdapter(candidate);
getLogger().info("Hook into "+candidate.getDisplayName()+" as restore adapter.");
getLogger().info("Hook into " + candidate.getDisplayName() + " as restore adapter.");
return true;
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.andrei1058.bedwars.api.events.player.PlayerKillEvent;
import com.andrei1058.bedwars.api.events.player.PlayerLeaveArenaEvent;
import com.andrei1058.bedwars.arena.Arena;
import com.andrei1058.bedwars.metrics.MetricsManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -51,11 +52,13 @@ private SpoilPlayerTNTFeature() {
}

public static void init() {
if (BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_PERFORMANCE_SPOIL_TNT_PLAYERS)) {
var enable = BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_PERFORMANCE_SPOIL_TNT_PLAYERS);
if (enable) {
if (instance == null) {
instance = new SpoilPlayerTNTFeature();
}
}
MetricsManager.appendPie("tnt_spoil_enable", () -> String.valueOf(enable));
}

private static class ParticleTask implements Runnable {
Expand Down Expand Up @@ -109,12 +112,11 @@ public void onPlace(BlockPlaceEvent event) {
if (arena == null || !arena.isPlayer(event.getPlayer()) || arena.isSpectator(event.getPlayer())) return;
if (inHand.getType() == Material.TNT) {
if (!instance.playersWithTnt.contains(event.getPlayer())) return;
Bukkit.getScheduler().runTaskLater(BedWars.plugin,
() -> {
if (!event.getPlayer().getInventory().contains(Material.TNT)) {
instance.playersWithTnt.remove(event.getPlayer());
}
}, 1L);
Bukkit.getScheduler().runTaskLater(BedWars.plugin, () -> {
if (!event.getPlayer().getInventory().contains(Material.TNT)) {
instance.playersWithTnt.remove(event.getPlayer());
}
}, 1L);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package com.andrei1058.bedwars.halloween;

import com.andrei1058.bedwars.BedWars;
import com.andrei1058.bedwars.api.configuration.ConfigPath;
import com.andrei1058.bedwars.halloween.shop.PumpkinContent;
import com.andrei1058.bedwars.metrics.MetricsManager;
import com.andrei1058.bedwars.shop.ShopManager;
import com.andrei1058.bedwars.shop.main.ShopCategory;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -54,10 +56,14 @@ private HalloweenSpecial() {
* Initialize Halloween Special.
*/
public static void init() {
if (INSTANCE == null) {
if (!checkAvailabilityDate()) return;
INSTANCE = new HalloweenSpecial();
var enable = BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_ENABLE_HALLOWEEN);
if (enable) {
if (INSTANCE == null && checkAvailabilityDate()) {
//noinspection InstantiationOfUtilityClass
INSTANCE = new HalloweenSpecial();
}
}
MetricsManager.appendPie("halloween_special_enable", () -> String.valueOf(enable));
}

protected static boolean checkAvailabilityDate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.andrei1058.bedwars.metrics;

import com.andrei1058.bedwars.BedWars;
import com.andrei1058.bedwars.api.language.Language;
import com.andrei1058.bedwars.support.citizens.JoinNPC;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;

import java.util.concurrent.Callable;

public class MetricsManager {

private static MetricsManager instance;

private final Metrics metrics;

private MetricsManager(BedWars plugin) {
metrics = new Metrics(plugin, 97320);

// base metrics
metrics.addCustomChart(new SimplePie("server_type", () -> BedWars.getServerType().toString()));
metrics.addCustomChart(new SimplePie("default_language", () -> Language.getDefaultLanguage().getIso()));
metrics.addCustomChart(new SimplePie("auto_scale", () -> String.valueOf(BedWars.autoscale)));
metrics.addCustomChart(new SimplePie("party_adapter", () -> BedWars.getParty().getClass().getName()));
metrics.addCustomChart(new SimplePie("chat_adapter", () -> BedWars.getChatSupport().getClass().getName()));
metrics.addCustomChart(new SimplePie("level_adapter", () -> BedWars.getLevelSupport().getClass().getName()));
metrics.addCustomChart(new SimplePie("db_adapter", () -> BedWars.getRemoteDatabase().getClass().getName()));
metrics.addCustomChart(new SimplePie("map_adapter", () -> BedWars.getAPI().getRestoreAdapter().getClass().getName()));
metrics.addCustomChart(new SimplePie("citizens_support", () -> String.valueOf(JoinNPC.isCitizensSupport())));
}

public Metrics getMetrics() {
return metrics;
}

public static void appendPie(String id, Callable<String> callable) {
if (null == instance) {
throw new RuntimeException("Metrics manager is not initialized!");
}
instance.getMetrics().addCustomChart(new SimplePie(id, callable));
}

public static void initService(BedWars plugin) {
if (null != instance) {
return;
}
instance = new MetricsManager(plugin);
}
}
Loading

0 comments on commit a6bd4a4

Please sign in to comment.