mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Add Fabric 1.19.4 server-side mod support (#348)
This commit is contained in:
1 parent
1bdf21dd7d
commit
29e0ed6ef4
181 files changed
+5566
-67
No files matched your search
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.FabricHuskHomes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface FabricTaskRunner extends TaskRunner {
|
||||
|
||||
ConcurrentHashMap<Integer, CompletableFuture<?>> tasks = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
default int runAsync(@NotNull Runnable runnable) {
|
||||
tasks.put(tasks.size(), CompletableFuture.runAsync(runnable, getPlugin().getMinecraftServer()));
|
||||
return tasks.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
default <T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier) {
|
||||
return CompletableFuture.supplyAsync(supplier, getPlugin().getMinecraftServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
default void runSync(@NotNull Runnable runnable) {
|
||||
getPlugin().getMinecraftServer().executeSync(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
default int runAsyncRepeating(@NotNull Runnable runnable, long delay) {
|
||||
tasks.put(tasks.size(), CompletableFuture.runAsync(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(delay * 50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
runnable.run();
|
||||
}
|
||||
}, getPlugin().getMinecraftServer()));
|
||||
return tasks.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
default void runLater(@NotNull Runnable runnable, long delay) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Thread.sleep(delay * 50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
runnable.run();
|
||||
}, getPlugin().getMinecraftServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
default void cancelTask(int taskId) {
|
||||
tasks.get(taskId).cancel(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void cancelAllTasks() {
|
||||
tasks.forEach((taskId, future) -> future.cancel(true));
|
||||
tasks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
FabricHuskHomes getPlugin();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user