Jump to content

Pferd + Spielersystem


615Power
 Share

Recommended Posts

In meinem Mingame bekommen Leute einen Sattel, und wenn sie damit einen Rechtsklick machen, spawnt ein Pferd und der Spieler wird draufgesetzt. Wenn man nun das Pferd verlässt (L-Shift) wird das Pferd gelöscht. Dadurch sind im Spiel nie freilaufene Pferde, aber Spieler können reiten. Nur bekomme ich eine Fehlermeldung. Zeige mal den Code, wie ich es mir gedacht habe. Ginge sicherlich einfacher....


	@EventHandler

	public void onInteract(PlayerInteractEvent e) {

		    ItemStack schild = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);

		    ItemMeta schildm = schild.getItemMeta();

		    schildm.setDisplayName("?6?oSchild");

		    schildm.setLore(Arrays.asList("?7Auswählen um 50% weniger Schaden zu bekommen"));

		    schild.setItemMeta(schildm);


		if (e.getItem().isSimilar(schild)) {

			e.setCancelled(true);

		} else {

			Player p = e.getPlayer();

			if (MainClass.players.containsKey(p.getName())) {

    			if (MainClass.players.get(p.getName()) == 7) {


    			    ItemStack horse = new ItemStack(Material.SADDLE);

    			    ItemMeta horsem = horse.getItemMeta();

    			    horsem.setDisplayName("?cPferd");

    			    horsem.setLore(Arrays.asList("?7Rechtsklick um auf Pferd zu steigen"));

    			    horse.setItemMeta(horsem);

    			    if (e.getItem().isSimilar(horse)) {

    			    	if (e.getAction().equals(Action.RIGHT_CLICK_AIR) ||(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {



    			    		for (Entity e1 : e.getPlayer().getWorld().getEntities()) {

    			    			   if (e1 instanceof Horse) {

    			    				   if (e1.hasMetadata(e.getPlayer().getName() + "horse")) {

    			    					   MyHorse = e1;

    			    					   horse1 = true;


    			    			   } else {

    			    			   }


    			    			}

    			    		}

    			    		if (horse1 =  false) {

    			    			Entity entity = p.getWorld().spawnEntity(p.getLocation(), EntityType.HORSE);

    			    			entity.setMetadata(p.getName() + "horse", new FixedMetadataValue(MainClass.getMainClass(), Horse.class));

    			    			Horse hentity = (Horse) entity;

    			    			hentity.setPassenger(p);

    			    			hentity.setColor(Color.BROWN);

    			    		}

    			    		else if (horse1 = true) {

    			    			if (MyHorse.getPassenger() == null) {

    			    				MyHorse.setPassenger(p);


    			    		}


    			    	}


    			    }

    			}

    			}


		    ItemStack horse = new ItemStack(Material.SADDLE);

		    ItemMeta horsem = horse.getItemMeta();

		    horsem.setDisplayName("?cPferd");

		    horsem.setLore(Arrays.asList("?7Rechtsklick um auf Pferd zu steigen"));

		    horse.setItemMeta(horsem);

		}

		}

	}

Jetzt bekomme ich folgenden Fehler:


[14:17:41] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KitPvPPlus v0.1

org.bukkit.event.EventException

 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-47b1dff-f233e7d]

 at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-47b1dff-f233e7d]

 at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:459) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:724) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]

 at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]

 at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-47b1dff-f233e7d]

 at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]

Caused by: java.lang.NullPointerException

 at de.mpgc.listener.KnightKit.onInteract(KnightKit.java:111) ~[?:?]

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]

 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]

 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-47b1dff-f233e7d]

 ... 16 more

In Zeile 111 steht folgendes:


if (MyHorse.getPassenger() == null) {

Wo liegt der Fehler jetzt genau. Dort wird nur abgefragt ob das Pferd einen Reiter hat. Dabei kann so ein Pferd gar nicht existieren. Da es noch gar nicht gespawnt wurde :(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...
B
B