Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Support for WorldGuard regions #8

Merged
merged 4 commits into from
Jul 17, 2024
Merged
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
13 changes: 7 additions & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v1
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17' # The JDK version to make available on the path.
distribution: 'temurin'
java-version: '21'
- name: Cache local Maven repository
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn clean package
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: Creepair (#${{ github.run_number }})
path: target/*.jar
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>im.wma.dev.Creepair</groupId>
<artifactId>Creepair</artifactId>
<version>0.4-DEV</version>
<version>0.5-DEV</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -13,6 +13,10 @@
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand All @@ -21,6 +25,12 @@
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<name>Creepair</name>
<url>http://wma.im</url>
Expand All @@ -42,8 +52,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
Expand Down
5 changes: 3 additions & 2 deletions res/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ worlds:
- world
above_y: 54
natural_blocks:
- GRASS
- SHORT_GRASS
- TALL_GRASS
- GRASS_BLOCK
- DIRT
- SANDSTONE
- SAND
- GRAVEL
- STONE
- GRASS_PATH
- DIRT_PATH
- ACACIA_LEAVES
- ACACIA_LOG
- BIRCH_LEAVES
Expand Down
3 changes: 2 additions & 1 deletion res/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Creepair
main: im.wma.dev.creepair.Creepair
version: ${version}
website: http://wma.im
api-version: 1.16 # Because of this Creepair is not compatible with verisons lower than 1.14
api-version: 1.20 # Because of this Creepair is not compatible with verisons lower than 1.14
softdepend: [WorldGuard]
commands:
creepair:
description: Returns the plugin version
Expand Down
18 changes: 18 additions & 0 deletions src/im/wma/dev/creepair/Creepair.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.util.List;
import java.util.logging.Level;

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -18,12 +22,15 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;

public class Creepair extends JavaPlugin implements Listener {
private final ArrayList<String> worlds = new ArrayList<>();
private final List<Material> naturalBlocks = new ArrayList<>();
private int y;
private RepairHelper helper;

private WorldGuardPlugin wg = null;

@Override
public void onEnable() {
Expand Down Expand Up @@ -69,6 +76,8 @@ public List<String> tabCommand(CommandSender sender, Command rootCommand, String

// Register "/check" command executor with Bukkit.
getCommand("creepair").setExecutor(creepairCommand);

this.wg = (WorldGuardPlugin) this.getServer().getPluginManager().getPlugin("WorldGuard");
}

public void reloadPluginConfig(CommandSender sender) {
Expand All @@ -90,6 +99,15 @@ public void onEntityExplode(EntityExplodeEvent event) {
return;
}

// Check WorldGuard status, if present let WorldGuard handle the event in a region with Flags.CREEPER_EXPLOSION
if(!(this.wg == null)){
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(event.getLocation());
if (!query.testState(loc, null, Flags.CREEPER_EXPLOSION)) {
event.setCancelled(true);
}
}

if (event.getLocation().getBlockY() >= y) {
event.setYield(0F);
for (Block block : event.blockList()) {
Expand Down