Skip to content

Commit

Permalink
More review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Feb 28, 2020
1 parent 53344b7 commit 1d5e511
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 33 deletions.
Binary file modified worldedit-bukkit/src/main/resources/worldedit-adapters.jar
Binary file not shown.
Expand Up @@ -138,9 +138,12 @@ public void timeout(Actor actor, LocalSession session,
)
@CommandPermissions("worldedit.fast")
public void fast(Actor actor, LocalSession session,
@Arg(desc = "The side effect", def = "") SideEffect sideEffect,
@Arg(desc = "The new side effect state", def = "") SideEffect.State newState,
@Switch(name = 'h', desc = "Show the info box") boolean showInfoBox) {
@Arg(desc = "The side effect", def = "")
SideEffect sideEffect,
@Arg(desc = "The new side effect state", def = "")
SideEffect.State newState,
@Switch(name = 'h', desc = "Show the info box")
boolean showInfoBox) {
if (sideEffect != null) {
SideEffect.State currentState = session.getSideEffectSet().getState(sideEffect);
if (newState != null && newState == currentState) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.world.World;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void setSideEffectSet(SideEffectSet sideEffectSet) {

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (sideEffectSet.doesRequireCleanup()) {
if (sideEffectSet.getState(SideEffect.LIGHTING) == SideEffect.State.DELAYED) {
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
}
if (postEditSimulation) {
Expand Down
Expand Up @@ -22,22 +22,20 @@
import java.util.Locale;

public enum SideEffect {
LIGHTING(State.ON, true),
NEIGHBORS(State.ON, false),
CONNECTIONS(State.ON, false),
ENTITY_AI(State.OFF, false),
PLUGIN_EVENTS(State.OFF, false);
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;
private final boolean requiresCleanup;

SideEffect(State defaultValue, boolean requiresCleanup) {
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;
this.requiresCleanup = requiresCleanup;
}

public String getDisplayName() {
Expand All @@ -52,15 +50,6 @@ public State getDefaultValue() {
return this.defaultValue;
}

/**
* Whether the world requires cleanup when this is disabled.
*
* @return if the world needs a cleanup
*/
public boolean requiresCleanup() {
return this.requiresCleanup;
}

public enum State {
OFF,
ON,
Expand Down
Expand Up @@ -29,13 +29,12 @@
import java.util.stream.Collectors;

public class SideEffectSet {
private static final SideEffectSet DEFAULT = new SideEffectSet();
private static final SideEffectSet NONE = new 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 boolean requiresCleanup = false;
private boolean appliesAny;

private SideEffectSet() {
Expand All @@ -45,7 +44,6 @@ private SideEffectSet() {
public SideEffectSet(Map<SideEffect, SideEffect.State> sideEffects) {
this.sideEffects = Maps.immutableEnumMap(sideEffects);

requiresCleanup = sideEffects.keySet().stream().anyMatch(SideEffect::requiresCleanup);
appliesAny = sideEffects.values().stream().anyMatch(state -> state != SideEffect.State.OFF);
}

Expand All @@ -59,10 +57,6 @@ public boolean doesApplyAny() {
return this.appliesAny;
}

public boolean doesRequireCleanup() {
return this.requiresCleanup;
}

public SideEffect.State getState(SideEffect effect) {
return sideEffects.getOrDefault(effect, effect.getDefaultValue());
}
Expand Down
Expand Up @@ -248,7 +248,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B
}

if (successful) {
if (sideEffectSet.shouldApply(SideEffect.LIGHTING)) {
if (sideEffectSet.getState(SideEffect.LIGHTING) == SideEffect.State.ON) {
world.getChunkManager().getLightingProvider().checkBlock(pos);
}
markAndNotifyBlock(world, pos, chunk, old, newState, sideEffectSet);
Expand All @@ -263,7 +263,7 @@ public boolean applySideEffects(BlockVector3 position, BlockState previousType,
net.minecraft.block.BlockState oldData = FabricAdapter.adapt(previousType);
net.minecraft.block.BlockState newData = getWorld().getBlockState(pos);

if (sideEffectSet.shouldApply(SideEffect.LIGHTING)) {
if (sideEffectSet.getState(SideEffect.LIGHTING) == SideEffect.State.ON) {
getWorld().getChunkManager().getLightingProvider().checkBlock(pos);
}
markAndNotifyBlock(getWorld(), pos, null, oldData, newData, sideEffectSet); // Update
Expand Down
Expand Up @@ -248,7 +248,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B
}

if (successful) {
if (sideEffectSet.shouldApply(SideEffect.LIGHTING)) {
if (sideEffectSet.getState(SideEffect.LIGHTING) == SideEffect.State.ON) {
world.getChunkProvider().getLightManager().checkBlock(pos);
}
markAndNotifyBlock(world, pos, chunk, old, newState, sideEffectSet);
Expand All @@ -263,7 +263,7 @@ public boolean applySideEffects(BlockVector3 position, BlockState previousType,
net.minecraft.block.BlockState oldData = ForgeAdapter.adapt(previousType);
net.minecraft.block.BlockState newData = getWorld().getBlockState(pos);

if (sideEffectSet.shouldApply(SideEffect.LIGHTING)) {
if (sideEffectSet.getState(SideEffect.LIGHTING) == SideEffect.State.ON) {
getWorld().getChunkProvider().getLightManager().checkBlock(pos);
}
markAndNotifyBlock(getWorld(), pos, null, oldData, newData, sideEffectSet); // Update
Expand Down

0 comments on commit 1d5e511

Please sign in to comment.