Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ repositories {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven {
name = "sk89q-repo"
url = "https://maven.enginehub.org/repo/"
}
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12")
}

def targetJavaVersion = 21
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/org/woftnw/battlewinner/Battlewinner.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.woftnw.battlewinner;

import org.bukkit.event.EventPriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.woftnw.battlewinner.gameplay.item.GrapplingHookManager;
import org.woftnw.battlewinner.worldguard.WorldGuardAccessor;

public final class Battlewinner extends JavaPlugin {

private static Battlewinner instance;
private final WorldGuardAccessor worldGuardAccessor = new WorldGuardAccessor();

@Override
public void onLoad() {
worldGuardAccessor.load();
}

@Override
public void onEnable() {
Expand All @@ -23,4 +29,8 @@ public void onDisable() {
public static Battlewinner getInstance() {
return instance;
}

public WorldGuardAccessor getWorldGuardAccessor() {
return worldGuardAccessor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.woftnw.battlewinner.worldguard;

import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.session.SessionManager;
import org.woftnw.battlewinner.Battlewinner;
import org.woftnw.battlewinner.worldguard.flag.RespiratorFlag;
import org.woftnw.battlewinner.worldguard.handler.RespiratorFlagHandler;

public class WorldGuardAccessor {

public final WorldGuardFlag[] flags = {
new RespiratorFlag()
};

public void load() {
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
for (WorldGuardFlag flag : flags) {
if (flag instanceof StateFlag) {
try {
// create a flag
StateFlag newFlag = new StateFlag(flag.getName(), (Boolean) flag.getDefault());
registry.register(newFlag);
flag.setFlag(newFlag); // only set our flag if there was no error
} catch (FlagConflictException e) {
// some other plugin registered a flag by the same name already.
// you can use the existing flag, but this may cause conflicts - be sure to check type
Flag<?> existing = registry.get(flag.getName());
if (existing instanceof StateFlag existingStateFlag) {
flag.setFlag(existingStateFlag);
} else {
// types don't match - this is bad news! some other plugin conflicts with you
// hopefully this never actually happens
Battlewinner.getInstance().getLogger().warning("Flag " + flag.getFlag().getName() + " is registered by another plugin!");
}
}
} else {
Battlewinner.getInstance().getLogger().warning("Flag " + flag.getFlag().getName() + " is not a StateFlag!");
}
}
SessionManager sessionManager = WorldGuard.getInstance().getPlatform().getSessionManager();
// second param allows for ordering of handlers - see the JavaDocs
sessionManager.registerHandler(RespiratorFlagHandler.FACTORY, null);
}

public WorldGuardFlag getFlag(String name) {
for (WorldGuardFlag flag : flags) {
if (name.equals(flag.getName())) return flag;
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.woftnw.battlewinner.worldguard;

import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.jetbrains.annotations.NotNull;

public interface WorldGuardFlag {

@NotNull
StateFlag getFlag();

void setFlag(StateFlag flag);

Object getDefault();

String getName();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.woftnw.battlewinner.worldguard.flag;

import com.sk89q.worldguard.protection.flags.StateFlag;
import org.jetbrains.annotations.NotNull;
import org.woftnw.battlewinner.worldguard.WorldGuardFlag;

public class RespiratorFlag implements WorldGuardFlag {

private StateFlag RESPIRATOR_FLAG;

@Override
public @NotNull StateFlag getFlag() {
return RESPIRATOR_FLAG;
}

@Override
public void setFlag(StateFlag flag) {
RESPIRATOR_FLAG = flag;
}

@Override
public Object getDefault() {
return false;
}

@Override
public String getName() {
return "respirator";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.woftnw.battlewinner.worldguard.handler;

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.woftnw.battlewinner.Battlewinner;

import java.util.Objects;
import java.util.regex.Pattern;

public class RespiratorFlagHandler extends Handler {
public static final Factory FACTORY = new Factory();
private final StateFlag FLAG = Battlewinner.getInstance().getWorldGuardAccessor().getFlag("respirator").getFlag();

public static class Factory extends Handler.Factory<RespiratorFlagHandler> {
@Override
public RespiratorFlagHandler create(Session session) {
// create an instance of a handler for the particular session
// if you need to pass certain variables based on, for example, the player
// whose session this is, do it here
return new RespiratorFlagHandler(session);
}
}
// construct with your desired flag to track changes
public RespiratorFlagHandler(Session session) {
super(session);
}
// ... override handler methods here

private long lastStageChange = 0;
private AsphyxiaStage stage = AsphyxiaStage.NONE;

@Override
public void tick(@NotNull LocalPlayer player, ApplicableRegionSet set) {
if (player.getHealth() <= 0) {
return;
}

if (!Objects.equals(set.queryValue(player, FLAG), StateFlag.State.ALLOW)) {
return;
}

long now = System.currentTimeMillis();

if (getSession().isInvincible(player) || (player.getGameMode() != GameModes.SURVIVAL && player.getGameMode() != GameModes.ADVENTURE)) {
// don't damage invincible players
return;
}

Player bukkitPlayer = BukkitAdapter.adapt(player);
final PotionEffect slowness1 = new PotionEffect(PotionEffectType.SLOWNESS, 20, 0, true, false);
final PotionEffect slowness2 = new PotionEffect(PotionEffectType.SLOWNESS, 20, 1, true, false);
final PotionEffect darkness = new PotionEffect(PotionEffectType.DARKNESS, 20, 0, true, false);
final PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 20, 0, true, false);
final PotionEffect poison1 = new PotionEffect(PotionEffectType.POISON, 20, 0, true, false);
final PotionEffect poison2 = new PotionEffect(PotionEffectType.POISON, 20, 1, true, false);
final PotionEffect nausea = new PotionEffect(PotionEffectType.NAUSEA, 20, 0, true, false);
final PotionEffect wither2 = new PotionEffect(PotionEffectType.WITHER, 20, 1, true, false);

if (stage == AsphyxiaStage.NONE) {

} else if (stage == AsphyxiaStage.MILD) {
bukkitPlayer.addPotionEffect(slowness1);
} else if (stage == AsphyxiaStage.MODERATE) {
bukkitPlayer.addPotionEffect(slowness1);
bukkitPlayer.addPotionEffect(darkness);
} else if (stage == AsphyxiaStage.HEAVY) {
bukkitPlayer.addPotionEffect(slowness2);
bukkitPlayer.addPotionEffect(darkness);
bukkitPlayer.addPotionEffect(poison1);
} else if (stage == AsphyxiaStage.EXTREME) {
bukkitPlayer.addPotionEffect(slowness2);
bukkitPlayer.addPotionEffect(blindness);
bukkitPlayer.addPotionEffect(poison2);
} else if (stage == AsphyxiaStage.LETHAL) {
bukkitPlayer.addPotionEffect(slowness2);
bukkitPlayer.addPotionEffect(blindness);
bukkitPlayer.addPotionEffect(nausea);
bukkitPlayer.addPotionEffect(wither2);
}

// 5 minutes in milliseconds
long stageTime = 5 * 60 * 1000;
if (now - lastStageChange > stageTime) {

if (stage == AsphyxiaStage.NONE) {
stage = AsphyxiaStage.MILD;
} else if (stage == AsphyxiaStage.MILD) {
stage = AsphyxiaStage.MODERATE;
} else if (stage == AsphyxiaStage.MODERATE) {
stage = AsphyxiaStage.HEAVY;
} else if (stage == AsphyxiaStage.HEAVY) {
stage = AsphyxiaStage.EXTREME;
} else if (stage == AsphyxiaStage.EXTREME) {
stage = AsphyxiaStage.LETHAL;
} else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "advancement grant " + player.getName() + " only vengeance:asphyxia");
}

lastStageChange = now;
}
}

/**
* Check whether a player is currently wearing a respirator
* @return true if the player is wearing a respirator, false otherwise
*/
public static boolean isPlayerWearingRespirator(@NotNull Player player) {
// Get the item in the helmet slot
ItemStack helmet = player.getInventory().getHelmet();
// If it is null or has no item meta, it is not a respirator
if (helmet == null || helmet.getItemMeta() == null) return false;
// Get component string
String componentString = helmet.getItemMeta().getAsComponentString();
// We need to check for the custom_data component with the respirator key
Pattern pattern = Pattern.compile("\\[.*minecraft:custom_data=\\{.*respirator:.*\\{.*}}.*]");
// True if exists, false otherwise
return (pattern.matcher(componentString).find());
}

enum AsphyxiaStage {
NONE, // nothing
MILD, // slowness
MODERATE, // slowness & darkness
HEAVY, // slowness 2, darkness, poison
EXTREME, // slowness 2, blindness, poison 2
LETHAL // slowness 2, blindness, nausea, wither 2
}
}

5 changes: 5 additions & 0 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ prefix: Battlewinner
authors: [ BogTheMudWing ]
description: 'A plugin for Wings of Fire: The New World that brings Battlewinner back from the dead.'
website: https://woftnw.org
dependencies:
server:
WorldGuard:
load: BEFORE
required: true
Loading