Added support for unbreaking with lava damage
Buffed fire protection
This commit is contained in:
parent
6debaf32bf
commit
84fe7237be
|
|
@ -49,9 +49,9 @@ public class CatchFish implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemSwitch(PlayerItemHeldEvent event) {
|
public void onItemSwitch(PlayerItemHeldEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getInventory().getItem(event.getNewSlot()) != null) {
|
ItemStack oldItem = player.getInventory().getItem(event.getPreviousSlot());
|
||||||
|
if (oldItem == null || !oldItem.getType().equals(Material.FISHING_ROD))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
stopLavaFishStart(uuid);
|
stopLavaFishStart(uuid);
|
||||||
LavaFishing lavaFishing = activeLavaFishers.get(uuid);
|
LavaFishing lavaFishing = activeLavaFishers.get(uuid);
|
||||||
|
|
@ -91,7 +91,8 @@ public class CatchFish implements Listener {
|
||||||
ItemStack itemStack = optionalFishingRod.get();
|
ItemStack itemStack = optionalFishingRod.get();
|
||||||
int lure = itemStack.getEnchantmentLevel(Enchantment.LURE);
|
int lure = itemStack.getEnchantmentLevel(Enchantment.LURE);
|
||||||
int fireProtection = itemStack.getEnchantmentLevel(Enchantment.PROTECTION_FIRE);
|
int fireProtection = itemStack.getEnchantmentLevel(Enchantment.PROTECTION_FIRE);
|
||||||
LavaFishing lavaFishing = new LavaFishing(lure, fireProtection, player, logger, event.getHook().getLocation());
|
int unbreaking = itemStack.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||||
|
LavaFishing lavaFishing = new LavaFishing(lure, fireProtection, unbreaking, player, logger, event.getHook().getLocation());
|
||||||
activeLavaFishers.put(uuid, lavaFishing);
|
activeLavaFishers.put(uuid, lavaFishing);
|
||||||
lavaFishing.runTaskTimerAsynchronously(fishingEvent, 1, 1);
|
lavaFishing.runTaskTimerAsynchronously(fishingEvent, 1, 1);
|
||||||
logger.debug("in lava above");
|
logger.debug("in lava above");
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
private int timeUntilLured;
|
private int timeUntilLured;
|
||||||
private final int lure;
|
private final int lure;
|
||||||
private final int fireProtection;
|
private final int fireProtection;
|
||||||
|
private final int unbreaking;
|
||||||
private final int minWaitTime = 60;
|
private final int minWaitTime = 60;
|
||||||
private final int maxWaitTime = 500;
|
private final int maxWaitTime = 500;
|
||||||
private boolean isBiting;
|
private boolean isBiting;
|
||||||
|
|
@ -32,12 +33,13 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Location hookLocation;
|
private final Location hookLocation;
|
||||||
|
|
||||||
public LavaFishing(int lure, int fireProtection, Player player, Logger logger, Location hookLocation) {
|
public LavaFishing(int lure, int fireProtection, int unbreaking, Player player, Logger logger, Location hookLocation) {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
if (activeFishers.containsKey(uuid)) {
|
if (activeFishers.containsKey(uuid)) {
|
||||||
activeFishers.get(uuid).cancel();
|
activeFishers.get(uuid).cancel();
|
||||||
}
|
}
|
||||||
activeFishers.put(uuid, this);
|
activeFishers.put(uuid, this);
|
||||||
|
this.unbreaking = unbreaking;
|
||||||
this.lure = lure;
|
this.lure = lure;
|
||||||
this.fireProtection = Math.min(5, fireProtection);
|
this.fireProtection = Math.min(5, fireProtection);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
@ -56,15 +58,16 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
|
|
||||||
private void damageHook() {
|
private void damageHook() {
|
||||||
if (!shouldDamageHook) {
|
if (!shouldDamageHook) {
|
||||||
logger.debug("Rod should not be damaged for this player");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (timeUntilHookDamage > 0) {
|
if (timeUntilHookDamage > 0) {
|
||||||
timeUntilHookDamage--;
|
timeUntilHookDamage--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("Damaging hook...");
|
|
||||||
resetTimeUntilHookDamage();
|
resetTimeUntilHookDamage();
|
||||||
|
if (unbreaking > 0 && random.nextInt(unbreaking + 1) > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
int fishingRodSlot = findFishingRodSlot(inventory);
|
int fishingRodSlot = findFishingRodSlot(inventory);
|
||||||
if (fishingRodSlot < 0) {
|
if (fishingRodSlot < 0) {
|
||||||
|
|
@ -100,19 +103,17 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetTimeUntilHookDamage() {
|
private void resetTimeUntilHookDamage() {
|
||||||
timeUntilHookDamage = random.nextInt(fireProtection * 5, 20 + fireProtection * 5);
|
timeUntilHookDamage = random.nextInt(fireProtection * 10, 20 + fireProtection * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnLavaParticles() {
|
private void spawnLavaParticles() {
|
||||||
// Customize the particle effect
|
|
||||||
Particle particle = Particle.LAVA;
|
Particle particle = Particle.LAVA;
|
||||||
int count = 10; // Number of particles to spawn
|
int count = 10;
|
||||||
double offsetX = 0.2; // X-axis offset
|
double offsetX = 0.2;
|
||||||
double offsetY = 1.0; // Y-axis offset (positive value for upward direction)
|
double offsetY = 1.0;
|
||||||
double offsetZ = 0.2; // Z-axis offset
|
double offsetZ = 0.2;
|
||||||
double extra = 0.1; // Extra random offset
|
double extra = 0.1;
|
||||||
|
|
||||||
// Spawn the lava particles
|
|
||||||
hookLocation.getWorld().spawnParticle(particle, hookLocation, count, offsetX, offsetY, offsetZ, extra);
|
hookLocation.getWorld().spawnParticle(particle, hookLocation, count, offsetX, offsetY, offsetZ, extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,21 +122,16 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
damageHook();
|
damageHook();
|
||||||
if (!isBiting && timeUntilLured > 0) {
|
if (!isBiting && timeUntilLured > 0) {
|
||||||
timeUntilLured--;
|
timeUntilLured--;
|
||||||
if (timeUntilLured % 5 == 0)
|
|
||||||
logger.debug("Time until lured: %", String.valueOf(timeUntilLured));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isBiting) {
|
if (!isBiting) {
|
||||||
isBiting = true;
|
isBiting = true;
|
||||||
this.timeUntilHooked = random.nextInt(20, 60);
|
this.timeUntilHooked = random.nextInt(20, 60);
|
||||||
spawnLavaParticles();
|
spawnLavaParticles();
|
||||||
logger.debug("Fish on hook in lava");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.timeUntilHooked > 0) {
|
if (this.timeUntilHooked > 0) {
|
||||||
this.timeUntilHooked--;
|
this.timeUntilHooked--;
|
||||||
if (timeUntilHooked % 5 == 0)
|
|
||||||
logger.debug("Time until hooked: %", String.valueOf(timeUntilHooked));
|
|
||||||
if (this.timeUntilHooked % 5 == 0)
|
if (this.timeUntilHooked % 5 == 0)
|
||||||
spawnLavaParticles();
|
spawnLavaParticles();
|
||||||
return;
|
return;
|
||||||
|
|
@ -146,4 +142,11 @@ public class LavaFishing extends BukkitRunnable {
|
||||||
public boolean canCatchFish() {
|
public boolean canCatchFish() {
|
||||||
return isBiting;
|
return isBiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void cancel() throws IllegalStateException {
|
||||||
|
super.cancel();
|
||||||
|
logger.debug("Cancelled");
|
||||||
|
activeFishers.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user