Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinhong11 committed Jun 8, 2024
1 parent 9f70fae commit e63b730
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/main/java/me/mmmjjkx/bbox/moreflags/MoreFlagsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void registerFlags(EntityListener entityListener) {
@Override
public void onReload() {
super.onReload();
saveConfig();

settings = new Config<>(this, Settings.class).loadConfigObject();

Expand All @@ -55,12 +56,9 @@ private void registerFlagSet(String id, Material icon, FlagSet flagSet, Listener
.mode(Flag.Mode.EXPERT)
.listener(listener)
.type(Flag.Type.SETTING)
.defaultSetting(flagSet.getDefaultValue())
.cooldown(flagSet.getChangeCooldown())
.build();
registerFlag(flag);

flag.setDefaultSetting(flagSet.getDefaultValue());
}
}
}
12 changes: 4 additions & 8 deletions src/main/java/me/mmmjjkx/bbox/moreflags/config/FlagSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import lombok.Setter;
import world.bentobox.bentobox.api.configuration.ConfigEntry;

@Getter
@Setter
public class FlagSet {
@Getter
public FlagSet() {
}

@ConfigEntry(path = "enabled")
private boolean enabled = true;
@Getter
@ConfigEntry(path = "change-cooldown")
private int changeCooldown = 0;
@ConfigEntry(path = "default-value")
private boolean defaultValue = false;

public boolean getDefaultValue() {
return defaultValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.mmmjjkx.bbox.moreflags.config;

import org.bukkit.configuration.MemorySection;
import world.bentobox.bentobox.database.objects.adapters.AdapterInterface;

import java.util.Map;

public class FlagSetSerializer implements AdapterInterface<FlagSet, Map<String, Object>> {

public FlagSetSerializer() {
}

@Override
public FlagSet deserialize(Object o) {
FlagSet flagSet = new FlagSet();
if (o instanceof MemorySection ms) {
flagSet.setEnabled(ms.getBoolean("enabled"));
flagSet.setChangeCooldown(ms.getInt("change-cooldown"));
}
return flagSet;
}

@Override
public Map<String, Object> serialize(Object o) {
if (o instanceof FlagSet fs) {
boolean enabled = fs.isEnabled();
int changeCooldown = fs.getChangeCooldown();
return Map.of("enabled", enabled, "change-cooldown", changeCooldown);
} else {
return null;
}
}
}
12 changes: 8 additions & 4 deletions src/main/java/me/mmmjjkx/bbox/moreflags/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
import lombok.Getter;
import lombok.Setter;
import world.bentobox.bentobox.api.configuration.*;
import world.bentobox.bentobox.database.objects.adapters.Adapter;

@StoreAt(filename = "config.yml")
@StoreAt(filename = "config.yml", path = "flags")
@Getter
@Setter
public class Settings implements ConfigObject {
@ConfigEntry(path = "flags.creeper_explosion")
@ConfigEntry(path = "creeper_explosion")
@ConfigComment("It can control creeper explosions.")
@Adapter(FlagSetSerializer.class)
private FlagSet creeperExplosions = new FlagSet();

@ConfigEntry(path = "flags.wither_explosion")
@ConfigEntry(path = ".wither_explosion")
@ConfigComment("It can control wither explosions.")
@Adapter(FlagSetSerializer.class)
private FlagSet witherExplosions = new FlagSet();

@ConfigEntry(path = "flags.phantom_spawning")
@ConfigEntry(path = "phantom_spawning")
@ConfigComment("It can control phantom spawning.")
@Adapter(FlagSetSerializer.class)
private FlagSet phantomSpawning = new FlagSet();
}
5 changes: 1 addition & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ flags:
creeper_explosion:
enabled: true
change-cooldown: 0
default-value: true
wither_explosion:
enabled: true
change-cooldown: 0
default-value: true
phantom_spawning:
enabled: true
change-cooldown: 0
default-value: true
change-cooldown: 0

0 comments on commit e63b730

Please sign in to comment.