협합
대표칭호 없음
Hyuphop a40d885140084f9b870c03bbb816392c
이해도 | 플러그인 |
---|
블럭 설치 시 "가지고 있는" 디버프 중 1개를 랜덤으로 제거되게 하고싶은데
설정해둔 모든 디버프 중 1개가 랜덤으로 제거되게밖에 못하겠네요 블럭 설치 시 가지고 있는 디버프 중에서 1개를 랜덤으로 제거되기 하려면 어떻게 해야하나요?
package g1.test.hyuphop.Test; import org.bukkit.command.CommandExecutor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import java.util.Random; public final class hyuphop extends JavaPlugin implements Listener, CommandExecutor { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this,this); // Plugin startup logic } @Override public void onDisable() { // Plugin shutdown logic } @EventHandler public void block1(BlockBreakEvent e) { Player w = e.getPlayer(); Random re = new Random(); int Random = re.nextInt(15)+1; if(Random == 1) { w.addPotionEffect(new PotionEffect(PotionEffectType.DARKNESS, 999999, 1, true)); }if(Random == 2){ w.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,999999,5,true)); }if(Random == 3){ w.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING,99999,1,true)); }if(Random == 4){ w.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION,999999,3,true)); }if(Random == 5){ w.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,999999,2,true)); }if(Random == 6){ w.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER,999999,3,true)); }if(Random == 7){ w.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS,999999,1,true)); }if(Random == 8){ w.addPotionEffect(new PotionEffect(PotionEffectType.POISON,999999,4,true)); }if(Random == 9){ w.addPotionEffect(new PotionEffect(PotionEffectType.WITHER,999999,3,true)); }if(Random == 10){ w.addPotionEffect(new PotionEffect(PotionEffectType.UNLUCK,999999,255,true)); }if(Random == 11){ w.addPotionEffect(new PotionEffect(PotionEffectType.HARM,1,0,true)); }if(Random == 12){ w.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING,999999,255,true)); }if(Random == 13){ w.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION,999999,0,true)); }if(Random == 14){ w.addPotionEffect(new PotionEffect(PotionEffectType.BAD_OMEN,999999,2,true)); }if(Random == 15){ w.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,999999,200,true)); } } @EventHandler //isExtendable() //PotionData public void block2(BlockPlaceEvent e) { Player q = e.getPlayer(); Random re1 = new Random(); if(q.addPotionEffect(new PotionEffect(PotionEffectType.DARKNESS, 999999, 1, true)); int Random = re1.nextInt(2)+1; if(Random == 1){ q.sendMessage("test"); }else{ q.sendMessage("test2"); } } }
0reo
2022.08.110reo
2022.08.11이걸 원하시는지는 잘 모르겠네요
협합
2022.08.11정확해요 너무 감사드려요 ㅜㅜㅜㅜ
lanthanide
2022.08.11Player.getActivePotionEffects()
로Collection<PotionEffect>
을 받아와서 iterate 해PotionEffect.getType()
이 디버프 종류인지 확인하고, 디버프라면List<PotionEffectType>
에 넣어줍니다.Random.netInt()
에List.size()
넣어서 난수 받아오고,List.get()
에 넣어준 뒤 리턴값을Player.removePotionEffect()
에 넣어주면 끝!협합
2022.08.11감사합니다아 ㅜㅜ