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

Merge pull request #1076 from LinoxGH/master

Fixes #253
This commit is contained in:
TheBusyBiscuit 2019-09-01 23:21:47 +02:00 committed by GitHub
commit 6dc24d0ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 40 deletions

View File

@ -261,6 +261,8 @@ public class SlimefunItem {
if (this instanceof VanillaItem) this.state = State.VANILLA;
else this.state = State.DISABLED;
}
postRegister();
} catch(Exception x) {
Slimefun.getLogger().log(Level.WARNING, "Registering the Item '" + id + "' for Slimefun " + Slimefun.getVersion() + " has failed", x);
}
@ -506,6 +508,8 @@ public class SlimefunItem {
ChargableBlock.registerCapacitor(id, capacity);
}
public void postRegister() {}
protected void setItem(ItemStack stack) {
this.item = stack;
}

View File

@ -1,11 +1,11 @@
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.items;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Bat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -19,12 +19,16 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemInteractionHandler;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.utils.Utilities;
public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
import java.util.UUID;
public GrapplingHook(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe);
public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
private long despawnTicks;
public GrapplingHook(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(category, item, id, recipeType, recipe, keys, values);
}
@Override
@ -33,27 +37,47 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
return (e, p, item) -> {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GRAPPLING_HOOK, true)) {
if (e.getClickedBlock() == null && !utilities.jumpState.containsKey(p.getUniqueId())) {
UUID uuid = p.getUniqueId();
if (e.getClickedBlock() == null && !utilities.jumpState.containsKey(uuid)) {
e.setCancelled(true);
if (p.getInventory().getItemInOffHand().getType() == Material.BOW) {
// Cancel, to fix dupe #740
return false;
}
utilities.jumpState.put(p.getUniqueId(), p.getInventory().getItemInMainHand().getType() != Material.SHEARS);
if (p.getInventory().getItemInMainHand().getType() == Material.LEAD) PlayerInventory.consumeItemInHand(p);
utilities.jumpState.put(uuid, p.getInventory().getItemInMainHand().getType() != Material.SHEARS);
if (p.getInventory().getItemInMainHand().getType() == Material.LEAD)
PlayerInventory.consumeItemInHand(p);
Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
Projectile projectile = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
projectile.setShooter(p);
projectile.setVelocity(direction);
Arrow arrow = (Arrow) projectile;
Arrow arrow = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
arrow.setShooter(p);
arrow.setVelocity(direction);
Bat b = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
b.setCanPickupItems(false);
b.setAI(false);
b.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
b.setLeashHolder(arrow);
utilities.damage.add(p.getUniqueId());
utilities.remove.put(p.getUniqueId(), new Entity[] {b, arrow});
utilities.damage.add(uuid);
utilities.remove.put(uuid, new Entity[]{b, arrow});
// To fix issue #253
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
if (utilities.jumpState.containsKey(uuid)) {
utilities.arrows.remove(uuid);
for (Entity n : utilities.remove.get(uuid)) {
if (n.isValid()) n.remove();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
utilities.damage.remove(uuid);
utilities.jumpState.remove(uuid);
utilities.remove.remove(uuid);
}, 20L);
}
}, despawnTicks);
}
return true;
}
@ -61,4 +85,8 @@ public class GrapplingHook extends SimpleSlimefunItem<ItemInteractionHandler> {
};
}
@Override
public void postRegister() {
despawnTicks = (int) Slimefun.getItemValue("GRAPPLING_HOOK", "despawn-seconds") * 20;
}
}

View File

@ -611,7 +611,8 @@ public final class SlimefunSetup {
.register(true);
new GrapplingHook(Categories.TOOLS, SlimefunItems.GRAPPLING_HOOK, "GRAPPLING_HOOK", RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, SlimefunItems.HOOK, SlimefunItems.HOOK, null, SlimefunItems.CHAIN, SlimefunItems.HOOK, SlimefunItems.CHAIN, null, null})
new ItemStack[] {null, SlimefunItems.HOOK, SlimefunItems.HOOK, null, SlimefunItems.CHAIN, SlimefunItems.HOOK, SlimefunItems.CHAIN, null, null},
new String[] {"despawn-seconds"}, new Object[] {60})
.register(true);
new MagicWorkbench().register();

View File

@ -39,7 +39,7 @@ public class BowListener implements Listener {
public void onArrowHit(final ProjectileHitEvent e) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
if (!e.getEntity().isValid()) return;
if (utilities.arrows.containsKey(e.getEntity().getUniqueId())) utilities.arrows.remove(e.getEntity().getUniqueId());
utilities.arrows.remove(e.getEntity().getUniqueId());
if (e.getEntity() instanceof Arrow) handleGrapplingHook((Arrow) e.getEntity());
}, 4L);
}
@ -55,7 +55,7 @@ public class BowListener implements Listener {
else p.setVelocity(arrow.getLocation().toVector().subtract(p.getLocation().toVector()));
for (Entity n: utilities.remove.get(p.getUniqueId())) {
n.remove();
if (n.isValid()) n.remove();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
@ -84,7 +84,7 @@ public class BowListener implements Listener {
p.setVelocity(v);
for (Entity n: utilities.remove.get(p.getUniqueId())) {
n.remove();
if (n.isValid()) n.remove();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {

View File

@ -16,7 +16,7 @@ public interface DamageableItem {
if (item == null || item.getType() == null || item.getType() == Material.AIR) {
return;
}
else if (item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + 40 / (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
else if (item.getAmount() > 0 && isDamageable() && !item.getEnchantments().containsKey(Enchantment.DURABILITY) || Math.random() * 100 <= (60 + Math.floorDiv(40, (item.getEnchantmentLevel(Enchantment.DURABILITY) + 1)))) {
ItemMeta meta = item.getItemMeta();
Damageable damageable = (Damageable) meta;