Need help with Dispaly Name

Discussion in 'Plugin Development' started by gabe4356, Sep 5, 2014.

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

    gabe4356

    So, I am making a plugin for my friends server, but I can't seem to get to set a nickname when I type the command, everything else works, but this doesn't, here is my code:

    Code:java
    1. player.setDisplayName(ChatColor.DARK_GREEN + "Elf : " + player.getDisplayName());
     
  2. r u sure that's not working? do you ahve any plugins that r overriding the nicks (e.g essentials[chat]?)
     
  3. Offline

    octoshrimpy

    Try saving the new nick to a string, and then assigning it. it might be going in a loop trying to get the DisplayName from itself.
     
  4. Offline

    Deleted user

    gabe4356
    Are you using Essentials on the server?
     
  5. Offline

    octoshrimpy

    JaguarJo <3 I'm guessing that was you.
     
  6. Offline

    Unica

    gabe4356
    It's being overridden. Is this for the chat? If so,
    Use
    Code:java
    1. e.setFormat("Elf"+p.getDisplayname());
     
  7. Offline

    Necrodoom

  8. Offline

    gabe4356

    Necrodoom Here:

    Code:java
    1. package gabe.races;
    2.  
    3. import java.io.File;
    4. import java.util.ArrayList;
    5. import java.util.List;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Material;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.enchantments.Enchantment;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.ShapedRecipe;
    19. import org.bukkit.inventory.meta.ItemMeta;
    20. import org.bukkit.plugin.java.JavaPlugin;
    21. import org.bukkit.potion.PotionEffect;
    22. import org.bukkit.potion.PotionEffectType;
    23.  
    24. public class GabeMain extends JavaPlugin implements Listener {
    25.  
    26.  
    27.  
    28.  
    29.  
    30. @EventHandler
    31. public void onPlayerJoin(PlayerJoinEvent event) {
    32. Player player = event.getPlayer();
    33. player.hasPermission("Fable.Dwarf");
    34. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD+ "Welcome! We have given you a Legendary Dwarven Sword!");
    35. ItemStack item1 = new ItemStack(Material.IRON_SWORD);
    36. ItemMeta im = item1.getItemMeta();
    37. im.addEnchant(Enchantment.FIRE_ASPECT , 2, true);
    38. im.addEnchant(Enchantment.KNOCKBACK , 2, true);
    39. im.addEnchant(Enchantment.DAMAGE_ALL , 2, true);
    40. im.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "Dwarven Sword");
    41. List<String> lore = new ArrayList<String>();
    42. lore.add(ChatColor.DARK_AQUA + "Legendary Dwarven Craftsmenship");
    43. im.setLore(lore);
    44. item1.setItemMeta(im);
    45.  
    46. player.getInventory().addItem(item1);
    47. }
    48.  
    49.  
    50.  
    51.  
    52.  
    53. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    54. Player player = (Player) sender;
    55. //Lets assume my onCommand method is above here and is working properly
    56.  
    57.  
    58.  
    59. if (cmd.getName().equalsIgnoreCase("Fable")) {
    60. player.sendMessage(ChatColor.GOLD+ "=================================");
    61. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + " Fablecraft Commands ");
    62. player.sendMessage(ChatColor.GOLD+ "=================================");
    63. player.sendMessage(ChatColor.AQUA+ "Race : List Available races to join (NOTE: Once you join one, no turning back!)");
    64. player.sendMessage(ChatColor.AQUA+ "JoinRace<racename> : Joins a specified race. Example: /JoinRaceDwarfs");
    65. player.sendMessage(ChatColor.AQUA+ "Fable : Lists help for Fablecraft Plugins");
    66. player.sendMessage(ChatColor.AQUA+ "Finfo : Lists Info About The Server Fablecraft");
    67. }
    68.  
    69. if (cmd.getName().equalsIgnoreCase("Finfo")) {
    70. player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "====================");
    71. player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + " FableCraft Info ");
    72. player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "====================");
    73. player.sendMessage(ChatColor.BLUE + "FableCraft is a Hub server, our main feature is the Mid-evil Roleplay server where Fablecraft got it's name from.");
    74. player.sendMessage(ChatColor.BLUE + "We will try our best to make your expierence here, on FableCraft great! We come out with Weekly Updates with new quests, and more!");
    75. player.sendMessage(ChatColor.BLUE + "We really hope you enjoy your stay here on FableCraft. For FC commands, type /Fable!");
    76.  
    77. }
    78. if (cmd.getName().equalsIgnoreCase("Race")) {
    79. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Fablecraft Races:");
    80. player.sendMessage(ChatColor.GOLD+ "" + ChatColor.BOLD + "=================");
    81. player.sendMessage(ChatColor.BLUE+ "" + ChatColor.BOLD + " Races ");
    82. player.sendMessage(ChatColor.GOLD+ "" + ChatColor.BOLD + "=================");
    83. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Dwarfs");
    84. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Elfs");
    85. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Atlantians");
    86. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Fox");
    87. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Human");
    88. player.sendMessage(ChatColor.AQUA+ "" + ChatColor.BOLD + "Cyclops");
    89. }
    90. if (cmd.getName().equalsIgnoreCase("JoinRaceDwarfs")) {
    91. player.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "You have joined the Dwarfs!");
    92. player.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "To get to the Dwarf Base, travel to the snowy Mountain.");
    93. player.setDisplayName(ChatColor.DARK_GRAY + "Dwarf : " + player.getDisplayName());
    94. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A DWARF!");
    95. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 99999, 4));
    96. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 99999, 1));
    97. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 99999, 5));
    98.  
    99. }
    100. if (cmd.getName().equalsIgnoreCase("JoinRaceElfs")) {
    101. player.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "You have joined the Elfs!");
    102. player.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "To get to the Elf Base, travel to the Big Jungle Tree.");
    103. player.setDisplayName(ChatColor.DARK_GREEN + "Elf : " + player.getDisplayName());
    104. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A ROYAL ELF!");
    105. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 6));
    106. player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 99999, 2));
    107.  
    108. }
    109. if (cmd.getName().equalsIgnoreCase("JoinRaceAtlantians")) {
    110. player.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "You have joined the Atlantians!");
    111. player.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "To get to the Atlantian Base, travel behind spawn, you will look down, and find it.");
    112. player.setDisplayName(ChatColor.AQUA + "Atlantian : " + player.getDisplayName());
    113. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A ADVANCED ATLANTIAN! So is the maker of this plugin :)");
    114. player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 99999, 4));
    115. player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 99999, 4));
    116.  
    117. }
    118. if (cmd.getName().equalsIgnoreCase("JoinRaceFox")) {
    119. player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "You have joined the Foxes!");
    120. player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "To get to the Fox Base, travel to a Birch forest...you will find your den.");
    121. player.setDisplayName(ChatColor.RED + "Fox : " + player.getDisplayName());
    122. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A FOX!");
    123. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 99999, 4));
    124. player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 99999, 2));
    125.  
    126. }
    127. if (cmd.getName().equalsIgnoreCase("JoinRaceCyclops")) {
    128. player.sendMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + "You have joined the Cyclops!");
    129. player.sendMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + "To get to the Cyclops Base, travel to a Cave near the shore, but facing the mountain.");
    130. player.setDisplayName(ChatColor.DARK_BLUE + "Elf : " + player.getDisplayName());
    131. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A Cyclops!");
    132. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 99999, 4));
    133. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 99999, 5));
    134.  
    135. }
    136. if (cmd.getName().equalsIgnoreCase("JoinRaceHuman")) {
    137. player.sendMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + "You have joined the Humans!");
    138. player.sendMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + "To get to the Human Base, travel to a Castle, not spawn, but it stands out.");
    139. player.setDisplayName(ChatColor.DARK_BLUE + "Elf : " + player.getDisplayName());
    140. player.sendMessage(ChatColor.BLUE + "NO TURNING BACK NOW! YOU ARE A HUMAN!");
    141. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 99999, 1));
    142. player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 99999, 1));
    143.  
    144. } else if (foo()) {
    145. player.sendMessage(ChatColor.DARK_RED + "Unknown command, type /Fable");
    146. }
    147.  
    148. return true;
    149. }
    150.  
    151.  
    152.  
    153.  
    154.  
    155. private boolean foo() {
    156. // TODO Auto-generated method stub
    157. return false;
    158. }
    159.  
    160.  
    161. public void onDisable() {
    162. getLogger().info(ChatColor.GREEN+ "Fablecraft plugin has been disabled!");
    163. getServer().broadcastMessage(ChatColor.GREEN+ "Fablecraft has been disabled!");
    164. //On Disable method stub
    165. }
    166.  
    167. @SuppressWarnings("deprecation")
    168. public void onEnable() {
    169. getLogger().info(ChatColor.GREEN+ "Fablecraft plugin has been enabled!");
    170. getServer().getPluginManager().registerEvents(this, this);
    171. getServer().broadcastMessage(ChatColor.GREEN+ "Fablecraft has been enabled!");
    172.  
    173.  
    174. ItemStack item = new ItemStack(Material.IRON_SWORD);
    175. ItemMeta im = item.getItemMeta();
    176. im.addEnchant(Enchantment.FIRE_ASPECT , 2, true);
    177. im.addEnchant(Enchantment.KNOCKBACK , 2, true);
    178. im.addEnchant(Enchantment.DAMAGE_ALL , 2, true);
    179. im.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "Dwarven Sword");
    180. List<String> lore = new ArrayList<String>();
    181. lore.add(ChatColor.DARK_AQUA + "Legendary Dwarven Craftsmenship");
    182. im.setLore(lore);
    183. item.setItemMeta(im);
    184. ShapedRecipe disk = new ShapedRecipe(item);
    185. disk.shape(new String[]{"%*%","%$%","*$*"}).setIngredient('$', Material.STICK).setIngredient('*', Material.DIAMOND).setIngredient('%', Material.GOLD_INGOT);
    186. Bukkit.getServer().addRecipe(disk);
    187.  
    188.  
    189.  
    190.  
    191. Config config = new Config(this, "config"); //Get the plugin's default config.yml file
    192. config.set("Version", "1.0.1");
    193. config.set(" Plugin Name", "FableCraft");
    194. config.set(" Author", "gabe4356");
    195. config.save(); //Save and write changes made to the config.
    196.  
    197. @SuppressWarnings("unused")
    198. String hello = config.getString("Version"); //Retrieve the string stored at the path "test" in the config.
    199.  
    200. for (Player player : Bukkit.getOnlinePlayers()){
    201. Config playerConfig = new Config(this, "Players" + File.separator + player.getName());
    202. playerConfig.set("name", player.getName());
    203. playerConfig.set(" Last Online", player.getLastPlayed());
    204. playerConfig.set(" When Player first Joined", player.getFirstPlayed());
    205. playerConfig.save();
    206. }
    207. //Creates a collection of .yml files in a new Players folder, for all online players, and stores their location.
    208. //Note, this is an example, remember that Bukkit is now supporting UUIDs, so use player.getUniqueID() if you want to make any further use of this.
    209.  
    210. Config cheese = new Config(this, "Cheese"); //Get the plugin's default config.yml file
    211. cheese.set("Fablecraft Is Cool", "true");
    212. cheese.set(" Cheddar?", "False");
    213. cheese.set(" Author", "gabe4356 (Cheese)");
    214. cheese.save(); //Save and write changes made to the config.
    215.  
    216. @SuppressWarnings("unused")
    217. String hello1 = cheese.getString("Version"); //Retrieve the string stored at the path "test" in the config.
    218.  
    219. //on Enable Method stub
    220.  
    221.  
    222. //on Enable Method stub
    223.  
    224.  
    225.  
    226.  
    227. }
    228. }
    229.  
    230.  
    231.  
    232.  
    233.  
    234.  
     
  9. Offline

    Necrodoom

    gabe4356
    1. Why unsafe cast sender to player? Check if its a player first.
    2. What the heck is foo() for?
    3. So the only displayname not working is elf? Or what?
     
Thread Status:
Not open for further replies.

Share This Page