Compare commits

...

5 Commits

Author SHA1 Message Date
johnfriedrich e5c745e018 Dont shade GD API 2022-05-28 22:50:24 +01:00
johnfriedrich 18ad2b50c0 Use player world as preset when using rtp without parameters 2022-05-28 22:50:24 +01:00
Phoenix616 b8d686d9d3
Re-add backwards support down to 1.13
Also update PaperLib dependency and repo
2022-05-22 12:42:51 +01:00
John c30af21608
Use recent GD API (#51) 2022-05-22 12:29:25 +01:00
Omer Oreg 61c32c5995
Implements Hooks for GriefDefender & ChunkyBorder. (#49)
* Added griefdefender support

* Added info command

* Fixed info command not executing

oops

* Implemented hook for chunkyborder

* Removed --info command

You can get this info in the logs.

* Update plugin.yml

* Added missing GriefDefender hook artifact
2022-05-22 00:23:34 +01:00
12 changed files with 233 additions and 10 deletions

View File

@ -40,7 +40,7 @@
</repository>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/content/groups/public</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>minebench-repo</id>
@ -52,13 +52,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.2</version>
<version>1.0.7</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -0,0 +1,44 @@
<?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">
<parent>
<artifactId>randomteleport-plugin-hooks</artifactId>
<groupId>de.themoep.randomteleport.pluginhook</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>chunkyborder</artifactId>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>codemc</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.popcraft</groupId>
<artifactId>chunkyborder</artifactId>
<version>1.0.43</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.popcraft</groupId>
<artifactId>chunky-bukkit</artifactId>
<version>1.2.93</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
package de.themoep.randomteleport.hook.plugin;
import de.themoep.randomteleport.hook.WorldborderHook;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import org.popcraft.chunkyborder.BorderData;
import org.popcraft.chunkyborder.ChunkyBorder;
public class ChunkyBorderHook implements WorldborderHook {
private final ChunkyBorder plugin;
public ChunkyBorderHook() {
this.plugin = (ChunkyBorder) Bukkit.getPluginManager().getPlugin("ChunkyBorder");
}
@Override
public Plugin getPlugin() {
return this.plugin;
}
@Override
public Location getCenter(World world) {
BorderData borderData = plugin.getBorders().get(world.getName());
return new Location(world, borderData.getCenterX(),0D,borderData.getCenterZ());
}
@Override
public double getBorderRadius(World world) {
BorderData borderData = plugin.getBorders().get(world.getName());
return borderData.getRadiusX();
}
@Override
public boolean isInsideBorder(Location location) {
BorderData borderData = plugin.getBorders().get(location.getWorld().getName());
return borderData.getBorder().isBounding(location.getBlockX(),location.getBlockZ());
}
@Override
public String getPluginName() {
return plugin.getName();
}
}

View File

@ -0,0 +1,40 @@
<?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">
<parent>
<artifactId>randomteleport-plugin-hooks</artifactId>
<groupId>de.themoep.randomteleport.pluginhook</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>griefdefender</artifactId>
<repositories>
<repository>
<id>gdapi</id>
<url>https://repo.glaremasters.me/repository/bloodshot</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.griefdefender</groupId>
<artifactId>api</artifactId>
<version>2.1.0-20220122.032038-5</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,46 @@
package de.themoep.randomteleport.hook.plugin;
import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.claim.ClaimManager;
import com.griefdefender.api.claim.ClaimTypes;
import de.themoep.randomteleport.hook.ProtectionHook;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class GriefDefenderHook implements ProtectionHook {
@Override
public Plugin getPlugin() {
return Bukkit.getPluginManager().getPlugin("GriefDefender");
}
@Override
public String getPluginName() {
return "GriefDefender";
}
@Override
public boolean canBuild(Player player, Location location) {
return canBuild(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public boolean canBuild(Player player, World world, int chunkX, int chunkZ) {
return canBuild(world, chunkX * 16, world.getSeaLevel(), chunkZ * 16);
}
private boolean canBuild(World world, int x, int y, int z) {
if (GriefDefender.getCore().isEnabled(world.getUID())) {
ClaimManager claimManager = GriefDefender.getCore().getClaimManager(world.getUID());
if (claimManager == null) {
return true;
} else {
return claimManager.getClaimAt(x, y, z).getType() == ClaimTypes.WILDERNESS;
}
}
return true;
}
}

View File

@ -18,10 +18,12 @@
<module>worldguard-6</module>
<module>worldguard-7</module>
<module>griefprevention</module>
<module>griefdefender</module>
<module>redprotect</module>
<module>factions</module>
<module>factions-uuid</module>
<module>worldborder</module>
<module>chunkyborder</module>
</modules>
<dependencies>

View File

@ -42,6 +42,18 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}.pluginhook</groupId>
<artifactId>chunkyborder</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}.pluginhook</groupId>
<artifactId>griefdefender</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@ -83,6 +83,8 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
private Material[] unsafeBlocks;
private Set<String> signVariables;
private boolean hasMinHeight = true;
public void onEnable() {
hookManager = new HookManager(this);
loadConfig();
@ -481,4 +483,21 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
public RandomSearcher getRandomSearcher(Player player, Location origin, int minRange, int maxRange, LocationValidator... validators) {
return new RandomSearcher(this, player, origin, minRange, maxRange, validators);
}
/**
* Utility method to get the min height of a world as old versions didn't have support for this.
* @param world The world
* @return The min height or 0 if querying that isn't supported
*/
public int getMinHeight(World world) {
if (hasMinHeight) {
try {
return world.getMinHeight();
} catch (NoSuchMethodError ignored) {
// getMinHeight is only available starting in 1.16.5
}
hasMinHeight = false;
}
return 0;
}
}

View File

@ -41,7 +41,14 @@ public class RandomTeleportCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
if (sender instanceof Player) {
runPreset("default", sender, (Player) sender, ((Player) sender).getLocation());
Player player = (Player) sender;
String preset = "default";
if (plugin.getConfig().getBoolean("use-player-world-as-preset", false)) {
String worldName = player.getWorld().getName().toLowerCase();
if (presetExistsInConfig(worldName))
preset = worldName;
}
runPreset(preset, sender, player, player.getLocation());
return true;
}
} else if (args.length == 1) {
@ -57,7 +64,7 @@ public class RandomTeleportCommand implements CommandExecutor {
}
} else {
try {
if (sender.hasPermission("randomteleport.manual")){
if (sender.hasPermission("randomteleport.manual")) {
plugin.parseAndRun(sender, getLocation(sender), args);
return true;
} else {
@ -88,7 +95,7 @@ public class RandomTeleportCommand implements CommandExecutor {
);
} else if (sender != target && !sender.hasPermission("randomteleport.tpothers")) {
plugin.sendMessage(sender, "error.no-permission.tp-others", "perm", "randomteleport.tpothers");
} else if (plugin.getConfig().getString("presets." + preset) == null) {
} else if (!presetExistsInConfig(preset)) {
plugin.sendMessage(sender, "error.preset-doesnt-exist", "preset", preset);
} else {
if (sender == target) {
@ -109,6 +116,10 @@ public class RandomTeleportCommand implements CommandExecutor {
}
}
private boolean presetExistsInConfig(String preset) {
return plugin.getConfig().getString("presets." + preset) != null;
}
private static Location getLocation(CommandSender sender) {
if (sender instanceof Entity) {
return ((Entity) sender).getLocation();

View File

@ -90,7 +90,7 @@ public class RandomSearcher {
setCenter(center);
setMinRadius(minRadius);
setMaxRadius(maxRadius);
minY = center.getWorld().getMinHeight();
minY = plugin.getMinHeight(center.getWorld());
if (center.getWorld().getEnvironment() == World.Environment.NETHER) {
maxY = 126;
} else {
@ -257,7 +257,8 @@ public class RandomSearcher {
* @param minY The min Y; has to be positive and less than the max Y!
*/
public void setMinY(int minY) {
Validate.isTrue(minY >= center.getWorld().getMinHeight() && minY < maxY, "Min Y has to be at least the world's minimum height and less than the max Y!");
Validate.isTrue(minY >= plugin.getMinHeight(center.getWorld()), "Min Y has to be at least the world's minimum height!");
Validate.isTrue(minY < maxY, "Min Y has to be less than the max Y!");
this.minY = minY;
}
@ -362,7 +363,7 @@ public class RandomSearcher {
}
lastCheck = center.getWorld().getTime();
Location randomLoc = center.clone();
randomLoc.setY(center.getWorld().getMinHeight());
randomLoc.setY(plugin.getMinHeight(center.getWorld()));
int minChunk = minRadius >> 4;
int maxChunk = maxRadius >> 4;
int randChunkX;

View File

@ -4,6 +4,9 @@ lang: en
debug: true
# Delay in ticks between checking chunks when searching
# Should we search for a preset named like the world the player is in when using /rtp without parameters?
use-player-world-as-preset: false
# Blocks to teleport on in normal mode
safe-blocks:
- sand

View File

@ -2,7 +2,7 @@ name: RandomTeleport
provides: [FUBSRandomTeleport]
main: de.themoep.randomteleport.RandomTeleport
version: '${minecraft.plugin.version}'
api-version: 1.17
api-version: 1.13
description: ${project.description}
author: Phoenix616
website: https://github.com/Phoenix616/RandomTeleport/