Facebook
From Silly Wolf, 8 Years ago, written in Java.
This paste is a reply to Kamilkime je na obiad obsa XD from Cactus100 - go back
Embed
package de.makrede.randomtp;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin implements Listener{

  public void onEnable(){
    getServer().getPluginManager().registerEvents(this, this);
  }
  
  public List getPlayersInRadius(Location location, int size){
    List players = new ArrayList();
    for (Player p : location.getWorld().getPlayers()) {
      if (location.distance(p.getLocation()) <= size) {
        players.add(p);
      }
    }
    return players;
  }
  
  @EventHandler
  public void onInteract(PlayerInteractEvent e){
    if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.STONE_BUTTON)){
      Location block = e.getClickedBlock().getLocation().add(1.0D, 0.0D, 0.0D);
      Location block1 = e.getClickedBlock().getLocation().add(-1.0D, 0.0D, 0.0D);
      Location block2 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, 1.0D);
      Location block3 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, -1.0D);
      if ((block.getBlock().getType() == Material.BEDROCK) || (block1.getBlock().getType() == Material.BEDROCK) || (block2.getBlock().getType() == Material.BEDROCK) || (block3.getBlock().getType() == Material.BEDROCK)) {
        for (Player p : getPlayersInRadius(e.getClickedBlock().getLocation(), 5)){
          Random rand = new Random();
          double x = rand.nextDouble() * 10000.0D - 5000.0D;
          double z = rand.nextDouble() * 10000.0D - 5000.0D;
          Location loc = new Location(e.getPlayer().getWorld(), x, e.getPlayer().getWorld().getHighestBlockYAt((int)x, (int)z), z);
          e.getPlayer().teleport(loc);
          Location ploc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ());
          ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
          e.getPlayer().teleport(ploc);
          p.teleport(e.getPlayer().getLocation());
          p.sendMessage(ChatColor.GOLD + "[LastCraft] Przeteleportowano w losowe koordynaty! ");
        }
      }
      if ((block.getBlock().getType() == Material.SPONGE) || (block1.getBlock().getType() == Material.SPONGE) || (block2.getBlock().getType() == Material.SPONGE) || (block3.getBlock().getType() == Material.SPONGE)){
        Random rand = new Random();
        double x = rand.nextDouble() * 10000.0D - 5000.0D;
        double z = rand.nextDouble() * 10000.0D - 5000.0D;
        Location loc = new Location(e.getPlayer().getWorld(), x, e.getPlayer().getWorld().getHighestBlockYAt((int)x, (int)z), z);
        e.getPlayer().teleport(loc);
        Location ploc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ());
        ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
        e.getPlayer().teleport(ploc);
        e.getPlayer().sendMessage(ChatColor.GOLD + "[LastCraft] Przeteleportowano w losowe koordynaty!");
      }
    }
  }
}