1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Added damageable setting

This commit is contained in:
TheBusyBiscuit 2020-08-24 20:35:35 +02:00
parent 8c2038634f
commit 9e92f64222

View File

@ -50,12 +50,13 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
private static final double BASE_POWER = 0.9; private static final double BASE_POWER = 0.9;
private final ItemSetting<Boolean> dualWielding = new ItemSetting<>("dual-wielding", true); private final ItemSetting<Boolean> dualWielding = new ItemSetting<>("dual-wielding", true);
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>("damage-on-use", true);
private final Map<Material, Double> materialSpeeds; private final Map<Material, Double> materialSpeeds;
private final Set<UUID> users = new HashSet<>(); private final Set<UUID> users = new HashSet<>();
public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe); super(category, item, recipeType, recipe);
addItemSetting(dualWielding); addItemSetting(dualWielding, damageOnUse);
String cfgKey = getID() + ".launch-amounts."; String cfgKey = getID() + ".launch-amounts.";
Config itemCfg = SlimefunPlugin.getItemCfg(); Config itemCfg = SlimefunPlugin.getItemCfg();
@ -101,23 +102,22 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
Player p = e.getPlayer(); Player p = e.getPlayer();
// Check if the Player is standing close to the wall // Check if the Player is standing close to the wall
if (p.getLocation().distanceSquared(block.getLocation().add(0.5, 0.5, 0.5)) > 3.5) { if (p.getLocation().distanceSquared(block.getLocation().add(0.5, 0.5, 0.5)) > 4) {
return; return;
} }
// Check for dual wielding
if (isDualWieldingEnabled() && !isItem(getOtherHandItem(p, e.getHand()))) { if (isDualWieldingEnabled() && !isItem(getOtherHandItem(p, e.getHand()))) {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.dual-wielding"); SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.dual-wielding");
return; return;
} }
// Top and bottom faces won't be allowed
if (e.getClickedFace() == BlockFace.DOWN || e.getClickedFace() == BlockFace.UP) { if (e.getClickedFace() == BlockFace.DOWN || e.getClickedFace() == BlockFace.UP) {
return; return;
} }
// Prevent players from spamming this
if (users.add(p.getUniqueId())) {
climb(p, e.getHand(), e.getItem(), block); climb(p, e.getHand(), e.getItem(), block);
}
}; };
} }
@ -133,16 +133,16 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) { private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) {
double power = materialSpeeds.getOrDefault(block.getType(), 0.0); double power = materialSpeeds.getOrDefault(block.getType(), 0.0);
Vector velocity = new Vector(0, 0, 0);
if (power > 0.05) { if (power > 0.05) {
// Prevent players from spamming this
if (users.add(p.getUniqueId())) {
int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED); int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED);
if (efficiencyLevel != 0) { if (efficiencyLevel != 0) {
power += efficiencyLevel * 0.1; power += efficiencyLevel * 0.1;
} }
velocity.setY(power * BASE_POWER); Vector velocity = new Vector(0, power * BASE_POWER, 0);
ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block); ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -153,6 +153,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
swing(p, hand, item); swing(p, hand, item);
} }
} }
}
else { else {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.wrong-material"); SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.wrong-material");
} }
@ -190,7 +191,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
@Override @Override
public boolean isDamageable() { public boolean isDamageable() {
return true; return damageOnUse.getValue();
} }
@Override @Override