Sign don't work?

Discussion in 'Plugin Development' started by Sean0402, Jul 26, 2014.

Thread Status:
Not open for further replies.
  1. I cannot understand why this sign don't work..
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. if (e.getLine(0).equalsIgnoreCase("[Kit]")) {
    4. e.setLine(0, "§5[§bKit§5]");
    5. e.setLine(1, "");
    6. e.setLine(2, "§6PVP §cKit");
    7. }
    8. }
    9.  
    10. @EventHandler
    11. public void onPlayerInteract(PlayerInteractEvent e) {
    12. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    13. if (e.getClickedBlock().getState() instanceof Sign) {
    14. Sign s = (Sign) e.getClickedBlock().getState();
    15. if (s.getLine(0).equalsIgnoreCase("§5[§bKit§5]")) {
    16. e.getPlayer().setHealth(20);
    17. e.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "PVPKits" + ChatColor.GRAY + "]" + ChatColor.AQUA + " You Chose PVP Kit!");
    18. }
    19. }
    20. }
     
  2. Offline

    Pizza371

    Sean0402 events registered? errors?
    pls more info
     
  3. Offline

    TheHandfish

    What exactly is the problem? You may want to do toLowerCase on the top line's text, and compare it to a lower case version of the string that you have at #15. Then use contains().
     
  4. Offline

    Niknea

    Sean0402 Change line 13 to:

    PHP:
    if(e.getClickedBlock().getType == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST){
     
  5. Niknea TheHandfish It should work fine.. Works fine on my other code but not this one.. I tried looking for a fix and cannot find anything.. Here is my whole main class:
    Code:java
    1. package me.sean0402.kit;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Random;
    7.  
    8. import net.milkbowl.vault.economy.Economy;
    9. import net.milkbowl.vault.economy.EconomyResponse;
    10. import net.minecraft.server.v1_7_R4.NBTTagList;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.block.Sign;
    14. import org.bukkit.ChatColor;
    15. import org.bukkit.Material;
    16. import org.bukkit.Sound;
    17. import org.bukkit.command.Command;
    18. import org.bukkit.command.CommandSender;
    19. import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
    20. import org.bukkit.enchantments.Enchantment;
    21. import org.bukkit.entity.Player;
    22. import org.bukkit.event.EventHandler;
    23. import org.bukkit.event.Listener;
    24. import org.bukkit.event.block.Action;
    25. import org.bukkit.event.block.SignChangeEvent;
    26. import org.bukkit.event.entity.FoodLevelChangeEvent;
    27. import org.bukkit.event.player.PlayerInteractEvent;
    28. import org.bukkit.event.player.PlayerJoinEvent;
    29. import org.bukkit.inventory.ItemStack;
    30. import org.bukkit.inventory.PlayerInventory;
    31. import org.bukkit.inventory.meta.ItemMeta;
    32. import org.bukkit.plugin.RegisteredServiceProvider;
    33. import org.bukkit.plugin.java.JavaPlugin;
    34. import org.bukkit.potion.Potion;
    35. import org.bukkit.potion.PotionEffect;
    36. import org.bukkit.potion.PotionEffectType;
    37. import org.bukkit.potion.PotionType;
    38. import org.bukkit.scheduler.BukkitRunnable;
    39.  
    40. public class Kit extends JavaPlugin implements Listener {
    41.  
    42. public static Economy econ = null;
    43.  
    44. public void onDisable() {
    45. Bukkit.getServer().getLogger()
    46. .info(ChatColor.AQUA + "[Kits] Disabling Kits By Sean0402");
    47. }
    48.  
    49. @EventHandler
    50. public void onFoodChange(FoodLevelChangeEvent e){
    51. e.setCancelled(true);
    52. }
    53.  
    54. @EventHandler
    55. public void onSignChange(SignChangeEvent e) {
    56. if (e.getLine(0).equalsIgnoreCase("[Kit]")) {
    57. e.setLine(0, "§5[§bKit§5]");
    58. e.setLine(1, "");
    59. e.setLine(2, "§6PVP §cKit");
    60. }
    61. }
    62.  
    63. @EventHandler
    64. public void onPlayerInteract(PlayerInteractEvent e) {
    65. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    66. if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST){
    67. Sign s = (Sign) e.getClickedBlock().getState();
    68. if (s.getLine(0).equalsIgnoreCase("§5[§bKit§5]")) {
    69. e.getPlayer().setHealth(20);
    70. e.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "PVPKits" + ChatColor.GRAY + "]" + ChatColor.AQUA + " You Chose PVP Kit!");
    71. }
    72. }
    73. }
    74.  
    75. public void onEnable() {
    76. if (!setupEconomy()) {
    77. Bukkit.getServer().getPluginManager()
    78. .registerEvents(this, this);
    79. Bukkit.getServer().getLogger()
    80. .info(ChatColor.AQUA + "[Kits] Loading Kits By Sean0402");
    81. getLogger().severe(
    82. ChatColor.RED
    83. + "Disabled due to no Vault dependency found!");
    84. getServer().getPluginManager().disablePlugin(this);
    85. return;
    86. }
    87. }
    88.  
    89. private boolean setupEconomy() {
    90. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    91. return false;
    92. }
    93. RegisteredServiceProvider<Economy> rsp = getServer()
    94. .getServicesManager().getRegistration(Economy.class);
    95. if (rsp == null) {
    96. return false;
    97. }
    98. econ = rsp.getProvider();
    99. return econ != null;
    100. }
    101.  
    102. ArrayList<Player> cooldown = new ArrayList<Player>();
    103.  
    104. public boolean onCommand(CommandSender sender, Command cmd,
    105. String commandLabel, String[] args) {
    106. if (!(sender instanceof Player)) {
    107. sender.sendMessage(ChatColor.RED + "Only players can get kits!");
    108. return true;
    109. }
    110.  
    111. final Player p = (Player) sender;
    112. PlayerInventory pi = p.getInventory();
    113.  
    114. if (cmd.getName().equalsIgnoreCase("pvp")) {
    115. p.setHealth(20);
    116. p.setFireTicks(0);
    117. p.setFoodLevel(20);
    118. if (cooldown.contains(p)) {
    119. } else {
    120. if ((p.hasPermission("cooldown.bypass"))) {
    121.  
    122. } else {
    123. cooldown.add(p);
    124. }
    125. EconomyResponse r = econ.withdrawPlayer(p.getName(), 10);
    126. if (r.transactionSuccess()) {
    127. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
    128. ItemStack bow = new ItemStack(Material.BOW, 1);
    129. ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET);
    130. ItemStack chestplate = new ItemStack(
    131. Material.DIAMOND_CHESTPLATE);
    132. ItemStack leggings = new ItemStack(
    133. Material.DIAMOND_LEGGINGS);
    134. ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS);
    135. ItemStack item = new ItemStack(Material.POTION, 1);
    136.  
    137. sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
    138. sword.addEnchantment(Enchantment.FIRE_ASPECT, 2);
    139. ItemMeta swordmeta = sword.getItemMeta();
    140. swordmeta.setDisplayName(ChatColor.RED + "PainBringer!");
    141. List<String> lore = new ArrayList<String>();
    142. lore.add(ChatColor.GREEN + "This Amazing Sword");
    143. lore.add(ChatColor.GREEN + "Can Bring Pain!");
    144. swordmeta.setLore(lore);
    145. sword.setItemMeta(swordmeta);
    146. pi.addItem(sword);
    147. bow.addEnchantment(Enchantment.ARROW_FIRE, 1);
    148. bow.addEnchantment(Enchantment.ARROW_DAMAGE, 2);
    149. bow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
    150. pi.addItem(bow);
    151. helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    152. 4);
    153. chestplate.addEnchantment(
    154. Enchantment.PROTECTION_ENVIRONMENTAL, 4);
    155. leggings.addEnchantment(
    156. Enchantment.PROTECTION_ENVIRONMENTAL, 4);
    157. boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,
    158. 4);
    159.  
    160. pi.setArmorContents(null);
    161. pi.setHelmet(helmet);
    162. pi.setChestplate(chestplate);
    163. pi.setLeggings(leggings);
    164. pi.setBoots(boots);
    165. pi.addItem(new ItemStack(Material.ENDER_PEARL, 16));
    166. pi.addItem(new ItemStack(Material.COOKED_BEEF, 32));
    167. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    168. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    169. Potion potion = new Potion(PotionType.FIRE_RESISTANCE);
    170. pi.addItem(potion.toItemStack(1));
    171. Potion potion1 = new Potion(PotionType.STRENGTH);
    172. pi.addItem(potion1.toItemStack(1));
    173. Potion potion2 = new Potion(PotionType.SPEED);
    174. pi.addItem(potion2.toItemStack(1));
    175. pi.addItem(new ItemStack(Material.ARROW, 1));
    176. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    177. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    178. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    179. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    180. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    181. Potion pot = new Potion(1);
    182. pot.setType(PotionType.WEAKNESS);
    183. pot.setHasExtendedDuration(true);
    184. pot.setSplash(true);
    185. pot.apply(item);
    186. p.getInventory().addItem(item);
    187. Potion pot1 = new Potion(1);
    188. pot1.setType(PotionType.POISON);
    189. pot1.setHasExtendedDuration(true);
    190. pot1.setSplash(true);
    191. pot1.apply(item);
    192. p.getInventory().addItem(item);
    193. Potion pot2 = new Potion(1);
    194. pot2.setType(PotionType.POISON);
    195. pot2.setHasExtendedDuration(true);
    196. pot2.setSplash(true);
    197. pot2.apply(item);
    198. p.getInventory().addItem(item);
    199. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    200. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    201. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    202. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    203. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    204. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    205. Potion pot3 = new Potion(1);
    206. pot3.setType(PotionType.WEAKNESS);
    207. pot3.setHasExtendedDuration(true);
    208. pot3.setSplash(true);
    209. pot3.apply(item);
    210. p.getInventory().addItem(item);
    211. Potion pot4 = new Potion(1);
    212. pot4.setType(PotionType.WEAKNESS);
    213. pot4.setHasExtendedDuration(true);
    214. pot4.setSplash(true);
    215. pot4.apply(item);
    216. p.getInventory().addItem(item);
    217. Potion pot5 = new Potion(1);
    218. pot5.setType(PotionType.WEAKNESS);
    219. pot5.setHasExtendedDuration(true);
    220. pot5.setSplash(true);
    221. pot5.apply(item);
    222. p.getInventory().addItem(item);
    223. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    224. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    225. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    226. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    227. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    228. pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1));
    229. Potion potion21 = new Potion(PotionType.STRENGTH);
    230. pi.addItem(potion21.toItemStack(1));
    231. Potion potion211 = new Potion(PotionType.REGEN);
    232. pi.addItem(potion211.toItemStack(1));
    233. Potion potion2111 = new Potion(PotionType.SPEED);
    234. pi.addItem(potion2111.toItemStack(1));
    235. // p.addPotionEffect(new
    236. // PotionEffect(PotionEffectType.REGENERATION, 10000000,
    237. // 0));
    238. // p.addPotionEffect(new
    239. // PotionEffect(PotionEffectType.SPEED, 100000000, 0));
    240. p.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD
    241. + "Kits" + ChatColor.GRAY + "]" + ChatColor.RED
    242. + " You Got Your Kit!");
    243. cooldown.add(p);
    244. Bukkit.getServer().getScheduler()
    245. .scheduleSyncDelayedTask(this, new Runnable() {
    246. public void run() {
    247. cooldown.remove(p);
    248. }
    249. }, 12000);
    250. return true;
    251. } else {
    252. p.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD
    253. + "Kits" + ChatColor.GRAY + "]" + ChatColor.RED
    254. + " Please Wait 10 Minutes For This Kit!");
    255. return true;
    256. }
    257. }
    258. }
    259. return false;
    260. }
    261. }
     
  6. Offline

    Niknea

    Sean0402 Can you take a picture of how the sign looks? Also debug your code, where does it stop?
     
  7. Niknea The sign does nothing just has on the top line [Kit] doesent add my extra code
     
  8. Offline

    _LB

    Where is your onEnable? I don't even see where you register your event listener.
     
  9. Offline

    Niknea

    Sean0402 Print out the first line on the sign, what is it? With color codes the string is a bit wonky.
     
  10. Offline

    BetaNyan

    Put your onEnable before your events
     
  11. Offline

    Niknea

    _LB Lines 75 - 87

    BetaNyan That would make absolutely no difference, the onEnable is executed before the events either way.
     
  12. Niknea Image of what I want the sign to look like:
    Changed the code abit:
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. if (e.getLine(0).equalsIgnoreCase("[Kit]")) {
    4. e.setLine(0, "§c[Kit]");
    5. e.setLine(1, "§bClick Here");
    6. e.setLine(2, "§bFor PvP");
    7. e.setLine(3, "§bKit!");
    8. }
    9. }

    http://gyazo.com/dff66e424483908e990d44ea269fd8e8
     
  13. Offline

    xTigerRebornx

    Sean0402 You are only registering your events and whatnot if Vault isn't found, then you instantly disable your plugin after. Take some time to sit down and work through your code's logic, and fix the obvious problem.
     
  14. xTigerRebornx I'm not that good at trying to think things through normally.. It looks fine from where I look at it, just doesent work..
     
  15. Offline

    xTigerRebornx

    Sean0402 Problem lies here:
    Code:
    if (!setupEconomy()) {
                Bukkit.getServer().getPluginManager()
                        .registerEvents(this, this);
                Bukkit.getServer().getLogger()
                        .info(ChatColor.AQUA + "[Kits] Loading Kits By Sean0402");
                getLogger().severe(
                        ChatColor.RED
                                + "Disabled due to no Vault dependency found!");
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    Taking this line by line, it helps if you get a sheet of paper or something to write on to visually see the flow.
    It goes like this:
    Code:
    if(!setupEconomy()){
     
    
    setupEconomy() verifies that a valid economy is installed, the ! is deciding that if setupEconomy() returns false, do the logic in the if statement. Basically, all the code in your if-block is executed if an economy is not installed.
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Bukkit.getServer().getLogger().info(ChatColor.AQUA + "[Kits] Loading Kits By Sean0402");
    getLogger().severe(ChatColor.RED + "Disabled due to no Vault dependency found!");
    getServer().getPluginManager().disablePlugin(this); // This line
                return;
            }
    These lines of code are executed if there is no economy. The one I have commented disables the plugin. However, notice you also are registering your events if the economy isn't present. Since you want your plugin to be disabled if there is no economy, it wouldn't make much sense to register your events then directly disable your plugin, would it?

    You want your events to be registered if the economy is present. A simple way of doing this is to return (escaping out of the method) if the economy plugin is not present. Doing something like this:
    Code:
    if (!setupEconomy()) {
                getLogger().severe(
                        ChatColor.RED
                                + "Disabled due to no Vault dependency found!");
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Bukkit.getServer().getLogger().info(ChatColor.AQUA + "[Kits] Loading Kits By Sean0402");
    Would make sure that your events are properly registered if the economy is present.
     
Thread Status:
Not open for further replies.

Share This Page