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

    the_merciless

    Lmao

    Your plugin yml is NOT right. Use any of the ones we just provided you
     
  2. Offline

    trusebruse

    What? My plugin.yml works. Is it necessary to use yours to make the plugin work?
     
  3. Offline

    the_merciless

    Do you get the message "you can not open Enchantment tables"?
     
  4. Offline

    trusebruse

    No.
     
  5. Offline

    the_merciless

    Paste all your code
     
  6. Offline

    trusebruse

    1. I tested you plugin.yml, Now i dont work.. gonna switch back
    2. Alright:
    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.Inventory;
    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 (Inventory event)
            {
               
            }  @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(ChatColor.AQUA + ("You can not open Enchantment tables."));  //this will send this message to the player involved
                        }
                    }
                }
            }
           
           
           
    
     
  7. Offline

    the_merciless

    DELETE EVERYTHING AND PASTE MY CODE IN, DO NOT EDIT IT
     
  8. Offline

    trusebruse

    Got no red lines, no errors.

    btw, i never understood what listener is. Can you please tell me? ;)

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

    TwistedMexi

    He used InventoryOpenEvent there because it works better for what he needs. From there he can check inventory type, if it's Enchantment he can cancel the event.
     
  10. Offline

    trusebruse

    Why can't i add a color code?
     
  11. Offline

    the_merciless

    You put an extra ( where it wasnt needed
     
  12. Offline

    trusebruse

    But it still dont work.
     
  13. Offline

    TwistedMexi

    Code:
    @EventListener
    public void openinv(InventoryOpenEvent ev){
            Inventory einv = ev.getInventory();
                if(einv.getType().equals(InventoryType.ENCHANTING))
                ev.setCancelled(true);
    }
    
     
  14. Offline

    the_merciless

    a Listener is what picks up the events, for example when a player moves it is the listener that recognises that the player has moved, or when you place a block. Essentialy it is the listeners job to pick up on the events that happen in the game.

    Please dont confuse things, there is no reason my code will not work for this. Your only making him go round in circles repeatedly changing his code

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

    TwistedMexi

    I didn't repeatedly change his code, nor am I "making him run around in circles", he shouldn't be using the playerInteractEvent, this is more efficient.
     
  16. Offline

    trusebruse

    I made a class next to the_merciless to try yours. It dont work because "void is an invalid type for the variable clickinv"
     
  17. Offline

    the_merciless

    It may be more effecient but its not helping at this moment, he doesnt understand comments, getting him to change half his code is only going to confuse him

    trusebruse, Please listen, do not change anything do not edit do not think you know better do not argue/disagree

    Delete ALL of your code and paste in mine. Then try it

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

    fireblast709

    trusebruse seriously not to troll you or anything, but a decent Java tutorial REALLY is adviced -_-
     
  19. Offline

    trusebruse

    Alright.

    But there is no code i can copy :3

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

    fireblast709

    trusebruse he means this code:
     
  21. Offline

    the_merciless

    no wait.....

    this code

    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;
     
     
     
     
     
            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)
            }
     
     
     
     
     
            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
                    }
                }
            }
        }
     
  22. Offline

    trusebruse

    Omg... It dont works.
     
  23. Offline

    TwistedMexi

    *doesn't. It doesn't work.

    and that doesn't tell us anything. You need to say WHY it doesn't work. What error are you getting?

    I believe you still have an incorrect plugin.yml
     
  24. Offline

    fireblast709

    the_merciless you forgot to check for right click air? Just brainstorming because that guy is not that much help (sorry, but it is true >_<). For the rest of my ridiculous post (ignore the rest), I go with an invalid plugin.yml
     
  25. Offline

    trusebruse

    Can you try open a server make this plugin and check by yourself?

    But because he told me to only copy the code and then try if it works by right clicking and only a message shows up, I dont have to tell him that nothing happens, i think he understand.

    EDIT: You know that it is wrong ingame right?

    So is this an incorrect plugin.yml?
    Code:
    name: NoEnchantmentTable
    main: me.trusebruse.NoEnchantmentTable.NoEnchantmentTable
    version: 1.0
    description: >
                You can not 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
  26. Offline

    NinjaW0lf

    Again, you keep modifing code they give you., Delete the description part
     
  27. Offline

    fireblast709

    trusebruse the event itself works, except one line
    the_merciless you throw a NPE here:
    Code:java
    1. plugin.getServer().getPluginManager().registerEvents(this, this);

    trusebruse change the above line to:
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
    TwistedMexi likes this.
  28. Offline

    the_merciless

    ok this 1 is tested and working use the following

    Code:
    package me.trusebruse.NoEnchantmentTable;
     
    import java.util.logging.Logger;
     
    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;
       
            public void onEnable(){
                this.logger.info("NoEnchantmentTable is enabled.");
                getServer().getPluginManager().registerEvents(this, this);
            }
           
            public void onDisable(){
                this.logger.info("NoEnchantmentTable is disabled.");
            }
     
               
            @EventHandler
            public void oninteract (PlayerInteractEvent event){ 
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK){                               
                    if (event.getClickedBlock().getType().equals(Material.ENCHANTMENT_TABLE)) {
                        event.setCancelled(true); 
                        event.getPlayer().sendMessage("You can not open Enchantment tables.");
                    }
                }
            }
        }
     
    
     
  29. Offline

    trusebruse

    Oh my god! I am so happy because nothing changed except some words in the yml... -.-
     
  30. Offline

    the_merciless

    ye i just caught that, i copied someones code posted earlier and never spotted that.
     
Thread Status:
Not open for further replies.

Share This Page