Solved Making Enchanting table not able to open

Discussion in 'Plugin Development' started by trusebruse, Nov 10, 2012.

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

    ZeusAllMighty11

    Now you know what I mean! xD
     
    TwistedMexi likes this.
  2. Offline

    the_merciless

    Lol

    When you report that something "does not work" it is useful to explain what the error says and post some of the code in question.

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

    TwistedMexi

    :| Please stop copy-pasting. you need to:
    For what you want, you need to do this:
    1. Check if it's right-click
    2. Check if the type of the block is an enchantment table
    3. If true, cancel the event. Right now you don't have an if statement wrapping your enchantment table line.

    Honestly a better way would be to use the InventoryOpenEvent and if the InventoryType is Enchantment, cancel it instead. This means it will only have to do anything if the're actually trying to open the enchantment window.
     
  4. Offline

    trusebruse

    No offense but i dont really understand what you mean with
    Code:
    if (player.hasPermission("random.permission")){
    if (player.blah()){
    //do this
    and
    Code:
    if (event.getType().equals(Material.ENCHANTMENT_TABLE)){
    //do this
    }
     
    and
     
    if (event.getTypeId().equals(54)){
    Dont get pissed when i dont get it. And i am not copying, i am looking what the difference is between mine, yours and TwistedMexi. When you say do this, i think you mean that you want me to copy and use your code.
     
  5. Offline

    the_merciless

    No never copy and use other peoples code unless they tell you to.

    when people write code they often use // these are used for comments which you do not want the code to read

    for example if you are writing code and want to make a little note of what the code does, you can do something like this

    Code:
    if (player.hasPermission("random.permission")){ //this is checking if the player has this permission
    java will read the 1st part but ignore what is written after the //

    The codes i wrote were just random crap so u could understand what the difference was between getType & getTypeId
     
  6. Offline

    TwistedMexi

    There's always going to be some adaptation needed when someone gives you a code snippet. You'll need to understand what a method is actually doing in order to write it properly.

    and he's asking for you to post the actual error you're receiving (shows up in your server's console as a stacktrace, or an error at the bottom of eclipse) when something isn't working. We can't tell you why it's not working unless you show us exactly what you set and the error received.
     
  7. Offline

    trusebruse

    So i should use this: public void InventoryOpenEvent(InventoryView transaction event)? It seemed to work but it says "Syntax error on token "event", delete this token" on event
     
  8. Offline

    NinjaW0lf

    Don't even know why i'm gonna try to help you, because u obviously know very little to none java. And know nothing about placements of brackets.

    First of all. Post your current Code, Everything.
    Second. Dont use a boolean for an event, it should always be
    Code:
    @EventHandler
    Public void onPlayerInteract(PlayerInteractEvent event) {
    //code here
    }
    Idc if this gives you errors, dont change it. Just tell me what the error is and i can help u fix it.
    Finally, i cant help much more than that until i see all your code.
     
  9. Offline

    trusebruse

    But i did show you the error message. :3
     
  10. the error is caused by the space inside the variable name
    Code:
    transaction event
    is not an vlid variable name,
    but
    Code:
    transactionEvent
    or
    Code:
    transaction_event
    is, my first example is recommend as coding way, as its the most used layout, so most people understand it directly
     
  11. Offline

    trusebruse

    I am sorry for the bracket thing at the start, i know how to use brackets. I was just trying to make it work first and fix the brackets later.

    I get errors at the "event"s at:
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
    {
    event.getType(Material.ENCHANTMENT_TABLE);
    {
    event.setCancelled(true);

    My whole code right now:
    Code:
    package me.trusebruse.NoEnchantmentTable;
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.*;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class NoEnchantmentTable extends JavaPlugin implements Listener
    {
            public final Logger logger = Logger.getLogger("Minecraft");
            public static NoEnchantmentTable plugin;
           
     
            @Override
            public void onEnable()
            {
                this.logger.info("NoEnchantmentTable is enabled.");
                // TODO Insert logic to be performed when the plugin is enabled
            }
     
            @Override
            public void onDisable()
            {
                this.logger.info("NoEnchantmentTable is disabled.");
                // TODO Insert logic to be performed when the plugin is disabled
            }
           
            @EventHandler
            public void InventoryOpenEvent(InventoryView transactionEvent)
                {
                    if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
                    {
                    event.getType(Material.ENCHANTMENT_TABLE);
                    {
                    event.setCancelled(true);
                    {
                   
                    }
           
           
           
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  12. Offline

    the_merciless

    Copy and paste this code, read the comments, and then delete them so you can read through the code and try to understand it.

    Code:
    package me.trusebruse.NoEnchantmentTable;
     
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
        public final class NoEnchantmentTable extends JavaPlugin implements Listener{
           
            public final Logger logger = Logger.getLogger("Minecraft");
            public static NoEnchantmentTable plugin;
     
           
         
           
         
            @Override
            public void onEnable(){
                this.logger.info("NoEnchantmentTable is enabled.");
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            }
         
           
           
           
           
            @Override
            public void onDisable(){
                this.logger.info("NoEnchantmentTable is disabled.");
     
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            }   
         
           
           
           
           
            @EventHandler
            public void oninteract (PlayerInteractEvent event){    //This line is naming the event "oninteract" and stating what event you wish to use
               
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK){                        //this line is checking if the player right clicked a block
                   
                    if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE) {    //this is checking if the player clicked a enchantment table
                       
                        event.setCancelled(true);  //if both of the above are true, this will cancel the event and stop anything happening
                       
                        event.getPlayer().sendMessage("You can not open Enchantment tables.");  //this will send this message to the player involved
                    }
                }
            }
        }
     
    
     
  13. your naming your variable "transactionEvent", but your accessing it whit "event", you wont exect a dog whit name "transactionEvent" when you call "event"
     
  14. Offline

    the_merciless

    What the f is " public void InventoryOpenEvent(InventoryView transactionEvent) "

    i give up.
     
  15. Offline

    brord

    I was writing it too, jsut like you with the comments xD
    Thanks for safing me the time to copy/paste :)
    (You better learn from it trusebruse)
     
  16. Offline

    NinjaW0lf

    K, First Add this in your onEnable Block
    Code:
    plugin.getServer().getPluginManager().registerEvents(this, this);
    So, ur onEnable should look like this:
    Code:
            @Override
            public void onEnable(){
                plugin.getServer().getPluginManager().registerEvents(this, this);
                this.logger.info("NoEnchantmentTable is enabled.");
                // TODO Insert logic to be performed when the plugin is enabled
            }
    The reason being is u need to register the events for them to work.

    Secondly, Do u want to use the interact event or inventory event, both will work. I suggest u use the inventory event.

    Change
    Code:
    event.getType(Material.ENCHANTMENT_TABLE);
    To
    Code:
    if (event.getMaterial().equals(Material.ENCHANTMENT_TABLE) {
     
    or
     
    if (event.getClickedBlock().getType().equals(Material.ENCHANTMENT_TABLE) {
    Either one of those should work.
    So, ur block should look like:

    Code:
    if (event.getMaterial().equals(Material.ENCHANTMENT_TABLE)) {
        event.setCancelled(true);
        event.getPlayer.sendMessage("Blah Blah Blah");
    }
     
  17. Offline

    the_merciless

    Damn, i forgot all about registering events lol

    Code:
    package me.trusebruse.NoEnchantmentTable;
     
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
        public final class NoEnchantmentTable extends JavaPlugin implements Listener{
           
            public final Logger logger = Logger.getLogger("Minecraft");
            public static NoEnchantmentTable plugin;
     
           
         
           
         
            @Override
            public void onEnable(){
                this.logger.info("NoEnchantmentTable is enabled.");
                plugin.getServer().getPluginManager().registerEvents(this, this);
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            }
         
           
           
           
           
            @Override
            public void onDisable(){
                this.logger.info("NoEnchantmentTable is disabled.");
     
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            }   
         
           
           
           
           
            @EventHandler
            public void oninteract (PlayerInteractEvent event){    //This line is naming the event "oninteract" and stating what event you wish to use
               
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK){                        //this line is checking if the player right clicked a block
                   
                    if (event.getClickedBlock().getType().equals(Material.ENCHANTMENT_TABLE)) {    //this is checking if the player clicked a enchantment table
                       
                        event.setCancelled(true);  //if both of the above are true, this will cancel the event and stop anything happening
                       
                        event.getPlayer().sendMessage("You can not open Enchantment tables.");  //this will send this message to the player involved
                    }
                }
            }
        }
     
    
     
  18. Offline

    NinjaW0lf

    NVM, u registered the events in your last post
     
  19. Offline

    trusebruse

  20. Offline

    the_merciless


    this should be if (event.getClickedBlock().getType().equals(Material.ENCHANTMENT_TABLE))
     
  21. Offline

    NinjaW0lf

    would not both work?
    idk i haven tried it.

    Code:
    getMaterial
     
    public Material getMaterial()
    Convenience method. Returns the material of the item represented by this event
    Returns:
    Material the material of the item used
    
     
  22. Offline

    the_merciless

    event.getType is the same as saying get the type of the playerinteractevent. you have to specify what you are trying to get they type of. event.getBlock().getType() is saying get the block involved in the event and then get the type of it
     
  23. Offline

    trusebruse

    Well, all these things i just messing everything up.
    One says do this when another says do this, then come the third and the fourth and says do this. I do not know what to do at all know. Please just tell me what i did wrong and what i should write.
     
  24. Offline

    the_merciless

    This should work for you

    Code:
    package me.trusebruse.NoEnchantmentTable;
     
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
        public final class NoEnchantmentTable extends JavaPlugin implements Listener{
         
            public final Logger logger = Logger.getLogger("Minecraft");
            public static NoEnchantmentTable plugin;
     
         
       
         
       
            @Override
            public void onEnable(){
                this.logger.info("NoEnchantmentTable is enabled.");
                plugin.getServer().getPluginManager().registerEvents(this, this);
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            }
       
         
         
         
         
            @Override
            public void onDisable(){
                this.logger.info("NoEnchantmentTable is disabled.");
     
                // TODO Insert logic to be performed. (THIS LINE IS A NOTE, YOU MAY DELETE IT)
            } 
       
         
         
         
         
            @EventHandler
            public void oninteract (PlayerInteractEvent event){    //This line is naming the event "oninteract" and stating what event you wish to use
             
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK){                        //this line is checking if the player right clicked a block
                 
                    if (event.getClickedBlock().getType().equals(Material.ENCHANTMENT_TABLE)) {    //this is checking if the player clicked a enchantment table
                     
                        event.setCancelled(true);  //if both of the above are true, this will cancel the event and stop anything happening
                     
                        event.getPlayer().sendMessage("You can not open Enchantment tables.");  //this will send this message to the player involved
                    }
                }
            }
        }
    
    Copy and paste it, remove the comments after reading and you are good to go.

    1000-1 odds on the fact he has made a plugin.yml (One that works)

    Anyone???

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

    brord

    Correct plugin.yml:

    Code:
     
    name: NoEnchantmentTable
    version: 0.1
    main: me.trusebruse.NoEnchantmentTable
    authors: [the_merciless]
    
     
  26. Offline

    trusebruse

    I can still open enchantment tables.
     
  27. Offline

    the_merciless

    Code:

    name: NoEnchantmentTable
    version: 0.1
    main: me.trusebruse.NoEnchantmentTable
    authors: [the_merciless] [trusebruse]


    he deserves a little credit, for the idea atleast

    Copy and paste your server.log

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

    trusebruse

    No it would be:
    Code:
    NoEnchantmentTable
    main: me.trusebruse.NoEnchantmentTable.NoEnchantmentTable
    version: 1.0
    description: >
                You can not open Enchantment tables.
    authors: [the_merciless]
    
    The plugin loads but i can open Enchantment tables.

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

    NinjaW0lf

    Do you just look at things and try to fuck it up...
     
  30. Offline

    trusebruse

    ?
     
Thread Status:
Not open for further replies.

Share This Page