From b45f7f5a8fe3f8eff1a89080ed50492c56601f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenzo=20Dellac=C3=A0?= Date: Sun, 10 Jan 2021 00:37:11 +0100 Subject: [PATCH] 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. --- .gitignore | 71 ++++++++++ .idea/dictionaries/Lorenzo.xml | 10 -- .idea/uiDesigner.xml | 124 ------------------ .idea/vcs.xml | 6 + .idea/workspace.xml | 77 ----------- UHC-Core.iml | 1 + .../mindoverflow/network/uhccore/UhcCore.java | 7 + .../listeners/PlayerDeathRespawnListener.java | 4 +- .../network/uhccore/utils/CommonValues.java | 6 +- 9 files changed, 92 insertions(+), 214 deletions(-) create mode 100644 .gitignore delete mode 100644 .idea/dictionaries/Lorenzo.xml delete mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b155595 --- /dev/null +++ b/.gitignore @@ -0,0 +1,71 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser \ No newline at end of file diff --git a/.idea/dictionaries/Lorenzo.xml b/.idea/dictionaries/Lorenzo.xml deleted file mode 100644 index 7ee5073..0000000 --- a/.idea/dictionaries/Lorenzo.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - bukkit - bungeecord - textcomponent - yamls - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 9fab3d0..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1582211391295 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/UHC-Core.iml b/UHC-Core.iml index 43c5e7f..602c66c 100644 --- a/UHC-Core.iml +++ b/UHC-Core.iml @@ -27,5 +27,6 @@ + \ No newline at end of file diff --git a/src/net/mindoverflow/network/uhccore/UhcCore.java b/src/net/mindoverflow/network/uhccore/UhcCore.java index fefe385..64ec3ce 100644 --- a/src/net/mindoverflow/network/uhccore/UhcCore.java +++ b/src/net/mindoverflow/network/uhccore/UhcCore.java @@ -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, ()-> { diff --git a/src/net/mindoverflow/network/uhccore/listeners/PlayerDeathRespawnListener.java b/src/net/mindoverflow/network/uhccore/listeners/PlayerDeathRespawnListener.java index 7ecf63c..ec027a8 100644 --- a/src/net/mindoverflow/network/uhccore/listeners/PlayerDeathRespawnListener.java +++ b/src/net/mindoverflow/network/uhccore/listeners/PlayerDeathRespawnListener.java @@ -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); } diff --git a/src/net/mindoverflow/network/uhccore/utils/CommonValues.java b/src/net/mindoverflow/network/uhccore/utils/CommonValues.java index fde6427..f01522d 100644 --- a/src/net/mindoverflow/network/uhccore/utils/CommonValues.java +++ b/src/net/mindoverflow/network/uhccore/utils/CommonValues.java @@ -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); }