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

Szansa na drop


EnglishPhilips

Rekomendowane odpowiedzi

Opublikowano

Witam,

public class DeathListener implements Listener
{
    Main plugin;
    
    public DeathListener(final Main plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
      
    @EventHandler
    public void PlayerDeathEvent(final PlayerDeathEvent e){
    	final Player p = e.getEntity();
    	final User user = User.get(p);
    	final ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    	final SkullMeta meta = (SkullMeta)item.getItemMeta();	
    	if (user.getRank().getPoints() >= 1000) {
    		meta.setOwner(p.getName());
    		item.setItemMeta((ItemMeta)meta);
    		p.getWorld().dropItemNaturally(p.getLocation(), item);
    		p.getWorld().strikeLightningEffect(p.getLocation());
    	}
    }
}

napisałem coś takiego. Chciałbym żeby było 25% szans na wydropienie tej głowy. Mam pytanie napisałby ktoś pozostałą część tego pluginu? Z góry dziękuję.

 

Pozdrawiam.

Opublikowano
public class DeathListener implements Listener
{
    Main plugin;
    
    public DeathListener(final Main plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
      
    @EventHandler
    public void PlayerDeathEvent(final PlayerDeathEvent e){
        if (RandomManager.getChance(25.0D))
    	final Player p = e.getEntity();
    	final User user = User.get(p);
    	final ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    	final SkullMeta meta = (SkullMeta)item.getItemMeta();	
    	if (user.getRank().getPoints() >= 1000) {
    		meta.setOwner(p.getName());
    		item.setItemMeta((ItemMeta)meta);
    		p.getWorld().dropItemNaturally(p.getLocation(), item);
    		p.getWorld().strikeLightningEffect(p.getLocation());
                   e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), new ItemStack(Material.SKULL_ITEM, 1));
    	}
    }

klasa RandomManager


public class RandomManager
{
  private static final Random rand = new Random();
  
  public static double getRandDouble(double min, double max)
    throws IllegalArgumentException
  {
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return rand.nextDouble() * (max - min) + min;
  }
  
  public static boolean getChance(double chance)
  {
    return (chance >= 100.0D) || (chance >= getRandDouble(0.0D, 100.0D));
  }
}

Nie testowane

Opublikowano
public class DeathListener implements Listener
{
    Main plugin;
    
    public DeathListener(final Main plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
      
    @EventHandler
    public void PlayerDeathEvent(final PlayerDeathEvent e){
        if (RandomManager.getChance(25.0D))
    	final Player p = e.getEntity();
    	final User user = User.get(p);
    	final ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
    	final SkullMeta meta = (SkullMeta)item.getItemMeta();	
    	if (user.getRank().getPoints() >= 1000) {
    		meta.setOwner(p.getName());
    		item.setItemMeta((ItemMeta)meta);
    		p.getWorld().dropItemNaturally(p.getLocation(), item);
    		p.getWorld().strikeLightningEffect(p.getLocation());
                   e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), new ItemStack(Material.SKULL_ITEM, 1));
    	}
    }

klasa RandomManager


public class RandomManager
{
  private static final Random rand = new Random();
  
  public static double getRandDouble(double min, double max)
    throws IllegalArgumentException
  {
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return rand.nextDouble() * (max - min) + min;
  }
  
  public static boolean getChance(double chance)
  {
    return (chance >= 100.0D) || (chance >= getRandDouble(0.0D, 100.0D));
  }
}

Nie testowane

 

Dziękuje za pomoc wszystko ładnie działa :) 

Zarchiwizowany

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

×
×
  • Dodaj nową pozycję...