Skip to content

Commit 9296490

Browse files
committed
PR feedback
1 parent b2ba274 commit 9296490

3 files changed

Lines changed: 20 additions & 26 deletions

File tree

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,19 @@ public SessionKey getSessionKey() {
133133
private volatile boolean active = true;
134134

135135
private void updateActive() {
136-
Block block = sender.getBlock();
137-
if (!block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
138-
active = false;
139-
return;
136+
try {
137+
Block block = sender.getBlock();
138+
if (!block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
139+
active = false;
140+
return;
141+
}
142+
Material type = block.getType();
143+
active = type == Material.COMMAND_BLOCK
144+
|| type == Material.CHAIN_COMMAND_BLOCK
145+
|| type == Material.REPEATING_COMMAND_BLOCK;
146+
} catch (Throwable t) {
147+
WorldEdit.logger.warn("Exception while updating command block sender active state", t);
140148
}
141-
Material type = block.getType();
142-
active = type == Material.COMMAND_BLOCK
143-
|| type == Material.CHAIN_COMMAND_BLOCK
144-
|| type == Material.REPEATING_COMMAND_BLOCK;
145149
}
146150

147151
@Override
@@ -158,13 +162,7 @@ public boolean isActive() {
158162
updateActive();
159163
} else {
160164
// We need to delegate to the right thread.
161-
Bukkit.getRegionScheduler().execute(plugin, sender.getBlock().getLocation(), () -> {
162-
try {
163-
updateActive();
164-
} catch (Throwable t) {
165-
WorldEdit.logger.warn("Exception while updating command block sender active state", t);
166-
}
167-
});
165+
Bukkit.getRegionScheduler().execute(plugin, sender.getBlock().getLocation(), this::updateActive);
168166
}
169167

170168
return active;
@@ -177,15 +175,10 @@ public boolean isActive() {
177175
// we should update it eventually
178176
// Suppress FutureReturnValueIgnored: We handle it in the block.
179177
@SuppressWarnings({"FutureReturnValueIgnored", "unused"})
180-
var unused = Bukkit.getScheduler().callSyncMethod(plugin,
181-
() -> {
182-
try {
183-
updateActive();
184-
} catch (Throwable t) {
185-
WorldEdit.logger.warn("Exception while updating command block sender active state", t);
186-
}
187-
return null;
188-
});
178+
var unused = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
179+
updateActive();
180+
return null;
181+
});
189182
}
190183
return active;
191184
}

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public void reload() {
123123
public int schedule(long delay, long period, Runnable task) {
124124
if (plugin.isFolia()) {
125125
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, scheduledTask -> task.run(), delay, period);
126-
// TODO Paper doesn't appear to have a concept of task IDs, so return -1 here for now.
126+
// TODO Paper doesn't appear to have a concept of task IDs, so return 1 here for now.
127127
// We may want to store these tasks and map them to our own IDs to cancel them later.
128-
return -1;
128+
return 1;
129129
} else {
130130
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
131131
}

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ BukkitImplAdapter getBukkitImplAdapter() {
534534
}
535535
} catch (Throwable t) {
536536
// Ignore, this likely means an outdated version.
537+
LOGGER.warn("Failed to check if server is running Folia", t);
537538
}
538539

539540
return false;

0 commit comments

Comments
 (0)