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