forked from Upstream/mmocore
Fishing conditions now apply on hook
This commit is contained in:
parent
75988f23f0
commit
f98d78959f
@ -18,8 +18,7 @@ public class BiomeCondition extends Condition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(ConditionInstance entity) {
|
public boolean isMet(ConditionInstance instance) {
|
||||||
Biome currentBiome = entity.getEntity().getLocation().getBlock().getBiome();
|
return names.contains(instance.getLocation().getBlock().getBiome().name());
|
||||||
return names.contains(currentBiome.name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,18 @@ import java.util.stream.Stream;
|
|||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ConditionInstance {
|
public class ConditionInstance {
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
private final Location applied;
|
private final Location applied;
|
||||||
private final List<String> regions;
|
private final List<String> regions;
|
||||||
|
|
||||||
public ConditionInstance(Entity entity) {
|
public ConditionInstance(@NotNull Entity entity) {
|
||||||
this(entity, entity.getLocation());
|
this(entity, entity.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionInstance(Entity entity, Location applied) {
|
public ConditionInstance(@NotNull Entity entity, @NotNull Location applied) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.regions = MMOCore.plugin.regionHandler.getRegions(this.applied = applied);
|
this.regions = MMOCore.plugin.regionHandler.getRegions(this.applied = applied);
|
||||||
|
|
||||||
@ -27,10 +28,17 @@ public class ConditionInstance {
|
|||||||
return regions.contains(name);
|
return regions.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Location getAppliedLocation() {
|
public Location getAppliedLocation() {
|
||||||
return applied;
|
return applied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Location getLocation() {
|
||||||
|
return applied;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public Entity getEntity() {
|
public Entity getEntity() {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,7 @@ public class DistanceCondition extends Condition{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(ConditionInstance entity) {
|
public boolean isMet(ConditionInstance instance) {
|
||||||
Entity entity1=entity.getEntity();
|
return instance.getLocation().getWorld().equals(location.getWorld()) && location.distance(instance.getLocation()) < distance;
|
||||||
return entity1.getWorld().equals(location.getWorld())&&location.distance(entity1.getLocation())<distance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@ public class TimeCondition extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(ConditionInstance entity) {
|
public boolean isMet(ConditionInstance entity) {
|
||||||
if (entity.getEntity() instanceof Player player) {
|
long time = entity.getLocation().getWorld().getTime();
|
||||||
long time = player.getWorld().getTime();
|
|
||||||
|
|
||||||
if (min < max) {
|
if (min < max) {
|
||||||
return time > min && time < max;
|
return time > min && time < max;
|
||||||
@ -31,7 +30,4 @@ public class TimeCondition extends Condition {
|
|||||||
return time > min || time < max;
|
return time > min || time < max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,14 @@ public class WeatherCondition extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(ConditionInstance entity) {
|
public boolean isMet(ConditionInstance entity) {
|
||||||
if (entity.getEntity() instanceof Player player) {
|
boolean isClear = entity.getLocation().getWorld().isClearWeather();
|
||||||
boolean isClear = player.getWorld().isClearWeather();
|
boolean hasStorm = entity.getLocation().getWorld().hasStorm();
|
||||||
boolean hasStorm = player.getWorld().hasStorm();
|
|
||||||
|
|
||||||
if (condition.equalsIgnoreCase("clear")) {
|
if (condition.equalsIgnoreCase("clear")) {
|
||||||
return isClear;
|
return isClear;
|
||||||
} else if (condition.equalsIgnoreCase("stormy")) {
|
} else if (condition.equalsIgnoreCase("stormy")) {
|
||||||
return hasStorm;
|
return hasStorm;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,6 @@ public class WorldCondition extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(ConditionInstance entity) {
|
public boolean isMet(ConditionInstance entity) {
|
||||||
return names.contains(entity.getEntity().getWorld().getName()) || names.contains("__global__");
|
return names.contains(entity.getLocation().getWorld().getName()) || names.contains("__global__");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ import net.Indyuce.mmocore.loot.fishing.FishingDropItem;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.FishHook;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -36,8 +39,8 @@ public class FishingManager extends SpecificProfessionManager {
|
|||||||
MMOCore.plugin.statManager.registerProfession("CRITICAL_FISHING_FAILURE_CHANCE", getLinkedProfession());
|
MMOCore.plugin.statManager.registerProfession("CRITICAL_FISHING_FAILURE_CHANCE", getLinkedProfession());
|
||||||
}
|
}
|
||||||
|
|
||||||
public FishingDropTable calculateDropTable(Entity entity) {
|
public FishingDropTable calculateDropTable(@NotNull Player player, @NotNull FishHook hook) {
|
||||||
ConditionInstance conditionEntity = new ConditionInstance(entity);
|
ConditionInstance conditionEntity = new ConditionInstance(player, hook.getLocation());
|
||||||
|
|
||||||
for (FishingDropTable table : tables)
|
for (FishingDropTable table : tables)
|
||||||
if (table.areConditionsMet(conditionEntity))
|
if (table.areConditionsMet(conditionEntity))
|
||||||
|
@ -45,7 +45,7 @@ public class FishingListener implements Listener {
|
|||||||
* Checks for drop tables. If no drop table, just plain vanilla
|
* Checks for drop tables. If no drop table, just plain vanilla
|
||||||
* fishing OTHERWISE initialize fishing, register other listener.
|
* fishing OTHERWISE initialize fishing, register other listener.
|
||||||
*/
|
*/
|
||||||
FishingDropTable table = MMOCore.plugin.fishingManager.calculateDropTable(player);
|
FishingDropTable table = MMOCore.plugin.fishingManager.calculateDropTable(player, hook);
|
||||||
if (table == null)
|
if (table == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user