hallo alle zusammen
ich wollte ein bukkit plugin proggen mitdem man wenn ein knopf gedrückt wird in eine lore teleportiert wird die vorher auf schienen gesetzt wurde
hat jemand ne idee wie das geht?
danke im vorraus!
TheCreeper202X

Edit: (03.01.2013 um 12:20)

So viel code hab ich fertig:
Code:
package de.creeperfans.achterbahn;

import net.minecraft.server.v1_4_6.EntityMinecart;
import net.minecraft.server.v1_4_6.MinecraftServer;
import net.minecraft.server.v1_4_6.WorldServer;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
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.java.JavaPlugin;

public class Achterbahn extends JavaPlugin implements Listener {

	private Location locBase;
	private Location locTP;
	private Location locButton;
	private boolean settedBase;
	private boolean settedTP;
	private boolean settedButton;
	
	public void onEnable() {
		this.getServer().getPluginManager().registerEvents(this, this);
		setDefaults();
		loadBase();
		loadTP();
		loadButton();
		this.getConfig().options().copyDefaults(true);
		this.saveConfig();
		System.out.println("[Achterbahn] Plugin aktiviert!");
	}
	
	public void onDisable() {
		saveBase();
		saveTP();
		saveButton();
		this.saveConfig();
		System.out.println("[Achterbahn] Plugin deaktiviert!");
	}

	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (cmd.getName().equalsIgnoreCase("achterbahn")) {
			if (sender instanceof Player) {
				Player p = (Player) sender;
				String subCmd = "";
				try {
					subCmd = args[0];
				} catch (ArrayIndexOutOfBoundsException ex) {
					p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Commands:");
					if (p.hasPermission("achterbahn.admin")) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Set the TP location: /achterbahn settp");
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Set the rail location: /achterbahn setrail");
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Set the button location: /achterbahn setbutton");
					}
					p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Teleport: /achterbahn tp");
					return true;
				}
				if (subCmd.equalsIgnoreCase("settp")) {
					if (!p.hasPermission("achterbahn.admin")) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "You don't have permissions to do that!");
						return true;
					}
					locTP = p.getLocation();
					settedTP = true;
					p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "TP setted!");
					return true;
				} else if (subCmd.equalsIgnoreCase("setbase")) {
					if (!p.hasPermission("achterbahn.admin")) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "You don't have permissions to do that!");
						return true;
					}
					locBase = p.getLocation();
					settedBase = true;
					p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Base setted!");
					return true;
				} else if (subCmd.equalsIgnoreCase("setbutton")) {
					if (!p.hasPermission("achterbahn.admin")) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "You don't have permissions to do that!");
						return true;
					}
					locButton = p.getLocation();
					settedButton = true;
					p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.GOLD + "Button setted!");
					return true;
				} else if (subCmd.equalsIgnoreCase("tp")) {
					if (!settedButton) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "Please set a button first!");
					} else if (!settedBase) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "Please set a base first!");
					} else if (!settedTP) {
						p.sendMessage(ChatColor.BLUE + "[Achterbahn] " + ChatColor.RED + "Please set a teleport first!");
					} else {
						p.teleport(locTP);
					}
					return true;
				}
			} else {
				sender.sendMessage(ChatColor.BLUE + "[Achterbahn]" + ChatColor.RED + "You can't use this command from the console!");
				return true;
			}
		}
		return false;
	}
	
	@Event Handler
	public void onPlayerInteract(PlayerInteractEvent event) {
		if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
			Block b = event.getClickedBlock();
			final Player p = event.getPlayer();
			if (b.getLocation().getBlockX() == locButton.getBlockX() && b.getLocation().getBlockY() == locButton.getBlockY() && b.getLocation().getBlockZ() == locButton.getBlockZ()) {
				MinecraftServer server = MinecraftServer.getServer();
				WorldServer theWorld = null;
				for (WorldServer world : server.worlds) {
					if (world.worldData.getName().equalsIgnoreCase(locBase.getWorld().getName())) {
						theWorld = world;
					}
				}
				if (theWorld != null) {
					EntityMinecart mc = new EntityMinecart(theWorld);
					mc.setLocation(locBase.getBlockX(), locBase.getBlockY(), locBase.getBlockZ(), 0, 0);
					theWorld.a(mc);
					locBase.getWorld().refreshChunk(locBase.getChunk().getX(), locBase.getChunk().getZ());
					p.teleport(new Location(locBase.getWorld(), locBase.getX() - 2, locBase.getY(), locBase.getZ(), locBase.getYaw(), locBase.getPitch()));
					mc.a(theWorld.a(p.getName()));
					theWorld.a(mc);
				}
			}
		}
	}
	
	private void setDefaults() {
		this.getConfig().addDefault("config.tp.x", 0.0D);
		this.getConfig().addDefault("config.tp.y", 0.0D);
		this.getConfig().addDefault("config.tp.z", 0.0D);
		this.getConfig().addDefault("config.tp.yaw", 0.0F);
		this.getConfig().addDefault("config.tp.pitch", 0.0F);
		this.getConfig().addDefault("config.tp.world", "world");
		this.getConfig().addDefault("config.tp.setted", false);
		this.getConfig().addDefault("config.base.x", 0.0D);
		this.getConfig().addDefault("config.base.y", 0.0D);
		this.getConfig().addDefault("config.base.z", 0.0D);
		this.getConfig().addDefault("config.base.yaw", 0.0F);
		this.getConfig().addDefault("config.base.pitch", 0.0F);
		this.getConfig().addDefault("config.base.world", "world");
		this.getConfig().addDefault("config.base.setted", false);
		this.getConfig().addDefault("config.button.x", 0.0D);
		this.getConfig().addDefault("config.button.y", 0.0D);
		this.getConfig().addDefault("config.button.z", 0.0D);
		this.getConfig().addDefault("config.button.yaw", 0.0F);
		this.getConfig().addDefault("config.button.pitch", 0.0F);
		this.getConfig().addDefault("config.button.world", "world");
		this.getConfig().addDefault("config.button.setted", false);
		this.getConfig().options().copyDefaults(true);
		this.saveConfig();
	}
	
	private void loadTP() {
		double x = this.getConfig().getDouble("config.tp.x");
		double y = this.getConfig().getDouble("config.tp.y");
		double z = this.getConfig().getDouble("config.tp.z");
		double yawD = this.getConfig().getDouble("config.tp.yaw");
		double pitchD = this.getConfig().getDouble("config.tp.pitch");
		String world = this.getConfig().getString("config.tp.world");
		boolean setted = this.getConfig().getBoolean("config.tp.setted");
		float yaw = Float.parseFloat(Double.toString(yawD));
		float pitch = Float.parseFloat(Double.toString(pitchD));
		locTP = new Location(this.getServer().getWorld(world), x, y, z, yaw, pitch);
		settedTP = setted;
	}

	private void loadBase() {
		double x = this.getConfig().getDouble("config.base.x");
		double y = this.getConfig().getDouble("config.base.y");
		double z = this.getConfig().getDouble("config.base.z");
		double yawD = this.getConfig().getDouble("config.base.yaw");
		double pitchD = this.getConfig().getDouble("config.base.pitch");
		String world = this.getConfig().getString("config.base.world");
		boolean setted = this.getConfig().getBoolean("config.base.setted");
		float yaw = Float.parseFloat(Double.toString(yawD));
		float pitch = Float.parseFloat(Double.toString(pitchD));
		locBase = new Location(this.getServer().getWorld(world), x, y, z, yaw, pitch);
		settedBase = setted;
	}
	
	private void loadButton() {
		double x = this.getConfig().getDouble("config.button.x");
		double y = this.getConfig().getDouble("config.button.y");
		double z = this.getConfig().getDouble("config.button.z");
		double yawD = this.getConfig().getDouble("config.button.yaw");
		double pitchD = this.getConfig().getDouble("config.button.pitch");
		String world = this.getConfig().getString("config.button.world");
		boolean setted = this.getConfig().getBoolean("config.button.setted");
		float yaw = Float.parseFloat(Double.toString(yawD));
		float pitch = Float.parseFloat(Double.toString(pitchD));
		locButton = new Location(this.getServer().getWorld(world), x, y, z, yaw, pitch);
		settedButton = setted;
	}
	
	private void saveTP() {
		this.getConfig().set("config.tp.x", locTP.getX());
		this.getConfig().set("config.tp.y", locTP.getY());
		this.getConfig().set("config.tp.z", locTP.getZ());
		this.getConfig().set("config.tp.yaw", locTP.getYaw());
		this.getConfig().set("config.tp.pitch", locTP.getPitch());
		this.getConfig().set("config.tp.world", locTP.getWorld().getName());
		this.getConfig().set("config.tp.setted", settedTP);
	}
	
	private void saveBase() {
		this.getConfig().set("config.base.x", locBase.getX());
		this.getConfig().set("config.base.y", locBase.getY());
		this.getConfig().set("config.base.z", locBase.getZ());
		this.getConfig().set("config.base.yaw", locBase.getYaw());
		this.getConfig().set("config.base.pitch", locBase.getPitch());
		this.getConfig().set("config.base.world", locBase.getWorld().getName());
		this.getConfig().set("config.base.setted", settedBase);
	}
	
	private void saveButton() {
		this.getConfig().set("config.button.x", locButton.getX());
		this.getConfig().set("config.button.y", locButton.getY());
		this.getConfig().set("config.button.z", locButton.getZ());
		this.getConfig().set("config.button.yaw", locButton.getYaw());
		this.getConfig().set("config.button.pitch", locButton.getPitch());
		this.getConfig().set("config.button.world", locButton.getWorld().getName());
		this.getConfig().set("config.button.setted", settedButton);
	}
	
}
aber beim ersten button klick lande ich x - 2 und nichts passiert weiter
beim zweiten mal is da ein "unsichtbares" minecart dass erst beim server restart sichtbar wird