From 21463a9ddacc743542a38c0a7f41a96c97ae3e54 Mon Sep 17 00:00:00 2001
From: Asintoto <166311378+Asintotoo@users.noreply.github.com>
Date: Thu, 18 Jul 2024 08:56:56 +0200
Subject: [PATCH] Add files via upload
---
pom.xml | 2 +-
.../asintoto/basic/players/BasicPlayer.java | 201 ++++++++++++++++++
2 files changed, 202 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/com/asintoto/basic/players/BasicPlayer.java
diff --git a/pom.xml b/pom.xml
index ee7f2e0..cd8ce53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.asintoto
Basic
- 1.1.17
+ 1.2.0
jar
Basic
diff --git a/src/main/java/com/asintoto/basic/players/BasicPlayer.java b/src/main/java/com/asintoto/basic/players/BasicPlayer.java
new file mode 100644
index 0000000..241842c
--- /dev/null
+++ b/src/main/java/com/asintoto/basic/players/BasicPlayer.java
@@ -0,0 +1,201 @@
+package com.asintoto.basic.players;
+
+import com.asintoto.colorlib.ColorLib;
+import com.asintoto.basic.Basic;
+import org.bukkit.BanList;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.Date;
+import java.util.UUID;
+
+public class BasicPlayer {
+ private Player player;
+
+ public BasicPlayer(Player player) {
+ this.player = player;
+ }
+
+
+ /**
+ * Send a message to the player.
+ * Formatted with ColorLib
+ *
+ * @param msg
+ */
+ public void sendMessage(String msg) {
+ player.sendMessage(ColorLib.setColors(msg));
+ }
+
+
+ /**
+ * Respawn the player
+ *
+ */
+ public void respawn() {
+ new BukkitRunnable() {
+
+ @Override
+ public void run() {
+ player.spigot().respawn();
+ }
+
+ }.runTaskLater(Basic.getPlugin(), 1L);
+ }
+
+
+ /**
+ * Get the IP Address of the player
+ *
+ * @return
+ */
+ public String getIP() {
+ if (player.getAddress() == null) {
+ return "N/A";
+ }
+ return player.getAddress().getAddress().getHostAddress();
+ }
+
+
+ /**
+ * Kill the player
+ *
+ */
+ public void kill() {
+ player.setHealth(0.0);
+ }
+
+
+ /**
+ * Method to run a command as the player.
+ * Make sure to type the command without /.
+ * Example: executeCommand(give @p diamond 1)
+ *
+ * @param command
+ */
+ public void executeCommand(String command) {
+ Bukkit.dispatchCommand(player, command);
+ }
+
+
+ /**
+ * Restore the health of the player
+ *
+ */
+ public void heal() {
+ player.setHealth(player.getMaxHealth());
+ }
+
+
+ /**
+ * Restore the hunger level and the saturation of the player
+ *
+ */
+ public void feed() {
+ player.setFoodLevel(20);
+ player.setSaturation(20.0f);
+ }
+
+
+ /**
+ *
+ * Ban the player.
+ * The duration must be in seconds
+ *
+ * @param reason
+ * @param duration
+ * @param ip
+ * @param source
+ */
+ public void ban(String reason, long duration, boolean ip, String source) {
+
+ Date banExpire = duration <= -1 ? null : new Date(System.currentTimeMillis() + duration * 1000);
+
+ BanList.Type bantype = ip ? BanList.Type.IP : BanList.Type.PROFILE;
+
+ player.getServer().getBanList(bantype).addBan(ip ? getIP() : player.getName(), reason, banExpire, source);
+ }
+
+ /**
+ * Perma-Ban a player
+ *
+ * @param reason
+ */
+ public void ban(String reason) {
+ ban(reason, -1, false, null);
+ }
+
+
+ /**
+ * Perma-IP-Ban a player
+ *
+ * @param reason
+ */
+ public void banIP(String reason) {
+ ban(reason, -1, true, null);
+ }
+
+ /**
+ * Get the player's UUID
+ *
+ * @return
+ */
+ public UUID getUUID() {
+ return player.getUniqueId();
+ }
+
+
+ /**
+ * Get the player's UUID to string
+ *
+ * @return
+ */
+ public String getUUIDtoString() {
+ return getUUID().toString();
+ }
+
+
+ /**
+ * Get the player
+ *
+ * @return
+ */
+ public Player getPlayer() {
+ return this.player;
+ }
+
+
+ /**
+ * Get the player
+ *
+ * @return
+ */
+ public Player player() {
+ return this.player;
+ }
+
+
+ /**
+ * Send a chat message as the player.
+ * Formatted with ColorLib
+ *
+ * @param msg
+ */
+ public void chat(String msg) {
+ player.chat(ColorLib.setColors(msg));
+ }
+
+
+ /**
+ * Convert a player to a BasicPlayer
+ *
+ * @param p
+ * @return
+ */
+ public static BasicPlayer from(Player p) {
+ return new BasicPlayer(p);
+ }
+
+
+}