Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.iamguus.experiencepvp.warps;
- import java.util.ArrayList;
- import me.iamguus.experiencepvp.Main;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.scheduler.BukkitRunnable;
- public class Warps implements Listener, CommandExecutor{
- ArrayList<String> delay = new ArrayList<String>();
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(sender instanceof Player) {
- final Player p = (Player) sender;
- if(label.equalsIgnoreCase("setwarp")) {
- if(p.hasPermission("experiencepvp.warps.setwarp")) {
- if(args.length == 0) {
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "You must specify a warp name!");
- return true;
- }
- Main.warpsConfig.set("warps." + args[0] + ".world", p.getLocation().getWorld().getName());
- Main.warpsConfig.set("warps." + args[0] + ".x", p.getLocation().getX());
- Main.warpsConfig.set("warps." + args[0] + ".y", p.getLocation().getY());
- Main.warpsConfig.set("warps." + args[0] + ".z", p.getLocation().getZ());
- Main.warpsConfig.set("warps." + args[0] + ".yaw", p.getLocation().getYaw());
- Main.warpsConfig.set("warps." + args[0] + ".pitch", p.getLocation().getPitch());
- Main.saveNewConfig();
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " has been set at your location!");
- } else {
- p.sendMessage("You may not run this command!");
- }
- }
- if(label.equalsIgnoreCase("warp")) {
- if(p.hasPermission("experiencepvp.warps.warp")) {
- if(args.length == 0) {
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warps: " + Main.warpsConfig.getConfigurationSection("warps").getKeys(false));
- return true;
- }
- if(Main.warpsConfig.getConfigurationSection("warps." + args[0] + "") == null) {
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "Warp " + args[0] + " does not exist!");
- return true;
- }
- final World w = Bukkit.getServer().getWorld(Main.warpsConfig.getString("warps." + args[0] + ".world"));
- final double x = Main.warpsConfig.getDouble("warps." + args[0] + ".x");
- final double z = Main.warpsConfig.getDouble("warps." + args[0] + ".z");
- final double y = Main.warpsConfig.getDouble("warps." + args[0] + ".y");
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Stop moving, you will be teleported in 3 seconds!");
- delay.add(p.getName());
- new BukkitRunnable() {
- public void run() {
- if(delay.contains(p.getName())) {
- p.teleport(new Location(w, x, y, z));
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Teleported successfully!");
- delay.remove(p.getName());
- }
- }
- }.runTaskLater(Main.getPlugin(), 2 * 20);
- return true;
- } else {
- p.sendMessage(ChatColor.RED + "You may not warp!");
- return true;
- }
- }
- if(label.equalsIgnoreCase("delwarp")) {
- if(p.hasPermission("experiencepvp.warp.delwarp")) {
- if(args.length == 0) {
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "You must specify a warp name!");
- return true;
- }
- if(Main.warpsConfig.getConfigurationSection("warps." + args[0]) == null) {
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " does not exist!");
- return true;
- }
- Main.warpsConfig.set("warps." + args[0], null);
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " has been successfully deleted!");
- Main.saveNewConfig();
- }
- } else {
- p.sendMessage(ChatColor.RED + "You may not warp!");
- }
- }
- return true;
- }
- @EventHandler
- public void onMove(PlayerMoveEvent e) {
- Player p = e.getPlayer();
- if(delay.contains(p.getName())) {
- if(e.getFrom().getX() != e.getTo().getX() || e.getFrom().getY() != e.getTo().getY() || e.getFrom().getZ() != e.getTo().getZ()) {
- delay.remove(p.getName()) ;
- p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "You moved, so you wont get teleported!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement