Skip to content

Commit

Permalink
Config saves.Only save if world save is on
Browse files Browse the repository at this point in the history
also description and format tweak for minimessage tags
  • Loading branch information
mcmonkey4eva committed Oct 21, 2022
1 parent b80bc3a commit a9b802a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.paper.PaperModule;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.chat.ComponentSerializer;
Expand All @@ -21,6 +22,7 @@ public static void register() {
// @Plugin Paper
// @description
// Returns the element with all MiniMessage tags parsed, see <@link url https://docs.adventure.kyori.net/minimessage/format.html> for more information.
// This may be useful for reading data from external plugins, but should not be used in normal scripts.
// -->
ElementTag.tagProcessor.registerTag(ElementTag.class, "parse_minimessage", (attribute, object) -> {
return new ElementTag(PaperModule.stringifyComponent(MiniMessage.miniMessage().deserialize(object.asString())));
Expand All @@ -32,11 +34,11 @@ public static void register() {
// @Plugin Paper
// @description
// Returns the element with all text formatting parsed into MiniMessage format.
// This may be useful for sending data to external plugins, but should not be used in normal scripts.
// -->
ElementTag.tagProcessor.registerTag(ElementTag.class, "to_minimessage", (attribute, object) -> {
return new ElementTag(MiniMessage.miniMessage().serialize(
PaperModule.jsonToComponent(ComponentSerializer.toString(FormattedTextHelper.parse(object.asString(), ChatColor.WHITE, false)))
));
Component parsed = PaperModule.jsonToComponent(ComponentSerializer.toString(FormattedTextHelper.parse(object.asString(), ChatColor.WHITE, false)));
return new ElementTag(MiniMessage.miniMessage().serialize(parsed));
});
}
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ public static void register() {
// # Stores a player ".dat" file's NBT data
// # NOTE: replace 'something' with your map data
// - define playerdata something
// - define data <[something].map_to_nbt.gzip_compress>
// - define data <[playerdata].map_to_nbt.gzip_compress>
// - ~filewrite path:data/<player.uuid>.dat data:<[data]>
// -->
MapTag.tagProcessor.registerStaticTag(BinaryTag.class, "map_to_nbt", (attribute, object) -> {
Expand Down
Expand Up @@ -122,6 +122,7 @@ public static void refillCache() {
cache_commandScriptAutoInit = config.getBoolean("Scripts.Command.Auto init", false);
PlayerFlagHandler.cacheTimeoutSeconds = config.getLong("Saves.Offline player cache timeout", 300);
PlayerFlagHandler.asyncPreload = config.getBoolean("Saves.Load async on login", true);
PlayerFlagHandler.saveOnlyWhenWorldSaveOn = config.getBoolean("Saves.Only save if world save is on", false);
RemoveCommand.alwaysWarnOnMassRemove = config.getBoolean("Commands.Remove.Always warn on mass delete", false);
ConfigurationSection colorSection = config.getConfigurationSection("Colors");
if (colorSection != null) {
Expand Down
Expand Up @@ -30,6 +30,8 @@ public class PlayerFlagHandler implements Listener {

public static boolean asyncPreload = false;

public static boolean saveOnlyWhenWorldSaveOn = false;

public static class CachedPlayerFlag {

public long lastAccessed;
Expand Down Expand Up @@ -93,6 +95,9 @@ public static void cleanCache() {
}

public static void saveThenExpire(UUID id, CachedPlayerFlag cache) {
if (saveOnlyWhenWorldSaveOn && !Bukkit.getWorlds().get(0).isAutoSave()) {
return;
}
BukkitRunnable expireTask = new BukkitRunnable() {
@Override
public void run() {
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/main/resources/config.yml
Expand Up @@ -294,6 +294,10 @@ Saves:
Skip flag cleaning: false
# When set to 'true', skips flag cleaning for ChunkTag and LocationTag flags.
Skip chunk flag cleaning: false
# When set to 'true', player flag autosaving will be delayed whenever world saves are disabled (eg via '/save-off').
# Player flags will still save as normal during shutdown, or when world saving is enabled.
# This checks based on your default world (server.worlds.first).
Only save if world save is on: false

Packets:
# Whether to allow Denizen to intercept packets from and to player clients.
Expand Down

0 comments on commit a9b802a

Please sign in to comment.