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;
|
2016-08-03 00:15:45 +02:00
|
|
|
import eu.univento.commons.player.DatabasePlayer;
|
|
|
|
import eu.univento.commons.player.Rank;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.Core;
|
2016-07-28 20:17:25 +02:00
|
|
|
import eu.univento.core.api.Hologram;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.Utils;
|
2016-07-28 20:17:25 +02:00
|
|
|
import eu.univento.core.api.effects.Blackscreen;
|
2016-04-13 05:52:53 +02:00
|
|
|
import eu.univento.core.api.effects.Effects;
|
|
|
|
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-07-28 20:17:25 +02:00
|
|
|
import eu.univento.core.api.shop.ShopItem;
|
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-09-19 17:21:39 +02:00
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
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-08-03 00:15:45 +02:00
|
|
|
import org.bukkit.Material;
|
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-07-28 20:17:25 +02:00
|
|
|
import org.bukkit.boss.BarColor;
|
|
|
|
import org.bukkit.boss.BarFlag;
|
|
|
|
import org.bukkit.boss.BarStyle;
|
|
|
|
import org.bukkit.boss.BossBar;
|
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-08-03 00:15:45 +02:00
|
|
|
public class CustomPlayer extends CraftPlayer{
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
private static final HashMap<UUID, CustomPlayer> PLAYERS = new HashMap<>();
|
2016-04-13 05:52:53 +02:00
|
|
|
private final Player PLAYER;
|
2016-08-03 00:15:45 +02:00
|
|
|
private final DatabasePlayer DATABASE_PLAYER;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
private boolean openInventory;
|
|
|
|
|
|
|
|
private CustomPlayer(Player player) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), ((CraftPlayer) player).getHandle());
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER = new DatabasePlayer(Core.getCommons(), player.getUniqueId());
|
2016-07-28 20:17:25 +02:00
|
|
|
PLAYERS.put(player.getUniqueId(), this);
|
2016-04-13 05:52:53 +02:00
|
|
|
PLAYER = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onLeave() {
|
|
|
|
Date date = new Date();
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER.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-08-03 00:15:45 +02:00
|
|
|
if (ServerSettings.isLobby()) DATABASE_PLAYER.setInDatabase("Pos", new BasicDBObject(location));
|
2016-04-13 05:52:53 +02:00
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
if (PLAYERS.containsKey(getUniqueId())) PLAYERS.remove(getUniqueId());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomPlayer getPlayer(String player) {
|
2016-07-28 20:17:25 +02:00
|
|
|
Player p = Bukkit.getPlayer(player);
|
|
|
|
if (PLAYERS.containsKey(p.getUniqueId())) {
|
|
|
|
return PLAYERS.get(p.getUniqueId());
|
2016-04-13 05:52:53 +02:00
|
|
|
} else {
|
2016-07-28 20:17:25 +02:00
|
|
|
return new CustomPlayer(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomPlayer getPlayer(UUID player) {
|
|
|
|
if(PLAYERS.containsKey(player)) {
|
|
|
|
return PLAYERS.get(player);
|
|
|
|
}
|
|
|
|
else {
|
2016-04-13 05:52:53 +02:00
|
|
|
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) {
|
2016-07-28 20:17:25 +02:00
|
|
|
return getPlayer(player.getUniqueId());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Player getPLAYER() {
|
|
|
|
return PLAYER;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:15:45 +02:00
|
|
|
public DatabasePlayer getDatabasePlayer() {
|
|
|
|
return DATABASE_PLAYER;
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:15:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasPlayedBefore() {
|
|
|
|
return DATABASE_PLAYER.hasPlayedBefore();
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
public void buy(ShopItem item) {
|
|
|
|
Map<ShopItem, Boolean> map = getBoughtItems();
|
|
|
|
map.put(item, false);
|
|
|
|
setBoughtItems(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<ShopItem, Boolean> getBoughtItems() {
|
|
|
|
Map<ShopItem, Boolean> map = new HashMap<>();
|
2016-08-03 00:15:45 +02:00
|
|
|
for (Map.Entry<String, Object> entry : DATABASE_PLAYER.getMapFromDatabase("bought").entrySet())
|
2016-07-28 20:17:25 +02:00
|
|
|
map.put(ShopItem.valueOf(String.valueOf(entry.getKey())), Boolean.valueOf(String.valueOf(entry.getValue())));
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setBoughtItems(Map<ShopItem, Boolean> map) {
|
|
|
|
Map<String, Boolean> items = new HashMap<>();
|
|
|
|
for (Map.Entry<ShopItem, Boolean> entry : map.entrySet()) items.put(String.valueOf(entry.getKey()), entry.getValue());
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER.setInDatabase("bought", items);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
2016-04-26 15:05:18 +02:00
|
|
|
|
|
|
|
public Location getLastLocation() {
|
2016-08-03 00:15:45 +02:00
|
|
|
Map<String, Object> map = DATABASE_PLAYER.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
|
|
|
}
|
|
|
|
|
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-28 20:17:25 +02:00
|
|
|
public void warn(WarnReason reason, CustomPlayer warner, String proof) {
|
|
|
|
Document doc = new Document("uuid", getUniqueId().toString());
|
|
|
|
doc.put("reason", reason.name());
|
|
|
|
doc.put("warner", warner.getUniqueId().toString());
|
|
|
|
doc.put("date", new Date());
|
|
|
|
doc.put("proof", proof);
|
|
|
|
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER.getWarnCollection().insertOne(doc);
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
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-07-28 20:17:25 +02:00
|
|
|
/*
|
|
|
|
@Deprecated
|
|
|
|
public void sendActionBar(String text) {
|
|
|
|
IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}");
|
|
|
|
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
|
|
|
|
sendPacket(ppoc);
|
|
|
|
}
|
|
|
|
*/
|
2016-04-26 15:05:18 +02:00
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
public void sendActionBar(String text) {
|
2016-09-19 17:21:39 +02:00
|
|
|
spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(text));
|
2016-07-28 20:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void sendTitle(int fadeIn, int stay, int fadeOut, String title, String subtitle) {
|
|
|
|
PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut);
|
|
|
|
sendPacket(packetPlayOutTimes);
|
|
|
|
|
|
|
|
if (subtitle != null) {
|
|
|
|
subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
|
|
|
|
IChatBaseComponent titleSub = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
|
|
|
|
PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
|
|
|
|
sendPacket(packetPlayOutSubTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title != null) {
|
|
|
|
title = ChatColor.translateAlternateColorCodes('&', title);
|
|
|
|
IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
|
|
|
|
PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
|
|
|
|
sendPacket(packetPlayOutTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BossBar sendBossBar(String text, BarColor color, BarStyle style, BarFlag flag) {
|
|
|
|
BossBar bar = Bukkit.createBossBar(text, color, style, flag);
|
|
|
|
bar.addPlayer(PLAYER);
|
|
|
|
return bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Hologram sendHologram(Location location, String... text) {
|
|
|
|
Hologram hologram = new Hologram(text, location);
|
|
|
|
hologram.showPlayer(this);
|
|
|
|
return hologram;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendTabHeaderAndFooter(String header, String footer) {
|
|
|
|
if (header == null)
|
|
|
|
header = "";
|
|
|
|
header = ChatColor.translateAlternateColorCodes('&', header);
|
|
|
|
|
|
|
|
if (footer == null)
|
|
|
|
footer = "";
|
|
|
|
footer = ChatColor.translateAlternateColorCodes('&', footer);
|
|
|
|
|
|
|
|
header = header.replaceAll("%player%", getDisplayName());
|
|
|
|
footer = footer.replaceAll("%player%", getDisplayName());
|
|
|
|
|
|
|
|
IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
|
|
|
|
IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
|
|
|
|
PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
|
|
|
|
try {
|
|
|
|
Field field = headerPacket.getClass().getDeclaredField("b");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(headerPacket, tabFoot);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
sendPacket(headerPacket);
|
|
|
|
}
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addExperience(int experience) {
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER.setExperience(DATABASE_PLAYER.getExperience() + experience);
|
2016-06-25 15:42:06 +02:00
|
|
|
setExp(0F);
|
2016-08-03 00:15:45 +02:00
|
|
|
giveExp(DATABASE_PLAYER.getExperience());
|
2016-06-25 15:42:06 +02:00
|
|
|
playSound(getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void substractExperience(int experience) {
|
2016-08-03 00:15:45 +02:00
|
|
|
DATABASE_PLAYER.setExperience(DATABASE_PLAYER.getExperience() - experience);
|
2016-06-25 15:42:06 +02:00
|
|
|
setExp(0F);
|
2016-08-03 00:15:45 +02:00
|
|
|
giveExp(DATABASE_PLAYER.getExperience());
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
public void refreshExperience() {
|
|
|
|
setLevel(0);
|
|
|
|
setExp(0F);
|
2016-08-03 00:15:45 +02:00
|
|
|
giveExp(DATABASE_PLAYER.getExperience());
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
2016-04-13 05:52:53 +02:00
|
|
|
public void playParticle(Location loc, EnumParticle ep, float f, int count) {
|
2016-08-03 00:15:45 +02:00
|
|
|
if (DATABASE_PLAYER.getSettings().hasEffectsEnabled()) 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);
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
private double getAttackSpeed() {
|
2016-04-13 05:52:53 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
2016-04-13 05:52:53 +02:00
|
|
|
public Messages getMessages() {
|
|
|
|
return new Messages(this);
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
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();
|
2016-08-03 00:15:45 +02:00
|
|
|
Core.getCommons().getLoggingHandler().getCore().error("Mojang Skin Server offline");
|
2016-06-25 15:42:06 +02:00
|
|
|
sendMessage("§cSkin Server sind offline");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
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
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
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) {
|
2016-07-28 20:17:25 +02:00
|
|
|
World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
|
2016-06-25 15:42:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
public void setBlackScreen(int seconds) {
|
|
|
|
Blackscreen.setBlack(PLAYER, seconds);
|
|
|
|
}
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
@Override
|
|
|
|
public boolean isOnline() {
|
2016-08-03 00:15:45 +02:00
|
|
|
return DATABASE_PLAYER.isOnline();
|
2016-05-08 10:45:34 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
public void setStoryResourcePack() {
|
|
|
|
setResourcePack("http://univento.eu/storyPack.zip");
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:05:18 +02:00
|
|
|
public void initScoreboard() {
|
|
|
|
Scoreboard board = getScoreboard();
|
|
|
|
board.getTeams().forEach(Team::unregister);
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
for (Rank rank : Rank.values()) {
|
2016-07-09 13:14:19 +02:00
|
|
|
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-09-19 17:21:39 +02:00
|
|
|
/**
|
|
|
|
* crash's the players client
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:21:39 +02:00
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
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-07-28 20:17:25 +02:00
|
|
|
@Deprecated
|
2016-06-25 15:42:06 +02:00
|
|
|
public void refreshTablist() {
|
|
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
|
|
|
setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
2016-08-03 00:15:45 +02:00
|
|
|
getScoreboard().getTeam(DATABASE_PLAYER.getRank().getTeam()).addEntry(player.getDisplayName());
|
2016-06-25 15:42:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param location location for effect
|
|
|
|
* @param effect particle effect
|
2016-08-03 00:15:45 +02:00
|
|
|
* @param id the id
|
|
|
|
* @param data the data
|
2016-07-28 20:17:25 +02:00
|
|
|
* @param offsetX offset in x direction
|
|
|
|
* @param offsetY offset in y direction
|
|
|
|
* @param offsetZ offset in z direction
|
|
|
|
* @param speed particle speed
|
|
|
|
* @param particleCount count of showed particles
|
|
|
|
* @param radius effect radius
|
|
|
|
*/
|
|
|
|
public void playEffect(Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius) {
|
2016-08-03 00:15:45 +02:00
|
|
|
if(DATABASE_PLAYER.getSettings().hasEffectsEnabled()) {
|
2016-09-19 17:21:39 +02:00
|
|
|
PLAYER.spigot().playEffect(location, effect, id, data, offsetX, offsetY, offsetZ, speed, particleCount, radius);
|
2016-08-03 00:15:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:21:39 +02:00
|
|
|
/**
|
|
|
|
* open or close chests for player
|
|
|
|
* @param loc location, block at location must be a type of chest
|
|
|
|
* @param open open or close the chest
|
|
|
|
*/
|
2016-08-03 00:15:45 +02:00
|
|
|
public void changeChestState(Location loc, boolean open) {
|
|
|
|
if(loc.getBlock().getType() != Material.CHEST) return;
|
|
|
|
byte dataByte = (open) ? (byte) 1 : 0;
|
|
|
|
BlockPosition position = new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
|
|
|
PacketPlayOutBlockAction blockActionPacket = new PacketPlayOutBlockAction(position, net.minecraft.server.v1_10_R1.Block.getById(loc.getBlock().getTypeId()), (byte) 1, dataByte);
|
|
|
|
sendPacket(blockActionPacket);
|
2016-07-09 13:14:19 +02:00
|
|
|
}
|
|
|
|
|
2016-09-19 17:21:39 +02:00
|
|
|
/**
|
|
|
|
* sets the amount of arrows that are in the body of the player
|
|
|
|
* @param count arrow count
|
|
|
|
*/
|
|
|
|
public void setArrowsInBody(int count) {
|
|
|
|
getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b), count);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getArrowsInBody() {
|
|
|
|
return getHandle().getDataWatcher().get(new DataWatcherObject<>(10, DataWatcherRegistry.b));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sends packets for item cooldown, items won't be disabled
|
|
|
|
* @param item item to have a cooldown
|
|
|
|
* @param time time in seconds
|
|
|
|
*/
|
|
|
|
public void setItemCooldown(ItemStack item, int time) {
|
|
|
|
sendPacket(new PacketPlayOutSetCooldown(item.getItem(), time));
|
|
|
|
}
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|