Disabling right and left mouse buttons?

Discussion in 'Plugin Development' started by ryanertel, Jan 7, 2013.

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

    ryanertel

    Hello i am a new plugin developer and i am working on my first plugin and i ran into a wall, so i was wondering if it is possible to disable the right and left mouse buttons and how i would do so if it is possible. Thank you in advance.
     
  2. Offline

    CubixCoders

    What do you mean by disable?
     
  3. Offline

    ryanertel

    i mean dissallow a user from doing anything in minecraft that uses the right and left clicks. It's meant to be used as a punishment.
     
  4. Offline

    Drew1080

    Use the PlayerInteractEvent then cancel the event, if the Action of the user is a left or right click.
     
  5. Offline

    CubixCoders

    Okay well you need to make a listener class and listen for the event PlayerInteractEvent and cancel the event. It's pretty easy.
     
  6. Offline

    ryanertel

    thank you, im pretty new to making Bukkit plugins so i don't know how all of the listeners and everything work quite yet.
     
  7. Offline

    CubixCoders

    Okay well let me walk you through it :)
    Code:java
    1.  
    2. //First we need to make a list, when you do the command to make them not able to
    3. List<String> punished = new ArrayList<String>();
    4. //To add people to the list use
    5. punished.add(player.getName());
    6. //To remove people from the list use this
    7. punished.remove(player.getName());
    8. //To check if someone is in a list use this
    9. if(punished.contains(player.getName());
    10. //Now we have to make the Listener class
    11. //You can decide if you want it in the main class, or an external class
    12. //For in the main class you have to make it implement Listener like so
    13. public class MyPlugin extends JavaPlugin implements Listener{}
    14. //If you want an external class, just make the class and implement Listener
    15. public class MyPluginListener implements Listener{}
    16. //Then to register the listener, you have to add this to your onEnable method
    17. PluginManager pm = getServer().getPluginManager();
    18. //This line depends on if your main class implements Listener if so use this
    19. pm.registerEvents(this, this);
    20. //If you made an external class that implements listener, use this
    21. pm.registerEvents(new MyPluginListener(this), this);
    22. //Now in your Listener class you have to add this
    23. //If it's in your main class ignore this
    24. public MyPlugin plugin;
    25. public MyPluginListener(MyPlugin instance){
    26. plugin=instance;
    27. }
    28. //Okay, now we have to make the class listen for the event PlayerInteractEvent
    29. @EventHandler // This is needed or else it wont work
    30. public void onInteract(PlayerInteractEvent event){
    31. Player p =event.getPlayer();
    32. String pname = p.getName();
    33. if(plugin.punished.contains(pname)){
    34. event.setCancelled(true);
    35. }
    36. }
    37.  
     
  8. Offline

    gomeow

    CubixCoders
    I would put the list into a flat file, because this way would not work through restart/reload
     
  9. Offline

    CubixCoders

    True true, if so just make the List = getConfig().getStringList("punished");
     
  10. Offline

    gomeow

    CubixCoders (Tahging is nice now) :D

    You would also need to factor that into the setting of the list
     
  11. Offline

    CubixCoders

    gomeow
    Yes yes it is :3
    Then i would add getConfig().set("punished", punished);
    saveConfig();
     
Thread Status:
Not open for further replies.

Share This Page