Advertisement
Guest User

Warps.java

a guest
Aug 11th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.55 KB | None | 0 0
  1. package me.iamguus.experiencepvp.warps;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import me.iamguus.experiencepvp.Main;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.Location;
  10. import org.bukkit.World;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandExecutor;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.EventHandler;
  16. import org.bukkit.event.Listener;
  17. import org.bukkit.event.player.PlayerMoveEvent;
  18. import org.bukkit.scheduler.BukkitRunnable;
  19.  
  20. public class Warps implements Listener, CommandExecutor{
  21.  
  22.     ArrayList<String> delay = new ArrayList<String>();
  23.    
  24.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  25.         if(sender instanceof Player) {
  26.             final Player p = (Player) sender;
  27.             if(label.equalsIgnoreCase("setwarp")) {
  28.                 if(p.hasPermission("experiencepvp.warps.setwarp")) {
  29.                     if(args.length == 0) {
  30.                         p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "You must specify a warp name!");
  31.                         return true;
  32.                     }
  33.                     Main.warpsConfig.set("warps." + args[0] + ".world", p.getLocation().getWorld().getName());
  34.                     Main.warpsConfig.set("warps." + args[0] + ".x", p.getLocation().getX());
  35.                     Main.warpsConfig.set("warps." + args[0] + ".y", p.getLocation().getY());
  36.                     Main.warpsConfig.set("warps." + args[0] + ".z", p.getLocation().getZ());
  37.                     Main.warpsConfig.set("warps." + args[0] + ".yaw", p.getLocation().getYaw());
  38.                     Main.warpsConfig.set("warps." + args[0] + ".pitch", p.getLocation().getPitch());
  39.                     Main.saveNewConfig();
  40.                     p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " has been set at your location!");
  41.                 } else {
  42.                     p.sendMessage("You may not run this command!");
  43.                 }
  44.             }
  45.                
  46.                 if(label.equalsIgnoreCase("warp")) {
  47.                     if(p.hasPermission("experiencepvp.warps.warp")) {
  48.                         if(args.length == 0) {
  49.                             p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warps: " + Main.warpsConfig.getConfigurationSection("warps").getKeys(false));
  50.                             return true;
  51.                         }
  52.                         if(Main.warpsConfig.getConfigurationSection("warps." + args[0] + "") == null) {
  53.                             p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "Warp " + args[0] + " does not exist!");
  54.                             return true;
  55.                         }
  56.                         final World w = Bukkit.getServer().getWorld(Main.warpsConfig.getString("warps." + args[0] + ".world"));
  57.                         final double x = Main.warpsConfig.getDouble("warps." + args[0] + ".x");
  58.                         final double z = Main.warpsConfig.getDouble("warps." + args[0] + ".z");
  59.                         final double y = Main.warpsConfig.getDouble("warps." + args[0] + ".y");
  60.                         p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Stop moving, you will be teleported in 3 seconds!");
  61.                         delay.add(p.getName());
  62.                         new BukkitRunnable() {
  63.                            
  64.                             public void run() {
  65.                                 if(delay.contains(p.getName())) {
  66.                                     p.teleport(new Location(w, x, y, z));
  67.                                     p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Teleported successfully!");
  68.                                     delay.remove(p.getName());
  69.                                 }
  70.                             }
  71.                         }.runTaskLater(Main.getPlugin(), 2 * 20);
  72.                         return true;
  73.                     } else {
  74.                         p.sendMessage(ChatColor.RED + "You may not warp!");
  75.                         return true;
  76.                     }
  77.                 }
  78.                 if(label.equalsIgnoreCase("delwarp")) {
  79.                     if(p.hasPermission("experiencepvp.warp.delwarp")) {
  80.                         if(args.length == 0) {
  81.                             p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.RED + "You must specify a warp name!");
  82.                             return true;
  83.                         }
  84.                         if(Main.warpsConfig.getConfigurationSection("warps." + args[0]) == null) {
  85.                             p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " does not exist!");
  86.                             return true;
  87.                         }
  88.                         Main.warpsConfig.set("warps." + args[0], null);
  89.                         p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Warp " + args[0] + " has been successfully deleted!");
  90.                         Main.saveNewConfig();
  91.                     }
  92.                 } else {
  93.                     p.sendMessage(ChatColor.RED + "You may not warp!");
  94.                 }
  95.             }
  96.         return true;
  97.     }
  98.     @EventHandler
  99.     public void onMove(PlayerMoveEvent e) {
  100.         Player p = e.getPlayer();
  101.         if(delay.contains(p.getName())) {
  102.             if(e.getFrom().getX() != e.getTo().getX() || e.getFrom().getY() != e.getTo().getY() || e.getFrom().getZ() != e.getTo().getZ()) {
  103.                 delay.remove(p.getName()) ;
  104.                 p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "You moved, so you wont get teleported!");
  105.             }
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement