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

Commit eeb0224

Browse files
committed
☕ Update for v1.1
1 parent 0b50165 commit eeb0224

37 files changed

Lines changed: 1049 additions & 1004 deletions

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88

99
configurations {
1010
group = 'me.arasple.mc.trhologram'
11-
version = '1.0-R2'
11+
version = '1.1'
1212

1313
sourceCompatibility = 1.8
1414
targetCompatibility = 1.8

files/UPDATES_CN.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# TrMenu Update Logs #
22

3+
#### VERSION 1.1
4+
- ##### 1.10
5+
- Since: 2020.2.24
6+
- Updates:
7+
- 取消对 1.8 的支持计划
8+
- 修复了一吨 BUG
9+
- 实现 1.13 以下版本的物品悬浮
10+
- 每个版本独立 NMS ,更稳
11+
- 完善了 API 内容
12+
- 改善了大量 trash code
313
#### VERSION 1.0
414
- ##### 1.0-R2
515
- Since: 2020.2.20

src/main/java/me/arasple/mc/trhologram/TrHologram.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22

33
import io.izzel.taboolib.loader.Plugin;
44
import io.izzel.taboolib.module.config.TConfig;
5-
import io.izzel.taboolib.module.dependency.Dependency;
65
import io.izzel.taboolib.module.inject.TInject;
6+
import io.izzel.taboolib.module.locale.TLocale;
77
import io.izzel.taboolib.module.locale.logger.TLogger;
8+
import me.arasple.mc.trhologram.hologram.HologramManager;
9+
import me.arasple.mc.trhologram.utils.FileWatcher;
810

911
/**
1012
* @author Arasple
1113
* @date 2020/1/1 16:57
1214
*/
1315
@Plugin.Version(5.17)
14-
@Dependency(maven = "org:kotlinlang:kotlin-stdlib:1.3.50", url = "https://skymc.oss-cn-shanghai.aliyuncs.com/libs/kotlin-stdlib-1.3.50.jar")
1516
public final class TrHologram extends Plugin {
1617

1718
@TInject("settings.yml")
1819
public final static TConfig SETTINGS = null;
1920
@TInject("§2Tr§aHologram")
2021
public final static TLogger LOGGER = null;
21-
@TInject(state = TInject.State.LOADING, init = "init", active = "active", cancel = "cancel")
22+
@TInject(state = TInject.State.LOADING, init = "init", active = "active")
2223
private final static TrHologramLoader LOADER = null;
2324

25+
@Override
26+
public void onStopping() {
27+
FileWatcher.INSTANCE.getWatcher().unregisterAll();
28+
HologramManager.INSTANCE.forceWrite();
29+
TLocale.sendToConsole("PLUGIN.DISABLED");
30+
}
31+
2432
public static double getTrVersion() {
25-
return 1.0;
33+
return 1.1;
2634
}
2735

2836
}

src/main/java/me/arasple/mc/trhologram/TrHologramLoader.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import io.izzel.taboolib.module.command.lite.CommandBuilder
44
import io.izzel.taboolib.module.config.TConfig
55
import io.izzel.taboolib.module.locale.TLocale
66
import io.izzel.taboolib.util.Files
7-
import me.arasple.mc.trhologram.hologram.HologramManager
87
import me.arasple.mc.trhologram.nms.HoloPackets
98
import me.arasple.mc.trhologram.updater.Updater
10-
import me.arasple.mc.trhologram.utils.FileWatcher
119
import org.bukkit.configuration.file.YamlConfiguration
1210
import java.io.InputStreamReader
1311
import java.util.function.Consumer
@@ -31,12 +29,6 @@ class TrHologramLoader {
3129
TLocale.sendToConsole("PLUGIN.ENABLED", TrHologram.getPlugin().description.version)
3230
}
3331

34-
fun cancel() {
35-
FileWatcher.getWatcher().unregisterAll()
36-
HologramManager.forceWrite()
37-
TLocale.sendToConsole("PLUGIN.DISABLED")
38-
}
39-
4032
private fun updateConfig() {
4133
val oldCfg: TConfig = TrHologram.SETTINGS
4234
val inputStream = TrHologram.getPlugin().getResource("settings.yml")

src/main/java/me/arasple/mc/trhologram/action/acts/ActionTellraw.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import io.izzel.taboolib.util.Strings;
77
import io.izzel.taboolib.util.Variables;
88
import me.arasple.mc.trhologram.action.base.AbstractAction;
9-
import me.arasple.mc.trhologram.utils.JsonItem;
9+
import me.arasple.mc.trhologram.utils.Utils;
1010
import me.arasple.mc.trhologram.utils.Vars;
1111
import net.md_5.bungee.chat.ComponentSerializer;
1212
import org.bukkit.entity.Player;
@@ -41,7 +41,7 @@ public void onExecute(Player player) {
4141
public void setContent(String content) {
4242
content = TLocale.Translate.setColored(content);
4343
tellraw = TellrawJson.create();
44-
if (JsonItem.isJson(content)) {
44+
if (Utils.INSTANCE.isJson(content)) {
4545
this.rawJson = content;
4646
return;
4747
}

src/main/java/me/arasple/mc/trhologram/commands/CommandDebug.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import java.io.InputStreamReader
2121
*/
2222
class CommandDebug : BaseSubCommand() {
2323

24+
private val builtTime = YamlConfiguration.loadConfiguration(InputStreamReader(Files.getResource(TrHologram.getPlugin(), "plugin.yml"))).getString("built-time", "Null")
25+
2426
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>) {
2527
if (sender is Player) {
2628
val player = sender
@@ -36,11 +38,17 @@ class CommandDebug : BaseSubCommand() {
3638

3739
sender.sendMessage("§3--------------------------------------------------")
3840
sender.sendMessage("")
39-
sender.sendMessage("§2Total Holograms: §6" + Hologram.HOLOGRAMS.values.sumBy { x -> x.size })
40-
sender.sendMessage("§2Running Tasks: §6" + Bukkit.getScheduler().activeWorkers.stream().filter { t: BukkitWorker -> t.owner === TrHologram.getPlugin() }.count() + Bukkit.getScheduler().pendingTasks.stream().filter { t: BukkitTask -> t.owner === TrHologram.getPlugin() }.count())
41-
sender.sendMessage("§2TabooLib: §f" + Plugin.getVersion())
41+
sender.sendMessage("§2Total Holograms: ")
42+
Hologram.HOLOGRAMS.forEach {
43+
if (it.value.isNotEmpty()) {
44+
sender.sendMessage("§r §8[${it.key}§8] - §7${it.value.size}")
45+
}
46+
}
47+
sender.sendMessage("")
48+
sender.sendMessage("§2Running Tasks: §6${Bukkit.getScheduler().activeWorkers.stream().filter { t: BukkitWorker -> t.owner === TrHologram.getPlugin() }.count() + Bukkit.getScheduler().pendingTasks.stream().filter { t: BukkitTask -> t.owner === TrHologram.getPlugin() }.count()}")
49+
sender.sendMessage("§2TabooLib: §f${Plugin.getVersion()}")
4250
sender.sendMessage("")
43-
sender.sendMessage("§2TrHologram Built-Time: §b" + YamlConfiguration.loadConfiguration(InputStreamReader(Files.getResource(TrHologram.getPlugin(), "plugin.yml"))).getString("built-time", "Null"))
51+
sender.sendMessage("§2TrHologram Built-Time: §b$builtTime")
4452
sender.sendMessage("")
4553
sender.sendMessage("§3--------------------------------------------------")
4654
}

src/main/java/me/arasple/mc/trhologram/hologram/Hologram.kt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.arasple.mc.trhologram.hologram
22

33
import io.izzel.taboolib.internal.apache.lang3.math.NumberUtils
4+
import io.izzel.taboolib.util.Strings
45
import io.izzel.taboolib.util.lite.Sounds
56
import me.arasple.mc.trhologram.TrHologram
67
import me.arasple.mc.trhologram.action.ActionGroups
@@ -30,13 +31,22 @@ class Hologram(var loadedFrom: String?, val id: String, var loc: Location, var c
3031

3132
val HOLOGRAMS: MutableMap<String, MutableList<Hologram>> = mutableMapOf()
3233

34+
fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>): Hologram {
35+
return createHologram(plugin, null, id, loc, contents, mutableListOf(), null, null)
36+
}
37+
38+
fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>, actions: MutableList<ActionGroups>): Hologram {
39+
return createHologram(plugin, null, id, loc, contents, actions, null, null)
40+
}
41+
3342
fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>, actions: MutableList<ActionGroups>, condition: String?, distance: String?): Hologram {
3443
return createHologram(plugin, null, id, loc, contents, actions, condition, distance)
3544
}
3645

3746
fun createHologram(plugin: Plugin, file: File?, id: String, loc: Location, contents: List<String>, actions: MutableList<ActionGroups>, condition: String?, distance: String?): Hologram {
3847
val path = if (file == null || !file.exists()) null else file.path
39-
val holo = Hologram(path, id, loc, contents, actions, condition!!, distance!!, NumberUtils.toDouble(distance, -1.0))
48+
val holo = Hologram(path, id, loc, contents, actions, condition ?: "", distance
49+
?: "", NumberUtils.toDouble(distance, -1.0))
4050
HOLOGRAMS.putIfAbsent(plugin.name, mutableListOf())
4151
HOLOGRAMS[plugin.name]?.add(holo)
4252
return holo
@@ -46,6 +56,26 @@ class Hologram(var loadedFrom: String?, val id: String, var loc: Location, var c
4656
return HOLOGRAMS.getOrDefault(TrHologram.getPlugin().name, mutableListOf())
4757
}
4858

59+
fun display(player: Player) {
60+
HOLOGRAMS.values.forEach { list ->
61+
list.forEach { hologram ->
62+
if (hologram.isVisible(player) && !hologram.viewers.contains(player)) {
63+
hologram.display(player)
64+
} else if (!hologram.isVisible(player) && hologram.viewers.contains(player)) {
65+
hologram.destroy(player)
66+
}
67+
}
68+
}
69+
}
70+
71+
fun destroy(player: Player) {
72+
HOLOGRAMS.values.forEach { list ->
73+
list.forEach { hologram ->
74+
hologram.removeViewer(player)
75+
}
76+
}
77+
}
78+
4979
}
5080

5181
fun display(vararg players: Player) {
@@ -90,7 +120,7 @@ class Hologram(var loadedFrom: String?, val id: String, var loc: Location, var c
90120
return false
91121
}
92122
val distance = if (finalViewDistance > 0) finalViewDistance else NumberUtils.toDouble(JavaScript.run(player, viewDistance).toString(), -1.0).coerceAtMost(70.0)
93-
return player.location.distance(loc) <= distance && JavaScript.run(player, viewCondition) as Boolean
123+
return (distance <= 0 || player.location.distance(loc) <= distance) && (Strings.isEmpty(viewCondition) || JavaScript.run(player, viewCondition) as Boolean)
94124
}
95125

96126
private fun refreshLines(player: Player) {
@@ -118,6 +148,7 @@ class Hologram(var loadedFrom: String?, val id: String, var loc: Location, var c
118148
fun delete() {
119149
lines.forEach { line -> line.cancelTask() }
120150
destroyAll()
151+
HOLOGRAMS.values.forEach { it -> it.removeIf { it == this } }
121152
}
122153

123154
fun removeViewer(player: Player) {

src/main/java/me/arasple/mc/trhologram/hologram/HologramLine.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ open class HologramLine(private var text: String, val hologram: Hologram) {
218218
PRIVATE METHODS & UTILS
219219
*/
220220
private fun getPackets(): HoloPackets {
221-
return HoloPackets.getInst()
221+
return HoloPackets.INSTANCE!!
222222
}
223223

224224

src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ object HologramManager {
6161
Hologram.getHolograms().forEach { hologram ->
6262
if (hologram.loadedFrom != null) {
6363
val file = File(hologram.loadedFrom)
64-
if (file.exists() && !FileWatcher.getWatcher().hasListener(file)) {
65-
FileWatcher.getWatcher().addSimpleListener(file) {
64+
if (file.exists() && !FileWatcher.watcher.hasListener(file)) {
65+
FileWatcher.watcher.addSimpleListener(file) {
6666
if (!writing) {
6767
try {
6868
hologram.initFromSection()
@@ -91,8 +91,8 @@ object HologramManager {
9191
val file = Files.file(FOLDER.path + "/" + id + ".yml")
9292
val holo = Hologram.createHologram(TrHologram.getPlugin(), file, id, loc, content.toList(), mutableListOf(), "null", "30")
9393
Bukkit.getOnlinePlayers().stream().filter { player -> holo.isVisible(player) }.forEach { player -> holo.display(player) }
94-
if (!FileWatcher.getWatcher().hasListener(file)) {
95-
FileWatcher.getWatcher().addSimpleListener(file) {
94+
if (!FileWatcher.watcher.hasListener(file)) {
95+
FileWatcher.watcher.addSimpleListener(file) {
9696
if (!writing) {
9797
try {
9898
holo.initFromSection()
@@ -136,10 +136,9 @@ object HologramManager {
136136
}
137137

138138
fun write(hologram: Hologram) {
139-
if (hologram.loadedFrom == null) {
140-
return
141-
}
142-
val file = File(hologram.loadedFrom)
139+
writing = true
140+
val loadedFrom = hologram.loadedFrom ?: return
141+
val file = File(loadedFrom)
143142
val yaml = YamlConfiguration.loadConfiguration(file)
144143
correctData(yaml)
145144
yaml["viewDistance"] = hologram.viewDistance
@@ -151,6 +150,9 @@ object HologramManager {
151150
} catch (e: IOException) {
152151
e.printStackTrace()
153152
}
153+
if (TrHologram.getPlugin().isEnabled) {
154+
Bukkit.getScheduler().runTaskLater(TrHologram.getPlugin(), Runnable { writing = false }, 20)
155+
}
154156
}
155157

156158
private fun restartTasks() {

0 commit comments

Comments
 (0)