Development Assistance How to get the color of a banner?

Discussion in 'Plugin Help/Development/Requests' started by zlToxicNetherlz, Jun 23, 2015.

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

    zlToxicNetherlz

    Please ignore my spelling mistakes , the used translator.

    I tried to get the color of the flag,I've done this with: " DyeColor color = ((BannerMeta)e.getClickedBlock().getState()).getBaseColor(); " but I can still make it work.

    My code:
    Code:
    public void onPlayerInteract(PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            if(e.getClickedBlock().getType() == Material.STANDING_BANNER) {
                DyeColor color = ((BannerMeta)e.getClickedBlock().getState()).getBaseColor(); /* < ERROR */
                if(color == DyeColor.BLUE) /* < ERROR */
                {
                    Block sb = e.getClickedBlock();
                    ItemStack B1 = new ItemStack(Material.BANNER);
                    BannerMeta B1M = (BannerMeta)B1.getItemMeta();
                    B1M.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Black");
                    B1M.setBaseColor(DyeColor.BLUE);
                    B1.setItemMeta(B1M);
                    final ArmorStand stand = p.getWorld().spawn(p.getLocation(), ArmorStand.class);
                    stand.setBasePlate(false);  
                    stand.setVisible(false);
                    stand.setGravity(false);
                    stand.setArms(false);
                    stand.setRemoveWhenFarAway(false);
                    stand.setCustomNameVisible(true);
                    stand.setHelmet(B1);
                    sb.setType(Material.AIR);
                    p.sendMessage(ChatColor.BLUE + " Flag in your head! ");
                    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                        public void run() {
                            Location standloc = p.getLocation();
                            int x = standloc.getBlockX();
                            int y = standloc.getBlockY();
                            int z = standloc.getBlockZ();
                            Location standlocnew = new Location(p.getWorld(), x + 0.5, y, z + 0.5);
                            standlocnew.setYaw(p.getLocation().getYaw());
                            standlocnew.setPitch(p.getLocation().getPitch());
                            stand.setCustomName(ChatColor.BLUE + " Blue Flag ");
                            stand.teleport(standlocnew);
                           
                        }
                    }, (long) (0.1), (long) (0.1));
                }
                else {
                    p.sendMessage(ChatColor.RED + " Its your flag! ");
                }
              }
               
           
        }
     
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    Boomer

    What exactly is the stacktrace error that idenfies that line? Null Pointer Exception? Index out of Bounds? Unable to cast object error?
     
  4. Offline

    zlToxicNetherlz

    @Boomer
    I did not want to refer to that line is wrong.
    The line does not throw any errors , but running the event in the game. The error is generated
    I changed the code a bit , but still does not work ...
    I will show my throwing error by clicking on the banner.
    My new code:
    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            if(e.getClickedBlock().getType() == Material.STANDING_BANNER) {
                    Block sb = e.getClickedBlock();
                    BannerMeta B1B = (BannerMeta)sb.getState();
                    if(B1B.getBaseColor() == DyeColor.BLUE) {
                         ItemStack B1 = new ItemStack(Material.BANNER);
                            BannerMeta B1M = (BannerMeta)B1.getItemMeta();
                            B1M.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "Black");
                            B1M.setBaseColor(DyeColor.BLUE);
                            B1.setItemMeta(B1M);
                            final ArmorStand stand = p.getWorld().spawn(p.getLocation(), ArmorStand.class);
                            stand.setBasePlate(false); 
                            stand.setVisible(true);
                            stand.setGravity(false);
                            stand.setArms(false);
                            stand.setRemoveWhenFarAway(false);
                            stand.setCustomNameVisible(true);
                            stand.setHelmet(B1);
                            sb.setType(Material.AIR);
                            p.sendMessage(ChatColor.BLUE + " Flag in your head! ");
                            getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                                public void run() {
                                    Location standloc = p.getLocation();
                                    int x = standloc.getBlockX();
                                    int y = standloc.getBlockY();
                                    int z = standloc.getBlockZ();
                                    Location standlocnew = new Location(p.getWorld(), x + 0.5, y, z + 0.5);
                                    standlocnew.setYaw(p.getLocation().getYaw());
                                    standlocnew.setPitch(p.getLocation().getPitch());
                                    stand.setCustomName(ChatColor.BLUE + " Blue Flag ");
                                    stand.teleport(standlocnew);
                                  
                                }
                            }, (long) (0.1), (long) (0.1));
                    }
                    else {
                        p.sendMessage(ChatColor.RED + " Its your flag! ");
                }
              
              
              }
              
          
        }
    Error:

    Code:
    [22:04:51 ERROR]: Could not pass event PlayerInteractEvent to BannerToHead v2.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:305) ~[Virus.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[Virus.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:226) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInt
    eractManager.java:463) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :724) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:50) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:80) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [Vir
    us.jar:git-Spigot-c3c767f-33d5de3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.7.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_45]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [Virus.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_45]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R1.block.Cr
    aftBanner cannot be cast to org.bukkit.inventory.meta.BannerMeta
            at b.h.MainClass.onPlayerInteract(MainClass.java:35) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _45]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _45]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_45]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:301) ~[Virus.jar:git-Spigot-c3c767f-33d5de3]
            ... 16 more
     
    Last edited: Jun 23, 2015
  5. Offline

    xTrollxDudex

    Wrong import
     
Thread Status:
Not open for further replies.

Share This Page