2017-09-07 22:36:54 +02:00
|
|
|
|
/*
|
2018-01-15 12:25:45 +01:00
|
|
|
|
* Copyright (c) 2018 univento.eu - All rights reserved
|
2017-09-07 22:36:54 +02:00
|
|
|
|
* You are not allowed to use, distribute or modify this code
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
|
package eu.univento.core.listeners;
|
|
|
|
|
|
2016-10-11 23:20:58 +02:00
|
|
|
|
import eu.univento.commons.player.language.MessageConstant;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
import eu.univento.core.Core;
|
2016-05-08 10:45:34 +02:00
|
|
|
|
import eu.univento.core.api.player.*;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
import eu.univento.core.api.server.ServerSettings;
|
2017-06-04 13:42:10 +02:00
|
|
|
|
import eu.univento.core.commands.BuilderCommands;
|
|
|
|
|
import eu.univento.core.commands.ModCommands;
|
2017-09-07 22:36:54 +02:00
|
|
|
|
import eu.univento.core.listeners.cloud.Servers;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
import org.bukkit.Bukkit;
|
2018-01-15 12:25:45 +01:00
|
|
|
|
import org.bukkit.SoundCategory;
|
2017-09-07 22:36:54 +02:00
|
|
|
|
import org.bukkit.entity.Player;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
|
import org.bukkit.event.Listener;
|
2016-11-24 19:52:24 +01:00
|
|
|
|
import org.bukkit.event.player.*;
|
2016-04-13 05:52:53 +02:00
|
|
|
|
import org.bukkit.scoreboard.Team;
|
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
import java.io.IOException;
|
2016-05-08 10:45:34 +02:00
|
|
|
|
import java.util.HashMap;
|
2016-07-28 20:17:25 +02:00
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
2016-05-08 10:45:34 +02:00
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author joethei
|
|
|
|
|
* @version 1.0
|
|
|
|
|
*/
|
2016-05-08 10:45:34 +02:00
|
|
|
|
public class JoinQuit implements Listener {
|
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
|
private List<CustomPlayer> firstJoin = new LinkedList<>();
|
|
|
|
|
private List<CustomPlayer> loading = new LinkedList<>();
|
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
|
@EventHandler
|
2016-11-24 19:52:24 +01:00
|
|
|
|
public void onPreLogin(AsyncPlayerPreLoginEvent e) {
|
2017-04-15 13:00:58 +02:00
|
|
|
|
/*
|
2016-11-24 19:52:24 +01:00
|
|
|
|
if(!Core.getCommons().getSecurityHandler().isValidServer(e.getAddress().getHostAddress())) {
|
|
|
|
|
e.setKickMessage("Im sorry, you can only join from our official IP: play.univento.eu");
|
2017-04-15 13:00:58 +02:00
|
|
|
|
e
|
|
|
|
|
.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
|
2016-10-28 23:50:06 +02:00
|
|
|
|
}
|
2017-04-15 13:00:58 +02:00
|
|
|
|
*/
|
2016-11-24 19:52:24 +01:00
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
2017-09-07 22:36:54 +02:00
|
|
|
|
@EventHandler
|
|
|
|
|
public void onLogin(PlayerLoginEvent e) {
|
|
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
2018-01-15 12:25:45 +01:00
|
|
|
|
if(e.getHostname() == null) p.getDatabasePlayer().load("unknown");
|
|
|
|
|
else p.getDatabasePlayer().load(e.getHostname());
|
2017-09-07 22:36:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 19:52:24 +01:00
|
|
|
|
@EventHandler
|
|
|
|
|
public void onJoin(PlayerJoinEvent e) {
|
|
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
2017-04-15 13:00:58 +02:00
|
|
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
2017-06-04 13:42:10 +02:00
|
|
|
|
if (ModCommands.getVanishedPlayers().contains(player) || SpectateManager.contains(player)) {
|
2016-04-13 05:52:53 +02:00
|
|
|
|
p.hidePlayer(player);
|
2017-04-15 13:00:58 +02:00
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
}
|
2018-01-15 12:25:45 +01:00
|
|
|
|
if(Servers.getTeleport().containsKey(p.getUniqueId())) p.teleport(Bukkit.getPlayer(Servers.getTeleport().remove(p.getUniqueId())));
|
|
|
|
|
|
2017-04-15 13:00:58 +02:00
|
|
|
|
HashMap<LabyMod, Boolean> labyModFeatures = new HashMap<>();
|
|
|
|
|
labyModFeatures.put(LabyMod.DAMAGEINDICATOR, false);
|
|
|
|
|
labyModFeatures.put(LabyMod.MINIMAP_RADAR, false);
|
|
|
|
|
labyModFeatures.put(LabyMod.ARMOR, false);
|
|
|
|
|
labyModFeatures.put(LabyMod.POTIONS, false);
|
|
|
|
|
labyModFeatures.put(LabyMod.ANIMATIONS, false);
|
|
|
|
|
labyModFeatures.put(LabyMod.EXTRAS, false);
|
|
|
|
|
p.setLabyModFeatures(labyModFeatures);
|
|
|
|
|
|
|
|
|
|
p.sendMessage(BetterPvP.getCodeString());
|
|
|
|
|
|
|
|
|
|
//disable code for minimap mod
|
|
|
|
|
p.sendMessage("§A§n§t§i§M§i§n§i§m§a§p");
|
|
|
|
|
p.sendMessage("§3 §6 §3 §6 §3 §6 §e");
|
|
|
|
|
p.sendMessage("§0§0§1§2§3§5§e§f");
|
|
|
|
|
p.sendMessage("§0§0§c§d§e§f");
|
|
|
|
|
|
|
|
|
|
assert getPayload() != null;
|
|
|
|
|
p.sendPluginMessage(Core.getInstance(), "schematica", getPayload());
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
|
p.setGameMode(ServerSettings.getGameMode());
|
2016-04-13 05:52:53 +02:00
|
|
|
|
p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
2016-04-26 15:05:18 +02:00
|
|
|
|
p.initScoreboard();
|
2017-06-04 13:42:10 +02:00
|
|
|
|
|
2017-09-07 22:36:54 +02:00
|
|
|
|
p.sendTabHeaderAndFooter("§2univento§8.§aeu\n§8× §7a unique universe &8×\n§e", "§6\n§bTwitter§8: §7@univentoEU\n§7auf gute §2Zusammenarbeit§8!");
|
2017-06-04 13:42:10 +02:00
|
|
|
|
|
2016-07-28 20:17:25 +02:00
|
|
|
|
for (CustomPlayer player : Core.getOnlinePlayers()) {
|
2017-04-15 13:00:58 +02:00
|
|
|
|
p.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> player.getScoreboard().getTeam(rank.getTeam()).addEntry(p.getDisplayName()));
|
|
|
|
|
player.getDatabasePlayer().getRankAsync().whenComplete((rank, throwable) -> p.getScoreboard().getTeam(rank.getTeam()).addEntry(player.getDisplayName()));
|
2016-04-13 05:52:53 +02:00
|
|
|
|
}
|
2017-06-04 13:42:10 +02:00
|
|
|
|
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
|
|
|
|
|
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
|
|
|
|
|
p.setNickName(NickName.getRandomNick());
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-06-25 15:42:06 +02:00
|
|
|
|
p.setCollidable(false);
|
2016-07-28 20:17:25 +02:00
|
|
|
|
|
2017-09-07 22:36:54 +02:00
|
|
|
|
if(Servers.getTeleport().containsKey(p.getUniqueId())) {
|
|
|
|
|
Player t = Bukkit.getPlayer(Servers.getTeleport().get(p.getUniqueId()));
|
|
|
|
|
p.teleport(t);
|
|
|
|
|
Servers.getTeleport().remove(p.getUniqueId());
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 12:25:45 +01:00
|
|
|
|
p.setStoryResourcePack();
|
|
|
|
|
loading.add(p);
|
2016-07-28 20:17:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onResourcePackStatus(PlayerResourcePackStatusEvent e) {
|
|
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
2017-04-15 13:00:58 +02:00
|
|
|
|
if (e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) {
|
|
|
|
|
if (firstJoin.contains(p)) {
|
2016-07-28 20:17:25 +02:00
|
|
|
|
firstJoin.remove(p);
|
2017-04-15 13:00:58 +02:00
|
|
|
|
if (ServerSettings.isLobby()) {
|
2018-01-15 12:25:45 +01:00
|
|
|
|
p.playSound(p.getEyeLocation(), "glider.boot_up", SoundCategory.MASTER, 1.0F, 1.0F);
|
2016-07-28 20:17:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loading.remove(p);
|
|
|
|
|
}
|
2017-04-15 13:00:58 +02:00
|
|
|
|
if (e.getStatus() == PlayerResourcePackStatusEvent.Status.FAILED_DOWNLOAD) {
|
2016-10-11 23:20:58 +02:00
|
|
|
|
p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.PACK_FAILED_DOWNLOAD));
|
2016-07-28 20:17:25 +02:00
|
|
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Core.getInstance(), p::setStoryResourcePack, 10 * 20L);
|
|
|
|
|
}
|
2017-04-15 13:00:58 +02:00
|
|
|
|
if (e.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED) {
|
2016-10-11 23:20:58 +02:00
|
|
|
|
p.sendMessage(p.getDatabasePlayer().getLanguage().getMessage(MessageConstant.PACK_DECLINED));
|
2016-07-28 20:17:25 +02:00
|
|
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Core.getInstance(), p::setStoryResourcePack, 10 * 20L);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
|
@EventHandler
|
|
|
|
|
public void onQuit(PlayerQuitEvent e) {
|
|
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
2017-06-04 13:42:10 +02:00
|
|
|
|
if (BuilderCommands.getBuildPlayers().containsKey(p))
|
|
|
|
|
BuilderCommands.getBuildPlayers().remove(p);
|
2017-04-15 13:00:58 +02:00
|
|
|
|
p.getDatabasePlayer().getSettingsAsync().whenComplete((playerSettings, throwable) -> {
|
|
|
|
|
if(playerSettings.isNicked() && !ServerSettings.isLobby()) {
|
|
|
|
|
p.removeNickName();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-08 10:45:34 +02:00
|
|
|
|
for (Team team : p.getScoreboard().getTeams()) {
|
2016-04-13 05:52:53 +02:00
|
|
|
|
team.removeEntry(p.getDisplayName());
|
|
|
|
|
}
|
2017-09-07 22:36:54 +02:00
|
|
|
|
p.onLeave();
|
2016-05-08 10:45:34 +02:00
|
|
|
|
}
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
2016-05-08 10:45:34 +02:00
|
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
|
|
|
|
public void onKick(PlayerKickEvent e) {
|
|
|
|
|
e.setLeaveMessage(null);
|
2016-04-13 05:52:53 +02:00
|
|
|
|
}
|
2016-05-08 10:45:34 +02:00
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
|
private byte[] getPayload() {
|
|
|
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
|
|
|
|
|
try {
|
|
|
|
|
dataOutputStream.writeByte(0);
|
|
|
|
|
dataOutputStream.writeBoolean(false);
|
|
|
|
|
dataOutputStream.writeBoolean(false);
|
|
|
|
|
dataOutputStream.writeBoolean(true);
|
|
|
|
|
|
|
|
|
|
return byteArrayOutputStream.toByteArray();
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
|
}
|