generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
5 changed files
with
173 additions
and
7 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
54 changes: 54 additions & 0 deletions
54
src/main/java/io/github/aws404/easypainter/command/EasyPainterCommand.java
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,54 @@ | ||
package io.github.aws404.easypainter.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; | ||
import io.github.aws404.easypainter.custom.MotiveCacheState; | ||
import net.minecraft.command.CommandException; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import net.minecraft.server.command.SetBlockCommand; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.world.PersistentStateManager; | ||
|
||
public class EasyPainterCommand { | ||
|
||
private static final SimpleCommandExceptionType NOT_PREPARED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("command.easy_painter.clearcache.not_prepared")); | ||
|
||
private static boolean prepared = false; | ||
|
||
public static void register(CommandDispatcher<ServerCommandSource> source) { | ||
source.register(CommandManager.literal("easy_painter") | ||
.requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(3)) | ||
.then(CommandManager.literal("clearcache") | ||
.executes(context -> { | ||
EasyPainterCommand.checkPrepared(); | ||
|
||
context.getSource().getMinecraftServer().save(false, true, true); | ||
context.getSource().getMinecraftServer().getPlayerManager().saveAllPlayerData(); | ||
context.getSource().getMinecraftServer().stop(false); | ||
|
||
PersistentStateManager manager = context.getSource().getMinecraftServer().getOverworld().getPersistentStateManager(); | ||
MotiveCacheState cache = MotiveCacheState.getOrCreate(manager); | ||
|
||
for (Identifier key : cache.getKeys()) { | ||
cache.removeEntry(manager, key); | ||
} | ||
|
||
manager.save(); | ||
|
||
return 1; | ||
}) | ||
) | ||
); | ||
} | ||
|
||
private static void checkPrepared() throws CommandSyntaxException { | ||
if (!prepared) { | ||
prepared = true; | ||
throw NOT_PREPARED_EXCEPTION.create(); | ||
} | ||
} | ||
} |
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
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
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