Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Asintotoo authored Jul 18, 2024
1 parent 9bacafa commit 21463a9
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.asintoto</groupId>
<artifactId>Basic</artifactId>
<version>1.1.17</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>Basic</name>
Expand Down
201 changes: 201 additions & 0 deletions src/main/java/com/asintoto/basic/players/BasicPlayer.java
Original file line number Diff line number Diff line change
@@ -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);
}


}

0 comments on commit 21463a9

Please sign in to comment.