Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-03 01:50:07 +01:00
Merge pull request #517 from EngineHub/feature/watchdog-ticking
Tick the watchdog on world actions
Dieser Commit ist enthalten in:
Commit
d8d25fbff1
@ -28,6 +28,8 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extension.platform.Capability;
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
||||||
import com.sk89q.worldedit.extension.platform.Preference;
|
import com.sk89q.worldedit.extension.platform.Preference;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
|
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||||
import com.sk89q.worldedit.world.DataFixer;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import com.sk89q.worldedit.world.registry.Registries;
|
import com.sk89q.worldedit.world.registry.Registries;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -52,6 +54,14 @@ public class BukkitServerInterface implements MultiUserPlatform {
|
|||||||
public WorldEditPlugin plugin;
|
public WorldEditPlugin plugin;
|
||||||
private CommandRegistration dynamicCommands;
|
private CommandRegistration dynamicCommands;
|
||||||
private boolean hookingEvents;
|
private boolean hookingEvents;
|
||||||
|
private final LazyReference<Watchdog> watchdog = LazyReference.from(() -> {
|
||||||
|
if (plugin.getBukkitImplAdapter() != null) {
|
||||||
|
return plugin.getBukkitImplAdapter().supportsWatchdog()
|
||||||
|
? new BukkitWatchdog(plugin.getBukkitImplAdapter())
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
|
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -103,6 +113,11 @@ public class BukkitServerInterface implements MultiUserPlatform {
|
|||||||
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
|
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Watchdog getWatchdog() {
|
||||||
|
return watchdog.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<com.sk89q.worldedit.world.World> getWorlds() {
|
public List<com.sk89q.worldedit.world.World> getWorlds() {
|
||||||
List<World> worlds = server.getWorlds();
|
List<World> worlds = server.getWorlds();
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
|
|
||||||
|
class BukkitWatchdog implements Watchdog {
|
||||||
|
|
||||||
|
private final BukkitImplAdapter adapter;
|
||||||
|
|
||||||
|
BukkitWatchdog(BukkitImplAdapter adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
adapter.tickWatchdog();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -62,6 +62,19 @@ public interface BukkitImplAdapter {
|
|||||||
@Nullable
|
@Nullable
|
||||||
DataFixer getDataFixer();
|
DataFixer getDataFixer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@code true} if {@link #tickWatchdog()} is implemented
|
||||||
|
*/
|
||||||
|
default boolean supportsWatchdog() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tick the server watchdog, if possible.
|
||||||
|
*/
|
||||||
|
default void tickWatchdog() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block at the given location.
|
* Get the block at the given location.
|
||||||
*
|
*
|
||||||
|
Binäre Datei nicht angezeigt.
@ -22,6 +22,8 @@ package com.sk89q.worldedit;
|
|||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
import com.sk89q.worldedit.extent.ChangeSetExtent;
|
import com.sk89q.worldedit.extent.ChangeSetExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.extent.MaskingExtent;
|
import com.sk89q.worldedit.extent.MaskingExtent;
|
||||||
@ -38,6 +40,7 @@ import com.sk89q.worldedit.extent.world.BlockQuirkExtent;
|
|||||||
import com.sk89q.worldedit.extent.world.ChunkLoadingExtent;
|
import com.sk89q.worldedit.extent.world.ChunkLoadingExtent;
|
||||||
import com.sk89q.worldedit.extent.world.FastModeExtent;
|
import com.sk89q.worldedit.extent.world.FastModeExtent;
|
||||||
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
|
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
|
||||||
|
import com.sk89q.worldedit.extent.world.WatchdogTickingExtent;
|
||||||
import com.sk89q.worldedit.function.GroundFunction;
|
import com.sk89q.worldedit.function.GroundFunction;
|
||||||
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
||||||
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
||||||
@ -188,6 +191,7 @@ public class EditSession implements Extent, AutoCloseable {
|
|||||||
private final MultiStageReorder reorderExtent;
|
private final MultiStageReorder reorderExtent;
|
||||||
private final MaskingExtent maskingExtent;
|
private final MaskingExtent maskingExtent;
|
||||||
private final BlockChangeLimiter changeLimiter;
|
private final BlockChangeLimiter changeLimiter;
|
||||||
|
private final List<WatchdogTickingExtent> watchdogExtents = new ArrayList<>(2);
|
||||||
|
|
||||||
private final Extent bypassReorderHistory;
|
private final Extent bypassReorderHistory;
|
||||||
private final Extent bypassHistory;
|
private final Extent bypassHistory;
|
||||||
@ -214,10 +218,18 @@ public class EditSession implements Extent, AutoCloseable {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
|
Watchdog watchdog = WorldEdit.getInstance().getPlatformManager()
|
||||||
|
.queryCapability(Capability.GAME_HOOKS).getWatchdog();
|
||||||
Extent extent;
|
Extent extent;
|
||||||
|
|
||||||
// These extents are ALWAYS used
|
// These extents are ALWAYS used
|
||||||
extent = fastModeExtent = new FastModeExtent(world, false);
|
extent = fastModeExtent = new FastModeExtent(world, false);
|
||||||
|
if (watchdog != null) {
|
||||||
|
// Reset watchdog before world placement
|
||||||
|
WatchdogTickingExtent watchdogExtent = new WatchdogTickingExtent(extent, watchdog);
|
||||||
|
extent = watchdogExtent;
|
||||||
|
watchdogExtents.add(watchdogExtent);
|
||||||
|
}
|
||||||
extent = survivalExtent = new SurvivalModeExtent(extent, world);
|
extent = survivalExtent = new SurvivalModeExtent(extent, world);
|
||||||
extent = new BlockQuirkExtent(extent, world);
|
extent = new BlockQuirkExtent(extent, world);
|
||||||
extent = new ChunkLoadingExtent(extent, world);
|
extent = new ChunkLoadingExtent(extent, world);
|
||||||
@ -230,6 +242,13 @@ public class EditSession implements Extent, AutoCloseable {
|
|||||||
extent = reorderExtent = new MultiStageReorder(extent, false);
|
extent = reorderExtent = new MultiStageReorder(extent, false);
|
||||||
extent = chunkBatchingExtent = new ChunkBatchingExtent(extent);
|
extent = chunkBatchingExtent = new ChunkBatchingExtent(extent);
|
||||||
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
|
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
|
||||||
|
if (watchdog != null) {
|
||||||
|
// reset before buffering extents, since they may buffer all changes
|
||||||
|
// before the world-placement reset can happen, and still cause halts
|
||||||
|
WatchdogTickingExtent watchdogExtent = new WatchdogTickingExtent(extent, watchdog);
|
||||||
|
extent = watchdogExtent;
|
||||||
|
watchdogExtents.add(watchdogExtent);
|
||||||
|
}
|
||||||
this.bypassHistory = new DataValidatorExtent(extent, world);
|
this.bypassHistory = new DataValidatorExtent(extent, world);
|
||||||
|
|
||||||
// These extents can be skipped by calling smartSetBlock()
|
// These extents can be skipped by calling smartSetBlock()
|
||||||
@ -536,6 +555,24 @@ public class EditSession implements Extent, AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this session will tick the watchdog.
|
||||||
|
*
|
||||||
|
* @return {@code true} if any watchdog extent is enabled
|
||||||
|
*/
|
||||||
|
public boolean isTickingWatchdog() {
|
||||||
|
return watchdogExtents.stream().anyMatch(WatchdogTickingExtent::isEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set all watchdog extents to the given mode.
|
||||||
|
*/
|
||||||
|
public void setTickingWatchdog(boolean active) {
|
||||||
|
for (WatchdogTickingExtent extent : watchdogExtents) {
|
||||||
|
extent.setEnabled(active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of blocks changed, including repeated block changes.
|
* Get the number of blocks changed, including repeated block changes.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +102,7 @@ public class LocalSession {
|
|||||||
private transient EditSession.ReorderMode reorderMode = EditSession.ReorderMode.MULTI_STAGE;
|
private transient EditSession.ReorderMode reorderMode = EditSession.ReorderMode.MULTI_STAGE;
|
||||||
private transient List<Countable<BlockState>> lastDistribution;
|
private transient List<Countable<BlockState>> lastDistribution;
|
||||||
private transient World worldOverride;
|
private transient World worldOverride;
|
||||||
|
private transient boolean tickingWatchdog = false;
|
||||||
|
|
||||||
// Saved properties
|
// Saved properties
|
||||||
private String lastScript;
|
private String lastScript;
|
||||||
@ -238,12 +239,7 @@ public class LocalSession {
|
|||||||
EditSession editSession = history.get(historyPointer);
|
EditSession editSession = history.get(historyPointer);
|
||||||
try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
||||||
.getEditSession(editSession.getWorld(), -1, newBlockBag, actor)) {
|
.getEditSession(editSession.getWorld(), -1, newBlockBag, actor)) {
|
||||||
newEditSession.enableStandardMode();
|
prepareEditingExtents(editSession, actor);
|
||||||
newEditSession.setReorderMode(reorderMode);
|
|
||||||
newEditSession.setFastMode(fastMode);
|
|
||||||
if (newEditSession.getSurvivalExtent() != null) {
|
|
||||||
newEditSession.getSurvivalExtent().setStripNbt(!actor.hasPermission("worldedit.setnbt"));
|
|
||||||
}
|
|
||||||
editSession.undo(newEditSession);
|
editSession.undo(newEditSession);
|
||||||
}
|
}
|
||||||
return editSession;
|
return editSession;
|
||||||
@ -266,12 +262,7 @@ public class LocalSession {
|
|||||||
EditSession editSession = history.get(historyPointer);
|
EditSession editSession = history.get(historyPointer);
|
||||||
try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
try (EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
|
||||||
.getEditSession(editSession.getWorld(), -1, newBlockBag, actor)) {
|
.getEditSession(editSession.getWorld(), -1, newBlockBag, actor)) {
|
||||||
newEditSession.enableStandardMode();
|
prepareEditingExtents(editSession, actor);
|
||||||
newEditSession.setReorderMode(reorderMode);
|
|
||||||
newEditSession.setFastMode(fastMode);
|
|
||||||
if (newEditSession.getSurvivalExtent() != null) {
|
|
||||||
newEditSession.getSurvivalExtent().setStripNbt(!actor.hasPermission("worldedit.setnbt"));
|
|
||||||
}
|
|
||||||
editSession.redo(newEditSession);
|
editSession.redo(newEditSession);
|
||||||
}
|
}
|
||||||
++historyPointer;
|
++historyPointer;
|
||||||
@ -294,6 +285,14 @@ public class LocalSession {
|
|||||||
this.worldOverride = worldOverride;
|
this.worldOverride = worldOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTickingWatchdog() {
|
||||||
|
return tickingWatchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTickingWatchdog(boolean tickingWatchdog) {
|
||||||
|
this.tickingWatchdog = tickingWatchdog;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default region selector.
|
* Get the default region selector.
|
||||||
*
|
*
|
||||||
@ -945,14 +944,19 @@ public class LocalSession {
|
|||||||
}
|
}
|
||||||
Request.request().setEditSession(editSession);
|
Request.request().setEditSession(editSession);
|
||||||
|
|
||||||
|
editSession.setMask(mask);
|
||||||
|
prepareEditingExtents(editSession, actor);
|
||||||
|
|
||||||
|
return editSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareEditingExtents(EditSession editSession, Actor actor) {
|
||||||
editSession.setFastMode(fastMode);
|
editSession.setFastMode(fastMode);
|
||||||
editSession.setReorderMode(reorderMode);
|
editSession.setReorderMode(reorderMode);
|
||||||
editSession.setMask(mask);
|
|
||||||
if (editSession.getSurvivalExtent() != null) {
|
if (editSession.getSurvivalExtent() != null) {
|
||||||
editSession.getSurvivalExtent().setStripNbt(!actor.hasPermission("worldedit.setnbt"));
|
editSession.getSurvivalExtent().setStripNbt(!actor.hasPermission("worldedit.setnbt"));
|
||||||
}
|
}
|
||||||
|
editSession.setTickingWatchdog(tickingWatchdog);
|
||||||
return editSession;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,10 +26,12 @@ import com.sk89q.worldedit.WorldEdit;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||||
|
import com.sk89q.worldedit.command.util.HookMode;
|
||||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
import com.sk89q.worldedit.function.mask.Mask;
|
import com.sk89q.worldedit.function.mask.Mask;
|
||||||
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
|
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
@ -198,6 +200,29 @@ public class GeneralCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
name = "/watchdog",
|
||||||
|
desc = "Changes watchdog hook state.",
|
||||||
|
descFooter = "This is dependent on platform implementation. " +
|
||||||
|
"Not all platforms support watchdog hooks, or contain a watchdog."
|
||||||
|
)
|
||||||
|
@CommandPermissions("worldedit.watchdog")
|
||||||
|
public void watchdog(Actor actor, LocalSession session,
|
||||||
|
@Arg(desc = "The mode to set the watchdog hook to", def = "")
|
||||||
|
HookMode hookMode) {
|
||||||
|
if (WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWatchdog() == null) {
|
||||||
|
actor.printError("This platform has no watchdog hook.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean previousMode = session.isTickingWatchdog();
|
||||||
|
if (hookMode != null && (hookMode == HookMode.ACTIVE) == previousMode) {
|
||||||
|
actor.printError("Watchdog hook already " + (previousMode ? "active" : "inactive") + ".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session.setTickingWatchdog(!previousMode);
|
||||||
|
actor.print("Watchdog hook now " + (previousMode ? "inactive" : "active") + ".");
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "gmask",
|
name = "gmask",
|
||||||
aliases = {"/gmask"},
|
aliases = {"/gmask"},
|
||||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.command.argument;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.command.util.HookMode;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
import com.sk89q.worldedit.util.TreeGenerator;
|
||||||
import org.enginehub.piston.CommandManager;
|
import org.enginehub.piston.CommandManager;
|
||||||
import org.enginehub.piston.converter.ArgumentConverter;
|
import org.enginehub.piston.converter.ArgumentConverter;
|
||||||
@ -46,6 +47,8 @@ public final class EnumConverter {
|
|||||||
full(EditSession.ReorderMode.class,
|
full(EditSession.ReorderMode.class,
|
||||||
r -> ImmutableSet.of(r.getDisplayName()),
|
r -> ImmutableSet.of(r.getDisplayName()),
|
||||||
null));
|
null));
|
||||||
|
commandManager.registerConverter(Key.of(HookMode.class),
|
||||||
|
basic(HookMode.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <E extends Enum<E>> ArgumentConverter<E> basic(Class<E> enumClass) {
|
private static <E extends Enum<E>> ArgumentConverter<E> basic(Class<E> enumClass) {
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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.command.util;
|
||||||
|
|
||||||
|
public enum HookMode {
|
||||||
|
ACTIVE, INACTIVE
|
||||||
|
}
|
@ -83,6 +83,15 @@ public interface Platform {
|
|||||||
*/
|
*/
|
||||||
int schedule(long delay, long period, Runnable task);
|
int schedule(long delay, long period, Runnable task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the watchdog service.
|
||||||
|
*
|
||||||
|
* @return the watchdog service, or {@code null} if none
|
||||||
|
*/
|
||||||
|
default @Nullable Watchdog getWatchdog() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of available or loaded worlds.
|
* Get a list of available or loaded worlds.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* 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.extension.platform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface to a {@link Platform}'s watchdog service.
|
||||||
|
*/
|
||||||
|
public interface Watchdog {
|
||||||
|
|
||||||
|
void tick();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* 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.extent.world;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
|
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extent that ticks the watchdog before every world-affecting action.
|
||||||
|
*/
|
||||||
|
public class WatchdogTickingExtent extends AbstractDelegateExtent {
|
||||||
|
|
||||||
|
// Number of operations we run per tick to the watchdog
|
||||||
|
private static final int OPS_PER_TICK = 100;
|
||||||
|
|
||||||
|
private final Watchdog watchdog;
|
||||||
|
private boolean enabled;
|
||||||
|
private int ops;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param extent the extent
|
||||||
|
* @param watchdog the watchdog to reset
|
||||||
|
*/
|
||||||
|
public WatchdogTickingExtent(Extent extent, Watchdog watchdog) {
|
||||||
|
super(extent);
|
||||||
|
this.watchdog = watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onOperation() {
|
||||||
|
if (enabled) {
|
||||||
|
ops++;
|
||||||
|
if (ops == OPS_PER_TICK) {
|
||||||
|
watchdog.tick();
|
||||||
|
ops = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
|
||||||
|
onOperation();
|
||||||
|
return super.setBlock(location, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Entity createEntity(Location location, BaseEntity entity) {
|
||||||
|
onOperation();
|
||||||
|
return super.createEntity(location, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
||||||
|
onOperation();
|
||||||
|
return super.setBiome(position, biome);
|
||||||
|
}
|
||||||
|
}
|
@ -26,12 +26,15 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extension.platform.Capability;
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
|
||||||
import com.sk89q.worldedit.extension.platform.Preference;
|
import com.sk89q.worldedit.extension.platform.Preference;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
import com.sk89q.worldedit.world.DataFixer;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.registry.Registries;
|
import com.sk89q.worldedit.world.registry.Registries;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.PlayerManager;
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
|
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@ -55,12 +58,15 @@ class FabricPlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
private final FabricWorldEdit mod;
|
private final FabricWorldEdit mod;
|
||||||
private final MinecraftServer server;
|
private final MinecraftServer server;
|
||||||
private final FabricDataFixer dataFixer;
|
private final FabricDataFixer dataFixer;
|
||||||
|
private final @Nullable Watchdog watchdog;
|
||||||
private boolean hookingEvents = false;
|
private boolean hookingEvents = false;
|
||||||
|
|
||||||
FabricPlatform(FabricWorldEdit mod, MinecraftServer server) {
|
FabricPlatform(FabricWorldEdit mod, MinecraftServer server) {
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.dataFixer = new FabricDataFixer(getDataVersion());
|
this.dataFixer = new FabricDataFixer(getDataVersion());
|
||||||
|
this.watchdog = server instanceof MinecraftDedicatedServer
|
||||||
|
? (Watchdog) server : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHookingEvents() {
|
boolean isHookingEvents() {
|
||||||
@ -97,6 +103,12 @@ class FabricPlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Watchdog getWatchdog() {
|
||||||
|
return watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends World> getWorlds() {
|
public List<? extends World> getWorlds() {
|
||||||
Iterable<ServerWorld> worlds = server.getWorlds();
|
Iterable<ServerWorld> worlds = server.getWorlds();
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.fabric.mixin;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
|
import net.minecraft.server.ServerTask;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.NonBlockingThreadExecutor;
|
||||||
|
import net.minecraft.util.SystemUtil;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
@Mixin(MinecraftServer.class)
|
||||||
|
public abstract class MixinMinecraftServer extends NonBlockingThreadExecutor<ServerTask> implements Watchdog {
|
||||||
|
|
||||||
|
public MixinMinecraftServer(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private long timeReference;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
timeReference = SystemUtil.getMeasuringTimeMs();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,8 @@
|
|||||||
"package": "com.sk89q.worldedit.fabric.mixin",
|
"package": "com.sk89q.worldedit.fabric.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinServerPlayerEntity"
|
"MixinServerPlayerEntity",
|
||||||
|
"MixinMinecraftServer"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
],
|
],
|
||||||
|
@ -34,6 +34,8 @@ configure<UserDevExtension> {
|
|||||||
"version" to "20190913-$mappingsMinecraftVersion"
|
"version" to "20190913-$mappingsMinecraftVersion"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
val runConfig = Action<RunConfig> {
|
val runConfig = Action<RunConfig> {
|
||||||
properties(mapOf(
|
properties(mapOf(
|
||||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.world.registry.Registries;
|
|||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import net.minecraft.server.management.PlayerList;
|
import net.minecraft.server.management.PlayerList;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.SharedConstants;
|
import net.minecraft.util.SharedConstants;
|
||||||
@ -56,12 +57,15 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
private final ForgeWorldEdit mod;
|
private final ForgeWorldEdit mod;
|
||||||
private final MinecraftServer server;
|
private final MinecraftServer server;
|
||||||
private final ForgeDataFixer dataFixer;
|
private final ForgeDataFixer dataFixer;
|
||||||
|
private final @Nullable ForgeWatchdog watchdog;
|
||||||
private boolean hookingEvents = false;
|
private boolean hookingEvents = false;
|
||||||
|
|
||||||
ForgePlatform(ForgeWorldEdit mod) {
|
ForgePlatform(ForgeWorldEdit mod) {
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.server = ServerLifecycleHooks.getCurrentServer();
|
this.server = ServerLifecycleHooks.getCurrentServer();
|
||||||
this.dataFixer = new ForgeDataFixer(getDataVersion());
|
this.dataFixer = new ForgeDataFixer(getDataVersion());
|
||||||
|
this.watchdog = server instanceof DedicatedServer
|
||||||
|
? new ForgeWatchdog((DedicatedServer) server) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHookingEvents() {
|
boolean isHookingEvents() {
|
||||||
@ -98,6 +102,12 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ForgeWatchdog getWatchdog() {
|
||||||
|
return watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends World> getWorlds() {
|
public List<? extends World> getWorlds() {
|
||||||
Iterable<ServerWorld> worlds = server.getWorlds();
|
Iterable<ServerWorld> worlds = server.getWorlds();
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.forge;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.extension.platform.Watchdog;
|
||||||
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
|
import net.minecraft.util.Util;
|
||||||
|
|
||||||
|
class ForgeWatchdog implements Watchdog {
|
||||||
|
|
||||||
|
private final DedicatedServer server;
|
||||||
|
|
||||||
|
ForgeWatchdog(DedicatedServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
server.serverTime = Util.milliTime();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
public net.minecraft.server.MinecraftServer field_211151_aa # serverTime
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren