Need help with disabling interaction with blocks

Discussion in 'Plugin Development' started by Nerdfuryz, Mar 15, 2013.

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

    Nerdfuryz

    Code:
    public class nohopper extends JavaPlugin
    implements Listener{
        public static Logger logger = Logger.getLogger("Minecraft");
       
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            nohopper.logger.info(pdfFile.getName() + "Has been Enabled! (Nerdfuryz)");
            logger.info("[NoHopper] Second Plugin made by NerdFuryz");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
           
        }
          @EventHandler
          public void blockplace(BlockPlaceEvent event)
          {
            if (event.getBlock().getType().equals(Material.HOPPER) && event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
              event.getPlayer().sendMessage(ChatColor.RED + "We have disabled this block until March 25th due to glitches");
              event.setCancelled(true);
              }
            }
              @EventHandler
              public void blockplace1(BlockPlaceEvent event)
              {
                if (event.getBlock().getType().equals(Material.TRAPPED_CHEST) && event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
                  event.getPlayer().sendMessage(ChatColor.RED + "We have disabled this block until March 25th due to glitches");
                  event.setCancelled(true);
                }
          }
              @EventHandler
              public void onPlayerInteractEvent(PlayerInteractEvent e) {
                if(e.getItem() != null){
                if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
                    (e.getItem().getType().equals(Material.POTION))) {
                    e.getPlayer().sendMessage(ChatColor.RED + "You're not allowed to use potions in Creative on DranCraft!");
                    e.getPlayer().getInventory().removeItem(new ItemStack[] { e.getItem() });
                    e.setCancelled(true);
                }
                }
                }
                @EventHandler
                public void onPlayerEvent(PlayerInteractEvent e) {
                if(e.getItem() != null){
                if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
                  (e.getItem().getType().equals(Material.HOPPER))) {
                    e.getPlayer().sendMessage(ChatColor.GOLD + "You're not allowed to shoot arrows in Creative on DranCraft!");
                    e.setCancelled(true);
                    }
                    }
                }
    What I am attempting to do is disable interaction and placement of both the hopper and trap chest temporarily until a plugin fixes dupe glitch. Can someone please correct this for me so it actually works?
     
  2. Offline

    minoneer

    Well,

    Well, we can try, if you tell us what's wrong. Are there any error logs? What exactly is not working? btw, is it intentional, that only player in creative are not allowed to set those blocks, while player in survival are allowed to?
     
  3. Offline

    Nerdfuryz

    Yes and I got the placement block correct it is just the interaction I don't get how to do. So I need someone to do that part for me.
     
  4. Offline

    minoneer

    You most likely will not find anyone here "to do it for you". We are happy to help and point you in the direction, but you'll have to do it yourself. That way you'll even learn something from it :)


    and again my question: are there any error logs? what exactly is not working? how did you test it?
     
  5. Offline

    Nerdfuryz

    Again I need a way to deny the interaction with the blocks at the end.
     
  6. Offline

    Technius

    Nerdfuryz You don't need to have two methods for the same event.

    Are you getting sent the messages?
     
  7. Offline

    Nerdfuryz

    Can someone please just correct it, I really have no idea how to continue or make it work better.
     
  8. Offline

    Brian_Entei

    To set out to do something, then rely on others to finish it is to not live life(i.e. being lazy). By asking someone to just do it for you is not far from asking someone to do it all for you. You need to get more familiar with Java, then come back and look at your code and try to figure it out on your own. That's how most successful people get life's tasks and problems completed. Basically, what I'm saying here is, don't give up until you are absolutely sure that it isn't possible, then try three more times just to be sure. Never give up!

    EDIT: Also, I forgot to say, if we don't know the EXACT problem, then we can't very well give you an EXACT solution, now can we? That's how it is with coding.
     
Thread Status:
Not open for further replies.

Share This Page