diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 24f5c54e7..dc1469ed2 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -45,15 +45,23 @@ import com.gmail.nossr50.worldguard.WorldGuardManager; import net.shatteredlands.shatt.backup.ZipLibrary; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class mcMMO extends JavaPlugin { /* Managers */ @@ -572,10 +580,10 @@ public class mcMMO extends JavaPlugin { private void registerCustomRecipes() { getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { if (configManager.getConfigItems().isChimaeraWingEnabled()) { - Recipe recipe = ChimaeraWing.getChimaeraWingRecipe(); + Recipe recipe = getChimaeraWingRecipe(); if(!SkillUtils.hasRecipeBeenRegistered(recipe)) - getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe()); + getServer().addRecipe(getChimaeraWingRecipe()); } }, 40); } @@ -586,7 +594,7 @@ public class mcMMO extends JavaPlugin { new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks); // Cleanup the backups folder - new CleanBackupFilesTask().runTaskAsynchronously(this); + new CleanBackupFilesTask(this).runTaskAsynchronously(this); // Bleed timer (Runs every 0.5 seconds) 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; 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) { - new UserPurgeTask().runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks); + new UserPurgeTask(this).runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks); } //Party System Stuff @@ -621,10 +629,46 @@ public class mcMMO extends JavaPlugin { } 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 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() { return dynamicSettingsManager; } diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index bbee24774..2df76bc35 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -88,7 +88,7 @@ public final class PartyManager { if (warmup > 0) { 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 { pluginRef.getEventManager().handlePartyTeleportEvent(teleportingPlayer, targetPlayer); } diff --git a/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java b/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java index 68bb2076e..cb9543769 100644 --- a/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java +++ b/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.runnables.items; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.Misc; @@ -11,9 +12,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; public class ChimaeraWingWarmup extends BukkitRunnable { + private mcMMO pluginRef; private McMMOPlayer mcMMOPlayer; - public ChimaeraWingWarmup(McMMOPlayer mcMMOPlayer) { + public ChimaeraWingWarmup(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { + this.pluginRef = pluginRef; this.mcMMOPlayer = mcMMOPlayer; } @@ -25,8 +28,9 @@ public class ChimaeraWingWarmup extends BukkitRunnable { private void checkChimaeraWingTeleport() { Player player = mcMMOPlayer.getPlayer(); 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")); mcMMOPlayer.setTeleportCommenceLocation(null); return; @@ -51,6 +55,6 @@ public class ChimaeraWingWarmup extends BukkitRunnable { } } - ChimaeraWing.chimaeraExecuteTeleport(); + chimaeraWing.chimaeraExecuteTeleport(); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java b/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java index ba0249d5b..de6aa7153 100644 --- a/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java +++ b/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.runnables.items; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.skills.SkillUtils; import org.bukkit.Location; @@ -8,10 +9,12 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; public class TeleportationWarmup extends BukkitRunnable { + private final mcMMO pluginRef; private McMMOPlayer mcMMOPlayer; private McMMOPlayer mcMMOTarget; - public TeleportationWarmup(McMMOPlayer mcMMOPlayer, McMMOPlayer mcMMOTarget) { + public TeleportationWarmup(mcMMO pluginRef, McMMOPlayer mcMMOPlayer, McMMOPlayer mcMMOTarget) { + this.pluginRef = pluginRef; this.mcMMOPlayer = mcMMOPlayer; this.mcMMOTarget = mcMMOTarget; } diff --git a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java index f7a27736e..54230f171 100644 --- a/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java +++ b/src/main/java/com/gmail/nossr50/util/ChimaeraWing.java @@ -2,41 +2,36 @@ package com.gmail.nossr50.util; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ShapelessRecipe; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.List; - public final class ChimaeraWing { - private static McMMOPlayer mcMMOPlayer; - private static Location location; + private final mcMMO pluginRef; + 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. * - * @param player Player whose item usage to check */ - public static void activationCheck(Player player) { - if (!pluginRef.getConfigManager().getConfigItems().isChimaeraWingEnabled()) { - return; - } - + public void activationCheck() { ItemStack inHand = player.getInventory().getItemInMainHand(); if (!ItemUtils.isChimaeraWing(inHand)) { @@ -48,12 +43,6 @@ public final class ChimaeraWing { return; } - mcMMOPlayer = pluginRef.getUserManager().getPlayer(player); - - //Not loaded - if (mcMMOPlayer == null) - return; - if (mcMMOPlayer.getTeleportCommenceLocation() != null) { return; } @@ -90,11 +79,9 @@ public final class ChimaeraWing { } } - location = player.getLocation(); - if (pluginRef.getConfigManager().getConfigItems().isPreventUndergroundUse()) { 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"); player.updateInventory(); player.setVelocity(new Vector(0, 0.5D, 0)); @@ -110,13 +97,13 @@ public final class ChimaeraWing { if (warmup > 0) { 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 { chimaeraExecuteTeleport(); } } - public static void chimaeraExecuteTeleport() { + public void chimaeraExecuteTeleport() { Player player = mcMMOPlayer.getPlayer(); 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(); mcMMOPlayer.actualizeChimeraWingLastUse(); mcMMOPlayer.setTeleportCommenceLocation(null); @@ -141,37 +128,4 @@ public final class ChimaeraWing { 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 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; - } }