2016-04-13 05:52:53 +02:00
|
|
|
package eu.univento.core.api.player;
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.authlib.properties.Property;
|
2016-04-26 15:05:18 +02:00
|
|
|
import com.mongodb.BasicDBObject;
|
|
|
|
import com.mongodb.CursorType;
|
|
|
|
import com.mongodb.client.FindIterable;
|
|
|
|
import com.mongodb.client.MongoCollection;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.Core;
|
2016-04-29 12:54:03 +02:00
|
|
|
import eu.univento.core.antihack.Hack;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.Actionbar;
|
|
|
|
import eu.univento.core.api.Utils;
|
2016-04-26 15:05:18 +02:00
|
|
|
import eu.univento.core.api.database.MongoDB;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.effects.Effects;
|
2016-05-08 10:45:34 +02:00
|
|
|
import eu.univento.core.api.languages.Language;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.languages.Messages;
|
2016-05-08 10:45:34 +02:00
|
|
|
import eu.univento.core.api.server.ServerSettings;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.server.Servers;
|
2016-06-25 15:42:06 +02:00
|
|
|
import eu.univento.core.api.utils.GameProfileBuilder;
|
|
|
|
import eu.univento.core.api.utils.UUIDFetcher;
|
2016-04-26 15:05:18 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
2016-06-25 15:42:06 +02:00
|
|
|
import net.minecraft.server.v1_10_R1.*;
|
|
|
|
import net.minecraft.server.v1_10_R1.World;
|
2016-04-26 15:05:18 +02:00
|
|
|
import org.bson.Document;
|
2016-05-08 10:45:34 +02:00
|
|
|
import org.bukkit.*;
|
2016-04-13 05:52:53 +02:00
|
|
|
import org.bukkit.attribute.Attribute;
|
2016-04-26 15:05:18 +02:00
|
|
|
import org.bukkit.attribute.AttributeInstance;
|
2016-04-13 05:52:53 +02:00
|
|
|
import org.bukkit.attribute.AttributeModifier;
|
2016-06-25 15:42:06 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
2016-04-13 05:52:53 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2016-06-25 15:42:06 +02:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2016-04-26 15:05:18 +02:00
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
2016-04-13 05:52:53 +02:00
|
|
|
import org.bukkit.scoreboard.Team;
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.ObjectOutputStream;
|
2016-05-08 10:45:34 +02:00
|
|
|
import java.lang.reflect.Field;
|
2016-04-26 15:05:18 +02:00
|
|
|
import java.util.*;
|
2016-06-25 15:42:06 +02:00
|
|
|
import java.util.logging.Level;
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
public class CustomPlayer extends CraftPlayer {
|
|
|
|
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private static final HashMap<String, CustomPlayer> PLAYERS = new HashMap<>();
|
2016-04-13 05:52:53 +02:00
|
|
|
private final Player PLAYER;
|
2016-05-08 10:45:34 +02:00
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
private String customPrefix;
|
|
|
|
private String customSuffix;
|
|
|
|
private String customColor;
|
2016-05-08 10:45:34 +02:00
|
|
|
private String nickname;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
private boolean openInventory;
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
private MongoCollection<Document> playerCollection;
|
|
|
|
private MongoCollection<Document> friendCollection;
|
|
|
|
private MongoCollection<Document> onlinePlayerCollection;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
private CustomPlayer(Player player) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
|
|
|
PLAYERS.put(player.getName().toLowerCase(), this);
|
|
|
|
PLAYER = player;
|
2016-05-08 10:45:34 +02:00
|
|
|
MongoDB mongoDB = Core.getMongoDB();
|
|
|
|
playerCollection = mongoDB.getDatabase().getCollection("players");
|
2016-04-26 15:05:18 +02:00
|
|
|
friendCollection = mongoDB.getDatabase().getCollection("friends");
|
2016-05-08 10:45:34 +02:00
|
|
|
onlinePlayerCollection = mongoDB.getDatabase().getCollection("online-players");
|
2016-06-25 15:42:06 +02:00
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onLeave() {
|
|
|
|
Date date = new Date();
|
2016-04-26 15:05:18 +02:00
|
|
|
setInDatabase("lastOnline", date);
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
HashMap<String, Object> location = new HashMap<>();
|
|
|
|
location.put("X", getLocation().getX());
|
|
|
|
location.put("Y", getLocation().getY());
|
|
|
|
location.put("Z", getLocation().getZ());
|
|
|
|
location.put("Yaw", getLocation().getYaw());
|
|
|
|
location.put("Pitch", getLocation().getPitch());
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
if (ServerSettings.isLobby()) setInDatabase("Pos", new BasicDBObject(location));
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
if (PLAYERS.containsKey(getName().toLowerCase())) PLAYERS.remove(getName().toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomPlayer getPlayer(String player) {
|
|
|
|
if (PLAYERS.containsKey(player.toLowerCase())) {
|
|
|
|
return PLAYERS.get(player.toLowerCase());
|
|
|
|
} else {
|
|
|
|
Player p = Bukkit.getPlayer(player);
|
|
|
|
return p == null ? null : new CustomPlayer(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
public static CustomPlayer getPlayer(Player player) {
|
|
|
|
return getPlayer(player.getName());
|
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public static CustomPlayer getPlayer(UUID uuid) {
|
|
|
|
return getPlayer(UUIDFetcher.getName(uuid));
|
|
|
|
}
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
public Player getPLAYER() {
|
|
|
|
return PLAYER;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void insertToDatabase() {
|
2016-04-29 12:54:03 +02:00
|
|
|
Document doc = new Document("uuid", getUniqueId().toString());
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
HashMap<String, Object> location = new HashMap<>();
|
|
|
|
location.put("X", getLocation().getX());
|
|
|
|
location.put("Y", getLocation().getY());
|
|
|
|
location.put("Z", getLocation().getZ());
|
|
|
|
location.put("Yaw", getLocation().getYaw());
|
|
|
|
location.put("Pitch", getLocation().getPitch());
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
doc.put("Pos", new BasicDBObject(location));
|
2016-05-08 10:45:34 +02:00
|
|
|
playerCollection.insertOne(doc);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasPlayedBefore() {
|
2016-06-25 15:42:06 +02:00
|
|
|
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
Document obj = cursor.first();
|
2016-04-26 15:05:18 +02:00
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
return true;
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
public void setRank(Rank rank) {
|
2016-04-26 15:05:18 +02:00
|
|
|
setInDatabase("rank", rank.toString());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setTSID(int id) {
|
2016-04-26 15:05:18 +02:00
|
|
|
setInDatabase("tsid", id);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setCoins(int coins) {
|
2016-04-26 15:05:18 +02:00
|
|
|
setInDatabase("coins", coins);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setExperience(int experience) {
|
2016-04-26 15:05:18 +02:00
|
|
|
setInDatabase("experience", experience);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private void setFoundSecrets(ArrayList<String> secrets) {
|
|
|
|
setInDatabase("foundSecrets", secrets);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public void addSecret(String name) {
|
|
|
|
ArrayList<String> list = getFoundSecrets();
|
|
|
|
list.add(name);
|
|
|
|
setFoundSecrets(list);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private void setFoundEggs(ArrayList<String> eggs) {
|
|
|
|
setInDatabase("foundEggs", eggs);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public void addEgg(String name) {
|
|
|
|
ArrayList<String> list = getFoundEggs();
|
|
|
|
list.add(name);
|
|
|
|
setFoundEggs(list);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private void setSettings(Map<String, Object> settings) {
|
|
|
|
setInDatabase("Settings", settings);
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
private void setSetting(String name, java.io.Serializable setting) {
|
2016-04-26 15:05:18 +02:00
|
|
|
Map<String, Object> list = getSettings();
|
|
|
|
list.put(name, setting);
|
|
|
|
setSettings(list);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
public Rank getRank() {
|
|
|
|
return Rank.valueOf(getStringFromDatabase("rank"));
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Date getFirstLogin() {
|
|
|
|
return getDateFromDatabase("firstLogin");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getLastLogin() {
|
|
|
|
return getDateFromDatabase("lastLogin");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getLastOnline() {
|
|
|
|
return getDateFromDatabase("lastOnline");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLastIP() {
|
|
|
|
return getStringFromDatabase("lastIP");
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTSID() {
|
|
|
|
return getIntegerFromDatabase("tsid");
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private int getTimesJoined() {
|
2016-06-25 15:42:06 +02:00
|
|
|
return getIntegerFromDatabase("timesJoined");
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getCoins() {
|
|
|
|
return getIntegerFromDatabase("coins");
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getExperience() {
|
|
|
|
return getIntegerFromDatabase("experience");
|
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public int getSecrets() {
|
|
|
|
return getFoundSecrets().size();
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
public ArrayList<String> getFoundSecrets() {
|
2016-04-26 15:05:18 +02:00
|
|
|
return getArrayListFromDatabase("foundSecrets");
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public int getEggs() {
|
|
|
|
return getFoundEggs().size();
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
|
|
|
private ArrayList<String> getFoundEggs() {
|
|
|
|
return getArrayListFromDatabase("foundEggs");
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private Map<String, Object> getSettings() {
|
|
|
|
return getMapFromDatabase("Settings");
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
|
|
|
public Location getLastLocation() {
|
|
|
|
Map<String, Object> map = getMapFromDatabase("Pos");
|
2016-06-25 15:42:06 +02:00
|
|
|
return new Location(Bukkit.getWorld("world"), (double) map.get("X"), (double) map.get("Y"), (double) map.get("Z"), (float) map.get("Yaw"), (float) map.get("Pitch"));
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPlayerVisibility() {
|
|
|
|
return (String) getSettings().get("playerVisibility");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasInventoryAnimation() {
|
|
|
|
return (boolean) getSettings().get("inventoryAnimation");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasTeleportAnimation() {
|
|
|
|
return (boolean) getSettings().get("teleportAnimation");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPartyRequests() {
|
|
|
|
return (boolean) getSettings().get("partyRequests");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasFriendRequests() {
|
|
|
|
return (boolean) getSettings().get("friendRequests");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasFriendJump() {
|
|
|
|
return (boolean) getSettings().get("friendJump");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasChatSounds() {
|
|
|
|
return (boolean) getSettings().get("chatSounds");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasEffects() {
|
|
|
|
return (boolean) getSettings().get("effects");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasStoryMode() {
|
|
|
|
return (boolean) getSettings().get("storyMode");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
return (String) getSettings().get("language");
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public boolean hasTsMove() {
|
|
|
|
return (boolean) getSettings().get("tsMove");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasScoreboard() {
|
|
|
|
return (boolean) getSettings().get("scoreboard");
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public void setPlayerVisibility(String visibility) {
|
|
|
|
setSetting("playerVisibility", visibility);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInventoryAnimation(boolean animation) {
|
|
|
|
setSetting("inventoryAnimation", animation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTeleportAnimation(boolean animation) {
|
|
|
|
setSetting("teleportAnimation", animation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPartyRequests(boolean requests) {
|
|
|
|
setSetting("partyRequests", requests);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFriendRequests(boolean requests) {
|
|
|
|
setSetting("friendRequests", requests);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFriendJump(boolean jump) {
|
|
|
|
setSetting("friendJump", jump);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChatSounds(boolean sounds) {
|
|
|
|
setSetting("chatSounds", sounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEffects(boolean effects) {
|
|
|
|
setSetting("effects", effects);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStoryMode(boolean storyMode) {
|
|
|
|
setSetting("storyMode", storyMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLanguage(String language) {
|
|
|
|
setSetting("language", language);
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public void setTsMove(boolean tsMove) {
|
|
|
|
setSetting("tsMove", tsMove);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScoreboard(boolean scoreboard) {
|
|
|
|
setSetting("scoreboard", scoreboard);
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void connectToServer(String server) {
|
|
|
|
Servers.connectServer(PLAYER, server);
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
public boolean isAllowed(Rank rank) {
|
|
|
|
return getRank().getValue() >= rank.getValue();
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public ArrayList<UUID> getFriends() {
|
2016-04-29 12:54:03 +02:00
|
|
|
FindIterable<Document> cursor = friendCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return (ArrayList<UUID>) doc.get("friends");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setFriends(ArrayList<UUID> friends) {
|
2016-04-29 12:54:03 +02:00
|
|
|
friendCollection.updateOne(new Document("uuid", getUniqueId().toString()), new Document("$set", new Document("friends", friends)));
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFriend(UUID uuid) {
|
|
|
|
return getFriends().contains(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addFriend(UUID uuid) {
|
|
|
|
ArrayList<UUID> list = getFriends();
|
|
|
|
list.add(uuid);
|
|
|
|
setFriends(list);
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:54:03 +02:00
|
|
|
public void warn(Hack hack) {
|
|
|
|
//TODO: add actual function
|
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public String getPrefix() {
|
|
|
|
if (customPrefix != null) return customPrefix;
|
2016-07-09 13:14:19 +02:00
|
|
|
if (isNicked()) return Rank.Premium.getPrefix();
|
|
|
|
return getRank().getPrefix();
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getSuffix() {
|
|
|
|
if (customSuffix != null) return customSuffix;
|
2016-07-09 13:14:19 +02:00
|
|
|
if (isNicked()) return Rank.Premium.getSuffix();
|
|
|
|
return getRank().getSuffix();
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public String getColor() {
|
|
|
|
if (customColor != null) return customColor;
|
2016-07-09 13:14:19 +02:00
|
|
|
if (isNicked()) return Rank.Premium.getColor();
|
|
|
|
return getRank().getColor();
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public Team getTeam() {
|
2016-07-09 13:14:19 +02:00
|
|
|
if (isNicked()) getScoreboard().getTeam(Rank.Premium.getTeam());
|
|
|
|
return getScoreboard().getTeam(getRank().getTeam());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void setCustomPrefix(String prefix) {
|
|
|
|
customPrefix = prefix;
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void setCustomSuffix(String suffix) {
|
|
|
|
customSuffix = suffix;
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void setCustomColor(String color) {
|
|
|
|
customColor = color;
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public boolean hasEmptyInventory() {
|
|
|
|
return Utils.hasEmptyInventory(PLAYER);
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void clearPotionEffects() {
|
|
|
|
Utils.clearPotionEffects(PLAYER);
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public boolean hasOpenInventory() {
|
|
|
|
return openInventory;
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void setOpenInventory(boolean openInventory) {
|
|
|
|
this.openInventory = openInventory;
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void addCoins(int coins) {
|
|
|
|
setCoins(getCoins() + coins);
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void substractCoins(int coins) {
|
|
|
|
setCoins(getCoins() - coins);
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void sendActionBar(String text) {
|
|
|
|
Actionbar.send(PLAYER, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addExperience(int experience) {
|
|
|
|
setExperience(getExperience() + experience);
|
|
|
|
setExp(0F);
|
|
|
|
giveExp(getExperience());
|
|
|
|
playSound(getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void substractExperience(int experience) {
|
|
|
|
setExperience(getExperience() - experience);
|
|
|
|
setExp(0F);
|
|
|
|
giveExp(getExperience());
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
public void refreshExperience() {
|
|
|
|
setLevel(0);
|
|
|
|
setExp(0F);
|
|
|
|
giveExp(getExperience());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playParticle(Location loc, EnumParticle ep, float f, int count) {
|
2016-06-25 15:42:06 +02:00
|
|
|
if (hasEffects()) Effects.playEffectToPlayer(PLAYER, loc, ep, f, count);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAttackSpeed(double speed) {
|
|
|
|
AttributeModifier modifier = new AttributeModifier("Core", speed, AttributeModifier.Operation.ADD_NUMBER);
|
|
|
|
getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(modifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getAttackSpeed() {
|
|
|
|
return getAttribute(Attribute.GENERIC_ATTACK_SPEED).getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetAttackSpeed() {
|
|
|
|
AttributeModifier modifier = new AttributeModifier("Core", getAttackSpeed(), AttributeModifier.Operation.ADD_NUMBER);
|
|
|
|
getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(modifier);
|
2016-04-26 15:05:18 +02:00
|
|
|
AttributeInstance instance = getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
|
|
|
instance.setBaseValue(16.0D);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Messages getMessages() {
|
|
|
|
return new Messages(this);
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public String getMessage(String message) {
|
2016-07-09 13:14:19 +02:00
|
|
|
return new Language(getLanguage()).getWord(message);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public boolean isNicked() {
|
|
|
|
return (boolean) getSettings().get("nicked");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setNicked(boolean nicked) {
|
|
|
|
setSetting("nicked", nicked);
|
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
private void loadSkin(String name) {
|
|
|
|
//Skin skin = new Skin(UUIDFetcher.getUUID(name).toString());
|
|
|
|
GameProfile skin;
|
|
|
|
GameProfile gp = getProfile();
|
|
|
|
try {
|
|
|
|
skin = GameProfileBuilder.fetch(UUIDFetcher.getUUID(name));
|
|
|
|
Collection<Property> properties = skin.getProperties().get("textures");
|
|
|
|
gp.getProperties().removeAll("textures");
|
|
|
|
gp.getProperties().putAll("textures", properties);
|
|
|
|
PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(getEntityId());
|
|
|
|
sendPacket(destroy);
|
|
|
|
PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, getHandle());
|
|
|
|
sendPacket(remove);
|
|
|
|
setHealth(0.0D);
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, getHandle());
|
|
|
|
sendPacket(add);
|
|
|
|
PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(getHandle());
|
|
|
|
Core.getOnlinePlayers().stream().filter(player -> !player.getName().equals(getName())).forEach(player -> sendPacket(spawn));
|
|
|
|
}
|
|
|
|
}.runTaskLater(Core.getInstance(), 4);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Core.log(Level.SEVERE, "Mojang Skin Server offline");
|
|
|
|
sendMessage("§cSkin Server sind offline");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public void removeNick() {
|
2016-06-25 15:42:06 +02:00
|
|
|
setNick(getName());
|
2016-05-08 10:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getNick() {
|
2016-06-25 15:42:06 +02:00
|
|
|
if (nickname != null) return nickname;
|
|
|
|
return null;
|
2016-05-08 10:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setNick(String name) {
|
2016-06-25 15:42:06 +02:00
|
|
|
setDisplayName(name);
|
|
|
|
Field nameField = getField(GameProfile.class, "name");
|
|
|
|
try {
|
|
|
|
nameField.set(getProfile(), name);
|
|
|
|
PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(getEntityId());
|
|
|
|
sendPacket(destroy);
|
|
|
|
PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, getHandle());
|
|
|
|
sendPacket(remove);
|
|
|
|
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, getHandle());
|
|
|
|
sendPacket(add);
|
|
|
|
PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(getHandle());
|
|
|
|
Core.getOnlinePlayers().stream().filter(players -> !players.equals(this)).forEach(players -> players.sendPacket(spawn));
|
|
|
|
}
|
|
|
|
}.runTaskLater(Core.getInstance(), 4);
|
|
|
|
|
|
|
|
loadSkin(name);
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void strikeLightning(Location loc) {
|
|
|
|
World nmsWorld = ((CraftWorld)loc.getWorld()).getHandle();
|
|
|
|
EntityLightning lightning = new EntityLightning(nmsWorld, loc.getX(), loc.getY(), loc.getZ(), true);
|
|
|
|
sendPacket(new PacketPlayOutSpawnEntityWeather(lightning));
|
|
|
|
playSound(loc, Sound.ENTITY_LIGHTNING_IMPACT, 20.0F, 1.0F);
|
|
|
|
playSound(loc, Sound.ENTITY_LIGHTNING_THUNDER, 20.0F, 1.0F);
|
2016-05-08 10:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOnline() {
|
|
|
|
FindIterable<Document> cursor = onlinePlayerCollection.find(new Document("uuid", getUniqueId().toString()));
|
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
Document doc = cursor.first();
|
|
|
|
return doc != null;
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
private void setInDatabase(String name, Object obj) {
|
2016-05-08 10:45:34 +02:00
|
|
|
playerCollection.updateOne(new Document("uuid", getUniqueId().toString()), new Document("$set", new Document(name, obj)));
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private Object getObjectFromDatbase(String name) {
|
2016-05-08 10:45:34 +02:00
|
|
|
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return doc.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getIntegerFromDatabase(String name) {
|
2016-05-08 10:45:34 +02:00
|
|
|
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return 0;
|
|
|
|
|
|
|
|
return doc.getInteger(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getStringFromDatabase(String name) {
|
2016-05-08 10:45:34 +02:00
|
|
|
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return doc.getString(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Date getDateFromDatabase(String name) {
|
2016-05-08 10:45:34 +02:00
|
|
|
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", getUniqueId().toString()));
|
2016-04-26 15:05:18 +02:00
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return doc.getDate(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ArrayList<String> getArrayListFromDatabase(String name) {
|
|
|
|
return (ArrayList<String>) getObjectFromDatbase(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> getMapFromDatabase(String name) {
|
|
|
|
return (Map<String, Object>) getObjectFromDatbase(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initScoreboard() {
|
|
|
|
Scoreboard board = getScoreboard();
|
|
|
|
board.getTeams().forEach(Team::unregister);
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
for(Rank rank : Rank.values()) {
|
|
|
|
Team team = board.registerNewTeam(rank.getTeam());
|
|
|
|
team.setPrefix(rank.getTab());
|
|
|
|
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
|
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
public void setLabyModFeatures(HashMap<LabyMod, Boolean> list) {
|
2016-04-26 15:05:18 +02:00
|
|
|
HashMap<String, Boolean> temp = new HashMap<>();
|
2016-07-09 13:14:19 +02:00
|
|
|
for (LabyMod feature : list.keySet())
|
2016-04-26 15:05:18 +02:00
|
|
|
temp.put(feature.name(), list.get(feature));
|
2016-07-09 13:14:19 +02:00
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
|
|
|
try {
|
|
|
|
ObjectOutputStream out = new ObjectOutputStream(byteOut);
|
|
|
|
out.writeObject(temp);
|
|
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(byteOut.toByteArray());
|
|
|
|
PacketDataSerializer packetDataSerializer = new PacketDataSerializer(byteBuf);
|
|
|
|
PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload("LABYMOD", packetDataSerializer);
|
|
|
|
getHandle().playerConnection.sendPacket(packet);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:54:03 +02:00
|
|
|
public void crashClient() {
|
2016-06-25 15:42:06 +02:00
|
|
|
sendPacket(new PacketPlayOutExplosion(9999999999D,
|
2016-04-29 12:54:03 +02:00
|
|
|
9999999999D, 9999999999D, 9999999999F,
|
|
|
|
new ArrayList<>(), new Vec3D(9999999999D,
|
|
|
|
9999999999D, 9999999999D)));
|
|
|
|
}
|
2016-05-08 10:45:34 +02:00
|
|
|
|
|
|
|
public void sendPacket(Packet<?> packet) {
|
|
|
|
getHandle().playerConnection.sendPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Field getField(Class<?> clazz, String name) {
|
|
|
|
try {
|
|
|
|
Field field = clazz.getDeclaredField(name);
|
|
|
|
field.setAccessible(true);
|
|
|
|
return field;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void refreshTablist() {
|
|
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
|
|
|
setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
|
|
|
getScoreboard().getTeam(player.getTeam().getName()).addEntry(player.getDisplayName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
public Player.Spigot spigot() {
|
|
|
|
return PLAYER.spigot();
|
|
|
|
}
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|