Remove Static Abuse - CWing (Needs more work)

This commit is contained in:
nossr50 2019-07-03 01:12:47 -07:00
parent 982e67af70
commit 35f3c5d585
5 changed files with 77 additions and 72 deletions

View File

@ -45,15 +45,23 @@ import com.gmail.nossr50.worldguard.WorldGuardManager;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class mcMMO extends JavaPlugin { public class mcMMO extends JavaPlugin {
/* Managers */ /* Managers */
@ -572,10 +580,10 @@ public class mcMMO extends JavaPlugin {
private void registerCustomRecipes() { private void registerCustomRecipes() {
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
if (configManager.getConfigItems().isChimaeraWingEnabled()) { if (configManager.getConfigItems().isChimaeraWingEnabled()) {
Recipe recipe = ChimaeraWing.getChimaeraWingRecipe(); Recipe recipe = getChimaeraWingRecipe();
if(!SkillUtils.hasRecipeBeenRegistered(recipe)) if(!SkillUtils.hasRecipeBeenRegistered(recipe))
getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe()); getServer().addRecipe(getChimaeraWingRecipe());
} }
}, 40); }, 40);
} }
@ -586,7 +594,7 @@ public class mcMMO extends JavaPlugin {
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks); new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
// Cleanup the backups folder // Cleanup the backups folder
new CleanBackupFilesTask().runTaskAsynchronously(this); new CleanBackupFilesTask(this).runTaskAsynchronously(this);
// Bleed timer (Runs every 0.5 seconds) // Bleed timer (Runs every 0.5 seconds)
new BleedTimerTask().runTaskTimer(this, Misc.TICK_CONVERSION_FACTOR, (Misc.TICK_CONVERSION_FACTOR / 2)); new BleedTimerTask().runTaskTimer(this, Misc.TICK_CONVERSION_FACTOR, (Misc.TICK_CONVERSION_FACTOR / 2));
@ -595,9 +603,9 @@ public class mcMMO extends JavaPlugin {
long purgeIntervalTicks = getConfigManager().getConfigDatabase().getConfigSectionCleaning().getPurgeInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR; long purgeIntervalTicks = getConfigManager().getConfigDatabase().getConfigSectionCleaning().getPurgeInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
if (getDatabaseCleaningSettings().isOnlyPurgeAtStartup()) { if (getDatabaseCleaningSettings().isOnlyPurgeAtStartup()) {
new UserPurgeTask().runTaskLaterAsynchronously(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup. new UserPurgeTask(this).runTaskLaterAsynchronously(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
} else if (purgeIntervalTicks > 0) { } else if (purgeIntervalTicks > 0) {
new UserPurgeTask().runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks); new UserPurgeTask(this).runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks);
} }
//Party System Stuff //Party System Stuff
@ -621,10 +629,46 @@ public class mcMMO extends JavaPlugin {
} }
if (configManager.getConfigNotifications().getConfigNotificationGeneral().isPlayerTips()) { if (configManager.getConfigNotifications().getConfigNotificationGeneral().isPlayerTips()) {
new NotifySquelchReminderTask().runTaskTimer(this, 60, ((20 * 60) * 60)); new NotifySquelchReminderTask(this).runTaskTimer(this, 60, ((20 * 60) * 60));
} }
} }
//TODO: Add this stuff to DSM, this location is temporary
private ShapelessRecipe getChimaeraWingRecipe() {
Material ingredient = Material.matchMaterial(configManager.getConfigItems().getChimaeraWingRecipeMats());
if(ingredient == null)
ingredient = Material.FEATHER;
int amount = configManager.getConfigItems().getChimaeraWingUseCost();
ShapelessRecipe chimaeraWing = new ShapelessRecipe(new NamespacedKey(this, "Chimaera"), getChimaeraWing());
chimaeraWing.addIngredient(amount, ingredient);
return chimaeraWing;
}
//TODO: Add this stuff to DSM, this location is temporary
public ItemStack getChimaeraWing() {
Material ingredient = Material.matchMaterial(configManager.getConfigItems().getChimaeraWingRecipeMats());
if(ingredient == null)
ingredient = Material.FEATHER;
//TODO: Make it so Chimaera wing amounts made is customizeable
ItemStack itemStack = new ItemStack(ingredient, 1);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.GOLD + localeManager.getString("Item.ChimaeraWing.Name"));
List<String> itemLore = new ArrayList<>();
itemLore.add("mcMMO Item");
itemLore.add(localeManager.getString("Item.ChimaeraWing.Lore"));
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public DynamicSettingsManager getDynamicSettingsManager() { public DynamicSettingsManager getDynamicSettingsManager() {
return dynamicSettingsManager; return dynamicSettingsManager;
} }

View File

@ -88,7 +88,7 @@ public final class PartyManager {
if (warmup > 0) { if (warmup > 0) {
teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Commencing", warmup)); teleportingPlayer.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Commencing", warmup));
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget).runTaskLater(pluginRef, 20 * warmup); new TeleportationWarmup(pluginRef, mcMMOPlayer, mcMMOTarget).runTaskLater(pluginRef, 20 * warmup);
} else { } else {
pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer); pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.runnables.items; package com.gmail.nossr50.runnables.items;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -11,9 +12,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class ChimaeraWingWarmup extends BukkitRunnable { public class ChimaeraWingWarmup extends BukkitRunnable {
private mcMMO pluginRef;
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
public ChimaeraWingWarmup(McMMOPlayer mcMMOPlayer) { public ChimaeraWingWarmup(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
this.pluginRef = pluginRef;
this.mcMMOPlayer = mcMMOPlayer; this.mcMMOPlayer = mcMMOPlayer;
} }
@ -25,8 +28,9 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
private void checkChimaeraWingTeleport() { private void checkChimaeraWingTeleport() {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation(); Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation();
ChimaeraWing chimaeraWing = new ChimaeraWing(pluginRef, mcMMOPlayer);
if (player.getLocation().distanceSquared(previousLocation) > 1.0 || !player.getInventory().containsAtLeast(ChimaeraWing.getChimaeraWing(0), 1)) { if (player.getLocation().distanceSquared(previousLocation) > 1.0 || !player.getInventory().containsAtLeast(pluginRef.getChimaeraWing(), 1)) {
player.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Cancelled")); player.sendMessage(pluginRef.getLocaleManager().getString("Teleport.Cancelled"));
mcMMOPlayer.setTeleportCommenceLocation(null); mcMMOPlayer.setTeleportCommenceLocation(null);
return; return;
@ -51,6 +55,6 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
} }
} }
ChimaeraWing.chimaeraExecuteTeleport(); chimaeraWing.chimaeraExecuteTeleport();
} }
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.runnables.items; package com.gmail.nossr50.runnables.items;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Location; import org.bukkit.Location;
@ -8,10 +9,12 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class TeleportationWarmup extends BukkitRunnable { public class TeleportationWarmup extends BukkitRunnable {
private final mcMMO pluginRef;
private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOPlayer;
private McMMOPlayer mcMMOTarget; private McMMOPlayer mcMMOTarget;
public TeleportationWarmup(McMMOPlayer mcMMOPlayer, McMMOPlayer mcMMOTarget) { public TeleportationWarmup(mcMMO pluginRef, McMMOPlayer mcMMOPlayer, McMMOPlayer mcMMOTarget) {
this.pluginRef = pluginRef;
this.mcMMOPlayer = mcMMOPlayer; this.mcMMOPlayer = mcMMOPlayer;
this.mcMMOTarget = mcMMOTarget; this.mcMMOTarget = mcMMOTarget;
} }

View File

@ -2,41 +2,36 @@ package com.gmail.nossr50.util;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup; import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
public final class ChimaeraWing { public final class ChimaeraWing {
private static McMMOPlayer mcMMOPlayer; private final mcMMO pluginRef;
private static Location location; private final McMMOPlayer mcMMOPlayer;
private final Player player;
private final Location location;
private ChimaeraWing() { public ChimaeraWing(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
this.pluginRef = pluginRef;
this.mcMMOPlayer = mcMMOPlayer;
this.player = mcMMOPlayer.getPlayer();
this.location = player.getLocation();
} }
/** /**
* Check for item usage. * Check for item usage.
* *
* @param player Player whose item usage to check
*/ */
public static void activationCheck(Player player) { public void activationCheck() {
if (!pluginRef.getConfigManager().getConfigItems().isChimaeraWingEnabled()) {
return;
}
ItemStack inHand = player.getInventory().getItemInMainHand(); ItemStack inHand = player.getInventory().getItemInMainHand();
if (!ItemUtils.isChimaeraWing(inHand)) { if (!ItemUtils.isChimaeraWing(inHand)) {
@ -48,12 +43,6 @@ public final class ChimaeraWing {
return; return;
} }
mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
//Not loaded
if (mcMMOPlayer == null)
return;
if (mcMMOPlayer.getTeleportCommenceLocation() != null) { if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
return; return;
} }
@ -90,11 +79,9 @@ public final class ChimaeraWing {
} }
} }
location = player.getLocation();
if (pluginRef.getConfigManager().getConfigItems().isPreventUndergroundUse()) { if (pluginRef.getConfigManager().getConfigItems().isPreventUndergroundUse()) {
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) { if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(amount - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost()))); player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost());
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail"); pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
player.updateInventory(); player.updateInventory();
player.setVelocity(new Vector(0, 0.5D, 0)); player.setVelocity(new Vector(0, 0.5D, 0));
@ -110,13 +97,13 @@ public final class ChimaeraWing {
if (warmup > 0) { if (warmup > 0) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup)); pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(pluginRef, 20 * warmup); new ChimaeraWingWarmup(pluginRef, mcMMOPlayer).runTaskLater(pluginRef, 20 * warmup);
} else { } else {
chimaeraExecuteTeleport(); chimaeraExecuteTeleport();
} }
} }
public static void chimaeraExecuteTeleport() { public void chimaeraExecuteTeleport() {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
if (pluginRef.getConfigManager().getConfigItems().doesChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) { if (pluginRef.getConfigManager().getConfigItems().doesChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
@ -130,7 +117,7 @@ public final class ChimaeraWing {
} }
} }
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(player.getInventory().getItemInMainHand().getAmount() - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost()))); player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost());
player.updateInventory(); player.updateInventory();
mcMMOPlayer.actualizeChimeraWingLastUse(); mcMMOPlayer.actualizeChimeraWingLastUse();
mcMMOPlayer.setTeleportCommenceLocation(null); mcMMOPlayer.setTeleportCommenceLocation(null);
@ -141,37 +128,4 @@ public final class ChimaeraWing {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass"); pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
} }
public static ItemStack getChimaeraWing(int amount) {
Material ingredient = Material.matchMaterial(pluginRef.getConfigManager().getConfigItems().getChimaeraWingRecipeMats());
if(ingredient == null)
ingredient = Material.FEATHER;
ItemStack itemStack = new ItemStack(ingredient, amount);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.GOLD + pluginRef.getLocaleManager().getString("Item.ChimaeraWing.Name"));
List<String> itemLore = new ArrayList<>();
itemLore.add("mcMMO Item");
itemLore.add(pluginRef.getLocaleManager().getString("Item.ChimaeraWing.Lore"));
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ShapelessRecipe getChimaeraWingRecipe() {
Material ingredient = Material.matchMaterial(pluginRef.getConfigManager().getConfigItems().getChimaeraWingRecipeMats());
if(ingredient == null)
ingredient = Material.FEATHER;
int amount = pluginRef.getConfigManager().getConfigItems().getChimaeraWingUseCost();
ShapelessRecipe chimaeraWing = new ShapelessRecipe(new NamespacedKey(pluginRef, "Chimaera"), getChimaeraWing(1));
chimaeraWing.addIngredient(amount, ingredient);
return chimaeraWing;
}
} }