Compare commits
8
Commits
pom_updates
...
3.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0555909799 | ||
|
|
d40e1e2bdb | ||
|
|
fae37a45aa | ||
|
|
2188684fbc | ||
|
|
8f31c584b6 | ||
|
|
89ece3e5d1 | ||
|
|
b26086878f | ||
|
|
f1a91908ff |
No files matched your search
+1
-145
@@ -1,146 +1,2 @@
|
||||
### Eclipse ###
|
||||
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
### Eclipse Patch ###
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Ruby plugin and RubyMine
|
||||
/.rakeTasks
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
|
||||
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
|
||||
!/.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
nbactions.xml
|
||||
out/
|
||||
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly project(":common")
|
||||
}
|
||||
@@ -1,63 +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>1.7.2</version>
|
||||
<name>PAPI-Expansion-Player</name>
|
||||
<description>PlaceholderAPI expansion for player placeholders</description>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.9.1</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>${name}</finalName>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<configuration>
|
||||
<target>1.8</target>
|
||||
<source>1.8</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
package at.helpch.placeholderapi.expansion.player;
|
||||
|
||||
import at.helpch.placeholderapi.api.expansion.Expansion;
|
||||
import at.helpch.placeholderapi.api.expansion.ExpansionDescription;
|
||||
import at.helpch.placeholderapi.api.expansion.Platform;
|
||||
import at.helpch.placeholderapi.api.expansion.placeholder.Placeholder;
|
||||
import at.helpch.placeholderapi.api.expansion.placeholder.PlaceholderContext;
|
||||
import at.helpch.placeholderapi.api.player.Player;
|
||||
import at.helpch.placeholderapi.api.player.keyable.key.PlayerKeys;
|
||||
import at.helpch.placeholderapi.api.server.Server;
|
||||
import at.helpch.placeholderapi.expansion.time.TimeFormatter;
|
||||
import at.helpch.placeholderapi.expansion.time.file.Config;
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ExpansionDescription(
|
||||
name = "Player",
|
||||
version = "2.0.0",
|
||||
identifier = "player",
|
||||
authors = "HelpChat",
|
||||
platforms = {Platform.BUKKIT, Platform.SPONGE, Platform.NUKKIT}
|
||||
)
|
||||
public final class PlayerExpansion extends Expansion {
|
||||
|
||||
private final TimeFormatter timeFormatter;
|
||||
private final Config config;
|
||||
|
||||
@Inject
|
||||
public PlayerExpansion(@NotNull final Config config) {
|
||||
this.config = config;
|
||||
|
||||
// TODO: instantiate a single TimeFormatted through out the project, with a main config
|
||||
this.timeFormatter = new TimeFormatter(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
@Placeholder("name")
|
||||
private String name(final PlaceholderContext context) {
|
||||
return context.getPlayer().get(PlayerKeys.NAME).orElse("");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package com.extendedclip.papi.expansion.player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
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.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.extendedclip.papi.expansion.player.PlayerUtil.*;
|
||||
|
||||
public class PlayerExpansion extends PlaceholderExpansion implements Configurable {
|
||||
|
||||
private final String VERSION = getClass().getPackage().getImplementationVersion();
|
||||
|
||||
private String low, medium, high;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "player";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "clip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDefaults() {
|
||||
Map<String, Object> defaults = new HashMap<>();
|
||||
defaults.put("ping_color.high", "&a");
|
||||
defaults.put("ping_color.medium", "&e");
|
||||
defaults.put("ping_color.low", "&c");
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public String onRequest(OfflinePlayer player, String identifier) {
|
||||
high = this.getString("ping_color.high", "&a");
|
||||
medium = this.getString("ping_color.medium", "&e");
|
||||
low = this.getString("ping_color.low", "&c");
|
||||
|
||||
if (identifier.startsWith("ping_")) {
|
||||
if (identifier.split("ping_").length > 1) {
|
||||
identifier = identifier.split("ping_")[1];
|
||||
Player t = Bukkit.getPlayer(identifier);
|
||||
if (t != null) {
|
||||
return getPing(t);
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
if (identifier.startsWith("colored_ping_")) {
|
||||
if (identifier.split("colored_ping_").length > 1) {
|
||||
identifier = identifier.split("colored_ping_")[1];
|
||||
Player t = Bukkit.getPlayer(identifier);
|
||||
if (t != null) {
|
||||
int p = Integer.valueOf(getPing(t));
|
||||
return ChatColor.translateAlternateColorCodes('&', p > 100 ? low : p >= 50 ? medium : high) + getPing(t);
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// offline placeholders
|
||||
switch (identifier) {
|
||||
case "name":
|
||||
return player.getName();
|
||||
case "uuid":
|
||||
return player.getUniqueId().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() : "";
|
||||
}
|
||||
|
||||
// online placeholders
|
||||
if (!player.isOnline()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Player p = player.getPlayer();
|
||||
|
||||
if (identifier.startsWith("has_permission_")) {
|
||||
if (identifier.split("has_permission_").length > 1) {
|
||||
String perm = identifier.split("has_permission_")[1];
|
||||
return bool(p.hasPermission(perm));
|
||||
}
|
||||
return bool(false);
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
switch (identifier) {
|
||||
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 "displayname":
|
||||
return p.getDisplayName();
|
||||
case "locale":
|
||||
return p.getLocale();
|
||||
case "gamemode":
|
||||
return p.getGameMode().name();
|
||||
case "direction":
|
||||
return getCardinalDirection(p);
|
||||
case "world":
|
||||
return p.getWorld().getName();
|
||||
case "x":
|
||||
return String.valueOf(p.getLocation().getBlockX());
|
||||
case "y":
|
||||
return String.valueOf(p.getLocation().getBlockY());
|
||||
case "z":
|
||||
return String.valueOf(p.getLocation().getBlockZ());
|
||||
case "biome":
|
||||
return String.valueOf(p.getLocation().getBlock().getBiome());
|
||||
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 "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 "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";
|
||||
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 "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_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_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_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 "ping":
|
||||
return getPing(p);
|
||||
case "colored_ping":
|
||||
int ping = Integer.valueOf(getPing(p));
|
||||
return ChatColor.translateAlternateColorCodes('&', ping > 100 ? low : ping >= 50 ? medium : high) + getPing(p);
|
||||
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());
|
||||
}
|
||||
// return null for unknown placeholders
|
||||
return null;
|
||||
}
|
||||
|
||||
public String bool(boolean b) {
|
||||
return b ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
package com.extendedclip.papi.expansion.player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/*
|
||||
*
|
||||
* 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 class 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;
|
||||
public static final double ticksPerSecond = 1000d / 60d / 60d;
|
||||
private static final SimpleDateFormat twentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
|
||||
private static final SimpleDateFormat twelve = new SimpleDateFormat("h:mm aa", Locale.ENGLISH);
|
||||
|
||||
public static String getPing(Player p) {
|
||||
try {
|
||||
Method getHandleMethod = p.getClass().getDeclaredMethod("getHandle", new Class[0]);
|
||||
Object nmsplayer = getHandleMethod.invoke(p, new Object[0]);
|
||||
Field pingField = nmsplayer.getClass().getDeclaredField("ping");
|
||||
return String.valueOf(pingField.getInt(nmsplayer));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 String getCardinalDirection(Player player) {
|
||||
double rotation = player.getLocation().getYaw() - 180.0F;
|
||||
if (rotation < 0.0D) {
|
||||
rotation += 360.0D;
|
||||
}
|
||||
if ((0.0D <= rotation) && (rotation < 22.5D)) {
|
||||
return "N";
|
||||
}
|
||||
if ((22.5D <= rotation) && (rotation < 67.5D)) {
|
||||
return "NE";
|
||||
}
|
||||
if ((67.5D <= rotation) && (rotation < 112.5D)) {
|
||||
return "E";
|
||||
}
|
||||
if ((112.5D <= rotation) && (rotation < 157.5D)) {
|
||||
return "SE";
|
||||
}
|
||||
if ((157.5D <= rotation) && (rotation < 202.5D)) {
|
||||
return "S";
|
||||
}
|
||||
if ((202.5D <= rotation) && (rotation < 247.5D) || (rotation <= -119.33) && (rotation > -179)) {
|
||||
return "SW";
|
||||
}
|
||||
if ((247.5D <= rotation) && (rotation < 292.5D) || (rotation <= -59.66) && (rotation > -119.33)) {
|
||||
return "W";
|
||||
}
|
||||
if ((292.5D <= rotation) && (rotation < 337.5D) || (rotation <= -0.0) && (rotation > -59.66)) {
|
||||
return "NW";
|
||||
}
|
||||
if ((337.5D <= rotation) && (rotation < 360.0D)) {
|
||||
return "N";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static ItemStack itemInHand(Player p) {
|
||||
try {
|
||||
return p.getInventory().getItemInMainHand();
|
||||
} catch (NoSuchMethodError e) {
|
||||
return p.getInventory().getItemInHand();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user