Ir para conteúdo
  • 0

[Duvida] Executar comando apos jogador quebrar uma quantia de blocos!


yLR111

Pergunta

7 respostass a esta questão

Posts Recomendados

  • 0

1. Pegue o jogador e armazene em uma HashMap (ao reiniciar os dados são apagados) ou em um arquivo (para que fiquem salvos)

2. Use o evento de quebrar um bloco para registrar no armazenamento o valor atual + 1

3. Verifique se o jogador atingiu uma quantidade X de blocos.

4. Caso a resposta seja sim, use o dispatchCommand para executar o comando.

Link para o comentário
Compartilhar em outros sites

  • 0

 

Simplificando o que o @JoaoY disse acima

	public HashMap<UUID, Integer> blocks = new HashMap<>();
	
	public void blockBreak(BlockBreakEvent e) {
		if (blocks.containsKey(e.getPlayer().getUniqueId())) {
			int atual = blocks.get(e.getPlayer().getUniqueId());
			blocks.remove(e.getPlayer().getUniqueId());
			blocks.put(e.getPlayer().getUniqueId(), atual++);
		} else {
			blocks.put(e.getPlayer().getUniqueId(), 1);
		}
		
		if (blocks.get(e.getPlayer().getUniqueId()) >= 1000) {
			Bukkit.dispatchCommand(e.getPlayer(), "player command");
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "console command");
		}
	}

testei, mas nao funcionou

package me.leo.api;

import java.util.HashMap;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class RewardOnMine implements Listener {
	
	public HashMap<UUID, Integer> blocks = new HashMap<>();
	
	@EventHandler
	public void blockBreak(BlockBreakEvent e) {
		Player p = e.getPlayer();
		Block block = e.getBlock();
		if(block.getType().equals(Material.LAPIS_ORE)) {
			if (blocks.containsKey(e.getPlayer().getUniqueId())) {
				int atual = blocks.get(e.getPlayer().getUniqueId());
				blocks.remove(e.getPlayer().getUniqueId());
				blocks.put(e.getPlayer().getUniqueId(), atual++);
			} else {
				blocks.put(e.getPlayer().getUniqueId(), 1);
			}
			
			if (blocks.get(e.getPlayer().getUniqueId()) >= 15) {
				Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "givecaixa Norm 1 " + p.getPlayer().getName());
				Bukkit.broadcastMessage("§a§lTESTE DE BLOCOS!");
			}
		}
	}

}
Link para o comentário
Compartilhar em outros sites

  • 0

 

Coloquei uns debug.

package me.leo.api;

import java.util.HashMap;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class RewardOnMine implements Listener {
	
	public HashMap<UUID, Integer> blocks = new HashMap<>();
	
	@EventHandler
	public void blockBreak(BlockBreakEvent e) {
		Player p = e.getPlayer();
		Block block = e.getBlock();
		if(block.getType().equals(Material.LAPIS_ORE)) {
			if (blocks.containsKey(e.getPlayer().getUniqueId())) {
				e.getPlayer().sendMessage("Ok, já tinhamos você.");
				int atual = blocks.get(e.getPlayer().getUniqueId());
				blocks.remove(e.getPlayer().getUniqueId());
				blocks.put(e.getPlayer().getUniqueId(), atual++);
			} else {
				blocks.put(e.getPlayer().getUniqueId(), 1);
				e.getPlayer().sendMessage("Ok, não tinhamos você.");
			}
			
			e.getPlayer().sendMessage("Você está com... " + blocks.get(e.getPlayer().getUniqueId()));
			
			if (blocks.get(e.getPlayer().getUniqueId()) >= 15) {
			e.getPlayer().sendMessage("Executou @%$#~&I?");
				Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "givecaixa Norm 1 " + p.getPlayer().getName());
				Bukkit.broadcastMessage("§a§lTESTE DE BLOCOS!");
			}
		}
	}

}

aparece as mensagem mais nao envia recompensa http://prntscr.com/k3iidk, alem q diminui pra 5 blocos pra testar

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

  • 0

aparece as mensagem mais nao envia recompensa http://prntscr.com/k3iidk, alem q diminui pra 5 blocos pra testar

 

em vez de usar remove e put usa replace :pense:

 

eu tmb recomendo usar ConcurrentHashMap em vez de HashMap normal

 

eu tmb recomendo salvar pelo nick em String do que salvar pela uuid '-' mas isso é indiferente

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

  • 0

 

Tenta

package me.leo.api;

import java.util.HashMap;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class RewardOnMine implements Listener {
	
	public HashMap<UUID, Integer> blocks = new HashMap<>();
	
	@EventHandler
	public void blockBreak(BlockBreakEvent e) {
		Player p = e.getPlayer();
		Block block = e.getBlock();
		if(block.getType().equals(Material.LAPIS_ORE)) {
			if (blocks.containsKey(e.getPlayer().getUniqueId())) {
				e.getPlayer().sendMessage("Ok, já tinhamos você.");
				int atual = blocks.get(e.getPlayer().getUniqueId());
				blocks.remove(e.getPlayer().getUniqueId());
				blocks.put(e.getPlayer().getUniqueId(), (atual + 1));
			} else {
				blocks.put(e.getPlayer().getUniqueId(), 1);
				e.getPlayer().sendMessage("Ok, não tinhamos você.");
			}
			
			e.getPlayer().sendMessage("Você está com... " + blocks.get(e.getPlayer().getUniqueId()));
			
			if (blocks.get(e.getPlayer().getUniqueId()) >= 15) {
			e.getPlayer().sendMessage("Executou @%$#~&I?");
				Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "givecaixa Norm 1 " + p.getPlayer().getName());
				Bukkit.broadcastMessage("§a§lTESTE DE BLOCOS!");
			}
		}
	}

}

Funcionou, mas tem como recomeçar quando ele chegar em 15 blocos http://prntscr.com/k3ilu5

Link para o comentário
Compartilhar em outros sites

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