forked from PaperMC/Folia
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab7a479
commit a017762
Showing
1 changed file
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: killerprojecte <[email protected]> | ||
Date: Sun, 2 Jul 2023 19:57:26 +0800 | ||
Subject: [PATCH] Fix some thing | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java | ||
index 5835a1ba3e2927c6b5d143506b440ac5a43aaaa4..eaf859c26b083ee4af9894f136d5f41f75868e5d 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java | ||
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java | ||
@@ -75,7 +75,7 @@ public abstract class Projectile extends Entity implements TraceableEntity { | ||
|
||
@Nullable | ||
public Entity getOwnerRaw() { // Folia - region threading | ||
- io.papermc.paper.util.TickThread.ensureTickThread(this, "Cannot update owner state asynchronously"); // Folia - region threading | ||
+ //io.papermc.paper.util.TickThread.ensureTickThread(this, "Cannot update owner state asynchronously"); // Folia - region threading // DirtyFolia - Removed check | ||
if (this.cachedOwner != null && !this.cachedOwner.isRemoved()) { | ||
this.refreshProjectileSource(false); // Paper | ||
return this.cachedOwner; | ||
diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java | ||
index 2b862066388cfede202a0c709f93ae89e2d17b30..bb28fb2f613d24db0c5ad9d97b9c9c8008a7c587 100644 | ||
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java | ||
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java | ||
@@ -258,7 +258,7 @@ public class MapItemSavedData extends SavedData { | ||
} | ||
|
||
public synchronized void tickCarriedBy(Player player, ItemStack stack) { // Folia - make map data thread-safe | ||
- io.papermc.paper.util.TickThread.ensureTickThread(player, "Ticking map player in incorrect region"); // Folia - region threading | ||
+ //io.papermc.paper.util.TickThread.ensureTickThread(player, "Ticking map player in incorrect region"); // Folia - region threading // DirtyFolia - Removed check | ||
if (!this.carriedByPlayers.containsKey(player)) { | ||
MapItemSavedData.HoldingPlayer worldmap_worldmaphumantracker = new MapItemSavedData.HoldingPlayer(player); | ||
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
index f182510ed01828215c59685ef77c9327059bd4a0..cad65858e2e9e09da93d9eee462d5360a1cdfa0c 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
@@ -1272,7 +1272,7 @@ public final class CraftServer implements Server { | ||
Preconditions.checkState(this.console.getAllLevels().iterator().hasNext(), "Cannot create additional worlds on STARTUP"); | ||
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot create a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes. | ||
Preconditions.checkArgument(creator != null, "WorldCreator cannot be null"); | ||
- io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("World create can be done only on global tick thread"); | ||
+ //io.papermc.paper.threadedregions.RegionizedServer.ensureGlobalTickThread("World create can be done only on global tick thread"); // DirtyFolia - Removed check | ||
|
||
String name = creator.name(); | ||
ChunkGenerator generator = creator.generator(); | ||
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java | ||
index 13af3853a7a470b5a5084363369720f5afb7c1d7..1b24396d007ef845c85e320a26b46b0925c505bf 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java | ||
@@ -3,11 +3,8 @@ package org.bukkit.craftbukkit.scheduler; | ||
import co.aikar.timings.MinecraftTimings; // Paper | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
-import java.util.ArrayList; | ||
-import java.util.Comparator; | ||
-import java.util.Iterator; | ||
-import java.util.List; | ||
-import java.util.PriorityQueue; | ||
+ | ||
+import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
@@ -17,6 +14,7 @@ import java.util.logging.Level; | ||
import com.destroystokyo.paper.ServerSchedulerReportingWrapper; | ||
import com.destroystokyo.paper.event.server.ServerExceptionEvent; | ||
import com.destroystokyo.paper.exception.ServerSchedulerException; | ||
+import dev.rgbmc.folia.FakePlugin; | ||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask; | ||
import org.apache.commons.lang.Validate; | ||
import org.bukkit.Bukkit; | ||
@@ -113,6 +111,8 @@ public class CraftScheduler implements BukkitScheduler { | ||
*/ // Paper end | ||
private static final int RECENT_TICKS; | ||
|
||
+ private static final Map<Integer, ScheduledTask> taskMap = new HashMap<>(); | ||
+ | ||
static { | ||
RECENT_TICKS = 30; | ||
} | ||
@@ -274,7 +274,10 @@ public class CraftScheduler implements BukkitScheduler { | ||
} | ||
// Paper start | ||
if (!this.isAsyncScheduler) { | ||
- this.asyncScheduler.cancelTask(taskId); | ||
+ //this.asyncScheduler.cancelTask(taskId); // DirtyFolia - Fix bug | ||
+ if (taskMap.containsKey(taskId)) { | ||
+ taskMap.get(taskId).cancel(); | ||
+ } | ||
} | ||
// Paper end | ||
CraftTask task = this.runners.get(taskId); | ||
@@ -312,6 +315,7 @@ public class CraftScheduler implements BukkitScheduler { | ||
} | ||
if (taskPending.getTaskId() == taskId) { | ||
taskPending.cancel0(); | ||
+ taskMap.remove(taskPending.getTaskId()); | ||
} | ||
} | ||
} | ||
@@ -321,7 +325,7 @@ public class CraftScheduler implements BukkitScheduler { | ||
Preconditions.checkArgument(plugin != null, "Cannot cancel tasks of null plugin"); | ||
// Paper start | ||
if (!this.isAsyncScheduler) { | ||
- this.asyncScheduler.cancelTasks(plugin); | ||
+ Bukkit.getAsyncScheduler().cancelTasks(plugin); | ||
} | ||
// Paper end | ||
final CraftTask task = new CraftTask( | ||
@@ -357,6 +361,7 @@ public class CraftScheduler implements BukkitScheduler { | ||
for (CraftTask runner : this.runners.values()) { | ||
if (runner.getOwner().equals(plugin)) { | ||
runner.cancel0(); | ||
+ taskMap.remove(runner.getTaskId()); | ||
} | ||
} | ||
} | ||
@@ -534,33 +539,39 @@ public class CraftScheduler implements BukkitScheduler { | ||
protected CraftTask handle(final CraftTask task, final long delay) { // Paper | ||
//if (true) throw new UnsupportedOperationException(); // Folia - region threading // DirtyFolia - Removed check | ||
// Paper start | ||
+ Plugin owner = task.getOwner(); | ||
+ if (owner == null) { | ||
+ owner = new FakePlugin(); | ||
+ } | ||
if (!this.isAsyncScheduler && !task.isSync()) { | ||
long mdelay = (long) (delay / 20.0 * 1000.0); | ||
ScheduledTask scheduledTask; | ||
if (mdelay <= 0) { | ||
- scheduledTask = Bukkit.getAsyncScheduler().runNow(task.getOwner(), stask -> { | ||
+ scheduledTask = Bukkit.getAsyncScheduler().runNow(owner, stask -> { | ||
task.run(); | ||
}); | ||
} else { | ||
- scheduledTask = Bukkit.getAsyncScheduler().runDelayed(task.getOwner(), stask -> { | ||
+ scheduledTask = Bukkit.getAsyncScheduler().runDelayed(owner, stask -> { | ||
task.run(); | ||
}, mdelay, TimeUnit.MILLISECONDS); | ||
} | ||
task.setScheduledTask(scheduledTask); | ||
+ taskMap.put(task.getTaskId(), scheduledTask); | ||
return task; | ||
} | ||
// Paper end | ||
ScheduledTask scheduledTask; | ||
if (delay <= 0) { | ||
- scheduledTask = Bukkit.getGlobalRegionScheduler().run(task.getOwner(), stask -> { | ||
+ scheduledTask = Bukkit.getGlobalRegionScheduler().run(owner, stask -> { | ||
task.run(); | ||
}); | ||
} else { | ||
- scheduledTask = Bukkit.getGlobalRegionScheduler().runDelayed(task.getOwner(), stask -> { | ||
+ scheduledTask = Bukkit.getGlobalRegionScheduler().runDelayed(owner, stask -> { | ||
task.run(); | ||
}, delay); | ||
} | ||
task.setScheduledTask(scheduledTask); | ||
+ taskMap.put(task.getTaskId(), scheduledTask); | ||
return task; | ||
} | ||
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java | ||
index 393061574058772fbf8689770f5bb18d8ae04bd1..dca2d08a1046bbca9684ad14e25c3cc2c5c7e25d 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java | ||
@@ -159,6 +159,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot | ||
* @return false if it is a craft future task that has already begun execution, true otherwise | ||
*/ | ||
boolean cancel0() { | ||
+ cancel(); | ||
this.setPeriod(CraftTask.CANCEL); | ||
return true; | ||
} |