Skip to content

Commit

Permalink
Update RedProtect hook for RedProtect 7.6.X
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Sep 2, 2019
1 parent 6aa7160 commit 3fe219c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
Binary file removed lib/RedProtect.jar
Binary file not shown.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.jikoo</groupId>
<artifactId>regionerator</artifactId>
<name>Regionerator</name>
<version>1.5.7</version>
<version>1.5.8</version>

<dependencies>
<dependency>
Expand Down Expand Up @@ -63,10 +63,16 @@
<version>24e3d4bf67</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>br.net.fabiozumbi12.RedProtect</groupId>
<artifactId>RedProtect-Core</artifactId>
<version>7.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>br.net.fabiozumbi12.RedProtect</groupId>
<artifactId>RedProtect-Spigot</artifactId>
<version>7.5.3</version>
<version>7.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.github.jikoo.regionerator.CoordinateConversions;
import com.github.jikoo.regionerator.PluginHook;

import com.github.jikoo.regionerator.world.DummyChunk;
import org.bukkit.Location;
import org.bukkit.World;

/**
Expand All @@ -15,29 +17,49 @@
*/
public class RedProtectHook extends PluginHook {

private boolean needAPI = false;

public RedProtectHook() {
super("RedProtect");
}

@Override
public boolean isHookUsable() {
try {
return super.isHookUsable();
} catch (Exception | NoSuchMethodError | NoSuchFieldError e) {
System.err.println("RedProtect fast hook failed usability! Falling back to slower API-based solution.");
System.err.println("Please report this stack trace:");
e.printStackTrace();
needAPI = true;
}

return super.isHookUsable();
}

@Override
public boolean isChunkProtected(World chunkWorld, int chunkX, int chunkZ) {
/*
* RedProtectAPI is somewhat lacking. Also, it contains a typo. While I'd bet it's pretty
* efficient and good, the code style is utterly horrifying.
*
* API-only solution:
* return RedProtectAPI.getChunkRegions(new DummyChunk(chunkWorld, chunkX, chunkZ)).size() > 0;
* However, that method is new in 6.6.0, and I can perform the needed checks faster avoiding it.
* RedProtectAPI is somewhat lacking and contains several typos.
* Check is far more efficient to perform off the API.
*/
for (Region region : RedProtect.get().rm.getRegionsByWorld(chunkWorld)) {
if (CoordinateConversions.blockToChunk(region.getMinMbrX()) > chunkX
|| CoordinateConversions.blockToChunk(region.getMaxMbrX()) < chunkX
|| CoordinateConversions.blockToChunk(region.getMinMbrZ()) > chunkZ
|| CoordinateConversions.blockToChunk(region.getMaxMbrZ()) < chunkZ) {

if (needAPI) {
return RedProtect.get().getAPI().getChunkRegions(new DummyChunk(chunkWorld, chunkX, chunkZ)).size() > 0;
}

for (Region region : RedProtect.get().rm.getRegionsByWorld(chunkWorld.getName())) {
Location min = region.getMinLocation();
Location max = region.getMaxLocation();
if (CoordinateConversions.blockToChunk(min.getBlockX()) > chunkX
|| CoordinateConversions.blockToChunk(max.getBlockX()) < chunkX
|| CoordinateConversions.blockToChunk(min.getBlockZ()) > chunkZ
|| CoordinateConversions.blockToChunk(max.getBlockZ()) < chunkZ) {
continue;
}
return true;
}

return false;
}

Expand Down

0 comments on commit 3fe219c

Please sign in to comment.