From a53505ee0bf6ce5f4ccf79fa1122b316870d1112 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 13 May 2019 08:53:22 -0700 Subject: [PATCH 1/5] Raised overfishing limit + improved tips --- Changelog.txt | 7 +++++++ pom.xml | 2 +- .../java/com/gmail/nossr50/listeners/PlayerListener.java | 2 +- .../com/gmail/nossr50/skills/fishing/FishingManager.java | 4 ++-- src/main/resources/locale/locale_en_US.properties | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7869c5487..22f314acf 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,10 @@ +Version 2.1.59 + Raised the overfishing limit from 3 to 10 + Improved the overfishing messages to be more clear about its mechanics + Overfishing locale keys renamed "Fishing.ScarcityTip" and "Fishing.LowResourcesTip" + + NOTES: This and other exploit prevention measures are much more customizable in 2.2, which shouldn't be too far off. + Version 2.1.58 Fixed the wrong locale string being used for Mining Double Drops diff --git a/pom.xml b/pom.xml index 1941eda3c..5bff90229 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.58 + 2.1.59 mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 36c099ced..7f8c447ad 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -385,7 +385,7 @@ public class PlayerListener implements Listener { { if(fishingManager.isExploitingFishing(event.getHook().getLocation().toVector())) { - player.sendMessage(LocaleLoader.getString("Fishing.Scarcity")); + player.sendMessage(LocaleLoader.getString("Fishing.ScarcityTip", 3)); event.setExpToDrop(0); Item caughtItem = (Item) caught; caughtItem.remove(); diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index 17385ad62..11c1040b8 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -44,7 +44,7 @@ import java.util.*; public class FishingManager extends SkillManager { public static final int FISHING_ROD_CAST_CD_MILLISECONDS = 100; - public static final int OVERFISH_LIMIT = 4; + public static final int OVERFISH_LIMIT = 10; private final long FISHING_COOLDOWN_SECONDS = 1000L; private long fishingRodCastTimestamp = 0L; @@ -139,7 +139,7 @@ public class FishingManager extends SkillManager { if(fishCaughtCounter + 1 == OVERFISH_LIMIT) { - getPlayer().sendMessage(LocaleLoader.getString("Fishing.LowResources")); + getPlayer().sendMessage(LocaleLoader.getString("Fishing.LowResourcesTip", 3)); } //If the new bounding box does not intersect with the old one, then update our bounding box reference diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index c4d6876e7..1ee3c2e54 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -223,10 +223,10 @@ Excavation.Skills.GigaDrillBreaker.Refresh=[[GREEN]]Your [[YELLOW]]Giga Drill Br Excavation.Skills.GigaDrillBreaker.Other.Off=Giga Drill Breaker[[GREEN]] has worn off for [[YELLOW]]{0} Excavation.Skills.GigaDrillBreaker.Other.On=[[GREEN]]{0}[[DARK_GREEN]] has used [[RED]]Giga Drill Breaker! #FISHING -Fishing.Scarcity=[[YELLOW]]&oThis area is suffering from overfishing, try fishing in a new area. +Fishing.ScarcityTip=[[YELLOW]]&oThis area is suffering from overfishing, cast your rod in a different spot for more fish. At least {0} blocks away. Fishing.Scared=[[GRAY]]&oChaotic movements will scare fish! Fishing.Exhausting=[[RED]]&oImproper use of the fishing rod will cause fatigue and wear out the rod! -Fishing.LowResources=[[GRAY]]You sense that there might not be many fish left in this area. +Fishing.LowResourcesTip=[[GRAY]]You sense that there might not be many fish left in this area. Try fishing at least {0} blocks away. Fishing.Ability.Info=Magic Hunter: [[GRAY]] **Improves With Treasure Hunter Rank** Fishing.Ability.Locked.0=LOCKED UNTIL {0}+ SKILL (SHAKE) Fishing.Ability.Locked.1=LOCKED UNTIL {0}+ SKILL (ICE FISHING) From 34869914c4a74b83a592b39129b38dc441c49b6f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 14 May 2019 15:14:30 -0700 Subject: [PATCH 2/5] Wolfs no longer kill themselves + tamed mob heart death message bug --- Changelog.txt | 6 ++++ pom.xml | 4 +-- .../nossr50/listeners/BlockListener.java | 14 ++++---- .../nossr50/listeners/EntityListener.java | 26 +++++++------- .../nossr50/skills/taming/TamingManager.java | 36 +++++++++++-------- .../nossr50/util/skills/CombatUtils.java | 23 ++++++++++++ .../resources/locale/locale_en_US.properties | 2 +- 7 files changed, 73 insertions(+), 38 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 22f314acf..2a2102895 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,9 @@ +Version 2.1.60 + Fixed a NPE error if a LivingEntity's target was set to null + Fixed a bug where tamed mobs could kill themselves if their owner shot them once + Corrected a typo when naming entities summoned by COTW (Locale string - Taming.Summon.Name.Format) + Fixed a bug where tamed mobs could have hearts instead of their name in their own death messages + Version 2.1.59 Raised the overfishing limit from 3 to 10 Improved the overfishing messages to be more clear about its mechanics diff --git a/pom.xml b/pom.xml index 5bff90229..d2a593aa6 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.59 + 2.1.60-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO @@ -167,7 +167,7 @@ org.spigotmc spigot-api - 1.14-R0.1-SNAPSHOT + 1.14.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 0b64b488a..635472cbd 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -66,16 +66,16 @@ public class BlockListener implements Listener { continue; //TODO: Should just store the amount of drops in the metadata itself and use a loop - if(event.getBlock().getState().getMetadata(mcMMO.doubleDrops).size() > 0) + if(event.getBlock().getMetadata(mcMMO.doubleDrops).size() > 0) { - event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().getState().removeMetadata(mcMMO.doubleDrops, plugin); + event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); + event.getBlock().removeMetadata(mcMMO.doubleDrops, plugin); } - else if(event.getBlock().getState().getMetadata(mcMMO.tripleDrops).size() > 0) + else if(event.getBlock().getMetadata(mcMMO.tripleDrops).size() > 0) { - event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().getState().removeMetadata(mcMMO.tripleDrops, plugin); + event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); + event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); + event.getBlock().removeMetadata(mcMMO.tripleDrops, plugin); } } } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 6570b65b5..1ceb994f9 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -25,6 +25,7 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; @@ -72,6 +73,12 @@ public class EntityListener implements Listener { if(!ExperienceConfig.getInstance().isEndermanEndermiteFarmingPrevented()) return; + //It's rare but targets can be null sometimes + if(event.getTarget() == null) + { + return; + } + //Prevent entities from giving XP if they target endermite if(event.getTarget() instanceof Endermite) { @@ -386,24 +393,15 @@ public class EntityListener implements Listener { /** * This sets entity names back to whatever they are supposed to be */ - if(!(attacker instanceof Player) && defender instanceof Player) + if(event.getFinalDamage() >= target.getHealth()) { - if(event.getFinalDamage() >= ((LivingEntity) defender).getHealth()) + if(attacker instanceof LivingEntity) { - List metadataValue = attacker.getMetadata("mcMMO_oldName"); - - if(metadataValue.size() <= 0) - return; - - if(metadataValue != null) - { - OldName oldName = (OldName) metadataValue.get(0); - attacker.setCustomName(oldName.asString()); - attacker.setCustomNameVisible(false); - } + CombatUtils.fixNames(event, (LivingEntity) attacker); } - } + CombatUtils.fixNames(event, target); + } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 944cdd5d1..1ebcb5344 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -231,6 +231,14 @@ public class TamingManager extends SkillManager { } public void attackTarget(LivingEntity target) { + if(target instanceof Tameable) + { + Tameable tameable = (Tameable) target; + if(tameable.getOwner() == getPlayer()) + { + return; + } + } double range = 5; Player player = getPlayer(); @@ -281,36 +289,36 @@ public class TamingManager extends SkillManager { } location = Misc.getLocationOffset(location, 1); - LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type); + LivingEntity callOfWildEntity = (LivingEntity) player.getWorld().spawnEntity(location, type); - FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player); + FakeEntityTameEvent event = new FakeEntityTameEvent(callOfWildEntity, player); mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { continue; } - entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); - ((Tameable) entity).setOwner(player); - entity.setRemoveWhenFarAway(false); + callOfWildEntity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); + ((Tameable) callOfWildEntity).setOwner(player); + callOfWildEntity.setRemoveWhenFarAway(false); - addToTracker(entity); + addToTracker(callOfWildEntity); switch (type) { case OCELOT: - ((Ocelot) entity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]); + ((Ocelot) callOfWildEntity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]); break; case WOLF: - entity.setMaxHealth(20.0); - entity.setHealth(entity.getMaxHealth()); + callOfWildEntity.setMaxHealth(20.0); + callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth()); break; case HORSE: - Horse horse = (Horse) entity; + Horse horse = (Horse) callOfWildEntity; - entity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15)); - entity.setHealth(entity.getMaxHealth()); + callOfWildEntity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15)); + callOfWildEntity.setHealth(callOfWildEntity.getMaxHealth()); horse.setColor(Horse.Color.values()[Misc.getRandom().nextInt(Horse.Color.values().length)]); horse.setStyle(Horse.Style.values()[Misc.getRandom().nextInt(Horse.Style.values().length)]); horse.setJumpStrength(Math.max(AdvancedConfig.getInstance().getMinHorseJumpStrength(), Math.min(Math.min(Misc.getRandom().nextDouble(), Misc.getRandom().nextDouble()) * 2, AdvancedConfig.getInstance().getMaxHorseJumpStrength()))); @@ -322,10 +330,10 @@ public class TamingManager extends SkillManager { } if (Permissions.renamePets(player)) { - entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type))); + callOfWildEntity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type))); } - ParticleEffectUtils.playCallOfTheWildEffect(entity); + ParticleEffectUtils.playCallOfTheWildEffect(callOfWildEntity); } ItemStack leftovers = new ItemStack(heldItem); 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 5d42b0a12..497782a80 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.util.skills; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; +import com.gmail.nossr50.datatypes.meta.OldName; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; @@ -30,10 +31,12 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.MetadataValue; import org.bukkit.projectiles.ProjectileSource; import java.util.EnumMap; import java.util.HashMap; +import java.util.List; import java.util.Map; public final class CombatUtils { @@ -358,6 +361,26 @@ public final class CombatUtils { } } + /** + * This cleans up names from displaying in chat as hearts + * @param event target event + * @param entity target entity + */ + public static void fixNames(EntityDamageByEntityEvent event, LivingEntity entity) + { + List metadataValue = entity.getMetadata("mcMMO_oldName"); + + if(metadataValue.size() <= 0) + return; + + if(metadataValue != null) + { + OldName oldName = (OldName) metadataValue.get(0); + entity.setCustomName(oldName.asString()); + entity.setCustomNameVisible(false); + } + } + public static int getLimitBreakDamage(Player player, SubSkillType subSkillType) { return RankUtils.getRank(player, subSkillType); } diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 1ee3c2e54..5846754c0 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -478,7 +478,7 @@ Taming.Summon.Fail.Ocelot=[[RED]]You have too many ocelots nearby to summon any Taming.Summon.Fail.Wolf=[[RED]]You have too many wolves nearby to summon any more. Taming.Summon.Fail.Horse=[[RED]]You have too many horses nearby to summon any more. Taming.Summon.Fail.TooMany=[[RED]]You have reached the maximum limit of pets to summon. [[YELLOW]]({0}) -Taming.Summon.Name.Format={0}''s {1} +Taming.Summon.Name.Format={0}'s {1} #UNARMED Unarmed.Ability.Bonus.0=Iron Arm Style Unarmed.Ability.Bonus.1=+{0} DMG Upgrade From e70e5b04b56e14b9be52738c5a851e017e3c10b1 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 14 May 2019 15:29:15 -0700 Subject: [PATCH 3/5] Remove unecessary parameter --- src/main/java/com/gmail/nossr50/listeners/EntityListener.java | 4 ++-- src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 1ceb994f9..7681e196a 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -397,10 +397,10 @@ public class EntityListener implements Listener { { if(attacker instanceof LivingEntity) { - CombatUtils.fixNames(event, (LivingEntity) attacker); + CombatUtils.fixNames((LivingEntity) attacker); } - CombatUtils.fixNames(event, target); + CombatUtils.fixNames(target); } } 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 497782a80..6a8d1e755 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -363,10 +363,9 @@ public final class CombatUtils { /** * This cleans up names from displaying in chat as hearts - * @param event target event * @param entity target entity */ - public static void fixNames(EntityDamageByEntityEvent event, LivingEntity entity) + public static void fixNames(LivingEntity entity) { List metadataValue = entity.getMetadata("mcMMO_oldName"); From 95652efbaa7ef95084a7dd1704e1536ec6ea31fd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 14 May 2019 16:14:01 -0700 Subject: [PATCH 4/5] Fix bonus drops on multi-block crops --- Changelog.txt | 1 + .../nossr50/datatypes/meta/BonusDropMeta.java | 14 +++++++++++++ .../nossr50/listeners/BlockListener.java | 21 +++++++++---------- src/main/java/com/gmail/nossr50/mcMMO.java | 3 +-- .../nossr50/skills/herbalism/Herbalism.java | 20 ++++++++++++++++-- .../com/gmail/nossr50/util/BlockUtils.java | 14 +++++++++++-- 6 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/datatypes/meta/BonusDropMeta.java diff --git a/Changelog.txt b/Changelog.txt index 2a2102895..aacf61dd1 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,6 +3,7 @@ Version 2.1.60 Fixed a bug where tamed mobs could kill themselves if their owner shot them once Corrected a typo when naming entities summoned by COTW (Locale string - Taming.Summon.Name.Format) Fixed a bug where tamed mobs could have hearts instead of their name in their own death messages + Fixed a bug where multi-block crops would fail to double/triple drop (Sugar Cane, Cactus, etc) Version 2.1.59 Raised the overfishing limit from 3 to 10 diff --git a/src/main/java/com/gmail/nossr50/datatypes/meta/BonusDropMeta.java b/src/main/java/com/gmail/nossr50/datatypes/meta/BonusDropMeta.java new file mode 100644 index 000000000..a9d093a56 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/meta/BonusDropMeta.java @@ -0,0 +1,14 @@ +package com.gmail.nossr50.datatypes.meta; + +import com.gmail.nossr50.mcMMO; +import org.bukkit.metadata.FixedMetadataValue; + +/** + * Stores how many bonus drops a block should give + */ +public class BonusDropMeta extends FixedMetadataValue { + + public BonusDropMeta(int value, mcMMO plugin) { + super(plugin, value); + } +} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 635472cbd..a627a09b3 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -4,6 +4,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.datatypes.meta.BonusDropMeta; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; @@ -65,17 +66,15 @@ public class BlockListener implements Listener { && !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, is.getType())) continue; - //TODO: Should just store the amount of drops in the metadata itself and use a loop - if(event.getBlock().getMetadata(mcMMO.doubleDrops).size() > 0) - { - event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().removeMetadata(mcMMO.doubleDrops, plugin); - } - else if(event.getBlock().getMetadata(mcMMO.tripleDrops).size() > 0) - { - event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); - event.getBlock().removeMetadata(mcMMO.tripleDrops, plugin); + if (event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) { + BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0); + int bonusCount = bonusDropMeta.asInt(); + + for (int i = 0; i < bonusCount; i++) { + event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is); + } + + event.getBlock().removeMetadata(mcMMO.BONUS_DROPS_METAKEY, plugin); } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 8362e13ff..530db4281 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -120,8 +120,7 @@ public class mcMMO extends JavaPlugin { public final static String infiniteArrowKey = "mcMMO: Infinite Arrow"; public final static String bowForceKey = "mcMMO: Bow Force"; public final static String arrowDistanceKey = "mcMMO: Arrow Distance"; - public final static String doubleDrops = "mcMMO: Double Drops"; - public final static String tripleDrops = "mcMMO: Triple Drops"; + public final static String BONUS_DROPS_METAKEY = "mcMMO: Double Drops"; //public final static String customDamageKey = "mcMMO: Custom Damage"; public final static String disarmedItemKey = "mcMMO: Disarmed Item"; public final static String playerDataKey = "mcMMO: Player Data"; 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 a51cab404..79e97d2df 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -87,7 +87,9 @@ public class Herbalism { protected static int countAndMarkDoubleDropsMultiBlockPlant(BlockState blockState, boolean triple, HerbalismManager herbalismManager) { Block block = blockState.getBlock(); Material blockType = blockState.getType(); - int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1; + int dropAmount = 0; + int bonusDropAmount = 0; + int bonusAdd = triple ? 2 : 1; if (blockType == Material.CHORUS_PLANT) { dropAmount = 1; @@ -96,6 +98,17 @@ public class Herbalism { dropAmount = calculateChorusPlantDrops(block, triple, herbalismManager); } } else { + //Check the block itself first + if(!mcMMO.getPlaceStore().isTrue(block)) + { + dropAmount++; + + if(herbalismManager.checkDoubleDrop(blockState)) + bonusDropAmount+=bonusAdd; + } else { + mcMMO.getPlaceStore().setFalse(blockState); + } + // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally for (int y = 1; y < 255; y++) { Block relativeBlock = block.getRelative(BlockFace.UP, y); @@ -110,11 +123,14 @@ public class Herbalism { dropAmount++; if(herbalismManager.checkDoubleDrop(relativeBlock.getState())) - BlockUtils.markDropsAsBonus(relativeBlock.getState(), triple); + bonusDropAmount+=bonusAdd; } } } + //Mark the original block for bonus drops + BlockUtils.markDropsAsBonus(blockState, bonusDropAmount); + return dropAmount; } diff --git a/src/main/java/com/gmail/nossr50/util/BlockUtils.java b/src/main/java/com/gmail/nossr50/util/BlockUtils.java index 61007bb07..87eb8ddd3 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockUtils.java +++ b/src/main/java/com/gmail/nossr50/util/BlockUtils.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.util; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.datatypes.meta.BonusDropMeta; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.mcMMO; @@ -30,9 +31,18 @@ public final class BlockUtils { */ public static void markDropsAsBonus(BlockState blockState, boolean triple) { if (triple) - blockState.setMetadata(mcMMO.tripleDrops, mcMMO.metadataValue); + blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(2, mcMMO.p)); else - blockState.setMetadata(mcMMO.doubleDrops, mcMMO.metadataValue); + blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(1, mcMMO.p)); + } + + /** + * Marks a block to drop extra copies of items + * @param blockState target blockstate + * @param amount amount of extra items to drop + */ + public static void markDropsAsBonus(BlockState blockState, int amount) { + blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(amount, mcMMO.p)); } /** From 2746bac86ac8b201960ac47bc19eac4b84d790a0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 14 May 2019 16:16:24 -0700 Subject: [PATCH 5/5] 2.1.60 --- Changelog.txt | 1 + pom.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index aacf61dd1..108f0b554 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -4,6 +4,7 @@ Version 2.1.60 Corrected a typo when naming entities summoned by COTW (Locale string - Taming.Summon.Name.Format) Fixed a bug where tamed mobs could have hearts instead of their name in their own death messages Fixed a bug where multi-block crops would fail to double/triple drop (Sugar Cane, Cactus, etc) + Optimized the bonus drop code to reduce overhead Version 2.1.59 Raised the overfishing limit from 3 to 10 diff --git a/pom.xml b/pom.xml index d2a593aa6..38d3521c6 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.60-SNAPSHOT + 2.1.60 mcMMO https://github.com/mcMMO-Dev/mcMMO