mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-28 03:09:07 +00:00
Start on feature patches
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package me.samsuik.sakura.player.visibility;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface VisibilitySettings {
|
||||
default boolean isEnabled(VisibilityType type) {
|
||||
return this.get(type) == VisibilityState.ON;
|
||||
}
|
||||
|
||||
default boolean isDisabled(VisibilityType type) {
|
||||
return this.get(type) == VisibilityState.OFF;
|
||||
}
|
||||
|
||||
default boolean isToggled(VisibilityType type) {
|
||||
return !type.isDefault(this.get(type));
|
||||
}
|
||||
|
||||
default VisibilityState toggle(VisibilityType type) {
|
||||
VisibilityState state = this.get(type);
|
||||
return this.set(type, toggleState(state));
|
||||
}
|
||||
|
||||
default VisibilityState cycle(VisibilityType type) {
|
||||
VisibilityState state = this.get(type);
|
||||
return this.set(type, type.cycle(state));
|
||||
}
|
||||
|
||||
default void toggleAll() {
|
||||
VisibilityState state = this.currentState();
|
||||
VisibilityState newState = toggleState(state);
|
||||
for (VisibilityType type : VisibilityTypes.types()) {
|
||||
this.set(type, newState);
|
||||
}
|
||||
}
|
||||
|
||||
VisibilityState get(VisibilityType type);
|
||||
|
||||
VisibilityState set(VisibilityType type, VisibilityState state);
|
||||
|
||||
VisibilityState currentState();
|
||||
|
||||
boolean playerModified();
|
||||
|
||||
static VisibilityState toggleState(VisibilityState state) {
|
||||
return state != VisibilityState.OFF ? VisibilityState.OFF : VisibilityState.ON;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.samsuik.sakura.player.visibility;
|
||||
|
||||
public enum VisibilityState {
|
||||
ON, MODIFIED, MINIMAL, OFF;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.samsuik.sakura.player.visibility;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public record VisibilityType(String key, ImmutableList<VisibilityState> states) {
|
||||
public VisibilityState getDefault() {
|
||||
return this.states.getFirst();
|
||||
}
|
||||
|
||||
public boolean isDefault(VisibilityState state) {
|
||||
return state == this.getDefault();
|
||||
}
|
||||
|
||||
public VisibilityState cycle(VisibilityState state) {
|
||||
int index = this.states.indexOf(state);
|
||||
int next = (index + 1) % this.states.size();
|
||||
return this.states.get(next);
|
||||
}
|
||||
|
||||
public static VisibilityType from(String key, boolean minimal) {
|
||||
return new VisibilityType(key, states(minimal));
|
||||
}
|
||||
|
||||
private static ImmutableList<VisibilityState> states(boolean minimal) {
|
||||
ImmutableList.Builder<VisibilityState> listBuilder = ImmutableList.builder();
|
||||
listBuilder.add(VisibilityState.ON);
|
||||
if (minimal) {
|
||||
listBuilder.add(VisibilityState.MINIMAL);
|
||||
}
|
||||
listBuilder.add(VisibilityState.OFF);
|
||||
return listBuilder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.samsuik.sakura.player.visibility;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@NullMarked
|
||||
public final class VisibilityTypes {
|
||||
private static final List<VisibilityType> TYPES = new ArrayList<>();
|
||||
|
||||
public static final VisibilityType TNT = register(create("tnt", true));
|
||||
public static final VisibilityType SAND = register(create("sand", true));
|
||||
public static final VisibilityType EXPLOSIONS = register(create("explosions", true));
|
||||
public static final VisibilityType SPAWNERS = register(create("spawners", false));
|
||||
public static final VisibilityType PISTONS = register(create("pistons", false));
|
||||
|
||||
public static ImmutableList<VisibilityType> types() {
|
||||
return ImmutableList.copyOf(TYPES);
|
||||
}
|
||||
|
||||
private static VisibilityType create(String key, boolean minimal) {
|
||||
return VisibilityType.from(key, minimal);
|
||||
}
|
||||
|
||||
private static VisibilityType register(VisibilityType type) {
|
||||
TYPES.add(type);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user