RandomTeleport: added permissions

This commit is contained in:
Erik Bročko 2018-09-08 01:52:59 +02:00
parent de5fb271a7
commit 02079533f4

View File

@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import cz.marwland.mc.core.MarwCore;
import cz.marwland.mc.core.features.Feature;
@ -27,24 +28,35 @@ public class RandomTeleport extends Feature {
if (!permissionMissingCheck(sender, this.getPermission()))
return true;
if (sender instanceof ConsoleCommandSender && args.length < 1) {
sender.sendMessage(ChatColor.RED + "You need to specify the world! " + ChatColor.YELLOW + "/rtp [world]");
if (!(sender instanceof Player) && args.length < 1) {
sender.sendMessage(ChatColor.RED + "You need to specify the player! " + ChatColor.YELLOW + "/rtp [player] [world]");
return true;
}
// Should never happen.
if (!(sender instanceof Player))
return false;
Player p = (Player) sender;
if (args.length >= 1) {
p = plugin.getServer().getPlayer(args[0]);
if (p == null) {
if (p != sender && !permissionMissingCheck(sender, this.getPermission() + ".others")) {
return true;
} else if (p == null) {
sender.sendMessage(ChatColor.RED + "Player not found!");
return true;
}
}
World w = p.getWorld();
if (args.length >= 2) {
w = plugin.getServer().getWorld(args[1]);
if (w != p.getWorld() && !permissionMissingCheck(sender, this.getPermission() + ".world." + w.getName()) ) {
return true;
} else if (w == null) {
sender.sendMessage(ChatColor.RED + "World not found!");
return true;
}
}
sender.sendMessage("teleporting...");
randomTeleport(w, p);
return true;
@ -72,7 +84,9 @@ public class RandomTeleport extends Feature {
int finx = minx + (int) (Math.random() * rangex) + wboff;
int finz = minz + (int) (Math.random() * rangez) + wboff;
Location targetloc = w.getHighestBlockAt(finx, finz).getLocation();
p.teleport(targetloc);
; }
targetloc.setYaw((float) (Math.random() * 360f));
targetloc.add(0.5d, 1d, 0.5d);
p.teleport(targetloc, TeleportCause.COMMAND);
}
}