forked from Upstream/mmocore
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;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
|
||||||
public class BiomeCondition extends Condition {
|
public class BiomeCondition extends Condition {
|
||||||
private final List<String> names;
|
private final List<String> names;
|
||||||
|
|
||||||
public BiomeCondition(MMOLineConfig config) {
|
public BiomeCondition(MMOLineConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
config.validate("name");
|
config.validate("name");
|
||||||
names = Arrays.asList(config.getString("name").toUpperCase().split(","));
|
names = Arrays.asList(config.getString("name").toUpperCase().split(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,36 +6,44 @@ 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);
|
||||||
|
|
||||||
regions.add("__global__");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInRegion(String name) {
|
regions.add("__global__");
|
||||||
return regions.contains(name);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Location getAppliedLocation() {
|
public boolean isInRegion(String name) {
|
||||||
return applied;
|
return regions.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity getEntity() {
|
@Deprecated
|
||||||
return entity;
|
public Location getAppliedLocation() {
|
||||||
}
|
return applied;
|
||||||
|
}
|
||||||
|
|
||||||
public Stream<String> getRegionStream() {
|
@NotNull
|
||||||
return regions.stream();
|
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.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
public class DistanceCondition extends Condition{
|
public class DistanceCondition extends Condition {
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final double distance;
|
private final double distance;
|
||||||
|
|
||||||
@ -17,18 +17,14 @@ public class DistanceCondition extends Condition{
|
|||||||
Validate.isTrue(config.contains("y"));
|
Validate.isTrue(config.contains("y"));
|
||||||
Validate.isTrue(config.contains("z"));
|
Validate.isTrue(config.contains("z"));
|
||||||
Validate.isTrue(config.contains("distance"));
|
Validate.isTrue(config.contains("distance"));
|
||||||
Validate.isTrue(Bukkit.getWorld(config.getString("world"))!=null,"This world doesn't exist");
|
Validate.isTrue(Bukkit.getWorld(config.getString("world")) != null, "This world doesn't exist");
|
||||||
location=new Location(Bukkit.getWorld(config.getString("world")),config.getDouble("x"),
|
location = new Location(Bukkit.getWorld(config.getString("world")), config.getDouble("x"),
|
||||||
config.getDouble("y"),config.getDouble("z"));
|
config.getDouble("y"), config.getDouble("z"));
|
||||||
distance=config.getDouble("distance");
|
distance = config.getDouble("distance");
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,17 +21,13 @@ 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;
|
||||||
} else {
|
} else {
|
||||||
// Allows for wrapping times, such as min=20000 max=6000
|
// Allows for wrapping times, such as min=20000 max=6000
|
||||||
return time > min || time < max;
|
return time > min || time < max;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,13 @@ 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