Permission help

Any help topics that don't fit in the current categories can go here.
Post Reply
KillzyazMadness
Posts: 3
Joined: Sun Mar 25, 2012 4:17 pm

Permission help

Post 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?
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

Re: Permission help

Post 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
Post Reply