Removed network code relying on client side mod.
Some checks failed
publish / publish (push) Has been cancelled
Some checks failed
publish / publish (push) Has been cancelled
This commit is contained in:
parent
b103bcba03
commit
2d405228db
11 changed files with 74 additions and 173 deletions
|
@ -14,7 +14,7 @@ loader_version_range=[4,)
|
||||||
modid=extbackup
|
modid=extbackup
|
||||||
mod_name=ExtBackup
|
mod_name=ExtBackup
|
||||||
group=net.sweevo
|
group=net.sweevo
|
||||||
mod_version=2.0.6
|
mod_version=2.0.8
|
||||||
## Upload Properties
|
## Upload Properties
|
||||||
upload_versions=1.21, 1.21.1
|
upload_versions=1.21, 1.21.1
|
||||||
upload_release=release
|
upload_release=release
|
||||||
|
|
|
@ -2,26 +2,17 @@ package net.sweevo.jinks;
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.DefaultUncaughtExceptionHandler;
|
import net.minecraft.DefaultUncaughtExceptionHandler;
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.neoforged.fml.i18n.I18nManager;
|
|
||||||
import net.neoforged.neoforge.network.registration.NetworkRegistry;
|
|
||||||
import net.sweevo.jinks.config.CommonConfig;
|
import net.sweevo.jinks.config.CommonConfig;
|
||||||
import net.sweevo.jinks.config.ServerConfig;
|
|
||||||
import net.sweevo.jinks.network.Pause;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class BackupThread extends Thread {
|
public class BackupThread extends Thread {
|
||||||
|
|
||||||
|
@ -38,18 +29,14 @@ public class BackupThread extends Thread {
|
||||||
this.script = CommonConfig.getScript();
|
this.script = CommonConfig.getScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean tryCreateBackup(MinecraftServer server) {
|
public static void tryCreateBackup(MinecraftServer server) {
|
||||||
BackupData backupData = BackupData.get(server);
|
BackupData backupData = BackupData.get(server);
|
||||||
if (BackupThread.shouldRunBackup(server)) {
|
if (BackupThread.shouldRunBackup(server)) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
BackupThread thread = new BackupThread(server, false);
|
BackupThread thread = new BackupThread(server, false);
|
||||||
thread.start();
|
thread.start();
|
||||||
long currentTime = System.currentTimeMillis();
|
|
||||||
backupData.updateSaveTime(currentTime);
|
backupData.updateSaveTime(currentTime);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldRunBackup(MinecraftServer server) {
|
public static boolean shouldRunBackup(MinecraftServer server) {
|
||||||
|
@ -57,51 +44,33 @@ public class BackupThread extends Thread {
|
||||||
if (!CommonConfig.isEnabled() || backupData.isPaused()) {
|
if (!CommonConfig.isEnabled() || backupData.isPaused()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return System.currentTimeMillis() - CommonConfig.getTimer() > backupData.getLastSaved();
|
return System.currentTimeMillis() - CommonConfig.getTimer() > backupData.getLastSaved();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createBackup(MinecraftServer server, boolean quiet) {
|
public static void createBackup(MinecraftServer server, boolean quiet) {
|
||||||
|
BackupData backupData = BackupData.get(server);
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
BackupThread thread = new BackupThread(server, quiet);
|
BackupThread thread = new BackupThread(server, quiet);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
backupData.updateSaveTime(currentTime);
|
||||||
|
|
||||||
@SuppressWarnings("null")
|
|
||||||
public static MutableComponent component(@Nullable ServerPlayer player, String key, Object... parameters) {
|
|
||||||
if (player != null) {
|
|
||||||
//noinspection UnstableApiUsage
|
|
||||||
if (NetworkRegistry.hasChannel(player.connection.connection, null, Pause.ID)) {
|
|
||||||
return Component.translatable(key, parameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Component.literal(String.format(Optional.ofNullable(I18nManager.loadTranslations("en_us").get(key)).orElse(key), parameters));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
this.broadcast("ExtBackup started...", Style.EMPTY.withColor(ChatFormatting.BLUE));
|
if (!this.quiet) { ChatHelper.broadcast(this.server,"ExtBackup started...", Style.EMPTY.withColor(ChatFormatting.BLUE)); }
|
||||||
|
ExtBackup.LOGGER.info("Starting backup...");
|
||||||
this.makeWorldBackup();
|
this.makeWorldBackup();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
String time = Timer.getTimer(end - start);
|
String time = Timer.getTimer(end - start);
|
||||||
this.broadcast("ExtBackup completed in %s", Style.EMPTY.withColor(ChatFormatting.BLUE), time);
|
if (!this.quiet) { ChatHelper.broadcast(this.server,"ExtBackup completed in %s", Style.EMPTY.withColor(ChatFormatting.BLUE), time); }
|
||||||
|
ExtBackup.LOGGER.info("Backup done.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExtBackup.LOGGER.error("Error backing up", e);
|
ExtBackup.LOGGER.error("Error backing up", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void broadcast(String message, Style style, Object... parameters) {
|
|
||||||
if (CommonConfig.sendMessages() && !this.quiet) {
|
|
||||||
this.server.execute(() -> this.server.getPlayerList().getPlayers().forEach(player -> {
|
|
||||||
if (ServerConfig.messagesForEveryone() || player.hasPermissions(2)) {
|
|
||||||
player.sendSystemMessage(BackupThread.component(player, message, parameters).withStyle(style));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vanilla copy with modifications
|
// vanilla copy with modifications
|
||||||
@SuppressWarnings("CallToPrintStackTrace")
|
@SuppressWarnings("CallToPrintStackTrace")
|
||||||
private void makeWorldBackup() {
|
private void makeWorldBackup() {
|
||||||
|
|
39
src/main/java/net/sweevo/jinks/ChatHelper.java
Normal file
39
src/main/java/net/sweevo/jinks/ChatHelper.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package net.sweevo.jinks;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.network.chat.Style;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.sweevo.jinks.config.CommonConfig;
|
||||||
|
import net.sweevo.jinks.config.ServerConfig;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class ChatHelper {
|
||||||
|
|
||||||
|
@SuppressWarnings("null")
|
||||||
|
public static MutableComponent component(@Nullable ServerPlayer player, String key, Object... parameters) {
|
||||||
|
if (player != null) { return Component.translatable(key, parameters); }
|
||||||
|
return Component.literal(String.format(key, parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tell(@Nullable ServerPlayer player, String chatMessage, Style style, Object... parameters) {
|
||||||
|
MutableComponent message = ChatHelper.component(player, chatMessage, parameters);
|
||||||
|
if (player != null) {
|
||||||
|
player.sendSystemMessage(message.withStyle(style));
|
||||||
|
} else {
|
||||||
|
ExtBackup.LOGGER.info(String.valueOf(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcast(MinecraftServer server, String message, Style style, Object... parameters) {
|
||||||
|
if (CommonConfig.sendMessages()) {
|
||||||
|
server.execute(() -> server.getPlayerList().getPlayers().forEach(player -> {
|
||||||
|
if (ServerConfig.messagesForEveryone() || player.hasPermissions(2)) {
|
||||||
|
player.sendSystemMessage(ChatHelper.component(player, message, parameters).withStyle(style));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package net.sweevo.jinks;
|
package net.sweevo.jinks;
|
||||||
|
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
@ -9,14 +11,11 @@ import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerAboutToStartEvent;
|
import net.neoforged.neoforge.event.server.ServerAboutToStartEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
||||||
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import net.neoforged.neoforge.network.registration.NetworkRegistry;
|
|
||||||
import net.sweevo.jinks.commands.BackupCommand;
|
import net.sweevo.jinks.commands.BackupCommand;
|
||||||
import net.sweevo.jinks.commands.PauseCommand;
|
import net.sweevo.jinks.commands.PauseCommand;
|
||||||
import net.sweevo.jinks.commands.StatusCommand;
|
import net.sweevo.jinks.commands.StatusCommand;
|
||||||
import net.sweevo.jinks.config.CommonConfig;
|
import net.sweevo.jinks.config.CommonConfig;
|
||||||
import net.sweevo.jinks.config.ServerConfig;
|
import net.sweevo.jinks.config.ServerConfig;
|
||||||
import net.sweevo.jinks.network.Pause;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,8 +30,9 @@ public class EventListener {
|
||||||
event.getDispatcher().register(Commands.literal(ExtBackup.MODID)
|
event.getDispatcher().register(Commands.literal(ExtBackup.MODID)
|
||||||
.requires(stack -> ServerConfig.commandsCheatsDisabled() || stack.hasPermission(2))
|
.requires(stack -> ServerConfig.commandsCheatsDisabled() || stack.hasPermission(2))
|
||||||
.then(BackupCommand.register())
|
.then(BackupCommand.register())
|
||||||
.then(StatusCommand.register())
|
|
||||||
.then(PauseCommand.register()));
|
.then(PauseCommand.register()));
|
||||||
|
event.getDispatcher().register(Commands.literal(ExtBackup.MODID)
|
||||||
|
.then(StatusCommand.register()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
@ -47,7 +47,8 @@ public class EventListener {
|
||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
# Put your backup script here!
|
# Put your backup script here!
|
||||||
exit 0""");
|
exit 0
|
||||||
|
""");
|
||||||
script.setExecutable(true);
|
script.setExecutable(true);
|
||||||
ExtBackup.LOGGER.info("No backup script was found, a script has been created at {}, please modify it to your liking.", script.getAbsolutePath());
|
ExtBackup.LOGGER.info("No backup script was found, a script has been created at {}, please modify it to your liking.", script.getAbsolutePath());
|
||||||
} catch (IOException | SecurityException e) {
|
} catch (IOException | SecurityException e) {
|
||||||
|
@ -63,14 +64,9 @@ public class EventListener {
|
||||||
public void onServerTick(LevelTickEvent.Post event) {
|
public void onServerTick(LevelTickEvent.Post event) {
|
||||||
if (event.getLevel() instanceof ServerLevel level && !level.isClientSide
|
if (event.getLevel() instanceof ServerLevel level && !level.isClientSide
|
||||||
&& level.getGameTime() % 20 == 0 && level == level.getServer().overworld()) {
|
&& level.getGameTime() % 20 == 0 && level == level.getServer().overworld()) {
|
||||||
|
|
||||||
if (!level.getServer().getPlayerList().getPlayers().isEmpty() || this.doBackup || CommonConfig.doNoPlayerBackups()) {
|
if (!level.getServer().getPlayerList().getPlayers().isEmpty() || this.doBackup || CommonConfig.doNoPlayerBackups()) {
|
||||||
this.doBackup = false;
|
this.doBackup = false;
|
||||||
|
BackupThread.tryCreateBackup(level.getServer());
|
||||||
boolean done = BackupThread.tryCreateBackup(level.getServer());
|
|
||||||
if (done) {
|
|
||||||
ExtBackup.LOGGER.info("Backup done.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,9 +75,9 @@ public class EventListener {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerConnect(PlayerEvent.PlayerLoggedInEvent event) {
|
public void onPlayerConnect(PlayerEvent.PlayerLoggedInEvent event) {
|
||||||
ServerPlayer player = (ServerPlayer) event.getEntity();
|
ServerPlayer player = (ServerPlayer) event.getEntity();
|
||||||
//noinspection UnstableApiUsage
|
if (CommonConfig.isEnabled() && event.getEntity().getServer() != null && (ServerConfig.commandsCheatsDisabled() || player.hasPermissions(2))) {
|
||||||
if (CommonConfig.isEnabled() && event.getEntity().getServer() != null && NetworkRegistry.hasChannel(player.connection.connection, null, Pause.ID)) {
|
boolean isPaused = BackupData.get(event.getEntity().getServer()).isPaused();
|
||||||
PacketDistributor.sendToPlayer(player, new Pause(BackupData.get(event.getEntity().getServer()).isPaused()));
|
if (isPaused) { ChatHelper.tell(player, "ExtBackup paused!", Style.EMPTY.withColor(ChatFormatting.RED)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +95,7 @@ public class EventListener {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onServerShutdown(ServerStoppingEvent event) {
|
public void onServerShutdown(ServerStoppingEvent event) {
|
||||||
if (CommonConfig.doRunOnShutDown()) {
|
if (CommonConfig.doRunOnShutDown()) {
|
||||||
boolean done = BackupThread.tryCreateBackup(event.getServer());
|
BackupThread.createBackup(event.getServer(), true);
|
||||||
if (done) {
|
|
||||||
ExtBackup.LOGGER.info("Backup done.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package net.sweevo.jinks;
|
package net.sweevo.jinks;
|
||||||
|
|
||||||
import net.neoforged.api.distmarker.Dist;
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.config.ModConfig;
|
import net.neoforged.fml.config.ModConfig;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
|
||||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
|
||||||
import net.sweevo.jinks.client.ClientEventHandler;
|
|
||||||
import net.sweevo.jinks.config.CommonConfig;
|
import net.sweevo.jinks.config.CommonConfig;
|
||||||
import net.sweevo.jinks.config.ServerConfig;
|
import net.sweevo.jinks.config.ServerConfig;
|
||||||
import net.sweevo.jinks.network.Pause;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -22,24 +17,12 @@ public class ExtBackup {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(ExtBackup.class);
|
public static final Logger LOGGER = LoggerFactory.getLogger(ExtBackup.class);
|
||||||
public static final String MODID = "extbackup";
|
public static final String MODID = "extbackup";
|
||||||
|
|
||||||
public ExtBackup(IEventBus modEventBus, ModContainer modContainer, Dist dist) {
|
public ExtBackup(IEventBus modEventBus, ModContainer modContainer) {
|
||||||
modContainer.registerConfig(ModConfig.Type.COMMON, CommonConfig.CONFIG);
|
modContainer.registerConfig(ModConfig.Type.COMMON, CommonConfig.CONFIG);
|
||||||
modContainer.registerConfig(ModConfig.Type.SERVER, ServerConfig.CONFIG);
|
modContainer.registerConfig(ModConfig.Type.SERVER, ServerConfig.CONFIG);
|
||||||
NeoForge.EVENT_BUS.register(new EventListener());
|
NeoForge.EVENT_BUS.register(new EventListener());
|
||||||
modEventBus.addListener(this::setup);
|
modEventBus.addListener(this::setup);
|
||||||
modEventBus.addListener(this::onRegisterPayloadHandler);
|
|
||||||
|
|
||||||
if (dist.isClient()) {
|
|
||||||
NeoForge.EVENT_BUS.register(new ClientEventHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onRegisterPayloadHandler(RegisterPayloadHandlersEvent event) {
|
|
||||||
PayloadRegistrar registrar = event.registrar(ExtBackup.MODID)
|
|
||||||
.versioned("1.0")
|
|
||||||
.optional();
|
|
||||||
|
|
||||||
registrar.playToClient(Pause.TYPE, Pause.CODEC, Pause::handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup(FMLCommonSetupEvent event) {
|
private void setup(FMLCommonSetupEvent event) {
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package net.sweevo.jinks.client;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
|
||||||
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
|
|
||||||
|
|
||||||
public class ClientEventHandler {
|
|
||||||
|
|
||||||
private static final MutableComponent COMPONENT = Component.translatable("extbackup.backups_paused").withStyle(ChatFormatting.RED);
|
|
||||||
private static boolean isPaused = false;
|
|
||||||
|
|
||||||
public static boolean isPaused() {
|
|
||||||
return isPaused;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setPaused(boolean paused) {
|
|
||||||
isPaused = paused;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onRenderText(CustomizeGuiOverlayEvent.DebugText event) {
|
|
||||||
if (!isPaused) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
|
||||||
guiGraphics.fill(3, 3, 20, 20, 0);
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
guiGraphics.drawString(Minecraft.getInstance().font, COMPONENT, 3, 3, 0);
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,11 +3,13 @@ package net.sweevo.jinks.commands;
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.sweevo.jinks.BackupData;
|
import net.sweevo.jinks.BackupData;
|
||||||
import net.sweevo.jinks.network.Pause;
|
import net.sweevo.jinks.ChatHelper;
|
||||||
|
import net.sweevo.jinks.ExtBackup;
|
||||||
|
|
||||||
public class PauseCommand implements Command<CommandSourceStack> {
|
public class PauseCommand implements Command<CommandSourceStack> {
|
||||||
|
|
||||||
|
@ -30,7 +32,12 @@ public class PauseCommand implements Command<CommandSourceStack> {
|
||||||
public int run(CommandContext<CommandSourceStack> context) {
|
public int run(CommandContext<CommandSourceStack> context) {
|
||||||
BackupData data = BackupData.get(context.getSource().getServer());
|
BackupData data = BackupData.get(context.getSource().getServer());
|
||||||
data.setPaused(this.paused);
|
data.setPaused(this.paused);
|
||||||
PacketDistributor.sendToAllPlayers(new Pause(this.paused));
|
if (this.paused) {
|
||||||
|
ChatHelper.tell(context.getSource().getPlayer(), "ExtBackup paused!", Style.EMPTY.withColor(ChatFormatting.RED));
|
||||||
|
ExtBackup.LOGGER.warn("ExtBackup paused!");}
|
||||||
|
else {
|
||||||
|
ChatHelper.tell(context.getSource().getPlayer(), "ExtBackup unpaused!", Style.EMPTY.withColor(ChatFormatting.GREEN));
|
||||||
|
ExtBackup.LOGGER.info("ExtBackup unpaused!");}
|
||||||
return this.paused ? 1 : 0;
|
return this.paused ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,13 +6,10 @@ import com.mojang.brigadier.context.CommandContext;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.sweevo.jinks.BackupData;
|
import net.sweevo.jinks.BackupData;
|
||||||
import net.sweevo.jinks.BackupThread;
|
import net.sweevo.jinks.ChatHelper;
|
||||||
import net.sweevo.jinks.ExtBackup;
|
|
||||||
import net.sweevo.jinks.config.CommonConfig;
|
|
||||||
|
|
||||||
public class StatusCommand implements Command<CommandSourceStack> {
|
public class StatusCommand implements Command<CommandSourceStack> {
|
||||||
|
|
||||||
|
@ -27,12 +24,7 @@ public class StatusCommand implements Command<CommandSourceStack> {
|
||||||
String paused = data.isPaused() ? "true" : "false";
|
String paused = data.isPaused() ? "true" : "false";
|
||||||
String nextUp = data.getNextBackup();
|
String nextUp = data.getNextBackup();
|
||||||
ServerPlayer player = context.getSource().getPlayer();
|
ServerPlayer player = context.getSource().getPlayer();
|
||||||
MutableComponent message = BackupThread.component(player, "Backups paused: %s. - Next backup: %s", paused, nextUp);
|
ChatHelper.tell(player, "Backups paused: %s. - Next backup: %s", Style.EMPTY.withColor(ChatFormatting.BLUE), paused, nextUp);
|
||||||
if (player != null) {
|
|
||||||
player.sendSystemMessage(message.withStyle(Style.EMPTY.withColor(ChatFormatting.BLUE)));
|
|
||||||
} else {
|
|
||||||
ExtBackup.LOGGER.info(String.valueOf(message));
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package net.sweevo.jinks.network;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
|
||||||
import net.sweevo.jinks.ExtBackup;
|
|
||||||
import net.sweevo.jinks.client.ClientEventHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public record Pause(boolean pause) implements CustomPacketPayload {
|
|
||||||
|
|
||||||
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ExtBackup.MODID, "pause");
|
|
||||||
public static final CustomPacketPayload.Type<Pause> TYPE = new Type<>(ID);
|
|
||||||
|
|
||||||
public static final StreamCodec<FriendlyByteBuf, Pause> CODEC = StreamCodec.composite(
|
|
||||||
ByteBufCodecs.BOOL, Pause::pause, Pause::new
|
|
||||||
);
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public Type<? extends CustomPacketPayload> type() {
|
|
||||||
return Pause.TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(IPayloadContext context) {
|
|
||||||
ClientEventHandler.setPaused(this.pause);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"extbackup.backup_started": "Backup gestartet...",
|
|
||||||
"extbackup.backup_finished": "Backup fertiggestellt in %s",
|
|
||||||
"extbackup.backups_paused": "Backups pausiert",
|
|
||||||
"extbackup.status_message": "Backups pausiert: %s. - Nächstes Backup: %s"
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"extbackup.backup_started": "Backup started...",
|
|
||||||
"extbackup.backup_finished": "Backup completed in %s",
|
|
||||||
"extbackup.backups_paused": "Backups paused",
|
|
||||||
"extbackup.status_message": "Backups paused: %s. - Next backup: %s"
|
|
||||||
}
|
|
Loading…
Reference in a new issue