Wither skull just blows up when spawned.

Discussion in 'Plugin Development' started by ChipDev, Jul 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ChipDev

    Hey guys, today I'm finishing up my friends plugin and I need one more help thing.
    onCommand doesn't trigger at all, and when i add a } after the other stuff before onCommand there is a error, Im stuck!
    Code:java
    1. package com.chip;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.util.Vector;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Item;
    9. import org.bukkit.entity.Pig;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.entity.Sheep;
    12. import org.bukkit.entity.WitherSkull;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.BlockBreakEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import org.bukkit.ChatColor;
    19. import org.bukkit.DyeColor;
    20. import org.bukkit.Location;
    21. import org.bukkit.Material;
    22.  
    23.  
    24. public class BlaukBlood extends JavaPlugin implements Listener {
    25. @Override
    26. public void onEnable() {
    27. getServer().getPluginManager().registerEvents(this, this);
    28. }
    29. public double getRandomDouble(double min, double max){
    30. Random r = new Random();
    31. double randomDouble = r.nextDouble();
    32. double result = min + (max - min) * randomDouble;
    33. return result;
    34. }
    35. @EventHandler
    36. public void onBlockBreak(BlockBreakEvent e) {
    37. if(e.getBlock().getType() == Material.REDSTONE_BLOCK) {
    38. for(int i=0; i<10; i++) {
    39. double random = getRandomDouble(-5.0, 5.0);
    40. double random2 = getRandomDouble(-5.0, 5.0);
    41. double random3 = getRandomDouble(-5.0, 5.0);
    42. Pig pig = e.getBlock().getWorld().spawn(e.getBlock().getLocation(), Pig.class);
    43. pig.setVelocity(new Vector(random, random2, random3));
    44. pig.setBaby();
    45. pig.setCustomName("Bobpig");
    46. pig.setCustomNameVisible(true);
    47. }
    48. }
    49. if(e.getBlock().getType() == Material.EMERALD_BLOCK ) {
    50. double random = getRandomDouble(-5.0, 5.0);
    51. double random2 = getRandomDouble(-5.0, 5.0);
    52. double random3 = getRandomDouble(-5.0, 5.0);
    53. Pig pig = e.getBlock().getWorld().spawn(e.getBlock().getLocation(), Pig.class);
    54. pig.setVelocity(new Vector(random, random2, random3));
    55. pig.setAdult();
    56. pig.setPassenger(e.getPlayer());
    57. pig.setCustomName(ChatColor.GREEN + "Fat Bobpig.");
    58. pig.setCustomNameVisible(true);
    59. }
    60. if(e.getBlock().getType() == Material.LAPIS_BLOCK) {
    61. double random = getRandomDouble(-5.0, 5.0);
    62. double random2 = getRandomDouble(-5.0, 5.0);
    63. double random3 = getRandomDouble(-5.0, 5.0);
    64. Sheep pig = e.getBlock().getWorld().spawn(e.getBlock().getLocation(), Sheep.class);
    65. pig.setVelocity(new Vector(random, random2, random3));
    66. pig.setAdult();
    67. pig.setPassenger(e.getPlayer());
    68. pig.setCustomName(ChatColor.RED + "" + ChatColor.BOLD + "...?");
    69. pig.setCustomNameVisible(true);
    70. pig.setColor(DyeColor.PINK);
    71. }
    72. }
    73. public void createEmeraldBlock(Location loc, Player player) {
    74. WitherSkull skull = player.getWorld().spawn(loc, WitherSkull.class);
    75. Item item = player.getWorld().spawn(loc, Item.class);
    76. item.setItemStack(new ItemStack(Material.EMERALD_BLOCK));
    77. skull.setVelocity(new Vector(0, 0, 0));
    78. skull.setPassenger(item);
    79. player.sendMessage(ChatColor.GOLD + "Items" + ChatColor.GRAY + "ยป" + ChatColor.DARK_AQUA + " Summoned emerald!");
    80. }
    81. public boolean onCommand(CommandSender sender, Command cmd, String[] args) {
    82. if(cmd.getName().equalsIgnoreCase("//FloatingEmeraldBlock")) {
    83. Player player = (Player) sender;
    84. createEmeraldBlock(player.getLocation().add(0, 2, 0), player);
    85. }
    86. return true;
    87. }
    88. }

    Anyone know why?
    Thanks! :D
     
  2. Offline

    xize

    ChipDev

    do you have put /FloatingEmeraldBlock in your plugin.yml? with that single slash? (not sure if it works with that slash though, normally if you plan to make such commands I recommend to use PlayerCommandPreProcessEvent from nature cmd.getName() already detects the first slash and in your plugin.yml you don't need to define a slash unless you have the case you want double slashes:p.
     
  3. Offline

    Maved

    ChipDev
    add @Override above your public boolean onCommand. Can't see any other reasons why it wouldn't work.
     
  4. Offline

    ChipDev

    Ok, thanks.
    Yes, i use //createemeraldblock in plugin.yml so it's triple slashes xD

    Maved
    It gives:
    The method onCommand(CommandSender, Command, String[]) of type BlaukBlood must override a superclass method

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    lzravanger

    I believe the syntax is now
    Code:java
    1. public void onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args);
     
  6. Offline

    ZodiacTheories

    ChipDev

    Putting @Override above it will do absolutely nothing
     
  7. Offline

    Flamedek

    ChipDev You missed String commandLabel in the onCommand method.
     
  8. Offline

    ChipDev

    Yep :)

    Guys, my wither skull just blows up :/
    also, Internal error while preforming this command.
    error:
    Code:
    29.07 09:32:53 [Server] INFO ... 13 more
    29.07 09:32:53 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at com.chip.BlaukBlood.onCommand(BlaukBlood.java:85) ~[?:?]
    29.07 09:32:53 [Server] INFO at com.chip.BlaukBlood.createEmeraldBlock(BlaukBlood.java:75) ~[?:?]
    29.07 09:32:53 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.CraftWorld.spawn(CraftWorld.java:833) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.CraftWorld.spawn(CraftWorld.java:1072) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bukkit.entity.Item
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    29.07 09:32:53 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command '//floatingemeraldblock' in plugin BlaukBlood v1.0
    29.07 09:32:53 [Server] ERROR null


    Changed name to new problem :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    DevRosemberg

    ChipDev Maybe

    Code:java
    1. WitherSkull skull = (WitherSkull) player.launchProjectile(WitherSkull.class);
    2. skull.setDirection(player.getLocation().getDirection());
     
  10. Offline

    ChipDev

    No, I just want a invisible wither skull so I can have the floating item :p

    So heres the problem: I get a internal error, and It doesn't have a emerald block on top :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page