mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Additional work towards 1.16 compatibility
- Very basic implementation of the SideEffects system. Will definitely need fine tuning for it to be functional, but is not considered a priority in my opinion. - Minor changes to the World interface and World implementations related to the SideEffects system. Shouldn't be the cause of any new bugs but be on the lookout. - Included debug in BukkitImplLoader.java to assist contributors in understanding what needs to be implemented for the adapter to load properly. Still very WIP but we're a few steps closer. So far, this is coming along better than I anticipated. Hopefully we can keep the momentum.
This commit is contained in:
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum SideEffect {
|
||||
LIGHTING(State.ON),
|
||||
NEIGHBORS(State.ON),
|
||||
CONNECTIONS(State.ON),
|
||||
ENTITY_AI(State.OFF),
|
||||
PLUGIN_EVENTS(State.OFF);
|
||||
|
||||
private final String displayName;
|
||||
private final String description;
|
||||
private final State defaultValue;
|
||||
|
||||
SideEffect(State defaultValue) {
|
||||
this.displayName = "worldedit.sideeffect." + this.name().toLowerCase(Locale.US);
|
||||
this.description = "worldedit.sideeffect." + this.name().toLowerCase(Locale.US) + ".description";
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public State getDefaultValue() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
OFF,
|
||||
ON,
|
||||
DELAYED;
|
||||
|
||||
private final String displayName;
|
||||
|
||||
State() {
|
||||
this.displayName = "worldedit.sideeffect.state." + this.name().toLowerCase(Locale.US);
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SideEffectSet {
|
||||
private static final SideEffectSet DEFAULT = new SideEffectSet(
|
||||
Arrays.stream(SideEffect.values()).collect(Collectors.toMap(Function.identity(), SideEffect::getDefaultValue))
|
||||
);
|
||||
private static final SideEffectSet NONE = new SideEffectSet();
|
||||
|
||||
private final Map<SideEffect, SideEffect.State> sideEffects;
|
||||
private final Set<SideEffect> appliedSideEffects;
|
||||
private final boolean appliesAny;
|
||||
|
||||
private SideEffectSet() {
|
||||
this(ImmutableMap.of());
|
||||
}
|
||||
|
||||
public SideEffectSet(Map<SideEffect, SideEffect.State> sideEffects) {
|
||||
this.sideEffects = Maps.immutableEnumMap(sideEffects);
|
||||
|
||||
appliedSideEffects = sideEffects.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() != SideEffect.State.OFF)
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toSet());
|
||||
appliesAny = !appliedSideEffects.isEmpty();
|
||||
}
|
||||
|
||||
public SideEffectSet with(SideEffect sideEffect, SideEffect.State state) {
|
||||
Map<SideEffect, SideEffect.State> entries = this.sideEffects.isEmpty() ? Maps.newEnumMap(SideEffect.class) : new EnumMap<>(this.sideEffects);
|
||||
entries.put(sideEffect, state);
|
||||
return new SideEffectSet(entries);
|
||||
}
|
||||
|
||||
public boolean doesApplyAny() {
|
||||
return this.appliesAny;
|
||||
}
|
||||
|
||||
public SideEffect.State getState(SideEffect effect) {
|
||||
return sideEffects.getOrDefault(effect, effect.getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this side effect is not off.
|
||||
*
|
||||
* This returns whether it is either delayed or on.
|
||||
*
|
||||
* @param effect The side effect
|
||||
* @return Whether it should apply
|
||||
*/
|
||||
public boolean shouldApply(SideEffect effect) {
|
||||
return getState(effect) != SideEffect.State.OFF;
|
||||
}
|
||||
|
||||
public Set<SideEffect> getSideEffectsToApply() {
|
||||
return this.appliedSideEffects;
|
||||
}
|
||||
|
||||
public static SideEffectSet defaults() {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
public static SideEffectSet none() {
|
||||
return NONE;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.formatting.component;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SideEffectBox extends PaginationBox {
|
||||
|
||||
private static List<SideEffect> sideEffects;
|
||||
|
||||
private SideEffectSet sideEffectSet;
|
||||
|
||||
private static List<SideEffect> getSideEffects() {
|
||||
if (sideEffects == null) {
|
||||
sideEffects = WorldEdit.getInstance().getPlatformManager().getSupportedSideEffects()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(Enum::name))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return sideEffects;
|
||||
}
|
||||
|
||||
public SideEffectBox(SideEffectSet sideEffectSet) {
|
||||
super("Side Effects");
|
||||
|
||||
this.sideEffectSet = sideEffectSet;
|
||||
}
|
||||
|
||||
private static final SideEffect.State[] SHOWN_VALUES = {SideEffect.State.OFF, SideEffect.State.ON};
|
||||
|
||||
@Override
|
||||
public Component getComponent(int number) {
|
||||
SideEffect effect = getSideEffects().get(number);
|
||||
SideEffect.State state = this.sideEffectSet.getState(effect);
|
||||
|
||||
TextComponent.Builder builder = TextComponent.builder();
|
||||
builder = builder.append(TranslatableComponent.of(effect.getDisplayName(), TextColor.YELLOW)
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of(effect.getDescription()))));
|
||||
for (SideEffect.State uiState : SHOWN_VALUES) {
|
||||
builder = builder.append(TextComponent.space());
|
||||
builder = builder.append(TranslatableComponent.of(uiState.getDisplayName(), uiState == state ? TextColor.WHITE : TextColor.GRAY)
|
||||
.clickEvent(ClickEvent.runCommand("//fast -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US)))
|
||||
.hoverEvent(HoverEvent.showText(uiState == state
|
||||
? TranslatableComponent.of("worldedit.sideeffect.box.current")
|
||||
: TranslatableComponent.of("worldedit.sideeffect.box.change-to", TranslatableComponent.of(uiState.getDisplayName()))
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComponentsSize() {
|
||||
return getSideEffects().size();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user