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:
parent
d23fb9e3e9
commit
160eebb7f6
3 changed files with 39 additions and 12 deletions
|
@ -29,6 +29,7 @@ GibsoniaCraft adds new tools to the server. Excavator/Hammer based off of BradzC
|
|||
|
||||
- Does not account for enchantments
|
||||
- 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
|
||||
[MIT](LICENSE)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
main: lightling.gibsoniacraft.GibsoniaCraft
|
||||
name: GibsoniaCraft
|
||||
version: 1.1.0
|
||||
version: 1.1.1
|
||||
author: Lightling
|
||||
description: Adds some small additions/changes to a PaperMC server
|
||||
api-version: 1.14
|
|
@ -5,6 +5,9 @@ import org.bukkit.Material;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
// Needed for handling events
|
||||
|
@ -63,6 +66,7 @@ public class BlockListener implements Listener
|
|||
String pName = player.getName();
|
||||
PlayerInteractListener pListener = gcPlugin.GetPlayerInteractListener();
|
||||
BlockFace blockFace = pListener.GetFaceByName(pName);
|
||||
ArrayList<Block> blocks = ToolUtil.GetSurroundingBlocks(blockFace, block);
|
||||
|
||||
// Grab durability information
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
@ -72,9 +76,13 @@ public class BlockListener implements Listener
|
|||
|
||||
// Used in determining if an extra block was broken (for durability)
|
||||
boolean success = false;
|
||||
if (blocks.size() > 1)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
||||
// Iterates through to break surrounding blocks
|
||||
for (Block b : ToolUtil.GetSurroundingBlocks(blockFace, block))
|
||||
for (Block b : blocks)
|
||||
{
|
||||
// Determine the block type and position
|
||||
Material blockMat = b.getType();
|
||||
|
@ -94,23 +102,30 @@ public class BlockListener implements Listener
|
|||
final ItemStack snow = new ItemStack(Material.SNOWBALL, 1 + b.getData());
|
||||
b.getWorld().dropItemNaturally(blockLoc, snow);
|
||||
}
|
||||
success = true;
|
||||
|
||||
b.breakNaturally();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Used for determining durability loss
|
||||
int addToDamage = 0;
|
||||
|
||||
// Do extra damage to durability if extra blocks were broken
|
||||
if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY))
|
||||
{
|
||||
int addToDamage = 2;
|
||||
if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL)
|
||||
addToDamage = 2;
|
||||
|
||||
// Diamond tools take less damage
|
||||
if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL)
|
||||
{
|
||||
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
|
||||
Block block = bbEvent.getBlock();
|
||||
ArrayList<Block> blocks = ToolUtil.GetUpwardLogs(block);
|
||||
|
||||
// Grab durability information
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
@ -149,6 +165,10 @@ public class BlockListener implements Listener
|
|||
|
||||
// Used in determining if an extra block was broken (for durability)
|
||||
boolean success = false;
|
||||
if (blocks.size() > 1)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
||||
for (Block b : ToolUtil.GetUpwardLogs(block))
|
||||
{
|
||||
|
@ -161,21 +181,27 @@ public class BlockListener implements Listener
|
|||
|
||||
if (isAxe)
|
||||
{
|
||||
success = true;
|
||||
b.breakNaturally();
|
||||
}
|
||||
}
|
||||
|
||||
// Used for determining durability loss
|
||||
int addToDamage = 0;
|
||||
|
||||
// Do extra damage to durability if extra blocks were broken
|
||||
if (success && !item.getEnchantments().containsKey(Enchantment.DURABILITY))
|
||||
{
|
||||
int addToDamage = 2;
|
||||
if (itemType == Material.DIAMOND_PICKAXE && itemType == Material.DIAMOND_SHOVEL)
|
||||
addToDamage = 2;
|
||||
|
||||
// Diamond tools take less damage
|
||||
if (itemType == Material.DIAMOND_PICKAXE || itemType == Material.DIAMOND_SHOVEL)
|
||||
{
|
||||
addToDamage = 1;
|
||||
}
|
||||
dMeta.setDamage(currDur + addToDamage);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
// Update durability
|
||||
dMeta.setDamage(currDur + addToDamage);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue