1
0
Fork 0

allowed for durability to only decrease with multiple blocks in blocks-list

This does not yet apply for hammers/excavators due to how blocks are added to the utility list.
This commit is contained in:
lightling 2019-09-16 16:42:10 -04:00
parent d23fb9e3e9
commit 160eebb7f6
3 changed files with 39 additions and 12 deletions

View file

@ -29,6 +29,7 @@ GibsoniaCraft adds new tools to the server. Excavator/Hammer based off of BradzC
- Does not account for enchantments - Does not account for enchantments
- Hammer/Excavator fails at x=-1 (and likely z=-1) - Hammer/Excavator fails at x=-1 (and likely z=-1)
- Due to the current check for hammer/excavator block adding (originally based off of PowerTool's method), durablity on hammers/excavators will always have extra durability reduction even if only one block was added (will eventually change to only add blocks to list if they are the right type, like with lumber-axe)
## License ## License
[MIT](LICENSE) [MIT](LICENSE)

View file

@ -1,6 +1,6 @@
main: lightling.gibsoniacraft.GibsoniaCraft main: lightling.gibsoniacraft.GibsoniaCraft
name: GibsoniaCraft name: GibsoniaCraft
version: 1.1.0 version: 1.1.1
author: Lightling author: Lightling
description: Adds some small additions/changes to a PaperMC server description: Adds some small additions/changes to a PaperMC server
api-version: 1.14 api-version: 1.14

View file

@ -5,6 +5,9 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import org.bukkit.Location; import org.bukkit.Location;
// Needed for handling events // Needed for handling events
@ -63,6 +66,7 @@ public class BlockListener implements Listener
String pName = player.getName(); String pName = player.getName();
PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener(); PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener();
BlockFace blockFace = pListener.GetFaceByName(pName); BlockFace blockFace = pListener.GetFaceByName(pName);
ArrayList<Block> blocks = ToolUtil.GetSurroundingBlocks(blockFace, block);
// Grab durability information // Grab durability information
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -72,9 +76,13 @@ public class BlockListener implements Listener
// Used in determining if an extra block was broken (for durability) // Used in determining if an extra block was broken (for durability)
boolean success = false; boolean success = false;
if (blocks.size() > 1)
{
success = true;
}
// Iterates through to break surrounding blocks // Iterates through to break surrounding blocks
for (Block b : ToolUtil.GetSurroundingBlocks(blockFace, block)) for (Block b : blocks)
{ {
// Determine the block type and position // Determine the block type and position
Material blockMat = b.getType(); Material blockMat = b.getType();
@ -94,23 +102,30 @@ public class BlockListener implements Listener
final ItemStack snow = new ItemStack(Material.SNOWBALL, 1 + b.getData()); final ItemStack snow = new ItemStack(Material.SNOWBALL, 1 + b.getData());
b.getWorld().dropItemNaturally(blockLoc, snow); b.getWorld().dropItemNaturally(blockLoc, snow);
} }
success = true;
b.breakNaturally(); b.breakNaturally();
} }
} }
// Used for determining durability loss
int addToDamage = 0;
// Do extra damage to durability if extra blocks were broken // Do extra damage to durability if extra blocks were broken
if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY)) if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY))
{ {
int addToDamage = 2; addToDamage = 2;
if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL)
// Diamond tools take less damage
if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL)
{ {
addToDamage = 1; addToDamage = 1;
} }
dMeta.setDamage(currDur + addToDamage);
item.setItemMeta(meta);
} }
// Update durability
dMeta.setDamage(currDur + addToDamage);
item.setItemMeta(meta);
} }
/** /**
@ -140,6 +155,7 @@ public class BlockListener implements Listener
// Get block information via the player listener // Get block information via the player listener
Block block = bbEvent.getBlock(); Block block = bbEvent.getBlock();
ArrayList<Block> blocks = ToolUtil.GetUpwardLogs(block);
// Grab durability information // Grab durability information
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -149,6 +165,10 @@ public class BlockListener implements Listener
// Used in determining if an extra block was broken (for durability) // Used in determining if an extra block was broken (for durability)
boolean success = false; boolean success = false;
if (blocks.size() > 1)
{
success = true;
}
for (Block b : ToolUtil.GetUpwardLogs(block)) for (Block b : ToolUtil.GetUpwardLogs(block))
{ {
@ -161,21 +181,27 @@ public class BlockListener implements Listener
if (isAxe) if (isAxe)
{ {
success = true;
b.breakNaturally(); b.breakNaturally();
} }
} }
// Used for determining durability loss
int addToDamage = 0;
// Do extra damage to durability if extra blocks were broken // Do extra damage to durability if extra blocks were broken
if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY)) if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY))
{ {
int addToDamage = 2; addToDamage = 2;
if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL)
// Diamond tools take less damage
if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL)
{ {
addToDamage = 1; addToDamage = 1;
} }
dMeta.setDamage(currDur + addToDamage);
item.setItemMeta(meta);
} }
// Update durability
dMeta.setDamage(currDur + addToDamage);
item.setItemMeta(meta);
} }
} }