8000 IS · TriggerReactor/TriggerReactor Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
wysohn edited this page Dec 18, 2018 · 3 revisions

IS Statement

When writing scripts, you will probably face the problem, such as what the specific entity's type is. One way to do it is like this: IF entity.getType().name() == "ZOMBIE" This use the Enum to check and process only if the entity is a zombie. But in some cases, you might want to use IF statement to filter all the creatures, not only a zombie. What would be the solution? you could use IF statement and add all possible monster types like this: IF entity.getType().name() == "ZOMBIE" || entity.getType().name() == "CREEPER" || blahblah... but this is way too tedious. And as developer ourselves, we want to find better way to solve it. And the solution is using IS statement.

Understanding Instance

In order to understand how IS statement work, you need to know at least some portion of how Java's Class hierarchy. Zombie(Click it to open the Javadoc), for example, you can see in the All Superinterfaces: list that one of the superclasses of Zombie is Monster. If you click on the Monster, in the All Known Subinterfaces: list, you probably will notice that the subclass of Monster is list of entities that can damage players, and that's what we are looking for.

Understanding Superclass and Subclass

  • Superclass: superclass is the mother class. For example, if there is a class Animal, you can have subclasses of Animal, such as Pig, Dog, Cow, etc. It's some kind of circle that groups multiple classes together. In the above example, the Monster class was grouping all the entities that can harm players.
  • Subclass: Like already said, it's the child of the mother class. Zombie is subclass of Monster.

Using IS Statement

Let's bring the example at the top again. We want to filter entities only if they are a monster. But putting every single monster type in IF statement is tedious, and in the future version of Minecraft, there might be more monsters are introduced. You wouldn't want to add those monster every time when a new version of Minecraft come out.

So, to go around, use IS statement:

IMPORT org.bukkit.entity.Monster
IF entity IS Monster
    do something if a monster...
ENDIF

IMPORT org.bukkit.entity.Player
IF entity IS Player
    do something if a player...
ENDIF

Notice that you have to IMPORT the class you want to use for IS statement. This is because you want to compare the type of entity directly with the exact class.

Plus, more the general the mother class is, the more IF statement will catch. For example, Monster is also a subclass of Entity(open and check it yourself), so if you filter it like IF entity IS Entity, it is same as not using the IF statement as entity is always an Entity anyway.

Plugin Description / 목차

1. Getting Started () (рус)

S.L. In-game Editor () (рус)

2. Triggers () (рус)

List and usage of Triggers / 트리거 목록과 사용 방법:

  • List of Executors / 실행자(Executor) 목록

4. Placeholders () (рус)

  • Using PlaceholderAPI / PlaceholderAPI 사용법
  • List of Placeholders / 플레이스 홀더(Placeholder) 목록

5. Conditions () (рус)

  • Creating Conditions / 조건식 만들기
    • Boolean Expressions / 부울 (Boolean) 표현 방법
  • Logical Operators / 연산자 사용법
  • IF statement / IF 조건문
  • Null Checking / Null 검사법
  • Switch Case / Switch Case 조건

6. Variables () (рус)

  • Local Variables / 지역 변수
  • Global Variables / 전역 변수

Advanced

Timings () (рус)

7. Methods () (рус)

  • Using Methods / 메소드 사용법
  • Special Data Types / 특수한 데이터 형식
  • Reading Javadocs / Javadoc 읽기
  • Handling Enum / Enum 데이터 처리
  • Lambda Expresion / Lambda(람다) 식 사용법

8. Array () (рус)

  • Creating an empty array / 빈 배열 만들기
  • Storing data into array / 배열에 데이터값 저장하기
  • Read data from array / 배열에서 데이터 읽기(불러오기)

9. Loops () (рус)

  • WHILE loop / WHILE 반복문
  • FOR loop / FOR 반복문
    • Iterating Collection / Collection 형식의 변수 순회법
    • #BREAK executor / #BREAK 실행자
    • #CONTINUE executor / #CONTINUE 실행자

10. Sync Mode () (рус)

  • #CANCELEVENT executor / #CANCELEVENT 실행자
  • Setting Sync/Async Mode / 동기, 비동기 모드 전환
    • Custom Trigger
    • Area Trigger

11. Custom Executors () (рус)

12. Plugin Access () (рус)

  • Check And Use / 플러그인 존재여부 확인
    • Get Third Party Plugin / 제 3자 플러그인 불러오기
    • Check Eligibility / 호환성 확인하기
    • Use the Plugin / 플러그인 사용하기

13. IMPORT Statement () (рус)

  • Creating new instance / 새 인스턴스 생성하기
  • Accessing static method / 종속 메소드 불러오기
  • Accessing static field / 종속 Enum 불러오기

14. IS Statement () (рус)

  • Understanding / 이해하기
    • Understanding Instance / 인스턴스 이해하기
    • Understanding Superclass / 부모클래스 이해하기
    • Understanding Subclass / 자식클래스 이해하기
  • Using IS Statement / IS조건연산자 사용하기

15. TRY-CATCH Statement () (рус)

  • Understanding TRY-CATCH Exception Handling / TRY-CATCH 예외처리 이해하기

Misc

16. Interface Casting () (рус)

module x.x does not "opens x.x" problem

  • List of Custom Events

Examples

Trigger

Trigger Example () (рус)

More Examples: Bukkit, Sponge

Case Specific

Clone this wiki locally
0