我正在尝试存储游戏中放置的所有块,然后当我运行命令resetblocks时,或者如果游戏不再运行,我将删除存储在HashMap中的所有块。
这是我存储块的方式。我只是不知道如何遍历HashMap并销毁每个块。
public HashMap<Block, Location> BlockReset = new HashMap<>();
// WHEN PLACED BLOCK
public void onPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
Location location = block.getLocation();
if (gameRunning == true) {
BlockReset.put(block, location);
}
}
答案 0 :(得分:0)
我不知道关于我的世界的事情,我检查了关于Block界面的javadoc并且找不到删除方法或类似的东西。我想你知道如何处理这个问题。相反,我帮助你使用地图:
class Plugin {
private Map<Block, Location> blocks = new HashMap<>();
public void onPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
Location location = block.getLocation();
if (gameRunning == true) {
blocks.put(block, location);
}
}
public removeAllBlocks() {
for(Map.Entry<Block, Location> entry : blocks.entrySet()) {
Block block = entry.getKey();
Location location entry.getValue();
block. // do what do you want with block and location
location. // block.delete() or other minecraft things
}
blocks.clear(); //removes all entries from map, now map is clear;
}
}
答案 1 :(得分:0)
您不需要HashMap随后保存和销毁块,因为只是位置很重要。
创建and
并按照以下方式执行操作:
List<Location>
此致