fix: move example config to resources, simplify WG to block-break only, fix teleport for stuck players only, add messages.yml

This commit is contained in:
loki5512344 2026-06-01 11:46:28 +02:00
parent f2be6d6ece
commit b80fefa6a4
6 changed files with 206 additions and 38 deletions

View file

@ -23,6 +23,7 @@ public final class WorldGuardConfigLoader {
/**
* Parses WorldGuard configuration from YAML.
* Simplified: only block-break flag.
*/
public WorldGuardConfig parse(YamlConfiguration yaml) {
ConfigurationSection wgSection = yaml.getConfigurationSection("worldguard");
@ -54,13 +55,10 @@ public final class WorldGuardConfigLoader {
members = defaults.getStringList("worldguard.members");
}
List<String> flags = yaml.getStringList("worldguard.flags");
if (flags.isEmpty()) {
flags = defaults.getStringList("worldguard.flags");
}
if (flags.isEmpty()) {
flags = List.of("passthrough=deny", "build=allow");
}
// Simplified: only block-break flag
// allow = все могут ломать, deny = никто не может, -g non_members = только владельцы
String blockBreak = yaml.getString("worldguard.block-break",
defaults.getString("worldguard.block-break", "allow"));
boolean protect = yaml.getBoolean("worldguard.protect-on-create",
defaults.getBoolean("worldguard.protect-on-create", true));
@ -70,7 +68,7 @@ public final class WorldGuardConfigLoader {
.template(template)
.owners(owners)
.members(members)
.flags(flags)
.blockBreak(blockBreak)
.protectOnCreate(protect)
.build();
}
@ -85,20 +83,21 @@ public final class WorldGuardConfigLoader {
yaml.set("worldguard.region-template", config.regionNameTemplate());
yaml.set("worldguard.owners", config.owners());
yaml.set("worldguard.members", config.members());
yaml.set("worldguard.flags", config.flags());
yaml.set("worldguard.block-break", config.blockBreak());
yaml.set("worldguard.protect-on-create", config.protectOnCreate());
}
}
/**
* Sets default values for WorldGuard configuration.
* Simplified: only block-break flag.
*/
public void setDefaults(YamlConfiguration yaml) {
yaml.set("worldguard.enabled", false);
yaml.set("worldguard.region-template", "{mine_name}_{random_4}");
yaml.set("worldguard.owners", List.of());
yaml.set("worldguard.members", List.of());
yaml.set("worldguard.flags", List.of("passthrough=deny", "build=allow"));
yaml.set("worldguard.block-break", "allow"); // allow = все могут ломать
yaml.set("worldguard.protect-on-create", true);
}
}

View file

@ -171,9 +171,9 @@ public final class MineResetHandler {
}
/**
* Teleports players standing inside the mine to a safe location.
* Teleports ONLY stuck players (those inside solid blocks) to a safe location.
* Uses player-spawn location if configured, otherwise uses teleport location.
* Prevents players from suffocating in blocks by finding a safe teleport spot.
* Only teleports if player is suffocating in a block, not all players in mine!
*/
private void teleportPlayers() {
// Get spawn location for stuck players (player-spawn config) or fall back to teleport location
@ -190,9 +190,20 @@ public final class MineResetHandler {
Location safeDest = BlockUpdateUtil.findSafeTeleportLocation(dest, 3);
for (Player p : dest.getWorld().getPlayers()) {
if (mine.contains(p.getLocation())) {
// Only teleport if player is INSIDE the mine AND is suffocating in a solid block
if (mine.contains(p.getLocation()) && isPlayerStuckInBlock(p)) {
p.teleport(safeDest);
}
}
}
/**
* Checks if player is stuck inside a solid block (suffocating).
*/
private boolean isPlayerStuckInBlock(Player player) {
Location loc = player.getLocation();
var block = loc.getBlock();
// Check if block at player position is solid (not air/liquid)
return block.getType().isSolid() && !block.isLiquid();
}
}

View file

@ -6,13 +6,14 @@ import java.util.Random;
/**
* Configuration for WorldGuard auto-region creation.
* Simplified: only controls who can break blocks in the mine.
*/
public record WorldGuardConfig(
boolean enabled,
String regionNameTemplate,
List<String> owners,
List<String> members,
List<String> flags,
String blockBreak,
boolean protectOnCreate
) {
@ -26,10 +27,8 @@ public record WorldGuardConfig(
: DEFAULT_TEMPLATE;
owners = owners != null ? List.copyOf(owners) : List.of();
members = members != null ? List.copyOf(members) : List.of();
flags = flags != null ? List.copyOf(flags) : List.of(
"passthrough=deny",
"build=allow"
);
// block-break: allow = все могут ломать, deny = никто не может, -g non_members = только владельцы
blockBreak = blockBreak != null && !blockBreak.isBlank() ? blockBreak : "allow";
protectOnCreate = protectOnCreate;
}
@ -77,6 +76,7 @@ public record WorldGuardConfig(
/**
* Default configuration with auto-region enabled.
* Everyone can break blocks (allow).
*/
public static WorldGuardConfig defaults() {
return new WorldGuardConfig(
@ -84,7 +84,7 @@ public record WorldGuardConfig(
DEFAULT_TEMPLATE,
List.of(),
List.of(),
List.of("passthrough=deny", "build=allow"),
"allow", // allow = все могут ломать
true
);
}
@ -98,7 +98,7 @@ public record WorldGuardConfig(
DEFAULT_TEMPLATE,
List.of(),
List.of(),
List.of(),
"allow",
false
);
}
@ -115,7 +115,7 @@ public record WorldGuardConfig(
private String template = DEFAULT_TEMPLATE;
private List<String> owners = List.of();
private List<String> members = List.of();
private List<String> flags = List.of("passthrough=deny", "build=allow");
private String blockBreak = "allow";
private boolean protectOnCreate = true;
public Builder enabled(boolean enabled) {
@ -138,8 +138,8 @@ public record WorldGuardConfig(
return this;
}
public Builder flags(List<String> flags) {
this.flags = flags;
public Builder blockBreak(String blockBreak) {
this.blockBreak = blockBreak;
return this;
}
@ -149,7 +149,6 @@ public record WorldGuardConfig(
}
public WorldGuardConfig build() {
return new WorldGuardConfig(enabled, template, owners, members, flags, protectOnCreate);
return new WorldGuardConfig(enabled, template, owners, members, blockBreak, protectOnCreate);
}
}
}