Ir para conteúdo
  • 0

[Resolvido] [Dúvida] WorldGuard


TequilAxBr

Pergunta

Olá, estou afzendo um plugin de terrenos e estou tendo problemas com a verificação de regions por perto, ela funciona, porem se o dono da region por perto for o cara que digitou o comando para comprar o terreno, não funciona...

Alguém sabe algo a respeito?

 

Verificação que estou fazendo:

		ApplicableRegionSet regions2 = rm.getApplicableRegions(pr); // pr = ProtectecCuboidRegion
		LocalPlayer localPlayer2 = plugin.getWorldGuard().wrapPlayer(p);
		if (!regions2.isOwnerOfAll(localPlayer2)){
			p.sendMessage(prefix + "§fSe afaste, existe terrenos nas redondezas.");
			rm.removeRegion(areaNome);
			return;
		}

Metodo completo:

	public void BuyTerreno(String area, int x, int z, Player p){
		RegionManager rm = plugin.getWorldGuard().getRegionManager(p.getWorld());
		String areaNome = p.getName().toLowerCase() + "_" + area.toLowerCase();
		if (hasArea(areaNome, p.getWorld().getName())) {
			p.sendMessage(prefix + "§fVocê já possui um terreno com esse nome.");
			return;
		}
		
		Location loc = p.getLocation();
		int x2 = loc.getBlockX();
		int z2 = loc.getBlockZ();
		BlockVector blockVector1 = new BlockVector(x2 - x/2, 256, z2 - z/2);
		BlockVector blockVector2 = new BlockVector(x2 + x/2, 0, z2 + z/2);

		ProtectedCuboidRegion pr = new ProtectedCuboidRegion(areaNome, blockVector1, blockVector2);
		DefaultDomain dM = new DefaultDomain();
		rm.addRegion(pr);
		pr.setPriority(100);
		dM.addPlayer(p.getName());
		pr.setOwners(dM);
		
		try{
			pr.setFlag(DefaultFlag.PVP, DefaultFlag.PVP.parseInput(plugin.getWorldGuard(), p, "deny"));
			pr.setFlag(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE.parseInput(plugin.getWorldGuard(), p, "deny"));
			pr.setFlag(DefaultFlag.TNT, DefaultFlag.TNT.parseInput(plugin.getWorldGuard(), p, "deny"));
			pr.setFlag(DefaultFlag.CREEPER_EXPLOSION, DefaultFlag.CREEPER_EXPLOSION.parseInput(plugin.getWorldGuard(), p, "deny"));
			pr.setFlag(DefaultFlag.USE, DefaultFlag.USE.parseInput(plugin.getWorldGuard(), p, "deny"));
		} catch (InvalidFlagFormat e) {
			e.printStackTrace();
		}
		ApplicableRegionSet regions2 = rm.getApplicableRegions(pr); // pr = ProtectecCuboidRegion
		LocalPlayer localPlayer2 = plugin.getWorldGuard().wrapPlayer(p);
		if (!regions2.isOwnerOfAll(localPlayer2)){
			p.sendMessage(prefix + "§fSe afaste, existe terrenos nas redondezas.");
			rm.removeRegion(areaNome);
			return;
		}

		try {
			rm.save();
		} catch (StorageException e) {
			e.printStackTrace();
		}

		makeMuro(p, x);
		p.sendMessage(prefix + "§fVocê compro um §eterreno §fcom sucesso.");
	}

Sim, eu sei que estou verificando se o dono das regions por perto foi diferente do nick do player, porem já olhei a src do HTerrenos e de outros plugins e todos fazem da mesma forma...

Alguém sabe uma solução para esse bug?

 

Versões dos plugins:

WorldGuard - 6.1

WorldEdit - 6.1

Editado por TequilAxBr
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados


O Ideal é vc usar intersections, independente se o dono é o mesmo ou não, como vc faz aqui:

if (!regions2.isOwnerOfAll(localPlayer2)){

As variaveis não são iguais as suas, mas da pra ter uma noção de como fazer.

 

Exemplo:

         RegionManager rm = AiQueVidaBandida.instancia.getWorldGuard().getRegionManager(p.getWorld());
        BlockVector min2 = new BlockVector(mr.pcr.getMinimumPoint().getBlockX() - 3, 0, mr.pcr.getMinimumPoint().getBlockZ() -3);
        BlockVector max2 = new BlockVector(mr.pcr.getMaximumPoint().getBlockX() + 3, 0, mr.pcr.getMaximumPoint().getBlockZ() +3);
        
        ProtectedCuboidRegion pcr1 = new ProtectedCuboidRegion(mr.pcr.getId()+"1", min2, max2);
        if(mr.terrenoOuExpandir >2){
            rm.removeRegion(mr.deletarExpandida.getId());
        }
        rm.addRegion(pcr1);
        ApplicableRegionSet set = rm.getApplicableRegions(pcr1);
        Intersections in = new Intersections(p, set, pcr1.getId(), pcr1, false);
        rm.removeRegion(pcr1.getId());
        if(!in.isOwnerOfAll && in.hasRegion || in.hasSubRegion){
           // p.sendMessage("§4Ocorreu um erro, nao foi possivel confirmar a compra, contate um administrador");
            p.sendMessage("§4Ah um terreno muito proximo! não foi possivel confirmar a compra!"); 

Vc vai precisar disso tb:

public class Intersections {

    public int size = 0;
    public boolean isOwnerOfAll = true;
    public boolean hasRegion = false;
    public boolean hasSubRegion = false;
    public boolean intersection3blocks = false;
    public ProtectedRegion subRegion = null;
    public ProtectedRegion region = null;
    public ProtectedCuboidRegion distancia = null;
    public String player;

    public Intersections(Player p, ApplicableRegionSet set, String ignorar, ProtectedCuboidRegion pcr, boolean Expandir) {
        this.distancia = pcr;
        this.player = p.getName();
        this.size = set.size();
        for (ProtectedRegion pr : set) {
            if (!pr.getId().equalsIgnoreCase(ignorar)) {
                if (!this.isInsideOF3Blocks(pr) || (p.getLocation().getBlockX() > pr.getMinimumPoint().getBlockX()
                        && p.getLocation().getBlockX() < pr.getMaximumPoint().getBlockX()
                        && p.getLocation().getBlockZ() > pr.getMinimumPoint().getBlockZ()
                        && p.getLocation().getBlockZ() < pr.getMaximumPoint().getBlockZ())) {
                    if (pr.getPriority() == 100) {
                        subRegion = pr;
                        hasSubRegion = true;
                    }
                    if (Expandir) {
                        if (pr.getPriority() == 50) {
                            if (!pr.getOwners().contains(p.getName().toLowerCase())) {
                                hasRegion = true;
                                region = pr;
                            }
                        }
                    } else {
                        if (pr.getPriority() == 50) {
                            hasRegion = true;
                            region = pr;
                        }
                    }
                } else {
                    this.intersection3blocks = true;
                }
                if (!pr.isOwner(p.getName())) {
                    isOwnerOfAll = false;
                }
            }
        }
    }

    public boolean isInsideRegion(Player p) {
        return p.getLocation().getBlockX() >= region.getMinimumPoint().getBlockX()
                && p.getLocation().getBlockZ() >= region.getMinimumPoint().getBlockZ()
                && p.getLocation().getBlockX() <= region.getMaximumPoint().getBlockX()
                && p.getLocation().getBlockZ() <= region.getMaximumPoint().getBlockZ();
    }

    private boolean isInsideOF3Blocks(ProtectedRegion pr) {
        return pr.getMinimumPoint().getBlockX() >= distancia.getMinimumPoint().getBlockX() - 3
                && pr.getMinimumPoint().getBlockZ() >= distancia.getMinimumPoint().getBlockZ() - 3
                && pr.getMaximumPoint().getBlockX() >= distancia.getMaximumPoint().getBlockX() - 3
                && pr.getMaximumPoint().getBlockZ() >= distancia.getMaximumPoint().getBlockZ() - 3;
    }

    public boolean isOneBlockInside(BlockVector min, BlockVector max) {
        return min.getBlockX() > region.getMinimumPoint().getBlockX() + 1 && min.getBlockZ() > region.getMinimumPoint().getBlockZ() + 1
                && max.getBlockX() < region.getMaximumPoint().getBlockX() - 1 && max.getBlockZ() < region.getMaximumPoint().getBlockZ() - 1;
    } 
Editado por ZidenVentania
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...