Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mc.dragopl.randomtp;
- import java.util.Random;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.block.Biome;
- import org.bukkit.block.Block;
- import org.bukkit.configuration.file.FileConfiguration;
- 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 TeleportPlugin
- extends JavaPlugin
- implements Listener
- {
- public void onEnable()
- {
- getServer().getPluginManager().registerEvents(this, this);
- saveDefaultConfig();
- }
- @EventHandler
- public void PPM(PlayerInteractEvent e)
- {
- Player p = e.getPlayer();
- if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) &&
- (e.getClickedBlock().getType() == Material.STONE_BUTTON))
- {
- Location c1 = e.getClickedBlock().getLocation().add(1.0D, 0.0D, 0.0D);
- Location c2 = e.getClickedBlock().getLocation().add(-1.0D, 0.0D, 0.0D);
- Location c3 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, 1.0D);
- Location c4 = e.getClickedBlock().getLocation().add(0.0D, 0.0D, -1.0D);
- if (c1.getBlock().getType() == Material.SPONGE)
- {
- Random r = new Random();
- double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- Location loc = new Location(e.getPlayer().getWorld(), x, p
- .getWorld().getHighestBlockYAt((int)x, (int)z), z);
- if (loc.getBlock().getBiome() == Biome.OCEAN)
- {
- p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
- }
- else if (loc.getBlock().getBiome() == Biome.RIVER)
- {
- p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
- }
- else
- {
- p.teleport(loc);
- Location ploc = new Location(p.getWorld(), p.getLocation()
- .getX(), p.getLocation().getY(), p.getLocation()
- .getZ());
- ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
- p.teleport(ploc);
- p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
- }
- }
- if (c2.getBlock().getType() == Material.SPONGE)
- {
- Random r = new Random();
- double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- Location loc = new Location(e.getPlayer().getWorld(), x, p
- .getWorld().getHighestBlockYAt((int)x, (int)z), z);
- if (loc.getBlock().getBiome() == Biome.OCEAN)
- {
- p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
- }
- else if (loc.getBlock().getBiome() == Biome.RIVER)
- {
- p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
- }
- else
- {
- p.teleport(loc);
- Location ploc = new Location(p.getWorld(), p.getLocation()
- .getX(), p.getLocation().getY(), p.getLocation()
- .getZ());
- ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
- p.teleport(ploc);
- p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
- }
- }
- if (c3.getBlock().getType() == Material.SPONGE)
- {
- Random r = new Random();
- double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- Location loc = new Location(e.getPlayer().getWorld(), x, p
- .getWorld().getHighestBlockYAt((int)x, (int)z), z);
- if (loc.getBlock().getBiome() == Biome.OCEAN)
- {
- p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
- }
- else if (loc.getBlock().getBiome() == Biome.RIVER)
- {
- p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
- }
- else
- {
- p.teleport(loc);
- Location ploc = new Location(p.getWorld(), p.getLocation()
- .getX(), p.getLocation().getY(), p.getLocation()
- .getZ());
- ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
- p.teleport(ploc);
- p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
- }
- }
- if (c4.getBlock().getType() == Material.SPONGE)
- {
- Random r = new Random();
- double x = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- double z = r.nextDouble() * getConfig().getDouble("coordinates.max") - getConfig().getDouble("coordinates.min");
- Location loc = new Location(e.getPlayer().getWorld(), x, p
- .getWorld().getHighestBlockYAt((int)x, (int)z), z);
- if (loc.getBlock().getBiome() == Biome.OCEAN)
- {
- p.sendMessage(getConfig().getString("messages.ocean").replaceAll("&", "§"));
- }
- else if (loc.getBlock().getBiome() == Biome.RIVER)
- {
- p.sendMessage(getConfig().getString("messages.river").replaceAll("&", "§"));
- }
- else
- {
- p.teleport(loc);
- Location ploc = new Location(p.getWorld(), p.getLocation()
- .getX(), p.getLocation().getY(), p.getLocation()
- .getZ());
- ploc.setY(e.getPlayer().getLocation().getY() + 5.0D);
- p.teleport(ploc);
- p.sendMessage(getConfig().getString("messages.teleported").replaceAll("&", "§"));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement