我对编码很新,我似乎无法找出为什么我的工作会出现语法错误。它说:语法错误,插入“}”来完成类体。这是我的代码:
package me.koda;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener implements Listener {
public BlockListener(AntiBlock plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
if (!player.hasPermission("playerAbilities.allowed")) {
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Place Blocks!");
e.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
if (!player.hasPermission("playerAbilities.allowed")) {
}
{
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Break Blocks!");
e.setCancelled(true);
}
} // <-- this one
@EventHandler
public void onBedrockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
if(e.getBlock().getType() == Material.BEDROCK) {
if (!player.hasPermission("playerAbilities.allowed")) {
player.sendMessage(ChatColor.RED + "You Cannot Place " + e.getBlock().getType().toString() + " Down!");
e.setCancelled(true);
} else player.sendMessage(ChatColor.GREEN + "You May Place " + e.getBlock().getType().toString() + " Down!");
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Place Blocks!");
e.setCancelled(true);
} // <--- this one
就像我说我对此非常新,我得到的所有帮助都非常感谢! 感谢
答案 0 :(得分:0)
你有大括号的几个问题,所以我修复了你的代码:
package me.koda;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockListener implements Listener {
public BlockListener(AntiBlock plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
if (!player.hasPermission("playerAbilities.allowed")) {
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Place Blocks!");
e.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
if (!player.hasPermission("playerAbilities.allowed")) {
}
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Break Blocks!");
e.setCancelled(true);
}
@EventHandler
public void onBedrockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
if(e.getBlock().getType() == Material.BEDROCK) {
if (!player.hasPermission("playerAbilities.allowed")) {
player.sendMessage(ChatColor.RED + "You Cannot Place " + e.getBlock().getType().toString() + " Down!");
e.setCancelled(true);
} else {
player.sendMessage(ChatColor.GREEN + "You May Place " + e.getBlock().getType().toString() + " Down!");
}
player.sendMessage(ChatColor.RED + "You, " + ChatColor.GOLD + player.getName() + ChatColor.RED + " Cant Place Blocks!");
e.setCancelled(true);
}
}
}
将您的代码与此进行比较,您将找出问题所在。