4 Commits
Author SHA1 Message Date
NotAlexNoyle 15d5c3f247 Exclude CODEOWNERS from language statistics 2026-11-03 10:43:46 -05:00
NotAlexNoyle 821dbd6735 Add CODEOWNERS (one staff approval) 2026-11-03 10:43:45 -05:00
Ryder Belserion 24b711a875 Update LICENSE 2024-12-06 23:04:37 -05:00
Ryder Belserion 3e12cfea67 Add base project 2024-12-02 14:35:23 -05:00
16 changed files with 212 additions and 60 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
.gitea/CODEOWNERS linguist-detectable=false
+3
View File
@@ -0,0 +1,3 @@
# Pull requests request review from the eligible staff team(s).
# One approval from either an Admin or Developer satisfies branch protection.
* @trueog/Admins @trueog/Developers
+72
View File
@@ -0,0 +1,72 @@
name: "🐛 Bug Report"
description: "Create a report to help us improve the plugin."
labels: [ "bug" ]
assignees:
- ryderbelserion
body:
- type: markdown
attributes:
value: |
Note: Search to see if an issue already exists for the bug you are reporting.
Add any gif / imgur links if need be. Markdown is supported!
If you have any large stack traces / errors, Please use https://mclo.gs/
Spark > https://spark.lucko.me/download
- type: input
attributes:
label: Spark link
description: We ask that Spark profile are shared through a link, not a screenshot. Screenshots inhibit our ability to figure out the real cause of the issue.
placeholder: Output of /spark profiler --timeout 300
validations:
required: false
- type: input
id: plugin_version
attributes:
label: Plugin Version
description: Type /version plugin-name in-game
validations:
required: true
- type: dropdown
id: version
attributes:
label: Server Version
description: What server version are you on?
options:
- "1.21.1"
- "1.21.2"
validations:
required: true
- type: dropdown
id: platform
attributes:
label: Server Platform
description: What server platform are you using?
options:
- Paper
- Purpur
- Folia
validations:
required: true
- type: textarea
id: bug
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to reproduce
description: Steps to reproduce the behavior.
placeholder: |
1. Go to '...'
2. Change value in placeholder.yml '...'
3. Run command '...'
4. See error
validations:
required: true
+20
View File
@@ -0,0 +1,20 @@
name: "🚩 Suggest a new flag to add"
description: "Missing a worldguard flag you don't have?"
labels: [ "feature" ]
body:
- type: textarea
id: feature
attributes:
label: Pick a name for it
description: "What do you want to name the worldguard flag?"
placeholder: "anti stabby max pro"
validations:
required: true
- type: textarea
attributes:
label: What does the worldguard flag do?
description: Describe what the worldguard flag does
validations:
required: true
+8 -3
View File
@@ -1,3 +1,8 @@
## New Flags
* Added a worldguard flag that prevents you from drowning.
* Added a worldguard flag that prevents natural mob spawning in regions.
## Changes:
- Updated how flags are handled internally to easily add newer flags.
- Currently working on another flag I am interested in.
## Fixed:
- Added a null check if the flag is not in the registry.
- This only happens if you enable a config option, and do `/simpleflags reload`
- WorldGuard flags can only be added on startup, as any time after that... the registry is frozen.
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2014-2024 CoreCraft Network
Copyright (c) 2024 Ryder Belserion
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
}
rootProject.group = "com.ryderbelserion.simpleflags"
rootProject.version = "1.0"
rootProject.version = "1.0.1"
rootProject.description = "A plugin that adds simple worldguard flags."
repositories {
@@ -1,52 +1,26 @@
package com.ryderbelserion.simpleflags.flags;
import ch.jalu.configme.SettingsManager;
import com.ryderbelserion.simpleflags.SimpleFlags;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.ryderbelserion.simpleflags.config.ConfigManager;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class FlagBuilder {
public abstract class FlagBuilder<T extends Flag> {
protected SimpleFlags plugin = JavaPlugin.getPlugin(SimpleFlags.class);
protected SettingsManager config = ConfigManager.getConfig();
public abstract void register();
public abstract String getName();
public abstract StateFlag getFlag();
public abstract T getFlag();
/**
* Prevent any type of damage in any region.
*
* @param player the player to prevent damage to.
* @param source the source of the damage.
* @param type the type of the damage to check.
* @return true or false
*/
public boolean preventDamage(Player player, DamageSource source, DamageType type) {
return source.getDamageType() == type && getQuery().testState(BukkitAdapter.adapt(player.getLocation()), WorldGuardPlugin.inst().wrapPlayer(player), getFlag());
}
/**
* Prevent spawning based on a supplied spawn reason.
*
* @param location the location to check.
* @param receivingReason the reason from the event.
* @param reason your reason.
* @return true or false
*/
public boolean preventSpawning(org.bukkit.Location location, CreatureSpawnEvent.SpawnReason receivingReason, CreatureSpawnEvent.SpawnReason reason) {
return receivingReason != reason || getQuery().testState(BukkitAdapter.adapt(location), null, getFlag());
}
public abstract boolean isEnabled();
/**
* @return A query of regions.
@@ -61,4 +35,5 @@ public abstract class FlagBuilder {
protected FlagRegistry getRegistry() {
return this.plugin.getWorldGuard().getFlagRegistry();
}
}
@@ -6,9 +6,9 @@ import java.util.Map;
public class FlagManager {
private final Map<String, FlagBuilder> flags = new HashMap<>();
private final Map<String, FlagBuilder<?>> flags = new HashMap<>();
public void addFlag(FlagBuilder builder) {
public <F extends FlagBuilder<?>> void addFlag(F builder) {
// Register the flag.
builder.register();
@@ -21,7 +21,7 @@ public class FlagManager {
return this.flags.containsKey(name);
}
public FlagBuilder getFlag(String name) {
public FlagBuilder<?> getFlag(String name) {
return this.flags.get(name);
}
@@ -29,7 +29,7 @@ public class FlagManager {
this.flags.remove(name);
}
public Map<String, FlagBuilder> getFlags() {
public Map<String, FlagBuilder<?>> getFlags() {
return Collections.unmodifiableMap(this.flags);
}
}
@@ -0,0 +1,11 @@
package com.ryderbelserion.simpleflags.flags.builders;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.sk89q.worldguard.protection.flags.IntegerFlag;
public abstract class IntegerFlagBuilder extends FlagBuilder<IntegerFlag> {
@Override
public abstract IntegerFlag getFlag();
}
@@ -0,0 +1,42 @@
package com.ryderbelserion.simpleflags.flags.builders;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
public abstract class StateFlagBuilder extends FlagBuilder<StateFlag> {
@Override
public abstract StateFlag getFlag();
/**
* Prevent any type of damage in any region.
*
* @param player the player to prevent damage to.
* @param source the source of the damage.
* @param type the type of the damage to check.
* @param flag the flag.
* @return true or false
*/
public boolean preventDamage(Player player, DamageSource source, DamageType type, StateFlag flag) {
return source.getDamageType() == type && getQuery().testState(BukkitAdapter.adapt(player.getLocation()), WorldGuardPlugin.inst().wrapPlayer(player), flag);
}
/**
* Prevent spawning based on a supplied spawn reason.
*
* @param location the location to check.
* @param receivingReason the reason from the event.
* @param reason your reason.
* @param flag the flag.
* @return true or false
*/
public boolean preventSpawning(org.bukkit.Location location, CreatureSpawnEvent.SpawnReason receivingReason, CreatureSpawnEvent.SpawnReason reason, StateFlag flag) {
return receivingReason != reason || getQuery().testState(BukkitAdapter.adapt(location), null, flag);
}
}
@@ -2,8 +2,9 @@ package com.ryderbelserion.simpleflags.flags.enums;
public enum CustomFlags {
NATURAL_FLAG("prevent_natural_spawning"),
DROWN_FLAG("prevent_drowning"),
NATURAL_FLAG("prevent_natural_spawning");
CAPACITY_FLAG("max_players");
private final String name;
@@ -1,21 +1,20 @@
package com.ryderbelserion.simpleflags.flags.types;
import com.ryderbelserion.simpleflags.config.ConfigManager;
import com.ryderbelserion.simpleflags.config.impl.Config;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
import com.ryderbelserion.simpleflags.flags.enums.CustomFlags;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import java.util.logging.Level;
public class DrownFlag extends FlagBuilder {
public class DrownFlag extends StateFlagBuilder {
private StateFlag flag;
@Override
public void register() {
if (!ConfigManager.getConfig().getProperty(Config.drowning_flag)) return;
if (!isEnabled()) return;
try {
getRegistry().register(this.flag = new StateFlag("prevent-drowning", true));
@@ -33,12 +32,17 @@ public class DrownFlag extends FlagBuilder {
}
@Override
public final String getName() {
public String getName() {
return CustomFlags.DROWN_FLAG.getName();
}
@Override
public final StateFlag getFlag() {
public StateFlag getFlag() {
return this.flag;
}
@Override
public boolean isEnabled() {
return this.config.getProperty(Config.drowning_flag);
}
}
@@ -1,21 +1,20 @@
package com.ryderbelserion.simpleflags.flags.types;
import com.ryderbelserion.simpleflags.config.ConfigManager;
import com.ryderbelserion.simpleflags.config.impl.Config;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
import com.ryderbelserion.simpleflags.flags.enums.CustomFlags;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import java.util.logging.Level;
public class NaturalFlag extends FlagBuilder {
public class NaturalFlag extends StateFlagBuilder {
private StateFlag flag;
@Override
public void register() {
if (!ConfigManager.getConfig().getProperty(Config.natural_spawning_flag)) return;
if (!isEnabled()) return;
try {
getRegistry().register(this.flag = new StateFlag("prevent-natural-spawning", true));
@@ -41,4 +40,9 @@ public class NaturalFlag extends FlagBuilder {
public StateFlag getFlag() {
return this.flag;
}
@Override
public boolean isEnabled() {
return this.config.getProperty(Config.natural_spawning_flag);
}
}
@@ -1,9 +1,10 @@
package com.ryderbelserion.simpleflags.listeners;
import com.ryderbelserion.simpleflags.SimpleFlags;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
import com.ryderbelserion.simpleflags.flags.FlagManager;
import com.ryderbelserion.simpleflags.flags.enums.CustomFlags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -28,9 +29,15 @@ public class DrowningListener implements Listener {
if (!this.flagManager.hasFlag(flagName)) return;
final FlagBuilder flag = this.flagManager.getFlag(flagName);
final StateFlagBuilder flag = (StateFlagBuilder) this.flagManager.getFlag(flagName);
if (!flag.preventDamage(player, event.getDamageSource(), DamageType.DROWN)) {
if (!flag.isEnabled()) return;
final StateFlag stateFlag = flag.getFlag();
if (stateFlag == null) return;
if (!flag.preventDamage(player, event.getDamageSource(), DamageType.DROWN, stateFlag)) {
event.setCancelled(true);
}
}
@@ -2,9 +2,10 @@ package com.ryderbelserion.simpleflags.listeners;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.ryderbelserion.simpleflags.SimpleFlags;
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
import com.ryderbelserion.simpleflags.flags.FlagManager;
import com.ryderbelserion.simpleflags.flags.enums.CustomFlags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -22,9 +23,15 @@ public class NaturalListener implements Listener {
if (!this.flagManager.hasFlag(flagName)) return;
final FlagBuilder flag = this.flagManager.getFlag(flagName);
final StateFlagBuilder flag = (StateFlagBuilder) this.flagManager.getFlag(flagName);
if (!flag.preventSpawning(event.getSpawnLocation(), event.getReason(), CreatureSpawnEvent.SpawnReason.NATURAL)) {
if (!flag.isEnabled()) return;
final StateFlag stateFlag = flag.getFlag();
if (stateFlag == null) return;
if (!flag.preventSpawning(event.getSpawnLocation(), event.getReason(), CreatureSpawnEvent.SpawnReason.NATURAL, stateFlag)) {
event.setCancelled(true);
}
}