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

Efekt speed po zjedzeniu ciastka


EnglishPhilips

Rekomendowane odpowiedzi

Opublikowano

Witam,

stworzyłem itemstack:

	public static ItemStack is = new ItemStack(Material.COOKIE, 1);{
		is.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
		ItemMeta im = is.getItemMeta();
		im.setDisplayName("Ciasteczko");
		is.setItemMeta(im);
	}

Chciałbym aby po zjedzeniu tego ciastka dawało mi efekt SPEED II. Ale nie za bardzo wiem jak sprawdzić czy gracz akurat je to ciastko.

 

Pozdrawiam.

Opublikowano


@EventHandler

public void onConsume(PlayerItemConsumeEvent event){

if(event.getItem().isSimilar(is)){

//rob sobie dalej co chcesz

}

}

Opublikowano
@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

Opublikowano

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

 

 

 

 

fKJeAI4.jpg

 

 

 

Opublikowano

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

Opublikowano

 

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

 

 

klasa od randomow, przydatna, jeżeli korzystasz z nich dużo, lub wytnij sobie kawałek kodu i dodaj do swojego:

     private static final Random rand = new Random();
 
        public static int getRandInt(int min, int max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return rand.nextInt(max - min + 1) + min;
        }
 
        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 float getRandFloat(float min, float max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return (rand.nextFloat() * (max - min)) + min;
        }
 
        public static boolean getChance(double chance) {
                return (chance >= 100) || (chance >= getRandDouble(0, 100));
        }

 

 

 

 

fKJeAI4.jpg

 

 

 

Opublikowano

 

 

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

 

 

klasa od randomow, przydatna, jeżeli korzystasz z nich dużo, lub wytnij sobie kawałek kodu i dodaj do swojego:

     private static final Random rand = new Random();
 
        public static int getRandInt(int min, int max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return rand.nextInt(max - min + 1) + min;
        }
 
        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 float getRandFloat(float min, float max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return (rand.nextFloat() * (max - min)) + min;
        }
 
        public static boolean getChance(double chance) {
                return (chance >= 100) || (chance >= getRandDouble(0, 100));
        }

No dobra, ale jak tego użyć bo nie za bardzo wiem?

Opublikowano

 

 

 

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

 

 

klasa od randomow, przydatna, jeżeli korzystasz z nich dużo, lub wytnij sobie kawałek kodu i dodaj do swojego:

     private static final Random rand = new Random();
 
        public static int getRandInt(int min, int max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return rand.nextInt(max - min + 1) + min;
        }
 
        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 float getRandFloat(float min, float max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return (rand.nextFloat() * (max - min)) + min;
        }
 
        public static boolean getChance(double chance) {
                return (chance >= 100) || (chance >= getRandDouble(0, 100));
        }

No dobra, ale jak tego użyć bo nie za bardzo wiem?

 

 

no masz sobie taką klasę i wykorzystujesz sobie metode, co w tym trudnego

Integer rand = getRandInt(0, 5);

i masz random pomiedzy 0 a 5

 

 

 

 

fKJeAI4.jpg

 

 

 

Opublikowano

 

 

 

 

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

 

 

klasa od randomow, przydatna, jeżeli korzystasz z nich dużo, lub wytnij sobie kawałek kodu i dodaj do swojego:

     private static final Random rand = new Random();
 
        public static int getRandInt(int min, int max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return rand.nextInt(max - min + 1) + min;
        }
 
        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 float getRandFloat(float min, float max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return (rand.nextFloat() * (max - min)) + min;
        }
 
        public static boolean getChance(double chance) {
                return (chance >= 100) || (chance >= getRandDouble(0, 100));
        }

No dobra, ale jak tego użyć bo nie za bardzo wiem?

 

 

no masz sobie taką klasę i wykorzystujesz sobie metode, co w tym trudnego

Integer rand = getRandInt(0, 5);

i masz random pomiedzy 0 a 5

 

Ok działa ale jest już ostatni problem. Losowy efekt nie wchodzi za każdym razem np. zjem 3 ciastka i wejdzie 2 razy.

Opublikowano

 

 

 

 

 

 

 

@EventHandler
public void onConsume(PlayerItemConsumeEvent event){
  if(event.getItem().isSimilar(is)){
    //rob sobie dalej co chcesz
  }
}

Ok dzięki działa, a ma jeszcze jedno pytanie;

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      final Random number = new Random();
      Player p = event.getPlayer();
      final int chance = 1 + number.nextInt(16);
      if (chance == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (chance == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
      if (chance == 3){
    	  p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));
      }
    }
  }
}

Zrobiłem coś takiego ale nie wiem dlaczego nie działa pomożesz ?

 

 

są jakieś błędy w konsoli, czy nic się nie pojawia?

Nic się nie pojawia wszystko ładuje się ok tylko po zjedzeniu ciastka nic się nie dzieje. Bez tego randoma działało na samym speed 2

 

 

klasa od randomow, przydatna, jeżeli korzystasz z nich dużo, lub wytnij sobie kawałek kodu i dodaj do swojego:

     private static final Random rand = new Random();
 
        public static int getRandInt(int min, int max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return rand.nextInt(max - min + 1) + min;
        }
 
        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 float getRandFloat(float min, float max) throws IllegalArgumentException {
                Validate.isTrue(max > min, "Max can't be smaller than min!");
                return (rand.nextFloat() * (max - min)) + min;
        }
 
        public static boolean getChance(double chance) {
                return (chance >= 100) || (chance >= getRandDouble(0, 100));
        }

No dobra, ale jak tego użyć bo nie za bardzo wiem?

 

 

no masz sobie taką klasę i wykorzystujesz sobie metode, co w tym trudnego

Integer rand = getRandInt(0, 5);

i masz random pomiedzy 0 a 5

 

Ok działa ale jest już ostatni problem. Losowy efekt nie wchodzi za każdym razem np. zjem 3 ciastka i wejdzie 2 razy.

 

 

pokaż cały kod, bo bez tego ciężko coś stwierdzić, ewentualnie zrób debuga

 

 

 

 

fKJeAI4.jpg

 

 

 

Opublikowano


public static ItemStack is = new ItemStack(Material.COOKIE, 1){

is.addUnsafeEnchantment(Enchantment.DURABILITY, 10);

ItemMeta im = is.getItemMeta();

im.setDisplayName("Ciasteczko");

is.setItemMeta(im);

}

@EventHandler

public void onConsume(PlayerItemConsumeEvent event){

if(event.getItem().isSimilar(is)){

final Random number = new Random();

Player p = event.getPlayer();

final int chance = 1 + number.nextInt(3);

if (chance == 1){

p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");

p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));

}

if (chance == 2){

p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");

p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));

}

if (chance == 3){

p.sendMessage("§6Otrzymales efekt CONFUSION II na 60sekund!");

p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60*20, 1));

}

}

}

 

Opublikowano

Aktualny kod:

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
    
    private static final Random rand = new Random();
    
    public static int getRandInt(int min, int max) throws IllegalArgumentException {
            Validate.isTrue(max > min, "Max can't be smaller than min!");
            return rand.nextInt(max - min + 1) + min;
    }

    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) || (chance == getRandDouble(0, 100));
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      Player p = event.getPlayer();
      Integer rand = getRandInt(0, 5);
      if (rand == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (rand == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
    }
  }
}

Opublikowano

 

Aktualny kod:

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
    
    private static final Random rand = new Random();
    
    public static int getRandInt(int min, int max) throws IllegalArgumentException {
            Validate.isTrue(max > min, "Max can't be smaller than min!");
            return rand.nextInt(max - min + 1) + min;
    }

    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) || (chance == getRandDouble(0, 100));
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      Player p = event.getPlayer();
      Integer rand = getRandInt(0, 5);
      if (rand == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (rand == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
    }
  }
}

Jezu ziomek jak losujesz inta od 0 do 5 a uwzględniasz tylko wylosowanie 1 i 2 no to się nie dziw zrób tam przynajmniej 

      if (rand == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      } else {
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      } 

albo

      if (rand <= 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
Opublikowano

 

 

Aktualny kod:

public class ConsumeCookieListener implements Listener
{
    CiastkoEffektPlugin plugin;
    
    public ConsumeCookieListener(final CiastkoEffektPlugin plugin) {
        this.plugin = plugin;
        this.plugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.plugin);
    }
    
    private static final Random rand = new Random();
    
    public static int getRandInt(int min, int max) throws IllegalArgumentException {
            Validate.isTrue(max > min, "Max can't be smaller than min!");
            return rand.nextInt(max - min + 1) + min;
    }

    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) || (chance == getRandDouble(0, 100));
    }
	
    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event){
      if(event.getItem().isSimilar(CiastkoEffektPlugin.ciastko)){
      Player p = event.getPlayer();
      Integer rand = getRandInt(0, 5);
      if (rand == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      }
      if (rand == 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }
    }
  }
}

Jezu ziomek jak losujesz inta od 0 do 5 a uwzględniasz tylko wylosowanie 1 i 2 no to się nie dziw zrób tam przynajmniej 

      if (rand == 1){
    	  p.sendMessage("§6Otrzymales efekt ABSORPTION II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 60*20, 1));
      } else {
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      } 

albo

      if (rand <= 2){
    	  p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
    	  p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      }

Działa ale nie tak jak powinno. Tzn zamiast 1 losowego efektu daje mi 1-5

Opublikowano

O bosz

robisz

private int Randomize()
  {
    Random r = new Random();
    int Low = 1;
    int High = 3;
    int Result = r.nextInt(High-Low) + Low;
    return Result;
  }

I sprawdzasz

    if (Randomize() == 1){
      p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      return;
    } else if (Randomize() == 2) {
      p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      return;
    } else if (Randomize() == 3) {
      p.sendMessage("§6Otrzymales efekt RAKA X na 100 lat!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.RAK, 60*200000000, 1));
      return;

I TAK DALEJ LOL.. Idź sobie poradniki obejrzyj bo nawet nie wiesz jak inta wylosować..

Opublikowano

O bosz

robisz

private int Randomize()
  {
    Random r = new Random();
    int Low = 1;
    int High = 3;
    int Result = r.nextInt(High-Low) + Low;
    return Result;
  }

I sprawdzasz

    if (Randomize() == 1){
      p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      return;
    } else if (Randomize() == 2) {
      p.sendMessage("§6Otrzymales efekt BLINDNESS II na 60sekund!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60*20, 1));
      return;
    } else if (Randomize() == 3) {
      p.sendMessage("§6Otrzymales efekt RAKA X na 100 lat!");
      p.addPotionEffect(new PotionEffect(PotionEffectType.RAK, 60*200000000, 1));
      return;

I TAK DALEJ LOL.. Idź sobie poradniki obejrzyj bo nawet nie wiesz jak inta wylosować..

Powiedzmy, że jest ok dzięki Ci bardzo za pomoc.

Zarchiwizowany

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

×
×
  • Dodaj nową pozycję...