I cannot understand why this sign don't work.. Code:java @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLine(0).equalsIgnoreCase("[Kit]")) { e.setLine(0, "§5[§bKit§5]"); e.setLine(1, ""); e.setLine(2, "§6PVP §cKit"); } } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if (e.getClickedBlock().getState() instanceof Sign) { Sign s = (Sign) e.getClickedBlock().getState(); if (s.getLine(0).equalsIgnoreCase("§5[§bKit§5]")) { e.getPlayer().setHealth(20); e.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "PVPKits" + ChatColor.GRAY + "]" + ChatColor.AQUA + " You Chose PVP Kit!"); } } }
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().
Sean0402 Change line 13 to: PHP: if(e.getClickedBlock().getType == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST){
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 package me.sean0402.kit; import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Random; import net.milkbowl.vault.economy.Economy;import net.milkbowl.vault.economy.EconomyResponse;import net.minecraft.server.v1_7_R4.NBTTagList; import org.bukkit.Bukkit;import org.bukkit.block.Sign;import org.bukkit.ChatColor;import org.bukkit.Material;import org.bukkit.Sound;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;import org.bukkit.enchantments.Enchantment;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.block.SignChangeEvent;import org.bukkit.event.entity.FoodLevelChangeEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.PlayerInventory;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.plugin.RegisteredServiceProvider;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.Potion;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType;import org.bukkit.potion.PotionType;import org.bukkit.scheduler.BukkitRunnable; public class Kit extends JavaPlugin implements Listener { public static Economy econ = null; public void onDisable() { Bukkit.getServer().getLogger() .info(ChatColor.AQUA + "[Kits] Disabling Kits By Sean0402"); } @EventHandler public void onFoodChange(FoodLevelChangeEvent e){ e.setCancelled(true); } @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLine(0).equalsIgnoreCase("[Kit]")) { e.setLine(0, "§5[§bKit§5]"); e.setLine(1, ""); e.setLine(2, "§6PVP §cKit"); } } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if(e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST){ Sign s = (Sign) e.getClickedBlock().getState(); if (s.getLine(0).equalsIgnoreCase("§5[§bKit§5]")) { e.getPlayer().setHealth(20); e.getPlayer().sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "PVPKits" + ChatColor.GRAY + "]" + ChatColor.AQUA + " You Chose PVP Kit!"); } } } public void onEnable() { 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; } } private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) { return false; } RegisteredServiceProvider<Economy> rsp = getServer() .getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } econ = rsp.getProvider(); return econ != null; } ArrayList<Player> cooldown = new ArrayList<Player>(); public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "Only players can get kits!"); return true; } final Player p = (Player) sender; PlayerInventory pi = p.getInventory(); if (cmd.getName().equalsIgnoreCase("pvp")) { p.setHealth(20); p.setFireTicks(0); p.setFoodLevel(20); if (cooldown.contains(p)) { } else { if ((p.hasPermission("cooldown.bypass"))) { } else { cooldown.add(p); } EconomyResponse r = econ.withdrawPlayer(p.getName(), 10); if (r.transactionSuccess()) { ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1); ItemStack bow = new ItemStack(Material.BOW, 1); ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET); ItemStack chestplate = new ItemStack( Material.DIAMOND_CHESTPLATE); ItemStack leggings = new ItemStack( Material.DIAMOND_LEGGINGS); ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); ItemStack item = new ItemStack(Material.POTION, 1); sword.addEnchantment(Enchantment.DAMAGE_ALL, 5); sword.addEnchantment(Enchantment.FIRE_ASPECT, 2); ItemMeta swordmeta = sword.getItemMeta(); swordmeta.setDisplayName(ChatColor.RED + "PainBringer!"); List<String> lore = new ArrayList<String>(); lore.add(ChatColor.GREEN + "This Amazing Sword"); lore.add(ChatColor.GREEN + "Can Bring Pain!"); swordmeta.setLore(lore); sword.setItemMeta(swordmeta); pi.addItem(sword); bow.addEnchantment(Enchantment.ARROW_FIRE, 1); bow.addEnchantment(Enchantment.ARROW_DAMAGE, 2); bow.addEnchantment(Enchantment.ARROW_INFINITE, 1); pi.addItem(bow); helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); chestplate.addEnchantment( Enchantment.PROTECTION_ENVIRONMENTAL, 4); leggings.addEnchantment( Enchantment.PROTECTION_ENVIRONMENTAL, 4); boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); pi.setArmorContents(null); pi.setHelmet(helmet); pi.setChestplate(chestplate); pi.setLeggings(leggings); pi.setBoots(boots); pi.addItem(new ItemStack(Material.ENDER_PEARL, 16)); pi.addItem(new ItemStack(Material.COOKED_BEEF, 32)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); Potion potion = new Potion(PotionType.FIRE_RESISTANCE); pi.addItem(potion.toItemStack(1)); Potion potion1 = new Potion(PotionType.STRENGTH); pi.addItem(potion1.toItemStack(1)); Potion potion2 = new Potion(PotionType.SPEED); pi.addItem(potion2.toItemStack(1)); pi.addItem(new ItemStack(Material.ARROW, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); Potion pot = new Potion(1); pot.setType(PotionType.WEAKNESS); pot.setHasExtendedDuration(true); pot.setSplash(true); pot.apply(item); p.getInventory().addItem(item); Potion pot1 = new Potion(1); pot1.setType(PotionType.POISON); pot1.setHasExtendedDuration(true); pot1.setSplash(true); pot1.apply(item); p.getInventory().addItem(item); Potion pot2 = new Potion(1); pot2.setType(PotionType.POISON); pot2.setHasExtendedDuration(true); pot2.setSplash(true); pot2.apply(item); p.getInventory().addItem(item); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); Potion pot3 = new Potion(1); pot3.setType(PotionType.WEAKNESS); pot3.setHasExtendedDuration(true); pot3.setSplash(true); pot3.apply(item); p.getInventory().addItem(item); Potion pot4 = new Potion(1); pot4.setType(PotionType.WEAKNESS); pot4.setHasExtendedDuration(true); pot4.setSplash(true); pot4.apply(item); p.getInventory().addItem(item); Potion pot5 = new Potion(1); pot5.setType(PotionType.WEAKNESS); pot5.setHasExtendedDuration(true); pot5.setSplash(true); pot5.apply(item); p.getInventory().addItem(item); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); pi.addItem(new ItemStack(Material.MUSHROOM_SOUP, 1)); Potion potion21 = new Potion(PotionType.STRENGTH); pi.addItem(potion21.toItemStack(1)); Potion potion211 = new Potion(PotionType.REGEN); pi.addItem(potion211.toItemStack(1)); Potion potion2111 = new Potion(PotionType.SPEED); pi.addItem(potion2111.toItemStack(1)); // p.addPotionEffect(new // PotionEffect(PotionEffectType.REGENERATION, 10000000, // 0)); // p.addPotionEffect(new // PotionEffect(PotionEffectType.SPEED, 100000000, 0)); p.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "Kits" + ChatColor.GRAY + "]" + ChatColor.RED + " You Got Your Kit!"); cooldown.add(p); Bukkit.getServer().getScheduler() .scheduleSyncDelayedTask(this, new Runnable() { public void run() { cooldown.remove(p); } }, 12000); return true; } else { p.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "Kits" + ChatColor.GRAY + "]" + ChatColor.RED + " Please Wait 10 Minutes For This Kit!"); return true; } } } return false; }}
Sean0402 Print out the first line on the sign, what is it? With color codes the string is a bit wonky.
_LB Lines 75 - 87 BetaNyan That would make absolutely no difference, the onEnable is executed before the events either way.
Niknea Image of what I want the sign to look like: Changed the code abit: Code:java @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLine(0).equalsIgnoreCase("[Kit]")) { e.setLine(0, "§c[Kit]"); e.setLine(1, "§bClick Here"); e.setLine(2, "§bFor PvP"); e.setLine(3, "§bKit!"); } } http://gyazo.com/dff66e424483908e990d44ea269fd8e8
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.
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..
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.