Create project
commit
ae6defc7e7
@ -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
|
@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>cn.isekai.mcp</groupId>
|
||||||
|
<artifactId>isekai-world-guard-flags</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>15</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
|
||||||
|
<worldGuard.version>7.0.6</worldGuard.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>isekai-world-guard-flags</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources/</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<!-- Clean the target folder content -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- Include resource files -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- Maven Java compiler -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- Generate a jar containing classes and resources -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sk89q-repo</id>
|
||||||
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dmulloy2-repo</id>
|
||||||
|
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>CodeMC</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spigot API, http://www.spigotmc.org/ or http://bukkit.org/ -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>${spigot.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
<artifactId>worldguard-core</artifactId>
|
||||||
|
<version>${worldGuard.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
<artifactId>worldguard-bukkit</artifactId>
|
||||||
|
<version>${worldGuard.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<ExpFlag> {
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
name: IsekaiWorldGuardFlags
|
||||||
|
main: cn.isekai.mcp.worldGuardFlags.PluginMain
|
||||||
|
api-version: 1.18
|
||||||
|
version: 1.0
|
||||||
|
depend:
|
||||||
|
- WorldGuard
|
Loading…
Reference in New Issue