Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Plugin na drop | aktywność dropu |


pan ktosik

Rekomendowane odpowiedzi

Opublikowano

tak jak w temacie, mam problem z moim pluginem na drop, wszystko idzie mi dobrze ,aż do momentu gdy trzeba było zrobić "włączanie/wyłączanie" danego itemu z listy dropu.

 

			for (String section : DropPlugin.getPlg().getConfig().getConfigurationSection("drops").getKeys(false)){
				if (Util.fixColor(e.getCurrentItem().getItemMeta().getDisplayName()).contains(Util.fixColor(section.toUpperCase()))){
					final String path = "drops."+section;
					final double chance = cfg.getDouble(path+".chance");
					final double chancevip = cfg.getDouble(path+".chancevip");
					final Material drop = Material.matchMaterial(cfg.getString(path+".drop"));
					final Material from = Material.matchMaterial(cfg.getString(path+".from"));
					final Integer min = cfg.getInt(path+".min");
					final Integer max = cfg.getInt(path+".max");
					final String message = cfg.getString(path+".message");
					final Drop dropItem = new Drop(chance, chancevip, drop, from, message, min, max);
					System.out.println("dropItem");
					System.out.println("changeenabled");
					System.out.println("gdi: "+Active.dropItemActive.get(p.getUniqueId()).get(dropItem));
					//Active.getDropItem(p.getUniqueId(), dropItem);
					//dropItem.chanceDisableDrop(p.getName());
					Active.changeDropItem(p.getUniqueId(), dropItem);
					System.out.println("gdi2: "+Active.dropItemActive.get(p.getUniqueId()).get(dropItem));
					p.closeInventory();
					Bukkit.dispatchCommand(p, "drop");
					System.out.println("open inventory drop");
				}
			}
		}
	}

w gdi jest null, w gdi2 jest false.

		p.openInventory(inv);
		slot = 0;
		for (String section : DropPlugin.getPlg().getConfig().getConfigurationSection("drops").getKeys(false)){
			final String path = "drops."+section;
			final double chance = cfg.getDouble(path+".chance");
			final double chancevip = cfg.getDouble(path+".chancevip");
			final Material drop = Material.matchMaterial(cfg.getString(path+".drop"));
			final Material from = Material.matchMaterial(cfg.getString(path+".from"));
			final Integer min = cfg.getInt(path+".min");
			final Integer max = cfg.getInt(path+".max");
			final String message = cfg.getString(path+".message");
			final ItemStack is = new ItemStack(drop);
			final ItemMeta im = is.getItemMeta();
			final Drop dropItem = new Drop(chance, chancevip, drop, from, message, min, max);
			im.setDisplayName(Util.fixColor("&8>> &7PRZEDMIOT: &3"+section.toUpperCase()));
			final List<String> lore = new ArrayList<String>();
			lore.add(Util.fixColor("&8>> &7Szansa: &c"+chance+"%"+" &8(&6VIP&8: &c+"+chancevip+"&8)"));
			lore.add(Util.fixColor("&8>> &7Wypada z: &c"+from.toString().toUpperCase()));
			lore.add(Util.fixColor("&8>> &7Ilosc: &c"+min+"&7x&8-&c"+max+"&7x"));
			lore.add(Util.fixColor(" "));
			Active.getDropItem(p.getUniqueId(), dropItem);
			lore.add(Util.fixColor("&8>> &7Aktywny: "+ Active.dropItemActive.get(p.getUniqueId()).get(dropItem)));
			im.setLore(lore);
			is.setItemMeta(im);
			inv.setItem(slot, is);
			slot++;		
			System.out.println("gdi3: "+Active.dropItemActive.get(p.getUniqueId()).get(dropItem));
		}
		p.updateInventory();
		return false;
	}

w gdi3 jest true..

mapy:

	public static Map<UUID, Map<Drop, Boolean>> dropItemActive = new HashMap<UUID, Map<Drop, Boolean>>();

	
	
	 public static void getDropItem(UUID u, Drop drop)
	  {
		final Map <Drop, Boolean> newUser = new HashMap<Drop, Boolean>();
		newUser.put(drop, true);
	    if (!dropItemActive.containsKey(u)){
	    	dropItemActive.put(u, newUser); 
	    }
	    else if (dropItemActive.get(u).get(drop) == null){
	    	dropItemActive.put(u, newUser);  
	    }
	    dropItemActive.get(u).get(drop);	
	 }
	  
	  public static void changeDropItem(UUID u, Drop drop){
		  final Map <Drop, Boolean> yes = new HashMap<Drop, Boolean>();
		  yes.put(drop, true);
		  final Map <Drop, Boolean> no = new HashMap<Drop, Boolean>();
		  no.put(drop, false);
		  if (dropItemActive.get(u) == null || dropItemActive.get(u).get(drop) == null){
			  dropItemActive.put(u, no);
			  System.out.println("no..");
			  return;
		  }
		  if (dropItemActive.get(u).get(drop)){
			  dropItemActive.put(u, no);
			  System.out.println("no..");
			  return;
		  }
		  else{
			  dropItemActive.put(u, yes);
			  System.out.println("yes..");
			  return;
		  }
	  }

 

 

obiekt drop:

	public Drop(double chance, double chancevip, Material drop, Material from, String message, Integer min, Integer max){
		this.chance = chance;
		this.chancevip = chancevip;
		this.drop = drop;
		this.from = from;
		this.message = message;
		this.min = min;
		this.max = max;
	}
	  

 

Opublikowano
public static Map<UUID, Map<Drop, Boolean>> dropItemActive = new HashMap<UUID, Map<Drop, Boolean>>();

zamiast tworzyć taką mapę, stwórz sobie obiekt typu DropPlayer i tam trzymaj liste dropów, które ma aktywowane, potem sprawdzaj w onBreak czy ma akurat ten drop właczony i tyle, nie potrzebna ci jest taka mapa.

 

 

 

 

fKJeAI4.jpg

 

 

 

Opublikowano

no okej, mam cos takiego:

public class User{
	
	private List<Drop> disabled_drops;
  
  	public User(){
  		this.disabled_drops = new ArrayList<Drop>();
  	}
  
  	public Boolean isDisabled(Drop drop){
  		if (this.disabled_drops.contains(drop)){
  			return true;
  		}
  		return false;
  	}
  
  	public void setDisabled(Drop drop, Boolean disabled){
  		if (disabled){
  			this.disabled_drops.add(drop);
  		} 
  		else{
  			this.disabled_drops.remove(drop);
  		}
  	}
}

i niby jest okej, ale tez caly czas jest true..

 

			for (String section : DropPlugin.getPlg().getConfig().getConfigurationSection("drops").getKeys(false)){
				if (Util.fixColor(e.getCurrentItem().getItemMeta().getDisplayName()).contains(Util.fixColor(section.toUpperCase()))){
					final User u = UserManager.getUser(p.getName());
					final String path = "drops."+section;
					final double chance = cfg.getDouble(path+".chance");
					final double chancevip = cfg.getDouble(path+".chancevip");
					final Material drop = Material.matchMaterial(cfg.getString(path+".drop"));
					final Material from = Material.matchMaterial(cfg.getString(path+".from"));
					final Integer min = cfg.getInt(path+".min");
					final Integer max = cfg.getInt(path+".max");
					final String message = cfg.getString(path+".message");
					final Drop dropItem = new Drop(chance, chancevip, drop, from, message, min, max);
					if (u.isDisabled(dropItem)){
						System.out.println("false");
						u.setDisabled(dropItem, false);
					}
					else{
						u.setDisabled(dropItem, true);
						System.out.println("true");
					}
					System.out.println("u: "+u.isDisabled(dropItem));
					p.closeInventory();
					Bukkit.dispatchCommand(p, "drop");
					System.out.println("open inventory drop");
				}
			}
		}
	}

/\ listener

 

komenda:

final Drop dropItem = new Drop(chance, chancevip, drop, from, message, min, max);

lore.add(Util.fixColor("&8>> &7Aktywny: "+ u.isDisabled(dropItem)).replace("false", Util.fixColor("&aTAK")).replace("true", Util.fixColor("&cNIE")));

 

15 minut temu, Nocny napisał:

public static Map<UUID, Map<Drop, Boolean>> dropItemActive = new HashMap<UUID, Map<Drop, Boolean>>();

zamiast tworzyć taką mapę, stwórz sobie obiekt typu DropPlayer i tam trzymaj liste dropów, które ma aktywowane, potem sprawdzaj w onBreak czy ma akurat ten drop właczony i tyle, nie potrzebna ci jest taka mapa.

 

Opublikowano
27 minut temu, Nocny napisał:

pokaż klasę UserManager

public class UserManager{
	
	public static HashMap<String, User> users = new HashMap<String, User>();
  
  	public static User getUser(String nick){
  		if (users.containsKey(nick)) {
  			return users.get(nick);
  		}
  		User user = new User();
  		users.put(nick, user);
  		return user;
  	}
}

 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...