我对使用JAVA编码非常陌生。欢迎任何提示!这是我的问题: 我正在重新创建一个名为“捉迷藏”的游戏。该插件的基本功能是:将信标放下-保存坐标和放置器名称。在信标中断时,喊出打破信标的人,那是谁的信标。起作用的部分是它应该喊出信标是谁的东西。它没有发布任何内容。这是我的代码:
Main.java
package org.mcuniversitydev.openhoh;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcuniversitydev.openhoh.listeners.beaconlistener.BeaconListener;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
new BeaconListener(this);
}
}
BeaconListener.java
package org.mcuniversitydev.openhoh.listeners.beaconlistener;
import org.bukkit.Bukkit;
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;
import org.mcuniversitydev.openhoh.Main;
@SuppressWarnings("unused")
public class BeaconListener implements Listener {
String[][][] beacons = {};
private Main plugin;
public BeaconListener(Main plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player p = e.getPlayer();
int bcc[] = {e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ()};
int x = bcc[0];
int y = bcc[1];
int z = bcc[2];
if (e.getBlock().getType() == Material.BEACON) {
beacons[x][y][z]=e.getPlayer().getDisplayName();
} else if (e.getBlock().getType() == Material.CRAFTING_TABLE || e.getBlock().getType() == Material.BLAST_FURNACE || e.getBlock().getType() == Material.FURNACE || e.getBlock().getType() == Material.ENCHANTING_TABLE || e.getBlock().getType() == Material.ANVIL || e.getBlock().getType() == Material.DAMAGED_ANVIL || e.getBlock().getType() == Material.CHIPPED_ANVIL) {
if(p.getLocation().getWorld().getBlockAt(x-1,y,z).getType() == Material.BEACON){
} else if(p.getLocation().getWorld().getBlockAt(x+1,y,z).getType() == Material.BEACON){
} else if(p.getLocation().getWorld().getBlockAt(x,y-1,z).getType() == Material.BEACON){
} else if(p.getLocation().getWorld().getBlockAt(x,y+1,z).getType() == Material.BEACON){
} else if(p.getLocation().getWorld().getBlockAt(x,y,z-1).getType() == Material.BEACON){
} else if(p.getLocation().getWorld().getBlockAt(x,y,z+1).getType() == Material.BEACON){
} else {
e.getBlock().breakNaturally();
p.sendMessage("You can only place this at your beacon!");
}
}
}
@EventHandler
//@SuppressWarnings("unused")
public void onBlockBreak(BlockBreakEvent e) {
Player p = e.getPlayer();
int bcc[] = {e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ()};
int x = bcc[0];
int y = bcc[1];
int z = bcc[2];
if (e.getBlock().getType() == Material.BEACON) {
if (e.isCancelled()) {
for (int i = 0;i<beacons.length;i++) {
for (int ii = 0;ii<beacons[i].length;ii++) {
for (int iii = 0;iii<beacons[i][i].length;iii++) {
if (i == x) {
if (ii == y) {
if (iii == z) {
final String bname=beacons[i][ii][iii];
//Bukkit.getOnlinePlayers().forEach(all -> {
// all.sendMessage(p.getDisplayName() + " has broken " + bname + "\'s beacon!");
//
//});
p.sendMessage("Common! You can do it! You allmost destroyed a beacon! It belongs to " + bname + "!");
}
}
}
}
}
}
} else {
//String bname = "";
for (int i = 0;i<beacons.length;i++) {
for (int ii = 0;ii<beacons[i].length;ii++) {
for (int iii = 0;iii<beacons[i][i].length;iii++) {
if (i == x) {
if (ii == y) {
if (iii == z) {
final String bname=beacons[i][ii][iii];
Bukkit.getOnlinePlayers().forEach(all -> {
all.sendMessage(p.getDisplayName() + " has broken " + bname + "\'s beacon!");
});
}
}
}
}
}
}
p.sendMessage("YES! You broke a beacon! Good job!");
}
}
}
}
提示和帮助,thnx。 :D