Facebook
From Silly Wolf, 8 Years ago, written in Java.
This paste is a reply to Kamilkime je na obiad obsa XD from Cactus100 - view diff
Embed
Download Paste or View Raw
Hits: 730
  1. package de.makrede.randomtp;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.Server;
  10. import org.bukkit.World;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.block.Action;
  16. import org.bukkit.event.player.PlayerInteractEvent;
  17. import org.bukkit.plugin.PluginManager;
  18. import org.bukkit.plugin.java.JavaPlugin;
  19.  
  20. public class Main extends JavaPlugin implements Listener{
  21.  
  22.   public void onEnable(){
  23.     getServer().getPluginManager().registerEvents(this, this);
  24.   }
  25.  
  26.   public List<Player> getPlayersInRadius(Location location, int size){
  27.     List<Player> players = new ArrayList();
  28.     for (Player p : location.getWorld().getPlayers()) {
  29.       if (location.distance(p.getLocation()) <= size) {
  30.         players.add(p);
  31.       }
  32.     }
  33.     return players;
  34.   }
  35.  
  36.   @EventHandler
  37.   public void onInteract(PlayerInteractEvent e){
  38.     if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.STONE_BUTTON)){
  39.       Location block = e.getClickedBlock().getLocation().add(1.0D, 0.0D, 0.0D);
  40.       Location block1 = e.getClickedBlock().getLocation().add(-1.0D, 0.0D, 0.0D);
  41.       Location block2 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, 1.0D);
  42.       Location block3 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, -1.0D);
  43.       if ((block.getBlock().getType() == Material.BEDROCK) || (block1.getBlock().getType() == Material.BEDROCK) || (block2.getBlock().getType() == Material.BEDROCK) || (block3.getBlock().getType() == Material.BEDROCK)) {
  44.         for (Player p : getPlayersInRadius(e.getClickedBlock().getLocation(), 5)){
  45.           Random rand = new Random();
  46.           double x = rand.nextDouble() * 10000.0D - 5000.0D;
  47.           double z = rand.nextDouble() * 10000.0D - 5000.0D;
  48.           Location loc = new Location(e.getPlayer().getWorld(), x, e.getPlayer().getWorld().getHighestBlockYAt((int)x, (int)z), z);
  49.           e.getPlayer().teleport(loc);
  50.           Location ploc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ());
  51.           ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  52.           e.getPlayer().teleport(ploc);
  53.           p.teleport(e.getPlayer().getLocation());
  54.           p.sendMessage(ChatColor.GOLD + "[LastCraft] Przeteleportowano w losowe koordynaty! ");
  55.         }
  56.       }
  57.       if ((block.getBlock().getType() == Material.SPONGE) || (block1.getBlock().getType() == Material.SPONGE) || (block2.getBlock().getType() == Material.SPONGE) || (block3.getBlock().getType() == Material.SPONGE)){
  58.         Random rand = new Random();
  59.         double x = rand.nextDouble() * 10000.0D - 5000.0D;
  60.         double z = rand.nextDouble() * 10000.0D - 5000.0D;
  61.         Location loc = new Location(e.getPlayer().getWorld(), x, e.getPlayer().getWorld().getHighestBlockYAt((int)x, (int)z), z);
  62.         e.getPlayer().teleport(loc);
  63.         Location ploc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ());
  64.         ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
  65.         e.getPlayer().teleport(ploc);
  66.         e.getPlayer().sendMessage(ChatColor.GOLD + "[LastCraft] Przeteleportowano w losowe koordynaty!");
  67.       }
  68.     }
  69.   }
  70. }
  71.