개인 자료란 (JE)

  서버 커뮤니티

Profile 협합 대표칭호 없음

Hyuphop a40d885140084f9b870c03bbb816392c

Profile

질문하기 Java

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

2022.08.11 조회 수 65 추천 수 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/115/774/003/262x150.crop.jpg?20240424234825

업데이트

마인크래프트 1.20.5 정식 업데이트

학교가기싫다

2024-04-24

0

/files/thumbnails/762/770/003/262x150.crop.jpg?20240418073724

레드스톤

T.B.H (고민중독) | 노트블럭 버전 | NoteBlock Cover [한국어 영어 중국어 가사 추가]

노트블럭전문가

2024-04-18

0

/files/thumbnails/218/767/003/262x150.crop.jpg?20240412130213

레드스톤

우리의 꿈 - 원피스 오프닝

노트블럭전문가

2024-04-12

0

/files/thumbnails/505/766/003/262x150.crop.jpg?20240411122306

레드스톤

기동전사 건담 수성의 마녀 | 노트블럭 커버 1

노트블럭전문가

2024-04-11

1

/files/thumbnails/932/765/003/262x150.crop.jpg?20240410124459

레드스톤

마인크래프트 노트블록으로 만든 『 밤양갱 (Bam Yang Gang) 』

노트블럭전문가

2024-04-10

0