Page 1 of 1

Permission help

Posted: Sat Mar 31, 2012 3:03 am
by KillzyazMadness
I'm making a plugin for my server that prevents the placing of certain blocks, but I'm getting an error as I'm trying to add permissions to it and I'm new to Java and don't know what to do, I get this error:

"player cannot be resolved"

I have put a " *** " around the player instance it is saying gives the error here is code:
package me.killzyazmadness.BlockPrevention;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
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.BlockPlaceEvent;

public class BlockPreventionBedrockListener implements Listener {
 
    @EventHandler(priority = EventPriority.HIGH)
    public void onBlockPlace(BlockPlaceEvent event){
        if (event.isCancelled())return;
     
        if(***player***.hasPermission("blockprevention.place")) {
            if (event.getBlock().getType() == Material.BEDROCK){
                event.setCancelled(false); }
         
        }else{
     
            if (event.getBlock().getType() == Material.BEDROCK){
            event.setCancelled(true);
        }
            Player player = event.getPlayer();
         
            player.sendMessage(ChatColor.RED + "Bedrock is not allowed!");
         
            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()){
                if (onlinePlayer.equals(player) == false){
                    onlinePlayer.sendMessage(ChatColor.RED + player.getName() + "just tried placing Bedrock!");
                }
            }
        }
    }
}
Anyone know what to do to fix this?

Re: Permission help

Posted: Sat Mar 31, 2012 9:37 am
by offluffy
It looks like the "player" variable is initialized after that if statement, so at that point, the plugin doesn't know what "player" is.

Just try moving line 27 up above line 18 somewhere XD