-
Notifications
You must be signed in to change notification settings - Fork 15
/
PlayerInteractListener.kt
72 lines (55 loc) · 2.17 KB
/
PlayerInteractListener.kt
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
package ir.syrent.velocityvanish.spigot.listener
import ir.syrent.velocityvanish.spigot.VelocityVanishSpigot
import ir.syrent.velocityvanish.spigot.ruom.Ruom
import ir.syrent.velocityvanish.spigot.storage.Settings
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.player.PlayerInteractEvent
class PlayerInteractListener(
private val plugin: VelocityVanishSpigot
) : Listener {
init {
Ruom.registerListener(this)
}
@EventHandler
private fun onActivePlate(event: PlayerInteractEvent) {
val player = event.player
val block = event.clickedBlock ?: return
if (!plugin.vanishedNames.contains(player.name)) return
if (event.action != Action.PHYSICAL && event.clickedBlock == null) return
if (!block.type.toString().contains("PLATE")) return
event.isCancelled = true
}
private val silentInventoryMaterials = Material.values().filter { it.name.contains("CHEST") || it.name.contains("SHULKER_BOX") || it.name.contains("BARREL") }
/**
* Note: Not working when some ProCosmetics cosmetics are enabled!
*/
@EventHandler
fun onChestOpen(event: PlayerInteractEvent) {
if (!Settings.silenOpenContainer) return
if (event.action != Action.RIGHT_CLICK_BLOCK) return
val block = event.clickedBlock ?: return
val player = event.player
if (!plugin.vanishedNames.contains(player.name)) return
if (block.type == Material.ENDER_CHEST) {
event.isCancelled = true
player.openInventory(player.enderChest)
return
}
if (!silentInventoryMaterials.contains(block.type)) return
val gamemode = player.gameMode
val flight = player.allowFlight
val fly = player.isFlying
player.allowFlight = true
player.isFlying = true
player.gameMode = GameMode.SPECTATOR
// TODO: Use Packet to open chest
Ruom.runSync({
player.gameMode = gamemode
player.allowFlight = flight
player.isFlying = fly
}, 2)
}}