Repository navigation
Expand file tree
/
Copy pathClassSystem.kt
More file actions
74 lines (64 loc) · 2.49 KB
/
Copy pathClassSystem.kt
File metadata and controls
74 lines (64 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2018 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT
package ru.endlesscode.mimic.classes
/**
* System that provides methods to work with player's class.
*
* Before implementing run an eye over all default method implementations
* and override all methods that work not properly for your case.
*/
@Deprecated("Use Classes API from mimic-bukkit-api instead, it supports class slots, subclasses and class levels.")
public interface ClassSystem {
/**
* Primary class of the player.
*
* It is called "primary" because some class systems can support many classes
* for one player. Primary class can't be null if player has at least one class.
*
* @return Primary class name or `null` if player has no any classes.
*/
public val primaryClass: String?
get() = classes.firstOrNull()
/**
* List of player classes.
*
* It is actual for systems which support many classes for one player.
* If system doesn't support - it just returns [List] with one element.
*
* Never returns `null`, but can return empty [List].
*
* @return List of player's classes
* @throws IllegalStateException If player-related object not exists.
*/
public val classes: List<String>
/** Returns `true` if player has any class. */
public fun hasAnyClass(): Boolean = classes.isNotEmpty()
/**
* Returns `true` if player has any of required classes.
* @since 0.6.2
*/
public fun hasAnyOfClasses(firstClass: String, vararg restClasses: String): Boolean {
return hasAnyOfClasses(listOf(firstClass, *restClasses))
}
/** Returns `true` if player has any of [requiredClasses]. */
public fun hasAnyOfClasses(requiredClasses: List<String>): Boolean {
return requiredClasses.any { hasClass(it) }
}
/**
* Returns `true` if player has all required classes.
* @since 0.6.2
*/
public fun hasAllClasses(firstClass: String, vararg restClasses: String): Boolean {
return hasAllClasses(listOf(firstClass, *restClasses))
}
/** Returns `true` if player has all [requiredClasses]. */
public fun hasAllClasses(requiredClasses: List<String>): Boolean {
return requiredClasses.all { hasClass(it) }
}
/** Returns `true` if player has [requiredClass]. */
public fun hasClass(requiredClass: String): Boolean {
return classes.any {
it.equals(requiredClass, ignoreCase = true)
}
}
}