String for a broadcast error.

Discussion in 'Plugin Development' started by PlayerNerd, Sep 1, 2014.

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

    PlayerNerd

    I was trying to make a broadcast command.
    I have this code:

    Code:java
    1. package com.playernerd.PlayerNerd.pvp;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.Server;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.HandlerList;
    13. import org.bukkit.inventory.FurnaceRecipe;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import KitHandler.KHWither;
    19.  
    20. public class Main extends JavaPlugin
    21. {
    22.  
    23.  
    24.  
    25.  
    26. public void onEnable()
    27. {
    28.  
    29.  
    30. //msg
    31. getLogger().info("Minerando Ferro...");
    32. getLogger().info("Criando base da espada...");
    33. getLogger().info("Decorando Armadura...");
    34. getLogger().info("Encantando...");
    35. getLogger().info("Pronto para o PvP.");
    36. getLogger().info("PlayerNerd PVP Ativado.");
    37.  
    38. //Events
    39.  
    40. getServer().getPluginManager().registerEvents(new PvPHandler(), this);
    41. getServer().getPluginManager().registerEvents(new KitInventory(), this);
    42. getServer().getPluginManager().registerEvents(new KHWither(), this);
    43. registerCommands();
    44.  
    45. //smelting
    46.  
    47. ItemStack carne = new ItemStack(Material.COOKED_BEEF);
    48. ItemMeta carneN = carne.getItemMeta();
    49. ArrayList<String> carneL = new ArrayList<String>();
    50. carneN.setDisplayName(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "#PiáTem" + ChatColor.DARK_RED + "] " + ChatColor.RED + "Carne Friboi");
    51. carneL.add(ChatColor.RED + "Carne Friboi.");
    52. carneN.setLore(carneL);
    53. carne.setItemMeta(carneN);
    54.  
    55.  
    56. FurnaceRecipe friboi = new FurnaceRecipe(new ItemStack(carne), Material.ROTTEN_FLESH);
    57.  
    58. Server b = Bukkit.getServer();
    59. b.addRecipe(friboi);
    60. }
    61.  
    62. public void onDisable()
    63. {
    64. getLogger().info("PlayerNerd PvP Desativado!");
    65. HandlerList.unregisterAll(this);
    66. }
    67.  
    68.  
    69. public void registerCommands()
    70. {
    71.  
    72. }
    73.  
    74. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    75.  
    76. if((sender instanceof Player)) {
    77. Player p = (Player) sender;
    78.  
    79. if(cmd.getName().equalsIgnoreCase("pvp"))
    80. {
    81. p.sendMessage("Player vs. Player");
    82. return true;
    83. }
    84.  
    85. if(cmd.getName().equalsIgnoreCase("wither"))
    86. {
    87. ItemStack withersword = new ItemStack(Material.IRON_SWORD);
    88. ItemMeta witherswordN = withersword.getItemMeta();
    89. ArrayList<String> witherswordL = new ArrayList<String>();
    90. witherswordN.setDisplayName(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "#PiáTem" + ChatColor.DARK_RED + "] " + ChatColor.BLACK + "Espada do Wither");
    91. witherswordL.add(ChatColor.RED + "Aquele que levar dano desta espada");
    92. witherswordL.add(ChatColor.RED + "ganhará efeito do Wither!");
    93. witherswordN.setLore(witherswordL);
    94. withersword.setItemMeta(witherswordN);
    95.  
    96.  
    97. p.getPlayer().getInventory().addItem(withersword);
    98. return true;
    99.  
    100.  
    101. }
    102.  
    103. }
    104.  
    105. if(cmd.getName().equalsIgnoreCase("bc"))
    106. {
    107.  
    108. if(args.length == 1)
    109. {
    110. String bc = args[0];
    111. Bukkit.getServer().broadcastMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + "#PiáTeam" + ChatColor.DARK_RED + "] " + bc);
    112. }
    113. }
    114.  
    115. return false;
    116. }
    117. }
    118.  
    119.  
    120.  


    and i have this error:

    Code:java
    1. Loading libraries, please wait...
    2. [20:03:27 INFO]: Starting minecraft server version 1.7.2
    3. >pl
    4. [20:03:27 INFO]: Loading properties
    5. [20:03:27 INFO]: Default game type: SURVIVAL
    6. [20:03:27 INFO]: Generating keypair
    7. [20:03:28 INFO]: Starting Minecraft server on *:25565
    8. [20:03:28 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.
    9. 3-2-g85f5776-b3024jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.4-SNAPSHOT
    10. )
    11. [20:03:28 ERROR]: Could not load 'plugins\PlayerNerd PvP.jar' in folder 'plugins
    12. '
    13. org.bukkit.plugin.InvalidDescriptionException: name is not defined
    14. at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile
    15. .java:811) ~[PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    16. at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.
    17. java:189) ~[PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    18. at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    19. inLoader.java:155) ~[PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    20. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    21. .java:133) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    22. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    23. va:350) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    24. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:31
    25. 2) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    26. at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [P
    27. iaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    28. at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    29. ) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    30. at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    31. a:126) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    32. at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    33. :424) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    34. at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    35. 17) [PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    36. Caused by: java.lang.NullPointerException
    37. at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile
    38. .java:804) ~[PiaGames.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    39. ... 10 more
    40. [20:03:28 INFO]: [PlayerNerdCore] Loading PlayerNerdCore v2.0
    41. [20:03:28 INFO]: [ClearLag] Loading ClearLag v2.7.1
    42. [20:03:28 INFO]: [WorldEdit] Loading WorldEdit v5.6.2
    43. [20:03:28 INFO]: [ProtocolLib] Loading ProtocolLib v3.4.0
    44. [20:03:28 INFO]: [PermissionsEx] Loading PermissionsEx v1.22.1
    45. [20:03:28 INFO]: [Effect Library] Loading EffectLib v1.7-SNAPSHOT
    46. [20:03:28 INFO]: [LibsDisguises] Loading LibsDisguises v8.2.6
    47. [20:03:28 INFO]: [PlayerNerdPet] Loading PlayerNerdPet v2.0
    48. [20:03:28 INFO]: [WorldGuard] Loading WorldGuard v5.8
    49. [20:03:28 INFO]: [WorldSaver] Loading WorldSaver v1.4
    50. [20:03:28 INFO]: [Essentials] Loading Essentials v2.12.2
    51. [20:03:28 INFO]: [EssentialsChat] Loading EssentialsChat v2.12.2
    52. [20:03:28 INFO]: [EssentialsProtect] Loading EssentialsProtect v2.12.2
    53. [20:03:28 INFO]: [EssentialsSpawn] Loading EssentialsSpawn v2.12.2
    54. [20:03:28 INFO]: [ProtocolLib] Enabling ProtocolLib v3.4.0
    55. [20:03:28 INFO]: [ProtocolLib] Started structure compiler thread.
    56. [20:03:28 INFO]: Preparing level "world"
    57. [20:03:29 INFO]: Preparing start region for level 0 (Seed: 1623597305087795683)
    58. [20:03:29 INFO]: ----- Bukkit Auto Updater -----
    59. [20:03:29 INFO]: It appears that you're running a Development Build, when you've
    60. specified in bukkit.yml that you prefer to run Recommended Builds.
    61. [20:03:29 INFO]: If you would like to be kept informed about new Development Bui
    62. ld releases, it is recommended that you change 'preferred-channel' in your bukki
    63. t.yml to 'dev'.
    64. [20:03:29 INFO]: With that set, you will be told whenever a new version is avail
    65. able for download, so that you can always keep up to date and secure with the la
    66. test fixes.
    67. [20:03:29 INFO]: If you would like to disable this warning, simply set 'suggest-
    68. channels' to false in bukkit.yml.
    69. [20:03:29 INFO]: ----- ------------------- -----
    70. [20:03:29 INFO]: Preparing start region for level 1 (Seed: 1623597305087795683)
    71. [20:03:30 INFO]: Preparing start region for level 2 (Seed: 1623597305087795683)
    72. [20:03:30 INFO]: [PlayerNerdCore] Enabling PlayerNerdCore v2.0
    73. [20:03:30 INFO]: [PlayerNerdCore] Alimentando Cabras...
    74. [20:03:30 INFO]: [PlayerNerdCore] Mimando Lhamas...
    75. [20:03:30 INFO]: [PlayerNerdCore] Fazendo Omelete...
    76. [20:03:30 INFO]: [PlayerNerdCore] Cagando...
    77. [20:03:30 INFO]: [PlayerNerdCore] Alimentando T-Rex...
    78. [20:03:30 INFO]: [PlayerNerdCore] PlayerNerd Core Ativado.
    79. [20:03:30 INFO]: [ClearLag] Enabling ClearLag v2.7.1
    80. [20:03:30 INFO]: [ClearLag] Loading modules...
    81. [20:03:30 INFO]: [ClearLag] No config updates found...
    82. [20:03:30 WARN]: [ClearLag] mob-range requires you to use bukkit v1.7_r3
    83. [20:03:30 INFO]: [ClearLag] Modules have been loaded!
    84. [20:03:30 INFO]: [ClearLag] Clearlag is now enabled!
    85. [20:03:30 INFO]: [WorldEdit] Enabling WorldEdit v5.6.2
    86. [20:03:30 INFO]: [ClearLag] Searching for updates..
    87. [20:03:31 INFO]: WEPIF: Using the Bukkit Permissions API.
    88. [20:03:32 INFO]: [PermissionsEx] Enabling PermissionsEx v1.22.1
    89. [20:03:32 INFO]: [PermissionsEx] Initializing file backend
    90. [20:03:32 INFO]: [PermissionsEx] Permissions file successfully reloaded
    91. [20:03:32 ERROR]: [PermissionsEx] ==============================================
    92. ==============================================
    93. [20:03:32 ERROR]: [PermissionsEx] As of version 1.21, PEX requires a version of
    94. Bukkit with UUID support to function (>1.7.5). Please download a non-UUID versio
    95. n of PermissionsEx to continue.
    96. [20:03:32 ERROR]: [PermissionsEx] Beginning reversion of potential invalid UUID
    97. conversion
    98. [20:03:32 ERROR]: [PermissionsEx] Reversion complete, disabling. PermissionsEx w
    99. ill not work until downgrade is complete
    100. [20:03:32 ERROR]: [PermissionsEx] ==============================================
    101. ==============================================
    102. [20:03:32 INFO]: [PermissionsEx] Disabling PermissionsEx v1.22.1
    103. [20:03:32 INFO]: WEPIF: Using the Bukkit Permissions API.
    104. [20:03:32 INFO]: WEPIF: Using the Bukkit Permissions API.
    105. [20:03:32 INFO]: [Effect Library] Enabling EffectLib v1.7-SNAPSHOT
    106. [20:03:33 INFO]: [LibsDisguises] Enabling LibsDisguises v8.2.6
    107. [20:03:34 INFO]: [PlayerNerdPet] Enabling PlayerNerdPet v2.0
    108. [20:03:34 INFO]: [PlayerNerdPet] Alimentando Porcos...
    109. [20:03:34 INFO]: [PlayerNerdPet] Mimando Ovelhas...
    110. [20:03:34 INFO]: [PlayerNerdPet] Colhendo Leite...
    111. [20:03:34 INFO]: [PlayerNerdPet] Fermentando Leite...
    112. [20:03:34 INFO]: [PlayerNerdPet] Comendo Queijo...
    113. [20:03:34 INFO]: [PlayerNerdPet] PlayerNerd Pets Ativado.
    114. [20:03:34 INFO]: [WorldGuard] Enabling WorldGuard v5.8
    115. [20:03:34 INFO]: [WorldGuard] (world) TNT ignition is PERMITTED.
    116. [20:03:34 INFO]: [WorldGuard] (world) Lighters are PERMITTED.
    117. [20:03:34 INFO]: [WorldGuard] (world) Lava fire is blocked.
    118. [20:03:34 INFO]: [WorldGuard] (world) Fire spread is UNRESTRICTED.
    119. [20:03:34 INFO]: [WorldGuard] Loaded configuration for world 'world'
    120. [20:03:34 INFO]: [WorldGuard] (world_nether) TNT ignition is PERMITTED.
    121. [20:03:34 INFO]: [WorldGuard] (world_nether) Lighters are PERMITTED.
    122. [20:03:34 INFO]: [WorldGuard] (world_nether) Lava fire is blocked.
    123. [20:03:34 INFO]: [WorldGuard] (world_nether) Fire spread is UNRESTRICTED.
    124. [20:03:34 INFO]: [WorldGuard] Loaded configuration for world 'world_nether'
    125. [20:03:34 INFO]: [WorldGuard] (world_the_end) TNT ignition is PERMITTED.
    126. [20:03:34 INFO]: [WorldGuard] (world_the_end) Lighters are PERMITTED.
    127. [20:03:34 INFO]: [WorldGuard] (world_the_end) Lava fire is blocked.
    128. [20:03:34 INFO]: [WorldGuard] (world_the_end) Fire spread is UNRESTRICTED.
    129. [20:03:34 INFO]: [WorldGuard] Loaded configuration for world 'world_the_end'
    130. [20:03:34 INFO]: [WorldGuard] 0 regions loaded for 'world'
    131. [20:03:34 INFO]: [WorldGuard] 0 regions loaded for 'world_nether'
    132. [20:03:34 INFO]: [WorldGuard] 0 regions loaded for 'world_the_end'
    133. [20:03:34 INFO]: [WorldSaver] Enabling WorldSaver v1.4
    134. [20:03:34 INFO]: [WorldSaver] enabled. Visit goo.gl/HWbai for plugin info
    135. [20:03:34 INFO]: [Essentials] Enabling Essentials v2.12.2
    136. [20:03:34 INFO]: Essentials: Using config file enhanced permissions.
    137. [20:03:34 INFO]: Permissions listed in as player-commands will be given to all u
    138. sers.
    139. [20:03:34 INFO]: [EssentialsChat] Enabling EssentialsChat v2.12.2
    140. [20:03:35 INFO]: [EssentialsProtect] Enabling EssentialsProtect v2.12.2
    141. [20:03:35 INFO]: [EssentialsSpawn] Enabling EssentialsSpawn v2.12.2
    142. [20:03:35 INFO]: Server permissions file permissions.yml is empty, ignoring it
    143. [20:03:35 INFO]: Done (6,177s)! For help, type "help" or "?"
    144. [20:03:35 INFO]: [ClearLag] No updates found!
    145. [20:03:35 INFO]: Plugins (14): PlayerNerdCore, ClearLag, WorldEdit, ProtocolLib,
    146. PermissionsEx, EffectLib, LibsDisguises, PlayerNerdPet, WorldGuard, WorldSaver,
    147. Essentials, EssentialsChat, EssentialsProtect, EssentialsSpawn
    148. >


    How can i fix it?
     
  2. Offline

    BillyGalbreath

    Your plugin.yml is incorrect. Read the stacktrace.......
     
  3. Offline

    PlayerNerd

    BillyGalbreath my plugin.yml:

    main: com.playernerd.PlayerNerd.pvp.Main
    version: 2.0
    author: PlayerNerd
    softdepend: [PlayerNerdCore]
    commands:
    pvp:
    description: pvp.
    usage: /<command>
    wither:
    description: sword.
    usage: /<command>
    bc:
    description: broadcast.
    usage: /<command>
     
  4. Offline

    luigieai

    PlayerNerd LOL MANO, presta atenção ;3
    Where is the name of the plugin on plugin.yml?
     
  5. Offline

    GreySwordz

    PlayerNerd At the beginning of the plugin.yml you have to put something like:
    Code:
    name: PlayerNerd
    so bukkit knows the name of your plugin.
     
  6. Offline

    PlayerNerd

    luigieai Mals eu não vi.
    Sorry i hadn´t seen.

    But how can i put more words? It only can "speak" one word. And how can i put color? (Like: &6, &4, etc)

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

    luigieai

  8. Offline

    PlayerNerd

    luigieai In the text, for example: /bc &6Hello guys. I can´t do it for 2 reasons:
    - The command only catchs 1 word.
    - The command can´t use color. I can´t use &6, &4, &b, &k., etc.
     
  9. Offline

    Hedgehogs4Me

    Here's what I'd do, but it might not be the best way:

    First initialize a StringBuilder. Then, set up a for loop that looks something like for(int j=0;j<args.length;j++). Next, for each arg[j], find if it contains & followed by a non-whitespace character (regex &\S or something like that) and replace the & in that with ChatColor.COLOR_CHAR (which is what prefixes colours in the actual Bukkit code, it's the little double S thing), then append it onto your StringBuilder. After the for loop, get the String from your StringBuilder or something (it's been a while since I've used StringBuilders) and broadcast that.

    EDIT: bloody bbcode, haha. Changed the variable to j.
     
  10. Offline

    PlayerNerd

  11. Offline

    BillyGalbreath

    For colors:

    Code:java
    1.  
    2. String message = "&4This &7&ois &r&4some words with &1c&2o&3l&4o&5r&6s&9!";
    3. message = ChatColor.translateAlternateColorCodes('&', message);
    4. Bukkit.getServer().broadcastMessage(message);
    5.  
     
  12. Offline

    Necrodoom

    PlayerNerd are you talking about onCommand? Args array contains the arguments.
     
  13. Offline

    NonameSL

    loop through all arguments and combine them to one string using a StringBuilder or str +=arg;
    Then translate alternative color codes of the string and broadcast that message
     
Thread Status:
Not open for further replies.

Share This Page