gpt4 book ai didi

java - Minecraft 插件 WorldEdit 获取区域

转载 作者:行者123 更新时间:2023-12-01 11:24:40 25 4
gpt4 key购买 nike

我正在尝试解析区域的所有者,到目前为止我一直在尝试选择区域,这是我的代码:

package pl.maccraft.regs;


import java.util.logging.Logger;

import net.milkbowl.vault.economy.Economy;

import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;

import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import org.bukkit.plugin.Plugin;



public final class egs extends JavaPlugin implements Listener {
private static final Logger log = Logger.getLogger("Minecraft");
public static Economy econ = null;
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
getWorldGuard();
if (!setupEconomy() ) {
log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
getServer().getPluginManager().disablePlugin(this);
return;
}
}
private WorldGuardPlugin getWorldGuard() {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");

// WorldGuard may not be loaded
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return null; // Maybe you want throw an exception instead
}

return (WorldGuardPlugin) plugin;

}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
@EventHandler
public void playerInteract(PlayerInteractEvent event){
Player player = event.getPlayer();
if(event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK){
Block b = event.getClickedBlock();
if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
Sign sign = (Sign) b.getState();
if (sign.getLine(0).equals("[sell]")){
event.setCancelled(true);
RegionContainer container = getWorldGuard().getRegionContainer();
RegionManager regions = container.get(world);
if (regions != null) {
ProtectedRegion region = regions.getRegion("spawn");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + region);
} else {
// The world has no region support or region data failed to load
}
sign.setLine(0, ChatColor.DARK_RED + "[sprzedam]");
sign.setLine(1, player.getName());
sign.setLine(3, ChatColor.DARK_RED + sign.getLine(2));
sign.update(true);

}
}
}
if(event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK){
Block b = event.getClickedBlock();
if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
Sign sign = (Sign) b.getState();
if (sign.getLine(0).equals(ChatColor.DARK_RED + "[sprzedam]")){
if (event.getPlayer().getName() != sign.getLine(1)){
sign.setLine(0, ChatColor.DARK_RED + "[sprzedane]");
sign.setLine(2, event.getPlayer().getName());
sign.update(true);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + econ.getBalance(player));
}else{
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say nie możesz kupić własnej działki");
}
}
}
}


}

}

问题出在这部分:

RegionContainer container = getWorldGuard().getRegionContainer();
RegionManager regions = container.get(world);
if (regions != null) {
ProtectedRegion region = regions.getRegion("spawn");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + region);
} else {
// The world has no region support or region data failed to load
}

世界下方有红色下划线,当我将其悬停时,它会给出以下信息:世界无法解析为变量。我不明白为什么会发生这种情况,因为这是从 WorldGuard API 页面复制过去的 - http://docs.enginehub.org/manual/worldguard/latest/developer/regions/managers/请帮助我

最佳答案

WorldGuard API 中通过名称获取区域的代码只是一个示例。您的 IDE 正在提示,因为它实际上无法找到您传递给 get() 方法的名为 world 的变量。您需要向 container.get(world) 方法提供您自己的 world 对象,在本例中,该对象可能是事件监听器方法中玩家的世界。例如:container.get(player.getWorld()); 可能会起作用。

关于java - Minecraft 插件 WorldEdit 获取区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30925555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com