forked from alkarinv/BattleArena
-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
23 changed files
with
354 additions
and
44 deletions.
There are no files selected for viewing
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,7 @@ | ||
repositories { | ||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") | ||
} | ||
|
||
dependencies { | ||
compileOnly("me.clip:placeholderapi:2.11.6") | ||
} |
123 changes: 123 additions & 0 deletions
123
...ion/src/main/java/org/battleplugins/arena/module/placeholderapi/BattleArenaExpansion.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,123 @@ | ||
package org.battleplugins.arena.module.placeholderapi; | ||
|
||
import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||
import org.battleplugins.arena.Arena; | ||
import org.battleplugins.arena.ArenaPlayer; | ||
import org.battleplugins.arena.BattleArena; | ||
import org.battleplugins.arena.competition.Competition; | ||
import org.battleplugins.arena.competition.phase.CompetitionPhaseType; | ||
import org.battleplugins.arena.resolver.Resolver; | ||
import org.battleplugins.arena.resolver.ResolverKey; | ||
import org.battleplugins.arena.resolver.ResolverKeys; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BattleArenaExpansion extends PlaceholderExpansion { | ||
private final BattleArena plugin; | ||
|
||
public BattleArenaExpansion(BattleArena plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public @NotNull String getIdentifier() { | ||
return "ba"; | ||
} | ||
|
||
@Override | ||
public @NotNull String getAuthor() { | ||
return "BattlePlugins"; | ||
} | ||
|
||
@Override | ||
public @NotNull String getVersion() { | ||
return this.plugin.getPluginMeta().getVersion(); | ||
} | ||
|
||
@Override | ||
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) { | ||
String[] split = params.split("_"); | ||
|
||
// No data for us to parse | ||
if (split.length < 2) { | ||
return null; | ||
} | ||
|
||
ArenaPlayer arenaPlayer = ArenaPlayer.getArenaPlayer(player); | ||
if (arenaPlayer != null && params.startsWith("competition")) { | ||
String placeholder = String.join("_", split).substring("competition_".length()); | ||
|
||
Resolver resolver = arenaPlayer.resolve(); | ||
ResolverKey<?> resolverKey = ResolverKeys.get(placeholder.replace("_", "-")); | ||
if (resolverKey != null && resolver.has(resolverKey)) { | ||
return resolver.resolveToString(resolverKey); | ||
} | ||
} | ||
|
||
// If player is null or no other placeholder resolvers have made it to this point, | ||
// handle more general placeholders | ||
|
||
String arenaName = split[0]; | ||
Arena arena = this.plugin.getArena(arenaName); | ||
|
||
// No arena, so not much we can do here | ||
if (arena == null) { | ||
return null; | ||
} | ||
|
||
// Remaining text in split array | ||
String placeholder = String.join("_", split).substring(arenaName.length() + 1); | ||
switch (placeholder) { | ||
case "active_competitions": { | ||
return String.valueOf(this.plugin.getCompetitions(arena).size()); | ||
} | ||
case "online_players": { | ||
int players = 0; | ||
for (Competition<?> competition : this.plugin.getCompetitions(arena)) { | ||
players += competition.getAlivePlayerCount() + competition.getSpectatorCount(); | ||
} | ||
|
||
return String.valueOf(players); | ||
} | ||
case "alive_players": { | ||
int online = 0; | ||
for (Competition<?> competition : this.plugin.getCompetitions(arena)) { | ||
online += competition.getAlivePlayerCount(); | ||
} | ||
|
||
return String.valueOf(online); | ||
} | ||
case "spectators": { | ||
int spectators = 0; | ||
for (Competition<?> competition : this.plugin.getCompetitions(arena)) { | ||
spectators += competition.getSpectatorCount(); | ||
} | ||
|
||
return String.valueOf(spectators); | ||
} | ||
case "waiting_competitions": { | ||
int waitingCompetitions = 0; | ||
for (Competition<?> competition : this.plugin.getCompetitions(arena)) { | ||
CompetitionPhaseType<?, ?> phase = competition.getPhase(); | ||
if (CompetitionPhaseType.WAITING.equals(phase)) { | ||
waitingCompetitions++; | ||
} | ||
} | ||
return String.valueOf(waitingCompetitions); | ||
} | ||
case "ingame_competitions": { | ||
int ingameCompetitions = 0; | ||
for (Competition<?> competition : this.plugin.getCompetitions(arena)) { | ||
CompetitionPhaseType<?, ?> phase = competition.getPhase(); | ||
if (CompetitionPhaseType.INGAME.equals(phase)) { | ||
ingameCompetitions++; | ||
} | ||
} | ||
return String.valueOf(ingameCompetitions); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/org/battleplugins/arena/module/placeholderapi/PlaceholderApiContainer.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,16 @@ | ||
package org.battleplugins.arena.module.placeholderapi; | ||
|
||
import org.battleplugins.arena.BattleArena; | ||
|
||
public class PlaceholderApiContainer { | ||
private final BattleArenaExpansion expansion; | ||
|
||
public PlaceholderApiContainer(BattleArena plugin) { | ||
this.expansion = new BattleArenaExpansion(plugin); | ||
this.expansion.register(); | ||
} | ||
|
||
public void disable() { | ||
this.expansion.unregister(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...rc/main/java/org/battleplugins/arena/module/placeholderapi/PlaceholderApiIntegration.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,39 @@ | ||
package org.battleplugins.arena.module.placeholderapi; | ||
|
||
import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; | ||
import org.battleplugins.arena.event.BattleArenaShutdownEvent; | ||
import org.battleplugins.arena.module.ArenaModule; | ||
import org.battleplugins.arena.module.ArenaModuleInitializer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
|
||
/** | ||
* A module that allows for hooking into the PlaceholderAPI plugin. | ||
*/ | ||
@ArenaModule(id = PlaceholderApiIntegration.ID, name = "PlaceholderAPI", description = "Adds support for hooking into the PlaceholderAPI plugin.", authors = "BattlePlugins") | ||
public class PlaceholderApiIntegration implements ArenaModuleInitializer { | ||
public static final String ID = "placeholderapi"; | ||
|
||
private PlaceholderApiContainer container; | ||
|
||
@EventHandler | ||
public void onPostInitialize(BattleArenaPostInitializeEvent event) { | ||
// Check that we have Vault installed | ||
if (!Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) { | ||
event.getBattleArena().module(PlaceholderApiIntegration.ID).ifPresent(container -> | ||
container.disable("PlaceholderAPI is required for the PlaceholderAPI integration module to work!") | ||
); | ||
|
||
return; | ||
} | ||
|
||
this.container = new PlaceholderApiContainer(event.getBattleArena()); | ||
} | ||
|
||
@EventHandler | ||
public void onShutdown(BattleArenaShutdownEvent event) { | ||
if (this.container != null) { | ||
this.container.disable(); | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.