Skip to content

Commit

Permalink
☕ Update for v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Arasple committed Feb 24, 2020
1 parent 0b50165 commit eeb0224
Show file tree
Hide file tree
Showing 37 changed files with 1,049 additions and 1,004 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

configurations {
group = 'me.arasple.mc.trhologram'
version = '1.0-R2'
version = '1.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
10 changes: 10 additions & 0 deletions files/UPDATES_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# TrMenu Update Logs #

#### VERSION 1.1
- ##### 1.10
- Since: 2020.2.24
- Updates:
- 取消对 1.8 的支持计划
- 修复了一吨 BUG
- 实现 1.13 以下版本的物品悬浮
- 每个版本独立 NMS ,更稳
- 完善了 API 内容
- 改善了大量 trash code
#### VERSION 1.0
- ##### 1.0-R2
- Since: 2020.2.20
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/me/arasple/mc/trhologram/TrHologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@

import io.izzel.taboolib.loader.Plugin;
import io.izzel.taboolib.module.config.TConfig;
import io.izzel.taboolib.module.dependency.Dependency;
import io.izzel.taboolib.module.inject.TInject;
import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.locale.logger.TLogger;
import me.arasple.mc.trhologram.hologram.HologramManager;
import me.arasple.mc.trhologram.utils.FileWatcher;

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

@TInject("settings.yml")
public final static TConfig SETTINGS = null;
@TInject("§2Tr§aHologram")
public final static TLogger LOGGER = null;
@TInject(state = TInject.State.LOADING, init = "init", active = "active", cancel = "cancel")
@TInject(state = TInject.State.LOADING, init = "init", active = "active")
private final static TrHologramLoader LOADER = null;

@Override
public void onStopping() {
FileWatcher.INSTANCE.getWatcher().unregisterAll();
HologramManager.INSTANCE.forceWrite();
TLocale.sendToConsole("PLUGIN.DISABLED");
}

public static double getTrVersion() {
return 1.0;
return 1.1;
}

}
8 changes: 0 additions & 8 deletions src/main/java/me/arasple/mc/trhologram/TrHologramLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import io.izzel.taboolib.module.command.lite.CommandBuilder
import io.izzel.taboolib.module.config.TConfig
import io.izzel.taboolib.module.locale.TLocale
import io.izzel.taboolib.util.Files
import me.arasple.mc.trhologram.hologram.HologramManager
import me.arasple.mc.trhologram.nms.HoloPackets
import me.arasple.mc.trhologram.updater.Updater
import me.arasple.mc.trhologram.utils.FileWatcher
import org.bukkit.configuration.file.YamlConfiguration
import java.io.InputStreamReader
import java.util.function.Consumer
Expand All @@ -31,12 +29,6 @@ class TrHologramLoader {
TLocale.sendToConsole("PLUGIN.ENABLED", TrHologram.getPlugin().description.version)
}

fun cancel() {
FileWatcher.getWatcher().unregisterAll()
HologramManager.forceWrite()
TLocale.sendToConsole("PLUGIN.DISABLED")
}

private fun updateConfig() {
val oldCfg: TConfig = TrHologram.SETTINGS
val inputStream = TrHologram.getPlugin().getResource("settings.yml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.izzel.taboolib.util.Strings;
import io.izzel.taboolib.util.Variables;
import me.arasple.mc.trhologram.action.base.AbstractAction;
import me.arasple.mc.trhologram.utils.JsonItem;
import me.arasple.mc.trhologram.utils.Utils;
import me.arasple.mc.trhologram.utils.Vars;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void onExecute(Player player) {
public void setContent(String content) {
content = TLocale.Translate.setColored(content);
tellraw = TellrawJson.create();
if (JsonItem.isJson(content)) {
if (Utils.INSTANCE.isJson(content)) {
this.rawJson = content;
return;
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/me/arasple/mc/trhologram/commands/CommandDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import java.io.InputStreamReader
*/
class CommandDebug : BaseSubCommand() {

private val builtTime = YamlConfiguration.loadConfiguration(InputStreamReader(Files.getResource(TrHologram.getPlugin(), "plugin.yml"))).getString("built-time", "Null")

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>) {
if (sender is Player) {
val player = sender
Expand All @@ -36,11 +38,17 @@ class CommandDebug : BaseSubCommand() {

sender.sendMessage("§3--------------------------------------------------")
sender.sendMessage("")
sender.sendMessage("§2Total Holograms: §6" + Hologram.HOLOGRAMS.values.sumBy { x -> x.size })
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())
sender.sendMessage("§2TabooLib: §f" + Plugin.getVersion())
sender.sendMessage("§2Total Holograms: ")
Hologram.HOLOGRAMS.forEach {
if (it.value.isNotEmpty()) {
sender.sendMessage("§r §8[${it.key}§8] - §7${it.value.size}")
}
}
sender.sendMessage("")
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()}")
sender.sendMessage("§2TabooLib: §f${Plugin.getVersion()}")
sender.sendMessage("")
sender.sendMessage("§2TrHologram Built-Time: §b" + YamlConfiguration.loadConfiguration(InputStreamReader(Files.getResource(TrHologram.getPlugin(), "plugin.yml"))).getString("built-time", "Null"))
sender.sendMessage("§2TrHologram Built-Time: §b$builtTime")
sender.sendMessage("")
sender.sendMessage("§3--------------------------------------------------")
}
Expand Down
35 changes: 33 additions & 2 deletions src/main/java/me/arasple/mc/trhologram/hologram/Hologram.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.arasple.mc.trhologram.hologram

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

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

fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>): Hologram {
return createHologram(plugin, null, id, loc, contents, mutableListOf(), null, null)
}

fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>, actions: MutableList<ActionGroups>): Hologram {
return createHologram(plugin, null, id, loc, contents, actions, null, null)
}

fun createHologram(plugin: Plugin, id: String, loc: Location, contents: List<String>, actions: MutableList<ActionGroups>, condition: String?, distance: String?): Hologram {
return createHologram(plugin, null, id, loc, contents, actions, condition, distance)
}

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

fun display(player: Player) {
HOLOGRAMS.values.forEach { list ->
list.forEach { hologram ->
if (hologram.isVisible(player) && !hologram.viewers.contains(player)) {
hologram.display(player)
} else if (!hologram.isVisible(player) && hologram.viewers.contains(player)) {
hologram.destroy(player)
}
}
}
}

fun destroy(player: Player) {
HOLOGRAMS.values.forEach { list ->
list.forEach { hologram ->
hologram.removeViewer(player)
}
}
}

}

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

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

fun removeViewer(player: Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ open class HologramLine(private var text: String, val hologram: Hologram) {
PRIVATE METHODS & UTILS
*/
private fun getPackets(): HoloPackets {
return HoloPackets.getInst()
return HoloPackets.INSTANCE!!
}


Expand Down
18 changes: 10 additions & 8 deletions src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ object HologramManager {
Hologram.getHolograms().forEach { hologram ->
if (hologram.loadedFrom != null) {
val file = File(hologram.loadedFrom)
if (file.exists() && !FileWatcher.getWatcher().hasListener(file)) {
FileWatcher.getWatcher().addSimpleListener(file) {
if (file.exists() && !FileWatcher.watcher.hasListener(file)) {
FileWatcher.watcher.addSimpleListener(file) {
if (!writing) {
try {
hologram.initFromSection()
Expand Down Expand Up @@ -91,8 +91,8 @@ object HologramManager {
val file = Files.file(FOLDER.path + "/" + id + ".yml")
val holo = Hologram.createHologram(TrHologram.getPlugin(), file, id, loc, content.toList(), mutableListOf(), "null", "30")
Bukkit.getOnlinePlayers().stream().filter { player -> holo.isVisible(player) }.forEach { player -> holo.display(player) }
if (!FileWatcher.getWatcher().hasListener(file)) {
FileWatcher.getWatcher().addSimpleListener(file) {
if (!FileWatcher.watcher.hasListener(file)) {
FileWatcher.watcher.addSimpleListener(file) {
if (!writing) {
try {
holo.initFromSection()
Expand Down Expand Up @@ -136,10 +136,9 @@ object HologramManager {
}

fun write(hologram: Hologram) {
if (hologram.loadedFrom == null) {
return
}
val file = File(hologram.loadedFrom)
writing = true
val loadedFrom = hologram.loadedFrom ?: return
val file = File(loadedFrom)
val yaml = YamlConfiguration.loadConfiguration(file)
correctData(yaml)
yaml["viewDistance"] = hologram.viewDistance
Expand All @@ -151,6 +150,9 @@ object HologramManager {
} catch (e: IOException) {
e.printStackTrace()
}
if (TrHologram.getPlugin().isEnabled) {
Bukkit.getScheduler().runTaskLater(TrHologram.getPlugin(), Runnable { writing = false }, 20)
}
}

private fun restartTasks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.arasple.mc.trhologram.utils;
package me.arasple.mc.trhologram.item;

import io.izzel.taboolib.internal.apache.lang3.math.NumberUtils;
import org.bukkit.Color;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/me/arasple/mc/trhologram/item/Mat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import io.izzel.taboolib.internal.apache.lang3.math.NumberUtils;
import io.izzel.taboolib.util.Strings;
import io.izzel.taboolib.util.item.Items;
import io.izzel.taboolib.util.lite.Materials;
import me.arasple.mc.trhologram.TrHologram;
import me.arasple.mc.trhologram.utils.*;
import me.arasple.mc.trhologram.utils.JavaScript;
import me.arasple.mc.trhologram.utils.Skulls;
import me.arasple.mc.trhologram.utils.Utils;
import me.arasple.mc.trhologram.utils.Vars;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -48,10 +52,10 @@ public Mat(String rawMat) {
}
this.mat = rawMat.replaceAll("<([^<>].+)>", "").replaceAll(" ", "");

if (JsonItem.isJson(this.mat)) {
if (Utils.INSTANCE.isJson(this.mat)) {
option = option != Option.VARIABLE ? Option.JSON : Option.VARIABLE;
if (option == Option.JSON) {
staticItem = JsonItem.fromJson(rawMat);
staticItem = Items.fromJson(rawMat);
}
}
}
Expand Down Expand Up @@ -82,8 +86,8 @@ public ItemStack createItem(Player player) {
if (staticItem != null) {
return staticItem.clone();
}
if (option == Option.VARIABLE && JsonItem.isJson(mat)) {
return JsonItem.fromJson(Vars.replace(player, mat));
if (option == Option.VARIABLE && Utils.INSTANCE.isJson(mat)) {
return Items.fromJson(Vars.replace(player, mat));
}
ItemStack item;
ItemMeta meta;
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/me/arasple/mc/trhologram/listeners/BugListener.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.arasple.mc.trhologram.listeners

import io.izzel.taboolib.module.inject.TListener
import me.arasple.mc.trhologram.hologram.Hologram
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerChangedWorldEvent

/**
* @author Arasple
* @date 2020/2/24 15:20
*/
@TListener
class ListenerPlayerChangeWorld : Listener {

@EventHandler
fun onChange(e: PlayerChangedWorldEvent) {
Hologram.display(e.player)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ListenerPlayerJoin : Listener {

@EventHandler
fun onJoin(e: PlayerJoinEvent) {
Hologram.getHolograms().stream().filter { hologram -> hologram.isVisible(e.player) }.forEach { hologram -> hologram.display(e.player) }
Hologram.display(e.player)
}

}
Loading

0 comments on commit eeb0224

Please sign in to comment.