WorldGuard dependency

This commit is contained in:
Erik Bročko 2018-09-08 18:04:09 +02:00
parent bd343888bb
commit 58f9a4d349
4 changed files with 71 additions and 10 deletions

View File

@ -17,4 +17,12 @@
<classpathentry kind="src" path="/BountifulAPI"/> <classpathentry kind="src" path="/BountifulAPI"/>
<classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar" sourcepath="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2-sources.jar"/> <classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar" sourcepath="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT-sources.jar"/> <classpathentry kind="var" path="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/bukkit/bukkit/1.13-R0.1-SNAPSHOT/bukkit-1.13-R0.1-SNAPSHOT-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sk89q/worldedit/worldedit-core/6.0.0-SNAPSHOT/worldedit-core-6.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/com/sk89q/worldedit/worldedit-core/6.0.0-SNAPSHOT/worldedit-core-6.0.0-SNAPSHOT-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/de/schlichtherle/truezip/6.8.3/truezip-6.8.3.jar" sourcepath="M2_REPO/de/schlichtherle/truezip/6.8.3/truezip-6.8.3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/rhino/js/1.7R2/js-1.7R2.jar" sourcepath="M2_REPO/rhino/js/1.7R2/js-1.7R2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar"/>
<classpathentry kind="var" path="M2_REPO/com/thoughtworks/paranamer/paranamer/2.6/paranamer-2.6.jar" sourcepath="M2_REPO/com/thoughtworks/paranamer/paranamer/2.6/paranamer-2.6-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sk89q/lib/jlibnoise/1.0.0/jlibnoise-1.0.0.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sk89q/jchronic/0.2.4a/jchronic-0.2.4a.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sk89q/worldguard/worldguard-legacy/6.2/worldguard-legacy-6.2.jar"/>
</classpath> </classpath>

16
pom.xml
View File

@ -71,6 +71,18 @@
<version>1.6.4</version> <version>1.6.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>6.2</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
@ -80,5 +92,9 @@
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository> </repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
</repositories> </repositories>
</project> </project>

View File

@ -4,6 +4,7 @@ version: 0.0.1
api-version: 1.12 api-version: 1.12
author: ericek111 author: ericek111
website: https://git.lixko.eu/MarwLand/MarwCore website: https://git.lixko.eu/MarwLand/MarwCore
softdepend: [WorldGuard]
commands: commands:
first: first:
description: First command. description: First command.

View File

@ -2,22 +2,25 @@ package cz.marwland.mc.essentials.features;
import java.util.Arrays; import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import cz.marwland.mc.core.MarwCore;
import cz.marwland.mc.core.features.Feature; import cz.marwland.mc.core.features.Feature;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
public class RandomTeleport extends Feature { public class RandomTeleport extends Feature {
public RandomTeleport(MarwCore plugin) { private int MAX_TRIES = 100;
super(plugin, null);
public RandomTeleport() {
super();
this.addCommand(new BukkitCommand( this.addCommand(new BukkitCommand(
"rtp", "rtp",
"Teleport player to random location in the current world.", "Teleport player to random location in the current world.",
@ -36,7 +39,7 @@ public class RandomTeleport extends Feature {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length >= 1) { if (args.length >= 1) {
p = plugin.getServer().getPlayer(args[0]); p = Bukkit.getServer().getPlayer(args[0]);
if (p != sender && !permissionMissingCheck(sender, this.getPermission() + ".others")) { if (p != sender && !permissionMissingCheck(sender, this.getPermission() + ".others")) {
return true; return true;
} else if (p == null) { } else if (p == null) {
@ -47,7 +50,7 @@ public class RandomTeleport extends Feature {
World w = p.getWorld(); World w = p.getWorld();
if (args.length >= 2) { if (args.length >= 2) {
w = plugin.getServer().getWorld(args[1]); w = Bukkit.getServer().getWorld(args[1]);
if (w != p.getWorld() && !permissionMissingCheck(sender, this.getPermission() + ".world." + w.getName()) ) { if (w != p.getWorld() && !permissionMissingCheck(sender, this.getPermission() + ".world." + w.getName()) ) {
return true; return true;
} else if (w == null) { } else if (w == null) {
@ -56,7 +59,6 @@ public class RandomTeleport extends Feature {
} }
} }
sender.sendMessage("teleporting...");
randomTeleport(w, p); randomTeleport(w, p);
return true; return true;
@ -64,12 +66,24 @@ public class RandomTeleport extends Feature {
@Override @Override
public String getPermission() { public String getPermission() {
return getPermissionPath() + "." + this.getName().toLowerCase(); return getPermissionPath();
} }
}); });
} }
public static void randomTeleport(World w, Player p) { public void randomTeleport(World w, Player p) {
Location loc = null;
for (int i = 0; i < MAX_TRIES && loc == null; i++) {
p.sendMessage("Generating #" + i);
loc = generateLoc(w);
if (!canTeleportHere(loc, p))
loc = null;
}
if (loc != null)
p.teleport(loc, TeleportCause.COMMAND);
}
public Location generateLoc(World w) {
int wboff = 16; int wboff = 16;
Location loc = w.getWorldBorder().getCenter(); Location loc = w.getWorldBorder().getCenter();
int radius = (int) w.getWorldBorder().getSize() / 2; int radius = (int) w.getWorldBorder().getSize() / 2;
@ -86,7 +100,29 @@ public class RandomTeleport extends Feature {
Location targetloc = w.getHighestBlockAt(finx, finz).getLocation(); Location targetloc = w.getHighestBlockAt(finx, finz).getLocation();
targetloc.setYaw((float) (Math.random() * 360f)); targetloc.setYaw((float) (Math.random() * 360f));
targetloc.add(0.5d, 1d, 0.5d); targetloc.add(0.5d, 1d, 0.5d);
p.teleport(targetloc, TeleportCause.COMMAND);
return targetloc;
}
public boolean canTeleportHere(Location loc, Player p) {
Block block = loc.getWorld().getBlockAt(loc);
p.sendMessage(block.getType().name());
BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(block, block.getData(), true);
Bukkit.getServer().getPluginManager().callEvent(canBuildEvent);
if(!canBuildEvent.isBuildable())
return false;
try {
p.sendMessage("trying");
if (!com.sk89q.worldguard.bukkit.WGBukkit.getPlugin().canBuild(p, block)) {
p.sendMessage("cannot");
return false;
}
} catch (NoClassDefFoundError e) {
}
p.sendMessage("can");
return true;
} }
} }