RandomTeleport

This commit is contained in:
Erik Bročko 2018-09-06 11:25:49 +02:00
parent 44556d788e
commit 2191b94b9a
3 changed files with 82 additions and 2 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash
if [[ "Eriks-MacBook-Air.local" == `hostname` ]]; then
if [[ "Darwin" == `uname` ]]; then
MC_PATH="../../server"
cp "$1" "../../server/plugins/$2.jar"
"$MC_PATH/cmd.sh" "plugman reload $2"
else

View File

@ -9,6 +9,7 @@ import cz.marwland.mc.core.features.Base;
import cz.marwland.mc.core.features.Feature;
import cz.marwland.mc.essentials.features.Borders;
import cz.marwland.mc.essentials.features.ChatNotifier;
import cz.marwland.mc.essentials.features.RandomTeleport;
public class MarwCore extends JavaPlugin {
@ -24,6 +25,7 @@ public class MarwCore extends JavaPlugin {
this.addFeature(new Borders(this));
this.addFeature(new ChatNotifier(this));
this.addFeature(new RandomTeleport(this));
configManager.load();
this.features.forEach((k, v) -> v.onEnable());

View File

@ -0,0 +1,78 @@
package cz.marwland.mc.essentials.features;
import java.util.Arrays;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import cz.marwland.mc.core.MarwCore;
import cz.marwland.mc.core.features.Feature;
import net.md_5.bungee.api.ChatColor;
public class RandomTeleport extends Feature {
public RandomTeleport(MarwCore plugin) {
super(plugin, null);
this.addCommand(new BukkitCommand(
"rtp",
"Teleport player to random location in the current world.",
"/rtp [player]",
Arrays.asList("randomtp", "randomteleport") ) {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
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]");
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) {
sender.sendMessage(ChatColor.RED + "Player not found!");
return true;
}
}
World w = p.getWorld();
randomTeleport(w, p);
return true;
}
@Override
public String getPermission() {
return getPermissionPath() + "." + this.getName().toLowerCase();
}
});
}
public static void randomTeleport(World w, Player p) {
int wboff = 16;
Location loc = w.getWorldBorder().getCenter();
int radius = (int) w.getWorldBorder().getSize() / 2;
int minx = loc.getBlockX() - radius;
int minz = loc.getBlockZ() - radius;
int maxx = loc.getBlockX() + radius;
int maxz = loc.getBlockZ() + radius;
if (wboff >= radius)
wboff = 0;
int rangex = (maxx - minx) - wboff * 2;
int rangez = (maxz - minz) - wboff * 2;
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);
; }
}