Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4411

Shulker entities are Colorable but getColor() returns null on default entity

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-f6a273b-02518f9 (MC: 1.13.1) (Implementing API version 1.13.1-R0.1-SNAPSHOT)
    • Yes

      The Shulker LivingEntity is Colorable but getColor() returns null on any Shulker that has just been spawned, i.e., it has the default purple color. After dying the shulker, getColor() will return a non-null correct dye color.

      https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Shulker.html

      Demo plugin source and binary attached. To test, go into creative and spawn a Shulker with a spawn egg. The code is this:

       

          @Override
          public void onEnable() {
              getServer().getPluginManager().registerEvents(this, this);
          }
      
      
          @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
          public void onEntitySpawn(EntitySpawnEvent e) {
              if (e.getEntityType().equals(EntityType.SHULKER)) {
                  getLogger().info("Shulker spawned");
                  if (e.getEntity() instanceof Colorable) {
                      Colorable c = (Colorable)e.getEntity();
                      getLogger().info("Entity is colorable");
                      if (c.getColor() != null) {
                          getLogger().info("Color name obtained successfully = " + c.getColor().name());
                      } else {
                          getLogger().severe("getColor is null!");
                      }
                      // Set color
                      c.setColor(DyeColor.GREEN);
                      if (c.getColor() != null) {
                          getLogger().info("Color name obtained successfully after dying = " + c.getColor().name());
                      } else {
                          getLogger().severe("getColor is null after dying!");
                      }
                  }
              }
          }
      

      Thanks!

       

            Unassigned Unassigned
            tastybento tastybento
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: