Change few things to optimize

This brings no particular changes, but hopefully coding will start again soon.
I just changed two methods to dynamically get the UhcCore instance instead of taking it as an argument.
This commit is contained in:
Lorenzo Dellacà
2021-01-10 00:37:11 +01:00
parent 3928c0ae9e
commit b45f7f5a8f
9 changed files with 92 additions and 214 deletions

View File

@@ -21,12 +21,19 @@ public class UhcCore extends JavaPlugin
public static Logger logger;
private PluginManager pluginManager;
private static UhcCore instance;
public static UhcCore getInstance()
{ return instance; }
// Method called when the plugin is being loaded.
@Override
public void onEnable()
{
instance = this;
// We need to run this in a task, because the plugin has to be initialized AFTER all the worlds are loaded.
// todo: after a few months, this sounds like a badly implemented idea
getServer().getScheduler().runTask(this, ()->
{

View File

@@ -61,7 +61,7 @@ public class PlayerDeathRespawnListener implements Listener
{
// Spawn a Firework where the player died.
CommonValues.spawnFirework(plugin, player.getLocation(), 15L);
CommonValues.spawnFirework(player.getLocation(), 15L);
// Load the player name.
String playerName = player.getName();
@@ -223,7 +223,7 @@ public class PlayerDeathRespawnListener implements Listener
for(Location loc : CommonValues.fireworksLocations)
{
debugger.sendDebugMessage(Level.INFO, "FIREWORK LOC: " + loc);
CommonValues.spawnFirework(plugin, loc, 10L);
CommonValues.spawnFirework(loc, 10L);
}

View File

@@ -58,6 +58,8 @@ public class CommonValues {
public static int borderX, borderZ, borderSize;
// todo: move following methods to their separate Utils class; this one is just for caching values...
// Function to check how many players a team has.
// This function returns the total number of alive teams.
public static void updatePlayersPerTeam()
@@ -100,7 +102,7 @@ public class CommonValues {
player.getInventory().setItem(4, CommonValues.teamsItem);
}
public static void spawnFirework(UhcCore plugin, Location location, long detonateDelay) {
public static void spawnFirework(Location location, long detonateDelay) {
Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
@@ -109,6 +111,8 @@ public class CommonValues {
fireworkMeta.addEffect(FireworkEffect.builder().withColor(Color.RED).flicker(true).build());
firework.setFireworkMeta(fireworkMeta);
UhcCore plugin = UhcCore.getInstance();
plugin.getServer().getScheduler().runTaskLater(plugin, firework::detonate, detonateDelay);
}