Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.09 KB | None | 0 0
  1. package mc.dragopl.randomtp;
  2.  
  3. import java.util.Random;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.Server;
  7. import org.bukkit.World;
  8. import org.bukkit.block.Biome;
  9. import org.bukkit.block.Block;
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.block.Action;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.plugin.PluginManager;
  17. import org.bukkit.plugin.java.JavaPlugin;
  18.  
  19. public class TeleportPlugin
  20.   extends JavaPlugin
  21.   implements Listener
  22. {
  23.   public void onEnable()
  24.   {
  25.     getServer().getPluginManager().registerEvents(this, this);
  26.     saveDefaultConfig();
  27.   }
  28.  
  29.   @EventHandler
  30.   public void PPM(PlayerInteractEvent e)
  31.   {
  32.     Player p = e.getPlayer();
  33.     if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) &&
  34.       (e.getClickedBlock().getType() == Material.STONE_BUTTON))
  35.     {
  36.       Location c1 = e.getClickedBlock().getLocation().add(1.0D, 0.0D, 0.0D);
  37.       Location c2 = e.getClickedBlock().getLocation().add(-1.0D, 0.0D, 0.0D);
  38.       Location c3 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, 1.0D);
  39.       Location c4 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, -1.0D);
  40.       if (c1.getBlock().getType() == Material.SPONGE)
  41.       {
  42.         Random r = new Random();
  43.         double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  44.         double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  45.         Location loc = new Location(e.getPlayer().getWorld(), x, p
  46.           .getWorld().getHighestBlockYAt((int)x, (int)z), z);
  47.         if (loc.getBlock().getBiome() == Biome.OCEAN)
  48.         {
  49.           p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
  50.         }
  51.         else if (loc.getBlock().getBiome() == Biome.RIVER)
  52.         {
  53.           p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
  54.         }
  55.         else
  56.         {
  57.           p.teleport(loc);
  58.           Location ploc = new Location(p.getWorld(), p.getLocation()
  59.             .getX(), p.getLocation().getY(), p.getLocation()
  60.             .getZ());
  61.           ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  62.           p.teleport(ploc);
  63.           p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
  64.         }
  65.       }
  66.       if (c2.getBlock().getType() == Material.SPONGE)
  67.       {
  68.         Random r = new Random();
  69.         double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  70.         double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  71.         Location loc = new Location(e.getPlayer().getWorld(), x, p
  72.           .getWorld().getHighestBlockYAt((int)x, (int)z), z);
  73.         if (loc.getBlock().getBiome() == Biome.OCEAN)
  74.         {
  75.           p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
  76.         }
  77.         else if (loc.getBlock().getBiome() == Biome.RIVER)
  78.         {
  79.           p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
  80.         }
  81.         else
  82.         {
  83.           p.teleport(loc);
  84.           Location ploc = new Location(p.getWorld(), p.getLocation()
  85.             .getX(), p.getLocation().getY(), p.getLocation()
  86.             .getZ());
  87.           ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  88.           p.teleport(ploc);
  89.           p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
  90.         }
  91.       }
  92.       if (c3.getBlock().getType() == Material.SPONGE)
  93.       {
  94.         Random r = new Random();
  95.         double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  96.         double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  97.         Location loc = new Location(e.getPlayer().getWorld(), x, p
  98.           .getWorld().getHighestBlockYAt((int)x, (int)z), z);
  99.         if (loc.getBlock().getBiome() == Biome.OCEAN)
  100.         {
  101.           p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
  102.         }
  103.         else if (loc.getBlock().getBiome() == Biome.RIVER)
  104.         {
  105.           p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
  106.         }
  107.         else
  108.         {
  109.           p.teleport(loc);
  110.           Location ploc = new Location(p.getWorld(), p.getLocation()
  111.             .getX(), p.getLocation().getY(), p.getLocation()
  112.             .getZ());
  113.           ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  114.           p.teleport(ploc);
  115.           p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
  116.         }
  117.       }
  118.       if (c4.getBlock().getType() == Material.SPONGE)
  119.       {
  120.         Random r = new Random();
  121.         double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  122.         double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
  123.         Location loc = new Location(e.getPlayer().getWorld(), x, p
  124.           .getWorld().getHighestBlockYAt((int)x, (int)z), z);
  125.         if (loc.getBlock().getBiome() == Biome.OCEAN)
  126.         {
  127.           p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
  128.         }
  129.         else if (loc.getBlock().getBiome() == Biome.RIVER)
  130.         {
  131.           p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
  132.         }
  133.         else
  134.         {
  135.           p.teleport(loc);
  136.           Location ploc = new Location(p.getWorld(), p.getLocation()
  137.             .getX(), p.getLocation().getY(), p.getLocation()
  138.             .getZ());
  139.           ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  140.           p.teleport(ploc);
  141.           p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
  142.         }
  143.       }
  144.     }
  145.   }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement