Cleanup & Silk Touch changes.

This commit is contained in:
GJ 2012-05-18 11:15:30 -04:00
parent 6da43b15c8
commit a622707608
4 changed files with 192 additions and 104 deletions

View File

@ -7,6 +7,9 @@ Key:
! Change
- Removal
Version 1.3.08
! Changed Mining to allow Silk Touch to work again since the dupe exploit has been fixed.
Version 1.3.07
+ Added ability to gain XP from custom blocks. Enable custom blocks in the config file, then enter the data in the blocks.yml file.
+ Added ability to gain XP with custom tools. Enable custom tools in the config file, then enter the data in the tools.yml file.

View File

@ -23,11 +23,9 @@ import com.gmail.nossr50.util.Users;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -43,6 +41,8 @@ import org.getspout.spoutapi.sound.SoundEffect;
public class BlockListener implements Listener {
private final mcMMO plugin;
private static Config configInstance = Config.getInstance();
private static Permissions permInstance = Permissions.getInstance();
public BlockListener(final mcMMO plugin) {
this.plugin = plugin;
@ -119,7 +119,7 @@ public class BlockListener implements Listener {
mcMMO.placeStore.setTrue(block);
}
if (id == Config.getInstance().getRepairAnvilId() && Config.getInstance().getRepairAnvilMessagesEnabled()) {
if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
Repair.placedAnvilCheck(player, id);
}
}
@ -134,60 +134,55 @@ public class BlockListener implements Listener {
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
Block block = event.getBlock();
Material mat = block.getType();
ItemStack inhand = player.getItemInHand();
ItemStack inHand = player.getItemInHand();
if (event instanceof FakeBlockBreakEvent) {
return;
}
/*
* HERBALISM
*/
/* HERBALISM */
if (BlockChecks.canBeGreenTerra(block)) {
/* Green Terra */
if (PP.getToolPreparationMode(ToolType.HOE) && Permissions.getInstance().greenTerra(player) && ((mat.equals(Material.CROPS) && block.getData() == CropState.RIPE.getData()) || BlockChecks.canBeGreenTerra(block))) {
if (PP.getToolPreparationMode(ToolType.HOE) && permInstance.greenTerra(player)) {
Skills.abilityCheck(player, SkillType.HERBALISM);
}
/* Triple drops */
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canBeGreenTerra(block)) {
if (PP.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, player, event, plugin);
}
if (Permissions.getInstance().herbalism(player) && BlockChecks.canBeGreenTerra(block)) {
if (permInstance.herbalism(player)) {
Herbalism.herbalismProcCheck(block, player, event, plugin);
}
}
/*
* MINING
*/
if (Permissions.getInstance().mining(player) && BlockChecks.canBeSuperBroken(block)) {
if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isPickaxe(inhand)) {
/* MINING */
else if (BlockChecks.canBeSuperBroken(block) && permInstance.mining(player)) {
if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) {
Mining.miningBlockCheck(player, block);
}
else if (!Config.getInstance().getMiningRequiresTool()) {
}
else {
Mining.miningBlockCheck(player, block);
}
}
/*
* WOOD CUTTING
*/
if (Permissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
if (Config.getInstance().getWoodcuttingRequiresTool() && ItemChecks.isAxe(inhand)) {
WoodCutting.woodcuttingBlockCheck(player, block);
}
else if (!Config.getInstance().getWoodcuttingRequiresTool()) {
/* WOOD CUTTING */
else if (BlockChecks.isLog(block) && permInstance.woodcutting(player)) {
if (configInstance.getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(inHand)) {
WoodCutting.woodcuttingBlockCheck(player, block);
}
}
else {
WoodCutting.woodcuttingBlockCheck(player, block);
}
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.getInstance().treeFeller(player) && ItemChecks.isAxe(inhand)) {
if (Config.getInstance().getToolModsEnabled()) {
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && permInstance.treeFeller(player) && ItemChecks.isAxe(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
WoodCutting.treeFeller(event);
}
}
@ -195,16 +190,16 @@ public class BlockListener implements Listener {
WoodCutting.treeFeller(event);
}
}
}
/*
* EXCAVATION
*/
if (BlockChecks.canBeGigaDrillBroken(block) && Permissions.getInstance().excavation(player) && !mcMMO.placeStore.isTrue(block)) {
if (Config.getInstance().getExcavationRequiresTool() && ItemChecks.isShovel(inhand)) {
/* EXCAVATION */
else if (BlockChecks.canBeGigaDrillBroken(block) && permInstance.excavation(player) && !mcMMO.placeStore.isTrue(block)) {
if (configInstance.getExcavationRequiresTool()) {
if (ItemChecks.isShovel(inHand)) {
Excavation.excavationProcCheck(block, player);
}
else if (!Config.getInstance().getExcavationRequiresTool()) {
}
else {
Excavation.excavationProcCheck(block, player);
}
}
@ -226,9 +221,9 @@ public class BlockListener implements Listener {
Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player);
ItemStack inhand = player.getItemInHand();
ItemStack inHand = player.getItemInHand();
Block block = event.getBlock();
Material mat = block.getType();
Material material = block.getType();
/*
* ABILITY PREPARATION CHECKS
@ -237,7 +232,7 @@ public class BlockListener implements Listener {
if (PP.getToolPreparationMode(ToolType.HOE) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.makeMossy(block))) {
Skills.abilityCheck(player, SkillType.HERBALISM);
}
else if (PP.getToolPreparationMode(ToolType.AXE) && mat.equals(Material.LOG) && Permissions.getInstance().treeFeller(player)) { //TODO: Why are we checking the permissions here?
else if (PP.getToolPreparationMode(ToolType.AXE) && BlockChecks.isLog(block) && permInstance.treeFeller(player)) { //TODO: Why are we checking the permissions here?
Skills.abilityCheck(player, SkillType.WOODCUTTING);
}
else if (PP.getToolPreparationMode(ToolType.PICKAXE) && BlockChecks.canBeSuperBroken(block)) {
@ -246,22 +241,22 @@ public class BlockListener implements Listener {
else if (PP.getToolPreparationMode(ToolType.SHOVEL) && BlockChecks.canBeGigaDrillBroken(block)) {
Skills.abilityCheck(player, SkillType.EXCAVATION);
}
else if (PP.getToolPreparationMode(ToolType.FISTS) && (BlockChecks.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW))) {
else if (PP.getToolPreparationMode(ToolType.FISTS) && (BlockChecks.canBeGigaDrillBroken(block) || material.equals(Material.SNOW))) {
Skills.abilityCheck(player, SkillType.UNARMED);
}
}
/* TREE FELLER SOUNDS */
if (Config.getInstance().spoutEnabled && mat.equals(Material.LOG) && PP.getAbilityMode(AbilityType.TREE_FELLER)) {
if (configInstance.spoutEnabled && BlockChecks.isLog(block) && PP.getAbilityMode(AbilityType.TREE_FELLER)) {
SpoutSounds.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
}
/*
* ABILITY TRIGGER CHECKS
*/
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && Permissions.getInstance().greenTerra(player) && BlockChecks.makeMossy(block)) {
if (Config.getInstance().getToolModsEnabled()) {
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && permInstance.greenTerra(player) && BlockChecks.makeMossy(block)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
Herbalism.greenTerra(player, block);
}
}
@ -270,9 +265,10 @@ public class BlockListener implements Listener {
}
}
else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
if (Config.getInstance().getExcavationRequiresTool() && ItemChecks.isShovel(inhand)) {
if (Config.getInstance().getToolModsEnabled()) {
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
if (configInstance.getExcavationRequiresTool()) {
if (ItemChecks.isShovel(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
}
@ -282,52 +278,53 @@ public class BlockListener implements Listener {
Excavation.gigaDrillBreaker(player, block);
}
}
else if (!Config.getInstance().getExcavationRequiresTool()) {
}
else {
event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block);
}
}
else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
if (inhand.getType().equals(Material.AIR)) {
if (inHand.getType().equals(Material.AIR)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
plugin.getServer().getPluginManager().callEvent(armswing);
event.setInstaBreak(true);
}
if (Config.getInstance().spoutEnabled) {
if (configInstance.spoutEnabled) {
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
}
}
else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
if (!player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { //TODO: Why are we checking this?
if (Config.getInstance().getMiningRequiresTool() && ItemChecks.isPickaxe(inhand)) {
if (Config.getInstance().getToolModsEnabled()) {
if ((ItemChecks.isCustomTool(inhand) && ModChecks.getToolFromItemStack(inhand).isAbilityEnabled()) || !ItemChecks.isCustomTool(inhand)) {
if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) {
if (ItemChecks.isCustomTool(inHand)) {
if (ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block);
Mining.superBreakerBlockCheck(player, block);
}
}
else {
event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block);
Mining.superBreakerBlockCheck(player, block);
}
}
else if (!Config.getInstance().getMiningRequiresTool()) {
}
else {
event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block);
Mining.superBreakerBlockCheck(player, block);
}
}
}
else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (mat.equals(Material.LEAVES) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) {
if (Config.getInstance().getWoodcuttingRequiresTool() && ItemChecks.isAxe(inhand)) {
else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) {
if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
if (configInstance.getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(inHand)) {
event.setInstaBreak(true);
WoodCutting.leafBlower(player, block);
}
}
else if (!Config.getInstance().getWoodcuttingRequiresTool() && !inhand.getType().equals(Material.SHEARS)) {
if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
else if (!inHand.getType().equals(Material.SHEARS)) {
event.setInstaBreak(true);
WoodCutting.leafBlower(player, block);
}

View File

@ -6,14 +6,13 @@ import org.bukkit.CoalType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.sound.SoundEffect;
import org.bukkit.enchantments.Enchantment;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Permissions;
@ -29,6 +28,74 @@ public class Mining {
private static Random random = new Random();
/**
* Handle double drops when using Silk Touch.
*
* @param block The block to process drops for
*/
private static void silkTouchDrops(Block block) {
Location loc = block.getLocation();
Material type = block.getType();
ItemStack item = new ItemStack(type);
Config configInstance = Config.getInstance();
switch (type) {
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
miningDrops(block);
break;
case COAL_ORE:
if (configInstance.getCoalDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
case DIAMOND_ORE:
if (configInstance.getDiamondDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (configInstance.getRedstoneDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
case GLOWSTONE:
if (configInstance.getGlowstoneDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
case LAPIS_ORE:
if (configInstance.getLapisDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
case STONE:
if (configInstance.getStoneDoubleDropsEnabled()) {
Misc.mcDropItem(loc, item);
}
break;
default:
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
Misc.mcDropItem(loc, item);
}
break;
}
}
/**
* Drop items from Mining & Blast Mining skills.
*
@ -130,7 +197,7 @@ public class Mining {
break;
default:
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
item = ModChecks.getCustomBlock(block).getItemDrop();
Misc.mcDropItem(loc, item);
}
@ -221,18 +288,21 @@ public class Mining {
* @param block The block being broken
*/
public static void miningBlockCheck(Player player, Block block) {
if (mcMMO.placeStore.isTrue(block) || player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
if (mcMMO.placeStore.isTrue(block)) {
return;
}
miningXP(player, block);
if (BlockChecks.canBeSuperBroken(block)) {
final int MAX_BONUS_LEVEL = 1000;
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().miningDoubleDrops(player)) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
silkTouchDrops(block);
}
else {
miningDrops(block);
}
}
@ -244,7 +314,7 @@ public class Mining {
* @param player The player using the ability
* @param block The block being affected
*/
public static void SuperBreakerBlockCheck(Player player, Block block) {
public static void superBreakerBlockCheck(Player player, Block block) {
Material type = block.getType();
int tier = Misc.getTier(player.getItemInHand());
int durabilityLoss = Config.getInstance().getAbilityToolDamage();

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.util;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
@ -158,7 +160,6 @@ public class BlockChecks {
switch (block.getType()) {
case BROWN_MUSHROOM:
case CACTUS:
case CROPS:
case MELON_BLOCK:
case NETHER_WARTS:
case PUMPKIN:
@ -170,6 +171,14 @@ public class BlockChecks {
case YELLOW_FLOWER:
return true;
case CROPS:
if (block.getData() == CropState.RIPE.getData()) {
return true;
}
else {
return false;
}
default:
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
return true;
@ -263,4 +272,13 @@ public class BlockChecks {
}
}
}
public static boolean isLog (Block block){
if (block.getType().equals(Material.LOG) || (customBlocksEnabled && ModChecks.isCustomLogBlock(block))) {
return true;
}
else {
return false;
}
}
}