Lock picking plugin

Discussion in 'Plugin Development' started by Nerdfuryz, Jul 6, 2013.

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

    Nerdfuryz

    Code:
    package me.dylan.stickyfingers;
    /*
    * Author: Dabo Ross
    * Website: www.daboross.net
    * Email: [email protected]
    */
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class wildWestBukkit extends JavaPlugin implements Listener{
        public final Logger logger = Logger.getLogger("Minecraft");
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this,this);
     
        }
        @EventHandler
          public void onrightclick(PlayerInteractEntityEvent e) {
            if (e.getRightClicked() != null)
            {
              for (Entity p : e.getPlayer().getNearbyEntities(2.0D, 2.0D, 2.0D))
              {
                if (!(p instanceof Player))
                  continue;
                Player p2 = (Player)p;
                if (p2.getGameMode() != GameMode.SURVIVAL)
                  continue;
                if (!e.getPlayer().hasLineOfSight(p))
                  continue;
                Player player = (Player) p2;
                Inventory targetInv = p2.getInventory();
                player.openInventory(targetInv);
                p2.sendMessage(ChatColor.RED + "You are being PickPocketed!");
              }
            }
            }
        @Override
        public void onDisable() {
        }
    }
    Won't seem to work at all for some reason, anyone have any ideas?
     
  2. Offline

    Nitnelave

    I'm not sure, but I think the hasLineOfSight method doesn't take in account whether the other player is facing you or not, just if there is an obstacle.
     
  3. Use this bro i just tested it and it worked :)

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("pickpocket")){
    2. Player p = (Player)sender;
    3. Player target = p.getServer().getPlayer(args[0]);
    4. Inventory targetInv = target.getInventory();
    5. if(args.length == 0){
    6. p.sendMessage(ChatColor.RED + "To Few Arguments !");
    7. }
    8. else if(args.length == 1){
    9. if(target != null){
    10. p.openInventory(targetInv);
    11. target.sendMessage(ChatColor.GOLD + p.getDisplayName() + ChatColor.RED + " Is Pickpocketing You !");
    12. }
    13. else if(target == null){
    14. p.sendMessage(ChatColor.RED + "Sorry That Player Is Offline Or Does Not Exist");
    15. }
    16. }
    17. }


    you dont have to use it on command just use the code inside it :)
     
  4. Offline

    Nerdfuryz

    Nitnelave, Either way. The plugin won't actually open up the inventory xD. Any idea why?

    Thanks, any idea what was wrong with mine for future reference?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. im not to sure sorry mate.
     
  6. Offline

    Nerdfuryz

    Still not working
    Code:
    package me.dylan.stickyfingers;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class wildWestBukkit extends JavaPlugin implements Listener{
        public final Logger logger = Logger.getLogger("Minecraft");
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this,this);
     
        }
        @EventHandler
          public void onrightclick(PlayerInteractEntityEvent e, Player sender, String[] args) {
            Player p = (Player)sender;
            Player target = p.getServer().getPlayer(args[0]);
            Inventory targetInv = target.getInventory();
            if(args.length == 0){
                p.sendMessage(ChatColor.RED + "To Few Arguments !");
            }
            else if(args.length == 1){
                if(target != null){
                    p.openInventory(targetInv);
                    target.sendMessage(ChatColor.GOLD + p.getDisplayName() + ChatColor.RED + " Is Pickpocketing You !");
                }
            }
        }
        @Override
        public void onDisable() {
        }
    }
    Notorious-Riddler
     
  7. Offline

    Rprrr

    Notorious-Riddler
    Please.. don't feed code.. especially not when your code isn't even right.
     

  8. excuse me sir but have you even tried to help ? I think not.
     
  9. Offline

    Nerdfuryz

    Don't be mean, he is only trying to help my issue.

    Also, if you feel you have the ability to help me out it would be great to do so :)

    I was talking about the other guy :p

    Notice how I quoted him not you xD

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

    Rprrr

    Notorious-Riddler
    No, I have not. No shit, really. But I strongly have something against your way of feeding code. People should learn by theirselves; you're only having him copy code he does not understand. Comment clearly if you're giving away the code ánd submit code that's actually right, because you've made some clear mistakes in your code. For example:

    1. You're not making sure the sender is actually a player. Will result in errors.
    2. You already try to use the first argument before checking if it's actually there - that will result in NPE spam in the console.
    3. .getPlayer(...) won't return null, even if the player has never played on the server before or if the player is offline. Trying to open the inventory without checking these things correctly (so in another way than 'target !=null') will result in errors.

    Also, I can criticize you whenever I want, even if you don't like it.
     
    foodyling likes this.
  11. Offline

    Nerdfuryz

    What do you think the issue is then?

    With my code
     
  12. Rprrr

    i want you to do me a little favour.

    Copy this code
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("pickpocket")){
    2.  
    3. if(args.length == 0){
    4. Player p = (Player)sender;
    5. p.sendMessage(ChatColor.RED + "To Few Arguments !");
    6. }
    7. else if(args.length == 1){
    8.  
    9.  
    10. Player target = getServer().getPlayer(args[0]);
    11.  
    12. if(target != null){
    13. Player p = (Player)sender;
    14. Inventory targetInv = target.getInventory();
    15. p.openInventory(targetInv);
    16. target.sendMessage(ChatColor.GOLD + p.getDisplayName() + ChatColor.RED + " Is Pickpocketing You !");
    17. }
    18. else if(target == null){
    19. Player p = (Player)sender;
    20. p.sendMessage(ChatColor.RED + "Sorry That Player Is Offline Or Does Not Exist");
    21. }
    22. }
    23. }


    put it in the plugin.yml

    test it in-game and i DARE YOU to come back here and tell me it doesn't work i have just tested it with a friend and it works completely fine.
     
  13. Offline

    Rprrr

    Nerdfuryz
    Well, the main issue is that an event doesn't have a 'sender' and it doesn't pass on 'arguments'. You're trying to handle it like it's an onCommand() function, which simply does not work. Take a look at the possibilities:

    http://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/PlayerInteractEntityEvent.html

    Notorious-Riddler
    Can you please leave the topic? You didn't read my post. Stop posting the same code with errors. If you're wanting to help someone - that's fine. But what you're doing is just extremely annyoing - you're posting code with errors, not a perfect way to 'help' someone. If you don't understand what's wrong with it, go read my post or ask me a question.

    Also, he doesn't want to pickpocket on a command, he wants to pickpocket on the event.

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

    SnipsRevival

  15. Offline

    Rprrr

    Notorious-Riddler
    Jesus. You seem not to be able to read.

    READ MY PREVIOUS POST TO SEE THE ERRORS IN YOUR CODE


    ^

    Too bad this is the only way you might understand what I've said. I shall quote myself again, in case you fail to find my post:


    I shall now quote myself again, marking the important lines:

    Can you now read it? Thanks.
     
  16. Offline

    Nerdfuryz

    Is anyone going to actually help out or is the flame war going to continue :confused:
     
    • Unacceptable behavior. Read the ToS again.
    Rprrr Can you kindly FUCK OFF thanks.
     
  17. Offline

    Rprrr

    foodyling likes this.
  18. Offline

    ZeusAllMighty11

  19. Offline

    Nerdfuryz

    so Player player = (Player) sender; ?

    I don't see anything for what I am looking for?

    Code:
      
              Player t = (Player) p2;
              Player player = (Player) sender;
              InventoryView targetInv = t.getOpenInventory();
              player.openInventory(targetInv);
              p2.sendMessage(ChatColor.RED + "You are being PickPocketed!");
            }
    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  20. Code:java
    1. @EventHandler
    2. public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    3. // Get the player from this event
    4. Player player = event.getPlayer();
    5. // Get the entity that was right-clicked on
    6. Entity entity = event.getRightClicked();
    7.  
    8. // Check if this entity was an instanceof a player, e.g. is it a Player object? and can we cast it to Player?
    9. if (entity instanceof Player) {
    10. // We can now cast it to Player
    11. Player target = (Player) entity;
    12.  
    13. // Use player and target variables to handle the rest
    14. }
    15. }
    16.  
     
Thread Status:
Not open for further replies.

Share This Page