From dceee5554d3241123e3ea656ee25c633a7c86203 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 28 Jan 2020 16:32:28 +0000 Subject: [PATCH 01/15] Fix CombatUtils NPE due to arrows from unloaded players --- .../com/gmail/nossr50/listeners/EntityListener.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 17e18fb4d..2f191cc6e 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -381,12 +381,15 @@ public class EntityListener implements Listener { } //Deflect checks - UnarmedManager unarmedManager = UserManager.getPlayer(defendingPlayer).getUnarmedManager(); + final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(defendingPlayer); + if (mcMMOPlayer != null) { + UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); - if (unarmedManager.canDeflect()) { - if(unarmedManager.deflectCheck()) { - event.setCancelled(true); - return; + if (unarmedManager.canDeflect()) { + if (unarmedManager.deflectCheck()) { + event.setCancelled(true); + return; + } } } } else { From 816b64cb7089685a2adaf179e2049221c9bd50ce Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 28 Jan 2020 16:37:02 +0000 Subject: [PATCH 02/15] Track spectral arrows for combat --- Changelog.txt | 4 ++++ src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index 354ea638e..3a2b5ef9b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,7 @@ +Version 2.1.115 + Fixed an issue with arrows causing exceptions with players not yet having data loaded + Spectral arrows are now tracked by mcMMO + Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales Fixed a bug where newer versions of MySQL did not like our rank command diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index bf5539c0b..99a1ee9f4 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -380,7 +380,7 @@ public final class CombatUtils { } } } - else if (entityType == EntityType.ARROW) { + else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { Arrow arrow = (Arrow) damager; ProjectileSource projectileSource = arrow.getShooter(); From 4eef4a3e417dcbf9dd45ad9bf6288fa0107c72ab Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 4 Feb 2020 23:29:51 +0000 Subject: [PATCH 03/15] Fix CCE from spectral arrows (Fixes #4114) --- src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 99a1ee9f4..fa6e052b9 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -221,7 +221,7 @@ public final class CombatUtils { } - private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) { + private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, AbstractArrow arrow) { double initialDamage = event.getDamage(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); @@ -381,7 +381,7 @@ public final class CombatUtils { } } else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { - Arrow arrow = (Arrow) damager; + AbstractArrow arrow = (AbstractArrow) damager; ProjectileSource projectileSource = arrow.getShooter(); if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) { From 11ca0d9ff101cd77f5e26dcacbc3a666c4ac305e Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 4 Feb 2020 23:36:54 +0000 Subject: [PATCH 04/15] Fix 1.13.x archery compat --- src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index fa6e052b9..42afeeca3 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -221,7 +221,7 @@ public final class CombatUtils { } - private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, AbstractArrow arrow) { + private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Projectile arrow) { double initialDamage = event.getDamage(); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); @@ -381,7 +381,7 @@ public final class CombatUtils { } } else if (entityType == EntityType.ARROW || entityType == EntityType.SPECTRAL_ARROW) { - AbstractArrow arrow = (AbstractArrow) damager; + Projectile arrow = (Projectile) damager; ProjectileSource projectileSource = arrow.getShooter(); if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) { From 4f161812aa85c6fb138b4d6d69233dd103a13003 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 9 Feb 2020 22:47:17 +0000 Subject: [PATCH 05/15] Use minimum level of salvagable properly --- .../com/gmail/nossr50/skills/salvage/SalvageManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 02a20cec2..5d3cc1134 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -82,11 +82,11 @@ public class SalvageManager extends SkillManager { return; } - /*int skillLevel = getSkillLevel(); - int minimumSalvageableLevel = salvageable.getMinimumLevel();*/ + /*int skillLevel = getSkillLevel();*/ + int minimumSalvageableLevel = salvageable.getMinimumLevel(); // Level check - if (!RankUtils.hasUnlockedSubskill(player, SubSkillType.SALVAGE_SCRAP_COLLECTOR)) { + if (getSkillLevel() < minimumSalvageableLevel) { NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Salvage.Skills.Adept.Level", String.valueOf(RankUtils.getUnlockLevel(SubSkillType.SALVAGE_ARCANE_SALVAGE)), StringUtils.getPrettyItemString(item.getType())); return; } From 8e8024e3e1d52f6803948eeadb85dc9539460746 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 9 Feb 2020 22:50:28 +0000 Subject: [PATCH 06/15] update changelog --- Changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.txt b/Changelog.txt index 3a2b5ef9b..9f373f01f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,7 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO + Use minimum level of salvageable properly Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales From 38d64f207d0532f8158eb9cfc0c8be3261c02200 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 12 Feb 2020 02:06:49 +0000 Subject: [PATCH 07/15] Fix default permission for Critical Strikes --- Changelog.txt | 1 + src/main/resources/plugin.yml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 9f373f01f..232675755 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,6 +2,7 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly + Fix axes Critical Strikes default permissions Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7f23ba9a3..7006f2318 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -273,7 +273,7 @@ permissions: description: Allows access to all Axes abilities children: mcmmo.ability.axes.axemastery: true - mcmmo.ability.axes.criticalhit: true + mcmmo.ability.axes.criticalstrikes: true mcmmo.ability.axes.greaterimpact: true mcmmo.ability.axes.armorimpact: true mcmmo.ability.axes.skullsplitter: true @@ -282,8 +282,8 @@ permissions: description: Adds damage to axes mcmmo.ability.axes.axemastery: description: Allows bonus damage from Axes - mcmmo.ability.axes.criticalhit: - description: Allows access to the Critical Hit ability + mcmmo.ability.axes.criticalstrikes: + description: Allows access to the Critical Strikes ability mcmmo.ability.axes.greaterimpact: description: Allows access to the Greater Impact ability mcmmo.ability.axes.armorimpact: From ab6dbe306d04e0d66fe5429d8a3128cab63bdb3c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 11:38:48 -0800 Subject: [PATCH 08/15] Fix potential NPE for salvage --- Changelog.txt | 3 ++- .../java/com/gmail/nossr50/skills/salvage/SalvageManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 232675755..53227539a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,7 +2,8 @@ Version 2.1.115 Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly - Fix axes Critical Strikes default permissions + Fix Axes Critical Strikes default permissions ( new fixed permission: mcmmo.ability.axes.criticalstrikes ) + Fix potential null pointer exception for salvage Version 2.1.114 Fix some more locale usages, should aim to further prevent issues with oddball locales diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 5d3cc1134..327cfcd95 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -66,7 +66,7 @@ public class SalvageManager extends SkillManager { Salvageable salvageable = mcMMO.getSalvageableManager().getSalvageable(item.getType()); - if (item.getItemMeta().isUnbreakable()) { + if (item.getItemMeta() != null && item.getItemMeta().isUnbreakable()) { NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable"); return; } From 4e21f1a2009689872d9867d9be34c5087c516b44 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 13:27:21 -0800 Subject: [PATCH 09/15] tweak and fix salvage result chance --- Changelog.txt | 1 + .../com/gmail/nossr50/skills/herbalism/HerbalismManager.java | 3 +-- .../java/com/gmail/nossr50/skills/salvage/SalvageManager.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 53227539a..adaf42ab0 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.115 + Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO Use minimum level of salvageable properly diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 18547bd99..9b6a68881 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -437,8 +437,7 @@ public class HerbalismManager extends SkillManager { } private HashSet getBrokenChorusBlocks(BlockState originalBreak) { - HashSet traversedBlocks = grabChorusTreeBrokenBlocksRecursive(originalBreak.getBlock(), new HashSet<>()); - return traversedBlocks; + return grabChorusTreeBrokenBlocksRecursive(originalBreak.getBlock(), new HashSet<>()); } private HashSet grabChorusTreeBrokenBlocksRecursive(Block currentBlock, HashSet traversed) { diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java index 327cfcd95..063fd746e 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java @@ -118,8 +118,8 @@ public class SalvageManager extends SkillManager { for(int x = 0; x < potentialSalvageYield-1; x++) { if(RandomChanceUtil.rollDice(chanceOfSuccess, 100)) { - chanceOfSuccess-=2; - Math.max(chanceOfSuccess, 95); + chanceOfSuccess-=3; + chanceOfSuccess = Math.max(chanceOfSuccess, 90); lotteryResults+=1; } From 8f265441884a2aba2b359cd924b25eda2ac74199 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 13:51:10 -0800 Subject: [PATCH 10/15] Immature plants will be replanted if weilding a hoe --- Changelog.txt | 1 + .../skills/herbalism/HerbalismManager.java | 37 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index adaf42ab0..69da6676f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.115 + Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 9b6a68881..3eb0951f2 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -143,6 +143,9 @@ public class HerbalismManager extends SkillManager { //Grab all broken blocks HashSet brokenBlocks = getBrokenHerbalismBlocks(blockBreakEvent); + if(brokenBlocks.size() == 0) + return; + //Handle rewards, xp, ability interactions, etc processHerbalismOnBlocksBroken(blockBreakEvent, brokenBlocks); } @@ -157,7 +160,12 @@ public class HerbalismManager extends SkillManager { //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - processGreenThumbPlants(originalBreak, isGreenTerraActive()); + processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + } + + //When replanting a immature crop we cancel the block break event and back out + if(blockBreakEvent.isCancelled()) { + return; } /* @@ -339,9 +347,11 @@ public class HerbalismManager extends SkillManager { //Calculate XP if(plantData instanceof Ageable) { Ageable plantAgeable = (Ageable) plantData; + if(isAgeableMature(plantAgeable) || isBizarreAgeable(plantData)) { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenBlockNewState.getType()); } + } else { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenPlantBlock.getType()); } @@ -635,10 +645,18 @@ public class HerbalismManager extends SkillManager { * @param blockState The {@link BlockState} to check ability activation for * @param greenTerra boolean to determine if greenTerra is active or not */ - private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) { - if (!BlockUtils.isFullyGrown(blockState)) + private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + BlockData blockData = blockState.getBlockData(); + + if (!(blockData instanceof Ageable)) return; + //If the ageable is NOT mature and the player is NOT using a hoe, abort + if(!isAgeableMature((Ageable) blockData) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { + return; + } + + Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); Material seed = null; @@ -678,7 +696,7 @@ public class HerbalismManager extends SkillManager { return; } - if (!processGrowingPlants(blockState, greenTerra)) { + if (!processGrowingPlants(blockState, blockBreakEvent, greenTerra)) { return; } @@ -695,11 +713,18 @@ public class HerbalismManager extends SkillManager { new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } - private boolean processGrowingPlants(BlockState blockState, boolean greenTerra) { + private boolean processGrowingPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + Ageable crops = (Ageable) blockState.getBlockData(); int greenThumbStage = getGreenThumbStage(); + //Immature plants will start over at 0 + if(!isAgeableMature(crops)) { + crops.setAge(0); + blockBreakEvent.setCancelled(true); + return true; + } + blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); - Ageable crops = (Ageable) blockState.getBlockData(); switch (blockState.getType()) { From e2073ff9f7c8fe92ebf8c0fb785ce5cfba4958c0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 15:58:53 -0800 Subject: [PATCH 11/15] Immature crop replanting, green thumb tweaks, replant accidental break protection --- Changelog.txt | 2 + .../gmail/nossr50/datatypes/meta/OldName.java | 1 + .../meta/RecentlyReplantedCropMeta.java | 17 ++++ src/main/java/com/gmail/nossr50/mcMMO.java | 1 + .../runnables/skills/DelayedCropReplant.java | 90 +++++++++++++++++++ .../skills/herbalism/HerbalismManager.java | 75 +++++++++++----- .../util/skills/ParticleEffectUtils.java | 15 +++- .../nossr50/util/sounds/SoundManager.java | 5 ++ 8 files changed, 179 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java create mode 100644 src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java diff --git a/Changelog.txt b/Changelog.txt index 69da6676f..a10e35f58 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Hoes no longer give free replants + There is now a feature in place to prevent breaking a newly automatically replanted (via green thumb) crop from being breakable for a few seconds after it appears Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java b/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java index b300f92cc..137399009 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/OldName.java @@ -12,4 +12,5 @@ public class OldName extends FixedMetadataValue { { super(plugin, oldName); } + } diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java new file mode 100644 index 000000000..5c630f7bc --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java @@ -0,0 +1,17 @@ +package com.gmail.nossr50.datatypes.meta; + +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.plugin.Plugin; + +public class RecentlyReplantedCropMeta extends FixedMetadataValue { + + /** + * Initializes a FixedMetadataValue with an Object + * + * @param owningPlugin the {@link Plugin} that created this metadata value + */ + public RecentlyReplantedCropMeta(Plugin owningPlugin) { + super(owningPlugin, true); + } + +} diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index b28777238..0306f6d68 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -107,6 +107,7 @@ public class mcMMO extends JavaPlugin { private static boolean isRetroModeEnabled; /* Metadata Values */ + public final static String REPLANT_META_KEY = "mcMMO: Recently Replanted"; public static final String FISH_HOOK_REF_METAKEY = "mcMMO: Fish Hook Tracker"; public static final String DODGE_TRACKER = "mcMMO: Dodge Tracker"; public static final String CUSTOM_DAMAGE_METAKEY = "mcMMO: Custom Damage"; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java new file mode 100644 index 000000000..d19411b5e --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -0,0 +1,90 @@ +package com.gmail.nossr50.runnables.skills; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.skills.ParticleEffectUtils; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.Ageable; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class DelayedCropReplant extends BukkitRunnable { + + private final int desiredCropAge; + private final Location cropLocation; + private final Material cropMaterial; + private boolean wasImmaturePlant; + private final BlockBreakEvent blockBreakEvent; + + /** + * Replants a crop after a delay setting the age to desiredCropAge + * @param cropState target {@link BlockState} + * @param desiredCropAge desired age of the crop + */ + public DelayedCropReplant(BlockBreakEvent blockBreakEvent, BlockState cropState, int desiredCropAge, boolean wasImmaturePlant) { + //The plant was either immature or something cancelled the event, therefor we need to treat it differently + this.blockBreakEvent = blockBreakEvent; + this.wasImmaturePlant = wasImmaturePlant; + this.cropMaterial = cropState.getType(); + this.desiredCropAge = desiredCropAge; + this.cropLocation = cropState.getLocation(); + } + + @Override + public void run() { + Block cropBlock = cropLocation.getBlock(); + BlockState currentState = cropBlock.getState(); + + if(blockBreakEvent.isCancelled()) { + wasImmaturePlant = true; + } + + //Two kinds of air in Minecraft + if(currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { + //The space is not currently occupied by a block so we can fill it + cropBlock.setType(cropMaterial); + + //Get new state (necessary?) + BlockState newState = cropBlock.getState(); + newState.setType(cropMaterial); + newState.update(); + Ageable ageable = (Ageable) newState.getBlockData(); + + //Crop age should always be 0 if the plant was immature + if(wasImmaturePlant) { + ageable.setAge(0); + } else { + //Otherwise make the plant the desired age + ageable.setAge(desiredCropAge); + } + + //Age the crop + newState.setBlockData(ageable); + + //Play an effect + ParticleEffectUtils.playGreenThumbEffect(cropLocation); + + //Remove the metadata marking the block as recently replanted + new removePlantMeta(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20); + } + + } + + private class removePlantMeta extends BukkitRunnable { + + private final Location cropLoc; + + public removePlantMeta(Location cropLoc) { + this.cropLoc = cropLoc; + } + + @Override + public void run() { + Block cropBlock = cropLoc.getBlock(); + cropBlock.removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + } + } + +} diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 3eb0951f2..69cd04b6e 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.BlockSnapshot; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.interactions.NotificationType; +import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; @@ -14,6 +15,7 @@ import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.runnables.skills.DelayedCropReplant; import com.gmail.nossr50.runnables.skills.DelayedHerbalismXPCheckTask; import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.skills.SkillManager; @@ -158,6 +160,13 @@ public class HerbalismManager extends SkillManager { private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet brokenPlants) { BlockState originalBreak = blockBreakEvent.getBlock().getState(); + //Check if the plant was recently replanted + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + return; + } + //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); @@ -639,6 +648,18 @@ public class HerbalismManager extends SkillManager { return Herbalism.convertShroomThumb(blockState); } + /** + * Starts the delayed replant task and turns + * @param desiredCropAge the desired age of the crop + * @param blockBreakEvent the {@link BlockBreakEvent} this crop was involved in + * @param cropState the {@link BlockState} of the crop + */ + private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) { + //Mark the plant as recently replanted to avoid accidental breakage + blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p)); + new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge, isImmature).runTaskLater(mcMMO.p, 20 * 2); + } + /** * Process the Green Thumb ability for plants. * @@ -651,12 +672,13 @@ public class HerbalismManager extends SkillManager { if (!(blockData instanceof Ageable)) return; + Ageable ageable = (Ageable) blockData; + //If the ageable is NOT mature and the player is NOT using a hoe, abort - if(!isAgeableMature((Ageable) blockData) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { + if(!isAgeableMature(ageable) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { return; } - Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); Material seed = null; @@ -696,31 +718,36 @@ public class HerbalismManager extends SkillManager { return; } - if (!processGrowingPlants(blockState, blockBreakEvent, greenTerra)) { + + if (!playerInventory.containsAtLeast(seedStack, 1)) { return; } - if(!ItemUtils.isHoe(getPlayer().getInventory().getItemInMainHand())) - { - if (!playerInventory.containsAtLeast(seedStack, 1)) { - return; - } - - playerInventory.removeItem(seedStack); - player.updateInventory(); // Needed until replacement available + if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) { + return; } + playerInventory.removeItem(seedStack); + player.updateInventory(); // Needed until replacement available + new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } - private boolean processGrowingPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { - Ageable crops = (Ageable) blockState.getBlockData(); + private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + //This check is needed + if(isBizarreAgeable(ageable)) { + return false; + } + + int finalAge = 0; int greenThumbStage = getGreenThumbStage(); //Immature plants will start over at 0 - if(!isAgeableMature(crops)) { - crops.setAge(0); + if(!isAgeableMature(ageable)) { blockBreakEvent.setCancelled(true); + startReplantTask(0, blockBreakEvent, blockState, true); + blockState.setType(Material.AIR); + blockState.update(); return true; } @@ -733,10 +760,10 @@ public class HerbalismManager extends SkillManager { case WHEAT: if (greenTerra) { - crops.setAge(3); + finalAge = 3; } else { - crops.setAge(greenThumbStage); + finalAge = getGreenThumbStage(); } break; @@ -744,30 +771,32 @@ public class HerbalismManager extends SkillManager { case NETHER_WART: if (greenTerra || greenThumbStage > 2) { - crops.setAge(2); + finalAge = 2; } else if (greenThumbStage == 2) { - crops.setAge(1); + finalAge = 1; } else { - crops.setAge(0); + finalAge = 0; } break; case COCOA: if (greenTerra || getGreenThumbStage() > 1) { - crops.setAge(1); + finalAge = 1; } else { - crops.setAge(0); + finalAge = 0; } break; default: return false; } - blockState.setBlockData(crops); + + //Start the delayed replant + startReplantTask(finalAge, blockBreakEvent, blockState, false); return true; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java index 76cc10308..4ddf909af 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.util.skills; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.util.sounds.SoundManager; +import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -14,6 +16,12 @@ public final class ParticleEffectUtils { private ParticleEffectUtils() {}; + public static void playGreenThumbEffect(Location location) { + World world = location.getWorld(); + playSmokeEffect(location); + SoundManager.worldSendSoundMaxPitch(world, location, SoundType.POP); + } + public static void playBleedEffect(LivingEntity livingEntity) { if (!Config.getInstance().getBleedEffectEnabled()) { return; @@ -27,7 +35,7 @@ public final class ParticleEffectUtils { return; } - playSmokeEffect(player); + playSmokeEffect(player.getLocation()); } public static void playFluxEffect(Location location) { @@ -38,9 +46,8 @@ public final class ParticleEffectUtils { location.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES, 1); } - public static void playSmokeEffect(LivingEntity livingEntity) { - Location location = livingEntity.getEyeLocation(); - World world = livingEntity.getWorld(); + public static void playSmokeEffect(Location location) { + World world = location.getWorld(); // Have to do it this way, because not all block directions are valid for smoke world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_EAST); diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java index 8bf24461f..fdb4e4e80 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java @@ -39,6 +39,11 @@ public class SoundManager { world.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType)); } + public static void worldSendSoundMaxPitch(World world, Location location, SoundType soundType) { + if(SoundConfig.getInstance().getIsEnabled(soundType)) + world.playSound(location, getSound(soundType), getVolume(soundType), 2.0F); + } + /** * All volume is multiplied by the master volume to get its final value * @param soundType target soundtype From 7c6d5c476d28295d138b874a02653e7ec0c30334 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 16:14:21 -0800 Subject: [PATCH 12/15] Green Thumb requires a hoe, sneak to break with a hoe --- Changelog.txt | 2 ++ .../nossr50/skills/herbalism/HerbalismManager.java | 14 ++++++++++---- .../gmail/nossr50/util/sounds/SoundManager.java | 2 ++ .../com/gmail/nossr50/util/sounds/SoundType.java | 1 + src/main/resources/sounds.yml | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index a10e35f58..15d7084df 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Green Thumb now requires a hoe to activate + You can sneak to break plants with a hoe in your hand (or just put the hoe away) Hoes no longer give free replants There is now a feature in place to prevent breaking a newly automatically replanted (via green thumb) crop from being breakable for a few seconds after it appears Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 69cd04b6e..c7a91cfc0 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -26,6 +26,8 @@ import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillUtils; +import com.gmail.nossr50.util.sounds.SoundManager; +import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -667,17 +669,19 @@ public class HerbalismManager extends SkillManager { * @param greenTerra boolean to determine if greenTerra is active or not */ private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + if(blockBreakEvent.getPlayer().isSneaking() || !ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { + return; + } + BlockData blockData = blockState.getBlockData(); - if (!(blockData instanceof Ageable)) + if (!(blockData instanceof Ageable)) { return; + } Ageable ageable = (Ageable) blockData; //If the ageable is NOT mature and the player is NOT using a hoe, abort - if(!isAgeableMature(ageable) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { - return; - } Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); @@ -729,6 +733,8 @@ public class HerbalismManager extends SkillManager { playerInventory.removeItem(seedStack); player.updateInventory(); // Needed until replacement available + //Play sound + SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED); new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java index fdb4e4e80..a3d7bc736 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundManager.java @@ -98,6 +98,8 @@ public class SoundManager { return Sound.ENTITY_ENDER_EYE_DEATH; case GLASS: return Sound.BLOCK_GLASS_BREAK; + case ITEM_CONSUMED: + return Sound.ITEM_BOTTLE_EMPTY; default: return null; } diff --git a/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java b/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java index 3a0e37eda..67e9b0e0b 100644 --- a/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java +++ b/src/main/java/com/gmail/nossr50/util/sounds/SoundType.java @@ -15,6 +15,7 @@ public enum SoundType { ABILITY_ACTIVATED_BERSERK, BLEED, GLASS, + ITEM_CONSUMED, TIRED; public boolean usesCustomPitch() diff --git a/src/main/resources/sounds.yml b/src/main/resources/sounds.yml index 837559568..f705b7d24 100644 --- a/src/main/resources/sounds.yml +++ b/src/main/resources/sounds.yml @@ -4,6 +4,10 @@ Sounds: # 1.0 = Max volume # 0.0 = No Volume MasterVolume: 1.0 + ITEM_CONSUMED: + Enable: true + Volume: 1.0 + Pitch: 1.0 GLASS: Enable: true Volume: 1.0 From a333f36fd80f3b3425ac41e6d40191fdfe1af048 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 16:19:19 -0800 Subject: [PATCH 13/15] Fix sneak check on GT --- .../com/gmail/nossr50/skills/herbalism/HerbalismManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index c7a91cfc0..0a50a60bf 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -171,7 +171,8 @@ public class HerbalismManager extends SkillManager { //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + if(!getPlayer().isSneaking()) + processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); } //When replanting a immature crop we cancel the block break event and back out @@ -669,7 +670,7 @@ public class HerbalismManager extends SkillManager { * @param greenTerra boolean to determine if greenTerra is active or not */ private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { - if(blockBreakEvent.getPlayer().isSneaking() || !ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { + if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { return; } From a598796c997708c44fef7f5fec7c2e42467af90f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 17:20:05 -0800 Subject: [PATCH 14/15] More tweaks to GT --- Changelog.txt | 2 + .../meta/RecentlyReplantedCropMeta.java | 4 +- .../nossr50/listeners/BlockListener.java | 5 -- .../runnables/skills/DelayedCropReplant.java | 24 ++++--- .../nossr50/skills/herbalism/Herbalism.java | 10 --- .../skills/herbalism/HerbalismManager.java | 65 ++++++++++--------- 6 files changed, 53 insertions(+), 57 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 15d7084df..b3440eba1 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,6 @@ Version 2.1.115 + Cocoa plants now require GT of at least 2 to start at the second stage of growth + Green Terra now boosts growth on Green Thumb by 1 stage (doesn't go above the maximum value though) Green Thumb now requires a hoe to activate You can sneak to break plants with a hoe in your hand (or just put the hoe away) Hoes no longer give free replants diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java index 5c630f7bc..20d8e00df 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/RecentlyReplantedCropMeta.java @@ -10,8 +10,8 @@ public class RecentlyReplantedCropMeta extends FixedMetadataValue { * * @param owningPlugin the {@link Plugin} that created this metadata value */ - public RecentlyReplantedCropMeta(Plugin owningPlugin) { - super(owningPlugin, true); + public RecentlyReplantedCropMeta(Plugin owningPlugin, Boolean recentlyPlanted) { + super(owningPlugin, recentlyPlanted); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 9023caa3d..56503f3b0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -424,11 +424,6 @@ public class BlockListener implements Listener { BlockState blockState = event.getBlock().getState(); ItemStack heldItem = player.getInventory().getItemInMainHand(); - if (Herbalism.isRecentlyRegrown(blockState)) { - event.setCancelled(true); - return; - } - if (ItemUtils.isSword(heldItem)) { HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager(); diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java index d19411b5e..f00f9579e 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -1,10 +1,12 @@ package com.gmail.nossr50.runnables.skills; +import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.skills.ParticleEffectUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.Ageable; import org.bukkit.event.block.BlockBreakEvent; @@ -37,19 +39,23 @@ public class DelayedCropReplant extends BukkitRunnable { Block cropBlock = cropLocation.getBlock(); BlockState currentState = cropBlock.getState(); + //Remove the metadata marking the block as recently replanted + new markPlantAsOld(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20*5); + if(blockBreakEvent.isCancelled()) { wasImmaturePlant = true; } //Two kinds of air in Minecraft - if(currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { + if(currentState.getType().equals(cropMaterial) || currentState.getType().equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) { +// if(currentState.getBlock().getRelative(BlockFace.DOWN)) //The space is not currently occupied by a block so we can fill it cropBlock.setType(cropMaterial); //Get new state (necessary?) BlockState newState = cropBlock.getState(); - newState.setType(cropMaterial); - newState.update(); +// newState.update(); + Ageable ageable = (Ageable) newState.getBlockData(); //Crop age should always be 0 if the plant was immature @@ -62,28 +68,30 @@ public class DelayedCropReplant extends BukkitRunnable { //Age the crop newState.setBlockData(ageable); + newState.update(true); //Play an effect ParticleEffectUtils.playGreenThumbEffect(cropLocation); - //Remove the metadata marking the block as recently replanted - new removePlantMeta(blockBreakEvent.getBlock().getLocation()).runTaskLater(mcMMO.p, 20); } } - private class removePlantMeta extends BukkitRunnable { + private class markPlantAsOld extends BukkitRunnable { private final Location cropLoc; - public removePlantMeta(Location cropLoc) { + public markPlantAsOld(Location cropLoc) { this.cropLoc = cropLoc; } @Override public void run() { Block cropBlock = cropLoc.getBlock(); - cropBlock.removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + if(cropBlock.getMetadata(mcMMO.REPLANT_META_KEY).size() > 0) + cropBlock.setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, false)); + + ParticleEffectUtils.playFluxEffect(cropLocation); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index b486db4f2..e461d2f37 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -58,14 +58,4 @@ public class Herbalism { } } - /** - * Check if the block has a recently grown crop from Green Thumb - * - * @param blockState - * The {@link BlockState} to check green thumb regrown for - * @return true if the block is recently regrown, false otherwise - */ - public static boolean isRecentlyRegrown(BlockState blockState) { - return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1); - } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 0a50a60bf..423778ce0 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -139,6 +139,16 @@ public class HerbalismManager extends SkillManager { return; } + //Check if the plant was recently replanted + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + + return; + } + } + /* * There are single-block plants and multi-block plants in Minecraft * In order to give out proper rewards, we need to collect all blocks that would be broken from this event @@ -161,22 +171,17 @@ public class HerbalismManager extends SkillManager { */ private void processHerbalismOnBlocksBroken(BlockBreakEvent blockBreakEvent, HashSet brokenPlants) { BlockState originalBreak = blockBreakEvent.getBlock().getState(); - - //Check if the plant was recently replanted - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { - //Crop is recently replanted to back out of destroying it - blockBreakEvent.setCancelled(true); - return; - } + boolean greenThumbActivated = false; //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - if(!getPlayer().isSneaking()) - processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + if(!getPlayer().isSneaking()) { + greenThumbActivated = processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + } } //When replanting a immature crop we cancel the block break event and back out - if(blockBreakEvent.isCancelled()) { + if(greenThumbActivated) { return; } @@ -659,8 +664,8 @@ public class HerbalismManager extends SkillManager { */ private void startReplantTask(int desiredCropAge, BlockBreakEvent blockBreakEvent, BlockState cropState, boolean isImmature) { //Mark the plant as recently replanted to avoid accidental breakage - blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p)); new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge, isImmature).runTaskLater(mcMMO.p, 20 * 2); + blockBreakEvent.getBlock().setMetadata(mcMMO.REPLANT_META_KEY, new RecentlyReplantedCropMeta(mcMMO.p, true)); } /** @@ -669,15 +674,15 @@ public class HerbalismManager extends SkillManager { * @param blockState The {@link BlockState} to check ability activation for * @param greenTerra boolean to determine if greenTerra is active or not */ - private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + private boolean processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { if(!ItemUtils.isHoe(blockBreakEvent.getPlayer().getInventory().getItemInMainHand())) { - return; + return false; } BlockData blockData = blockState.getBlockData(); if (!(blockData instanceof Ageable)) { - return; + return false; } Ageable ageable = (Ageable) blockData; @@ -714,30 +719,30 @@ public class HerbalismManager extends SkillManager { break; default: - return; + return false; } ItemStack seedStack = new ItemStack(seed); if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) { - return; + return false; } if (!playerInventory.containsAtLeast(seedStack, 1)) { - return; + return false; } if (!processGrowingPlants(blockState, ageable, blockBreakEvent, greenTerra)) { - return; + return false; } playerInventory.removeItem(seedStack); player.updateInventory(); // Needed until replacement available //Play sound SoundManager.sendSound(player, player.getLocation(), SoundType.ITEM_CONSUMED); - - new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); + return true; +// new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } private boolean processGrowingPlants(BlockState blockState, Ageable ageable, BlockBreakEvent blockBreakEvent, boolean greenTerra) { @@ -747,31 +752,23 @@ public class HerbalismManager extends SkillManager { } int finalAge = 0; - int greenThumbStage = getGreenThumbStage(); + int greenThumbStage = getGreenThumbStage(greenTerra); //Immature plants will start over at 0 if(!isAgeableMature(ageable)) { blockBreakEvent.setCancelled(true); startReplantTask(0, blockBreakEvent, blockState, true); blockState.setType(Material.AIR); - blockState.update(); return true; } - blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); - switch (blockState.getType()) { case POTATOES: case CARROTS: case WHEAT: - if (greenTerra) { - finalAge = 3; - } - else { - finalAge = getGreenThumbStage(); - } + finalAge = getGreenThumbStage(greenTerra); break; case BEETROOTS: @@ -790,7 +787,7 @@ public class HerbalismManager extends SkillManager { case COCOA: - if (greenTerra || getGreenThumbStage() > 1) { + if (getGreenThumbStage(greenTerra) >= 2) { finalAge = 1; } else { @@ -807,7 +804,11 @@ public class HerbalismManager extends SkillManager { return true; } - private int getGreenThumbStage() { + private int getGreenThumbStage(boolean greenTerraActive) { + if(greenTerraActive) + return Math.min(RankUtils.getHighestRank(SubSkillType.HERBALISM_GREEN_THUMB), + RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB) + 1); + return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB); } } From 95c403a467f4ddc1759882b906885f83b79c8526 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 17:31:00 -0800 Subject: [PATCH 15/15] More tweaks to GT --- .../skills/herbalism/HerbalismManager.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 423778ce0..8ff40c286 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -140,12 +140,19 @@ public class HerbalismManager extends SkillManager { } //Check if the plant was recently replanted - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { - if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { - //Crop is recently replanted to back out of destroying it - blockBreakEvent.setCancelled(true); + if(blockBreakEvent.getBlock().getBlockData() instanceof Ageable) { + Ageable ageableCrop = (Ageable) blockBreakEvent.getBlock().getBlockData(); - return; + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).size() >= 1) { + if(blockBreakEvent.getBlock().getMetadata(mcMMO.REPLANT_META_KEY).get(0).asBoolean()) { + if(isAgeableMature(ageableCrop)) { + blockBreakEvent.getBlock().removeMetadata(mcMMO.REPLANT_META_KEY, mcMMO.p); + } else { + //Crop is recently replanted to back out of destroying it + blockBreakEvent.setCancelled(true); + return; + } + } } } @@ -756,9 +763,10 @@ public class HerbalismManager extends SkillManager { //Immature plants will start over at 0 if(!isAgeableMature(ageable)) { - blockBreakEvent.setCancelled(true); +// blockBreakEvent.setCancelled(true); startReplantTask(0, blockBreakEvent, blockState, true); - blockState.setType(Material.AIR); +// blockState.setType(Material.AIR); + blockBreakEvent.setDropItems(false); return true; }