mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-18 08:52:10 +01:00
Fishing conditions now apply on hook
This commit is contained in:
parent
75988f23f0
commit
f98d78959f
@ -8,18 +8,17 @@ import org.bukkit.block.Biome;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
|
||||
public class BiomeCondition extends Condition {
|
||||
private final List<String> names;
|
||||
private final List<String> names;
|
||||
|
||||
public BiomeCondition(MMOLineConfig config) {
|
||||
super(config);
|
||||
public BiomeCondition(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
config.validate("name");
|
||||
names = Arrays.asList(config.getString("name").toUpperCase().split(","));
|
||||
}
|
||||
config.validate("name");
|
||||
names = Arrays.asList(config.getString("name").toUpperCase().split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance entity) {
|
||||
Biome currentBiome = entity.getEntity().getLocation().getBlock().getBiome();
|
||||
return names.contains(currentBiome.name());
|
||||
}
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance instance) {
|
||||
return names.contains(instance.getLocation().getBlock().getBiome().name());
|
||||
}
|
||||
}
|
||||
|
@ -6,36 +6,44 @@ import java.util.stream.Stream;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionInstance {
|
||||
private final Entity entity;
|
||||
private final Location applied;
|
||||
private final List<String> regions;
|
||||
private final Entity entity;
|
||||
private final Location applied;
|
||||
private final List<String> regions;
|
||||
|
||||
public ConditionInstance(Entity entity) {
|
||||
this(entity, entity.getLocation());
|
||||
}
|
||||
public ConditionInstance(@NotNull Entity entity) {
|
||||
this(entity, entity.getLocation());
|
||||
}
|
||||
|
||||
public ConditionInstance(Entity entity, Location applied) {
|
||||
this.entity = entity;
|
||||
this.regions = MMOCore.plugin.regionHandler.getRegions(this.applied = applied);
|
||||
|
||||
regions.add("__global__");
|
||||
}
|
||||
public ConditionInstance(@NotNull Entity entity, @NotNull Location applied) {
|
||||
this.entity = entity;
|
||||
this.regions = MMOCore.plugin.regionHandler.getRegions(this.applied = applied);
|
||||
|
||||
public boolean isInRegion(String name) {
|
||||
return regions.contains(name);
|
||||
}
|
||||
regions.add("__global__");
|
||||
}
|
||||
|
||||
public Location getAppliedLocation() {
|
||||
return applied;
|
||||
}
|
||||
public boolean isInRegion(String name) {
|
||||
return regions.contains(name);
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
@Deprecated
|
||||
public Location getAppliedLocation() {
|
||||
return applied;
|
||||
}
|
||||
|
||||
public Stream<String> getRegionStream() {
|
||||
return regions.stream();
|
||||
}
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return applied;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Stream<String> getRegionStream() {
|
||||
return regions.stream();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class DistanceCondition extends Condition{
|
||||
public class DistanceCondition extends Condition {
|
||||
private final Location location;
|
||||
private final double distance;
|
||||
|
||||
@ -17,18 +17,14 @@ public class DistanceCondition extends Condition{
|
||||
Validate.isTrue(config.contains("y"));
|
||||
Validate.isTrue(config.contains("z"));
|
||||
Validate.isTrue(config.contains("distance"));
|
||||
Validate.isTrue(Bukkit.getWorld(config.getString("world"))!=null,"This world doesn't exist");
|
||||
location=new Location(Bukkit.getWorld(config.getString("world")),config.getDouble("x"),
|
||||
config.getDouble("y"),config.getDouble("z"));
|
||||
distance=config.getDouble("distance");
|
||||
Validate.isTrue(Bukkit.getWorld(config.getString("world")) != null, "This world doesn't exist");
|
||||
location = new Location(Bukkit.getWorld(config.getString("world")), config.getDouble("x"),
|
||||
config.getDouble("y"), config.getDouble("z"));
|
||||
distance = config.getDouble("distance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance entity) {
|
||||
Entity entity1=entity.getEntity();
|
||||
return entity1.getWorld().equals(location.getWorld())&&location.distance(entity1.getLocation())<distance;
|
||||
public boolean isMet(ConditionInstance instance) {
|
||||
return instance.getLocation().getWorld().equals(location.getWorld()) && location.distance(instance.getLocation()) < distance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,17 +21,13 @@ public class TimeCondition extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance entity) {
|
||||
if (entity.getEntity() instanceof Player player) {
|
||||
long time = player.getWorld().getTime();
|
||||
long time = entity.getLocation().getWorld().getTime();
|
||||
|
||||
if (min < max) {
|
||||
return time > min && time < max;
|
||||
} else {
|
||||
// Allows for wrapping times, such as min=20000 max=6000
|
||||
return time > min || time < max;
|
||||
}
|
||||
if (min < max) {
|
||||
return time > min && time < max;
|
||||
} else {
|
||||
// Allows for wrapping times, such as min=20000 max=6000
|
||||
return time > min || time < max;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,13 @@ public class WeatherCondition extends Condition {
|
||||
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance entity) {
|
||||
if (entity.getEntity() instanceof Player player) {
|
||||
boolean isClear = player.getWorld().isClearWeather();
|
||||
boolean hasStorm = player.getWorld().hasStorm();
|
||||
boolean isClear = entity.getLocation().getWorld().isClearWeather();
|
||||
boolean hasStorm = entity.getLocation().getWorld().hasStorm();
|
||||
|
||||
if (condition.equalsIgnoreCase("clear")) {
|
||||
return isClear;
|
||||
} else if (condition.equalsIgnoreCase("stormy")) {
|
||||
return hasStorm;
|
||||
}
|
||||
if (condition.equalsIgnoreCase("clear")) {
|
||||
return isClear;
|
||||
} else if (condition.equalsIgnoreCase("stormy")) {
|
||||
return hasStorm;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -17,6 +17,6 @@ public class WorldCondition extends Condition {
|
||||
|
||||
@Override
|
||||
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.bukkit.configuration.ConfigurationSection;
|
||||
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.logging.Level;
|
||||
@ -36,8 +39,8 @@ public class FishingManager extends SpecificProfessionManager {
|
||||
MMOCore.plugin.statManager.registerProfession("CRITICAL_FISHING_FAILURE_CHANCE", getLinkedProfession());
|
||||
}
|
||||
|
||||
public FishingDropTable calculateDropTable(Entity entity) {
|
||||
ConditionInstance conditionEntity = new ConditionInstance(entity);
|
||||
public FishingDropTable calculateDropTable(@NotNull Player player, @NotNull FishHook hook) {
|
||||
ConditionInstance conditionEntity = new ConditionInstance(player, hook.getLocation());
|
||||
|
||||
for (FishingDropTable table : tables)
|
||||
if (table.areConditionsMet(conditionEntity))
|
||||
|
@ -45,7 +45,7 @@ public class FishingListener implements Listener {
|
||||
* Checks for drop tables. If no drop table, just plain vanilla
|
||||
* 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)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user