mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
More event work.
This commit is contained in:
parent
a65bcb9e5d
commit
997685b5ec
@ -0,0 +1,12 @@
|
||||
package com.gmail.nossr50.events.skills.herbalism;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
|
||||
|
||||
public abstract class McMMOPlayerHerbalismEvent extends McMMOPlayerSkillEvent {
|
||||
public McMMOPlayerHerbalismEvent(Player player) {
|
||||
super(player, SkillType.HERBALISM);
|
||||
}
|
||||
}
|
@ -143,7 +143,7 @@ public class BlockListener implements Listener {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
/* HERBALISM */
|
||||
if (BlockUtils.affectedByGreenTerra(blockState)) {
|
||||
if (BlockUtils.affectedByGreenTerra(blockState) && Permissions.skillEnabled(player, SkillType.HERBALISM)) {
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
/* Green Terra */
|
||||
@ -153,9 +153,7 @@ public class BlockListener implements Listener {
|
||||
* We don't check the block store here because herbalism has too many unusual edge cases.
|
||||
* Instead, we check it inside the drops handler.
|
||||
*/
|
||||
if (SkillType.HERBALISM.getPermissions(player)) {
|
||||
herbalismManager.herbalismBlockCheck(blockState);
|
||||
}
|
||||
herbalismManager.blockBreak(blockState);
|
||||
}
|
||||
|
||||
/* MINING */
|
||||
@ -331,7 +329,7 @@ public class BlockListener implements Listener {
|
||||
* We don't need to check permissions here because they've already been checked for the ability to even activate.
|
||||
*/
|
||||
if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState)) {
|
||||
if (mcMMOPlayer.getHerbalismManager().processGreenTerra(blockState)) {
|
||||
if (mcMMOPlayer.getHerbalismManager().greenTerra(blockState)) {
|
||||
blockState.update(true);
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +425,6 @@ public class PlayerListener implements Listener {
|
||||
// Make sure the player knows what he's doing when trying to salvage an enchanted item
|
||||
if (!(heldItem.getEnchantments().size() > 0) || repairManager.checkConfirmation(type, true)) {
|
||||
repairManager.handleSalvage(block.getLocation(), heldItem);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -516,13 +515,9 @@ public class PlayerListener implements Listener {
|
||||
/* GREEN THUMB CHECK */
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
if (herbalismManager.canGreenThumbBlock(blockState)) {
|
||||
player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1));
|
||||
|
||||
if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
|
||||
if (herbalismManager.greenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
|
||||
blockState.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* SHROOM THUMB CHECK */
|
||||
else if (herbalismManager.canUseShroomThumb(blockState)) {
|
||||
|
@ -92,7 +92,7 @@ public class HerbalismManager extends SkillManager {
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @return true if the ability was successful, false otherwise
|
||||
*/
|
||||
public boolean processGreenTerra(BlockState blockState) {
|
||||
public boolean greenTerra(BlockState blockState) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (!Permissions.greenThumbBlock(player, blockState.getType())) {
|
||||
@ -100,34 +100,29 @@ public class HerbalismManager extends SkillManager {
|
||||
}
|
||||
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack seed = new ItemStack(Material.SEEDS);
|
||||
|
||||
if (!playerInventory.containsAtLeast(seed, 1)) {
|
||||
if (!playerInventory.contains(Material.SEEDS)) {
|
||||
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
||||
return false;
|
||||
}
|
||||
|
||||
playerInventory.removeItem(seed);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
playerInventory.removeItem(new ItemStack(Material.SEEDS));
|
||||
player.updateInventory();
|
||||
|
||||
return Herbalism.convertGreenTerraBlocks(blockState);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Process double drops & XP gain for Herbalism.
|
||||
*
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
*/
|
||||
public void herbalismBlockCheck(BlockState blockState) {
|
||||
public void blockBreak(BlockState blockState) {
|
||||
Player player = getPlayer();
|
||||
Material material = blockState.getType();
|
||||
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK);
|
||||
|
||||
if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canBlockCheck()) {
|
||||
if (!canBlockCheck() || (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -182,7 +177,14 @@ public class HerbalismManager extends SkillManager {
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @return true if the ability was successful, false otherwise
|
||||
*/
|
||||
public boolean processGreenThumbBlocks(BlockState blockState) {
|
||||
public boolean greenThumbBlocks(BlockState blockState) {
|
||||
if (!canGreenThumbBlock(blockState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = getPlayer().getItemInHand();
|
||||
heldItem.setAmount(heldItem.getAmount() - 1);
|
||||
|
||||
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
|
||||
getPlayer().sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
||||
return false;
|
||||
@ -283,43 +285,35 @@ public class HerbalismManager extends SkillManager {
|
||||
private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
|
||||
Player player = getPlayer();
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack seed = null;
|
||||
Material seed = null;
|
||||
|
||||
switch (blockState.getType()) {
|
||||
case CARROT:
|
||||
seed = new ItemStack(Material.CARROT_ITEM);
|
||||
seed = Material.CARROT_ITEM;
|
||||
break;
|
||||
|
||||
case CROPS:
|
||||
seed = new ItemStack(Material.SEEDS);
|
||||
seed = Material.SEEDS;
|
||||
break;
|
||||
|
||||
case NETHER_WARTS:
|
||||
seed = new ItemStack(Material.NETHER_STALK);
|
||||
seed = Material.NETHER_STALK;
|
||||
break;
|
||||
|
||||
case POTATO:
|
||||
seed = new ItemStack(Material.POTATO_ITEM);
|
||||
seed = Material.POTATO_ITEM;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!playerInventory.containsAtLeast(seed, 1)) {
|
||||
if (!playerInventory.contains(seed) || (!greenTerra && !SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) || !handleBlockState(blockState, greenTerra)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!greenTerra && !SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!handleBlockState(blockState, greenTerra)) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerInventory.removeItem(seed);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
playerInventory.removeItem(new ItemStack(seed));
|
||||
player.updateInventory();
|
||||
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class RepairManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (item.getDurability() == 0) {
|
||||
player.setItemInHand(new ItemStack(Material.AIR));
|
||||
player.setItemInHand(null);
|
||||
location.setY(location.getY() + 1);
|
||||
|
||||
Misc.dropItems(location, new ItemStack(Repair.getRepairAndSalvageItem(item)), Repair.getRepairAndSalvageQuantities(item) * item.getAmount());
|
||||
|
@ -255,7 +255,7 @@ public class TamingManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
|
||||
heldItem.setAmount(heldItemAmount - summonAmount);
|
||||
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,8 @@ public class Unarmed {
|
||||
|
||||
nextSlot++;
|
||||
}
|
||||
} else if (firstEmpty != -1) {
|
||||
}
|
||||
else if (firstEmpty != -1) {
|
||||
drop.remove();
|
||||
dropStack.setAmount(dropAmount);
|
||||
inventory.setItem(firstEmpty, dropStack);
|
||||
|
@ -4,7 +4,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.SmoothBrick;
|
||||
|
||||
@ -104,7 +103,7 @@ public class UnarmedManager extends SkillManager {
|
||||
|
||||
Misc.dropItem(defender.getLocation(), event.getDroppedItem());
|
||||
|
||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||
defender.setItemInHand(null);
|
||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,8 @@ public final class ChimaeraWing {
|
||||
|
||||
if (Config.getInstance().getChimaeraPreventUseUnderground()) {
|
||||
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
|
||||
player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
|
||||
inHand.setAmount(amount - Config.getInstance().getChimaeraUseCost());
|
||||
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
|
||||
player.updateInventory();
|
||||
player.setVelocity(new Vector(0, 0.5D, 0));
|
||||
CombatUtils.dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
|
||||
mcMMOPlayer.actualizeChimeraWingLastUse();
|
||||
@ -130,8 +129,8 @@ public final class ChimaeraWing {
|
||||
}
|
||||
}
|
||||
|
||||
player.setItemInHand(new ItemStack(getChimaeraWing(player.getItemInHand().getAmount() - Config.getInstance().getChimaeraUseCost())));
|
||||
player.updateInventory();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
inHand.setAmount(inHand.getAmount() - Config.getInstance().getChimaeraUseCost());
|
||||
mcMMOPlayer.actualizeChimeraWingLastUse();
|
||||
mcMMOPlayer.setTeleportCommenceLocation(null);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user