Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f939649cd | ||
|
|
4f84911bc2 | ||
|
|
269367ad2b | ||
|
|
1683cfe940 | ||
|
|
f158356044 | ||
|
|
dd555ef372 | ||
|
|
4486d2e08a | ||
|
|
252ba2c209 | ||
|
|
8042692c6a | ||
|
|
8653722289 | ||
|
|
b7c405fc30 | ||
|
|
2b6c3867ea | ||
|
|
c68b99b4f5 | ||
|
|
b1152f8f50 | ||
|
|
3b322e71a0 | ||
|
|
5e464897d7 | ||
|
|
4694f1e3d8 | ||
|
|
1b12182cf2 | ||
|
|
70234ac910 | ||
|
|
310040edba | ||
|
|
298bdc7f65 | ||
|
|
e79e94539e | ||
|
|
e265297e02 | ||
|
|
2a4fab9d04 | ||
|
|
61c1c4cc91 | ||
|
|
d4bd25f1f9 | ||
|
|
20e32fd180 | ||
|
|
cc8bbd411f | ||
|
|
d3ced7a57b | ||
|
|
bcb3cd7956 | ||
|
|
4973036378 | ||
|
|
d1e9acc677 | ||
|
|
b021ffb03e | ||
|
|
552a442cb4 | ||
|
|
036e793033 | ||
|
|
64fc245d72 | ||
|
|
030c0d81c1 | ||
|
|
5b87b2a823 | ||
|
|
234631d8fc | ||
|
|
f1075da09a | ||
|
|
ddf0f60033 | ||
|
|
f590186546 | ||
|
|
5fafba633f | ||
|
|
3db53609e0 | ||
|
|
5d42ed3f19 | ||
|
|
ecd02f3630 | ||
|
|
2ed1e08f5b | ||
|
|
774276c9b8 | ||
|
|
0c2837ddd8 | ||
|
|
40495b6a4e | ||
|
|
f82205da3b | ||
|
|
370c37889b |
No files matched your search
@@ -1 +0,0 @@
|
||||
.gitea/CODEOWNERS linguist-detectable=false
|
||||
@@ -1,3 +0,0 @@
|
||||
# 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
|
||||
@@ -1,72 +0,0 @@
|
||||
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
|
||||
@@ -1,20 +0,0 @@
|
||||
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
|
||||
+3
-8
@@ -1,8 +1,3 @@
|
||||
## 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.
|
||||
## New Flags
|
||||
* Added a worldguard flag that prevents you from drowning.
|
||||
* Added a worldguard flag that prevents natural mob spawning in regions.
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Ryder Belserion
|
||||
Copyright (c) 2014-2024 CoreCraft Network
|
||||
|
||||
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
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
rootProject.group = "com.ryderbelserion.simpleflags"
|
||||
rootProject.version = "1.0.1"
|
||||
rootProject.version = "1.0"
|
||||
rootProject.description = "A plugin that adds simple worldguard flags."
|
||||
|
||||
repositories {
|
||||
|
||||
@@ -1,26 +1,52 @@
|
||||
package com.ryderbelserion.simpleflags.flags;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import com.ryderbelserion.simpleflags.SimpleFlags;
|
||||
import com.ryderbelserion.simpleflags.config.ConfigManager;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
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.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<T extends Flag> {
|
||||
public abstract class FlagBuilder {
|
||||
|
||||
protected SimpleFlags plugin = JavaPlugin.getPlugin(SimpleFlags.class);
|
||||
|
||||
protected SettingsManager config = ConfigManager.getConfig();
|
||||
|
||||
public abstract void register();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract T getFlag();
|
||||
public abstract StateFlag getFlag();
|
||||
|
||||
public abstract boolean isEnabled();
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A query of regions.
|
||||
@@ -35,5 +61,4 @@ public abstract class FlagBuilder<T extends Flag> {
|
||||
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 <F extends FlagBuilder<?>> void addFlag(F builder) {
|
||||
public void addFlag(FlagBuilder 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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
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();
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
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,9 +2,8 @@ package com.ryderbelserion.simpleflags.flags.enums;
|
||||
|
||||
public enum CustomFlags {
|
||||
|
||||
NATURAL_FLAG("prevent_natural_spawning"),
|
||||
DROWN_FLAG("prevent_drowning"),
|
||||
CAPACITY_FLAG("max_players");
|
||||
NATURAL_FLAG("prevent_natural_spawning");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.ryderbelserion.simpleflags.flags.types;
|
||||
|
||||
import com.ryderbelserion.simpleflags.config.ConfigManager;
|
||||
import com.ryderbelserion.simpleflags.config.impl.Config;
|
||||
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
|
||||
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
|
||||
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 StateFlagBuilder {
|
||||
public class DrownFlag extends FlagBuilder {
|
||||
|
||||
private StateFlag flag;
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
if (!isEnabled()) return;
|
||||
if (!ConfigManager.getConfig().getProperty(Config.drowning_flag)) return;
|
||||
|
||||
try {
|
||||
getRegistry().register(this.flag = new StateFlag("prevent-drowning", true));
|
||||
@@ -32,17 +33,12 @@ public class DrownFlag extends StateFlagBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public final String getName() {
|
||||
return CustomFlags.DROWN_FLAG.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StateFlag getFlag() {
|
||||
public final StateFlag getFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.config.getProperty(Config.drowning_flag);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.ryderbelserion.simpleflags.flags.types;
|
||||
|
||||
import com.ryderbelserion.simpleflags.config.ConfigManager;
|
||||
import com.ryderbelserion.simpleflags.config.impl.Config;
|
||||
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
|
||||
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
|
||||
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 StateFlagBuilder {
|
||||
public class NaturalFlag extends FlagBuilder {
|
||||
|
||||
private StateFlag flag;
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
if (!isEnabled()) return;
|
||||
if (!ConfigManager.getConfig().getProperty(Config.natural_spawning_flag)) return;
|
||||
|
||||
try {
|
||||
getRegistry().register(this.flag = new StateFlag("prevent-natural-spawning", true));
|
||||
@@ -40,9 +41,4 @@ public class NaturalFlag extends StateFlagBuilder {
|
||||
public StateFlag getFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.config.getProperty(Config.natural_spawning_flag);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.ryderbelserion.simpleflags.listeners;
|
||||
|
||||
import com.ryderbelserion.simpleflags.SimpleFlags;
|
||||
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
|
||||
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
|
||||
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;
|
||||
@@ -29,15 +28,9 @@ public class DrowningListener implements Listener {
|
||||
|
||||
if (!this.flagManager.hasFlag(flagName)) return;
|
||||
|
||||
final StateFlagBuilder flag = (StateFlagBuilder) this.flagManager.getFlag(flagName);
|
||||
final FlagBuilder flag = this.flagManager.getFlag(flagName);
|
||||
|
||||
if (!flag.isEnabled()) return;
|
||||
|
||||
final StateFlag stateFlag = flag.getFlag();
|
||||
|
||||
if (stateFlag == null) return;
|
||||
|
||||
if (!flag.preventDamage(player, event.getDamageSource(), DamageType.DROWN, stateFlag)) {
|
||||
if (!flag.preventDamage(player, event.getDamageSource(), DamageType.DROWN)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package com.ryderbelserion.simpleflags.listeners;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||
import com.ryderbelserion.simpleflags.SimpleFlags;
|
||||
import com.ryderbelserion.simpleflags.flags.builders.StateFlagBuilder;
|
||||
import com.ryderbelserion.simpleflags.flags.FlagBuilder;
|
||||
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;
|
||||
@@ -23,15 +22,9 @@ public class NaturalListener implements Listener {
|
||||
|
||||
if (!this.flagManager.hasFlag(flagName)) return;
|
||||
|
||||
final StateFlagBuilder flag = (StateFlagBuilder) this.flagManager.getFlag(flagName);
|
||||
final FlagBuilder flag = this.flagManager.getFlag(flagName);
|
||||
|
||||
if (!flag.isEnabled()) return;
|
||||
|
||||
final StateFlag stateFlag = flag.getFlag();
|
||||
|
||||
if (stateFlag == null) return;
|
||||
|
||||
if (!flag.preventSpawning(event.getSpawnLocation(), event.getReason(), CreatureSpawnEvent.SpawnReason.NATURAL, stateFlag)) {
|
||||
if (!flag.preventSpawning(event.getSpawnLocation(), event.getReason(), CreatureSpawnEvent.SpawnReason.NATURAL)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user