mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 04:26:42 +00:00
Add basic preloading (#1221)
This commit is contained in:
@ -28,6 +28,8 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
||||
import com.sk89q.worldedit.command.util.annotation.Preload;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
@ -162,6 +164,8 @@ public class BiomeCommands {
|
||||
descFooter = "By default, uses all the blocks in your selection"
|
||||
)
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
@CommandPermissions("worldedit.biome.set")
|
||||
public void setBiome(
|
||||
Player player, LocalSession session, EditSession editSession,
|
||||
@ -184,9 +188,7 @@ public class BiomeCommands {
|
||||
if (mask != null) {
|
||||
replace = new RegionMaskingFilter(editSession, mask, replace);
|
||||
}
|
||||
//FAWE start > add extent to RegionVisitor to allow chunk preloading
|
||||
RegionVisitor visitor = new RegionVisitor(region, replace, editSession);
|
||||
//FAWE end
|
||||
RegionVisitor visitor = new RegionVisitor(region, replace);
|
||||
Operations.completeLegacy(visitor);
|
||||
|
||||
player.print(Caption.of(
|
||||
|
@ -45,6 +45,7 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
||||
import com.sk89q.worldedit.command.util.annotation.Preload;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
@ -112,6 +113,7 @@ public class ClipboardCommands {
|
||||
desc = "Copy the selection to the clipboard"
|
||||
)
|
||||
@CommandPermissions("worldedit.clipboard.copy")
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void copy(
|
||||
Actor actor, LocalSession session, EditSession editSession,
|
||||
@ -242,6 +244,7 @@ public class ClipboardCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.clipboard.cut")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void cut(
|
||||
Actor actor, LocalSession session, EditSession editSession,
|
||||
|
@ -33,6 +33,7 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
||||
import com.sk89q.worldedit.command.util.annotation.Preload;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
@ -435,6 +436,7 @@ public class GenerationCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.generation.shape.biome")
|
||||
@Logging(ALL)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int generateBiome(
|
||||
Actor actor, LocalSession session, EditSession editSession,
|
||||
@ -511,6 +513,7 @@ public class GenerationCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.generation.caves")
|
||||
@Logging(PLACEMENT)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void caves(
|
||||
Actor actor, LocalSession session, EditSession editSession, @Selection Region region,
|
||||
@ -548,6 +551,7 @@ public class GenerationCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.generation.ore")
|
||||
@Logging(PLACEMENT)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void ores(
|
||||
Actor actor,
|
||||
@ -619,6 +623,7 @@ public class GenerationCommands {
|
||||
@Command(name = "/ore", desc = "Generates ores")
|
||||
@CommandPermissions("worldedit.generation.ore")
|
||||
@Logging(PLACEMENT)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void ore(
|
||||
Actor actor,
|
||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
||||
import com.sk89q.worldedit.command.util.annotation.Preload;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.GroundFunction;
|
||||
@ -105,6 +106,7 @@ public class RegionCommands {
|
||||
@CommandPermissions("worldedit.region.set")
|
||||
@Logging(REGION)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
public int set(
|
||||
Actor actor, EditSession editSession,
|
||||
@Selection Region region,
|
||||
@ -125,6 +127,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.set")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
public void air(Actor actor, EditSession editSession, @Selection Region region) throws WorldEditException {
|
||||
set(actor, editSession, region, BlockTypes.AIR);
|
||||
}
|
||||
@ -305,6 +308,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.replace")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int replace(
|
||||
Actor actor, EditSession editSession, @Selection Region region,
|
||||
@ -351,6 +355,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.overlay")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void lay(
|
||||
Player player,
|
||||
@ -429,6 +434,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.faces")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int faces(
|
||||
Actor actor, EditSession editSession, @Selection Region region,
|
||||
@ -447,6 +453,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.smooth")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int smooth(
|
||||
Actor actor, EditSession editSession, @Selection Region region,
|
||||
@ -522,6 +529,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.move")
|
||||
@Logging(ORIENTATION_REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int move(
|
||||
Actor actor, World world, EditSession editSession, LocalSession session,
|
||||
@ -586,6 +594,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.fall")
|
||||
@Logging(ORIENTATION_REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public void fall(
|
||||
Player player, EditSession editSession, LocalSession session,
|
||||
@ -604,6 +613,7 @@ public class RegionCommands {
|
||||
desc = "Repeat the contents of the selection"
|
||||
)
|
||||
@CommandPermissions("worldedit.region.stack")
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Logging(ORIENTATION_REGION)
|
||||
public int stack(
|
||||
Actor actor, World world, EditSession editSession, LocalSession session,
|
||||
@ -713,6 +723,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.deform")
|
||||
@Logging(ALL)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int deform(
|
||||
Actor actor, LocalSession session, EditSession editSession,
|
||||
@ -788,6 +799,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.hollow")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int hollow(
|
||||
Actor actor, EditSession editSession,
|
||||
@ -823,6 +835,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.forest")
|
||||
@Logging(REGION)
|
||||
@Preload(Preload.PreloadCheck.PRELOAD)
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int forest(
|
||||
Actor actor, EditSession editSession, @Selection Region region,
|
||||
@ -853,7 +866,9 @@ public class RegionCommands {
|
||||
density = density / 100;
|
||||
FloraGenerator generator = new FloraGenerator(editSession);
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
|
||||
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
||||
//FAWE start - provide extent for preloading
|
||||
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground, editSession);
|
||||
//FAWE end
|
||||
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
||||
Operations.completeLegacy(visitor);
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class FloodFillTool implements BlockTool {
|
||||
//FAWE start - Respect masks
|
||||
Mask mask = initialType.toMask(editSession);
|
||||
BlockReplace function = new BlockReplace(editSession, pattern);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range, editSession);
|
||||
visitor.visit(origin);
|
||||
Operations.completeLegacy(visitor);
|
||||
//FAWE end
|
||||
|
@ -86,7 +86,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
final int radius = (int) range;
|
||||
final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
|
||||
editSession.setMask(null);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
|
||||
//TODO: Fix below
|
||||
//visitor.visit(pos);
|
||||
//Operations.completeBlindly(visitor);
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.sk89q.worldedit.command.util.annotation;
|
||||
|
||||
import com.fastasyncworldedit.core.Fawe;
|
||||
import com.fastasyncworldedit.core.queue.implementation.preloader.Preloader;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.enginehub.piston.inject.InjectAnnotation;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates how the affected blocks should be hinted at in the log.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({
|
||||
ElementType.PARAMETER,
|
||||
ElementType.METHOD
|
||||
})
|
||||
@InjectAnnotation
|
||||
public @interface Preload {
|
||||
|
||||
PreloadCheck value() default PreloadCheck.NEVER;
|
||||
|
||||
enum PreloadCheck {
|
||||
PRELOAD {
|
||||
@Override
|
||||
public void preload(Actor actor, InjectedValueAccess context) {
|
||||
World world = context.injectedValue(Key.of(EditSession.class)).get().getWorld();
|
||||
Preloader preloader = Fawe.imp().getPreloader(true);
|
||||
preloader.update(actor, world);
|
||||
}
|
||||
},
|
||||
|
||||
NEVER {};
|
||||
|
||||
public void preload(Actor actor, InjectedValueAccess context) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.sk89q.worldedit.command.util.annotation;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.gen.CommandCallListener;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Logs called commands to a logger.
|
||||
*/
|
||||
public class PreloadHandler implements CommandCallListener {
|
||||
|
||||
@Override
|
||||
public void beforeCall(Method method, CommandParameters parameters) {
|
||||
Preload preloadAnnotation = method.getAnnotation(Preload.class);
|
||||
if (preloadAnnotation == null) {
|
||||
return;
|
||||
}
|
||||
Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
|
||||
Optional<EditSession> editSessionOpt = parameters.injectedValue(Key.of(EditSession.class));
|
||||
|
||||
if (actorOpt.isEmpty() || editSessionOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Actor actor = actorOpt.get();
|
||||
// Don't attempt to preload if effectively disabled
|
||||
if (Settings.IMP.QUEUE.PRELOAD_CHUNK_COUNT <= 1) {
|
||||
return;
|
||||
}
|
||||
preloadAnnotation.value().preload(actor, parameters);
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
* @see com.sk89q.worldedit.command.util.annotation.ConfirmHandler
|
||||
* @see com.sk89q.worldedit.command.util.annotation.Link
|
||||
* @see com.sk89q.worldedit.command.util.annotation.PatternList
|
||||
* @see com.sk89q.worldedit.command.util.annotation.Preload
|
||||
* @see com.sk89q.worldedit.command.util.annotation.PreloadHandler
|
||||
* @see com.sk89q.worldedit.command.util.annotation.Step
|
||||
* @see com.sk89q.worldedit.command.util.annotation.Time
|
||||
*/
|
||||
|
Reference in New Issue
Block a user