hytale
This commit is contained in:
1 parent
9fb5b2347f
commit
1c9ab6be8a
7 files changed
+676
-735
No files matched your search
+24
-1
@@ -124,6 +124,22 @@ fabric.properties
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Gradle ###
|
||||
.gradle/
|
||||
gradle-app.setting
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
### OS/Logs ###
|
||||
*.log
|
||||
hs_err_pid*
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
.DS_Store
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
@@ -148,4 +164,11 @@ nbdist/
|
||||
nbactions.xml
|
||||
|
||||
### Piggy's Debugging Shit ###
|
||||
server/
|
||||
server/
|
||||
gradlew.bat
|
||||
gradlew
|
||||
gradle/wrapper/gradle-wrapper.jar
|
||||
libs/HytaleServer.jar
|
||||
libs/papiHytale.jar
|
||||
|
||||
gradle/wrapper/gradle-wrapper.properties
|
||||
@@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'com.extendedclip.papi.expansion.player'
|
||||
version = '1.0.0'
|
||||
description = 'PlaceholderAPI expansion for player placeholders'
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compileOnly files('libs/HytaleServer.jar')
|
||||
compileOnly files('libs/papiHytale.jar')
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
tasks.named('jar') {
|
||||
archiveBaseName.set('PAPI-Expansion-HyPlayer')
|
||||
manifest {
|
||||
attributes(
|
||||
'Implementation-Title': project.name,
|
||||
'Implementation-Version': project.version
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<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.extendedclip.papi.expansion.player</groupId>
|
||||
<artifactId>player-expansion</artifactId>
|
||||
<version>2.0.9</version>
|
||||
|
||||
<name>PAPI-Expansion-Player</name>
|
||||
<description>PlaceholderAPI expansion for player placeholders</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<finalName>${project.name}</finalName>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = 'hyplayer-expansion'
|
||||
@@ -21,91 +21,75 @@
|
||||
|
||||
package com.extendedclip.papi.expansion.player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.Configurable;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.*;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.durability;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.format12;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.format24;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getBiome;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getCapitalizedBiome;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getEmptySlots;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getDirection;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getTotalExperience;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.getXZDirection;
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.itemInHand;
|
||||
import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
import com.hypixel.hytale.server.core.universe.Universe;
|
||||
|
||||
public final class PlayerExpansion extends PlaceholderExpansion implements Configurable {
|
||||
private String low;
|
||||
private String medium;
|
||||
private String high;
|
||||
import at.helpch.placeholderapi.PlaceholderAPIPlugin;
|
||||
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
private int mediumValue;
|
||||
private int highValue;
|
||||
|
||||
private String north;
|
||||
private String northEast;
|
||||
private String east;
|
||||
private String southEast;
|
||||
private String south;
|
||||
private String southWest;
|
||||
private String west;
|
||||
private String northWest;
|
||||
public final class PlayerExpansion extends PlaceholderExpansion {
|
||||
// private String low;
|
||||
// private String medium;
|
||||
// private String high;
|
||||
|
||||
// private int mediumValue;
|
||||
// private int highValue;
|
||||
|
||||
// private String north;
|
||||
// private String northEast;
|
||||
// private String east;
|
||||
// private String southEast;
|
||||
// private String south;
|
||||
// private String southWest;
|
||||
// private String west;
|
||||
// private String northWest;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "player";
|
||||
return "hyPlayer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "clip";
|
||||
return "HelpChat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "2.0.9";
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDefaults() {
|
||||
Map<String, Object> defaults = new HashMap<>();
|
||||
defaults.put("ping_color.high", "&c");
|
||||
defaults.put("ping_color.medium", "&e");
|
||||
defaults.put("ping_color.low", "&a");
|
||||
defaults.put("ping_value.medium", 50);
|
||||
defaults.put("ping_value.high", 100);
|
||||
defaults.put("direction.north", "N");
|
||||
defaults.put("direction.north_east", "NE");
|
||||
defaults.put("direction.east", "E");
|
||||
defaults.put("direction.south_east", "SE");
|
||||
defaults.put("direction.south", "S");
|
||||
defaults.put("direction.south_west", "SW");
|
||||
defaults.put("direction.west", "W");
|
||||
defaults.put("direction.north_west", "NW");
|
||||
return defaults;
|
||||
}
|
||||
// @Override
|
||||
// public Map<String, Object> getDefaults() {
|
||||
// Map<String, Object> defaults = new HashMap<>();
|
||||
// defaults.put("ping_color.high", "&c");
|
||||
// defaults.put("ping_color.medium", "&e");
|
||||
// defaults.put("ping_color.low", "&a");
|
||||
// defaults.put("ping_value.medium", 50);
|
||||
// defaults.put("ping_value.high", 100);
|
||||
// defaults.put("direction.north", "N");
|
||||
// defaults.put("direction.north_east", "NE");
|
||||
// defaults.put("direction.east", "E");
|
||||
// defaults.put("direction.south_east", "SE");
|
||||
// defaults.put("direction.south", "S");
|
||||
// defaults.put("direction.south_west", "SW");
|
||||
// defaults.put("direction.west", "W");
|
||||
// defaults.put("direction.north_west", "NW");
|
||||
// return defaults;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String identifier) {
|
||||
public String onRequest(Player player, String identifier) {
|
||||
|
||||
final boolean targetedPing = identifier.startsWith("ping_");
|
||||
final boolean targetedColoredPing = identifier.startsWith("colored_ping_");
|
||||
if (targetedPing || targetedColoredPing) {
|
||||
final Player target = Bukkit.getPlayer(identifier.substring(targetedPing ? 5 : 13)); // yes, I know, magic value
|
||||
// final boolean targetedPing = identifier.startsWith("ping_");
|
||||
// final boolean targetedColoredPing = identifier.startsWith("colored_ping_");
|
||||
// if (targetedPing || targetedColoredPing) {
|
||||
// final Player target = Bukkit.getPlayer(identifier.substring(targetedPing ? 5 : 13)); // yes, I know, magic value
|
||||
|
||||
return target == null ? "0" : retrievePing(target, targetedColoredPing);
|
||||
}
|
||||
// return target == null ? "0" : retrievePing(target, targetedColoredPing);
|
||||
// }
|
||||
|
||||
if (player == null) {
|
||||
return "";
|
||||
@@ -114,49 +98,44 @@ public final class PlayerExpansion extends PlaceholderExpansion implements Confi
|
||||
// offline placeholders
|
||||
switch (identifier) {
|
||||
case "name":
|
||||
return player.getName();
|
||||
return player.getDisplayName();
|
||||
case "uuid":
|
||||
return player.getUniqueId().toString();
|
||||
return player.getUuid().toString();
|
||||
case "has_played_before":
|
||||
return bool(player.hasPlayedBefore());
|
||||
case "online":
|
||||
return bool(player.isOnline());
|
||||
case "is_whitelisted":
|
||||
return bool(player.isWhitelisted());
|
||||
case "is_banned":
|
||||
return bool(player.isBanned());
|
||||
case "is_op":
|
||||
return bool(player.isOp());
|
||||
case "first_played":
|
||||
case "first_join":
|
||||
return String.valueOf(player.getFirstPlayed());
|
||||
case "first_played_formatted":
|
||||
case "first_join_date":
|
||||
return PlaceholderAPIPlugin.getDateFormat().format(new Date(player.getFirstPlayed()));
|
||||
case "last_played":
|
||||
case "last_join":
|
||||
return String.valueOf(player.getLastPlayed());
|
||||
case "last_played_formatted":
|
||||
case "last_join_date":
|
||||
return PlaceholderAPIPlugin.getDateFormat().format(new Date(player.getLastPlayed()));
|
||||
case "bed_x":
|
||||
return player.getBedSpawnLocation() != null ? String.valueOf(player.getBedSpawnLocation().getX()) : "";
|
||||
case "bed_y":
|
||||
return player.getBedSpawnLocation() != null ? String.valueOf(player.getBedSpawnLocation().getY()) : "";
|
||||
case "bed_z":
|
||||
return player.getBedSpawnLocation() != null ? String.valueOf(player.getBedSpawnLocation().getZ()) : "";
|
||||
case "bed_world":
|
||||
return player.getBedSpawnLocation() != null ? player.getBedSpawnLocation().getWorld()
|
||||
.getName() : "";
|
||||
|
||||
return bool(!player.isFirstSpawn());
|
||||
// case "online":
|
||||
// return bool(player.isOnline());
|
||||
// case "is_whitelisted":
|
||||
// return bool(player.isWhitelisted());
|
||||
// case "is_banned":
|
||||
// return bool(player.isBanned());
|
||||
// case "is_op":
|
||||
// return bool();
|
||||
// case "first_played":
|
||||
// case "first_join":
|
||||
// return String.valueOf(player.get);
|
||||
// case "first_played_formatted":
|
||||
// case "first_join_date":
|
||||
// return PlaceholderAPIPlugin.getDateFormat().format(new Date(player.getFirstPlayed()));
|
||||
// case "last_played":
|
||||
// case "last_join":
|
||||
// return String.valueOf(player.getLastPlayed());
|
||||
// case "last_played_formatted":
|
||||
// case "last_join_date":
|
||||
// return PlaceholderAPIPlugin.getDateFormat().format(new Date(player.getLastPlayed()));
|
||||
case "spawn_x":
|
||||
return String.valueOf(player.getRespawnPosition(null, identifier, null).getAxisDirection().getX());
|
||||
case "spawn_y":
|
||||
return String.valueOf(player.getRespawnPosition(null, identifier, null).getAxisDirection().getY());
|
||||
case "spawn_z":
|
||||
return String.valueOf(player.getRespawnPosition(null, identifier, null).getAxisDirection().getZ());
|
||||
// case "spawn_world":
|
||||
// return String.valueOf(player.getRespawnPosition(null, identifier, null));
|
||||
}
|
||||
|
||||
// online placeholders
|
||||
if (!player.isOnline()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Player p = player.getPlayer();
|
||||
|
||||
Player p = player;
|
||||
|
||||
// to get rid of IDE warnings
|
||||
if (p == null) {
|
||||
@@ -171,317 +150,355 @@ public final class PlayerExpansion extends PlaceholderExpansion implements Confi
|
||||
return bool(false);
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_potioneffect_")) {
|
||||
if (identifier.split("has_potioneffect_").length > 1) {
|
||||
String effect = identifier.split("has_potioneffect_")[1];
|
||||
PotionEffectType potion = PotionEffectType.getByName(effect);
|
||||
return bool(p.hasPotionEffect(potion));
|
||||
}
|
||||
}
|
||||
// if (identifier.startsWith("has_potioneffect_")) {
|
||||
// if (identifier.split("has_potioneffect_").length > 1) {
|
||||
// String effect = identifier.split("has_potioneffect_")[1];
|
||||
// PotionEffectType potion = PotionEffectType.getByName(effect);
|
||||
// return bool(p.hasPotionEffect(potion));
|
||||
// }
|
||||
// }
|
||||
|
||||
if (identifier.startsWith("item_in_hand_level_")) {
|
||||
if (identifier.split("item_in_hand_level_").length > 1) {
|
||||
String enchantment = identifier.split("item_in_hand_level_")[1];
|
||||
return String.valueOf(itemInHand(p).getEnchantmentLevel(Enchantment.getByName(enchantment)));
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
if (identifier.startsWith("item_in_offhand_level_")) {
|
||||
if (identifier.split("item_in_offhand_level_").length > 1) {
|
||||
String enchantment = identifier.split("item_in_offhand_level_")[1];
|
||||
return String.valueOf(p.getInventory().getItemInOffHand().getEnchantmentLevel(Enchantment.getByName(enchantment)));
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
// if (identifier.startsWith("item_in_hand_level_")) {
|
||||
// if (identifier.split("item_in_hand_level_").length > 1) {
|
||||
// String enchantment = identifier.split("item_in_hand_level_")[1];
|
||||
// return String.valueOf(itemInHand(p).getEnchantmentLevel(Enchantment.getByName(enchantment)));
|
||||
// }
|
||||
// return "0";
|
||||
// }
|
||||
// if (identifier.startsWith("item_in_offhand_level_")) {
|
||||
// if (identifier.split("item_in_offhand_level_").length > 1) {
|
||||
// String enchantment = identifier.split("item_in_offhand_level_")[1];
|
||||
// return String.valueOf(p.getInventory().getItemInOffHand().getEnchantmentLevel(Enchantment.getByName(enchantment)));
|
||||
// }
|
||||
// return "0";
|
||||
// }
|
||||
|
||||
if (identifier.startsWith("locale")) {
|
||||
String localeStr = PlayerUtil.getLocale(p);
|
||||
String localeStrISO = localeStr.replace("_", "-");
|
||||
// if (identifier.startsWith("locale")) {
|
||||
|
||||
switch (identifier) {
|
||||
case "locale":
|
||||
return localeStr;
|
||||
case "locale_country":
|
||||
Locale locale = Locale.forLanguageTag(localeStrISO);
|
||||
if (locale == null)
|
||||
return "";
|
||||
return locale.getCountry();
|
||||
case "locale_display_country":
|
||||
locale = Locale.forLanguageTag(localeStrISO);
|
||||
if (locale == null)
|
||||
return "";
|
||||
return locale.getDisplayCountry();
|
||||
case "locale_display_name":
|
||||
locale = Locale.forLanguageTag(localeStrISO);
|
||||
if (locale == null)
|
||||
return "";
|
||||
return locale.getDisplayName();
|
||||
case "locale_short":
|
||||
return localeStr.substring(0, localeStr.indexOf("_"));
|
||||
}
|
||||
}
|
||||
// return Universe.get().getPlayer(p.getUuid()).getLanguage();
|
||||
|
||||
// switch (identifier) {
|
||||
// case "locale":
|
||||
// return localeStr;
|
||||
// case "locale_country":
|
||||
// Locale locale = Locale.forLanguageTag(localeStrISO);
|
||||
// if (locale == null)
|
||||
// return "";
|
||||
// return locale.getCountry();
|
||||
// case "locale_display_country":
|
||||
// locale = Locale.forLanguageTag(localeStrISO);
|
||||
// if (locale == null)
|
||||
// return "";
|
||||
// return locale.getDisplayCountry();
|
||||
// case "locale_display_name":
|
||||
// locale = Locale.forLanguageTag(localeStrISO);
|
||||
// if (locale == null)
|
||||
// return "";
|
||||
// return locale.getDisplayName();
|
||||
// case "locale_short":
|
||||
// return localeStr.substring(0, localeStr.indexOf("_"));
|
||||
// }
|
||||
// }
|
||||
|
||||
switch (identifier) {
|
||||
case "absorption": {
|
||||
if (VersionHelper.HAS_ABSORPTION_METHODS) {
|
||||
return Integer.toString((int) p.getAbsorptionAmount());
|
||||
} else {
|
||||
return "-1";
|
||||
}
|
||||
}
|
||||
case "has_empty_slot":
|
||||
return bool(p.getInventory().firstEmpty() > -1);
|
||||
case "empty_slots":
|
||||
return String.valueOf(getEmptySlots(p));
|
||||
case "server":
|
||||
case "servername":
|
||||
return "now available in the server expansion";
|
||||
case "language":
|
||||
return Universe.get().getPlayer(p.getUuid()).getLanguage();
|
||||
// case "absorption": {
|
||||
// if (VersionHelper.HAS_ABSORPTION_METHODS) {
|
||||
// return Integer.toString((int) p.getAbsorptionAmount());
|
||||
// } else {
|
||||
// return "-1";
|
||||
// }
|
||||
// }
|
||||
// case "has_empty_slot":
|
||||
// return p.getInventory().get
|
||||
// return bool(p.getInventory().firstEmpty() > -1);
|
||||
// case "empty_slots":
|
||||
// return String.valueOf(getEmptySlots(p));
|
||||
// case "server":
|
||||
// case "servername":
|
||||
// return "now available in the server expansion";
|
||||
case "displayname":
|
||||
return p.getDisplayName();
|
||||
case "list_name":
|
||||
return p.getPlayerListName();
|
||||
// case "list_name":
|
||||
// return p.getPlayerListName();
|
||||
case "gamemode":
|
||||
return p.getGameMode().name();
|
||||
case "direction":
|
||||
switch (getDirection(p)) {
|
||||
case NORTH:
|
||||
return north;
|
||||
case NORTH_EAST:
|
||||
return northEast;
|
||||
case EAST:
|
||||
return east;
|
||||
case SOUTH_EAST:
|
||||
return southEast;
|
||||
case SOUTH:
|
||||
return south;
|
||||
case SOUTH_WEST:
|
||||
return southWest;
|
||||
case WEST:
|
||||
return west;
|
||||
case NORTH_WEST:
|
||||
return northWest;
|
||||
}
|
||||
return "";
|
||||
case "direction_xz":
|
||||
return getXZDirection(p);
|
||||
// case "direction":
|
||||
// switch (PlayerUtil.getDirection(p)) { //Universe.get().getPlayer(p.getUuid()).getHeadRotation
|
||||
// case NORTH:
|
||||
// return north;
|
||||
// case NORTH_EAST:
|
||||
// return northEast;
|
||||
// case EAST:
|
||||
// return east;
|
||||
// case SOUTH_EAST:
|
||||
// return southEast;
|
||||
// case SOUTH:
|
||||
// return south;
|
||||
// case SOUTH_WEST:
|
||||
// return southWest;
|
||||
// case WEST:
|
||||
// return west;
|
||||
// case NORTH_WEST:
|
||||
// return northWest;
|
||||
// }
|
||||
// return "";
|
||||
// case "direction_xz":
|
||||
// return getXZDirection(p);
|
||||
case "world":
|
||||
return p.getWorld().getName();
|
||||
case "world_type":
|
||||
World.Environment environment = p.getWorld().getEnvironment();
|
||||
if (environment == World.Environment.NETHER) {
|
||||
return "Nether";
|
||||
} else if (environment == World.Environment.THE_END) {
|
||||
return "The End";
|
||||
} else if (environment == World.Environment.NORMAL) {
|
||||
return "Overworld";
|
||||
}
|
||||
return "";
|
||||
// case "world_type":
|
||||
// World.Environment environment = p.getWorld().getEnvironment();
|
||||
// if (environment == World.Environment.NETHER) {
|
||||
// return "Nether";
|
||||
// } else if (environment == World.Environment.THE_END) {
|
||||
// return "The End";
|
||||
// } else if (environment == World.Environment.NORMAL) {
|
||||
// return "Overworld";
|
||||
// }
|
||||
// return "";
|
||||
case "x":
|
||||
return String.valueOf(p.getLocation().getBlockX());
|
||||
case "x_long":
|
||||
return String.valueOf(p.getLocation().getX());
|
||||
return String.valueOf(Universe.get().getPlayer(p.getUuid()).getTransform().getPosition().getX());
|
||||
// case "x_long":
|
||||
// return String.valueOf(p.getLocation().getX());
|
||||
case "y":
|
||||
return String.valueOf(p.getLocation().getBlockY());
|
||||
case "y_long":
|
||||
return String.valueOf(p.getLocation().getY());
|
||||
return String.valueOf(Universe.get().getPlayer(p.getUuid()).getTransform().getPosition().getY());
|
||||
// case "y_long":
|
||||
// return String.valueOf(p.getLocation().getY());
|
||||
case "z":
|
||||
return String.valueOf(p.getLocation().getBlockZ());
|
||||
case "z_long":
|
||||
return String.valueOf(p.getLocation().getZ());
|
||||
return String.valueOf(Universe.get().getPlayer(p.getUuid()).getTransform().getPosition().getZ());
|
||||
// case "z_long":
|
||||
// return String.valueOf(p.getLocation().getZ());
|
||||
case "yaw":
|
||||
return String.valueOf(p.getLocation().getYaw());
|
||||
return String.valueOf(Universe.get().getPlayer(p.getUuid()).getHeadRotation().getYaw());
|
||||
case "pitch":
|
||||
return String.valueOf(p.getLocation().getPitch());
|
||||
return String.valueOf(Universe.get().getPlayer(p.getUuid()).getHeadRotation().getPitch());
|
||||
case "biome":
|
||||
return getBiome(p);
|
||||
case "biome_capitalized":
|
||||
return getCapitalizedBiome(p);
|
||||
case "light_level":
|
||||
return String.valueOf(p.getLocation().getBlock().getLightLevel());
|
||||
case "ip":
|
||||
return p.getAddress().getAddress().getHostAddress();
|
||||
case "allow_flight":
|
||||
return bool(p.getAllowFlight());
|
||||
case "can_pickup_items":
|
||||
return bool(p.getCanPickupItems());
|
||||
case "compass_x":
|
||||
return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockX()) : "";
|
||||
case "compass_y":
|
||||
return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockY()) : "";
|
||||
case "compass_z":
|
||||
return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockZ()) : "";
|
||||
case "compass_world":
|
||||
return p.getCompassTarget() != null ? p.getCompassTarget().getWorld().getName() : "";
|
||||
case "block_underneath":
|
||||
return String.valueOf(p.getLocation().clone().subtract(0, 1, 0).getBlock().getType());
|
||||
case "custom_name":
|
||||
return p.getCustomName() != null ? p.getCustomName() : p.getName();
|
||||
case "exp":
|
||||
return String.valueOf(p.getExp());
|
||||
case "current_exp":
|
||||
return String.valueOf(getTotalExperience(p));
|
||||
case "total_exp":
|
||||
return String.valueOf(p.getTotalExperience());
|
||||
case "exp_to_level":
|
||||
return String.valueOf(p.getExpToLevel());
|
||||
case "level":
|
||||
return String.valueOf(p.getLevel());
|
||||
case "fly_speed":
|
||||
return String.valueOf(p.getFlySpeed());
|
||||
case "food_level":
|
||||
return String.valueOf(p.getFoodLevel());
|
||||
case "health":
|
||||
return String.valueOf(p.getHealth());
|
||||
case "health_rounded":
|
||||
return String.valueOf(Math.round(p.getHealth()));
|
||||
case "health_scale":
|
||||
return String.valueOf(p.getHealthScale());
|
||||
case "has_health_boost":
|
||||
return bool(p.hasPotionEffect(PotionEffectType.HEALTH_BOOST));
|
||||
case "health_boost": {
|
||||
if (p.getHealthScale() > 20) {
|
||||
return Double.toString(p.getHealthScale() - 20);
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
return p.getWorldMapTracker().getCurrentBiomeName();
|
||||
// case "biome_capitalized":
|
||||
// return getCapitalizedBiome(p);
|
||||
// case "light_level":
|
||||
// return String.valueOf(p.getLocation().getBlock().getLightLevel()); */
|
||||
// case "network_id":
|
||||
// return String.valueOf(p.getNetworkId());
|
||||
// case "allow_flight":
|
||||
// return bool(p.getAllowFlight());
|
||||
// case "can_pickup_items":
|
||||
// return bool(p.getCanPickupItems());
|
||||
// case "compass_x":
|
||||
// return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockX()) : "";
|
||||
// case "compass_y":
|
||||
// return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockY()) : "";
|
||||
// case "compass_z":
|
||||
// return p.getCompassTarget() != null ? String.valueOf(p.getCompassTarget().getBlockZ()) : "";
|
||||
// case "compass_world":
|
||||
// return p.getCompassTarget() != null ? p.getCompassTarget().getWorld().getName() : "";
|
||||
// case "block_underneath":
|
||||
// return String.valueOf(p.getLocation().clone().subtract(0, 1, 0).getBlock().getType());
|
||||
// case "custom_name":
|
||||
// return p.getCustomName() != null ? p.getCustomName() : p.getName();
|
||||
// case "exp":
|
||||
// return String.valueOf(p.getExp());
|
||||
// case "current_exp":
|
||||
// return String.valueOf(getTotalExperience(p));
|
||||
// case "total_exp":
|
||||
// return String.valueOf(p.getTotalExperience());
|
||||
// case "exp_to_level":
|
||||
// return String.valueOf(p.getExpToLevel());
|
||||
// case "level":
|
||||
// return String.valueOf(p.getLevel());
|
||||
// case "fly_speed":
|
||||
// return String.valueOf(p.getFlySpeed());
|
||||
// case "food_level":
|
||||
// return String.valueOf(p.getFoodLevel());
|
||||
// case "health":
|
||||
// return String.valueOf(p.getHealth());
|
||||
// case "health_rounded":
|
||||
// return String.valueOf(Math.round(p.getHealth()));
|
||||
// case "health_scale":
|
||||
// return String.valueOf(p.getHealthScale());
|
||||
// case "has_health_boost":
|
||||
// return bool(p.hasPotionEffect(PotionEffectType.HEALTH_BOOST));
|
||||
// case "health_boost": {
|
||||
// if (p.getHealthScale() > 20) {
|
||||
// return Double.toString(p.getHealthScale() - 20);
|
||||
// } else {
|
||||
// return "0";
|
||||
// }
|
||||
// }
|
||||
case "item_in_hand":
|
||||
return String.valueOf(itemInHand(p).getType());
|
||||
case "item_in_hand_name":
|
||||
return itemInHand(p).getType() != Material.AIR && itemInHand(p).getItemMeta().hasDisplayName() ? itemInHand(p).getItemMeta().getDisplayName() : "";
|
||||
case "item_in_hand_data":
|
||||
return itemInHand(p).getType() != Material.AIR ? String.valueOf(itemInHand(p).getDurability()) : "0";
|
||||
return String.valueOf(p.getInventory().getActiveHotbarItem().getItemId());
|
||||
case "item_in_hand_quantity":
|
||||
return String.valueOf(p.getInventory().getActiveHotbarItem().getQuantity());
|
||||
case "item_in_hand_durability":
|
||||
return String.valueOf(durability(itemInHand(p)));
|
||||
case "item_in_offhand":
|
||||
return String.valueOf(p.getInventory().getItemInOffHand().getType());
|
||||
case "item_in_offhand_name":
|
||||
return p.getInventory().getItemInOffHand().getType() != Material.AIR && p.getInventory().getItemInOffHand().getItemMeta().hasDisplayName() ? p.getInventory().getItemInOffHand().getItemMeta().getDisplayName() : "";
|
||||
case "item_in_offhand_data":
|
||||
return p.getInventory().getItemInOffHand().getType() != Material.AIR ? String.valueOf(p.getInventory().getItemInOffHand().getDurability()) : "0";
|
||||
case "item_in_offhand_durability":
|
||||
return String.valueOf(durability(p.getInventory().getItemInOffHand()));
|
||||
case "last_damage":
|
||||
return String.valueOf(p.getLastDamage());
|
||||
case "max_health":
|
||||
return String.valueOf(p.getMaxHealth());
|
||||
case "max_health_rounded":
|
||||
return String.valueOf(Math.round(p.getMaxHealth()));
|
||||
case "max_air":
|
||||
return String.valueOf(p.getMaximumAir());
|
||||
case "max_no_damage_ticks":
|
||||
return String.valueOf(p.getMaximumNoDamageTicks());
|
||||
case "no_damage_ticks":
|
||||
return String.valueOf(p.getNoDamageTicks());
|
||||
case "armor_helmet_name":
|
||||
return Optional.ofNullable(p.getInventory().getHelmet()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
case "armor_helmet_data":
|
||||
return p.getInventory().getHelmet() != null ? String.valueOf(p.getInventory().getHelmet().getDurability()) : "0";
|
||||
case "armor_helmet_durability":
|
||||
return String.valueOf(durability(p.getInventory().getHelmet()));
|
||||
case "armor_chestplate_name":
|
||||
return Optional.ofNullable(p.getInventory().getChestplate()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
case "armor_chestplate_data":
|
||||
return p.getInventory().getChestplate() != null ? String.valueOf(p.getInventory().getChestplate().getDurability()) : "0";
|
||||
case "armor_chestplate_durability":
|
||||
return String.valueOf(durability(p.getInventory().getChestplate()));
|
||||
case "armor_leggings_name":
|
||||
return Optional.ofNullable(p.getInventory().getLeggings()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
case "armor_leggings_data":
|
||||
return p.getInventory().getLeggings() != null ? String.valueOf(p.getInventory().getLeggings().getDurability()) : "0";
|
||||
case "armor_leggings_durability":
|
||||
return String.valueOf(durability(p.getInventory().getLeggings()));
|
||||
case "armor_boots_name":
|
||||
return Optional.ofNullable(p.getInventory().getBoots()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
case "armor_boots_data":
|
||||
return p.getInventory().getBoots() != null ? String.valueOf(p.getInventory().getBoots().getDurability()) : "0";
|
||||
case "armor_boots_durability":
|
||||
return String.valueOf(durability(p.getInventory().getBoots()));
|
||||
case "ping":
|
||||
return retrievePing(p, false);
|
||||
case "colored_ping":
|
||||
return retrievePing(p, true);
|
||||
case "time":
|
||||
return String.valueOf(p.getPlayerTime());
|
||||
case "time_offset":
|
||||
return String.valueOf(p.getPlayerTimeOffset());
|
||||
case "remaining_air":
|
||||
return String.valueOf(p.getRemainingAir());
|
||||
case "saturation":
|
||||
return String.valueOf(p.getSaturation());
|
||||
case "sleep_ticks":
|
||||
return String.valueOf(p.getSleepTicks());
|
||||
case "thunder_duration":
|
||||
return String.valueOf(p.getWorld().getThunderDuration());
|
||||
case "ticks_lived":
|
||||
return String.valueOf(p.getTicksLived());
|
||||
case "seconds_lived":
|
||||
return String.valueOf(p.getTicksLived() / 20);
|
||||
case "minutes_lived":
|
||||
return String.valueOf((p.getTicksLived() / 20) / 60);
|
||||
case "walk_speed":
|
||||
return String.valueOf(p.getWalkSpeed());
|
||||
case "weather_duration":
|
||||
return String.valueOf(p.getWorld().getWeatherDuration());
|
||||
case "world_time":
|
||||
return String.valueOf(p.getWorld().getTime());
|
||||
case "world_time_12":
|
||||
return format12(p.getWorld().getTime());
|
||||
case "world_time_24":
|
||||
return format24(p.getWorld().getTime());
|
||||
case "is_flying":
|
||||
return bool(p.isFlying());
|
||||
case "is_sleeping":
|
||||
return bool(p.isSleeping());
|
||||
case "is_conversing":
|
||||
return bool(p.isConversing());
|
||||
case "is_dead":
|
||||
return bool(p.isDead());
|
||||
case "is_sneaking":
|
||||
return bool(p.isSneaking());
|
||||
case "is_sprinting":
|
||||
return bool(p.isSprinting());
|
||||
case "is_leashed":
|
||||
return bool(p.isLeashed());
|
||||
case "is_inside_vehicle":
|
||||
return bool(p.isInsideVehicle());
|
||||
return String.valueOf(p.getInventory().getActiveHotbarItem().getDurability());
|
||||
case "item_in_hand_broken":
|
||||
return bool(p.getInventory().getActiveHotbarItem().isBroken());
|
||||
case "item_in_hand_unbreakable":
|
||||
return bool(p.getInventory().getActiveHotbarItem().isUnbreakable());
|
||||
// case "item_in_hand_name":
|
||||
// return itemInHand(p).getType() != Material.AIR && itemInHand(p).getItemMeta().hasDisplayName() ? itemInHand(p).getItemMeta().getDisplayName() : "";
|
||||
// case "item_in_hand_data":
|
||||
// return itemInHand(p).getType() != Material.AIR ? String.valueOf(itemInHand(p).getDurability()) : "0";
|
||||
// case "item_in_hand_durability":
|
||||
// return String.valueOf(durability(itemInHand(p)));
|
||||
// case "item_in_offhand":
|
||||
// return String.valueOf(p.getInventory().getItemInOffHand().getType());
|
||||
// case "item_in_offhand_name":
|
||||
// return p.getInventory().getItemInOffHand().getType() != Material.AIR && p.getInventory().getItemInOffHand().getItemMeta().hasDisplayName() ? p.getInventory().getItemInOffHand().getItemMeta().getDisplayName() : "";
|
||||
// case "item_in_offhand_data":
|
||||
// return p.getInventory().getItemInOffHand().getType() != Material.AIR ? String.valueOf(p.getInventory().getItemInOffHand().getDurability()) : "0";
|
||||
// case "item_in_offhand_durability":
|
||||
// return String.valueOf(durability(p.getInventory().getItemInOffHand()));
|
||||
// case "last_damage":
|
||||
// return String.valueOf(p.getLastDamage());
|
||||
// case "max_health":
|
||||
// return String.valueOf(p.getMaxHealth());
|
||||
// case "max_health_rounded":
|
||||
// return String.valueOf(Math.round(p.getMaxHealth()));
|
||||
// case "max_air":
|
||||
// return String.valueOf(p.getMaximumAir());
|
||||
// case "max_no_damage_ticks":
|
||||
// return String.valueOf(p.getMaximumNoDamageTicks());
|
||||
// case "no_damage_ticks":
|
||||
// return String.valueOf(p.getNoDamageTicks());
|
||||
// case "armor_helmet_name":
|
||||
// return Optional.ofNullable(p.getInventory().getHelmet()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
// case "armor_helmet_data":
|
||||
// return p.getInventory().getHelmet() != null ? String.valueOf(p.getInventory().getHelmet().getDurability()) : "0";
|
||||
// case "armor_helmet_durability":
|
||||
// return String.valueOf(durability(p.getInventory().getHelmet()));
|
||||
// case "armor_chestplate_name":
|
||||
// return Optional.ofNullable(p.getInventory().getChestplate()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
// case "armor_chestplate_data":
|
||||
// return p.getInventory().getChestplate() != null ? String.valueOf(p.getInventory().getChestplate().getDurability()) : "0";
|
||||
// case "armor_chestplate_durability":
|
||||
// return String.valueOf(durability(p.getInventory().getChestplate()));
|
||||
// case "armor_leggings_name":
|
||||
// return Optional.ofNullable(p.getInventory().getLeggings()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
// case "armor_leggings_data":
|
||||
// return p.getInventory().getLeggings() != null ? String.valueOf(p.getInventory().getLeggings().getDurability()) : "0";
|
||||
// case "armor_leggings_durability":
|
||||
// return String.valueOf(durability(p.getInventory().getLeggings()));
|
||||
// case "armor_boots_name":
|
||||
// return Optional.ofNullable(p.getInventory().getBoots()).map(a -> a.getItemMeta().getDisplayName()).orElse("");
|
||||
// case "armor_boots_data":
|
||||
// return p.getInventory().getBoots() != null ? String.valueOf(p.getInventory().getBoots().getDurability()) : "0";
|
||||
// case "armor_boots_durability":
|
||||
// return String.valueOf(durability(p.getInventory().getBoots()));
|
||||
// case "ping":
|
||||
// return retrievePing(p, false);
|
||||
// case "colored_ping":
|
||||
// return retrievePing(p, true);
|
||||
// case "time":
|
||||
|
||||
// return String.valueOf(p.getPlayerTime());
|
||||
// case "time_offset":
|
||||
// return String.valueOf(p.getPlayerTimeOffset());
|
||||
// case "remaining_air":
|
||||
// return String.valueOf(p.getRemainingAir());
|
||||
// case "saturation":
|
||||
// return String.valueOf(p.getSaturation());
|
||||
// case "sleep_ticks":
|
||||
// return String.valueOf(p.getSleepTicks());
|
||||
// case "thunder_duration":
|
||||
// return String.valueOf(p.getWorld().getThunderDuration());
|
||||
// case "ticks_lived":
|
||||
// return String.valueOf(p.getTicksLived());
|
||||
// case "seconds_lived":
|
||||
// return String.valueOf(p.getTicksLived() / 20);
|
||||
// case "minutes_lived":
|
||||
// return String.valueOf((p.getTicksLived() / 20) / 60);
|
||||
// case "walk_speed":
|
||||
// return String.valueOf(p.getWalkSpeed());
|
||||
// case "weather_duration":
|
||||
// return String.valueOf(p.getWorld().getWeatherDuration());
|
||||
// case "world_time":
|
||||
// return String.valueOf(p.getWorld().getTime());
|
||||
// case "world_time_12":
|
||||
// return format12(p.getWorld().getTime());
|
||||
// case "world_time_24":
|
||||
// return format24(p.getWorld().getTime());
|
||||
// case "is_flying":
|
||||
// return bool(p.isFlying());
|
||||
// case "is_sleeping":
|
||||
// return bool(p.isSleeping());
|
||||
// case "is_conversing":
|
||||
// return bool(p.isConversing());
|
||||
// case "is_dead":
|
||||
// return bool(p.isDead());
|
||||
// case "is_sneaking":
|
||||
// return bool(p.isSneaking());
|
||||
// case "is_sprinting":
|
||||
// return bool(p.isSprinting());
|
||||
// case "is_leashed":
|
||||
// return bool(p.isLeashed());
|
||||
// case "is_inside_vehicle":
|
||||
// return bool(p.isInsideVehicle());
|
||||
|
||||
case "current_fall_distance":
|
||||
return String.valueOf(p.getCurrentFallDistance());
|
||||
case "view_radius":
|
||||
return String.valueOf(p.getViewRadius());
|
||||
case "client_view_radius":
|
||||
return String.valueOf(p.getClientViewRadius());
|
||||
case "since_last_spawn_nanos":
|
||||
return String.valueOf(p.getSinceLastSpawnNanos());
|
||||
case "mount_entity_id":
|
||||
return String.valueOf(p.getMountEntityId());
|
||||
case "is_collidable":
|
||||
return bool(p.isCollidable());
|
||||
|
||||
}
|
||||
// return null for unknown placeholders
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register() {
|
||||
low = this.getString("ping_color.low", "&a");
|
||||
medium = this.getString("ping_color.medium", "&e");
|
||||
high = this.getString("ping_color.high", "&c");
|
||||
mediumValue = this.getInt("ping_value.medium", 50);
|
||||
highValue = this.getInt("ping_value.high", 100);
|
||||
north = this.getString("direction.north", "N");
|
||||
northEast = this.getString("direction.north_east", "NE");
|
||||
east = this.getString("direction.east", "E");
|
||||
southEast = this.getString("direction.south_east", "SE");
|
||||
south = this.getString("direction.south", "S");
|
||||
southWest = this.getString("direction.south_west", "SW");
|
||||
west = this.getString("direction.west", "W");
|
||||
northWest = this.getString("direction.north_west", "NW");
|
||||
// @Override
|
||||
// public boolean register() {
|
||||
// low = this.getString("ping_color.low", "&a");
|
||||
// medium = this.getString("ping_color.medium", "&e");
|
||||
// high = this.getString("ping_color.high", "&c");
|
||||
// mediumValue = this.getInt("ping_value.medium", 50);
|
||||
// highValue = this.getInt("ping_value.high", 100);
|
||||
// north = this.getString("direction.north", "N");
|
||||
// northEast = this.getString("direction.north_east", "NE");
|
||||
// east = this.getString("direction.east", "E");
|
||||
// southEast = this.getString("direction.south_east", "SE");
|
||||
// south = this.getString("direction.south", "S");
|
||||
// southWest = this.getString("direction.south_west", "SW");
|
||||
// west = this.getString("direction.west", "W");
|
||||
// northWest = this.getString("direction.north_west", "NW");
|
||||
|
||||
|
||||
return super.register();
|
||||
}
|
||||
// return super.register();
|
||||
// }
|
||||
|
||||
public String bool(boolean b) {
|
||||
return b ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
||||
return b ? PlaceholderAPIPlugin.instance().configManager().config().booleanValue().trueValue() : PlaceholderAPIPlugin.instance().configManager().config().booleanValue().falseValue();
|
||||
}
|
||||
|
||||
|
||||
private String retrievePing(final Player player, final boolean colored) {
|
||||
final int ping = PlayerUtil.getPing(player);
|
||||
if (!colored) {
|
||||
return String.valueOf(ping);
|
||||
}
|
||||
// private String retrievePing(final Player player, final boolean colored) {
|
||||
// final int ping = PlayerUtil.getPing(player);
|
||||
// if (!colored) {
|
||||
// return String.valueOf(ping);
|
||||
// }
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', ping > highValue ? high : ping > mediumValue ? medium : low) + ping;
|
||||
}
|
||||
// return ChatColor.translateAlternateColorCodes('&', ping > highValue ? high : ping > mediumValue ? medium : low) + ping;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public @NotNull Class provideConfigType() {
|
||||
// // TODO Auto-generated method stub
|
||||
// throw new UnsupportedOperationException("Unimplemented method 'provideConfigType'");
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public @NotNull Object provideDefault() {
|
||||
// // TODO Auto-generated method stub
|
||||
// throw new UnsupportedOperationException("Unimplemented method 'provideDefault'");
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,260 +1,259 @@
|
||||
package com.extendedclip.papi.expansion.player;
|
||||
// package com.extendedclip.papi.expansion.player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
// import com.hypixel.hytale.server.core.HytaleServer;
|
||||
// import com.hypixel.hytale.server.core.entity.entities.Player;
|
||||
// import com.hypixel.hytale.server.core.universe.Universe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
// import at.helpch.placeholderapi.PlaceholderAPIPlugin;
|
||||
// import at.helpch.placeholderapi.expansion.Configurable;
|
||||
// import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
/*
|
||||
*
|
||||
* Player-Expansion
|
||||
* Copyright (C) 2018 Ryan McCarthy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class PlayerUtil {
|
||||
// import java.lang.reflect.Field;
|
||||
// import java.lang.reflect.InvocationTargetException;
|
||||
// import java.lang.reflect.Method;
|
||||
// import java.text.ParseException;
|
||||
// import java.text.SimpleDateFormat;
|
||||
// import java.util.Locale;
|
||||
// import java.util.function.Function;
|
||||
// import java.util.logging.Level;
|
||||
|
||||
public static final int ticksAtMidnight = 18000;
|
||||
public static final int ticksPerDay = 24000;
|
||||
public static final int ticksPerHour = 1000;
|
||||
public static final double ticksPerMinute = 1000d / 60d;
|
||||
private static final SimpleDateFormat twentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
|
||||
private static final SimpleDateFormat twelve = new SimpleDateFormat("h:mm aa", Locale.ENGLISH);
|
||||
private static final BlockFace[] radial = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
|
||||
// /*
|
||||
// *
|
||||
// * Player-Expansion
|
||||
// * Copyright (C) 2018 Ryan McCarthy
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// *
|
||||
// *
|
||||
// */
|
||||
// public final class PlayerUtil {
|
||||
|
||||
private PlayerUtil() { }
|
||||
// // public static final int ticksAtMidnight = 18000;
|
||||
// // public static final int ticksPerDay = 24000;
|
||||
// // public static final int ticksPerHour = 1000;
|
||||
// // public static final double ticksPerMinute = 1000d / 60d;
|
||||
// // private static final SimpleDateFormat twentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
|
||||
// // private static final SimpleDateFormat twelve = new SimpleDateFormat("h:mm aa", Locale.ENGLISH);
|
||||
// // private static final BlockFace[] radial = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
|
||||
|
||||
private static final Function<Player, Integer> PLAYER_GET_PING = new Function<Player, Integer>() {
|
||||
// private PlayerUtil() { }
|
||||
|
||||
private Field ping;
|
||||
private Method getHandle;
|
||||
// private static final Function<Player, Integer> PLAYER_GET_PING = new Function<Player, Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer apply(final Player player) {
|
||||
// 1.17 added Player#getPing, and we can use that directly
|
||||
if (VersionHelper.IS_1_17_OR_NEWER) {
|
||||
return player.getPing();
|
||||
}
|
||||
// private Field ping;
|
||||
// private Method getHandle;
|
||||
|
||||
// For versions before 1.17 we need to use reflection
|
||||
if (ping == null) {
|
||||
try {
|
||||
cacheReflection(player);
|
||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public Integer apply(final Player player) {
|
||||
// // 1.17 added Player#getPing, and we can use that directly
|
||||
// if (VersionHelper.IS_1_17_OR_NEWER) {
|
||||
// return player.getPing();
|
||||
// }
|
||||
|
||||
try {
|
||||
return ping.getInt(getHandle.invoke(player));
|
||||
} catch (final IllegalAccessException | InvocationTargetException ex) {
|
||||
PlaceholderAPIPlugin.getInstance()
|
||||
.getLogger()
|
||||
.log(Level.SEVERE, "Could not get the ping of " + player.getName() + ", using -1 as fallback value", ex);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// // For versions before 1.17 we need to use reflection
|
||||
// if (ping == null) {
|
||||
// try {
|
||||
// cacheReflection(player);
|
||||
// } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
// try {
|
||||
// return ping.getInt(getHandle.invoke(player));
|
||||
// } catch (final IllegalAccessException | InvocationTargetException ex) {
|
||||
// PlaceholderAPIPlugin.getInstance()
|
||||
// .getLogger()
|
||||
// .log(Level.SEVERE, "Could not get the ping of " + player.getName() + ", using -1 as fallback value", ex);
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
|
||||
private void cacheReflection(final Player player) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
getHandle = player.getClass().getDeclaredMethod("getHandle");
|
||||
getHandle.setAccessible(true);
|
||||
// private void cacheReflection(final Player player) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
// getHandle = player.getClass().getDeclaredMethod("getHandle");
|
||||
// getHandle.setAccessible(true);
|
||||
|
||||
final Object entityPlayer = getHandle.invoke(player);
|
||||
ping = entityPlayer.getClass().getDeclaredField("ping");
|
||||
ping.setAccessible(true);
|
||||
}
|
||||
};
|
||||
// final Object entityPlayer = getHandle.invoke(player);
|
||||
// ping = entityPlayer.getClass().getDeclaredField("ping");
|
||||
// ping.setAccessible(true);
|
||||
// }
|
||||
// };
|
||||
|
||||
private static final Function<Player, String> PLAYER_GET_LOCALE = new Function<Player, String>() {
|
||||
// private static final Function<Player, String> PLAYER_GET_LOCALE = new Function<Player, String>() {
|
||||
|
||||
private Field locale;
|
||||
private Method getHandle;
|
||||
// private Field locale;
|
||||
// private Method getHandle;
|
||||
|
||||
@Override
|
||||
public String apply(final Player player) {
|
||||
if (locale == null) {
|
||||
try {
|
||||
cacheReflection(player);
|
||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public String apply(final Player player) {
|
||||
// if (locale == null) {
|
||||
// try {
|
||||
// cacheReflection(player);
|
||||
// } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
final Object entityPlayer = getHandle.invoke(player);
|
||||
return (String) locale.get(entityPlayer);
|
||||
} catch (final IllegalAccessException | InvocationTargetException ex) {
|
||||
PlaceholderAPIPlugin.getInstance()
|
||||
.getLogger()
|
||||
.log(Level.SEVERE, "Could not get the locale of " + player.getName() + ", using 'en_US' as fallback value", ex);
|
||||
}
|
||||
return "en_US";
|
||||
}
|
||||
// try {
|
||||
// final Object entityPlayer = getHandle.invoke(player);
|
||||
// return (String) locale.get(entityPlayer);
|
||||
// } catch (final IllegalAccessException | InvocationTargetException ex) {
|
||||
// PlaceholderAPIPlugin.getInstance()
|
||||
// .getLogger()
|
||||
// .log(Level.SEVERE, "Could not get the locale of " + player.getName() + ", using 'en_US' as fallback value", ex);
|
||||
// }
|
||||
// return "en_US";
|
||||
// }
|
||||
|
||||
|
||||
private void cacheReflection(final Player player) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
getHandle = player.getClass().getDeclaredMethod("getHandle");
|
||||
getHandle.setAccessible(true);
|
||||
// private void cacheReflection(final Player player) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
// getHandle = player.getClass().getDeclaredMethod("getHandle");
|
||||
// getHandle.setAccessible(true);
|
||||
|
||||
final Object entityPlayer = getHandle.invoke(player);
|
||||
// final Object entityPlayer = getHandle.invoke(player);
|
||||
|
||||
if (VersionHelper.IS_1_20_4_OR_NEWER) {
|
||||
locale = entityPlayer.getClass().getField("cO");
|
||||
} else if (VersionHelper.IS_1_20_2_OR_NEWER) {
|
||||
locale = entityPlayer.getClass().getField("cM");
|
||||
} else {
|
||||
locale = entityPlayer.getClass().getField("locale");
|
||||
}
|
||||
}
|
||||
};
|
||||
// if (VersionHelper.IS_1_20_4_OR_NEWER) {
|
||||
// locale = entityPlayer.getClass().getField("cO");
|
||||
// } else if (VersionHelper.IS_1_20_2_OR_NEWER) {
|
||||
// locale = entityPlayer.getClass().getField("cM");
|
||||
// } else {
|
||||
// locale = entityPlayer.getClass().getField("locale");
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
|
||||
public static int getPing(final Player player) {
|
||||
return PLAYER_GET_PING.apply(player);
|
||||
}
|
||||
// public static int getPing(final Player player) {
|
||||
// return PLAYER_GET_PING.apply(player);
|
||||
// }
|
||||
|
||||
public static String getLocale(final Player player) {
|
||||
return PLAYER_GET_LOCALE.apply(player);
|
||||
}
|
||||
// public static String getLocale(final Player player) {
|
||||
// return PLAYER_GET_LOCALE.apply(player);
|
||||
// }
|
||||
|
||||
public static String format12(long ticks) {
|
||||
try {
|
||||
return twelve.format(twentyFour.parse(ticksToTime(ticks)));
|
||||
} catch (ParseException e) {
|
||||
return ticksToTime(ticks);
|
||||
}
|
||||
}
|
||||
// public static String format12(long ticks) {
|
||||
// try {
|
||||
// return twelve.format(twentyFour.parse(ticksToTime(ticks)));
|
||||
// } catch (ParseException e) {
|
||||
// return ticksToTime(ticks);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static String format24(long ticks) {
|
||||
return ticksToTime(ticks);
|
||||
}
|
||||
// public static String format24(long ticks) {
|
||||
// return ticksToTime(ticks);
|
||||
// }
|
||||
|
||||
private static String ticksToTime(long ticks) {
|
||||
ticks = ticks - ticksAtMidnight + ticksPerDay;
|
||||
long hours = ticks / ticksPerHour;
|
||||
ticks -= hours * ticksPerHour;
|
||||
long mins = (long) Math.floor(ticks / ticksPerMinute);
|
||||
if (hours >= 24) {
|
||||
hours = hours - 24;
|
||||
}
|
||||
return (hours < 10 ? "0" + hours : hours) + ":" + (mins < 10 ? "0" + mins : mins);
|
||||
}
|
||||
// private static String ticksToTime(long ticks) {
|
||||
// ticks = ticks - ticksAtMidnight + ticksPerDay;
|
||||
// long hours = ticks / ticksPerHour;
|
||||
// ticks -= hours * ticksPerHour;
|
||||
// long mins = (long) Math.floor(ticks / ticksPerMinute);
|
||||
// if (hours >= 24) {
|
||||
// hours = hours - 24;
|
||||
// }
|
||||
// return (hours < 10 ? "0" + hours : hours) + ":" + (mins < 10 ? "0" + mins : mins);
|
||||
// }
|
||||
|
||||
public static BlockFace getDirection(Player player) {
|
||||
return radial[Math.round(player.getLocation().getYaw() / 45f) & 0x7].getOppositeFace();
|
||||
}
|
||||
// public static BlockFace getDirection(Player player) {
|
||||
// return radial[Math.round(player.getLocation().getYaw() / 45f) & 0x7].getOppositeFace();
|
||||
// }
|
||||
|
||||
public static String getXZDirection(Player player) {
|
||||
double rotation = player.getLocation().getYaw();
|
||||
if (rotation < 0.0D) {
|
||||
rotation += 360.0D;
|
||||
}
|
||||
// public static String getXZDirection(Player player) {
|
||||
// double rotation = player.getLocation().getYaw();
|
||||
// if (rotation < 0.0D) {
|
||||
// rotation += 360.0D;
|
||||
// }
|
||||
|
||||
if (Math.abs(rotation) <= 45 || Math.abs(rotation - 360) <= 45) {
|
||||
return "+Z";
|
||||
} else if (Math.abs(rotation - 90) <= 45) {
|
||||
return "-X";
|
||||
} else if (Math.abs(rotation - 180) <= 45) {
|
||||
return "-Z";
|
||||
} else if (Math.abs(rotation - 270) <= 45) {
|
||||
return "+X";
|
||||
}
|
||||
// if (Math.abs(rotation) <= 45 || Math.abs(rotation - 360) <= 45) {
|
||||
// return "+Z";
|
||||
// } else if (Math.abs(rotation - 90) <= 45) {
|
||||
// return "-X";
|
||||
// } else if (Math.abs(rotation - 180) <= 45) {
|
||||
// return "-Z";
|
||||
// } else if (Math.abs(rotation - 270) <= 45) {
|
||||
// return "+X";
|
||||
// }
|
||||
|
||||
return "";
|
||||
}
|
||||
// return "";
|
||||
// }
|
||||
|
||||
public static ItemStack itemInHand(Player p) {
|
||||
try {
|
||||
return p.getInventory().getItemInMainHand();
|
||||
} catch (NoSuchMethodError e) {
|
||||
return p.getInventory().getItemInHand();
|
||||
}
|
||||
}
|
||||
// public static ItemStack itemInHand(Player p) {
|
||||
// try {
|
||||
// return p.getInventory().getItemInMainHand();
|
||||
// } catch (NoSuchMethodError e) {
|
||||
// return p.getInventory().getItemInHand();
|
||||
// }
|
||||
// }
|
||||
|
||||
public static int durability(ItemStack item) {
|
||||
return item != null ? item.getType().getMaxDurability() - item.getDurability() : 0;
|
||||
}
|
||||
// public static int durability(ItemStack item) {
|
||||
// return item != null ? item.getType().getMaxDurability() - item.getDurability() : 0;
|
||||
// }
|
||||
|
||||
public static int getEmptySlots(Player p) {
|
||||
int slots = 0;
|
||||
PlayerInventory inv = p.getInventory();
|
||||
for (ItemStack is : inv.getContents()) {
|
||||
if (is == null) slots++;
|
||||
}
|
||||
// public static int getEmptySlots(Player p) {
|
||||
// int slots = 0;
|
||||
// PlayerInventory inv = p.getInventory();
|
||||
// for (ItemStack is : inv.getContents()) {
|
||||
// if (is == null) slots++;
|
||||
// }
|
||||
|
||||
if (!Bukkit.getBukkitVersion().contains("1.7") && !Bukkit.getBukkitVersion().contains("1.8")) {
|
||||
if (inv.getItemInOffHand() == null || inv.getItemInOffHand().getType() == Material.AIR) slots--;
|
||||
if (inv.getHelmet() == null) slots--;
|
||||
if (inv.getChestplate() == null) slots--;
|
||||
if (inv.getLeggings() == null) slots--;
|
||||
if (inv.getBoots() == null) slots--;
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
// if (!Bukkit.getBukkitVersion().contains("1.7") && !Bukkit.getBukkitVersion().contains("1.8")) {
|
||||
// if (inv.getItemInOffHand() == null || inv.getItemInOffHand().getType() == Material.AIR) slots--;
|
||||
// if (inv.getHelmet() == null) slots--;
|
||||
// if (inv.getChestplate() == null) slots--;
|
||||
// if (inv.getLeggings() == null) slots--;
|
||||
// if (inv.getBoots() == null) slots--;
|
||||
// }
|
||||
// return slots;
|
||||
// }
|
||||
|
||||
private static int getExperienceAtLevel(int level) {
|
||||
if (level <= 15) {
|
||||
return (level << 1) + 7;
|
||||
}
|
||||
if (level <= 30) {
|
||||
return (level * 5) - 38;
|
||||
}
|
||||
return (level * 9) - 158;
|
||||
}
|
||||
// private static int getExperienceAtLevel(int level) {
|
||||
// if (level <= 15) {
|
||||
// return (level << 1) + 7;
|
||||
// }
|
||||
// if (level <= 30) {
|
||||
// return (level * 5) - 38;
|
||||
// }
|
||||
// return (level * 9) - 158;
|
||||
// }
|
||||
|
||||
public static int getTotalExperience(Player player) {
|
||||
int experience = Math.round(getExperienceAtLevel(player.getLevel()) * player.getExp());
|
||||
int currentLevel = player.getLevel();
|
||||
while (currentLevel > 0) {
|
||||
currentLevel--;
|
||||
experience += getExperienceAtLevel(currentLevel);
|
||||
}
|
||||
if (experience < 0) {
|
||||
experience = 0;
|
||||
}
|
||||
return experience;
|
||||
}
|
||||
// public static int getTotalExperience(Player player) {
|
||||
// int experience = Math.round(getExperienceAtLevel(player.getLevel()) * player.getExp());
|
||||
// int currentLevel = player.getLevel();
|
||||
// while (currentLevel > 0) {
|
||||
// currentLevel--;
|
||||
// experience += getExperienceAtLevel(currentLevel);
|
||||
// }
|
||||
// if (experience < 0) {
|
||||
// experience = 0;
|
||||
// }
|
||||
// return experience;
|
||||
// }
|
||||
|
||||
public static String getBiome(Player p) {
|
||||
if (VersionHelper.IS_1_21_3_OR_NEWER) {
|
||||
return p.getLocation().getBlock().getBiome().name();
|
||||
}
|
||||
// public static String getBiome(Player p) {
|
||||
// if (VersionHelper.IS_1_21_3_OR_NEWER) {
|
||||
// return p.getLocation().getBlock().getBiome().name();
|
||||
// }
|
||||
|
||||
return String.valueOf(p.getLocation().getBlock().getBiome());
|
||||
}
|
||||
// return String.valueOf(p.getLocation().getBlock().getBiome());
|
||||
// }
|
||||
|
||||
public static String getCapitalizedBiome(Player p) {
|
||||
String[] biomeWords = getBiome(p).split("_");
|
||||
for (int i = 0; i < biomeWords.length; i++) {
|
||||
biomeWords[i] = biomeWords[i].substring(0, 1).toUpperCase() + biomeWords[i].substring(1).toLowerCase();
|
||||
}
|
||||
return String.join(" ", biomeWords);
|
||||
}
|
||||
}
|
||||
// public static String getCapitalizedBiome(Player p) {
|
||||
// String[] biomeWords = getBiome(p).split("_");
|
||||
// for (int i = 0; i < biomeWords.length; i++) {
|
||||
// biomeWords[i] = biomeWords[i].substring(0, 1).toUpperCase() + biomeWords[i].substring(1).toLowerCase();
|
||||
// }
|
||||
// return String.join(" ", biomeWords);
|
||||
// }
|
||||
// }
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.extendedclip.papi.expansion.player;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Matt (<a href="https://github.com/ipsk">@ipsk</a>)
|
||||
*/
|
||||
public final class VersionHelper {
|
||||
|
||||
private static final int VERSION = getCurrentVersion();
|
||||
|
||||
/**
|
||||
* @see Damageable#getAbsorptionAmount()
|
||||
*/
|
||||
public static final boolean HAS_ABSORPTION_METHODS = VERSION >= 1_15_0;
|
||||
|
||||
/**
|
||||
* @see Player#getPing()
|
||||
*/
|
||||
public static final boolean IS_1_17_OR_NEWER = VERSION >= 1_17_0;
|
||||
|
||||
/**
|
||||
* @see Player#getLocale()
|
||||
*/
|
||||
public static final boolean IS_1_20_2_OR_NEWER = VERSION >= 1_20_2;
|
||||
|
||||
/**
|
||||
* @see Player#getLocale()
|
||||
*/
|
||||
public static final boolean IS_1_20_4_OR_NEWER = VERSION >= 1_20_4;
|
||||
|
||||
public static final boolean IS_1_21_3_OR_NEWER = VERSION >= 1_21_3;
|
||||
|
||||
private VersionHelper() { }
|
||||
|
||||
/**
|
||||
* Gets the current server version
|
||||
*
|
||||
* @return A protocol like number representing the version, for example 1.16.5 - 1165
|
||||
*/
|
||||
private static int getCurrentVersion() {
|
||||
// No need to cache since will only run once
|
||||
final Matcher matcher = Pattern.compile("(?<version>\\d+\\.\\d+)(?<patch>\\.\\d+)?").matcher(Bukkit.getBukkitVersion());
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
if (matcher.find()) {
|
||||
final String patch = matcher.group("patch");
|
||||
|
||||
stringBuilder
|
||||
.append(matcher.group("version").replace(".", ""))
|
||||
.append((patch == null) ? "0" : patch.replace(".", ""));
|
||||
}
|
||||
|
||||
final Integer version = Ints.tryParse(stringBuilder.toString());
|
||||
|
||||
// Should never fail
|
||||
if (version == null) {
|
||||
throw new IllegalArgumentException("Could not retrieve server version!");
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user