Jump to content

Recommended Posts

Posted

my code so far my PlayerInteractEvent is not getting called and i got banned on bukkit forums for posting this same question

package me.marshall;

 

import org.bukkit.Material;

import org.bukkit.command.Command;

import org.bukkit.command.CommandSender;

import org.bukkit.entity.Player;

import org.bukkit.event.EventHandler;

import org.bukkit.event.EventPriority;

import org.bukkit.event.Listener;

import org.bukkit.event.block.Action;

import org.bukkit.event.player.PlayerInteractEvent;

import org.bukkit.plugin.PluginManager;

import org.bukkit.plugin.java.JavaPlugin;

 

public class Main extends JavaPlugin implements Listener{

   

    @Override

    public void onEnable(){

        PluginManager pm = this.getServer().getPluginManager();

        pm.registerEvents(PlayerInteractEvent, this);

        getLogger().info("SenseRestrict has been Enabled.");

    }

   

    @Override

    public void onDisable(){

        getLogger().info("SenseRestrict has been Disabled.");

    }

   

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

        Player user = (Player) sender;

        if(cmd.getName().equalsIgnoreCase("restricted")){

            user.sendMessage("§a§m---------------------------------------------");

            user.sendMessage("§2->§4 Banned-Items:");

            user.sendMessage("§2->§4 add some items here");

            user.sendMessage("§a§m---------------------------------------------");

            return true;

        }

        return false;

    }

 

    @EventHandler(priority=EventPriority.HIGH)

    public void onPlayerClickItem(PlayerInteractEvent e) {

        Player user = e.getPlayer();

        if(user.getItemInHand().equals(Material.DIRT) && e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR)|| e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){

            user.sendMessage("§a§m---------------------------------------------");

            user.sendMessage("§2->§4 That item can only be used in crafting.");

            user.sendMessage("§a§m---------------------------------------------");

        }

   

    }

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...