Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinhong11 committed Jul 19, 2024
1 parent e63b730 commit 4c40a25
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.mmmjjkx.bbox</groupId>
<artifactId>MoreFlags</artifactId>
<version>1.0.2</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>MoreFlags</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/mmmjjkx/bbox/moreflags/FlagNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class FlagNames {
public static final String CREEPER_EXPLOSION = "creeper_explosion";
public static final String WITHER_EXPLOSION = "wither_explosion";
public static final String PHANTOM_SPAWNING = "phantom_spawning";
public static final String WITCH_POTION_THROWING = "witch_potion_throwing";
}
9 changes: 5 additions & 4 deletions src/main/java/me/mmmjjkx/bbox/moreflags/MoreFlagsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class MoreFlagsAddon extends Addon {
@Override
public void onEnable() {
saveDefaultConfig();
saveConfig();

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

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

EntityListener entityListener = new EntityListener(settings);

Expand All @@ -32,6 +32,7 @@ private void registerFlags(EntityListener entityListener) {
registerFlagSet(FlagNames.CREEPER_EXPLOSION, Material.CREEPER_HEAD, settings.getCreeperExplosions(), entityListener);
registerFlagSet(FlagNames.WITHER_EXPLOSION, Material.WITHER_SKELETON_SKULL, settings.getWitherExplosions(), entityListener);
registerFlagSet(FlagNames.PHANTOM_SPAWNING, Material.PHANTOM_SPAWN_EGG, settings.getPhantomSpawning(), entityListener);
registerFlagSet(FlagNames.WITCH_POTION_THROWING, Material.SPLASH_POTION, settings.getWitchPotionThrowing(), entityListener);
}

@Override
Expand All @@ -41,8 +42,7 @@ public void onReload() {

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

Settings save = new Settings();
new Config<>(this, Settings.class).saveConfigObject(save);
new Config<>(this, Settings.class).saveConfigObject(settings);
}

@Override
Expand All @@ -57,6 +57,7 @@ private void registerFlagSet(String id, Material icon, FlagSet flagSet, Listener
.listener(listener)
.type(Flag.Type.SETTING)
.cooldown(flagSet.getChangeCooldown())
.defaultSetting(flagSet.getDefaultValue())
.build();
registerFlag(flag);
}
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/me/mmmjjkx/bbox/moreflags/config/FlagSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

import lombok.Getter;
import lombok.Setter;
import world.bentobox.bentobox.api.configuration.ConfigEntry;

@Getter
@Setter
public class FlagSet {
public FlagSet() {
enabled = true;
changeCooldown = 0;
defaultValue = true;
}

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

public boolean getDefaultValue() {
return defaultValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ public FlagSetSerializer() {
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"));
flagSet.setEnabled(ms.getBoolean("enabled", true));
flagSet.setChangeCooldown(ms.getInt("change-cooldown", 0));
flagSet.setDefaultValue(ms.getBoolean("default-value", true));
} else if (o instanceof Map<?, ?> m) {
Map<String, Object> map = (Map<String, Object>) m;
flagSet.setEnabled((boolean) map.getOrDefault("enabled", true));
flagSet.setChangeCooldown((int) map.getOrDefault("change-cooldown", 0));
flagSet.setDefaultValue((boolean) map.getOrDefault("default-value", true));
}
return flagSet;
}
Expand All @@ -25,7 +31,8 @@ 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);
boolean defaultValue = fs.getDefaultValue();
return Map.of("enabled", enabled, "change-cooldown", changeCooldown, "default-value", defaultValue);
} else {
return null;
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/me/mmmjjkx/bbox/moreflags/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@
import world.bentobox.bentobox.api.configuration.*;
import world.bentobox.bentobox.database.objects.adapters.Adapter;

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

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

@ConfigEntry(path = "phantom_spawning")
@ConfigComment("It can control phantom spawning.")
@Adapter(FlagSetSerializer.class)
private FlagSet phantomSpawning = new FlagSet();
private FlagSet phantomSpawning;

@ConfigEntry(path = "witch_potion_throwing", since = "1.1")
@ConfigComment("It can control witch potion throwing.")
@Adapter(FlagSetSerializer.class)
private FlagSet witchPotionThrowing;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import me.mmmjjkx.bbox.moreflags.config.Settings;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Witch;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.projectiles.ProjectileSource;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.database.objects.Island;
Expand Down Expand Up @@ -54,6 +57,16 @@ public void spawn(EntitySpawnEvent e) {
}
}

@EventHandler
public void potionDrop(PotionSplashEvent e) {
ProjectileSource source = e.getPotion().getShooter();
if (source instanceof Witch witch) {
if (settings.getWitchPotionThrowing().isEnabled() && !inIsland(witch, FlagNames.WITCH_POTION_THROWING, true)) {
e.setCancelled(true);
}
}
}

private boolean inIsland(Entity en, String id, boolean destExpression) {
IslandsManager im = BentoBox.getInstance().getIslands();
Optional<Island> island = im.getIslandAt(en.getLocation());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MoreFlags
main: me.mmmjjkx.bbox.moreflags.MoreFlagsAddon
version: 1.0.0
version: "${project.version}"
api-version: 1.16.4
authors: mmmjjkx
description: Adds more flags to the game mode addon.
30 changes: 20 additions & 10 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
flags:
creeper_explosion:
enabled: true
change-cooldown: 0
wither_explosion:
enabled: true
change-cooldown: 0
phantom_spawning:
enabled: true
change-cooldown: 0
#It can control creeper explosions.
creeper_explosion:
enabled: true
change-cooldown: 0
default-value: true
#It can control wither explosions.
wither_explosion:
enabled: true
change-cooldown: 0
default-value: true
#It can control phantom spawning.
phantom_spawning:
enabled: true
change-cooldown: 0
default-value: true
#It can control witch potion throwing.
witch_potion_throwing:
enabled: true
change-cooldown: 0
default-value: true
5 changes: 4 additions & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ protection:
description: "&aAllow &7/ &c Prevent &awither explosions destroying blocks"
phantom_spawning:
name: Phantom spawning
description: "&aAllow &7/ &c Prevent &aphantoms spawning"
description: "&aAllow &7/ &c Prevent &aphantoms spawning"
witch_potion_throwing:
name: Witch potion throwing
description: "&aAllow &7/ &c Prevent &awitches throwing potions"
5 changes: 4 additions & 1 deletion src/main/resources/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ protection:
description: "&a允许&7/&c禁止 &a凋零爆炸破坏方块"
phantom_spawning:
name: 幻翼生成
description: "&a允许&7/&c禁止 &a幻翼生成"
description: "&a允许&7/&c禁止 &a幻翼生成"
witch_potion_throwing:
name: 女巫药水投掷
description: "&a允许&7/&c禁止 &a女巫药水投掷"
5 changes: 4 additions & 1 deletion src/main/resources/locales/zh-HK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ protection:
description: "&a允许&7/&c禁止 &a凋零爆炸破坏方块"
phantom_spawning:
name: 幻翼生成
description: "&a允许&7/&c禁止 &a幻翼生成"
description: "&a允许&7/&c禁止 &a幻翼生成"
witch_potion_throwing:
name: 女巫药水投掷
description: "&a允许&7/&c禁止 &a女巫药水投掷"

0 comments on commit 4c40a25

Please sign in to comment.