mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-20 09:11:26 +01:00
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:
commit
441cea0208
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user