mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Add option to change lighting behaviour in queues
This commit is contained in:
parent
f0e9a8c5fe
commit
1552a8e74b
@ -63,7 +63,8 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||||
|
|
||||||
private final SideEffectSet sideEffectSet;
|
private final SideEffectSet noSideEffectSet;
|
||||||
|
private final SideEffectSet lightingSideEffectSet;
|
||||||
private org.bukkit.World bukkitWorld;
|
private org.bukkit.World bukkitWorld;
|
||||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||||
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||||
@ -71,7 +72,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
|
|
||||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
||||||
super(world);
|
super(world);
|
||||||
sideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||||
|
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public BlockState getBlock(int x, int y, int z) {
|
@Override public BlockState getBlock(int x, int y, int z) {
|
||||||
@ -177,7 +179,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
||||||
try {
|
try {
|
||||||
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
|
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
|
||||||
getWorld().setBlock(blockVector3, block, sideEffectSet);
|
getWorld().setBlock(blockVector3, block, noSideEffectSet);
|
||||||
} catch (WorldEditException ignored) {
|
} catch (WorldEditException ignored) {
|
||||||
StateWrapper sw = new StateWrapper(tag);
|
StateWrapper sw = new StateWrapper(tag);
|
||||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
|
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
|
||||||
@ -205,7 +207,23 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
|||||||
*/
|
*/
|
||||||
private void setWorldBlock(int x, int y, int z, @Nonnull BaseBlock block, @Nonnull BlockVector2 blockVector2) {
|
private void setWorldBlock(int x, int y, int z, @Nonnull BaseBlock block, @Nonnull BlockVector2 blockVector2) {
|
||||||
try {
|
try {
|
||||||
getWorld().setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
BlockVector3 loc = BlockVector3.at(x, y, z);
|
||||||
|
boolean lighting = false;
|
||||||
|
switch (getLightingMode()) {
|
||||||
|
case NONE:
|
||||||
|
break;
|
||||||
|
case PLACEMENT:
|
||||||
|
lighting = block.getBlockType().getMaterial().getLightValue() > 0;
|
||||||
|
break;
|
||||||
|
case REPLACEMENT:
|
||||||
|
lighting = block.getBlockType().getMaterial().getLightValue() > 0
|
||||||
|
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Can only be "all"
|
||||||
|
lighting = true;
|
||||||
|
}
|
||||||
|
getWorld().setBlock(loc, block, lighting ? lightingSideEffectSet : noSideEffectSet);
|
||||||
} catch (WorldEditException ignored) {
|
} catch (WorldEditException ignored) {
|
||||||
// Fallback to not so nice method
|
// Fallback to not so nice method
|
||||||
BlockData blockData = BukkitAdapter.adapt(block);
|
BlockData blockData = BukkitAdapter.adapt(block);
|
||||||
|
@ -543,6 +543,12 @@ public class Settings extends Config {
|
|||||||
@Comment({"Time to wait in ms before beginning to notify player or console of progress.",
|
@Comment({"Time to wait in ms before beginning to notify player or console of progress.",
|
||||||
"Prevent needless notification of progress for short queues."})
|
"Prevent needless notification of progress for short queues."})
|
||||||
public static int NOTIFY_WAIT = 5000;
|
public static int NOTIFY_WAIT = 5000;
|
||||||
|
@Comment({"How lighitng should be handled by the queue. Modes:",
|
||||||
|
" - 0 - Do not do any lighting (fastest)",
|
||||||
|
" - 1 - Only execute lighting where blocks with light values are placed",
|
||||||
|
" - 2 - Only execute lighting where blocks with light values are placed or removed/replaced",
|
||||||
|
" - 3 - Always execute lighting (slowest)"})
|
||||||
|
public static int LIGHTING_MODE = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Comment("Settings related to tab completion")
|
@Comment("Settings related to tab completion")
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.queue;
|
package com.plotsquared.core.queue;
|
||||||
|
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||||
import com.plotsquared.core.util.PatternUtil;
|
import com.plotsquared.core.util.PatternUtil;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
@ -55,6 +56,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
|||||||
private final World world;
|
private final World world;
|
||||||
private final ConcurrentHashMap<BlockVector2, LocalChunk> blockChunks = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<BlockVector2, LocalChunk> blockChunks = new ConcurrentHashMap<>();
|
||||||
private final List<BlockVector2> readRegion = new ArrayList<>();
|
private final List<BlockVector2> readRegion = new ArrayList<>();
|
||||||
|
private final List<ProgressSubscriber> progressSubscribers = new ArrayList<>();
|
||||||
private long modified;
|
private long modified;
|
||||||
private LocalChunk lastWrappedChunk;
|
private LocalChunk lastWrappedChunk;
|
||||||
private int lastX = Integer.MIN_VALUE;
|
private int lastX = Integer.MIN_VALUE;
|
||||||
@ -68,7 +70,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
|||||||
private Consumer<BlockVector2> consumer = null;
|
private Consumer<BlockVector2> consumer = null;
|
||||||
private boolean unloadAfter = true;
|
private boolean unloadAfter = true;
|
||||||
private Runnable whenDone;
|
private Runnable whenDone;
|
||||||
private List<ProgressSubscriber> progressSubscribers = new ArrayList<>();
|
@Nullable private LightingMode lightingMode = LightingMode.valueOf(Settings.QUEUE.LIGHTING_MODE);
|
||||||
|
|
||||||
public BasicQueueCoordinator(@Nonnull World world) {
|
public BasicQueueCoordinator(@Nonnull World world) {
|
||||||
super(world);
|
super(world);
|
||||||
@ -265,6 +267,17 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
|||||||
this.progressSubscribers.add(progressSubscriber);
|
this.progressSubscribers.add(progressSubscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @Nonnull public final LightingMode getLightingMode() {
|
||||||
|
if (lightingMode == null) {
|
||||||
|
return LightingMode.valueOf(Settings.QUEUE.LIGHTING_MODE);
|
||||||
|
}
|
||||||
|
return this.lightingMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public final void setLightingMode(@Nullable LightingMode mode) {
|
||||||
|
this.lightingMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public Runnable getCompleteTask() {
|
@Override public Runnable getCompleteTask() {
|
||||||
return this.whenDone;
|
return this.whenDone;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.queue;
|
package com.plotsquared.core.queue;
|
||||||
|
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
@ -191,7 +192,7 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable @Override public Consumer<BlockVector2> getChunkConsumer() {
|
@Override @Nullable public Consumer<BlockVector2> getChunkConsumer() {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
return parent.getChunkConsumer();
|
return parent.getChunkConsumer();
|
||||||
}
|
}
|
||||||
@ -210,6 +211,19 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @Nonnull public LightingMode getLightingMode() {
|
||||||
|
if (parent != null) {
|
||||||
|
return parent.getLightingMode();
|
||||||
|
}
|
||||||
|
return LightingMode.valueOf(Settings.QUEUE.LIGHTING_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void setLightingMode(@Nullable LightingMode mode) {
|
||||||
|
if (parent != null) {
|
||||||
|
parent.setLightingMode(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override @Nonnull public List<BlockVector2> getReadChunks() {
|
@Override @Nonnull public List<BlockVector2> getReadChunks() {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
return parent.getReadChunks();
|
return parent.getReadChunks();
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) ${year} IntellectualSites
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (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 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.plotsquared.core.queue;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum LightingMode {
|
||||||
|
|
||||||
|
NONE(0), PLACEMENT(1), REPLACEMENT(2), ALL(3);
|
||||||
|
|
||||||
|
private static final Map<Integer, LightingMode> map = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (LightingMode mode : LightingMode.values()) {
|
||||||
|
map.put(mode.mode, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final int mode;
|
||||||
|
|
||||||
|
LightingMode(int mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LightingMode valueOf(int mode) {
|
||||||
|
return map.get(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMode() {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
@ -359,6 +359,18 @@ public abstract class QueueCoordinator {
|
|||||||
*/
|
*/
|
||||||
public abstract void addProgressSubscriber(@Nonnull ProgressSubscriber progressSubscriber);
|
public abstract void addProgressSubscriber(@Nonnull ProgressSubscriber progressSubscriber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link LightingMode} to be used when setting blocks
|
||||||
|
*/
|
||||||
|
@Nonnull public abstract LightingMode getLightingMode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link LightingMode} to be used when setting blocks
|
||||||
|
*
|
||||||
|
* @param mode lighting mode. Null to use default.
|
||||||
|
*/
|
||||||
|
public abstract void setLightingMode(@Nullable LightingMode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill a cuboid between two positions with a BlockState
|
* Fill a cuboid between two positions with a BlockState
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user