Ir para conteúdo
  • 0

[Resolvido] Olha eu aqui de novo :D - SignChangeEvent e PlayerInteractEvent


Dery

Pergunta

Bem estou criando um novo plugin, e estou com problemas para adicionar uma permissão para criar a placa e para quando o player clicar com o direito nela o console dar uns comandos, aqui o código que estou usando:

@EventHandler
		public void Placa(SignChangeEvent e){
			Player p = e.getPlayer();
			World mundo = e.getBlock().getWorld();
			double x = e.getBlock().getX();
			double y = e.getBlock().getY();
			double z = e.getBlock().getZ();
			if(e.getLine(0).equalsIgnoreCase("[Placa]")){
				if(p.hasPermission(getConfig().getString("Config.Permissao"))){
					e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
					e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
					e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
					e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
					p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
				}else{
					p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
					e.setCancelled(true);
				}
			}
		}
	
	@EventHandler
	public void PlacaInteract(PlayerInteractEvent e){
		if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
        if (e.getClickedBlock().getState() instanceof Sign){
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(0).equalsIgnoreCase(getConfig().getString("Config.Placa.Linha1"))){
                        for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
                        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
                        }
                }
		}
	}

A parte do PlayerInteractEvent que estou tendo problema é a de dar os comandos via cmd:

for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
                        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));

HELP?

Link para o comentário
Compartilhar em outros sites

16 respostass a esta questão

Posts Recomendados


@EventHandler

public void PlacaInteract(PlayerInteractEvent e){

if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;

if (e.getClickedBlock().getState() instanceof Sign){

Sign s = (Sign) e.getClickedBlock().getState();

if (s.getLine(0).equalsIgnoreCase("[Placa]")){

for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){

Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));

}

}

}

}

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

	@EventHandler
	public void PlacaInteract(PlayerInteractEvent e){
		if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
        if (e.getClickedBlock().getState() instanceof Sign){
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(0).equalsIgnoreCase("[Placa]")){
                        for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
                        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
                        }
                }
		}
	}

A linha que o cara interagir teve esta escrito do msm jeito que você criou

 

Ok, mas e a permissão?

Link para o comentário
Compartilhar em outros sites

Ok, mas e a permissão?

@EventHandler
		public void Placa(SignChangeEvent e){
			Player p = e.getPlayer();
                        if(!p.hasPermission("Criar.placa")return;
			World mundo = e.getBlock().getWorld();
			double x = e.getBlock().getX();
			double y = e.getBlock().getY();
			double z = e.getBlock().getZ();
			if(e.getLine(0).equalsIgnoreCase("[Placa]")){
				if(p.hasPermission(getConfig().getString("Config.Permissao"))){
					e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
					e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
					e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
					e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
					p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
				}else{
					p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
					e.setCancelled(true);
				}
			}
		}
Link para o comentário
Compartilhar em outros sites

@EventHandler
		public void Placa(SignChangeEvent e){
			Player p = e.getPlayer();
                        if(!p.hasPermission("Criar.placa")return;
			World mundo = e.getBlock().getWorld();
			double x = e.getBlock().getX();
			double y = e.getBlock().getY();
			double z = e.getBlock().getZ();
			if(e.getLine(0).equalsIgnoreCase("[Placa]")){
				if(p.hasPermission(getConfig().getString("Config.Permissao"))){
					e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
					e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
					e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
					e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
					p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
				}else{
					p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
					e.setCancelled(true);
				}
			}
		}

Não funcionou

Link para o comentário
Compartilhar em outros sites

Guest ThePeppernut
if(e.getLine(0).equalsIgnoreCase("[Placa]")){
				if(p.hasPermission("evento.criar"){
					e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
					e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
					e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
					e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
					p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
				}else{
					p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
					e.setCancelled(true);

				}
			}

Você também esqueceu de quebrar a placa caso o player não tenha permissão, essa funcionabilidade foi adicionada neste segundo cógio (que já tem a correção do seu BUG também):

if(e.getLine(0).equalsIgnoreCase("[Placa]")){
				if(p.hasPermission("evento.criar"){
					e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
					e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
					e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
					e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
					p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
				}else{
					p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
					e.setCancelled(true);
                                        e.getBlock().breakNaturally();

				}
			}
Link para o comentário
Compartilhar em outros sites

@EventHandler
	public void PlacaInteract(PlayerInteractEvent e){
		if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
        if (e.getClickedBlock().getState() instanceof Sign){
                Sign s = (Sign) e.getClickedBlock().getState();

                //Adicionei a perm aqui:
                if (s.getLine(0).equalsIgnoreCase(getConfig().getString("Config.Placa.Linha1") 
                && e.getPlayer.HasPermission("myplugin.command." + s.getLine(0))){ //Verificar se o player pode usar o comando que esta na primeira linha da placa, ou se pode usar a placa!
                        for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
                        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
                        }
                }
		}
	}

Parece simples. Adicionei a verificação da permissão no seu codigo, sem alterar nada. Qual o problema ao executar os comandos? O IDE(Eclipse) não ta ajudando?

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

Guest ThePeppernut

Sobre ao clicar na placa, você quere que quando o player clique nela ele vença o evento, receba money, feche o evento e teleporte o resto para o spawn?

 


 

 

 

@EventHandler
    public void PlacaInteract(PlayerInteractEvent e){
        if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
if (e.getClickedBlock().getState() instanceof Sign){
Sign s = (Sign) e.getClickedBlock().getState();

//Adicionei a perm aqui:
if (s.getLine(0).equalsIgnoreCase(getConfig().getString("Config.Placa.Linha1")
&& e.getPlayer.HasPermission("myplugin.command." + s.getLine(0))){ //Verificar se o player pode usar o comando que esta na primeira linha!
for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
}
}
        }
    }

Parece simples. Adicionei a verificação da permissão no seu codigo, sem alterar nada. Qual o problema ao executar os comandos? O IDE(Eclipse) não ta ajudando?

 

 

Se eu não me engano, ele quer adicionar permissão para o player criar a placa.

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

@EventHandler
	public void PlacaInteract(PlayerInteractEvent e){
		if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
        if (e.getClickedBlock().getState() instanceof Sign){
                Sign s = (Sign) e.getClickedBlock().getState();

                //Adicionei a perm aqui:
                if (s.getLine(0).equalsIgnoreCase(getConfig().getString("Config.Placa.Linha1") 
                && e.getPlayer.HasPermission("myplugin.command." + s.getLine(0))){ //Verificar se o player pode usar o comando que esta na primeira linha da placa, ou se pode usar a placa!
                        for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
                        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
                        }
                }
		}
	}

Parece simples. Adicionei a verificação da permissão no seu codigo, sem alterar nada. Qual o problema ao executar os comandos? O IDE(Eclipse) não ta ajudando?

 

Ele não está "detectando" a primeira linha da placa, já tentei das duas maneiras, "[Placa]" e "getConfig().getString("Config.Placa.Lina1")" mas não detecta a primeira linha da placa

Link para o comentário
Compartilhar em outros sites

Ele não está "detectando" a primeira linha da placa, já tentei das duas maneiras, "[Placa]" e "getConfig().getString("Config.Placa.Lina1")" mas não detecta a primeira linha da placa

Aqui nessa parte:

if (e.getClickedBlock().getState() instanceof Sign){

Tira o ".getState()" pois isso não retorna Sign, mas o "getClickedBlock()" sim!

Link para o comentário
Compartilhar em outros sites

 

 

 

 

 

Bem estou criando um novo plugin, e estou com problemas para adicionar uma permissão para criar a placa e para quando o player clicar com o direito nela o console dar uns comandos, aqui o código que estou usando:

@EventHandler
        public void Placa(SignChangeEvent e){
            Player p = e.getPlayer();
            World mundo = e.getBlock().getWorld();
            double x = e.getBlock().getX();
            double y = e.getBlock().getY();
            double z = e.getBlock().getZ();
            if(e.getLine(0).equalsIgnoreCase("[Placa]")){
                if(p.hasPermission(getConfig().getString("Config.Permissao"))){
                    e.setLine(0, getConfig().getString("Config.Placa.Linha1").replace("&", "§"));
                    e.setLine(1, getConfig().getString("Config.Placa.Linha2").replace("&", "§"));
                    e.setLine(2, getConfig().getString("Config.Placa.Linha3").replace("&", "§"));
                    e.setLine(3, getConfig().getString("Config.Placa.Linha4").replace("&", "§"));
                    p.sendMessage(getConfig().getString("Mensagens.Placa.Change").replace("&", "§").replace("@mundo", mundo.getName()).replace("@x", df.format(x)).replace("@y", df.format(y)).replace("@z", df.format(z)));
                }else{
                    p.sendMessage(getConfig().getString("Mensagem.SemPermissao").replace("&", "§"));
                    e.setCancelled(true);
                }
            }
        }
    
    @EventHandler
    public void PlacaInteract(PlayerInteractEvent e){
        if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
if (e.getClickedBlock().getState() instanceof Sign){
Sign s = (Sign) e.getClickedBlock().getState();
if (s.getLine(0).equalsIgnoreCase(getConfig().getString("Config.Placa.Linha1"))){
for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));
}
}
        }
    }

A parte do PlayerInteractEvent que estou tendo problema é a de dar os comandos via cmd:

for(String cmds : getConfig().getStringList("Config.Placa.Comandos")){
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds.replace("@player", e.getPlayer().getName()));

HELP?

 

 

Resolvido?!

Link para o comentário
Compartilhar em outros sites

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