Plugin is loading but not functioning

Discussion in 'Plugin Development' started by BrushPainter, Oct 8, 2014.

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

    BrushPainter

  2. Offline

    Skionz

    If it isnt a logic error we need the stacktrace
     
  3. Offline

    BrushPainter

    I believe it is a logical error because the console isn't producing any errors, it says it is loading fine. I can type the command /dice and it gives me the dice and sends the message but when I right click while holding it, nothing at all happens.
     
  4. Offline

    xTigerRebornx

    BrushPainter In in your listener for the interact event, you do:
    Code:
     if(event.getPlayer().getItemInHand().equals(Material.QUARTZ_BLOCK)) {
    This will never be true, as getItemInHand() returns an ItemStack, which will never equal a Material. You may be wanting to compare its type, which you can get by invoking getType() on the ItemStack returned.
     
  5. Offline

    BrushPainter


    Thanks for the reply, is this the change I should have made?
    Code:java
    1. public void playerInteractEvent(PlayerInteractEvent event) {
    2. if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR)) {
    3.  
    4. ItemStack dice = new ItemStack(Material.QUARTZ_BLOCK, 1);
    5. //ItemMeta diceMeta = dice.getItemMeta();
    6. //diceMeta.setDisplayName(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]");
    7.  
    8. // if(event.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]")) {
    9. if(event.getPlayer().getItemInHand().equals(dice)) {


    If not, is this the change? Because I tested the first one and it's doing the same thing:

    Code:java
    1. public void playerInteractEvent(PlayerInteractEvent event) {
    2. if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR)) {
    3.  
    4. //ItemStack dice = new ItemStack(Material.QUARTZ_BLOCK, 1);
    5. //ItemMeta diceMeta = dice.getItemMeta();
    6. //diceMeta.setDisplayName(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]");
    7.  
    8. // if(event.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]")) {
    9. if(event.getPlayer().getItemInHand().getType().equals(Material.QUARTZ)) {
     
  6. Offline

    xTigerRebornx

    BrushPainter ItemStack#equals() will compare both ItemStacks so that they are exactly the same, including ItemMeta and amount. Since your ItemStack has lore, it won't work because the one you are comparing it to doesn't have that lore. The best thing would be to check the Material and its ItemMeta (name and lore)
     
  7. Offline

    BrushPainter


    Ok so I disabled the command for now, I'm just using a block of quartz. Here's my updated code but I'm very confused as for what to do:

    Code:java
    1. package me.BrushPainter.Dice;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Effect;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.World;
    11. //import org.bukkit.command.Command;
    12. //import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. //import org.bukkit.event.Listener;
    17. import org.bukkit.event.block.Action;
    18. import org.bukkit.event.player.PlayerInteractEvent;
    19. //import org.bukkit.inventory.ItemStack;
    20. //import org.bukkit.inventory.meta.ItemMeta;
    21. import org.bukkit.plugin.java.JavaPlugin;
    22.  
    23. public class Main extends JavaPlugin implements Listener {
    24.  
    25. @EventHandler
    26. public void playerInteractEvent(PlayerInteractEvent event) {
    27. if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR)) {
    28.  
    29. // ItemStack dice = new ItemStack(Material.QUARTZ_BLOCK, 1);
    30. // ItemMeta diceMeta = dice.getItemMeta();
    31. // diceMeta.setDisplayName(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]");
    32.  
    33. // if(event.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.RED + "[" + ChatColor.WHITE + "Die" + ChatColor.RED + "]")) {
    34. if(event.getPlayer().getItemInHand().getType().equals(Material.QUARTZ)) {
    35.  
    36. Player player = (Player) event;
    37. String playerName = player.getName();
    38. World world = player.getWorld();
    39. Location location = player.getLocation();
    40.  
    41. int maximum = 100;
    42. int minimum = 1;
    43.  
    44. Random number = new Random();
    45. int range = maximum - minimum + 1;
    46. int randomNum = number.nextInt(range) + minimum;
    47.  
    48. world.playEffect(location, Effect.SMOKE, 2003);
    49.  
    50. player.sendMessage(ChatColor.YELLOW + "You" + ChatColor.GRAY + "rolled a " + ChatColor.AQUA + ChatColor.BOLD + randomNum + ChatColor.RESET + ChatColor.GRAY + "!");
    51.  
    52. Bukkit.broadcast(ChatColor.YELLOW + playerName + ChatColor.GRAY + "rolled a " + ChatColor.AQUA + ChatColor.BOLD + randomNum + ChatColor.RESET + ChatColor.GRAY + "!", null);
    53.  
    54. }
    55. }
    56. }
    57.  
    58. public void onEnable() {
    59.  
    60. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    61.  
    62. getLogger().info("Dice Enabled");
    63.  
    64. }
    65.  
    66. public void onDisable() {
    67.  
    68. getLogger().info("Dice Disabled");
    69.  
    70. }
    71. }


    Please keep in mind that the purple text is a disabled part of code because I'm using "//"
     
  8. Offline

    Skionz

    Can't cast player to event lol use event.getPlayer()
     
Thread Status:
Not open for further replies.

Share This Page