This just isnt working

Discussion in 'Plugin Development' started by ChintziSecilMC, Dec 14, 2014.

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

    ChintziSecilMC

    For some reason this isn't working like it just doesn't. But for some reason when i click it with a gadget (basicaly an itemstack that does something) it does it, anyways heres my code.

    Code:
            if (player.getWorld().getName().equals("skie")) {
                if (event.getClickedBlock().getType().equals(Material.ENDER_CHEST)) {
                    event.setCancelled(true);
                    Block block = event.getClickedBlock();
                    Location blockLocation = block.getLocation();
                    block.setType(Material.AIR);
                    Firework firework = (Firework) player.getWorld().spawn(blockLocation, Firework.class);
                    FireworkMeta fireworkMeta = firework.getFireworkMeta();
                    FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(Color.AQUA).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
                    fireworkMeta.addEffect(effect);
                    fireworkMeta.setPower(1);
                    firework.setFireworkMeta(fireworkMeta);
                    player.sendMessage(ChatColor.GREEN + "You found a present!");
                }
            }
     
    Last edited: Dec 14, 2014
  2. Offline

    pookeythekid

    @ChintziSecilMC Does absolutely nothing happen when you try it? If not, what does happen? And for good measure you may as well post your whole class.
     
  3. Offline

    Hex_27

    @ChintziSecilMC Did you register your event on onEnable? Check if you missed out the @EventHandler annotation.
     
    pookeythekid likes this.
  4. Offline

    ChintziSecilMC

    @pookeythekid
    It opens the chest, and doesnt say the message or do the firework


    @Hex_27
    Yeah this is just apart of code i have and everything else in this event (PlayerInteractEvent) works just not this
     
    Last edited: Dec 14, 2014
  5. Offline

    ChipDev

    Full class please?
     
  6. Offline

    ChintziSecilMC

    Full File Code:

    Code:
    package net.wrightnz.minecraft.skiecraft.listeners;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import me.confuser.barapi.BarAPI;
    import net.wrightnz.minecraft.skiecraft.AmmoType;
    import net.wrightnz.minecraft.skiecraft.ParticleEffect;
    import net.wrightnz.minecraft.skiecraft.PlayerSettingsHelper;
    import net.wrightnz.minecraft.skiecraft.commands.Command_Trail;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.EnderPearl;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.entity.TNTPrimed;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.event.player.PlayerTeleportEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.util.Vector;
    
    public class PlayerListener implements Listener {
    
        public static List<Player> playersWithTrails = new ArrayList();
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerMove(PlayerMoveEvent event) {
            /* if ((player.getGameMode() != GameMode.CREATIVE) && (player.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) && (!player.isFlying())) {
             * player.setAllowFlight(true);
             * }*/
    
            if (Command_Trail.activeTrail != null) {
                Player player = event.getPlayer();
                if (PlayerSettingsHelper.hasTrailsOn(player)) {
                    Player[] players = player.getServer().getOnlinePlayers();
                    Location playerLocation = player.getLocation();
                    playerLocation.setY(playerLocation.getY() + 1);
                    Command_Trail.activeTrail.display(0.1F, 0.1F, 0.1F, 0.1F, 4, playerLocation, Arrays.asList(players));
                }
            }
            Player player = event.getPlayer();
            if (player != null) {
                if (player.getInventory().getBoots().getType().equals(Material.LEATHER_BOOTS)) {
                    if (player.getInventory().getBoots().getItemMeta().getDisplayName().equals(
                            ChatColor.DARK_GRAY + "S"
                            + ChatColor.DARK_PURPLE + "h"
                            + ChatColor.DARK_GRAY + "a"
                            + ChatColor.DARK_PURPLE + "d"
                            + ChatColor.DARK_GRAY + "o"
                            + ChatColor.DARK_PURPLE + "w "
                            + ChatColor.DARK_GRAY + "B"
                            + ChatColor.DARK_PURPLE + "o"
                            + ChatColor.DARK_GRAY + "o"
                            + ChatColor.DARK_PURPLE + "t"
                            + ChatColor.DARK_GRAY + "s")) {
                        Player[] players = player.getServer().getOnlinePlayers();
                        ParticleEffect.SMOKE.display(0.15F, 0.15F, 0.15F, 0.02F, 2, player.getLocation(), Arrays.asList(players));
                        ParticleEffect.FOOTSTEP.display(0, 0, 0, 0, 1, player.getLocation(), Arrays.asList(players));
                    }
                } else {
                    if (player.getInventory().getChestplate().getType().equals(Material.LEATHER_CHESTPLATE)) {
                        if (player.getInventory().getChestplate().getItemMeta().getDisplayName().equals(
                                ChatColor.DARK_GRAY + "S"
                                + ChatColor.DARK_PURPLE + "h"
                                + ChatColor.DARK_GRAY + "a"
                                + ChatColor.DARK_PURPLE + "d"
                                + ChatColor.DARK_GRAY + "o"
                                + ChatColor.DARK_PURPLE + "w "
                                + ChatColor.DARK_GRAY + "C"
                                + ChatColor.DARK_PURPLE + "h"
                                + ChatColor.DARK_GRAY + "e"
                                + ChatColor.DARK_PURPLE + "s"
                                + ChatColor.DARK_GRAY + "t")) {
                            Player[] players = player.getServer().getOnlinePlayers();
                            ParticleEffect.WITCH_MAGIC.display(0.1F, 0.1F, 0.1F, 0.1F, 3, player.getLocation(), Arrays.asList(players));
                        }
                    }
                }
            }
        }
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerTeleport(PlayerTeleportEvent event) {
    
            Player player = event.getPlayer();
            Player[] players = player.getServer().getOnlinePlayers();
            ParticleEffect.WITCH_MAGIC.display(0.3F, 0.3F, 0.3F, 0.1F, 10, player.getLocation(), Arrays.asList(players));
        }
    
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_GRAY.toString() + ChatColor.BOLD.toString() + "Smoke Bomb")) {
                Player[] players = player.getServer().getOnlinePlayers();
                Location location = player.getLocation();
                location.setY(location.getY() + 1);
                //player.getNearbyEntities(3, 3, 3);
                ParticleEffect.HUGE_EXPLOSION.display(0.1F, 0.1F, 0.1F, 1, 3, location, Arrays.asList(players));
                player.playSound(location, Sound.FIZZ, 1.0F, 1.0F);
            }
    
            if (player.getWorld().getName().equals("skie")) {
                event.setCancelled(true);
                if (event.getClickedBlock().getType().equals(Material.ENDER_CHEST)) {
                    Block block = (Block) event.getClickedBlock();
                    Location blockLocation = block.getLocation();
                    block.setType(Material.AIR);
                    Firework firework = (Firework) player.getWorld().spawn(blockLocation, Firework.class);
                    FireworkMeta fireworkMeta = firework.getFireworkMeta();
                    FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(Color.AQUA).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
                    fireworkMeta.addEffect(effect);
                    fireworkMeta.setPower(1);
                    firework.setFireworkMeta(fireworkMeta);
                    player.sendMessage(ChatColor.GREEN + "You found a present!");
                }
            }
    }
    @ChipDev
    Sorry i can't post full code cause theres too much letters in the class for me to post :/ i just added an extra '}' to make a little more sence

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

    TGRHavoc

    It could be that you're not in a world called "skie"...
     
  8. Offline

    DeadlyScone

    @ChintziSecilMC

    What I want to know is why you are canceling the event before checking if it is the material you want. Also try using

    Code:java
    1.  
    2. if(event.getClickedBlock().getType() == Material.ENDER_CHEST){
    3.  
     
  9. Offline

    Dragonphase

    WHY?!?!
     
    AdamQpzm likes this.
  10. Offline

    Webbeh

    Try with this instead.
    Code:
    event.getClickedBlock().getType() == Material.ENDER_CHEST
     
  11. Offline

    mythbusterma

    @Webbeh

    It honestly makes little to no actual difference, and it will work either way. It is certainly not causing the error described.
     
  12. Offline

    Webbeh

    I'm seriously not so sure about that.
     
  13. Offline

    DeadlyScone

    @mythbusterma

    I believe this may be the cause of the error, if anything it's worth the try.

    The == operator compares two objects as they relate in memory, ignoring their contents.
    versus .equals() which compares the contents of each object.

    You may be correct though.


    Edit.
    @Webbeh Why did you dupe my post and pass it off as your code? Or am I instigating presumably?
     
    Last edited: Dec 15, 2014
  14. Offline

    mythbusterma

    @DeadlyScone

    Yes, and programmatically enums are represented as constants, and as such can be compared with either, although == is usually prefered.

    @ChintziSecilMC

    Add debug messages to your code and try again.
     
  15. Offline

    ChintziSecilMC

    @mythbusterma
    Kk


    @Dragonphase
    Like i quoted i couldn't post full code, i have a lot of other things i have in that .Java Class

    @DeadlyScone
    Because i don't want the enderchest to be opened i want it so when you right click the chest it doesnt open but just set's the enderchest block type to air, says a message and shoots a firework

    Sorry to be off topic, cause one of the prizes i wanted to be a head of someone with a santa head, anyone know how to set a player skin to a Skull item?

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

    TheCodingCat

    you mean create a head with a player head? In that case then do this
    Code:
    ItemStack stack = new ItemStack(Material.SKULL_ITEM,1(short)3);
    SkullMeta m = (SkullMeta) stack.getItemMeta();
    m.setOwner(playername);
    stack.setItemMeta(m);
     
  17. Offline

    ChintziSecilMC

    @TheCodingCat
    @mythbusterma
    @DeadlyScone
    @Webbeh
    @Dragonphase
    @TGRHavoc
    @ChipDev
    @Hex_27
    @pookeythekid

    Updated Code:

    Code:
            if (player.getWorld().getName().equals("skie")) {
                if (event.getClickedBlock().getType() == Material.ENDER_CHEST) {
                    event.setCancelled(true);
                    Block block = (Block) event.getClickedBlock();
                    Location blockLocation = block.getLocation();
                    block.setType(Material.AIR);
                    Firework firework = (Firework) player.getWorld().spawn(blockLocation, Firework.class);
                    FireworkMeta fireworkMeta = firework.getFireworkMeta();
                    FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(Color.LIME).withColor(Color.RED).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
                    fireworkMeta.addEffect(effect);
                    fireworkMeta.setPower(1);
                    firework.setFireworkMeta(fireworkMeta);
                    player.sendMessage(ChatColor.DARK_RED + "Santa: " + ChatColor.GREEN + "Ho ho ho, looks like you found a present there lad");
                }
            }
    @TheCodingCat

    Yeah thanks :D

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

    DeadlyScone

    @ChintziSecilMC
    I understand your intention, I don't understand your reasoning. So basically you are saying if you are a player in that world and you left click a button or anything that triggers the interact event including other chests, it will cancel all interactions?

    Edit: seen you fixed it so nvm
     
  19. Offline

    Skionz

    Which line isn't passing?
     
  20. Offline

    ChintziSecilMC

    Just found something weird, i was just testing and i did /i stick 1 name:&6Majestic_Stick then when i hit it, it did the method, why is that?
    @DeadlyScone @Skionz
     
  21. Offline

    Skionz

  22. Offline

    nverdier

    @ChintziSecilMC Or when you did the command? If it's the command then WHAT?!??!??! but if it's the Ender Chest do you want people to not be able to do it if their hands are empty?
     
  23. Offline

    ChintziSecilMC

    @Skionz
    When i hit the Ender Chest with the item

    @nverdier
    Doesn't really matter all i want is if they interact with it in any way
     
  24. Offline

    nverdier

    Then what's the problem?
    EDIT: Wait do you mean if you LEFT click it opposed to right click it? Like it works both ways?
     
  25. Offline

    DeadlyScone

    @ChintziSecilMC

    If you have nothing in your hand and you right click the chest nothing happens, correct?
     
    Last edited: Dec 15, 2014
  26. Offline

    ChintziSecilMC

    @DeadlyScone
    Ohh!!! how do i make it so it does activate if a player has something in their or air in their hand?
     
    Last edited: Dec 15, 2014
  27. Offline

    DeadlyScone

    @ChintziSecilMC
    damn , I must have been drunk when I posted that. It does fire I believe if you right click a block with nothing in your hand. I'll try working this out for you in a min.

    In the mean time add a debug message right below the if world = skie and see if you received it.

    Code:java
    1.  
    2. @EventHandler
    3.  
    4. public void onPlayerInteract(PlayerInteractEvent event){
    5.  
    6. Player player = event.getPlayer();
    7.  
    8.  
    9.  
    10. if (player.getWorld().getName().equalsIgnoreCase("skie") && event.getClickedBlock().getType() == Material.ENDER_CHEST) {
    11.  
    12. event.setCancelled(true);
    13.  
    14.  
    15.  
    16. Block block = (Block) event.getClickedBlock();
    17.  
    18. Location blockLocation = block.getLocation();
    19.  
    20. block.setType(Material.AIR);
    21.  
    22.  
    23.  
    24. Firework firework = (Firework) player.getWorld().spawn(blockLocation, Firework.class);
    25.  
    26. FireworkMeta fireworkMeta = firework.getFireworkMeta();
    27.  
    28. FireworkEffect effect = FireworkEffect.builder().flicker(true).withColor(Color.AQUA).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
    29.  
    30. fireworkMeta.addEffect(effect);
    31.  
    32. fireworkMeta.setPower(1);
    33.  
    34. firework.setFireworkMeta(fireworkMeta);
    35.  
    36.  
    37.  
    38. player.sendMessage(ChatColor.GREEN + "You found a present!");
    39.  
    40. }
    41.  
    42. }
    43.  


    That worked for me. so make sure you have the correct world name and you are in that world.

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

    Dragonphase

    @ChintziSecilMC

    Again, is there absolutely any need for your list to be static? If your reasoning behind it is to allow other classes to retrieve data from it, I highly suggest you read up on OOP and Java.
     
  29. Offline

    Webbeh

    Didn't see you wrote that. And didn't pass it as my own either anyway so who cares.
     
  30. Offline

    DeadlyScone

    @Dragonphase

    I want to know why this "don't use static" is such a huge thing. Lets discard the OP's code for now. Lets say i have a class with a constant static hash map and i need other classes able to modify it (get and put info). Why is this bad if i decide to make the access static? I don't want a vague answer or "i need to read something" I want you, in your own words to tell me how come.

    PS, sorry for going off topic slightly, its just this itch that you can't itch.
     
    Last edited: Dec 16, 2014
Thread Status:
Not open for further replies.

Share This Page