mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2026-01-04 15:41:35 +00:00
moon phase
This commit is contained in:
@@ -35,6 +35,7 @@ import net.momirealms.customfishing.compatibility.VaultHook;
|
||||
import net.momirealms.customfishing.compatibility.papi.ParseUtils;
|
||||
import net.momirealms.customfishing.util.ClassUtils;
|
||||
import net.momirealms.customfishing.util.ConfigUtils;
|
||||
import net.momirealms.customfishing.util.MoonPhase;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -182,6 +183,7 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
this.registerEndWithRequirement();
|
||||
this.registerEqualsRequirement();
|
||||
this.registerBiomeRequirement();
|
||||
this.registerMoonPhaseRequirement();
|
||||
this.registerDateRequirement();
|
||||
this.registerPluginLevelRequirement();
|
||||
this.registerPermissionRequirement();
|
||||
@@ -599,6 +601,29 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMoonPhaseRequirement() {
|
||||
registerRequirement("moon-phase", (args, actions, advanced) -> {
|
||||
HashSet<String> moonPhases = new HashSet<>(ConfigUtils.stringListArgs(args));
|
||||
return condition -> {
|
||||
long days = condition.getLocation().getWorld().getFullTime() / 24_000;
|
||||
if (moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH)))
|
||||
return true;
|
||||
if (advanced) triggerActions(actions, condition);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
registerRequirement("!moon-phase", (args, actions, advanced) -> {
|
||||
HashSet<String> moonPhases = new HashSet<>(ConfigUtils.stringListArgs(args));
|
||||
return condition -> {
|
||||
long days = condition.getLocation().getWorld().getFullTime() / 24_000;
|
||||
if (!moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH)))
|
||||
return true;
|
||||
if (advanced) triggerActions(actions, condition);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void registerWorldRequirement() {
|
||||
registerRequirement("world", (args, actions, advanced) -> {
|
||||
HashSet<String> worlds = new HashSet<>(ConfigUtils.stringListArgs(args));
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum MoonPhase {
|
||||
|
||||
FULL_MOON(0L),
|
||||
WANING_GIBBOUS(1L),
|
||||
LAST_QUARTER(2L),
|
||||
WANING_CRESCENT(3L),
|
||||
NEW_MOON(4L),
|
||||
WAXING_CRESCENT(5L),
|
||||
FIRST_QUARTER(6L),
|
||||
WAXING_GIBBOUS(7L);
|
||||
|
||||
private final long day;
|
||||
|
||||
MoonPhase(long day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
private static final Map<Long, MoonPhase> BY_DAY = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (MoonPhase phase : values()) {
|
||||
BY_DAY.put(phase.day, phase);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static MoonPhase getPhase(long day) {
|
||||
return BY_DAY.get(day % 8L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user