Util Send actionbar message 1.8.3

Discussion in 'Resources' started by WizardlyBump17, Mar 19, 2019.

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

    WizardlyBump17

    Code:
    package packetplayoutchat;
    
    import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
    
    import org.bukkit.Bukkit;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
    
    public class ActionBarMessage {
      
    
       public static void sendMessage(Player p, String message) {
         PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a("{\"text\":\"" + message.replace("&", "§") + "\"}"), (byte) 2);
         ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
       }
      
       public static void broadcastMessage(String message) {
         PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a("{\"text\":\"" + message.replace("&", "§") + "\"}"), (byte) 2);
         for (Player p : Bukkit.getServer().getOnlinePlayers()) {
      ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
      }
       }
      
    }
    
    Code:
    package packetplayoutchat;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class C implements CommandExecutor {
    
       @Override
       public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
        
         if(cmd.getName().equalsIgnoreCase("actionbar")) {
           if(sender instanceof Player) {
             Player p = (Player) sender;
             if(args.length == 0) {
               p.sendMessage("§c/actionbar (me, server) [args]");
             } else {
               if(args.length < 2) {
                 p.sendMessage("§c/actionbar (me, server) [args]");
               } else {
                 if(args[0].equalsIgnoreCase("me")) {
                   StringBuilder sb = new StringBuilder();
                   for(int i = 1; i < args.length; i++) {
                     if(i > 1) sb.append(" ");
                     sb.append(args[i]);
                   }
                   ActionBarMessage.sendMessage(p, sb.toString());
                   p.sendMessage("§aYou sent the message to yourself!");
                 }
                 if(args[0].equalsIgnoreCase("server")) {
                   StringBuilder sb = new StringBuilder();
                   for(int i = 1; i < args.length; i++) {
                     if(i > 1) sb.append(" ");
                     sb.append(args[i]);
                   }
                   ActionBarMessage.broadcastMessage(sb.toString());
                   p.sendMessage("§aYou the message sent to all!");
                   Bukkit.getServer().broadcastMessage("§aYou received a message from " + p.getName());
                 }
               }
             }
           }
         }
        
         return false;
       }
    }
    
     
  2. Offline

    Chr0mosom3

    @WizardlyBump17 , useless. All this is is just code, you are not explaining anything. No one can learn anything from this
     
  3. Offline

    Tango_

    Well it is a Util, not a tutorial. If you understand how to code it's pretty self explanatory. The second chunk of code is them giving an example of how the code can be used. The top chunk of code is the actual utility, to send an action bar message to a player, and to broadcast an action bar message.
     
Thread Status:
Not open for further replies.

Share This Page