commit ae6defc7e7979cebbc1ba6a4f5815d3a9d677d37 Author: Hyperzlib Date: Tue Aug 6 22:51:40 2024 +0800 Create project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54abab5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +.idea \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2b9c5b3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,107 @@ + + + 4.0.0 + + cn.isekai.mcp + isekai-world-guard-flags + 1.0-SNAPSHOT + + + 17 + 15 + UTF-8 + 1.18-R0.1-SNAPSHOT + 7.0.6 + + + + isekai-world-guard-flags + + + src/main/resources/ + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 3.2.0 + + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sk89q-repo + https://maven.enginehub.org/repo/ + + + dmulloy2-repo + https://repo.dmulloy2.net/nexus/repository/public/ + + + CodeMC + https://repo.codemc.org/repository/maven-public + + + + + + + org.spigotmc + spigot-api + ${spigot.version} + provided + + + + com.sk89q.worldguard + worldguard-core + ${worldGuard.version} + provided + + + com.sk89q.worldguard + worldguard-bukkit + ${worldGuard.version} + provided + + + org.projectlombok + lombok + 1.18.24 + compile + + + + \ No newline at end of file diff --git a/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginLogger.java b/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginLogger.java new file mode 100644 index 0000000..f8fd6b6 --- /dev/null +++ b/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginLogger.java @@ -0,0 +1,27 @@ +package cn.isekai.mcp.worldGuardFlags; + +import java.util.logging.Logger; + +public class PluginLogger { + private static Logger logger; + + private PluginLogger() { + // Class only has static methods and should not be instantiated + } + + public static void setLogger(Logger logger) { + PluginLogger.logger = logger; + } + + public static void info(String message) { + logger.info(message); + } + + public static void warning(String message) { + logger.warning(message); + } + + public static void severe(String message) { + logger.severe(message); + } +} diff --git a/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginMain.java b/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginMain.java new file mode 100644 index 0000000..6d15f0d --- /dev/null +++ b/src/main/java/cn/isekai/mcp/worldGuardFlags/PluginMain.java @@ -0,0 +1,56 @@ +package cn.isekai.mcp.worldGuardFlags; + +import cn.isekai.mcp.worldGuardFlags.flags.Flags; +import cn.isekai.mcp.worldGuardFlags.handlers.ExpFlag; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.session.SessionManager; +import lombok.Getter; +import org.bukkit.event.Listener; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +public class PluginMain extends JavaPlugin { + @Getter + private WorldGuardPlugin worldGuardPlugin; + + @Getter + private WorldGuard worldGuard; + + @Getter + private RegionContainer regionContainer; + + @Getter + private SessionManager sessionManager; + + @Override + public void onLoad() { + PluginLogger.setLogger(getLogger()); + + final PluginManager pluginManager = getServer().getPluginManager(); + this.worldGuardPlugin = (WorldGuardPlugin) pluginManager.getPlugin("WorldGuard"); + this.worldGuard = WorldGuard.getInstance(); + + try { + FlagRegistry flagRegistry = this.worldGuard.getFlagRegistry(); + flagRegistry.register(Flags.EXP_AMOUNT); + flagRegistry.register(Flags.EXP_DELAY); + } catch (Exception e) { + this.getServer().getPluginManager().disablePlugin(this); + + throw new RuntimeException(e instanceof IllegalStateException ? + "WorldGuard prevented flag registration. Did you reload the plugin? This is not supported!" : + "Flag registration failed!", e); + } + } + + @Override + public void onEnable() { + this.regionContainer = this.worldGuard.getPlatform().getRegionContainer(); + this.sessionManager = this.worldGuard.getPlatform().getSessionManager(); + + this.sessionManager.registerHandler(ExpFlag.FACTORY, null); + } +} diff --git a/src/main/java/cn/isekai/mcp/worldGuardFlags/flags/Flags.java b/src/main/java/cn/isekai/mcp/worldGuardFlags/flags/Flags.java new file mode 100644 index 0000000..b2f6ba1 --- /dev/null +++ b/src/main/java/cn/isekai/mcp/worldGuardFlags/flags/Flags.java @@ -0,0 +1,8 @@ +package cn.isekai.mcp.worldGuardFlags.flags; + +import com.sk89q.worldguard.protection.flags.IntegerFlag; + +public final class Flags { + public final static IntegerFlag EXP_AMOUNT = new IntegerFlag("exp-amount"); + public final static IntegerFlag EXP_DELAY = new IntegerFlag("exp-delay"); +} diff --git a/src/main/java/cn/isekai/mcp/worldGuardFlags/handlers/ExpFlag.java b/src/main/java/cn/isekai/mcp/worldGuardFlags/handlers/ExpFlag.java new file mode 100644 index 0000000..fa29b34 --- /dev/null +++ b/src/main/java/cn/isekai/mcp/worldGuardFlags/handlers/ExpFlag.java @@ -0,0 +1,73 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package cn.isekai.mcp.worldGuardFlags.handlers; + +import cn.isekai.mcp.worldGuardFlags.flags.Flags; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.session.Session; +import com.sk89q.worldguard.session.handler.Handler; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class ExpFlag extends Handler { + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory { + @Override + public ExpFlag create(Session session) { + return new ExpFlag(session); + } + } + + private long lastGiveExp = 0; + + public ExpFlag(Session session) { + super(session); + } + + @Override + public void tick(LocalPlayer player, ApplicableRegionSet set) { + if (player.getHealth() <= 0) { + return; + } + + long now = System.currentTimeMillis(); + + Integer expAmount = set.queryValue(player, Flags.EXP_AMOUNT); + Integer expDelay = set.queryValue(player, Flags.EXP_DELAY); + + if (expAmount == null || expDelay == null) { + return; + } + + if (now - lastGiveExp > expDelay * 1000) { + Player bukkitPlayer = ((BukkitPlayer) player).getPlayer(); + if (bukkitPlayer != null) { + bukkitPlayer.giveExp(expAmount); + } + lastGiveExp = now; + } + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..34ce6fe --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: IsekaiWorldGuardFlags +main: cn.isekai.mcp.worldGuardFlags.PluginMain +api-version: 1.18 +version: 1.0 +depend: + - WorldGuard \ No newline at end of file