Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 1f965fc

Browse files
committed
refactor: clean 130 files of code
1 parent f0c42da commit 1f965fc

File tree

130 files changed

+786
-1590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+786
-1590
lines changed

api/build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@ plugins {
22
kotlin("jvm") version "1.9.22"
33
}
44

5-
repositories {
6-
}
7-
8-
95
dependencies {
106
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
117
}
128

139

1410
tasks {
15-
1611
compileKotlin {
1712
kotlinOptions.jvmTarget = "21"
1813
}
19-
2014
}
21-
kotlin{
15+
16+
kotlin {
2217
jvmToolchain(21)
2318
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.undefined.api
22

3-
43
import org.bukkit.plugin.java.JavaPlugin
54

65
class API(javaPlugin: JavaPlugin) {
@@ -10,8 +9,7 @@ class API(javaPlugin: JavaPlugin) {
109
}
1110

1211
init {
13-
com.undefined.api.API.Companion.plugin = javaPlugin
14-
12+
plugin = javaPlugin
1513
}
1614

1715
}

api/src/main/java/com/undefined/api/customEvents/ParticleEvent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ class ParticleEvent(
1515
val yDist: Float,
1616
val zDist: Float,
1717
player: Player
18-
): UndefinedEvent() {
19-
}
18+
): UndefinedEvent()

api/src/main/java/com/undefined/api/customEvents/SoundEvent.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class SoundEvent(
1616
) : UndefinedEvent()
1717

1818
enum class SoundSource(name: String, id: Int) {
19-
2019
MASTER("master",0),
2120
MUSIC("music",1),
2221
RECORDS("record",2),
@@ -27,5 +26,4 @@ enum class SoundSource(name: String, id: Int) {
2726
PLAYERS("players",7),
2827
AMBIENT("ambient",8),
2928
VOICE("voice",9)
30-
3129
}

api/src/main/java/com/undefined/api/customEvents/block/BlockProgressUpdateEvent.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@ import kotlin.math.round
1515

1616
class BlockProgressUpdateEvent(val location: Location, val stage: Int): UndefinedEvent()
1717

18-
class BlockProgressManager(){
18+
class BlockProgressManager {
1919

2020
private val blockList: HashMap<Location, Int> = hashMapOf()
2121

2222
init {
23-
2423
event<BlockDamageEvent> {
25-
2624
val breakTime = getTimeNeeded(block, player)
25+
val timeDetween = ceil(breakTime / 10).toInt()
2726

2827
if (breakTime < 2 || player.gameMode != GameMode.SURVIVAL) return@event
2928

30-
val timeDetween = ceil(breakTime / 10).toInt()
31-
3229
blockList[block.location] = 0
33-
3430
Bukkit.getPluginManager().callEvent(BlockProgressUpdateEvent(block.location, 0))
3531

3632
com.undefined.api.scheduler.repeatingTask(timeDetween) {
@@ -48,7 +44,6 @@ class BlockProgressManager(){
4844
blockList[block.location] = stage
4945
Bukkit.getPluginManager().callEvent(BlockProgressUpdateEvent(block.location, stage))
5046
}
51-
5247
}
5348

5449
event<BlockBreakEvent> {

api/src/main/java/com/undefined/api/customEvents/entity/player/PlayerArmorChangeEvent.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,21 @@ class PlayerArmorChangeManager {
2020
Pair("BOOTS", 36)
2121
)
2222

23-
2423
init {
25-
2624
event<PlayerInteractEvent> {
27-
2825
if (item == null) return@event
29-
30-
if (action == Action.RIGHT_CLICK_BLOCK) {
31-
if (clickedBlock!!.state is InventoryHolder){
32-
return@event
33-
}
34-
}
35-
26+
if (action == Action.RIGHT_CLICK_BLOCK && clickedBlock!!.state is InventoryHolder) return@event
3627
if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return@event
3728

3829
val name = item!!.type.name
30+
val last = name.split("_").last()
3931

4032
if (!name.contains("_")) return@event
41-
42-
val last = name.split("_").last
43-
4433
if (!armorMap.containsKey(last)) return@event
4534

4635
val slot = armorMap[last]!!
47-
4836
Bukkit.getPluginManager().callEvent(PlayerArmorChangeEvent(player, item!!, slot))
49-
5037
}
51-
52-
5338
}
5439

5540
}

api/src/main/java/com/undefined/api/customEvents/entity/player/PlayerHitByPlayerEvent.kt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,41 @@ import org.bukkit.event.EventPriority
1212
import org.bukkit.event.entity.EntityDamageByEntityEvent
1313
import java.util.UUID
1414

15-
1615
/**
1716
* @hidden
1817
*/
19-
class PlayerHitByPlayerManager(){
20-
init {
18+
class PlayerHitByPlayerManager {
2119

20+
init {
2221
val enderCrystalMap: HashMap<EnderCrystal, UUID> = hashMapOf()
2322

2423
event<EntityDamageByEntityEvent> (priority = EventPriority.HIGHEST) {
2524
if (isCancelled) return@event
2625
val player = entity as? Player ?: return@event
2726
val damagerPlayer = damager as? Player
28-
if (damagerPlayer != null){
27+
if (damagerPlayer != null) {
2928
if (damagerPlayer == player) return@event
3029
Bukkit.getPluginManager().callEvent(PlayerHitByPlayerEvent(player, damagerPlayer, HitCause.HAND))
3130
return@event
3231
}
3332

3433
val projectile = damager as? Projectile
35-
if (projectile != null){
34+
if (projectile != null) {
3635
if (projectile.shooter is Player) {
3736
if (projectile.shooter as Player == player) return@event
3837
Bukkit.getPluginManager().callEvent(PlayerHitByPlayerEvent(player, projectile.shooter as Player, HitCause.PROJECTILE))
3938
}
4039
}
4140

4241
val tnt = damager as? TNTPrimed
43-
if (tnt != null){
44-
if (tnt.source is Player)
42+
if (tnt != null) {
43+
if (tnt.source is Player) {
4544
if (tnt.source == player) return@event
4645
Bukkit.getPluginManager().callEvent(PlayerHitByPlayerEvent(player, tnt.source as Player, HitCause.EXPLOSIVE))
46+
}
4747
}
4848

49-
if (enderCrystalMap.containsKey(damager)){
50-
49+
if (enderCrystalMap.containsKey(damager)) {
5150
val uuid = enderCrystalMap[damager]
5251

5352
if (uuid != null) {
@@ -64,18 +63,14 @@ class PlayerHitByPlayerManager(){
6463

6564
event<EntityDamageByEntityEvent> (priority = EventPriority.HIGHEST) {
6665
if (isCancelled) return@event
67-
val player = damager as? Player ?: return@event
68-
69-
if (entity is EnderCrystal){
7066

67+
val player = damager as? Player ?: return@event
68+
if (entity is EnderCrystal) {
7169
enderCrystalMap[entity as EnderCrystal] = player.uniqueId
7270
delay(2) { enderCrystalMap.remove(entity as EnderCrystal) }
73-
7471
}
75-
7672
}
7773

78-
7974
}
8075

8176
}
@@ -93,7 +88,7 @@ class PlayerHitByPlayerEvent(val hitPlayer: Player, val damager: Player, val hit
9388
* Enum class representing the cause of a hit.
9489
*
9590
*/
96-
enum class HitCause(){
91+
enum class HitCause {
9792
HAND,
9893
PROJECTILE,
9994
END_CRYSTAL,

api/src/main/java/com/undefined/api/customEvents/entity/player/PlayerMainHandSwitchEvent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ import com.undefined.api.event.UndefinedEvent
44
import org.bukkit.entity.Player
55
import org.bukkit.inventory.ItemStack
66

7-
class PlayerMainHandSwitchEvent(val player: Player, val itemStack: ItemStack?): UndefinedEvent() {
8-
}
7+
class PlayerMainHandSwitchEvent(val player: Player, val itemStack: ItemStack?): UndefinedEvent()

api/src/main/java/com/undefined/api/customEvents/entity/player/PlayerUseItemEvent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ package com.undefined.api.customEvents.entity.player
33
import com.undefined.api.event.UndefinedEvent
44
import org.bukkit.entity.Player
55

6-
class PlayerUseItemEvent(val player: Player, val offhand: Boolean, val starting: Boolean): UndefinedEvent() {
7-
}
6+
class PlayerUseItemEvent(val player: Player, val offhand: Boolean, val starting: Boolean): UndefinedEvent()

api/src/main/java/com/undefined/api/event/Event.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.undefined.api.event
22

3-
import com.undefined.api.API
43
import org.bukkit.Bukkit
54
import org.bukkit.event.Cancellable
65
import org.bukkit.event.Event
@@ -28,7 +27,6 @@ inline fun <reified T : Event> event(
2827
priority,
2928
{ _, event ->
3029
if (event is T) callback(event)
31-
3230
},
3331
com.undefined.api.API.plugin,
3432
ignoreCancelled
@@ -38,7 +36,7 @@ inline fun <reified T : Event> event(
3836
/**
3937
* Implementation of the [Listener] interface that provides a method to unregister the listener from the [HandlerList].
4038
*/
41-
class UndefinedListener: Listener{
39+
class UndefinedListener: Listener {
4240
fun unregister() = HandlerList.unregisterAll(this)
4341
}
4442

@@ -47,7 +45,7 @@ class UndefinedListener: Listener{
4745
*
4846
* @property async Specifies whether the event should be handled asynchronously or not. Default value is false.
4947
*/
50-
open class UndefinedEvent(async: Boolean = false): Event(async), Cancellable{
48+
open class UndefinedEvent(async: Boolean = false): Event(async), Cancellable {
5149

5250
/**
5351
* Represents the cancellation status of an event.
@@ -63,6 +61,7 @@ open class UndefinedEvent(async: Boolean = false): Event(async), Cancellable{
6361
* @return true if the event has been cancelled, false otherwise
6462
*/
6563
override fun isCancelled() = cancelled
64+
6665
/**
6766
* Sets the cancellation state of the event. A cancelled event will not be called
6867
* by event handlers, and will not propagate to other event listeners.
@@ -72,6 +71,7 @@ open class UndefinedEvent(async: Boolean = false): Event(async), Cancellable{
7271
override fun setCancelled(cancel: Boolean) {
7372
cancelled = cancel
7473
}
74+
7575
/**
7676
*
7777
* @hidden

api/src/main/java/com/undefined/api/nms/EntityInteract.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package com.undefined.api.nms
33
import com.undefined.api.nms.interfaces.NMSEntity
44
import org.bukkit.entity.Player
55

6-
76
class EntityInteract(val actionType: ClickType, val nmsEntity: NMSEntity, val player: Player)
87

98
enum class ClickType {
10-
119
RIGHT_CLICK,
1210
LEFT_CLICK
13-
1411
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
package com.undefined.api.nms
22

3-
enum class ItemSlot(val slot: Int){
4-
3+
enum class ItemSlot(val slot: Int) {
54
MAINHAND(0),
65
OFFHAND(40),
76
CHEST(38),
87
LEGS(37),
98
HEAD(39),
109
FEET(36)
11-
1210
}
1311

1412
object ItemSlotObject{
1513
fun getItemSlotFromSlot(int: Int): ItemSlot?{
16-
17-
ItemSlot.entries.forEach() {
18-
if (it.slot == int) {
19-
return it
20-
}
21-
}
22-
14+
ItemSlot.entries.forEach { if (it.slot == int) return it }
2315
return null
2416
}
2517
}

api/src/main/java/com/undefined/api/nms/ServerPlayer.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import java.io.InputStreamReader
88
import java.net.URI
99
import kotlin.math.floor
1010

11-
1211
fun NMSLivingEntity.toDeltaValue(value: Double, newValue: Double) = (((newValue - value) * 32 * 128).toInt().toShort())
1312

1413
fun NMSLivingEntity.toRotationValue(rotation: Float): Byte = floor(rotation * 256.0f / 360.0f).toInt().toByte()
1514

16-
1715
fun NMSPlayer.getSkinTexture(name: String): Array<String> {
1816

1917
val textureProperty: JsonObject
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.undefined.api.nms.extensions
22

33
fun <T : Any> Any.getPrivateField(fieldName: String): T = javaClass.getDeclaredField(fieldName).apply { isAccessible = true }[this] as T
4-
54
fun <T : Any> Any.getPrivateFieldFromSuper(fieldName: String): T = javaClass.superclass.getDeclaredField(fieldName).apply { isAccessible = true }[this] as T

api/src/main/java/com/undefined/api/nms/extensions/PlayerExtension.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import com.undefined.api.API
44
import org.bukkit.entity.Player
55
import org.bukkit.metadata.FixedMetadataValue
66

7-
fun Player.setMetaData(name: String, any: Any){
8-
this.setMetadata(name, FixedMetadataValue(com.undefined.api.API.plugin, any))
7+
fun Player.setMetaData(name: String, any: Any) {
8+
this.setMetadata(name, FixedMetadataValue(API.plugin, any))
99
}
1010

1111
fun Player.getMetaDataInfo(name: String): Any? = if (this.hasMetadata(name)) this.getMetadata(name)[0] else null
12-
fun Player.removeMetaData(name: String) = this.removeMetadata(name, com.undefined.api.API.plugin)
12+
fun Player.removeMetaData(name: String) = this.removeMetadata(name, API.plugin)

0 commit comments

Comments
 (0)