-
-
Notifications
You must be signed in to change notification settings - Fork 51
MobArena PlayerTag Fixes #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| package com.denizenscript.depenizen.bukkit.properties.mobarena; | ||
|
|
||
| import com.denizenscript.denizen.objects.PlayerTag; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import com.denizenscript.denizencore.objects.core.MapTag; | ||
| import com.denizenscript.denizencore.utilities.debugging.SlowWarning; | ||
| import com.denizenscript.depenizen.bukkit.bridges.MobArenaBridge; | ||
| import com.denizenscript.depenizen.bukkit.objects.mobarena.MobArenaArenaTag; | ||
| import com.garbagemule.MobArena.ArenaPlayer; | ||
| import com.garbagemule.MobArena.ArenaPlayerStatistics; | ||
| import com.garbagemule.MobArena.MobArena; | ||
| import com.garbagemule.MobArena.framework.Arena; | ||
|
|
||
| public class MobArenaPlayerExtensions { | ||
|
|
||
| public static SlowWarning mobArenaPlayerTags = new SlowWarning("mobArenaPlayerTags", "Tags in the format 'PlayerTag.mobarena.x' have been deprecated: check the meta site for updated versions."); | ||
|
|
||
| public static Arena getArena(PlayerTag player) { | ||
| return ((MobArena) MobArenaBridge.instance.plugin).getArenaMaster().getArenaWithPlayer(player.getPlayerEntity()); | ||
| } | ||
|
|
||
| public static ArenaPlayer getArenaPlayer(PlayerTag player) { | ||
| return getArena(player).getArenaPlayer(player.getPlayerEntity()); | ||
| } | ||
|
|
||
| public static void register() { | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.in_mobarena> | ||
| // @returns ElementTag(Boolean) | ||
| // @plugin Depenizen, MobArena | ||
| // @description | ||
| // Returns whether the player is in a mobarena. | ||
| // --> | ||
| PlayerTag.tagProcessor.registerTag(ElementTag.class, "in_mobarena", (attribute, player) -> { | ||
| return new ElementTag(getArena(player) != null); | ||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.current_mobarena> | ||
| // @returns MobArenaArenaTag | ||
| // @plugin Depenizen, MobArena | ||
| // @description | ||
| // Returns the arena the player is in. | ||
| // NOTE: Requires the player to be in an arena. | ||
| // --> | ||
| PlayerTag.tagProcessor.registerTag(MobArenaArenaTag.class, "current_mobarena", (attribute, player) -> { | ||
| return getArena(player) != null ? new MobArenaArenaTag(getArena(player)) : null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to be calling |
||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena_class> | ||
| // @returns ElementTag | ||
| // @plugin Depenizen, MobArena | ||
| // @description | ||
| // Returns the name of the class the player is using. | ||
| // NOTE: Requires the player to be in an arena. | ||
| // --> | ||
| PlayerTag.tagProcessor.registerTag(ElementTag.class, "mobarena_class", (attribute, player) -> { | ||
| return getArena(player) != null ? new ElementTag(getArenaPlayer(player).getArenaClass().getConfigName(), true) : null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe same thing here, alongside making |
||
| }); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena_stats> | ||
| // @returns MapTag | ||
| // @plugin Depenizen, MobArena | ||
| // @description | ||
| // Returns the stats of a player in their current arena. | ||
| // Valid keys are 'KILLS', 'DAMAGE_DONE', 'DAMAGE_TAKEN', 'LAST_WAVE', 'TIMES_SWUNG', and 'TIMES_HIT'. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
| // --> | ||
| PlayerTag.tagProcessor.registerTag(MapTag.class, "mobarena_stats", (attribute, player) -> { | ||
| if (getArena(player) == null) { | ||
| attribute.echoError("This player is not in an arena."); | ||
| return null; | ||
| } | ||
| ArenaPlayerStatistics stats = getArenaPlayer(player).getStats(); | ||
| MapTag values = new MapTag(); | ||
| values.putObject("kills", new ElementTag(stats.getInt("kills"))); | ||
| values.putObject("damage_done", new ElementTag(stats.getInt("dmgDone"))); | ||
| values.putObject("damage_taken", new ElementTag(stats.getInt("dmgTaken"))); | ||
| values.putObject("last_wave", new ElementTag(stats.getInt("lastWave"))); | ||
| values.putObject("times_swung", new ElementTag(stats.getInt("swings"))); | ||
| values.putObject("times_hit", new ElementTag(stats.getInt("hits"))); | ||
| return values; | ||
| }); | ||
|
|
||
| PlayerTag.tagProcessor.registerTag(ObjectTag.class, "mobarena", (attribute, player) -> { | ||
| mobArenaPlayerTags.warn(attribute.context); | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.in_arena> | ||
| // @returns ElementTag(Boolean) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.in_mobarena' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick but these should start lowercase, as they're used as a part of a bigger message in e.g. VSC |
||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.in_mobarena>. | ||
| // --> | ||
| if (attribute.startsWith("in_arena", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(getArena(player) != null); | ||
| } | ||
| if (getArena(player) != null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, no need to call it each time - seeing as this is all one big tag block anyway just put it in a variable |
||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.current_arena> | ||
| // @returns MobArenaArenaTag | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.current_mobarena' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.current_mobarena>. | ||
| // --> | ||
| if (attribute.startsWith("current_arena", 2)) { | ||
| attribute.fulfill(1); | ||
| return new MobArenaArenaTag(getArena(player)); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.class> | ||
| // @returns ElementTag | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_class' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_class>. | ||
| // --> | ||
| else if (attribute.startsWith("class", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(getArenaPlayer(player).getArenaClass().getConfigName(), true); | ||
| } | ||
| } | ||
|
|
||
| if (attribute.startsWith("stats", 2)) { | ||
| attribute.fulfill(1); | ||
| ArenaPlayerStatistics stats = getArenaPlayer(player).getStats(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this not remove functionality? Looks like it let you input any mob arena previously (same for the new |
||
| if (stats == null) { | ||
| return null; | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].kills> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[kills]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'KILLS' key. | ||
| // --> | ||
| if (attribute.startsWith("kills", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("kills")); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].damage_done> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[damage_done]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'DAMAGE_DONE' key. | ||
| // @description | ||
| // Returns the amount of damage the player has dealt in the arena. | ||
| // --> | ||
| else if (attribute.startsWith("damage_done", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("dmgDone")); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].damage_taken> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[damage_taken]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'DAMAGE_TAKEN' key. | ||
| // --> | ||
| else if (attribute.startsWith("damage_taken", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("dmgTaken")); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].last_wave> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[last_wave]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'LAST_WAVE' key. | ||
| // --> | ||
| else if (attribute.startsWith("last_wave", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("lastWave")); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].times_swung> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[times_swung]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'TIMES_SWUNG' key. | ||
| // --> | ||
| else if (attribute.startsWith("times_swung", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("swings")); | ||
| } | ||
|
|
||
| // <--[tag] | ||
| // @attribute <PlayerTag.mobarena.stats[<mobarena>].times_hit> | ||
| // @returns ElementTag(Number) | ||
| // @plugin Depenizen, MobArena | ||
| // @deprecated Use 'PlayerTag.mobarena_stats.get[times_hit]' | ||
| // @description | ||
| // Deprecated in favor of <@link tag PlayerTag.mobarena_stats> with the 'TIMES_HIT' key. | ||
| // --> | ||
| else if (attribute.startsWith("times_hit", 2)) { | ||
| attribute.fulfill(1); | ||
| return new ElementTag(stats.getInt("hits")); | ||
| } | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the format X->in the X format,meta docs for more information