Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 02:50:05 +01:00
Cherry pick upstream commits to fix SideEffectSet (#1737)
* Fix SideEffectSet.none() being the default set (#1620) * Fix SideEffectSet.none() being the default set * Remove the unnecessary private empty constructor for SideEffectSet * Back to ImmutableMap.of * Speed up Fast Reorder Mode and make it default (#1653) * Speed up Fast Reorder Mode and make it default * Make non-exposed side effects internal * Docs on isExposed Co-authored-by: Matthew Miller <mnmiller1@me.com>
Dieser Commit ist enthalten in:
Ursprung
d7543884a5
Commit
b237ddf076
@ -59,7 +59,9 @@ public class SideEffectConverter implements ArgumentConverter<SideEffect> {
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String input, InjectedValueAccess context) {
|
||||
return limitByPrefix(getSideEffects().stream().map(sideEffect -> sideEffect.name().toLowerCase(Locale.US)), input);
|
||||
return limitByPrefix(getSideEffects().stream()
|
||||
.filter(SideEffect::isExposed)
|
||||
.map(sideEffect -> sideEffect.name().toLowerCase(Locale.US)), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,10 +32,13 @@ import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -50,6 +53,11 @@ public class SideEffectExtent extends AbstractDelegateExtent {
|
||||
private SideEffectSet sideEffectSet = SideEffectSet.defaults();
|
||||
private boolean postEditSimulation;
|
||||
|
||||
private static final SideEffectSet INTERNAL_NONE = new SideEffectSet(
|
||||
Arrays.stream(SideEffect.values())
|
||||
.collect(Collectors.toMap(Function.identity(), state -> SideEffect.State.OFF))
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
@ -86,7 +94,7 @@ public class SideEffectExtent extends AbstractDelegateExtent {
|
||||
positions.put(location, world.getBlock(location));
|
||||
}
|
||||
|
||||
return world.setBlock(location, block, postEditSimulation ? SideEffectSet.none() : sideEffectSet);
|
||||
return world.setBlock(location, block, postEditSimulation ? INTERNAL_NONE : sideEffectSet);
|
||||
}
|
||||
|
||||
public boolean commitRequired() {
|
||||
|
@ -174,7 +174,7 @@ public interface WorldNativeAccess<NC, NBS, NP> {
|
||||
if (isChunkTicking(chunk)) {
|
||||
if (sideEffectSet.shouldApply(SideEffect.ENTITY_AI)) {
|
||||
notifyBlockUpdate(chunk, pos, oldState, newState);
|
||||
} else {
|
||||
} else if (sideEffectSet.shouldApply(SideEffect.NETWORK)) {
|
||||
// If we want to skip entity AI, just mark the block for sending
|
||||
markBlockChanged(chunk, pos);
|
||||
}
|
||||
@ -190,7 +190,9 @@ public interface WorldNativeAccess<NC, NBS, NP> {
|
||||
}
|
||||
|
||||
// Seems used only for PoI updates
|
||||
onBlockStateChange(pos, oldState, newState);
|
||||
if (sideEffectSet.shouldApply(SideEffect.POI_UPDATE)) {
|
||||
onBlockStateChange(pos, oldState, blockState1);
|
||||
}
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
|
@ -22,21 +22,31 @@ package com.sk89q.worldedit.util;
|
||||
import java.util.Locale;
|
||||
|
||||
public enum SideEffect {
|
||||
LIGHTING(State.ON),
|
||||
NEIGHBORS(State.ON),
|
||||
UPDATE(State.ON),
|
||||
VALIDATION(State.OFF),
|
||||
ENTITY_AI(State.OFF),
|
||||
EVENTS(State.OFF);
|
||||
LIGHTING(State.ON, true),
|
||||
NEIGHBORS(State.ON, true),
|
||||
UPDATE(State.ON, true),
|
||||
VALIDATION(State.OFF, true),
|
||||
ENTITY_AI(State.OFF, true),
|
||||
EVENTS(State.OFF, true),
|
||||
/**
|
||||
* Internal use only.
|
||||
*/
|
||||
POI_UPDATE(State.ON, false),
|
||||
/**
|
||||
* Internal use only.
|
||||
*/
|
||||
NETWORK(State.ON, false);
|
||||
|
||||
private final String displayName;
|
||||
private final String description;
|
||||
private final State defaultValue;
|
||||
private final boolean exposed;
|
||||
|
||||
SideEffect(State defaultValue) {
|
||||
SideEffect(State defaultValue, boolean exposed) {
|
||||
this.displayName = "worldedit.sideeffect." + this.name().toLowerCase(Locale.US);
|
||||
this.description = "worldedit.sideeffect." + this.name().toLowerCase(Locale.US) + ".description";
|
||||
this.defaultValue = defaultValue;
|
||||
this.exposed = exposed;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
@ -51,6 +61,15 @@ public enum SideEffect {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this side effect is considered API.
|
||||
*
|
||||
* @return if the side effect is exposed via API
|
||||
*/
|
||||
public boolean isExposed() {
|
||||
return exposed;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
OFF,
|
||||
ON,
|
||||
|
@ -31,10 +31,12 @@ 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 DEFAULT = new SideEffectSet();
|
||||
private static final SideEffectSet NONE = new SideEffectSet(
|
||||
Arrays.stream(SideEffect.values())
|
||||
.filter(SideEffect::isExposed)
|
||||
.collect(Collectors.toMap(Function.identity(), state -> SideEffect.State.OFF))
|
||||
);
|
||||
private static final SideEffectSet NONE = new SideEffectSet();
|
||||
|
||||
private final Map<SideEffect, SideEffect.State> sideEffects;
|
||||
private final Set<SideEffect> appliedSideEffects;
|
||||
|
@ -23,8 +23,11 @@ import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||
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;
|
||||
@ -36,21 +39,23 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class SideEffectBox extends PaginationBox {
|
||||
|
||||
private static List<SideEffect> sideEffects;
|
||||
private static final LazyReference<List<SideEffect>> SIDE_EFFECTS = LazyReference.from(() ->
|
||||
WorldEdit.getInstance().getPlatformManager().getSupportedSideEffects()
|
||||
.stream()
|
||||
.filter(SideEffect::isExposed)
|
||||
.sorted(Comparator.comparing(effect ->
|
||||
WorldEditText.reduceToText(
|
||||
TranslatableComponent.of(effect.getDisplayName()),
|
||||
Locale.US
|
||||
)
|
||||
))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
private final SideEffectSet sideEffectSet;
|
||||
|
||||
private static List<SideEffect> getSideEffects() {
|
||||
//FAWE start
|
||||
if (sideEffects == null) {
|
||||
sideEffects = WorldEdit.getInstance().getPlatformManager().getSupportedSideEffects()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(Enum::name))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
return sideEffects;
|
||||
return SIDE_EFFECTS.getValue();
|
||||
}
|
||||
|
||||
public SideEffectBox(SideEffectSet sideEffectSet) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren