1.11 Spigot Minigame update

Discussion in 'Spigot Plugin Development' started by Arcader2k, Apr 14, 2017.

  1. Hey there! I am currently working on building a Minigame plugin and I am having an issue while trying to update it. It has worked in the past, but since the updates came about, I can no longer get it to work.

    Here is a snippet of the error:
    Code (Text):

    public void sendAll(Player p, int fadeIn, int stay, int fadeOut, String title,
    String subtitle, String actionText, String header, String footer)
      {
      PlayerConnection playerConnection = p.getHandle().playerConnection;
      if ((title != null) && (subtitle != null))
      {
      PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle

    (PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut);
      playerConnection.sendPacket(packetPlayOutTimes);
      }
     
    The method getHandler() is undefined for the type Player
     
  2. #getHandle() is a method from the CraftPlayer class, not the Player class itself. Simply cast your Player variable to CraftPlayer and it should be available :)
     
  3. Heres my entire .class:
    Code (Text):

    package com.FrostFire;
    import java.lang.reflect.Field;
    import net.minecraft.server.v1_11_R1.IChatBaseComponent;
    import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
    import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerListHeaderFooter;
    import net.minecraft.server.v1_11_R1.PacketPlayOutTitle;
    import net.minecraft.server.v1_11_R1.PlayerConnection;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    public class Title
    {
      static Title plugin;
      public static Title am = new Title();
      public Title()
      {
     
      }
      public static Title getManager()
      {
      return am;
      }
      public Title(Main RageFFA)
      {
     
      }
      public void sendTitle(Player p, int fadeIn, int stay, int fadeOut, String title)
      {
      sendAll(p, fadeIn, stay, fadeOut, title, null, null, null, null);
      }
      public void sendSubtitle(Player p, int fadeIn, int stay, int fadeOut, String subtitle)
      {
      sendAll(p, fadeIn, stay, fadeOut, null, subtitle, null, null, null);
      }
      public void sendTitles(Player p, int fadeIn, int stay, int fadeOut, String title, String subtitle)
      {
      sendAll(p, fadeIn, stay, fadeOut, title, subtitle, null, null, null);
      }
      public void sendActionbar(Player p, String text)
      {
      sendAll(p, 0, 0, 0, null, null, text, null, null);
      }
      public void sendTablist(Player p, String header, String footer)
      {
      sendAll(p, 0, 0, 0, null, null, null, header, footer);
      }
      public void sendAll(Player p, int fadeIn, int stay, int fadeOut, String title, String subtitle, String actionText, String header, String footer)
      {
      PlayerConnection playerConnection = ((CraftPlayer) p).getHandle().playerConnection;
      if ((title != null) && (subtitle != null))
      {
      PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut);
      playerConnection.sendPacket(packetPlayOutTimes);
      }
      if (title != null)
      {
      IChatBaseComponent titleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', title) + "\"}");
      PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleComponent);
      playerConnection.sendPacket(titlePacket);
      }
      if (subtitle != null)
      {
      IChatBaseComponent subtitleComponent = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\"}");
      PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, subtitleComponent);
      playerConnection.sendPacket(subtitlePacket);
      }
      if (actionText != null)
      {
      IChatBaseComponent actionComponent = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', actionText) + "\"}");
      PacketPlayOutChat actionPacket = new PacketPlayOutChat(actionComponent);
      playerConnection.sendPacket(actionPacket);
      }
      if ((header != null) || (footer != null))
      {
      header = header == null ? "" : ChatColor.translateAlternateColorCodes('&', header);
      footer = footer == null ? "" : ChatColor.translateAlternateColorCodes('&', footer);
      IChatBaseComponent headerComponent = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + header + "\"}");
      IChatBaseComponent footerComponent = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + footer + "\"}");
      PacketPlayOutPlayerListHeaderFooter packetTablist = new PacketPlayOutPlayerListHeaderFooter(headerComponent);
      try
      {
      Field field = packetTablist.getClass().getDeclaredField("b");
      field.setAccessible(true);
      field.set(packetTablist, footerComponent);
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      playerConnection.sendPacket(packetTablist);
      }
      }
    }
     
    I tried casting CraftPlayer to p, but still no good.. CraftPlayer cannot be resolved to a type.
     
  4. I have not changed much since last successful build.
     
  5. You need to import "org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer".