Merge branch 'weather-time-conditions' into 'master'

feat(conditions): Add Weather and Time conditions

See merge request phoenix-dvpmt/mmocore!22
This commit is contained in:
Jules 2023-06-25 00:19:03 +00:00
commit 441cea0208
3 changed files with 77 additions and 0 deletions

View File

@ -119,6 +119,12 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("permission"))
return new PermissionCondition(config);
if (config.getKey().equals("weather"))
return new WeatherCondition(config);
if (config.getKey().equals("time"))
return new TimeCondition(config);
return null;
}

View File

@ -0,0 +1,37 @@
package net.Indyuce.mmocore.loot.chest.condition;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
public class TimeCondition extends Condition {
private final int min;
private final int max;
public TimeCondition(MMOLineConfig config) {
super(config);
Validate.isTrue(config.contains("min"));
Validate.isTrue(config.contains("max"));
min = config.getInt("min");
max = config.getInt("max");
}
@Override
public boolean isMet(ConditionInstance entity) {
if (entity.getEntity() instanceof Player player) {
long time = player.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;
}
}
return false;
}
}

View File

@ -0,0 +1,34 @@
package net.Indyuce.mmocore.loot.chest.condition;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
public class WeatherCondition extends Condition {
private final String condition;
public WeatherCondition(MMOLineConfig config) {
super(config);
Validate.isTrue(config.contains("condition"));
condition = config.getString("condition");
}
@Override
public boolean isMet(ConditionInstance entity) {
if (entity.getEntity() instanceof Player player) {
boolean isClear = player.getWorld().isClearWeather();
boolean hasStorm = player.getWorld().hasStorm();
if (condition.equalsIgnoreCase("clear")) {
return isClear;
} else if (condition.equalsIgnoreCase("stormy")) {
return hasStorm;
}
}
return false;
}
}