개인 자료란 (JE)

  서버 커뮤니티

Profile 협합 대표칭호 없음

Hyuphop a40d885140084f9b870c03bbb816392c

Profile

질문하기 Java

블럭 설치 시 가지고 있는 디버프 중 1개 제거

2022.08.11 조회 수 66 추천 수 0
이해도 플러그인 

블럭 설치 시 "가지고 있는" 디버프 중 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");
    }

}

}

5개의 댓글

0reo
2022.08.11
Collection<PotionEffect> collection = player.getActivePotionEffects();
ArrayList<PotionEffect> list = new ArrayList(collection);
Random r = new Random();
int num = r.nextInt(list.size());
PotionEffect e = list.get(num);
player.removePotionEffect(e.getType());
0reo
2022.08.11
@0reo

이걸 원하시는지는 잘 모르겠네요

협합
2022.08.11
@0reo

정확해요 너무 감사드려요 ㅜㅜㅜㅜ

lanthanide
2022.08.11

Player.getActivePotionEffects()Collection<PotionEffect> 을 받아와서 iterate 해 PotionEffect.getType() 이 디버프 종류인지 확인하고, 디버프라면 List<PotionEffectType> 에 넣어줍니다. Random.netInt()List.size() 넣어서 난수 받아오고, List.get() 에 넣어준 뒤 리턴값을 Player.removePotionEffect() 에 넣어주면 끝!

협합
2022.08.11
@lanthanide

감사합니다아 ㅜㅜ

뉴스 및 창작물
/files/thumbnails/268/789/003/262x150.crop.jpg?20240515192032

레드스톤

벌레먹은 돌 빠르게 제거하는 법

GlassesFilm

2024-05-15

0

/files/thumbnails/797/788/003/262x150.crop.jpg?20240515090924

건축

마인크래프트로 구현한 카르카손 보드게임

Warak

2024-05-15

1

/files/thumbnails/487/784/003/262x150.crop.jpg?20240508233607

모드

Windows Borderless 모드에서 악성코드 발견

학교가기싫다

2024-05-08

1

/files/thumbnails/384/778/003/262x150.crop.jpg?20240512002324

업데이트

마인크래프트 자바 에디션 스냅샷 24w18a

학교가기싫다

2024-05-06

0

/files/thumbnails/855/781/003/262x150.crop.jpg?20240505141129

레드스톤

레이저 클리너

GlassesFilm

2024-05-05

1