--- a/net/minecraft/server/commands/ScheduleCommand.java
+++ b/net/minecraft/server/commands/ScheduleCommand.java
@@ -3,6 +3,8 @@
 import com.mojang.brigadier.CommandDispatcher;
 import com.mojang.brigadier.arguments.IntegerArgumentType;
 import com.mojang.brigadier.arguments.StringArgumentType;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
 import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
@@ -12,7 +14,6 @@
 import java.util.Collection;
 import net.minecraft.commands.CommandFunction;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.SharedSuggestionProvider;
 import net.minecraft.commands.arguments.TimeArgument;
 import net.minecraft.commands.arguments.item.FunctionArgument;
@@ -24,64 +25,71 @@
 import net.minecraft.world.level.timers.TimerQueue;
 
 public class ScheduleCommand {
+
     private static final SimpleCommandExceptionType ERROR_SAME_TICK = new SimpleCommandExceptionType(Component.translatable("commands.schedule.same_tick"));
-    private static final DynamicCommandExceptionType ERROR_CANT_REMOVE = new DynamicCommandExceptionType((eventName) -> {
-        return Component.translatable("commands.schedule.cleared.failure", eventName);
+    private static final DynamicCommandExceptionType ERROR_CANT_REMOVE = new DynamicCommandExceptionType((object) -> {
+        return Component.translatable("commands.schedule.cleared.failure", object);
     });
-    private static final SuggestionProvider<CommandSourceStack> SUGGEST_SCHEDULE = (context, builder) -> {
-        return SharedSuggestionProvider.suggest(context.getSource().getServer().getWorldData().overworldData().getScheduledEvents().getEventsIds(), builder);
+    private static final SuggestionProvider<CommandSourceStack> SUGGEST_SCHEDULE = (commandcontext, suggestionsbuilder) -> {
+        return SharedSuggestionProvider.suggest((Iterable) ((net.minecraft.commands.CommandSourceStack) commandcontext.getSource()).getLevel().serverLevelData.getScheduledEvents().getEventsIds(), suggestionsbuilder); // Paper
     };
 
+    public ScheduleCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
-        dispatcher.register(Commands.literal("schedule").requires((source) -> {
-            return source.hasPermission(2);
-        }).then(Commands.literal("function").then(Commands.argument("function", FunctionArgument.functions()).suggests(FunctionCommand.SUGGEST_FUNCTION).then(Commands.argument("time", TimeArgument.time()).executes((context) -> {
-            return schedule(context.getSource(), FunctionArgument.getFunctionOrTag(context, "function"), IntegerArgumentType.getInteger(context, "time"), true);
-        }).then(Commands.literal("append").executes((context) -> {
-            return schedule(context.getSource(), FunctionArgument.getFunctionOrTag(context, "function"), IntegerArgumentType.getInteger(context, "time"), false);
-        })).then(Commands.literal("replace").executes((context) -> {
-            return schedule(context.getSource(), FunctionArgument.getFunctionOrTag(context, "function"), IntegerArgumentType.getInteger(context, "time"), true);
-        }))))).then(Commands.literal("clear").then(Commands.argument("function", StringArgumentType.greedyString()).suggests(SUGGEST_SCHEDULE).executes((context) -> {
-            return remove(context.getSource(), StringArgumentType.getString(context, "function"));
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("schedule").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(net.minecraft.commands.Commands.literal("function").then(net.minecraft.commands.Commands.argument("function", FunctionArgument.functions()).suggests(FunctionCommand.SUGGEST_FUNCTION).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("time", TimeArgument.time()).executes((commandcontext) -> {
+            return ScheduleCommand.schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), true);
+        })).then(net.minecraft.commands.Commands.literal("append").executes((commandcontext) -> {
+            return ScheduleCommand.schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), false);
+        }))).then(net.minecraft.commands.Commands.literal("replace").executes((commandcontext) -> {
+            return ScheduleCommand.schedule((CommandSourceStack) commandcontext.getSource(), FunctionArgument.getFunctionOrTag(commandcontext, "function"), IntegerArgumentType.getInteger(commandcontext, "time"), true);
+        })))))).then(net.minecraft.commands.Commands.literal("clear").then(net.minecraft.commands.Commands.argument("function", StringArgumentType.greedyString()).suggests(ScheduleCommand.SUGGEST_SCHEDULE).executes((commandcontext) -> {
+            return ScheduleCommand.remove((CommandSourceStack) commandcontext.getSource(), StringArgumentType.getString(commandcontext, "function"));
         }))));
     }
 
     private static int schedule(CommandSourceStack source, Pair<ResourceLocation, Either<CommandFunction, Collection<CommandFunction>>> function, int time, boolean replace) throws CommandSyntaxException {
         if (time == 0) {
-            throw ERROR_SAME_TICK.create();
+            throw ScheduleCommand.ERROR_SAME_TICK.create();
         } else {
-            long l = source.getLevel().getGameTime() + (long)time;
-            ResourceLocation resourceLocation = function.getFirst();
-            TimerQueue<MinecraftServer> timerQueue = source.getServer().getWorldData().overworldData().getScheduledEvents();
-            function.getSecond().ifLeft((function2) -> {
-                String string = resourceLocation.toString();
+            long j = source.getLevel().getGameTime() + (long) time;
+            ResourceLocation minecraftkey = (ResourceLocation) function.getFirst();
+            TimerQueue<MinecraftServer> customfunctioncallbacktimerqueue = source.getLevel().serverLevelData.overworldData().getScheduledEvents(); // CraftBukkit - SPIGOT-6667: Use world specific function timer
+
+            ((Either) function.getSecond()).ifLeft((customfunction) -> {
+                String s = minecraftkey.toString();
+
                 if (replace) {
-                    timerQueue.remove(string);
+                    customfunctioncallbacktimerqueue.remove(s);
                 }
 
-                timerQueue.schedule(string, l, new FunctionCallback(resourceLocation));
+                customfunctioncallbacktimerqueue.schedule(s, j, new FunctionCallback(minecraftkey));
                 source.sendSuccess(() -> {
-                    return Component.translatable("commands.schedule.created.function", resourceLocation, time, l);
+                    return Component.translatable("commands.schedule.created.function", minecraftkey, time, j);
                 }, true);
-            }).ifRight((functions) -> {
-                String string = "#" + resourceLocation;
+            }).ifRight((collection) -> {
+                String s = "#" + minecraftkey;
+
                 if (replace) {
-                    timerQueue.remove(string);
+                    customfunctioncallbacktimerqueue.remove(s);
                 }
 
-                timerQueue.schedule(string, l, new FunctionTagCallback(resourceLocation));
+                customfunctioncallbacktimerqueue.schedule(s, j, new FunctionTagCallback(minecraftkey));
                 source.sendSuccess(() -> {
-                    return Component.translatable("commands.schedule.created.tag", resourceLocation, time, l);
+                    return Component.translatable("commands.schedule.created.tag", minecraftkey, time, j);
                 }, true);
             });
-            return Math.floorMod(l, Integer.MAX_VALUE);
+            return Math.floorMod(j, Integer.MAX_VALUE);
         }
     }
 
     private static int remove(CommandSourceStack source, String eventName) throws CommandSyntaxException {
-        int i = source.getServer().getWorldData().overworldData().getScheduledEvents().remove(eventName);
+        int i = source.getLevel().serverLevelData.getScheduledEvents().remove(eventName); // Paper
+
         if (i == 0) {
-            throw ERROR_CANT_REMOVE.create(eventName);
+            throw ScheduleCommand.ERROR_CANT_REMOVE.create(eventName);
         } else {
             source.sendSuccess(() -> {
                 return Component.translatable("commands.schedule.cleared.success", i, eventName);
