-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
179d8d6
commit 9e7a3a4
Showing
9 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
api/src/main/java/kr/toxicity/hud/api/event/CustomPopupEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kr.toxicity.hud.api.event; | ||
|
||
import lombok.Getter; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.player.PlayerEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Getter | ||
public class CustomPopupEvent extends PlayerEvent implements BetterHudEvent { | ||
private final String name; | ||
private final Map<String, String> variables = new HashMap<>(); | ||
public CustomPopupEvent(@NotNull Player who, @NotNull String name) { | ||
super(who); | ||
this.name = name; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
dist/src/main/kotlin/kr/toxicity/hud/manager/TriggerManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
dist/src/main/kotlin/kr/toxicity/hud/skript/SkriptManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package kr.toxicity.hud.skript | ||
|
||
import ch.njol.skript.Skript | ||
import kr.toxicity.hud.manager.BetterHudManager | ||
import kr.toxicity.hud.resource.GlobalResource | ||
import kr.toxicity.hud.skript.effect.EffCallPopupEvent | ||
import kr.toxicity.hud.skript.effect.EffShowPopup | ||
import org.bukkit.Bukkit | ||
|
||
object SkriptManager: BetterHudManager { | ||
override fun start() { | ||
if (Bukkit.getPluginManager().isPluginEnabled("Skript")) { | ||
Skript.registerEffect(EffShowPopup::class.java, "[show] popup %string% to %players% [with [variable] [of] %-objects%] [keyed by %-object%]") | ||
Skript.registerEffect(EffCallPopupEvent::class.java, "call popup event for %players% named %string% [with [variable] [of] %-objects%] [keyed by %-object%]") | ||
} | ||
} | ||
|
||
override fun reload(resource: GlobalResource) { | ||
} | ||
|
||
override fun end() { | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
dist/src/main/kotlin/kr/toxicity/hud/skript/effect/EffCallPopupEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kr.toxicity.hud.skript.effect | ||
|
||
import ch.njol.skript.lang.Effect | ||
import ch.njol.skript.lang.Expression | ||
import ch.njol.skript.lang.SkriptParser | ||
import ch.njol.skript.util.LiteralUtils | ||
import ch.njol.util.Kleenean | ||
import kr.toxicity.hud.api.event.CustomPopupEvent | ||
import kr.toxicity.hud.util.call | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.Event | ||
|
||
class EffCallPopupEvent: Effect() { | ||
override fun toString(p0: Event?, p1: Boolean): String { | ||
return "call popup event for ${player.toString(p0, p1)} named ${name.toString(p0, p1)} with variable of ${objects?.toString(p0, p1)} keyed by ${key?.toString(p0, p1)}" | ||
} | ||
|
||
private lateinit var player: Expression<Player> | ||
private lateinit var name: Expression<String> | ||
private var objects: Expression<*>? = null | ||
private var key: Expression<*>? = null | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun init(p0: Array<out Expression<*>?>, p1: Int, p2: Kleenean, p3: SkriptParser.ParseResult): Boolean { | ||
player = p0[0] as Expression<Player> | ||
name = p0[1] as Expression<String> | ||
if (p0[2] != null) { | ||
objects = p0[2] as Expression<String> | ||
if (p0[3] != null) key = p0[3] | ||
if (LiteralUtils.hasUnparsedLiteral(objects)) objects = LiteralUtils.defendExpression<Any>(objects) | ||
} | ||
return true | ||
} | ||
|
||
override fun execute(p0: Event) { | ||
val obj = objects?.getAll(p0) ?: emptyArray() | ||
name.getSingle(p0)?.let { n -> | ||
player.getAll(p0).forEach { p -> | ||
CustomPopupEvent(p, n).apply { | ||
obj.forEachIndexed { i, s -> | ||
variables["skript_${i + 1}"] = s.toString() | ||
} | ||
}.call() | ||
} | ||
} | ||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
dist/src/main/kotlin/kr/toxicity/hud/skript/effect/EffShowPopup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package kr.toxicity.hud.skript.effect | ||
|
||
import ch.njol.skript.lang.Effect | ||
import ch.njol.skript.lang.Expression | ||
import ch.njol.skript.lang.ExpressionList | ||
import ch.njol.skript.lang.SkriptParser | ||
import ch.njol.skript.util.LiteralUtils | ||
import ch.njol.util.Kleenean | ||
import kr.toxicity.hud.api.event.CustomPopupEvent | ||
import kr.toxicity.hud.api.update.BukkitEventUpdateEvent | ||
import kr.toxicity.hud.manager.PopupManagerImpl | ||
import kr.toxicity.hud.util.call | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.Event | ||
import java.util.UUID | ||
|
||
class EffShowPopup: Effect() { | ||
override fun toString(p0: Event?, p1: Boolean): String { | ||
return "show popup ${popup.toString(p0, p1)} to ${player.toString(p0, p1)} with variable of ${objects?.toString(p0, p1)} keyed by ${key?.toString(p0, p1)}" | ||
} | ||
|
||
private lateinit var popup: Expression<String> | ||
private lateinit var player: Expression<Player> | ||
private var objects: Expression<*>? = null | ||
private var key: Expression<*>? = null | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun init(p0: Array<out Expression<*>?>, p1: Int, p2: Kleenean, p3: SkriptParser.ParseResult): Boolean { | ||
popup = p0[0] as Expression<String> | ||
player = p0[1] as Expression<Player> | ||
if (p0[2] != null) { | ||
objects = p0[2] as Expression<String> | ||
if (p0[3] != null) key = p0[3] | ||
if (LiteralUtils.hasUnparsedLiteral(objects)) objects = LiteralUtils.defendExpression<Any>(objects) | ||
} | ||
return true | ||
} | ||
|
||
override fun execute(p0: Event) { | ||
val popup = PopupManagerImpl.getPopup(popup.getSingle(p0) ?: return) ?: return | ||
val obj = objects?.getAll(p0) ?: emptyArray() | ||
player.getAll(p0).forEach { p -> | ||
val event = CustomPopupEvent(p, "").apply { | ||
obj.forEachIndexed { i, s -> | ||
variables["skript_${i + 1}"] = s.toString() | ||
} | ||
} | ||
runCatching { | ||
popup.show(BukkitEventUpdateEvent(event, key?.getSingle(p0) ?: UUID.randomUUID()), p) | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ softdepend: | |
- Vault | ||
- floodgate | ||
- Geyser-Spigot | ||
- Skript | ||
commands: | ||
betterhud: | ||
aliases: | ||
|