Contributor: darbyjack | Cleaned up the PlaceholderAPI expansion, updated to latest version. Keep placeholders on /papi reload

This commit is contained in:
Unknown 2018-11-30 04:25:01 +00:00
parent 45d8527ebc
commit e60a4beaa8
3 changed files with 187 additions and 119 deletions

50
pom.xml
View File

@ -1,6 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.songoda</groupId>
<artifactId>SkyBlock</artifactId>
<version>32</version>
<groupId>com.songoda</groupId>
<artifactId>SkyBlock</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>32</version>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<version>3.6.1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>private</id>
<url>http://repo.songoda.com/repository/private</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>be.maximvdw</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>net.milkbowl</groupId>
<artifactId>vault</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13.2</version>
</dependency>
</dependencies>
</project>

View File

@ -18,123 +18,140 @@ import me.goodandevil.skyblock.island.Role;
public class EZPlaceholder extends PlaceholderExpansion {
private final SkyBlock skyblock;
public EZPlaceholder(SkyBlock skyblock) {
this.skyblock = skyblock;
}
public String getIdentifier() {
return "skyblock";
private final SkyBlock skyblock;
public EZPlaceholder(SkyBlock skyblock) {
this.skyblock = skyblock;
}
@Override
public String getIdentifier() {
return "skyblock";
}
@Override
public String getPlugin() {
return null;
}
public String getAuthor() {
return skyblock.getDescription().getAuthors().get(0);
}
public String getVersion() {
return skyblock.getDescription().getVersion();
}
public String onPlaceholderRequest(Player player, String identifier) {
if (identifier.equalsIgnoreCase("islands")) {
return "" + skyblock.getVisitManager().getIslands().size();
}
if(player == null){
return "";
}
IslandManager islandManager = skyblock.getIslandManager();
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (islandManager.hasIsland(player)) {
Island island = islandManager.getIsland(skyblock.getPlayerDataManager().getPlayerData(player).getOwner());
if (identifier.equalsIgnoreCase("island_size")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_size.Non-empty.Message").replace("%placeholder", "" + island.getSize()));
} else if (identifier.equalsIgnoreCase("island_radius")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_radius.Non-empty.Message").replace("%placeholder", "" + island.getRadius()));
} else if (identifier.equalsIgnoreCase("island_level")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_level.Non-empty.Message").replace("%placeholder", "" + island.getLevel().getLevel()));
} else if (identifier.equalsIgnoreCase("island_points")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_points.Non-empty.Message").replace("%placeholder", "" + island.getLevel().getPoints()));
} else if (identifier.equalsIgnoreCase("island_role")) {
for (Role roleList : Role.values()) {
if (island.isRole(roleList, player.getUniqueId())) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_role.Non-empty.Message").replace("%placeholder", roleList.name()));
}
}
} else if (identifier.equalsIgnoreCase("island_owner")) {
UUID islandOwnerUUID = island.getOwnerUUID();
Player targetPlayer = Bukkit.getServer().getPlayer(islandOwnerUUID);
if (targetPlayer == null) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_owner.Non-empty.Other.Message").replace("%placeholder", Bukkit.getServer().getOfflinePlayer(islandOwnerUUID).getName()));
} else {
if (targetPlayer.getName().equals(player.getName())) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_owner.Non-empty.Yourself.Message").replace("%placeholder", targetPlayer.getName()));
} else {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_owner.Non-empty.Other.Message").replace("%placeholder", targetPlayer.getName()));
}
}
} else if (identifier.equalsIgnoreCase("island_biome")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_biome.Non-empty.Message").replace("%placeholder", island.getBiomeName()));
} else if (identifier.equalsIgnoreCase("island_time")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_time.Non-empty.Message").replace("%placeholder", "" + island.getTime()));
} else if (identifier.equalsIgnoreCase("island_weather")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_weather.Non-empty.Message").replace("%placeholder", "" + island.getWeatherName()));
} else if (identifier.equalsIgnoreCase("island_bans")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_bans.Non-empty.Message").replace("%placeholder", "" + island.getBan().getBans().size()));
} else if (identifier.equalsIgnoreCase("island_members_total")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_members_total.Non-empty.Message").replace("%placeholder", "" + (island.getRole(Role.Member).size() + island.getRole(Role.Operator).size() + 1)));
} else if (identifier.equalsIgnoreCase("island_members")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_members.Non-empty.Message").replace("%placeholder", "" + island.getRole(Role.Member).size()));
} else if (identifier.equalsIgnoreCase("island_operators")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_operators.Non-empty.Message").replace("%placeholder", "" + island.getRole(Role.Operator).size()));
} else if (identifier.equalsIgnoreCase("island_visitors")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_visitors.Non-empty.Message").replace("%placeholder", "" + island.getVisitors().size()));
}
return null;
}
if (identifier.equalsIgnoreCase("island_size")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_size.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_radius")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_radius.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_level")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_level.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_points")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_points.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_role")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_role.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_owner")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_owner.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_biome")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_biome.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_time")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_time.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_weather")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_weather.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_bans")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_bans.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_members_total")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_members_total.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_members")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_members.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_operators")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_operators.Empty.Message"));
} else if (identifier.equalsIgnoreCase("island_visitors")) {
return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.skyblock_island_visitors.Empty.Message"));
}
return null;
}
@Override
public String getAuthor() {
return skyblock.getDescription().getAuthors().get(0);
}
@Override
public String getVersion() {
return skyblock.getDescription().getVersion();
}
public String onPlaceholderRequest(Player player, String identifier) {
if (identifier.equalsIgnoreCase("islands")) {
return "" + skyblock.getVisitManager().getIslands().size();
}
if (player == null) {
return "";
}
IslandManager islandManager = skyblock.getIslandManager();
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (islandManager.hasIsland(player)) {
Island island = islandManager.getIsland(skyblock.getPlayerDataManager().getPlayerData(player).getOwner());
switch (identifier) {
case "island_size":
return value(configLoad, "Placeholder.skyblock_island_size.Non-empty.Message", island.getSize());
case "island_radius":
return value(configLoad, "Placeholder.skyblock_island_radius.Non-empty.Message", island.getSize());
case "island_level":
return value(configLoad, "Placeholder.skyblock_island_level.Non-empty.Message", island.getLevel().getLevel());
case "island_points":
return value(configLoad, "Placeholder.skyblock_island_points.Non-empty.Message", island.getLevel().getPoints());
case "island_biome":
return value(configLoad, "Placeholder.skyblock_island_biome.Non-empty.Message", island.getBiomeName());
case "island_time":
return value(configLoad, "Placeholder.skyblock_island_time.Non-empty.Message", island.getTime());
case "island_weather":
return value(configLoad, "Placeholder.skyblock_island_weather.Non-empty.Message", island.getWeatherName());
case "island_bans":
return value(configLoad, "Placeholder.skyblock_island_bans.Non-empty.Message", island.getBan().getBans().size());
case "island_members_total":
return value(configLoad, "Placeholder.skyblock_island_members_total.Non-empty.Message", (island.getRole(Role.Member).size() + island.getRole(Role.Operator).size() + 1));
case "island_members":
return value(configLoad, "Placeholder.skyblock_island_members.Non-empty.Message", island.getRole(Role.Member).size());
case "island_operators":
return value(configLoad, "Placeholder.skyblock_island_operators.Non-empty.Message", island.getRole(Role.Operator).size());
case "island_visitors":
return value(configLoad, "Placeholder.skyblock_island_visitors.Non-empty.Message", island.getVisitors().size());
case "island_role":
for (Role roleList : Role.values()) {
if (island.isRole(roleList, player.getUniqueId())) {
return value(configLoad, "Placeholder.skyblock_island_role.Non-empty.Message", roleList.name());
}
}
case "island_owner":
UUID owner = island.getOwnerUUID();
Player target = Bukkit.getServer().getPlayer(owner);
if (target == null) {
return value(configLoad, "Placeholder.skyblock_island_owner.Non-empty.Other.Message", Bukkit.getServer().getOfflinePlayer(owner).getName());
}
if (target.getName().equals(player.getName())) {
return value(configLoad, "Placeholder.skyblock_island_owner.Non-empty.Yourself.Message", target.getName());
} else {
return value(configLoad, "Placeholder.skyblock_island_owner.Non-empty.Other.Message", target.getName());
}
}
return null;
}
switch (identifier) {
case "island_size":
return value(configLoad, "Placeholder.skyblock_island_size.Empty.Message");
case "island_radius":
return value(configLoad, "Placeholder.skyblock_island_radius.Empty.Message");
case "island_level":
return value(configLoad, "Placeholder.skyblock_island_level.Empty.Message");
case "island_points":
return value(configLoad, "Placeholder.skyblock_island_points.Empty.Message");
case "island_role":
return value(configLoad, "Placeholder.skyblock_island_role.Empty.Message");
case "island_owner":
return value(configLoad, "Placeholder.skyblock_island_owner.Empty.Message");
case "island_biome":
return value(configLoad, "Placeholder.skyblock_island_biome.Empty.Message");
case "island_time":
return value(configLoad, "Placeholder.skyblock_island_time.Empty.Message");
case "island_weather":
return value(configLoad, "Placeholder.skyblock_island_weather.Empty.Message");
case "island_bans":
return value(configLoad, "Placeholder.skyblock_island_bans.Empty.Message");
case "island_members_total":
return value(configLoad, "Placeholder.skyblock_island_members_total.Empty.Message");
case "island_members":
return value(configLoad, "Placeholder.skyblock_island_members.Empty.Message");
case "island_operators":
return value(configLoad, "Placeholder.skyblock_island_operators.Empty.Message");
case "island_visitors":
return value(configLoad, "Placeholder.skyblock_island_visitors.Empty.Message");
}
return null;
}
private String color(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}
private String value(FileConfiguration configLoad, String string, Object value) {
return color(configLoad.getString(string).replace("%placeholder", (CharSequence) value));
}
private String value(FileConfiguration configLoad, String string) {
return color(configLoad.getString(string));
}
}

View File

@ -0,0 +1,9 @@
Copyright (c) 2018 Brianna OKeefe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software with minimal restriction, including the rights to use, copy, modify or merge while excluding the rights to publish, (re)distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The same distribution rights and limitations above shall similarly apply to any and all source code, and other means that can be used to emulate this work.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.