commit e0e00081a8ee265680d578ca8eb0baca42321d8a Author: Brandon <46827438+disclearing@users.noreply.github.com> Date: Thu Apr 6 23:47:43 2023 +0100 Nerds !! diff --git a/anticheat/pom.xml b/anticheat/pom.xml new file mode 100644 index 0000000..de28e29 --- /dev/null +++ b/anticheat/pom.xml @@ -0,0 +1,28 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + anticheat + + + 8 + 8 + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + Project + + + + \ No newline at end of file diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/AnticheatMain.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/AnticheatMain.java new file mode 100644 index 0000000..c5b26c5 --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/AnticheatMain.java @@ -0,0 +1,26 @@ +package io.github.guilhermematthew.anticheat; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public class AnticheatMain extends Constant { + + @Override + public void enable() { + + Bukkit.getConsoleSender().sendMessage(Fields.ENABLED); + + } + + @Override + public void disable() { + + Bukkit.getConsoleSender().sendMessage(Fields.DISABLED); + + } + + @Override + public void load() { + + } +} diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Constant.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Constant.java new file mode 100644 index 0000000..349142d --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Constant.java @@ -0,0 +1,36 @@ +package io.github.guilhermematthew.anticheat; + +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class Constant extends JavaPlugin implements Listener +{ + + //PLUGINS GETTERS + private PluginManager pm = Bukkit.getPluginManager(); + + //PLUGIN GETTING SYSTEM + private AnticheatMain plugin; + public AnticheatMain getPlugin() { + return plugin; + } + + //SYSTEM ABSTRACT LOG MAIN + public abstract void enable(); + public abstract void disable(); + public abstract void load(); + @Override + public void onEnable() { + this.enable(); + } + @Override + public void onDisable() { + this.disable(); + } + @Override + public void onLoad() { + this.load(); + } +} diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Fields.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Fields.java new file mode 100644 index 0000000..852d1c2 --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/Fields.java @@ -0,0 +1,10 @@ +package io.github.guilhermematthew.anticheat; + +public class Fields { + + public static final String + + ENABLED = "§aThis is system AC has enabled sucessfuel!", + DISABLED = "§cThis is system AC has disabled sucessfuel!"; + +} diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/controller/PlayerController.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/controller/PlayerController.java new file mode 100644 index 0000000..336460b --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/controller/PlayerController.java @@ -0,0 +1,24 @@ +package io.github.guilhermematthew.anticheat.controller; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class PlayerController { + + private int clicks; + private long expireTime = System.currentTimeMillis() + 1000; + public void addClicks() { + clicks++; + } + + private long startTime = System.currentTimeMillis(); + private int click; + private long lastClick; + public void addClick() { + this.click++; + this.lastClick = System.currentTimeMillis(); + } + +} diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/list/Autoclicker.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/list/Autoclicker.java new file mode 100644 index 0000000..3e353ef --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/list/Autoclicker.java @@ -0,0 +1,95 @@ +package io.github.guilhermematthew.anticheat.list; + +import io.github.guilhermematthew.anticheat.controller.PlayerController; +import io.github.guilhermematthew.anticheat.listeners.ConstantListeners; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import java.util.HashMap; +import java.util.Map; + +public class Autoclicker extends ConstantListeners { + + private Map clicksPerSecond; + private Map cooldownMap; + +/* public Autoclicker() { + clicksPerSecond = new HashMap<>(); + cooldownMap = new HashMap<>(); + + ProtocolLibrary.getProtocolManager() + .addPacketListener(new PacketAdapter(BukkitMain.getInstance(), PacketType.Play.Client.ARM_ANIMATION) { + + @Override + public void onPacketReceiving(PacketEvent event) { + Player player = event.getPlayer(); + + if (player == null || ProtocolGetter.getPing(player) >= 100) + return; + + if (cooldownMap.containsKey(player) && cooldownMap.get(player) > System.currentTimeMillis()) + return; + + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.ADVENTURE) + return; + + try { + if (player.getTargetBlock((Set) null, 4).getType() != Material.AIR) { + return; + } + } catch (IllegalStateException ex) { + return; + } + + handle(player); + } + + }); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerInteract(BlockDamageEvent event) { + clicksPerSecond.remove(event.getPlayer()); + cooldownMap.put(event.getPlayer(), System.currentTimeMillis() + 10000l); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + clicksPerSecond.remove(event.getPlayer()); + cooldownMap.remove(event.getPlayer()); + } + + public void handle(Player player) { + Clicks click = clicksPerSecond.computeIfAbsent(player, v -> new Clicks()); + + if (click.getExpireTime() < System.currentTimeMillis()) { + if (click.getClicks() >= 20) { + alert(player, click.getClicks()); + } + + clicksPerSecond.remove(player); + return; + } + + click.addClick(); + } + + @EventHandler + public void onUpdate(UpdateEvent event) { + if (event.getType() == UpdateType.SECOND) { + Iterator> iterator = clicksPerSecond.entrySet().iterator(); + + while (iterator.hasNext()) { + Entry entry = iterator.next(); + + if (entry.getValue().getExpireTime() < System.currentTimeMillis()) { + if (entry.getValue().getClicks() >= 20) { + alert(entry.getKey(), entry.getValue().getClicks()); + } + + iterator.remove(); + } + } + } + }*/ +} diff --git a/anticheat/src/main/java/io/github/guilhermematthew/anticheat/listeners/ConstantListeners.java b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/listeners/ConstantListeners.java new file mode 100644 index 0000000..943f4b7 --- /dev/null +++ b/anticheat/src/main/java/io/github/guilhermematthew/anticheat/listeners/ConstantListeners.java @@ -0,0 +1,43 @@ +package io.github.guilhermematthew.anticheat.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import java.util.function.Predicate; + +@Getter +public class ConstantListeners implements Listener { + + private String nameAt; + @Setter + private boolean alertCommon; + @Setter + private int maxAlerts = 10; + + public ConstantListeners() { + nameAt = getClass().getSimpleName().replace("ConstantListeners", ""); + } + + public void alert(Player player) { + alert(player, 0); + } + + public void alert(Player player, int cpsCount) { + broadcast(gamingProfile -> gamingProfile.isStaffer(), "§9Anticheat> §fO jogador §d" + player.getName() + "§f está usando §c" + getNameAt() + + (cpsCount > 0 ? " §4(" + cpsCount + " cps)" : "") + " §7(" + 1 + "/" + maxAlerts + ")!"); + } + + public void broadcast(Predicate filter, String message) { + CommonsGeneral.getProfileManager().getGamingProfiles().stream() + .filter(gamingProfile -> gamingProfile.isStaffer()) + .forEach(gamingProfile -> gamingProfile.sendMessage(message)); + } + + +} diff --git a/commons/.classpath b/commons/.classpath new file mode 100644 index 0000000..a5d9509 --- /dev/null +++ b/commons/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/commons/.project b/commons/.project new file mode 100644 index 0000000..242e05b --- /dev/null +++ b/commons/.project @@ -0,0 +1,23 @@ + + + commons + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/commons/.settings/org.eclipse.jdt.core.prefs b/commons/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/commons/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/commons/.settings/org.eclipse.m2e.core.prefs b/commons/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/commons/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/commons/dependency-reduced-pom.xml b/commons/dependency-reduced-pom.xml new file mode 100644 index 0000000..727e225 --- /dev/null +++ b/commons/dependency-reduced-pom.xml @@ -0,0 +1,129 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + commons + + clean install + + + maven-shade-plugin + 2.4 + + + package + + shade + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + viaversion-repo + https://repo.viaversion.com + + + + + org.github.paperspigot + paperspigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + json-simple + com.googlecode.json-simple + + + guava + com.google.guava + + + ebean + org.avaje + + + snakeyaml + org.yaml + + + bungeecord-chat + net.md-5 + + + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + com.comphenix.protocol + ProtocolLib + 4.8.0 + provided + + + byte-buddy + net.bytebuddy + + + + + com.viaversion + viaversion-api + [4.0.0,5.0.0) + provided + + + org.projectlombok + lombok + 1.16.12 + provided + + + net.md-5 + bungeecord-api + 1.16-R0.4 + system + D:/Users/zFros/Desktop/[SRC]/Dependencias/Zartema.jar + + + + 8 + 8 + + + diff --git a/commons/pom.xml b/commons/pom.xml new file mode 100644 index 0000000..7e9dc5d --- /dev/null +++ b/commons/pom.xml @@ -0,0 +1,129 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + commons + + + 8 + 8 + + + + clean install + + + org.apache.maven.plugins + maven-shade-plugin + 2.4 + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + package + + shade + + + + + + + + + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + viaversion-repo + https://repo.viaversion.com + + + + + + net.md-5 + bungeecord-api + 1.16-R0.4 + D:/Users/zFros/Desktop/[SRC]/Dependencias/Zartema.jar + system + + + org.github.paperspigot + paperspigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + com.comphenix.protocol + ProtocolLib + 4.8.0 + provided + + + org.apache.commons + commons-lang3 + 3.12.0 + + + com.google.code.gson + gson + 2.10 + + + redis.clients + jedis + 2.9.0 + + + org.apache.commons + commons-pool2 + 2.11.1 + + + com.viaversion + viaversion-api + [4.0.0,5.0.0) + provided + + + com.zaxxer + HikariCP + 4.0.3 + + + net.dv8tion + JDA + 5.0.0-beta.3 + + + + \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsConst.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsConst.java new file mode 100644 index 0000000..4812fe8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsConst.java @@ -0,0 +1,21 @@ +package com.br.guilhermematthew.nowly.commons; + +import com.google.gson.Gson; +import com.google.gson.JsonParser; + +import java.util.Random; + +public class CommonsConst { + + public static final String SERVER_NAME = "LEAGUE"; + public static final String DEFAULT_COLOR = "§2"; + public static final String PREFIX = DEFAULT_COLOR + "§l" + SERVER_NAME.toUpperCase(); + public static final String LOJA = "www.leaguemc.com.br"; + public static final String DISCORD = "discord.gg/leaguemc"; + public static final String DIR_CONFIG_NAME = "DustConfig"; + public static final String PERMISSION_PREFIX = "commons"; + + public static final Random RANDOM = new Random(); + public static final JsonParser PARSER = new JsonParser(); + public static final Gson GSON = new Gson(); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsGeneral.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsGeneral.java new file mode 100644 index 0000000..0955365 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/CommonsGeneral.java @@ -0,0 +1,81 @@ +package com.br.guilhermematthew.nowly.commons; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQL; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.ProfileManager; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServersManager; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher; + +public class CommonsGeneral { + + private static final ProfileManager profileManager = new ProfileManager(); + private static final UUIDFetcher uuidFetcher = new UUIDFetcher(); + private static final ServersManager serversManager = new ServersManager(); + private static final MySQL mySQL = new MySQL(); + + private static PluginInstance pluginInstance = PluginInstance.UNKNOWN; + + public static boolean correctlyStarted() { + if (!getMySQL().isConnected()) { + error("A conexao com o MySQL nao teve exito, fechando servidor."); + return false; + } + return true; + } + + public static ProfileManager getProfileManager() { + return profileManager; + } + + public static UUIDFetcher getUUIDFetcher() { + return uuidFetcher; + } + + public static PluginInstance getPluginInstance() { + return pluginInstance; + } + + public static void setPluginInstance(PluginInstance pluginInstance) { + CommonsGeneral.pluginInstance = pluginInstance; + } + + public static ServersManager getServersManager() { + return serversManager; + } + + public static void shutdown() { + if (pluginInstance == PluginInstance.BUNGEECORD) { + BungeeMain.shutdown(); + } else { + BukkitMain.shutdown(); + } + } + + public static void error(String message) { + console("§c[ERRO] " + message); + } + + public static void console(String message) { + if (pluginInstance == PluginInstance.BUKKIT) { + BukkitMain.console(message); + } else { + BungeeMain.console(message); + } + } + + public static void runAsync(Runnable runnable) { + if (pluginInstance == PluginInstance.BUKKIT) { + BukkitMain.runAsync(runnable); + } else { + BungeeMain.runAsync(runnable); + } + } + + public static MySQL getMySQL() { + return mySQL; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.java new file mode 100644 index 0000000..7284026 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.java @@ -0,0 +1,165 @@ +package com.br.guilhermematthew.nowly.commons.bukkit; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemListener; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuListener; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandFramework; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStatusUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.scheduler.BukkitUpdateScheduler; +import com.br.guilhermematthew.nowly.commons.bukkit.listeners.CoreListener; +import com.br.guilhermematthew.nowly.commons.bukkit.listeners.WorldDListener; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.BukkitManager; +import com.br.guilhermematthew.nowly.commons.bukkit.networking.BukkitPacketsHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.loader.BukkitListeners; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.IOException; +import java.util.UUID; + +public class BukkitMain extends JavaPlugin { + + @Getter + @Setter + private static BukkitMain instance; + + @Getter + @Setter + private static int serverID; + + @Getter + @Setter + private static ServerType serverType; + + @Getter + @Setter + private static boolean loaded; + + @Getter + @Setter + private static BukkitManager manager; + + public static void console(String msg) { + Bukkit.getConsoleSender().sendMessage("[Commons] " + msg); + } + + public static void runAsync(Runnable runnable) { + Bukkit.getScheduler().runTaskAsynchronously(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + runLater(runnable, 5); + } + + public static void runLater(Runnable runnable, long ticks) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, ticks); + } + + public static void runSync(Runnable runnable) { + if (getInstance().isEnabled() && !getInstance().getServer().isPrimaryThread()) { + getInstance().getServer().getScheduler().runTask(getInstance(), runnable); + } else { + runnable.run(); + } + } + + public static BukkitPlayer getBukkitPlayer(final UUID uniqueId) { + return (BukkitPlayer) CommonsGeneral.getProfileManager().getGamingProfile(uniqueId); + } + + public static void shutdown() { + Bukkit.shutdown(); + } + + public void onLoad() { + saveDefaultConfig(); + + setLoaded(false); + + setInstance(this); + setManager(new BukkitManager()); + + // new BukkitLogFilter().registerFilter(); + + CommonsGeneral.setPluginInstance(PluginInstance.BUKKIT); + + getManager().getConfigurationManager().init(); + getServer().getMessenger().registerOutgoingPluginChannel(this, "WDL|CONTROL"); + getServer().getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", new WorldDListener()); + setServerType(ServerType.getServer(getConfig().getString("Servidor"))); + setServerID(getConfig().getInt("ServidorID")); + + CommonsGeneral.getMySQL().openConnection(); + } + + public void onEnable() { + if (getServerType() != ServerType.UNKNOWN) { + if (CommonsGeneral.correctlyStarted()) { + CommonsGeneral.getMySQL().createTables(); + + ServerCommunication.startClient(getServerType().getName(), getServerID(), getConfig().getString("Socket.Host")); + ServerCommunication.setPacketHandler(new BukkitPacketsHandler()); + + BukkitServerAPI.unregisterCommands("op", "deop", "kill", "about", "ver", "?", "scoreboard", "me", "say", "pl", + "plugins", "reload", "rl", "stop", "ban", "ban-ip", "msg", "ban-list", "help", "pardon", + "pardon-ip", "tp", "xp", "gamemode", "minecraft"); + + BukkitCommandFramework.INSTANCE.loadCommands(this, "com.br.guilhermematthew.nowly.commons.bukkit.commands.register"); + BukkitListeners.loadListeners(getInstance(), "com.br.guilhermematthew.nowly.commons.bukkit.listeners"); + + getServer().getMessenger().registerOutgoingPluginChannel(getInstance(), "BungeeCord"); + + if (getServerType().useMenuListener()) { + MenuListener.registerListeners(); + } + + if (getServerType().useActionItem()) { + Bukkit.getServer().getPluginManager().registerEvents(new ActionItemListener(), getInstance()); + } + + CoreListener.init(); + Bukkit.getServer().getScheduler().runTaskTimer(getInstance(), new BukkitUpdateScheduler(), 1, 1); + + initialize(); + } else { + Bukkit.shutdown(); + } + } else { + console("§cTipo de servidor nao encontrado, mude na configuracao!"); + Bukkit.shutdown(); + } + } + + public void onDisable() { + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(BukkitMain.getServerType(), BukkitMain.getServerID()) + .type(PacketType.BUKKIT_SEND_INFO).field("bukkit-server-turn-off")); + + CommonsGeneral.getMySQL().closeConnection(); + + if (Server.getInstance() != null) { + try { + Server.getInstance().getServerGeneral().disconnect(); + } catch (IOException e) { + } + } + } + + public void initialize() { + getServer().getScheduler().runTaskTimer(getInstance(), () -> { + ServerStatusUpdateEvent event = new ServerStatusUpdateEvent(getServer().getOnlinePlayers().size(), true); + + getServer().getPluginManager().callEvent(event); + }, 0, 20L * getServerType().getSecondsUpdateStatus()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.java new file mode 100644 index 0000000..2d202fd --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.java @@ -0,0 +1,180 @@ +package com.br.guilhermematthew.nowly.commons.bukkit; + +public class BukkitMessages { + + public static final String + + SEU_TEMPO_DE_GRUPO_EXPIROU = "§cO rank %s §cque você possuia teve seu tempo esgotado!", + VOCE_DESATIVOU_A_VISIBILIDADE_DOS_JOGADORES = "§cVocê desativou a opção de visibilidade dos jogadores.", + VOCE_ATIVOU_A_VISIBILIDADE_DOS_JOGADORES = "§aVocê ativou a opção de visibilidade dos jogadores.", + VOCE_ESTA_TENTANDO_EXECUTAR_COMANDOS_MUITO_RAPIDO = "§cVocê está tentando executar comandos muito rápido!", + CONNECTING = "§aConectando...", + SEU_SLOT_FOI_DADO_A_UM_JOGADOR_VIP = "§cO slot que você possuia foi liberado para um jogador VIP!", + DEATH_MESSAGE_XP = "§c-%quantia% XP", + KILL_MESSAGE_XP = "§a+%quantia% XP", + KILL_MESSAGE_COINS = "§a+%quantia% coins", + DEATH_MESSAGE_COINS = "§c-%quantia% coins", + + ACABOU_OS_SLOTS_PARA_MEMBROS = "§cO servidor está lotado!", + + //PREFERENCES + CLAN_TAG_DISPLAY_ATIVADO = "§aAgora a TAG do seu Clan irá aparecer.", + CLAN_TAG_DISPLAY_DESATIVADO = "§cAgora a TAG do seu Clan não irá aparecer.", + + RANKS_PREFIX = "§eOs ranks são ligas ou patentes que Você pode upar ganhando XPs jogando, matando jogadores e ganhando partidas.", + + SUAS_MEDALHAS = "§aSuas medalhas: ", + TIROU_MEDALHA = "§cVocê removeu sua medalha.", + MEDALHA_SELECIONADA = "§aVocê selecionou a medalha %medalha%§a com sucesso.", + NAO_POSSUI_MEDALHA = "§cVocê não possui a medalha citada.", + + + //TAGS START + + SUAS_TAGS = "§aSuas tags:", + VOCE_JA_ESTA_USANDO_ESTA_TAG = "§cVocê já está utilizando está tag.", + TAG_SELECIONADA = "§aVocê está utilizando a tag %tag%", + NAO_POSSUI_TAG = "§cVocê não possui esta TAG.", + VOCE_NAO_PODE_TROCAR_A_TAG = "§cVocê não pode trocar sua tag.", + + //TAGS END + + //LEAGUE START + + PLAYER_SUBIU_DE_LIGA = "§aParabéns! O jogador %nick% alcançou uma nova liga. Ela é %liga%", + VOCE_SUBIU_DE_LIGA = "§aParabéns, Você subiu de liga! continue jogando e aprimorando suas habilidades.", + + //LEAGUE END + + VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO = "§cVocê não possui permissão para utilizar este comando.", + THE_SERVER_IS_LOADING = "§cO servidor ainda não carregou.", + THE_SERVER_NOT_RECEIVED_PLAYER_DATA = "§cA sala %s §cnão possui recebimentos de dados do mesmo.", + THE_SERVER_WITH_WHITELIST = "§cEsta sala atualmente está liberada somente para equipe.", + + STOP_PREFIX = "§cFechando servidor...", + STOP_SENDING_PLAYERS_TO_LOBBY = "§aTentando enviar todos os jogadores locais para o Lobby.", + PLAYER_SERVER_RESTARTING = "§cO Servidor atual irá reiniciar, Você será movido automaticamente para o Lobby.", + + //FAKE START + + FAKE_LIST_PREFIX = "§c", + FAKE_LIST_LINHA = "§f- §e%nickFake% §f(§7%nickReal%§f)", + FAKE_HELP = "§cUtilize o comando: /fake (nick/random/#/list)", + NAO_ESTA_USANDO_FAKE = "§cVocê não está utilizando um Fake.", + NAO_PODE_TIRAR_FAKE = "§cVocê não pode %action% o fake agora.", + TIROU_FAKE = "§aFake removido com sucesso!", + NENHUM_FAKE_RANDOM = "§cNenhum fake disponivel.", + FAKE_INDISPONIVEL = "§cEste nick está associado a uma conta original.", + FAKE_SUCESSO = "§aVocê alterou seu nick para: §e§l%nick%", + NENHUM_JOGADOR_COM_FAKE = "§eNenhum jogador está utilizado fake!", + VOCE_ENTROU_NO_SERVIDOR_COM_O_FAKE = "§aVocê entrou no servidor utilizando fake!", + + //FAKE END; + + COOLDOWN_MESSAGE = "§cAguarde %tempo% para usar novamente.", + + //CHAT + CHAT_COOLDOWN = "§cAguarde para digitar no chat novamente.", + CHAT_ESTA_DESATIVADO = "§cO chat está desativado.", + CHAT_DESATIVADO = "§cO chat foi desativado.", + CHAT_ATIVADO = "§aO chat foi ativado.", + CHAT_LIMPO = "§aO chat foi limpo.", + COMANDO_BLOQUEADO = "§cEste comando está bloqueado em nosso servidor.", + COMANDO_INEXISTENTE = "§cEste comando não existe.", + + SYNC_TPALL_RUNNING = "§cJá existe um SyncTpall em andamento.", + SYNC_TPALL_FINALIZED = "§aSyncTpall terminado!", + TPALL = "§aTodos os jogadores foram teletransportado!", + + BROADCAST_USAGE = "§cPara enviar um anúncio no seu servidor utilize: /bc (mensagem)", + BROADCAST_PREFIX = "§2§lLEAGUE §8» §f", + + CLEAR_DROPS = "§cForam removidos %quantia% itens do chão.", + KILL_MOBS = "§cForam removidos %quantia% mobs.", + + DANO_ATIVADO = "§aO DANO foi ativado!", + DANO_DESATIVADO = "§cO DANO foi desativado!", + + PVP_ATIVADO = "§aO PVP foi ativado!", + PVP_DESATIVADO = "§cO PVP foi desativado", + + JOGADOR_OFFLINE = "§cJogador offline!", + + FLY_ATIVADO = "§aO modo voar foi ativado.", + FLY_DESATIVADO = "§cO modo voar foi desativado.", + + FLY_ATIVADO_PARA = "§eO modo voar foi ativado para §b%nick%", + FLY_DESATIVADO_PARA = "§eO modo voar foi desativado para §b%nick%", + + INVSEE = "§cUtilize: /invsee ", + INVSEE_SUCESSO = "§aVocê abriu o inventário de %nick%", + VOCE_NAO_PODE_ABRIR_SEU_INVENTARIO = "§cVocê não pode abrir o seu próprio inventário.", + + SEU_PING = "§eSeu ping atual é: §b%quantia% ms", + PING_OUTRO = "§eO ping do player %nick%§f é de: §b%quantia% ms", + + GAMEMODE_CHANGE_FOR_SENDER = "§eVocê alterou o modo de jogo do(a) jogador(a) %nick% §apara o modo %gamemode%", + VOCE_JA_ESTA_NESSE_GAMEMODE = "§cVocê ja está nesse modo de jogo!", + GAMEMODE_CHANGED = "§aSeu modo de jogo foi alterado para %gamemode%", + + TELEPORT_USAGE = + "§cUtilize: /tp \n" + + "§cUtilize: /tp \n" + + "§cUtilize: /tp \n" + + "§cUtilize: /tp ", + + TELEPORTED_TO_PLAYER = "§aVocê foi teleportado para §7§l%nick% §acom sucesso!", + TELEPORTED_PLAYER_TO_PLAYER = "§cVocê teleportou §7%nick% §apara o §7%nick1%", + TELEPORTED_TO_LOCATION = "§aVocê se teleportou para §7%coords%", + TELEPORTED_PLAYER_TO_LOCATION = "§aVocê teleportou o §7%nick% §apara §7%coords%", + + //SKIN START + + SKIN_USAGE = "§cUtilize: /skin ", + SKIN_MUDADA = "§aSua skin foi alterada com sucesso!", + SKIN_ATUALIZADA = "§aSua skin foi atualizada com sucesso!", + + ERROR_ON_UPDATE_SKIN = "§cOcorreu um erro ao tentar atualizar sua skin!", + ERROR_ON_CHANGE_SKIN = "§cOcorreu um erro ao tentar trocar sua skin!", + + SKIN_AGUARDE_PARA_TROCAR = "§cAguarde para trocar de skin novamente!", + SKIN_DOWNLOADING = "§aSkin sendo baixada, aguarde...", + VOCE_NAO_PODE_TROCAR_SUA_SKIN_AGORA = "§cVocê não pode trocar sua skin agora!", + //SKIN END; + + //TELL AND REPLY START + + TELL_SPY = "§f[SPY] §8Mensagem de §6%nick% §8para §6%nick1%§8: §f%mensagem%", + + COMMAND_REPLY_USAGE = "§cUtilize: /r ", + VOCE_NAO_TEM_NENHUMA_CONVERSA_PARA_RESPONDER = "§cVocê não tem nenhuma conversa para responder.", + + COMMAND_TELL_USAGE = "\n" + + "§cUtilize: /tell \n" + + "§cUtilize: /tell \n", + + TELL_PARA_JOGADOR = "§8Mensagem para §6%nick%: §f%mensagem%", + TELL_DE_JOGADOR = "§8Mensagem para §6%nick%: §f%mensagem%", + + TELL_JA_ESTA_ATIVADO = "§aSuas mensagens privadas já estão ativas.", + TELL_JA_ESTA_DESATIVADO = "§cSuas mensagens privadas já estão desativadas.", + TELL_ATIVADO = "§aAgora você poderá receber mensagens privadas.", + TELL_DESATIVADO = "§cVocê desativou o recebimento de mensagens privadas.", + VOCE_NAO_PODE_ENVIAR_MENSAGEM_PARA_VOCE_MESMO = "§cVocê não pode enviar mensagem para si mesmo.", + JOGADOR_COM_TELL_DESATIVADO = "§cO jogador não pode receber mensagens privadas.", + //TELL AND REPLY END + + NAO_TEM_CONTA = "§cO nickname citado não possuí um registro na rede.", + + //ADMIN START + + ADMIN_CANCELADO = "§cVocê não pode sair e/ou entrar no modo admin agora.", + SAIU_DO_ADMIN = "§dVocê saiu do modo VANISH!", + ENTROU_NO_ADMIN = "§dVocê entrou no modo VANISH!\n§dAgora você está visível somente para Moderação e Superiores.", + PLAYER_SAIU_DO_ADMIN = "§c%nick% saiu do modo admin!", + PLAYER_ENTROU_NO_ADMIN = "§a%nick% entrou no modo admin", + PLAYER_FICOU_VISIVEL = "§aVocê está visível para todos os jogadores.", + PLAYER_FICOU_INVISIVEL = "§cVocê está invisível para todos jogadores com cargo abaixo de %grupo%"; + + //ADMIN END +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.java new file mode 100644 index 0000000..c0cc1b1 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.commons.bukkit; + +import lombok.Getter; + +public class BukkitSettings { + + @Getter + public static boolean + + CHAT_OPTION = true, + PVP_OPTION = true, + DANO_OPTION = true, + DOUBLE_COINS_OPTION = false, + DOUBLE_XP_OPTION = false, + + LOGIN_OPTION = true; +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.java new file mode 100644 index 0000000..6f6617f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.java @@ -0,0 +1,143 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.account; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.permission.PlayerAttachment; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeTagEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import com.mojang.authlib.properties.Property; +import lombok.Getter; +import lombok.Setter; +import lombok.val; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +@Getter +@Setter +public class BukkitPlayer extends GamingProfile { + + private String lastMessage; + private Long lastChangeSkin; + private Property lastSkin; + private PlayerAttachment playerAttachment; + private Tag actualTag; + + public BukkitPlayer(String nick, String address, UUID uniqueId) { + super(nick, address, uniqueId); + this.lastMessage = ""; + this.lastChangeSkin = 0L; + this.actualTag = Groups.MEMBRO.getTag(); + } + + + public void addXP(final int amount) { + League actualLeague = League.getRanking(getInt(DataType.XP)), + newLeague = League.getRanking(getInt(DataType.XP) + amount); + + getData(DataType.XP).add(amount); + + if (actualLeague != newLeague) { + Player player = getPlayer(); + + Bukkit.broadcastMessage(BukkitMessages.PLAYER_SUBIU_DE_LIGA.replace("%nick%", player.getName()).replace("%liga%", newLeague.getColor() + + newLeague.getName().toUpperCase())); + + player.sendMessage(BukkitMessages.VOCE_SUBIU_DE_LIGA); + + TagManager.setTag(player, getActualTag(), this); + Bukkit.getServer().getPluginManager().callEvent(new PlayerRequestEvent(player, "update-scoreboard")); + } + } + + public void removeXP(final int amount) { + League actualLeague = League.getRanking(getInt(DataType.XP)); + + getData(DataType.XP).remove(amount); + + League newLeague = League.getRanking(getInt(DataType.XP)); + + if (actualLeague != newLeague) { + Player player = getPlayer(); + + Bukkit.getServer().getPluginManager().callEvent(new PlayerRequestEvent(player, "update-scoreboard")); + TagManager.setTag(player, getActualTag(), this); + } + } + + public void updateTag(final Player player, final Tag newTag, boolean forced) { + PlayerChangeTagEvent event = new PlayerChangeTagEvent(player, getActualTag(), newTag, forced); + + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return; + + if(actualTag != newTag) { + set(DataType.TAG, newTag.getName()); + + BukkitMain.runAsync(() -> getDataHandler().saveCategory(DataCategory.ACCOUNT)); + } + + this.actualTag = newTag; + } + + public Player getPlayer() { + return Bukkit.getPlayer(getUniqueId()); + } + + public void setLastMessage(String name) { + this.lastMessage = name; + } + + public boolean canChangeSkin() { + return getLastChangeSkin() + TimeUnit.SECONDS.toMillis(40) < System.currentTimeMillis(); + } + + public void injectPermissions(Player player) { + if (playerAttachment == null) playerAttachment = new PlayerAttachment(player, BukkitMain.getInstance()); + + playerAttachment.removePermissions(playerAttachment.getPermissions()); + playerAttachment.addPermissions(getGroup().getPermissions()); + + val permissions = getData(DataType.PERMISSIONS).getList(); + playerAttachment.addPermissions(permissions); + } + + public void validateGroups() { + Long groupTime = getLong(DataType.GROUP_TIME); + + if (groupTime != 0L) { + if (System.currentTimeMillis() > groupTime) { + getData(DataType.GROUP_TIME).setValue(0L); + getData(DataType.GROUP).setValue("Membro"); + getData(DataType.GROUP_CHANGED_BY).setValue("Console"); + + Groups groupExpired = getGroup(); + + if (getString(DataType.FAKE).isEmpty()) { + setActualTag(getGroup().getTag()); + TagManager.setTag(getPlayer(), getGroup()); + } else { + setActualTag(Groups.MEMBRO.getTag()); + TagManager.setTag(getPlayer(), Groups.MEMBRO); + } + + Player player = getPlayer(); + player.sendMessage(String.format(BukkitMessages.SEU_TEMPO_DE_GRUPO_EXPIROU, groupExpired.getColor() + groupExpired.getName())); + + injectPermissions(player); + + BukkitMain.runAsync(() -> getDataHandler().saveCategory(DataCategory.ACCOUNT)); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.java new file mode 100644 index 0000000..32c1e51 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.account.permission; + +import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.plugin.Plugin; + +import java.util.ArrayList; +import java.util.List; + +public class PlayerAttachment { + + private final PermissionAttachment attachment; + + public PlayerAttachment(Player player, Plugin plugin) { + this.attachment = player.addAttachment(plugin); + } + + public void addPermission(String permission) { + this.attachment.setPermission(permission, true); + } + + public void addPermissions(List permissions) { + if (permissions == null) { + return; + } + + for (String permission : permissions) { + this.attachment.setPermission(permission, true); + } + } + + public void removePermissions(List permissions) { + if (permissions == null) return; + + for (String permission : permissions) this.attachment.setPermission(permission, false); + } + + public void resetPermissions() { + if (getPermissions().size() != 0) { + for (String permissions : getPermissions()) { + this.attachment.setPermission(permissions, false); + } + } + } + + public void removePermission(String permission) { + this.attachment.setPermission(permission, false); + } + + public List getPermissions() { + return new ArrayList<>(attachment.getPermissions().keySet()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.java new file mode 100644 index 0000000..ac24164 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.java @@ -0,0 +1,149 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class BukkitServerAPI { + + @Getter + private static boolean registeredServer = false; + + public static void registerServer() { + registeredServer = true; + + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(BukkitMain.getServerType(), BukkitMain.getServerID()). + type(PacketType.BUKKIT_SEND_INFO). + field("bukkit-register-server"). + fieldValue(Bukkit.getServer().getIp()). + extraValue("" + Bukkit.getServer().getPort())); + } + + public static void redirectPlayer(final Player player, final String server) { + redirectPlayer(player, server, false); + } + + public static boolean checkItem(ItemStack item, String display) { + return (item != null && item.getType() != Material.AIR && item.hasItemMeta() && item.getItemMeta().hasDisplayName() + && item.getItemMeta().getDisplayName().startsWith(display)); + } + + @SuppressWarnings("UnstableApiUsage") + public static void redirectPlayer(final Player player, final String server, final boolean kick) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Connect"); + out.writeUTF(server); + + player.sendPluginMessage(BukkitMain.getInstance(), "BungeeCord", out.toByteArray()); + + player.sendMessage(BukkitMessages.CONNECTING); + + if (kick) { + BukkitMain.runLater(() -> { + if (player.isOnline()) { + if (server.equalsIgnoreCase("LobbyPvP") || (server.equalsIgnoreCase("LobbyHardcoreGames"))) { + player.sendMessage("§cOcorreu um erro ao tentar conectar-se ao Servidor: §7" + server); + redirectPlayer(player, "Lobby", true); + } else { + player.kickPlayer("§cOcorreu um erro ao tentar conectar-se ao servidor: " + server); + } + } + }, 40); + } + } + + @SuppressWarnings("unchecked") + public static void unregisterCommands(String... commands) { + try { + Field firstField = Bukkit.getServer().getClass().getDeclaredField("commandMap"); + firstField.setAccessible(true); + CommandMap commandMap = (CommandMap) firstField.get(Bukkit.getServer()); + Field secondField = commandMap.getClass().getDeclaredField("knownCommands"); + secondField.setAccessible(true); + HashMap knownCommands = (HashMap) secondField.get(commandMap); + for (String command : commands) { + if (knownCommands.containsKey(command)) { + knownCommands.remove(command); + List aliases = new ArrayList<>(); + for (String key : knownCommands.keySet()) { + if (!key.contains(":")) + continue; + + String substr = key.substring(key.indexOf(":") + 1); + if (substr.equalsIgnoreCase(command)) { + aliases.add(key); + } + } + for (String alias : aliases) { + knownCommands.remove(alias); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void removePlayerFile(UUID uuid) { + World world = Bukkit.getWorlds().get(0); + File folder = new File(world.getWorldFolder(), "playerdata"); + + if (folder.exists() && folder.isDirectory()) { + File file = new File(folder, uuid.toString() + ".dat"); + Bukkit.getScheduler().runTaskLaterAsynchronously(BukkitMain.getInstance(), () -> { + if (file.exists() && !file.delete()) { + removePlayerFile(uuid); + } + }, 2L); + } + } + + public static void warnStaff(String message, Groups tag) { + for (GamingProfile profiles : CommonsGeneral.getProfileManager().getGamingProfiles()) { + if (profiles.getGroup().getLevel() >= tag.getLevel()) { + Player target = Bukkit.getPlayer(profiles.getUniqueId()); + + if (target != null) target.sendMessage(message); + } + } + } + + public static Player getExactPlayerByNick(String nick) { + Player finded = null; + + for (GamingProfile profiles : CommonsGeneral.getProfileManager().getGamingProfiles()) { + if (profiles.getNick().equalsIgnoreCase(nick)) { + finded = Bukkit.getPlayer(profiles.getUniqueId()); + break; + } + } + + return finded; + } + + public static String getRealNick(Player target) { + return CommonsGeneral.getProfileManager().getGamingProfile(target.getUniqueId()).getNick(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.java new file mode 100644 index 0000000..af4afd6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.java @@ -0,0 +1,23 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.actionbar; + +import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; +import net.minecraft.server.v1_8_R3.PacketPlayOutChat; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class ActionBarAPI { + + public static void send(final Player player, final String message) { + PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a("{\"text\": \"" + message + "\"}"), (byte) 2); + + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + public static void broadcast(final String message) { + PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a("{\"text\": \"" + message + "\"}"), (byte) 2); + + for (Player onlines : Bukkit.getOnlinePlayers()) + ((CraftPlayer) onlines).getHandle().playerConnection.sendPacket(packet); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.java new file mode 100644 index 0000000..c5b552b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.java @@ -0,0 +1,82 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.bossbar; + +import lombok.Getter; +import lombok.Setter; +import net.minecraft.server.v1_8_R3.EntityWither; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; +import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +@Getter +@Setter +public class BossBar { + + private Player player; + private EntityWither wither; + private boolean cancelar, tempo; + private int segundos; + + public BossBar(final Player player, final String message, final boolean tempo) { + setPlayer(player); + setCancelar(false); + setTempo(tempo); + setSegundos(20); + + setWither(new EntityWither(((CraftWorld) player.getWorld()).getHandle())); + + getWither().setInvisible(true); + getWither().setCustomName(message); + getWither().getEffects().clear(); + getWither().setLocation(getViableLocation().getX(), getViableLocation().getY(), getViableLocation().getZ(), 0, 0); + + ((CraftPlayer) getPlayer()).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntityLiving(getWither())); + } + + public void onSecond() { + if (isCancelar()) { + destroy(); + return; + } + + if (!getPlayer().isOnline()) { + setCancelar(true); + return; + } + + if (!isTempo()) { + update(); + return; + } + + if (getSegundos() == 0) { + destroy(); + setCancelar(true); + return; + } + + segundos--; + update(); + } + + public void update() { + if (wither == null || player == null) return; + + wither.setLocation(getViableLocation().getX(), getViableLocation().getY(), getViableLocation().getZ(), 0, 0); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(wither)); + } + + public Location getViableLocation() { + if (player == null) + return new Location(Bukkit.getWorld("world"), 0, 0, 0); + return player.getEyeLocation().add(player.getEyeLocation().getDirection().multiply(28)); + } + + public void destroy() { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(wither.getId())); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.java new file mode 100644 index 0000000..20b54ad --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.java @@ -0,0 +1,114 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.bossbar; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class BossBarAPI { + + private static final HashMap bossBars = new HashMap<>(); + private static boolean initialized = false; + + private static void init() { + if (initialized) return; + + initialized = true; + + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + if (getBossBars().containsKey(event.getPlayer().getUniqueId())) { + getBossBars().get(event.getPlayer().getUniqueId()).destroy(); + getBossBars().remove(event.getPlayer().getUniqueId()); + } + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) { + if (getBossBars().containsKey(event.getEntity().getUniqueId())) { + getBossBars().get(event.getEntity().getUniqueId()).destroy(); + getBossBars().remove(event.getEntity().getUniqueId()); + } + + if (event.getEntity().getKiller() != null) { + if (getBossBars().containsKey(event.getEntity().getKiller().getUniqueId())) { + getBossBars().get(event.getEntity().getKiller().getUniqueId()).destroy(); + getBossBars().remove(event.getEntity().getKiller().getUniqueId()); + } + } + } + + @EventHandler + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + if (bossBars.size() > 0) { + List toRemove = new ArrayList<>(); + + for (BossBar boss : bossBars.values()) { + if (boss.isCancelar()) { + boss.destroy(); + toRemove.add(boss.getPlayer().getUniqueId()); + } else { + boss.onSecond(); + } + } + + toRemove.forEach(uuids -> bossBars.remove(uuids)); + + toRemove.clear(); + toRemove = null; + } + } + + }, BukkitMain.getInstance()); + } + + public static void send(Player player, String name, int tempo) { + if (!initialized) { + init(); + send(player, name, tempo); + return; + } + + if (getBossBars().containsKey(player.getUniqueId())) { + getBossBars().get(player.getUniqueId()).destroy(); + } + + BossBar bossBar = new BossBar(player, name, true); + bossBar.setSegundos(tempo); + + getBossBars().put(player.getUniqueId(), bossBar); + } + + public static void send(Player player, String name) { + if (!initialized) { + init(); + send(player, name); + return; + } + + if (getBossBars().containsKey(player.getUniqueId())) { + getBossBars().get(player.getUniqueId()).destroy(); + } + + BossBar bossBar = new BossBar(player, name, false); + getBossBars().put(player.getUniqueId(), bossBar); + } + + public static HashMap getBossBars() { + return bossBars; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.java new file mode 100644 index 0000000..cbc490a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.java @@ -0,0 +1,139 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.actionbar.ActionBarAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.types.Cooldown; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class CooldownAPI { + + private static final Map> map = new ConcurrentHashMap<>(); + private static boolean registred = false; + + private static void registerListener() { + if (registred) return; + + registred = true; + + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.TICK) return; + if (event.getCurrentTick() % 2 > 0) return; + + for (UUID uuid : map.keySet()) { + Player player = Bukkit.getPlayer(uuid); + + if (player != null) { + List list = map.get(uuid); + Iterator it = list.iterator(); + + Cooldown found = null; + while (it.hasNext()) { + Cooldown cooldown = it.next(); + if (!cooldown.expired()) { + found = cooldown; + continue; + } + it.remove(); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1F, 1F); + } + + if (found != null && found.isBarAPI()) { + display(player, found); + } else if (list.isEmpty()) { + ActionBarAPI.send(player, ""); + map.remove(uuid); + } + } + } + } + }, BukkitMain.getInstance()); + } + + private static void display(Player player, Cooldown cooldown) { + StringBuilder bar = new StringBuilder(); + double percentage = cooldown.getPercentage(); + double remaining = cooldown.getRemaining(); + double count = 20 - Math.max(percentage > 0D ? 1 : 0, percentage / 5); + + for (int a = 0; a < count; a++) + bar.append("§a" + ":"); + + for (int a = 0; a < 20 - count; a++) + bar.append("§c" + ":"); + + String name = cooldown.getName(); + + ActionBarAPI.send(player, name + " " + bar + "§f " + String.format(Locale.US, "%.1fs", remaining)); + } + + @SuppressWarnings("unused") + public static void removeAllCooldowns(Player player) { + if (map.containsKey(player.getUniqueId())) { + List list = map.get(player.getUniqueId()); + Iterator it = list.iterator(); + while (it.hasNext()) { + Cooldown cooldown = it.next(); + it.remove(); + } + } + } + + public static void sendMessage(Player player, String name) { + if (map.containsKey(player.getUniqueId())) { + List list = map.get(player.getUniqueId()); + for (Cooldown cooldown : list) + if (cooldown.getName().equals(name)) { + player.sendMessage(BukkitMessages.COOLDOWN_MESSAGE.replace("%tempo%", StringUtility.toMillis(cooldown.getRemaining()))); + } + } + } + + public static void addCooldown(Player player, Cooldown cooldown) { + if (!registred) { + registerListener(); + } + + List list = map.computeIfAbsent(player.getUniqueId(), v -> new ArrayList<>()); + list.add(cooldown); + } + + public static boolean removeCooldown(Player player, String name) { + if (map.containsKey(player.getUniqueId())) { + List list = map.get(player.getUniqueId()); + Iterator it = list.iterator(); + while (it.hasNext()) { + Cooldown cooldown = it.next(); + if (cooldown.getName().equals(name)) { + it.remove(); + return true; + } + } + } + return false; + } + + public static boolean hasCooldown(Player player, String name) { + if (map.containsKey(player.getUniqueId())) { + List list = map.get(player.getUniqueId()); + for (Cooldown cooldown : list) + if (cooldown.getName().equals(name)) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.java new file mode 100644 index 0000000..9c846bc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.java @@ -0,0 +1,38 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.types; + +import lombok.Getter; + +import java.util.concurrent.TimeUnit; + +public class Cooldown { + + @Getter + private final String name; + + @Getter + private final Long duration; + private final long startTime = System.currentTimeMillis(); + + @Getter + private final boolean barAPI; + + public Cooldown(final String name, final Long duration, final boolean barAPI) { + this.name = name; + this.duration = duration; + + this.barAPI = barAPI; + } + + public double getPercentage() { + return (getRemaining() * 100) / duration; + } + + public double getRemaining() { + long endTime = startTime + TimeUnit.SECONDS.toMillis(duration); + return (-(System.currentTimeMillis() - endTime)) / 1000D; + } + + public boolean expired() { + return getRemaining() < 0D; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.java new file mode 100644 index 0000000..8de5b90 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.java @@ -0,0 +1,207 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.fake; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import lombok.val; +import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction; +import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +public class FakeAPI { + + public static void changePlayerName(Player player, String name) { + changePlayerName(player, name, true); + } + + public static void changePlayerName(Player player, String name, boolean respawn) { + Collection players = player.getWorld().getPlayers(); + EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + GameProfile playerProfile = entityPlayer.getProfile(); + + if (respawn) { + removeFromTab(player, players); + } + + try { + Field field = playerProfile.getClass().getDeclaredField("name"); + field.setAccessible(true); + field.set(playerProfile, name); + field.setAccessible(false); + entityPlayer.getClass().getDeclaredField("displayName").set(entityPlayer, name); + } catch (Exception e) { + e.printStackTrace(); + } + + if (respawn) respawnPlayer(player); + } + + public static void removePlayerSkin(Player player) { + removePlayerSkin(player, true); + } + + public static void removePlayerSkin(Player player, boolean respawn) { + EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + GameProfile playerProfile = entityPlayer.getProfile(); + playerProfile.getProperties().removeAll("textures"); + + if (respawn) { + respawnPlayer(player); + } + } + + public static void changePlayerSkin(Player player, String skinValue, String skinSignature) { + changePlayerSkin(player, skinValue, skinSignature, true); + } + + public static void changePlayerSkin(Player player, String skinValue, String skinSignature, boolean respawn) { + BukkitPlayer bPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + bPlayer.setLastSkin(new Property("textures", skinValue, skinSignature)); + + if (respawn) respawnPlayer(player); + } + + public static void removeFromTab(Player player, Collection players) { + PacketPlayOutPlayerInfo removePlayerInfo = + new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) player).getHandle()); + + for (Player online : players) { + if (online.canSee(player)) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(removePlayerInfo); + } + } + } + + @SuppressWarnings("deprecation") + public static void respawnPlayer(Player p) { + try { + if (!p.isOnline()) return; + + CraftPlayer cp = (CraftPlayer) p; + EntityPlayer ep = cp.getHandle(); + int entId = ep.getId(); + Location l = p.getLocation(); + + val textures = BukkitMain.getBukkitPlayer(p.getUniqueId()).getLastSkin(); + if (textures != null) { + ep.getProfile().getProperties().removeAll(textures.getName()); + ep.getProfile().getProperties().put(textures.getName(), textures); + } + + val actualPing = ep.ping; + + PacketPlayOutPlayerInfo removeInfo = + new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ep); + + PacketPlayOutEntityDestroy removeEntity = + new PacketPlayOutEntityDestroy(entId); + + PacketPlayOutNamedEntitySpawn addNamed = + new PacketPlayOutNamedEntitySpawn(ep); + + PacketPlayOutPlayerInfo addInfo = + new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ep); + + PacketPlayOutRespawn respawn = new PacketPlayOutRespawn(((WorldServer) ep.getWorld()).dimension, + ep.world.getDifficulty(), ep.getWorld().worldData.getType(), EnumGamemode.getById(p.getGameMode().getValue())); + + PacketPlayOutPosition pos = + new PacketPlayOutPosition(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch(), new HashSet<>()); + + PacketPlayOutEntityEquipment itemhand = + new PacketPlayOutEntityEquipment(entId, 0, CraftItemStack.asNMSCopy(p.getItemInHand())); + + PacketPlayOutEntityEquipment helmet = + new PacketPlayOutEntityEquipment(entId, 4, CraftItemStack.asNMSCopy(p.getInventory().getHelmet())); + + PacketPlayOutEntityEquipment chestplate = + new PacketPlayOutEntityEquipment(entId, 3, CraftItemStack.asNMSCopy(p.getInventory().getChestplate())); + + PacketPlayOutEntityEquipment leggings = + new PacketPlayOutEntityEquipment(entId, 2, CraftItemStack.asNMSCopy(p.getInventory().getLeggings())); + + PacketPlayOutEntityEquipment boots = + new PacketPlayOutEntityEquipment(entId, 1, CraftItemStack.asNMSCopy(p.getInventory().getBoots())); + + PacketPlayOutHeldItemSlot slot = + new PacketPlayOutHeldItemSlot(p.getInventory().getHeldItemSlot()); + + List toUpdate = new ArrayList<>(); + + for (Player pOnline : Bukkit.getServer().getOnlinePlayers()) { + CraftPlayer craftOnline = (CraftPlayer) pOnline; + PlayerConnection con = craftOnline.getHandle().playerConnection; + + if (pOnline.equals(p)) { + con.sendPacket(removeInfo); + con.sendPacket(addInfo); + con.sendPacket(respawn); + con.sendPacket(pos); + con.sendPacket(slot); + + craftOnline.updateScaledHealth(); + craftOnline.getHandle().triggerHealthUpdate(); + craftOnline.updateInventory(); + + if (pOnline.isOp()) { + pOnline.setOp(false); + pOnline.setOp(true); + } + } else if ((pOnline.canSee(p)) && (pOnline.getWorld().equals(p.getWorld()))) { + con.sendPacket(removeEntity); + con.sendPacket(removeInfo); + con.sendPacket(addInfo); + con.sendPacket(addNamed); + con.sendPacket(itemhand); + con.sendPacket(helmet); + con.sendPacket(chestplate); + con.sendPacket(leggings); + con.sendPacket(boots); + + pOnline.hidePlayer(p); + toUpdate.add(pOnline); + } else { + con.sendPacket(removeInfo); + con.sendPacket(addInfo); + } + } + + BukkitMain.runLater(() -> { + if (!p.isOnline()) { + return; + } + + toUpdate.forEach(players -> players.showPlayer(p)); + }, 10); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void addToTab(Player player, Collection players) { + PacketPlayOutPlayerInfo addPlayerInfo = + new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ((CraftPlayer) player).getHandle()); + + PacketPlayOutPlayerInfo updatePlayerInfo = + new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, ((CraftPlayer) player).getHandle()); + + for (Player online : players) { + if (online.canSee(player)) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(addPlayerInfo); + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(updatePlayerInfo); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.java new file mode 100644 index 0000000..ab6a712 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.java @@ -0,0 +1,632 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.ClassBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.NMSClass; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.Reflection; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.DataWatcher; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; +import com.br.guilhermematthew.nowly.commons.bukkit.api.protocol.ProtocolGetter; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; + +abstract class CraftHologram implements Hologram { + + static final FieldResolver PacketPlayOutSpawnEntityLivingFieldResolver = new FieldResolver(NMSClass.PacketPlayOutSpawnEntityLiving); + + protected int[] hologramIDs; + protected int[] touchIDs; + + protected boolean packetsBuilt; + + /*** + * Packets + ***/ + /* Hologram */ + protected Object spawnPacketArmorStand; + protected Object spawnPacketWitherSkull; + protected Object spawnPacketHorse_1_7; + protected Object spawnPacketHorse_1_8; + protected Object attachPacket; + protected Object teleportPacketArmorStand; + protected Object teleportPacketSkull; + protected Object teleportPacketHorse_1_7; + protected Object teleportPacketHorse_1_8; + protected Object destroyPacket; + protected Object ridingAttachPacket; + protected Object ridingEjectPacket; + /* Touch */ + protected Object spawnPacketTouchSlime; + protected Object spawnPacketTouchVehicle; + protected Object attachPacketTouch; + protected Object destroyPacketTouch; + protected Object teleportPacketTouchSlime; + protected Object teleportPacketTouchVehicle; + + /*** + * DataWatchers + ***/ + /* Hologram */ + protected Object dataWatcherArmorStand; + protected Object dataWatcherWitherSkull; + protected Object dataWatcherHorse_1_7; + protected Object dataWatcherHorse_1_8; + /* Touch */ + protected Object dataWatcherTouchSlime; + protected Object dataWatcherTouchVehicle; + + protected boolean matchesTouchID(int id) { + if (!this.isTouchable() || this.touchIDs == null) { + return false; + } + for (int i : this.touchIDs) { + if (i == id) { + return true; + } + } + return false; + } + + protected boolean matchesHologramID(int id) { + if (!HologramAPI.packetsEnabled() || this.hologramIDs == null) { + return false; + } + for (int i : this.hologramIDs) { + if (i == id) { + return true; + } + } + return false; + } + + protected void buildPackets(boolean rebuild) throws Exception { + if (!rebuild && this.packetsBuilt) { + throw new IllegalStateException("packets already built"); + } + if (rebuild && !this.packetsBuilt) { + throw new IllegalStateException("cannot rebuild packets before building once"); + } + Object world = Reflection.getHandle(this.getLocation().getWorld()); + + /* Hologram packets */ + if (HologramAPI.is1_8 && !HologramAPI.useProtocolSupport) { + Object armorStand = ClassBuilder.buildEntityArmorStand(world, this.getLocation().add(0, HologramOffsets.ARMOR_STAND_DEFAULT, 0), this.getText()); + + ClassBuilder.setupArmorStand(armorStand); + + if (rebuild) { + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(armorStand, this.hologramIDs[0]); + } else { + this.hologramIDs = new int[]{AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(armorStand)}; + } + + this.spawnPacketArmorStand = ClassBuilder.buildArmorStandSpawnPacket(armorStand); + this.dataWatcherArmorStand = AccessUtil.setAccessible(PacketPlayOutSpawnEntityLivingFieldResolver.resolveByFirstType(NMSClass.DataWatcher)).get(this.spawnPacketArmorStand); + + this.teleportPacketArmorStand = ClassBuilder.buildTeleportPacket(this.hologramIDs[0], this.getLocation().add(0, HologramOffsets.ARMOR_STAND_DEFAULT, 0), true, false); + } else { + + // Spawn Horse + Object horse_1_7 = ClassBuilder.buildEntityHorse_1_7(world, this.getLocation().add(0, HologramOffsets.WITHER_SKULL_HORSE, 0), this.getText()); + Object horse_1_8 = ClassBuilder.buildEntityHorse_1_8(world, this.getLocation().add(0, HologramOffsets.ARMOR_STAND_PACKET, 0), this.getText()); + + // Spawn WitherSkull + Object witherSkull_1_7 = ClassBuilder.buildEntityWitherSkull(world, this.getLocation().add(0, HologramOffsets.WITHER_SKULL_HORSE, 0)); + this.dataWatcherWitherSkull = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(witherSkull_1_7); + + if (rebuild) { + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(witherSkull_1_7, this.hologramIDs[0]); + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(horse_1_7, this.hologramIDs[1]); + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(horse_1_8, this.hologramIDs[2]); + // Reset the entity count + Field entityCountField = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("entityCount")); + entityCountField.set(null, (int) entityCountField.get(null) - 3); + } else { + this.hologramIDs = new int[]{ + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(witherSkull_1_7), + // + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(horse_1_7), + // + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(horse_1_8) + }; + } + + /* Packets */ + + // 1.7 Horse + this.spawnPacketHorse_1_7 = ClassBuilder.buildHorseSpawnPacket_1_7(horse_1_7, this.getText()); + this.dataWatcherHorse_1_7 = AccessUtil.setAccessible(PacketPlayOutSpawnEntityLivingFieldResolver.resolveByFirstType(NMSClass.DataWatcher)).get(this.spawnPacketHorse_1_7); + + // Special 1.8 client packet which replaces the entity with an ArmorStand + this.spawnPacketHorse_1_8 = ClassBuilder.buildHorseSpawnPacket_1_8(horse_1_8, this.getText()); + this.dataWatcherHorse_1_8 = AccessUtil.setAccessible(PacketPlayOutSpawnEntityLivingFieldResolver.resolveByFirstType(NMSClass.DataWatcher)).get(this.spawnPacketHorse_1_8); + + // WitherSkull + this.spawnPacketWitherSkull = ClassBuilder.buildWitherSkullSpawnPacket(witherSkull_1_7); + + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + this.attachPacket = NMSClass.PacketPlayOutAttachEntity.getConstructor(int.class, NMSClass.Entity, NMSClass.Entity).newInstance(0, horse_1_7, witherSkull_1_7); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.attachPacket, this.hologramIDs[1]); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("c")).set(this.attachPacket, this.hologramIDs[0]); + } else { + this.attachPacket = NMSClass.PacketPlayOutAttachEntity.newInstance(); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("a")).set(this.attachPacket, this.hologramIDs[1]); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.attachPacket, this.hologramIDs[0]); + } + + if (!HologramAPI.is1_8 || HologramAPI.useProtocolSupport) { + this.teleportPacketSkull = ClassBuilder.buildTeleportPacket(this.hologramIDs[0], this.getLocation().add(0, HologramOffsets.WITHER_SKULL_HORSE, 0), true, false); + this.teleportPacketHorse_1_7 = ClassBuilder.buildTeleportPacket(this.hologramIDs[1], this.getLocation().add(0, HologramOffsets.WITHER_SKULL_HORSE, 0), true, false); + } + this.teleportPacketHorse_1_8 = ClassBuilder.buildTeleportPacket(this.hologramIDs[2], this.getLocation().add(0, HologramOffsets.ARMOR_STAND_PACKET, 0), true, false); + } + + /* Touch packets */ + if (this.isTouchable()) { + int size = this.getText() == null ? 1 : (this.getText().length() / 2 / 3); + Object touchSlime = ClassBuilder.buildEntitySlime(world, this.getLocation().add(0, HologramOffsets.TOUCH_SLIME_SKULL, 0), size); + this.dataWatcherTouchSlime = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(touchSlime); + + Object touchVehicle = null; + + if (HologramAPI.is1_8 && !HologramAPI.useProtocolSupport) { + touchVehicle = ClassBuilder.buildEntityArmorStand(world, this.getLocation().add(0, HologramOffsets.ARMOR_STAND_PACKET + HologramOffsets.TOUCH_SLIME_ARMOR_STAND, 0), null); + this.dataWatcherTouchVehicle = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(touchVehicle); + + ClassBuilder.setupArmorStand(touchVehicle); + } else { + touchVehicle = ClassBuilder.buildEntityWitherSkull(world, this.getLocation().add(0, HologramOffsets.TOUCH_SLIME_SKULL, 0)); + this.dataWatcherTouchVehicle = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(touchVehicle); + // ClassBuilder.setDataWatcherValue(this.dataWatcherTouchVehicle, 0, (byte) 32); + DataWatcher.setValue(this.dataWatcherTouchVehicle, 0, DataWatcher.V1_9.ValueType.ENTITY_FLAG, (byte) 32); + } + + if (rebuild) { + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(touchSlime, this.touchIDs[0]); + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).set(touchVehicle, this.touchIDs[1]); + // Reset the entity count + Field entityCountField = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("entityCount")); + entityCountField.set(null, (int) entityCountField.get(null) - 2); + } else { + this.touchIDs = new int[]{ + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(touchSlime), + // + AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("id")).getInt(touchVehicle) + }; + } + + this.spawnPacketTouchSlime = ClassBuilder.buildSlimeSpawnPacket(touchSlime); + if (HologramAPI.is1_8 && !HologramAPI.useProtocolSupport) { + this.spawnPacketTouchVehicle = ClassBuilder.buildArmorStandSpawnPacket(touchVehicle); + } else { + this.spawnPacketTouchVehicle = ClassBuilder.buildWitherSkullSpawnPacket(touchVehicle); + } + + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + this.attachPacketTouch = NMSClass.PacketPlayOutAttachEntity.getConstructor(int.class, NMSClass.Entity, NMSClass.Entity).newInstance(0, touchSlime, touchVehicle); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.attachPacketTouch, this.touchIDs[0]); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("c")).set(this.attachPacketTouch, this.touchIDs[1]); + } else { + this.attachPacketTouch = NMSClass.PacketPlayOutAttachEntity.newInstance(); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("a")).set(this.attachPacketTouch, this.touchIDs[0]); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.attachPacketTouch, this.touchIDs[1]); + } + + this.teleportPacketTouchSlime = ClassBuilder.buildTeleportPacket(this.touchIDs[0], this.getLocation().add(0, HologramOffsets.TOUCH_SLIME_SKULL, 0), true, false); + if (HologramAPI.is1_8 && !HologramAPI.useProtocolSupport) { + this.teleportPacketTouchVehicle = ClassBuilder.buildTeleportPacket(this.touchIDs[1], this.getLocation().add(0, HologramOffsets.ARMOR_STAND_PACKET + HologramOffsets.TOUCH_SLIME_ARMOR_STAND, 0), true, false); + } else { + this.teleportPacketTouchVehicle = ClassBuilder.buildTeleportPacket(this.touchIDs[1], this.getLocation().add(0, HologramOffsets.TOUCH_SLIME_SKULL, 0), true, false); + } + + if (!rebuild) { + this.destroyPacketTouch = NMSClass.PacketPlayOutEntityDestroy.getConstructor(int[].class).newInstance(this.touchIDs); + } + + } + + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + this.ridingAttachPacket = NMSClass.PacketPlayOutAttachEntity.newInstance(); + this.ridingEjectPacket = NMSClass.PacketPlayOutAttachEntity.newInstance(); + + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("a")).set(this.ridingAttachPacket, 0); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("a")).set(this.ridingEjectPacket, 0); + + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.ridingAttachPacket, this.hologramIDs[0]); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("b")).set(this.ridingEjectPacket, this.hologramIDs[0]); + + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("c")).set(this.ridingAttachPacket, this.getAttachedTo() != null ? this.getAttachedTo().getEntityId() : -1); + AccessUtil.setAccessible(NMSClass.PacketPlayOutAttachEntity.getDeclaredField("c")).set(this.ridingEjectPacket, -1); + } else { + this.ridingAttachPacket = NMSClass.PacketPlayOutMount.newInstance(); + this.ridingEjectPacket = NMSClass.PacketPlayOutMount.newInstance(); + + AccessUtil.setAccessible(NMSClass.PacketPlayOutMount.getDeclaredField("a")).set(this.ridingAttachPacket, ((DefaultHologram) this).isAttached() && this.getAttachedTo() != null ? this.getAttachedTo().getEntityId() : -1); + AccessUtil.setAccessible(NMSClass.PacketPlayOutMount.getDeclaredField("a")).set(this.ridingEjectPacket, ((DefaultHologram) this).isAttached() && this.getAttachedTo() != null ? this.getAttachedTo().getEntityId() : -1); + + AccessUtil.setAccessible(NMSClass.PacketPlayOutMount.getDeclaredField("b")).set(this.ridingAttachPacket, new int[]{this.hologramIDs[0]}); + AccessUtil.setAccessible(NMSClass.PacketPlayOutMount.getDeclaredField("b")).set(this.ridingEjectPacket, new int[0]); + } + + if (!rebuild) { + this.destroyPacket = NMSClass.PacketPlayOutEntityDestroy.getConstructor(int[].class).newInstance(this.hologramIDs); + } + } + + protected void sendSpawnPackets(final Collection receivers, final boolean holo, final boolean touch) { + if (holo) { + if (HologramAPI.is1_8 && !HologramAPI.useProtocolSupport) { + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + HologramAPI.sendPacket(p, this.spawnPacketArmorStand); + } + } else { + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + if (ProtocolGetter.getVersion(p) > 5) { + HologramAPI.sendPacket(p, this.spawnPacketHorse_1_8); + } else { + HologramAPI.sendPacket(p, this.spawnPacketHorse_1_7); + HologramAPI.sendPacket(p, this.spawnPacketWitherSkull); + HologramAPI.sendPacket(p, this.attachPacket); + } + } + } + } + if (touch && this.isTouchable()) { + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + HologramAPI.sendPacket(p, this.spawnPacketTouchSlime); + HologramAPI.sendPacket(p, this.spawnPacketTouchVehicle); + HologramAPI.sendPacket(p, this.attachPacketTouch); + } + } + if (holo || touch) { + new BukkitRunnable() { + + @Override + public void run() { + CraftHologram.this.sendTeleportPackets(receivers, holo, touch); + } + }.runTaskLater(BukkitMain.getInstance(), 1L); + } + } + + protected void sendTeleportPackets(final Collection receivers, boolean holo, boolean touch) { + if (!holo && !touch) { + return; + } + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + if (holo) { + if (!HologramAPI.is1_8 || HologramAPI.useProtocolSupport) { + if (ProtocolGetter.getVersion(p) > 5) { + HologramAPI.sendPacket(p, this.teleportPacketHorse_1_8); + } else { + HologramAPI.sendPacket(p, this.teleportPacketHorse_1_7); + HologramAPI.sendPacket(p, this.teleportPacketSkull); + } + } else { + HologramAPI.sendPacket(p, this.teleportPacketArmorStand); + } + } + if (touch && this.isTouchable()) { + HologramAPI.sendPacket(p, this.teleportPacketTouchSlime); + HologramAPI.sendPacket(p, this.teleportPacketTouchVehicle); + } + } + } + + protected void sendNamePackets(Player p) { + if (!isShown(p)) { + return; + } + + try { + int id = HologramAPI.is1_8 && !HologramAPI.useProtocolSupport ? this.hologramIDs[0] : ProtocolGetter.getVersion(p) > 5 ? this.hologramIDs[2] : this.hologramIDs[1]; + Object dataWatcher = HologramAPI.is1_8 && !HologramAPI.useProtocolSupport ? this.dataWatcherArmorStand : ProtocolGetter.getVersion(p) > 5 ? this.dataWatcherHorse_1_8 : this.dataWatcherHorse_1_7; + Object packet = ClassBuilder.buildNameMetadataPacket(id, dataWatcher, 2, 3, this.getText()); + HologramAPI.sendPacket(p, packet); + if (ProtocolGetter.getVersion(p) <= 5) { + if (this.hologramIDs.length > 1) { + HologramAPI.sendPacket(p, ClassBuilder.buildNameMetadataPacket(this.hologramIDs[1], this.dataWatcherHorse_1_7, 10, 11, this.getText())); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void sendNamePackets(final Collection receivers) { + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + try { + int id = HologramAPI.is1_8 && !HologramAPI.useProtocolSupport ? this.hologramIDs[0] : ProtocolGetter.getVersion(p) > 5 ? this.hologramIDs[2] : this.hologramIDs[1]; + Object dataWatcher = HologramAPI.is1_8 && !HologramAPI.useProtocolSupport ? this.dataWatcherArmorStand : ProtocolGetter.getVersion(p) > 5 ? this.dataWatcherHorse_1_8 : this.dataWatcherHorse_1_7; + Object packet = ClassBuilder.buildNameMetadataPacket(id, dataWatcher, 2, 3, this.getText()); + HologramAPI.sendPacket(p, packet); + if (ProtocolGetter.getVersion(p) <= 5) { + if (this.hologramIDs.length > 1) { + HologramAPI.sendPacket(p, ClassBuilder.buildNameMetadataPacket(this.hologramIDs[1], this.dataWatcherHorse_1_7, 10, 11, this.getText())); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + protected void sendDestroyPackets(Collection receivers) { + for (Player p : receivers) { + HologramAPI.sendPacket(p, this.destroyPacket); + if (this.isTouchable()) { + HologramAPI.sendPacket(p, this.destroyPacketTouch); + } + } + } + + protected void sendAttachPacket(Collection receivers) { + for (Player p : receivers) { + if (!isShown(p)) { + continue; + } + + if (!((DefaultHologram) this).isAttached()) { + HologramAPI.sendPacket(p, this.ridingEjectPacket); + } else { + HologramAPI.sendPacket(p, this.ridingAttachPacket); + } + } + } + + @Override + public abstract Location getLocation(); + + @Override + public abstract void setLocation(Location loc); + + @Override + public abstract String getText(); + + @Override + public abstract void setText(String text); + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (this.attachPacket == null ? 0 : this.attachPacket.hashCode()); + result = prime * result + (this.attachPacketTouch == null ? 0 : this.attachPacketTouch.hashCode()); + result = prime * result + (this.dataWatcherArmorStand == null ? 0 : this.dataWatcherArmorStand.hashCode()); + result = prime * result + (this.dataWatcherHorse_1_7 == null ? 0 : this.dataWatcherHorse_1_7.hashCode()); + result = prime * result + (this.dataWatcherHorse_1_8 == null ? 0 : this.dataWatcherHorse_1_8.hashCode()); + result = prime * result + (this.dataWatcherTouchSlime == null ? 0 : this.dataWatcherTouchSlime.hashCode()); + result = prime * result + (this.dataWatcherTouchVehicle == null ? 0 : this.dataWatcherTouchVehicle.hashCode()); + result = prime * result + (this.dataWatcherWitherSkull == null ? 0 : this.dataWatcherWitherSkull.hashCode()); + result = prime * result + (this.destroyPacket == null ? 0 : this.destroyPacket.hashCode()); + result = prime * result + (this.destroyPacketTouch == null ? 0 : this.destroyPacketTouch.hashCode()); + result = prime * result + Arrays.hashCode(this.hologramIDs); + result = prime * result + (this.packetsBuilt ? 1231 : 1237); + result = prime * result + (this.spawnPacketArmorStand == null ? 0 : this.spawnPacketArmorStand.hashCode()); + result = prime * result + (this.spawnPacketHorse_1_7 == null ? 0 : this.spawnPacketHorse_1_7.hashCode()); + result = prime * result + (this.spawnPacketHorse_1_8 == null ? 0 : this.spawnPacketHorse_1_8.hashCode()); + result = prime * result + (this.spawnPacketTouchSlime == null ? 0 : this.spawnPacketTouchSlime.hashCode()); + result = prime * result + (this.spawnPacketTouchVehicle == null ? 0 : this.spawnPacketTouchVehicle.hashCode()); + result = prime * result + (this.spawnPacketWitherSkull == null ? 0 : this.spawnPacketWitherSkull.hashCode()); + result = prime * result + (this.teleportPacketArmorStand == null ? 0 : this.teleportPacketArmorStand.hashCode()); + result = prime * result + (this.teleportPacketHorse_1_7 == null ? 0 : this.teleportPacketHorse_1_7.hashCode()); + result = prime * result + (this.teleportPacketHorse_1_8 == null ? 0 : this.teleportPacketHorse_1_8.hashCode()); + result = prime * result + (this.teleportPacketSkull == null ? 0 : this.teleportPacketSkull.hashCode()); + result = prime * result + (this.teleportPacketTouchSlime == null ? 0 : this.teleportPacketTouchSlime.hashCode()); + result = prime * result + (this.teleportPacketTouchVehicle == null ? 0 : this.teleportPacketTouchVehicle.hashCode()); + result = prime * result + Arrays.hashCode(this.touchIDs); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + CraftHologram other = (CraftHologram) obj; + if (this.attachPacket == null) { + if (other.attachPacket != null) { + return false; + } + } else if (!this.attachPacket.equals(other.attachPacket)) { + return false; + } + if (this.attachPacketTouch == null) { + if (other.attachPacketTouch != null) { + return false; + } + } else if (!this.attachPacketTouch.equals(other.attachPacketTouch)) { + return false; + } + if (this.dataWatcherArmorStand == null) { + if (other.dataWatcherArmorStand != null) { + return false; + } + } else if (!this.dataWatcherArmorStand.equals(other.dataWatcherArmorStand)) { + return false; + } + if (this.dataWatcherHorse_1_7 == null) { + if (other.dataWatcherHorse_1_7 != null) { + return false; + } + } else if (!this.dataWatcherHorse_1_7.equals(other.dataWatcherHorse_1_7)) { + return false; + } + if (this.dataWatcherHorse_1_8 == null) { + if (other.dataWatcherHorse_1_8 != null) { + return false; + } + } else if (!this.dataWatcherHorse_1_8.equals(other.dataWatcherHorse_1_8)) { + return false; + } + if (this.dataWatcherTouchSlime == null) { + if (other.dataWatcherTouchSlime != null) { + return false; + } + } else if (!this.dataWatcherTouchSlime.equals(other.dataWatcherTouchSlime)) { + return false; + } + if (this.dataWatcherTouchVehicle == null) { + if (other.dataWatcherTouchVehicle != null) { + return false; + } + } else if (!this.dataWatcherTouchVehicle.equals(other.dataWatcherTouchVehicle)) { + return false; + } + if (this.dataWatcherWitherSkull == null) { + if (other.dataWatcherWitherSkull != null) { + return false; + } + } else if (!this.dataWatcherWitherSkull.equals(other.dataWatcherWitherSkull)) { + return false; + } + if (this.destroyPacket == null) { + if (other.destroyPacket != null) { + return false; + } + } else if (!this.destroyPacket.equals(other.destroyPacket)) { + return false; + } + if (this.destroyPacketTouch == null) { + if (other.destroyPacketTouch != null) { + return false; + } + } else if (!this.destroyPacketTouch.equals(other.destroyPacketTouch)) { + return false; + } + if (!Arrays.equals(this.hologramIDs, other.hologramIDs)) { + return false; + } + if (this.packetsBuilt != other.packetsBuilt) { + return false; + } + if (this.spawnPacketArmorStand == null) { + if (other.spawnPacketArmorStand != null) { + return false; + } + } else if (!this.spawnPacketArmorStand.equals(other.spawnPacketArmorStand)) { + return false; + } + if (this.spawnPacketHorse_1_7 == null) { + if (other.spawnPacketHorse_1_7 != null) { + return false; + } + } else if (!this.spawnPacketHorse_1_7.equals(other.spawnPacketHorse_1_7)) { + return false; + } + if (this.spawnPacketHorse_1_8 == null) { + if (other.spawnPacketHorse_1_8 != null) { + return false; + } + } else if (!this.spawnPacketHorse_1_8.equals(other.spawnPacketHorse_1_8)) { + return false; + } + if (this.spawnPacketTouchSlime == null) { + if (other.spawnPacketTouchSlime != null) { + return false; + } + } else if (!this.spawnPacketTouchSlime.equals(other.spawnPacketTouchSlime)) { + return false; + } + if (this.spawnPacketTouchVehicle == null) { + if (other.spawnPacketTouchVehicle != null) { + return false; + } + } else if (!this.spawnPacketTouchVehicle.equals(other.spawnPacketTouchVehicle)) { + return false; + } + if (this.spawnPacketWitherSkull == null) { + if (other.spawnPacketWitherSkull != null) { + return false; + } + } else if (!this.spawnPacketWitherSkull.equals(other.spawnPacketWitherSkull)) { + return false; + } + if (this.teleportPacketArmorStand == null) { + if (other.teleportPacketArmorStand != null) { + return false; + } + } else if (!this.teleportPacketArmorStand.equals(other.teleportPacketArmorStand)) { + return false; + } + if (this.teleportPacketHorse_1_7 == null) { + if (other.teleportPacketHorse_1_7 != null) { + return false; + } + } else if (!this.teleportPacketHorse_1_7.equals(other.teleportPacketHorse_1_7)) { + return false; + } + if (this.teleportPacketHorse_1_8 == null) { + if (other.teleportPacketHorse_1_8 != null) { + return false; + } + } else if (!this.teleportPacketHorse_1_8.equals(other.teleportPacketHorse_1_8)) { + return false; + } + if (this.teleportPacketSkull == null) { + if (other.teleportPacketSkull != null) { + return false; + } + } else if (!this.teleportPacketSkull.equals(other.teleportPacketSkull)) { + return false; + } + if (this.teleportPacketTouchSlime == null) { + if (other.teleportPacketTouchSlime != null) { + return false; + } + } else if (!this.teleportPacketTouchSlime.equals(other.teleportPacketTouchSlime)) { + return false; + } + if (this.teleportPacketTouchVehicle == null) { + if (other.teleportPacketTouchVehicle != null) { + return false; + } + } else if (!this.teleportPacketTouchVehicle.equals(other.teleportPacketTouchVehicle)) { + return false; + } + return Arrays.equals(this.touchIDs, other.touchIDs); + } + + @Override + public String toString() { + return "{\"hologramIDs\":\"" + Arrays.toString(this.hologramIDs) + "\",\"touchIDs\":\"" + Arrays + .toString(this.touchIDs) + "\",\"packetsBuilt\":\"" + this.packetsBuilt + "\",\"spawnPacketArmorStand\":\"" + this.spawnPacketArmorStand + "\",\"spawnPacketWitherSkull\":\"" + this.spawnPacketWitherSkull + "\",\"spawnPacketHorse_1_7\":\"" + this.spawnPacketHorse_1_7 + "\",\"spawnPacketHorse_1_8\":\"" + this.spawnPacketHorse_1_8 + "\",\"attachPacket\":\"" + this.attachPacket + + "\",\"teleportPacketArmorStand\":\"" + this.teleportPacketArmorStand + "\",\"teleportPacketSkull\":\"" + this.teleportPacketSkull + "\",\"teleportPacketHorse_1_7\":\"" + this.teleportPacketHorse_1_7 + "\",\"teleportPacketHorse_1_8\":\"" + this.teleportPacketHorse_1_8 + "\",\"destroyPacket\":\"" + this.destroyPacket + "\",\"spawnPacketTouchSlime\":\"" + this.spawnPacketTouchSlime + + "\",\"spawnPacketTouchWitherSkull\":\"" + this.spawnPacketTouchVehicle + "\",\"attachPacketTouch\":\"" + this.attachPacketTouch + "\",\"destroyPacketTouch\":\"" + this.destroyPacketTouch + "\",\"teleportPacketTouchSlime\":\"" + this.teleportPacketTouchSlime + "\",\"teleportPacketTouchWitherSkull\":\"" + this.teleportPacketTouchVehicle + "\",\"dataWatcherArmorStand\":\"" + + this.dataWatcherArmorStand + "\",\"dataWatcherWitherSkull\":\"" + this.dataWatcherWitherSkull + "\",\"dataWatcherHorse_1_7\":\"" + this.dataWatcherHorse_1_7 + "\",\"dataWatcherHorse_1_8\":\"" + this.dataWatcherHorse_1_8 + "\",\"dataWatcherTouchSlime\":\"" + this.dataWatcherTouchSlime + "\",\"dataWatcherTouchWitherSkull\":\"" + this.dataWatcherTouchVehicle + "\"}"; + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.java new file mode 100644 index 0000000..61d3318 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.java @@ -0,0 +1,489 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch.TouchHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.view.ViewHandler; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import javax.annotation.Nonnull; +import java.util.*; + +public class DefaultHologram extends CraftHologram { + + private final List touchHandlers = new ArrayList<>(); + private final List viewHandlers = new ArrayList<>(); + private Location location; + private String text, name; + private boolean touchable; + private boolean spawned; + private boolean isAttached; + private Entity attachedTo; + private Hologram lineBelow; + private Hologram lineAbove; + + private BukkitRunnable updater; + + private final HashMap showns = new HashMap<>(); + + protected DefaultHologram(String name, @Nonnull Location loc, String text) { + this.location = loc; + this.text = text; + this.name = name; + } + + @Override + public boolean isSpawned() { + return this.spawned; + } + + @Override + public void spawn(long ticks) { + if (ticks < 1) { + throw new IllegalArgumentException("ticks must be at least 1"); + } + this.spawn(); + new BukkitRunnable() { + + @Override + public void run() { + DefaultHologram.this.despawn(); + } + }.runTaskLater(BukkitMain.getInstance(), ticks); + } + + @Override + public boolean spawn() { + this.validateDespawned(); + if (!this.packetsBuilt) { + try { + this.buildPackets(false); + this.packetsBuilt = true; + } catch (Exception e) { + e.printStackTrace(); + } + } + try { + this.spawned = HologramAPI.spawn(this, this.getLocation().getWorld().getPlayers()); + } catch (Exception e) { + e.printStackTrace(); + } + return this.spawned; + } + + @Override + public boolean despawn() { + this.validateSpawned(); + try { + this.spawned = !HologramAPI.despawn(this, this.getLocation().getWorld().getPlayers()); + } catch (Exception e) { + e.printStackTrace(); + } + return !this.spawned; + } + + @Override + public Location getLocation() { + return this.location.clone(); + } + + @Override + public void setLocation(Location loc) { + this.move(loc); + } + + @Override + public String getText() { + return this.text; + } + + @Override + public void setText(String text) { + this.text = text; + + if (this.isSpawned()) { + try { + this.buildPackets(true); + } catch (Exception e) { + e.printStackTrace(); + } + this.sendNamePackets(this.getLocation().getWorld().getPlayers()); + } + } + + public void update(Player player) { + if (this.isSpawned()) { + try { + this.buildPackets(true); + } catch (Exception e) { + e.printStackTrace(); + } + this.sendNamePackets(player); + } + } + + @Override + public void update() { + this.setText(this.getText()); + } + + @Override + public void update(long interval) { + if (interval == -1) { + if (this.updater == null) { + throw new IllegalStateException("Not updating"); + } + this.updater.cancel(); + this.updater = null; + return; + } + if (this.updater != null) { + throw new IllegalStateException("Already updating"); + } + if (interval < 1) { + throw new IllegalArgumentException("Interval must be at least 1"); + } + this.updater = new BukkitRunnable() { + + @Override + public void run() { + DefaultHologram.this.update(); + } + }; + this.updater.runTaskTimer(BukkitMain.getInstance(), interval, interval); + } + + @Override + public void move(@Nonnull Location loc) { + if (loc == null) { + throw new IllegalArgumentException("location cannot be null"); + } + if (this.location.equals(loc)) { + return; + } + if (!this.location.getWorld().equals(loc.getWorld())) { + throw new IllegalArgumentException("cannot move to different world"); + } + this.location = loc; + if (this.isSpawned()) { + try { + this.buildPackets(true);// Re-build the packets since the location is now different + } catch (Exception e) { + e.printStackTrace(); + } + this.sendTeleportPackets(this.getLocation().getWorld().getPlayers(), true, true); + } + } + + @Override + public boolean isTouchable() { + return this.touchable && HologramAPI.packetsEnabled; + } + + @Override + public void setTouchable(boolean flag) { + this.validateTouchEnabled(); + if (flag == this.isTouchable()) { + return; + } + this.touchable = flag; + if (this.isSpawned()) { + try { + this.buildPackets(true); + } catch (Exception e) { + e.printStackTrace(); + } + this.sendSpawnPackets(this.getLocation().getWorld().getPlayers(), false, true); + } + } + + @Override + public void addTouchHandler(TouchHandler handler) { + this.validateTouchEnabled(); + if (!this.isTouchable()) { + throw new IllegalStateException("Hologram is not touchable"); + } + this.touchHandlers.add(handler); + } + + @Override + public void removeTouchHandler(TouchHandler handler) { + this.validateTouchEnabled(); + if (!this.isTouchable()) { + throw new IllegalStateException("Hologram is not touchable"); + } + this.touchHandlers.remove(handler); + } + + @Override + public Collection getTouchHandlers() { + return new ArrayList<>(this.touchHandlers); + } + + @Override + public void clearTouchHandlers() { + for (TouchHandler handler : this.getTouchHandlers()) { + this.removeTouchHandler(handler); + } + } + + @Override + public void addViewHandler(ViewHandler handler) { + this.validateViewsEnabled(); + this.viewHandlers.add(handler); + } + + @Override + public void removeViewHandler(ViewHandler handler) { + this.validateViewsEnabled(); + this.viewHandlers.remove(handler); + } + + @Override + public Collection getViewHandlers() { + return new ArrayList<>(this.viewHandlers); + } + + @Override + public void clearViewHandlers() { + for (ViewHandler handler : this.getViewHandlers()) { + this.removeViewHandler(handler); + } + } + + @Override + public Hologram addLineBelow(String name, String text) { + this.validateSpawned(); + Hologram hologram = HologramAPI.createHologram(name, this.getLocation().subtract(0, 0.25, 0), text); + this.lineBelow = hologram; + ((DefaultHologram) hologram).lineAbove = this; + + hologram.spawn(); + return hologram; + } + + @Override + public Hologram getLineBelow() { + this.validateSpawned(); + return this.lineBelow; + } + + @Override + public boolean removeLineBelow() { + if (this.getLineBelow() != null) { + if (this.getLineBelow().isSpawned()) { + this.getLineBelow().despawn(); + } + this.lineBelow = null; + return true; + } + return false; + } + + @Override + public Collection getLinesBelow() { + List list = new ArrayList<>(); + + Hologram current = this; + while ((current = ((DefaultHologram) current).lineBelow) != null) { + list.add(current); + } + + return list; + } + + @Override + public Hologram addLineAbove(String name, String text) { + this.validateSpawned(); + Hologram hologram = HologramAPI.createHologram(name, this.getLocation().add(0, 0.25, 0), text); + this.lineAbove = hologram; + ((DefaultHologram) hologram).lineBelow = this; + + hologram.spawn(); + return hologram; + } + + @Override + public Hologram getLineAbove() { + this.validateSpawned(); + return this.lineAbove; + } + + @Override + public boolean removeLineAbove() { + if (this.getLineAbove() != null) { + if (this.getLineAbove().isSpawned()) { + this.getLineAbove().despawn(); + } + this.lineAbove = null; + return true; + } + return false; + } + + @Override + public Collection getLinesAbove() { + List list = new ArrayList<>(); + + Hologram current = this; + while ((current = ((DefaultHologram) current).lineAbove) != null) { + list.add(current); + } + + return list; + } + + @Override + public Collection getLines() { + List list = new ArrayList<>(this.getLinesAbove()); + list.add(this); + list.addAll(this.getLinesBelow()); + return list; + } + + @Override + public Entity getAttachedTo() { + return attachedTo; + } + + @Override + public void setAttachedTo(Entity attachedTo) { + if (attachedTo == this.attachedTo) { + return; + } + setAttached(attachedTo != null); + if (attachedTo != null) { + this.attachedTo = attachedTo; + } + if (this.isSpawned()) { + try { + this.buildPackets(true); + } catch (Exception e) { + e.printStackTrace(); + } + this.sendAttachPacket(this.getLocation().getWorld().getPlayers()); + } + //Wait for the packet to send (in 1.9), since it requires the attached's entity-id + this.attachedTo = attachedTo; + } + + public boolean isAttached() { + return isAttached; + } + + public void setAttached(boolean isAttached) { + this.isAttached = isAttached; + } + + private void validateTouchEnabled() { + if (!HologramAPI.packetsEnabled()) { + throw new IllegalStateException("Touch-holograms are not enabled"); + } + } + + private void validateViewsEnabled() { + if (!HologramAPI.packetsEnabled()) { + throw new IllegalStateException("ViewHandlers are not enabled"); + } + } + + private void validateSpawned() { + if (!this.spawned) { + throw new IllegalStateException("Not spawned"); + } + } + + private void validateDespawned() { + if (this.spawned) { + throw new IllegalStateException("Already spawned"); + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.location == null ? 0 : this.location.hashCode()); + result = prime * result + (this.spawned ? 1231 : 1237); + result = prime * result + (this.text == null ? 0 : this.text.hashCode()); + result = prime * result + (this.touchHandlers == null ? 0 : this.touchHandlers.hashCode()); + result = prime * result + (this.touchable ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + DefaultHologram other = (DefaultHologram) obj; + if (this.location == null) { + if (other.location != null) { + return false; + } + } else if (!this.location.equals(other.location)) { + return false; + } + if (this.spawned != other.spawned) { + return false; + } + if (this.text == null) { + if (other.text != null) { + return false; + } + } else if (!this.text.equals(other.text)) { + return false; + } + if (this.touchHandlers == null) { + if (other.touchHandlers != null) { + return false; + } + } else if (!this.touchHandlers.equals(other.touchHandlers)) { + return false; + } + return this.touchable == other.touchable; + } + + @Override + public String toString() { + return "{\"location\":\"" + this.location + "\",\"text\":\"" + this.text + "\",\"touchable\":\"" + this.touchable + "\",\"spawned\":\"" + this.spawned + "\",\"touchHandlers\":\"" + this.touchHandlers + "\"}"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean isShown(Player player) { + if (!showns.containsKey(player.getUniqueId())) { + showns.put(player.getUniqueId(), false); + return false; + } + return showns.get(player.getUniqueId()); + } + + @Override + public void setShown(Player player, boolean valor) { + showns.put(player.getUniqueId(), valor); + } + + public void clean() { + showns.clear(); + } + + public void clean(Player player) { + showns.remove(player.getUniqueId()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.java new file mode 100644 index 0000000..a3a9d77 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.java @@ -0,0 +1,232 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch.TouchHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.view.ViewHandler; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Collection; + +public interface Hologram { + + String getName(); + + void setName(@Nullable String text); + + boolean isSpawned(); + + boolean isShown(Player player); + + /** + * Spawns the hologram and despawns it after the specified timeout + * + * @param ticks timeout + */ + void spawn(@Nonnull @Nonnegative long ticks); + + /** + * Spawns the hologram + * + * @return true if the hologram has been spawned + */ + boolean spawn(); + + /** + * Despawns the hologram + * + * @return true if the hologram has been despawned + */ + boolean despawn(); + + /** + * @return The text content of the hologram + */ + String getText(); + + /** + * @param text New text content of the hologram + */ + void setText(@Nullable String text); + + /** + * Updates the content of the hologram for player + */ + void update(Player player); + + /** + * Updates the content of the hologram + */ + void update(); + + /** + * Automatically updates the content of the hologram -1 as the interval argument will stop the update + * + * @param interval Update interval in ticks, -1 to stop updating + */ + void update(long interval); + + /** + * @return The {@link Location} of the hologram + */ + Location getLocation(); + + /** + * @param loc changes the {@link Location} of the hologram + * @see Hologram#move(Location) + */ + void setLocation(@Nonnull Location loc); + + /** + * Moves the hologram + * + * @param loc new {@link Location} of the hologram + */ + void move(@Nonnull Location loc); + + /** + * @return true if the hologram is touchable + */ + boolean isTouchable(); + + /** + * Changes the touchability + * + * @param flag true if the hologram should be touchable, + */ + void setTouchable(boolean flag); + + /** + * Adds a touch handler to the hologram + * + * @param handler {@link TouchHandler} instance + */ + void addTouchHandler(@Nonnull TouchHandler handler); + + /** + * Removes a touch handler from the hologram + * + * @param handler {@link TouchHandler} instance + */ + void removeTouchHandler(@Nonnull TouchHandler handler); + + /** + * @return a {@link Collection} of registered {@link TouchHandler}s + */ + Collection getTouchHandlers(); + + /** + * Removes all {@link TouchHandler}s from the hologram + */ + void clearTouchHandlers(); + + /** + * Adds a view handler to the hologram + * + * @param handler {@link ViewHandler} instance + */ + void addViewHandler(@Nonnull ViewHandler handler); + + /** + * Removes a view handler from the hologram + * + * @param handler {@link ViewHandler} instance + */ + void removeViewHandler(@Nonnull ViewHandler handler); + + /** + * @return a {@link Collection} of registered {@link ViewHandler}s + */ + @Nonnull + Collection getViewHandlers(); + + /** + * Removes all {@link ViewHandler}s from the hologram + */ + void clearViewHandlers(); + + /** + * Adds a {@link Hologram} line below this hologram + * + * @param text Text content of the hologram + * @return A new {@link Hologram} instance + */ + @Nonnull + Hologram addLineBelow(String name, String text); + + /** + * @return The {@link Hologram} line below this hologram + */ + @Nullable + Hologram getLineBelow(); + + /** + * Removes the line below this hologram + * + * @return true if the hologram has been removed + */ + boolean removeLineBelow(); + + /** + * @return a {@link Collection} of all below {@link Hologram} lines + */ + @Nonnull + Collection getLinesBelow(); + + /** + * Adds a {@link Hologram} line above this hologram + * + * @param text Text content of the hologram + * @return A new {@link Hologram} instance + */ + @Nonnull + Hologram addLineAbove(String name, String text); + + /** + * @return The {@link Hologram} line above this hologram + */ + @Nullable + Hologram getLineAbove(); + + /** + * Removes the line above this hologram + * + * @return true if the hologram has been removed + */ + boolean removeLineAbove(); + + /** + * @return a {@link Collection} of all above {@link Hologram} lines + */ + @Nonnull + Collection getLinesAbove(); + + /** + * @return a {@link Collection} of all below and above {@link Hologram} lines (Including this hologram) + */ + @Nonnull + Collection getLines(); + + /** + * @return The entity the hologram is attached to + */ + @Nullable + Entity getAttachedTo(); + + /** + * Attached the hologram to a entity + * + * @param entity Entity to attach the hologram to, or null to remove the attachment + */ + void setAttachedTo(@Nullable Entity entity); + + void setShown(Player player, boolean valor); + + void clean(Player player); + + void clean(); + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.java new file mode 100644 index 0000000..4b51342 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.java @@ -0,0 +1,168 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.Reflection; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnull; +import java.util.*; + +public abstract class HologramAPI { + + protected static final List holograms = new ArrayList<>(); + public static boolean packetsEnabled = false; + protected static final boolean is1_8/*Or 1.9*/ = Minecraft.VERSION.newerThan(Minecraft.Version.v1_8_R1); + protected static final boolean useProtocolSupport = true; + + //NEW + + public static Hologram createHologramAndSpawn(final String name, final Location loc, String text) { + Hologram hologram = new DefaultHologram(name, loc, text); + hologram.spawn(); + holograms.add(hologram); + return hologram; + } + + + /** + * Creates a new {@link Hologram} + * + * @param loc {@link Location} to spawn the hologram at + * @param text Initial text content of the hologram + * @return a new {@link Hologram} + */ + + public static boolean spawnSingle(@Nonnull final Hologram hologram, final Player p) throws Exception { + if (hologram == null) { + throw new IllegalArgumentException("hologram cannot be null"); + } + + if (!hologram.isShown(p)) { + hologram.setShown(p, true); + + spawn(hologram, new LinkedList<>(Collections.singletonList(p))); + } + return true; + } + + public static boolean despawnSingle(@Nonnull Hologram hologram, Player p) throws Exception { + if (hologram == null) { + throw new IllegalArgumentException("hologram cannot be null"); + } + + if (hologram.isShown(p)) { + hologram.setShown(p, false); + + ((CraftHologram) hologram).sendDestroyPackets(new LinkedList<>(Collections.singletonList(p))); + } + return true; + } + + public static Hologram createHologram(String name, Location loc, String text) { + Hologram hologram = new DefaultHologram(name, loc, text); + holograms.add(hologram); + return hologram; + } + + /** + * Removes a {@link Hologram} + * + * @param loc {@link Location} of the hologram + * @param text content of the hologram + * @return true if a hologram was found and has been removed, false otherwise + */ + public static boolean removeHologram(Location loc, String text) { + Hologram toRemove = null; + for (Hologram h : holograms) { + if (h.getLocation().equals(loc) && h.getText().equals(text)) { + toRemove = h; + break; + } + } + if (toRemove != null) { + return removeHologram(toRemove); + } + return false; + } + + /** + * Removes a {@link Hologram} + * + * @param hologram {@link Hologram} to remove + * @return true if the hologram has been removed + */ + public static boolean removeHologram(@Nonnull Hologram hologram) { + if (hologram.isSpawned()) { + hologram.despawn(); + hologram.clean(); + } + return holograms.remove(hologram); + } + + /** + * @return {@link Collection} of all registered {@link Hologram}s + */ + public static Collection getHolograms() { + return new ArrayList<>(holograms); + } + + protected static boolean spawn(@Nonnull final Hologram hologram, final Collection receivers) throws Exception { + if (hologram == null) { + throw new IllegalArgumentException("hologram cannot be null"); + } + + checkReceiverWorld(hologram, receivers); + + if (!receivers.isEmpty()) { + ((CraftHologram) hologram).sendSpawnPackets(receivers, true, true); + ((CraftHologram) hologram).sendTeleportPackets(receivers, true, true); + ((CraftHologram) hologram).sendNamePackets(receivers); + ((CraftHologram) hologram).sendAttachPacket(receivers); + } + + return true; + } + + protected static boolean despawn(@Nonnull Hologram hologram, Collection receivers) throws Exception { + if (hologram == null) { + throw new IllegalArgumentException("hologram cannot be null"); + } + if (receivers.isEmpty()) { + return false; + } + + ((CraftHologram) hologram).sendDestroyPackets(receivers); + return true; + } + + protected static void sendPacket(Player p, Object packet) { + if (p == null || packet == null) { + throw new IllegalArgumentException("player and packet cannot be null"); + } + try { + Object handle = Reflection.getHandle(p); + Object connection = Reflection.getFieldWithException(handle.getClass(), "playerConnection").get(handle); + Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, packet); + } catch (Exception e) { + } + } + + protected static Collection checkReceiverWorld(final Hologram hologram, final Collection receivers) { + for (Iterator iterator = receivers.iterator(); iterator.hasNext(); ) { + Player next = iterator.next(); + if (!next.getWorld().equals(hologram.getLocation().getWorld())) { + iterator.remove(); + } + } + return receivers; + } + + public static boolean is1_8() { + return is1_8; + } + + public static boolean packetsEnabled() { + return packetsEnabled; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.java new file mode 100644 index 0000000..36f6a40 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.java @@ -0,0 +1,246 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.NMSClass; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.DataWatcher; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch.TouchAction; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch.TouchHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.view.ViewHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.PacketObject; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListener; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListenerAPI; +import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; +import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Map; + +public class HologramInjector { + + private static final FieldResolver DataWatcherFieldResolver = new FieldResolver(NMSClass.DataWatcher); + + private static final String DELAY_TAG = "delay.hologram"; + + public static void inject(Plugin plugin) { + PacketListenerAPI.addListener(new PacketListener() { + + public void onPacketReceiving(PacketObject packetObject) { + Object packet = packetObject.getPacket(); + + if (packet instanceof PacketPlayInUseEntity) { + int id = (int) getPacketValue("a", packet); + Object useAction = getPacketValue("action", packet); + TouchAction action = TouchAction.fromUseAction(useAction); + if (action == TouchAction.UNKNOWN) { + return;// UNKNOWN means an invalid packet, so just ignore it + } + + if (hasDelay(packetObject.getPlayer())) { + packetObject.setCancelled(true); + return; + } + addDelay(packetObject.getPlayer()); + + for (Hologram h : HologramAPI.getHolograms()) { + if (((DefaultHologram) h).matchesTouchID(id)) { + for (TouchHandler t : h.getTouchHandlers()) { + t.onTouch(h, packetObject.getPlayer(), action); + } + } + } + } + } + + public void onPacketSending(PacketObject packetObject) { + Object packet = packetObject.getPacket(); + + int type = -1; + + if (packet instanceof PacketPlayOutSpawnEntityLiving) { + type = 0; + + } + if (packet instanceof PacketPlayOutEntityMetadata) { + type = 1; + } + + if (type == 0 || type == 1) { + int a = (int) getPacketValue("a", packet); + Object dataWatcher = + type == 0 ? + (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? + getPacketValue("l", packet) : getPacketValue("m", packet)) : null; + + if (dataWatcher != null) { + try { + dataWatcher = cloneDataWatcher(dataWatcher);// Clone the DataWatcher, we don't want to change the name values permanently + AccessUtil.setAccessible(Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? NMSClass.DataWatcher.getDeclaredField("a") : NMSClass.DataWatcher.getDeclaredField("b")).set(dataWatcher, null); + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + setPacketValue("l", dataWatcher, packet); + } else { + setPacketValue("m", dataWatcher, packet); + } + } catch (Exception e) { + e.printStackTrace(); + return;// Allowing further changes here would mess up the packet values + } + } + + List list = (List) (type == 1 ? getPacketValue("b", packet) : null); + int listIndex = -1; + + String text = null; + try { + if (type == 0) { + // text = (String) ClassBuilder.getWatchableObjectValue(ClassBuilder.getDataWatcherValue(dataWatcher, 2)); + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + text = (String) DataWatcher.V1_8.getWatchableObjectValue(DataWatcher.V1_8.getValue(dataWatcher, 2)); + } else { + Field dField = AccessUtil.setAccessible(NMSClass.DataWatcher.getDeclaredField("d")); + Object dValue = dField.get(dataWatcher); + if (dValue == null) { + return; + } + if (Map.class.isAssignableFrom(dValue.getClass())) { + if (((Map) dValue).isEmpty()) { + return; + } + } + text = (String) DataWatcher.V1_9.getValue(dataWatcher, DataWatcher.V1_9.ValueType.ENTITY_NAME); + } + } else if (type == 1) { + if (list != null) { + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + for (int i = 0; i < list.size(); i++) { + // int index = ClassBuilder.getWatchableObjectIndex(list.get(i)); + int index = DataWatcher.V1_8.getWatchableObjectIndex(list.get(i)); + if (index == 2) { + // if (ClassBuilder.getWatchableObjectType(list.get(i)) == 4) {//Check if it is a string + if (DataWatcher.V1_8.getWatchableObjectType(list.get(i)) == 4) {//Check if it is a string + // text = (String) ClassBuilder.getWatchableObjectValue(list.get(i)); + text = (String) DataWatcher.V1_8.getWatchableObjectValue(list.get(i)); + listIndex = i; + break; + } + } + } + } else { + if (list.size() > 2) { + if (DataWatcher.V1_9.getItemType(list.get(2)) == String.class) { + text = (String) DataWatcher.V1_9.getItemValue(list.get(2)); + listIndex = 2; + } + } + } + } + } + } catch (Exception e) { + if (!HologramAPI.useProtocolSupport) { + e.printStackTrace();//Ignore the exception(s) when using protocol support + } + } + + if (text == null) { + return;// The text will (or should) never be null + } + + for (Hologram h : HologramAPI.getHolograms()) { + if (((CraftHologram) h).matchesHologramID(a)) { + for (ViewHandler v : h.getViewHandlers()) { + text = v.onView(h, packetObject.getPlayer(), text); + } + } + } + + if (text == null) { + packetObject.setCancelled(true);//Cancel the packet if the text is null after calling the view handlers + return; + } + + try { + if (type == 0) { + // ClassBuilder.setDataWatcherValue(dataWatcher, 2, text); + DataWatcher.setValue(dataWatcher, 2, DataWatcher.V1_9.ValueType.ENTITY_NAME, text); + } else if (type == 1) { + if (list == null || listIndex == -1) { + return; + } + // Object object = ClassBuilder.buildWatchableObject(2, text); + Object object = Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? DataWatcher.V1_8.newWatchableObject(2, text) : DataWatcher.V1_9.newDataWatcherItem(DataWatcher.V1_9.ValueType.ENTITY_NAME.getType(), text); + list.set(listIndex, object); + setPacketValue("b", list, packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + + public static void setPacketValue(String field, Object value, Object packet) { + FieldResolver fieldResolver = new FieldResolver(packet.getClass()); + try { + fieldResolver.resolve(field).set(packet, value); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static Object getPacketValue(String field, Object packet) { + FieldResolver fieldResolver = new FieldResolver(packet.getClass()); + try { + return fieldResolver.resolve(field).get(packet); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static Object cloneDataWatcher(Object original) throws Exception { + if (original == null) { + return null; + } + // Object clone = NMSClass.DataWatcher.getConstructor(new Class[] { + // NMSClass.Entity }).newInstance(new Object[] { null }); + Object clone = DataWatcher.newDataWatcher(null); + int index = 0; + Object current = null; + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + // while ((current = ClassBuilder.getDataWatcherValue(original, index++)) != + // null) { + // ClassBuilder.setDataWatcherValue(clone, + // ClassBuilder.getWatchableObjectIndex(current), + // ClassBuilder.getWatchableObjectValue(current)); + // } + while ((current = DataWatcher.V1_8.getValue(original, index++)) != null) { + DataWatcher.V1_8.setValue(clone, DataWatcher.V1_8.getWatchableObjectIndex(current), + DataWatcher.V1_8.getWatchableObjectValue(current)); + } + } else { + Field mapField = DataWatcherFieldResolver.resolve("c"); + mapField.set(clone, mapField.get(original)); + // while ((current = DataWatcher.V1_9.getItem(original, index++)) != null) { + // DataWatcher.V1_9.setItem(clone, index++, current); + // } + + } + return clone; + } + + private static boolean hasDelay(Player player) { + if (!player.hasMetadata(DELAY_TAG)) return false; + return player.getMetadata(DELAY_TAG).get(0).asLong() > System.currentTimeMillis(); + } + + private static void addDelay(Player player) { + player.setMetadata(DELAY_TAG, new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis() + 600)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.java new file mode 100644 index 0000000..dd65224 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.java @@ -0,0 +1,117 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.protocol.ProtocolGetter; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.metadata.FixedMetadataValue; + +public class HologramListeners { + + private final static String LOCKED_TAG = "LOCKED.HOLOGRAMS.TIME"; + private static Listener listener; + + public static void registerListeners() { + + listener = new Listener() { + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + handleHolograms(event.getPlayer(), event.getPlayer().getLocation()); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + for (Hologram hologram : HologramAPI.getHolograms()) { + if (hologram.isSpawned()) { + hologram.clean(event.getPlayer()); + } + } + } + + @EventHandler + public void onRealMovement(PlayerMoveEvent event) { + if(!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + Player player = event.getPlayer(); + if (isLocked(player)) return; + + handleHolograms(player, event.getTo()); + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + Player player = e.getPlayer(); + if (isLocked(player)) return; + + handleHolograms(player, e.getTo()); + } + }; + + Bukkit.getServer().getPluginManager().registerEvents(listener, BukkitMain.getInstance()); + } + + public static void unregisterListeners() { + HandlerList.unregisterAll(listener); + listener = null; + } + + public static void handleHolograms(Player player, Location location) { + lock(player); + + for (Hologram hologram : HologramAPI.getHolograms()) { + if (!hologram.isSpawned()) continue; + if (!hologram.getLocation().getWorld().getName().equals(location.getWorld().getName())) continue; + + if (hologram.getLocation().distance(location) <= 80) { + + boolean spawn = true; + + if (hologram.getName().equalsIgnoreCase("name")) { + if (ProtocolGetter.getVersion(player) < 6) spawn = false; + } + + if (spawn) { + try { + HologramAPI.spawnSingle(hologram, player); + } catch (Exception ex) { + } + } + } else { + try { + HologramAPI.despawnSingle(hologram, player); + } catch (Exception ex) { + } + } + } + + removeLock(player); + } + + public static void lock(Player player) { + lock(player, 1500L); + } + + public static void removeLock(Player player) { + player.removeMetadata(LOCKED_TAG, BukkitMain.getInstance()); + } + + public static void lock(Player player, Long time) { + player.setMetadata(LOCKED_TAG, new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis() + time)); + } + + private static boolean isLocked(final Player player) { + if (!player.hasMetadata(LOCKED_TAG)) return false; + return player.getMetadata(LOCKED_TAG).get(0).asLong() > System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.java new file mode 100644 index 0000000..2c61540 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.java @@ -0,0 +1,11 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +class HologramOffsets { + + protected static final double WITHER_SKULL_HORSE = 54.56; + protected static final double ARMOR_STAND_PACKET = -2.25; + protected static final double ARMOR_STAND_DEFAULT = -1.25; + protected static final double TOUCH_SLIME_SKULL = -0.4; + protected static final double TOUCH_SLIME_ARMOR_STAND = 0.4; + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.java new file mode 100644 index 0000000..16e2763 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.java @@ -0,0 +1,30 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram; + +import lombok.Getter; +import lombok.val; + +@Getter +public class PlayerTop implements Comparable { + + private final String playerName; + private final int value; + + public PlayerTop(String playerName, int value) { + this.playerName = playerName; + this.value = value; + } + + @Override + public int compareTo(PlayerTop o) { + return o.getValue() - getValue(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof PlayerTop)) return false; + + val topObj = (PlayerTop) obj; + + return topObj.getPlayerName().equals(playerName) && topObj.getValue() == value; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.java new file mode 100644 index 0000000..a7fb289 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.java @@ -0,0 +1,300 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.DataWatcher; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft.NMSClassResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.DataWatcher.V1_9.ValueType.*; + +public abstract class ClassBuilder { + + static NMSClassResolver nmsClassResolver = new NMSClassResolver(); + + static FieldResolver EntitySlimeFieldResolver = new FieldResolver(NMSClass.EntitySlime); + static FieldResolver EntityFieldResolver = new FieldResolver(NMSClass.Entity); + static final FieldResolver PacketPlayOutSpawnEntityLivingFieldResolver = new FieldResolver(NMSClass.PacketPlayOutSpawnEntityLiving); + static final FieldResolver DataWatcherFieldResolver = new FieldResolver(NMSClass.DataWatcher); + + public static Object buildEntityWitherSkull(Object world, Location loc) throws Exception { + Object witherSkull = NMSClass.EntityWitherSkull.getConstructor(NMSClass.World).newInstance(world); + updateEntityLocation(witherSkull, loc); + + return witherSkull; + } + + public static Object buildEntityHorse_1_7(Object world, Location loc, String name) throws Exception { + Object horse_1_7 = NMSClass.EntityHorse.getConstructor(NMSClass.World).newInstance(world); + updateEntityLocation(horse_1_7, loc); + if (HologramAPI.is1_8()) { + if (name != null) { + NMSClass.Entity.getDeclaredMethod("setCustomName", String.class).invoke(horse_1_7, name); + } + NMSClass.Entity.getDeclaredMethod("setCustomNameVisible", boolean.class).invoke(horse_1_7, name != null && !name.isEmpty()); + } else { + if (name != null) { + NMSClass.EntityInsentient.getDeclaredMethod("setCustomName", String.class).invoke(horse_1_7, name); + } + NMSClass.EntityInsentient.getDeclaredMethod("setCustomNameVisible", boolean.class).invoke(horse_1_7, name != null && !name.isEmpty()); + } + Object horseDataWatcher = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(horse_1_7); + NMSClass.EntityAgeable.getDeclaredMethod("setAge", int.class).invoke(horse_1_7, -1700000); + // NMSClass.DataWatcher.getDeclaredMethod("watch", new Class[] { + // int.class, + // Object.class }).invoke(horseDataWatcher, new Object[] { + // 12, + // -1700000 });// Size + DataWatcher.setValue(horseDataWatcher, 12, ENTITY_FLAG, (byte) -1700000); + + return horse_1_7; + } + + public static Object buildEntityHorse_1_8(Object world, Location loc, String name) throws Exception { + Object horse_1_8 = NMSClass.EntityHorse.getConstructor(NMSClass.World).newInstance(world); + updateEntityLocation(horse_1_8, loc); + if (HologramAPI.is1_8()) { + if (name != null) { + NMSClass.Entity.getDeclaredMethod("setCustomName", String.class).invoke(horse_1_8, name); + } + NMSClass.Entity.getDeclaredMethod("setCustomNameVisible", boolean.class).invoke(horse_1_8, true); + } else { + NMSClass.EntityInsentient.getDeclaredMethod("setCustomName", String.class).invoke(horse_1_8, name); + NMSClass.EntityInsentient.getDeclaredMethod("setCustomNameVisible", boolean.class).invoke(horse_1_8, name != null && !name.isEmpty()); + } + + return horse_1_8; + } + + public static Object buildEntityArmorStand(Object world, Location loc, String name) throws Exception { + Object armorStand = NMSClass.EntityArmorStand.getConstructor(NMSClass.World).newInstance(world); + updateEntityLocation(armorStand, loc); + if (name != null) { + NMSClass.Entity.getDeclaredMethod("setCustomName", String.class).invoke(armorStand, name); + } + NMSClass.Entity.getDeclaredMethod("setCustomNameVisible", boolean.class).invoke(armorStand, name != null && !name.isEmpty()); + + return armorStand; + } + + public static Object setupArmorStand(Object armorStand) throws Exception { + NMSClass.EntityArmorStand.getDeclaredMethod("setInvisible", boolean.class).invoke(armorStand, true); + NMSClass.EntityArmorStand.getDeclaredMethod("setSmall", boolean.class).invoke(armorStand, true); + NMSClass.EntityArmorStand.getDeclaredMethod("setArms", boolean.class).invoke(armorStand, false); + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_10_R1)) { + NMSClass.EntityArmorStand.getDeclaredMethod("setGravity", boolean.class).invoke(armorStand, false); + } else { + NMSClass.Entity.getDeclaredMethod("setNoGravity", boolean.class).invoke(armorStand, true); + } + NMSClass.EntityArmorStand.getDeclaredMethod("setBasePlate", boolean.class).invoke(armorStand, false); + + return armorStand; + } + + public static Object buildEntitySlime(Object world, Location loc, int size) throws Exception { + Object slime = NMSClass.EntitySlime.getConstructor(NMSClass.World).newInstance(world); + updateEntityLocation(slime, loc); + Object dataWatcher = AccessUtil.setAccessible(NMSClass.Entity.getDeclaredField("datawatcher")).get(slime); + // setDataWatcherValue(dataWatcher, 0, (byte) 32); + // setDataWatcherValue(dataWatcher, 16, (byte) (size < 1 ? 1 : size > 100 ? 100 : size)); + DataWatcher.setValue(dataWatcher, 0, ENTITY_FLAG, (byte) 32); + DataWatcher.setValue(dataWatcher, 16, ENTITY_SLIME_SIZE, (size < 1 ? 1 : Math.min(size, 100)));//Size + + return slime; + } + + public static Object buildWitherSkullSpawnPacket(Object skull) throws Exception { + Object spawnPacketSkull = NMSClass.PacketPlayOutSpawnEntity.getConstructor(NMSClass.Entity, int.class).newInstance(skull, EntityType.WITHER_SKULL.getTypeId()); + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntity.getDeclaredField("j")).set(spawnPacketSkull, 66); + } else { + AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntity.getDeclaredField("k")).set(spawnPacketSkull, 66); + } + + return spawnPacketSkull; + } + + public static Object buildSkullMetaPacket(int id, Object dataWatcher) throws Exception { + // setDataWatcherValue(dataWatcher, 0, (byte) 32); + DataWatcher.setValue(dataWatcher, 0, ENTITY_FLAG, (byte) 32); + + return NMSClass.PacketPlayOutEntityMetadata.getConstructor(int.class, NMSClass.DataWatcher, boolean.class).newInstance(id, dataWatcher, true); + } + + public static Object buildHorseSpawnPacket_1_7(Object horse, String name) throws Exception { + if (horse == null) { + throw new IllegalArgumentException("horse cannot be null"); + } + Object spawnPacketHorse_1_7 = NMSClass.PacketPlayOutSpawnEntityLiving.getConstructor(NMSClass.EntityLiving).newInstance(horse); + Object dataWatcher_1_7 = AccessUtil.setAccessible(PacketPlayOutSpawnEntityLivingFieldResolver.resolveByFirstType(NMSClass.DataWatcher)).get(spawnPacketHorse_1_7); + + if (name != null) { + // setDataWatcherValue(dataWatcher_1_7, 10, name); + DataWatcher.setValue(dataWatcher_1_7, 10, ENTITY_NAME, name); + } + // setDataWatcherValue(dataWatcher_1_7, 11, (byte) (name != null && !name.isEmpty() ? 1 : 0)); + DataWatcher.setValue(dataWatcher_1_7, 11, ENTITY_NAME_VISIBLE, (byte) (name != null && !name.isEmpty() ? 1 : 0)); + // NMUClass.gnu_trove_map_hash_TIntObjectHashMap.getDeclaredMethod("put", int.class, Object.class).invoke(map, 12, NMSClass.WatchableObject.getConstructor(int.class, int.class, Object.class).newInstance(2, 12, -1700000)); + DataWatcher.setValue(dataWatcher_1_7, 12, ENTITY_FLAG, -1700000); + + return spawnPacketHorse_1_7; + } + + //No changes for 1.9 here - use ArmorStands + public static Object buildHorseSpawnPacket_1_8(Object horse, String name) throws Exception { + if (horse == null) { + throw new IllegalArgumentException("horse cannot be null"); + } + Object spawnPacketHorse_1_8 = NMSClass.PacketPlayOutSpawnEntityLiving.getConstructor(NMSClass.EntityLiving).newInstance(horse); + AccessUtil.setAccessible(NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("b")).setInt(spawnPacketHorse_1_8, 30); + Object dataWatcher_1_8 = AccessUtil.setAccessible(PacketPlayOutSpawnEntityLivingFieldResolver.resolveByFirstType(NMSClass.DataWatcher)).get(spawnPacketHorse_1_8); + Map map_1_8 = (Map) DataWatcherFieldResolver.resolveByLastType(Map.class).get(dataWatcher_1_8); + map_1_8.put(10, NMSClass.WatchableObject.getConstructor(int.class, int.class, Object.class).newInstance(0, 10, (byte) 1)); + + List toRemove = new ArrayList<>(); + + for (Map.Entry entry : map_1_8.entrySet()) {// 100 is a random value, we just want to get all values + Object current = entry.getValue(); + if (current == null) { + continue; + } + int index = AccessUtil.setAccessible(NMSClass.WatchableObject.getDeclaredField("b")).getInt(current); + if (index == 2) { + AccessUtil.setAccessible(NMSClass.WatchableObject.getDeclaredField("c")).set(current, name); + } else if (index != 3) { + toRemove.add(Integer.valueOf(index)); + } + } + + for (Integer i : toRemove) { + map_1_8.remove(i); + } + + map_1_8.put(0, NMSClass.WatchableObject.getConstructor(int.class, int.class, Object.class).newInstance(0, 0, (byte) 32)); + + return spawnPacketHorse_1_8; + } + + public static Object buildSlimeSpawnPacket(Object slime) throws Exception { + + return NMSClass.PacketPlayOutSpawnEntityLiving.getConstructor(NMSClass.EntityLiving).newInstance(slime); + } + + public static Object buildNameMetadataPacket(int id, Object dataWatcher, int nameIndex, int visibilityIndex, String name) throws Exception { + // dataWatcher = setDataWatcherValue(dataWatcher, nameIndex, name != null ? name : "");// Pass an empty string to avoid exceptions + // dataWatcher = setDataWatcherValue(dataWatcher, visibilityIndex, (byte) (name != null && !name.isEmpty() ? 1 : 0)); + DataWatcher.setValue(dataWatcher, nameIndex, ENTITY_NAME, name != null ? name : "");// Pass an empty string to avoid exceptions + DataWatcher.setValue(dataWatcher, visibilityIndex, ENTITY_NAME_VISIBLE, Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? (byte) (name != null && !name.isEmpty() ? 1 : 0) : (name != null && !name.isEmpty()));//Byte < 1.9, Boolean >= 1.9 + + return NMSClass.PacketPlayOutEntityMetadata.getConstructor(int.class, NMSClass.DataWatcher, boolean.class).newInstance(id, dataWatcher, true); + } + + public static Object updateEntityLocation(Object entity, Location loc) throws Exception { + NMSClass.Entity.getDeclaredField("locX").set(entity, loc.getX()); + NMSClass.Entity.getDeclaredField("locY").set(entity, loc.getY()); + NMSClass.Entity.getDeclaredField("locZ").set(entity, loc.getZ()); + return entity; + } + + // public static Object buildDataWatcher(@Nullable Object entity) throws Exception { + // Object dataWatcher = NMSClass.DataWatcher.getConstructor(NMSClass.Entity).newInstance(entity); + // return dataWatcher; + // } + // + // public static Object buildWatchableObject(int index, Object value) throws Exception { + // return buildWatchableObject(getDataWatcherValueType(value), index, value); + // } + // + // public static Object buildWatchableObject(int type, int index, Object value) throws Exception { + // return NMSClass.WatchableObject.getConstructor(int.class, int.class, Object.class).newInstance(type, index, value); + // } + // + // public static Object setDataWatcherValue(Object dataWatcher, int index, Object value) throws Exception { + // int type = getDataWatcherValueType(value); + // + // Object map = AccessUtil.setAccessible(NMSClass.DataWatcher.getDeclaredField("dataValues")).get(dataWatcher); + // NMUClass.gnu_trove_map_hash_TIntObjectHashMap.getDeclaredMethod("put", int.class, Object.class).invoke(map, index, buildWatchableObject(type, index, value)); + // + // return dataWatcher; + // } + // + // public static Object getDataWatcherValue(Object dataWatcher, int index) throws Exception { + // Object map = AccessUtil.setAccessible(NMSClass.DataWatcher.getDeclaredField("dataValues")).get(dataWatcher); + // Object value = NMUClass.gnu_trove_map_hash_TIntObjectHashMap.getDeclaredMethod("get", int.class).invoke(map, index); + // + // return value; + // } + // + // public static int getWatchableObjectIndex(Object object) throws Exception { + // int index = AccessUtil.setAccessible(NMSClass.WatchableObject.getDeclaredField("b")).getInt(object); + // return index; + // } + // + // public static int getWatchableObjectType(Object object) throws Exception { + // int type = AccessUtil.setAccessible(NMSClass.WatchableObject.getDeclaredField("a")).getInt(object); + // return type; + // } + // + // public static Object getWatchableObjectValue(Object object) throws Exception { + // Object value = AccessUtil.setAccessible(NMSClass.WatchableObject.getDeclaredField("c")).get(object); + // return value; + // } + // + // public static int getDataWatcherValueType(Object value) { + // int type = 0; + // if (value instanceof Number) { + // if (value instanceof Byte) { + // type = 0; + // } else if (value instanceof Short) { + // type = 1; + // } else if (value instanceof Integer) { + // type = 2; + // } else if (value instanceof Float) { + // type = 3; + // } + // } else if (value instanceof String) { + // type = 4; + // } else if (value != null && value.getClass().equals(NMSClass.ItemStack)) { + // type = 5; + // } else if (value != null && (value.getClass().equals(NMSClass.ChunkCoordinates) || value.getClass().equals(NMSClass.BlockPosition))) { + // type = 6; + // } else if (value != null && value.getClass().equals(NMSClass.Vector3f)) { + // type = 7; + // } + // + // return type; + // } + + public static Object buildArmorStandSpawnPacket(Object armorStand) throws Exception { + Object spawnPacket = NMSClass.PacketPlayOutSpawnEntityLiving.getConstructor(NMSClass.EntityLiving).newInstance(armorStand); + AccessUtil.setAccessible(Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1) ? NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("b") : NMSClass.PacketPlayOutSpawnEntityLiving.getDeclaredField("c")).setInt(spawnPacket, 30); + + return spawnPacket; + } + + public static Object buildTeleportPacket(int id, Location loc, boolean onGround, boolean heightCorrection) throws Exception { + Object packet = NMSClass.PacketPlayOutEntityTeleport.newInstance(); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("a")).set(packet, id); + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("b")).set(packet, (int) (loc.getX() * 32D)); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("c")).set(packet, (int) (loc.getY() * 32D)); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("d")).set(packet, (int) (loc.getZ() * 32D)); + } else { + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("b")).set(packet, loc.getX()); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("c")).set(packet, loc.getY()); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("d")).set(packet, loc.getZ()); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("g")).set(packet, onGround); + } + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("e")).set(packet, (byte) (int) (loc.getYaw() * 256F / 360F)); + AccessUtil.setAccessible(NMSClass.PacketPlayOutEntityTeleport.getDeclaredField("f")).set(packet, (byte) (int) (loc.getPitch() * 256F / 360F)); + + return packet; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.java new file mode 100644 index 0000000..0a4308a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.java @@ -0,0 +1,10 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection; + +public abstract class MathUtil { + + public static int floor(double d1) { + int i = (int) d1; + return d1 >= i ? i : i - 1; + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.java new file mode 100644 index 0000000..40b7c07 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection; + +import java.lang.reflect.Field; + +public abstract class NMSClass { + + public static Class Entity; + public static Class EntityLiving; + public static Class EntityInsentient; + public static Class EntityAgeable; + public static Class EntityHorse; + public static Class EntityArmorStand; + public static Class EntityWitherSkull; + public static Class EntitySlime; + public static Class World; + public static Class PacketPlayOutSpawnEntityLiving; + public static Class PacketPlayOutSpawnEntity; + public static Class PacketPlayOutEntityDestroy; + public static Class PacketPlayOutAttachEntity; + public static Class PacketPlayOutMount;//1.9 + public static Class PacketPlayOutEntityTeleport; + public static Class PacketPlayOutEntityMetadata; + public static Class DataWatcher; + public static Class WatchableObject; + public static Class ItemStack; + public static Class ChunkCoordinates; + public static Class BlockPosition; + public static Class Vector3f; + public static Class EnumEntityUseAction; + private static boolean initialized = false; + + static { + if (!initialized) { + for (Field f : NMSClass.class.getDeclaredFields()) { + if (f.getType().equals(Class.class)) { + try { + f.set(null, Reflection.getNMSClassWithException(f.getName())); + } catch (Exception e) { + if (f.getName().equals("WatchableObject")) { + try { + f.set(null, Reflection.getNMSClassWithException("DataWatcher$WatchableObject")); + } catch (Exception e1) { + // e1.printStackTrace(); - Ignore for 1.9 + } + } + } + } + } + initialized = true; + } + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.java new file mode 100644 index 0000000..f1f1d53 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.java @@ -0,0 +1,33 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection; + +import java.lang.reflect.Field; + +public abstract class NMUClass { + + public static Class gnu_trove_map_TIntObjectMap; + public static Class gnu_trove_map_hash_TIntObjectHashMap; + public static Class gnu_trove_impl_hash_THash; + public static Class io_netty_channel_Channel; + private static boolean initialized = false; + + static { + if (!initialized) { + for (Field f : NMUClass.class.getDeclaredFields()) { + if (f.getType().equals(Class.class)) { + try { + String name = f.getName().replace("_", "."); + if (Reflection.getVersion().contains("1_8")) { + f.set(null, Class.forName(name)); + } else { + f.set(null, Class.forName("net.minecraft.util." + name)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + initialized = true; + } + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.java new file mode 100644 index 0000000..f8b245b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.java @@ -0,0 +1,91 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection; + +import org.bukkit.Bukkit; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public abstract class Reflection { + + public static String getVersion() { + String name = Bukkit.getServer().getClass().getPackage().getName(); + return name.substring(name.lastIndexOf('.') + 1) + "."; + } + + public static Class getNMSClass(String className) { + String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Class getNMSClassWithException(String className) throws Exception { + String fullName = "net.minecraft.server." + getVersion() + className; + return Class.forName(fullName); + } + + public static Class getOBCClass(String className) { + String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Object getHandle(Object obj) { + try { + return getMethod(obj.getClass(), "getHandle", new Class[0]).invoke(obj); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static Field getField(Class clazz, String name) { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static Field getFieldWithException(Class clazz, String name) throws Exception { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } + + public static Method getMethod(Class clazz, String name, Class... args) { + for (Method m : clazz.getMethods()) { + if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + } + return null; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) { + return false; + } + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.java new file mode 100644 index 0000000..b853f79 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.java @@ -0,0 +1,37 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.annotation; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Resolves the annotated {@link de.inventivegames.reflection.resolver.wrapper.ClassWrapper} or {@link java.lang.Class} field to the first matching class name. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Class { + + /** + * Name of the class. Use {nms}.MyClass for NMS classes, or {obc}.MyClass for OBC classes. Use > or < as a name prefix in combination with {@link #versions()} to specify versions newer- or older-than. + * + * @return the class name + */ + String[] value(); + + /** + * Specific versions for the names. + * + * @return Array of versions for the class names + */ + Minecraft.Version[] versions() default {}; + + /** + * Whether to ignore any reflection exceptions thrown. Defaults to true + * + * @return whether to ignore exceptions + */ + boolean ignoreExceptions() default true; +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.java new file mode 100644 index 0000000..fadee69 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.annotation; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Resolves the annotated {@link org.inventivegames.reflection.resolver.wrapper.FieldWrapper} or {@link java.lang.reflect.Field} field to the first matching field name. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Field { + + /** + * Name of the class to load this field from + * + * @return name of the class + */ + String className(); + + /** + * Possible names of the field. Use > or < as a name prefix in combination with {@link #versions()} to specify versions newer- or older-than. + * + * @return names of the field + */ + String[] value(); + + /** + * Specific versions for the names. + * + * @return Array of versions for the class names + */ + Minecraft.Version[] versions() default {}; + + /** + * Whether to ignore any reflection exceptions thrown. Defaults to true + * + * @return whether to ignore exceptions + */ + boolean ignoreExceptions() default true; +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.java new file mode 100644 index 0000000..53b56fb --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.annotation; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Resolves the annotated {@link org.inventivegames.reflection.resolver.wrapper.MethodWrapper} or {@link java.lang.reflect.Method} field to the first matching method name. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Method { + + /** + * Name of the class to load this method from + * + * @return name of the class + */ + String className(); + + /** + * Possible names of the method. Use > or < as a name prefix in combination with {@link #versions()} to specify versions newer- or older-than. + * + * @return method names + */ + String[] value(); + + /** + * Specific versions for the names. + * + * @return Array of versions for the class names + */ + Minecraft.Version[] versions() default {}; + + /** + * Whether to ignore any reflection exceptions thrown. Defaults to true + * + * @return whether to ignore exceptions + */ + boolean ignoreExceptions() default true; +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.java new file mode 100644 index 0000000..f2dac57 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.java @@ -0,0 +1,205 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.annotation; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ClassResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.MethodResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.ClassWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.FieldWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.MethodWrapper; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ReflectionAnnotations { + + public static final ReflectionAnnotations INSTANCE = new ReflectionAnnotations(); + + static final Pattern classRefPattern = Pattern.compile("@Class\\((.*)\\)"); + + private ReflectionAnnotations() { + } + + public void load(Object toLoad) { + if (toLoad == null) { + throw new IllegalArgumentException("toLoad cannot be null"); + } + + ClassResolver classResolver = new ClassResolver(); + + for (java.lang.reflect.Field field : toLoad.getClass().getDeclaredFields()) { + Class classAnnotation = field.getAnnotation(Class.class); + Field fieldAnnotation = field.getAnnotation(Field.class); + Method methodAnnotation = field.getAnnotation(Method.class); + + if (classAnnotation == null && fieldAnnotation == null && methodAnnotation == null) { + continue; + } else { + field.setAccessible(true); + } + + if (classAnnotation != null) { + List nameList = parseAnnotationVersions(Class.class, classAnnotation); + if (nameList.isEmpty()) { + throw new IllegalArgumentException("@Class names cannot be empty"); + } + String[] names = nameList.toArray(new String[0]); + for (int i = 0; i < names.length; i++) {// Replace NMS & OBC + names[i] = names[i] + .replace("{nms}", "net.minecraft.server." + Minecraft.VERSION.name()) + .replace("{obc}", "org.bukkit.craftbukkit." + Minecraft.VERSION.name()); + } + try { + if (ClassWrapper.class.isAssignableFrom(field.getType())) { + field.set(toLoad, classResolver.resolveWrapper(names)); + } else if (java.lang.Class.class.isAssignableFrom(field.getType())) { + field.set(toLoad, classResolver.resolve(names)); + } else { + throwInvalidFieldType(field, toLoad, "Class or ClassWrapper"); + return; + } + } catch (ReflectiveOperationException e) { + if (!classAnnotation.ignoreExceptions()) { + throwReflectionException("@Class", field, toLoad, e); + return; + } + } + } else if (fieldAnnotation != null) { + List nameList = parseAnnotationVersions(Field.class, fieldAnnotation); + if (nameList.isEmpty()) { + throw new IllegalArgumentException("@Field names cannot be empty"); + } + String[] names = nameList.toArray(new String[0]); + try { + FieldResolver fieldResolver = new FieldResolver(parseClass(Field.class, fieldAnnotation, toLoad)); + if (FieldWrapper.class.isAssignableFrom(field.getType())) { + field.set(toLoad, fieldResolver.resolveWrapper(names)); + } else if (java.lang.reflect.Field.class.isAssignableFrom(field.getType())) { + field.set(toLoad, fieldResolver.resolve(names)); + } else { + throwInvalidFieldType(field, toLoad, "Field or FieldWrapper"); + return; + } + } catch (ReflectiveOperationException e) { + if (!fieldAnnotation.ignoreExceptions()) { + throwReflectionException("@Field", field, toLoad, e); + return; + } + } + } else { + List nameList = parseAnnotationVersions(Method.class, methodAnnotation); + if (nameList.isEmpty()) { + throw new IllegalArgumentException("@Method names cannot be empty"); + } + String[] names = nameList.toArray(new String[0]); + + boolean isSignature = names[0].contains(" ");// Only signatures can contain spaces (e.g. "void aMethod()") + for (String s : names) { + if (s.contains(" ") != isSignature) { + throw new IllegalArgumentException("Inconsistent method names: Cannot have mixed signatures/names"); + } + } + + try { + MethodResolver methodResolver = new MethodResolver(parseClass(Method.class, methodAnnotation, toLoad)); + if (MethodWrapper.class.isAssignableFrom(field.getType())) { + if (isSignature) { + field.set(toLoad, methodResolver.resolveSignatureWrapper(names)); + } else { + field.set(toLoad, methodResolver.resolveWrapper(names)); + } + } else if (java.lang.reflect.Method.class.isAssignableFrom(field.getType())) { + if (isSignature) { + field.set(toLoad, methodResolver.resolveSignature(names)); + } else { + field.set(toLoad, methodResolver.resolve(names)); + } + } else { + throwInvalidFieldType(field, toLoad, "Method or MethodWrapper"); + return; + } + } catch (ReflectiveOperationException e) { + if (!methodAnnotation.ignoreExceptions()) { + throwReflectionException("@Method", field, toLoad, e); + return; + } + } + } + } + } + + /** + * Parses an annotation to the current server version. Removes all entries that don't match the version, but keeps the original order for matching names. + * + * @param clazz Class of the annotation + * @param annotation annotation + * @param annotation type + * @return a list of matching names + */ + List parseAnnotationVersions(java.lang.Class clazz, A annotation) { + List list = new ArrayList<>(); + + try { + String[] names = (String[]) clazz.getMethod("value").invoke(annotation); + Minecraft.Version[] versions = (Minecraft.Version[]) clazz.getMethod("versions").invoke(annotation); + + if (versions.length == 0) {// No versions specified -> directly use the names + list.addAll(Arrays.asList(names)); + } else { + if (versions.length > names.length) { + throw new RuntimeException("versions array cannot have more elements than the names (" + clazz + ")"); + } + for (int i = 0; i < versions.length; i++) { + if (Minecraft.VERSION == versions[i]) {// Wohoo, perfect match! + list.add(names[i]); + } else { + if (names[i].startsWith(">") && Minecraft.VERSION.newerThan(versions[i])) {// Match if the current version is newer + list.add(names[i].substring(1)); + } else if (names[i].startsWith("<") && Minecraft.VERSION.olderThan(versions[i])) {// Match if the current version is older + list.add(names[i].substring(1)); + } + } + } + } + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + + return list; + } + + String parseClass(java.lang.Class clazz, A annotation, Object toLoad) { + try { + String className = (String) clazz.getMethod("className").invoke(annotation); + Matcher matcher = classRefPattern.matcher(className); + while (matcher.find()) { + if (matcher.groupCount() != 1) { + continue; + } + String fieldName = matcher.group(1);// It's a reference to a previously loaded class + java.lang.reflect.Field field = toLoad.getClass().getField(fieldName); + if (ClassWrapper.class.isAssignableFrom(field.getType())) { + return ((ClassWrapper) field.get(toLoad)).getName(); + } else if (java.lang.Class.class.isAssignableFrom(field.getType())) { + return ((java.lang.Class) field.get(toLoad)).getName(); + } + } + return className; + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + void throwInvalidFieldType(java.lang.reflect.Field field, Object toLoad, String expected) { + throw new IllegalArgumentException("Field " + field.getName() + " in " + toLoad.getClass() + " is not of type " + expected + ", it's " + field.getType()); + } + + void throwReflectionException(String annotation, java.lang.reflect.Field field, Object toLoad, ReflectiveOperationException exception) { + throw new RuntimeException("Failed to set " + annotation + " field " + field.getName() + " in " + toLoad.getClass(), exception); + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.java new file mode 100644 index 0000000..c6926d3 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.java @@ -0,0 +1,425 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ConstructorResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.MethodResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ResolverQuery; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft.NMSClassResolver; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Map; + +public class DataWatcher { + + static final NMSClassResolver nmsClassResolver = new NMSClassResolver(); + + static final Class ItemStack = nmsClassResolver.resolveSilent("ItemStack"); + static final Class ChunkCoordinates = nmsClassResolver.resolveSilent("ChunkCoordinates"); + static final Class BlockPosition = nmsClassResolver.resolveSilent("BlockPosition"); + static final Class Vector3f = nmsClassResolver.resolveSilent("Vector3f"); + static final Class DataWatcher = nmsClassResolver.resolveSilent("DataWatcher"); + static final ConstructorResolver DataWacherConstructorResolver = new ConstructorResolver(DataWatcher); + static final FieldResolver DataWatcherFieldResolver = new FieldResolver(DataWatcher); + static final MethodResolver DataWatcherMethodResolver = new MethodResolver(DataWatcher); + static final Class Entity = nmsClassResolver.resolveSilent("Entity"); + + private DataWatcher() { + } + + public static Object newDataWatcher(Object entity) throws ReflectiveOperationException { + return DataWacherConstructorResolver.resolve(new Class[]{Entity}).newInstance(entity); + } + + public static Object setValue(Object dataWatcher, int index, Object dataWatcherObject/*1.9*/, Object value) throws ReflectiveOperationException { + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + return V1_8.setValue(dataWatcher, index, value); + } else { + return V1_9.setValue(dataWatcher, dataWatcherObject, value); + } + } + + public static Object setValue(Object dataWatcher, int index, V1_9.ValueType type, Object value) throws ReflectiveOperationException { + return setValue(dataWatcher, index, type.getType(), value); + } + + public static Object setValue(Object dataWatcher, int index, Object value, FieldResolver dataWatcherObjectFieldResolver/*1.9*/, String... dataWatcherObjectFieldNames/*1.9*/) throws ReflectiveOperationException { + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + return V1_8.setValue(dataWatcher, index, value); + } else { + Object dataWatcherObject = dataWatcherObjectFieldResolver.resolve(dataWatcherObjectFieldNames).get(null/*Should be a static field*/); + return V1_9.setValue(dataWatcher, dataWatcherObject, value); + } + } + + @Deprecated + public static Object getValue(DataWatcher dataWatcher, int index) throws ReflectiveOperationException { + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + return V1_8.getValue(dataWatcher, index); + } else { + return V1_9.getValue(dataWatcher, index); + } + } + + public static Object getValue(Object dataWatcher, int index, V1_9.ValueType type) throws ReflectiveOperationException { + return getValue(dataWatcher, index, type.getType()); + } + + public static Object getValue(Object dataWatcher, int index, Object dataWatcherObject/*1.9*/) throws ReflectiveOperationException { + if (Minecraft.VERSION.olderThan(Minecraft.Version.v1_9_R1)) { + return V1_8.getWatchableObjectValue(V1_8.getValue(dataWatcher, index)); + } else { + return V1_9.getValue(dataWatcher, dataWatcherObject); + } + } + + //TODO: update type-ids to 1.9 + public static int getValueType(Object value) { + int type = 0; + if (value instanceof Number) { + if (value instanceof Byte) { + type = 0; + } else if (value instanceof Short) { + type = 1; + } else if (value instanceof Integer) { + type = 2; + } else if (value instanceof Float) { + type = 3; + } + } else if (value instanceof String) { + type = 4; + } else if (value != null && value.getClass().equals(ItemStack)) { + type = 5; + } else if (value != null && (value.getClass().equals(ChunkCoordinates) || value.getClass().equals(BlockPosition))) { + type = 6; + } else if (value != null && value.getClass().equals(Vector3f)) { + type = 7; + } + + return type; + } + + /** + * Helper class for versions newer than 1.9 + */ + public static class V1_9 { + + static final Class DataWatcherItem = nmsClassResolver.resolveSilent("DataWatcher$Item");//>= 1.9 only + static final Class DataWatcherObject = nmsClassResolver.resolveSilent("DataWatcherObject");//>= 1.9 only + + static ConstructorResolver DataWatcherItemConstructorResolver;//>=1.9 only + + static FieldResolver DataWatcherItemFieldResolver;//>=1.9 only + static FieldResolver DataWatcherObjectFieldResolver;//>=1.9 only + + public static Object newDataWatcherItem(Object dataWatcherObject, Object value) throws ReflectiveOperationException { + if (DataWatcherItemConstructorResolver == null) { + DataWatcherItemConstructorResolver = new ConstructorResolver(DataWatcherItem); + } + return DataWatcherItemConstructorResolver.resolveFirstConstructor().newInstance(dataWatcherObject, value); + } + + public static Object setItem(Object dataWatcher, int index, Object dataWatcherObject, Object value) throws ReflectiveOperationException { + return setItem(dataWatcher, index, newDataWatcherItem(dataWatcherObject, value)); + } + + public static Object setItem(Object dataWatcher, int index, Object dataWatcherItem) throws ReflectiveOperationException { + Map map = (Map) DataWatcherFieldResolver.resolveByLastTypeSilent(Map.class).get(dataWatcher); + map.put(index, dataWatcherItem); + return dataWatcher; + } + + public static Object setValue(Object dataWatcher, Object dataWatcherObject, Object value) throws ReflectiveOperationException { + DataWatcherMethodResolver.resolve("set").invoke(dataWatcher, dataWatcherObject, value); + return dataWatcher; + } + + // public static Object getValue(Object dataWatcher, int index) throws ReflectiveOperationException { + // Map map = (Map) DataWatcherFieldResolver.resolve("c").get(dataWatcher); + // return map.get(index); + // } + + public static Object getItem(Object dataWatcher, Object dataWatcherObject) throws ReflectiveOperationException { + return DataWatcherMethodResolver.resolve(new ResolverQuery("c", DataWatcherObject)).invoke(dataWatcher, dataWatcherObject); + } + + public static Object getValue(Object dataWatcher, Object dataWatcherObject) throws ReflectiveOperationException { + return DataWatcherMethodResolver.resolve("get").invoke(dataWatcher, dataWatcherObject); + } + + public static Object getValue(Object dataWatcher, ValueType type) throws ReflectiveOperationException { + return getValue(dataWatcher, type.getType()); + } + + public static Object getItemObject(Object item) throws ReflectiveOperationException { + if (DataWatcherItemFieldResolver == null) { + DataWatcherItemFieldResolver = new FieldResolver(DataWatcherItem); + } + return DataWatcherItemFieldResolver.resolve("a").get(item); + } + + public static int getItemIndex(Object dataWatcher, Object item) throws ReflectiveOperationException { + int index = -1;//Return -1 if the item is not in the DataWatcher + Map map = (Map) DataWatcherFieldResolver.resolveByLastTypeSilent(Map.class).get(dataWatcher); + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().equals(item)) { + index = entry.getKey(); + break; + } + } + return index; + } + + public static Type getItemType(Object item) throws ReflectiveOperationException { + if (DataWatcherObjectFieldResolver == null) { + DataWatcherObjectFieldResolver = new FieldResolver(DataWatcherObject); + } + Object object = getItemObject(item); + Object serializer = DataWatcherObjectFieldResolver.resolve("b").get(object); + Type[] genericInterfaces = serializer.getClass().getGenericInterfaces(); + if (genericInterfaces.length > 0) { + Type type = genericInterfaces[0]; + if (type instanceof ParameterizedType) { + Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments(); + if (actualTypes.length > 0) { + return actualTypes[0]; + } + } + } + return null; + } + + public static Object getItemValue(Object item) throws ReflectiveOperationException { + if (DataWatcherItemFieldResolver == null) { + DataWatcherItemFieldResolver = new FieldResolver(DataWatcherItem); + } + return DataWatcherItemFieldResolver.resolve("b").get(item); + } + + public static void setItemValue(Object item, Object value) throws ReflectiveOperationException { + DataWatcherItemFieldResolver.resolve("b").set(item, value); + } + + public enum ValueType { + + /** + * Byte + */ + ENTITY_FLAG("Entity", 57, 0 /*"ax", "ay"*/), + /** + * Integer + */ + ENTITY_AIR_TICKS("Entity", 58, 1/*"ay", "az"*/), + /** + * String + */ + ENTITY_NAME("Entity", 59, 2/*"az", "aA"*/), + /** + * Byte < 1.9 Boolean > 1.9 + */ + ENTITY_NAME_VISIBLE("Entity", 60, 3/*"aA", "aB"*/), + /** + * Boolean + */ + ENTITY_SILENT("Entity", 61, 4/*"aB", "aC"*/), + + ////////// + + //TODO: Add EntityLiving#as (Byte) + ENTITY_as("EntityLiving", 2, 0/* "as", "at"*/), + + /** + * Float + */ + ENTITY_LIVING_HEALTH("EntityLiving", "HEALTH"), + + //TODO: Add EntityLiving#f (Integer) - Maybe active potions? + ENTITY_LIVING_f("EntityLiving", 4, 2/*"f"*/), + + //TODO: Add EntityLiving#g (Boolean) - Maybe ambient potions? + ENTITY_LIVING_g("EntityLiving", 5, 3/*"g"*/), + + //TODO: Add EntityLiving#h (Integer) + ENTITY_LIVING_h("EntityLiving", 6, 4/*"h"*/), + + ////////// + + /** + * Byte + */ + ENTITY_INSENTIENT_FLAG("EntityInsentient", 0, 0/* "a"*/), + + /////////// + + /** + * Integer + */ + ENTITY_SLIME_SIZE("EntitySlime", 0, 0/* "bt", "bu"*/), + + ///////////// + + //TODO: Add EntityWither#a (Integer) + ENTITY_WITHER_a("EntityWither", 0, 0/*"a"*/), + + //TODO: Add EntityWither#b (Integer) + ENTITY_WIHER_b("EntityWither", 1, 1/*"b"*/), + + //TODO: Add EntityWither#c (Integer) + ENTITY_WITHER_c("EntityWither", 2, 2/*"c"*/), + + //TODO: Add EntityWither#bv (Integer) - (DataWatcherObject[] bv, seems to be an array of {a, b, c}) + ENTITY_WITHER_bv("EntityWither", 3, 3/*"bv", "bw"*/), + + //TODO: Add EntityWither#bw (Integer) + ENTITY_WITHER_bw("EntityWither", 4, 4/*"bw", "bx"*/), + + ////////// + + ENTITY_AGEABLE_CHILD("EntityAgeable", 0, 0), + + /////////// + + ENTITY_HORSE_STATUS("EntityHorse", 3, 0), + ENTITY_HORSE_HORSE_TYPE("EntityHorse", 4, 1), + ENTITY_HORSE_HORSE_VARIANT("EntityHorse", 5, 2), + ENTITY_HORSE_OWNER_UUID("EntityHorse", 6, 3), + ENTITY_HORSE_HORSE_ARMOR("EntityHorse", 7, 4), + + ///////// + + + /** + * Float + */ + ENTITY_HUMAN_ABSORPTION_HEARTS("EntityHuman", 0, 0 /*"a"*/), + + /** + * Integer + */ + ENTITY_HUMAN_SCORE("EntityHuman", 1, 1 /*"b"*/), + + /** + * Byte + */ + ENTITY_HUMAN_SKIN_LAYERS("EntityHuman", 2, 2 /*"bp", "bq"*/), + + /** + * Byte (0 = left, 1 = right) + */ + ENTITY_HUMAN_MAIN_HAND("EntityHuman", 3, 3/*"bq", "br"*/); + + private Object type; + + ValueType(String className, String... fieldNames) { + try { + this.type = new FieldResolver(nmsClassResolver.resolve(className)).resolve(fieldNames).get(null); + } catch (Exception e) { + if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) { + System.err.println("[ReflectionHelper] Failed to find DataWatcherObject for " + className + " " + Arrays.toString(fieldNames)); + } + } + } + + ValueType(String className, int index) { + try { + this.type = new FieldResolver(nmsClassResolver.resolve(className)).resolveIndex(index).get(null); + } catch (Exception e) { + if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) { + System.err.println("[ReflectionHelper] Failed to find DataWatcherObject for " + className + " #" + index); + } + } + } + + ValueType(String className, int index, int offset) { + int firstObject = 0; + try { + Class clazz = nmsClassResolver.resolve(className); + for (Field field : clazz.getDeclaredFields()) { + if ("DataWatcherObject".equals(field.getType().getSimpleName())) { + break; + } + firstObject++; + } + this.type = new FieldResolver(clazz).resolveIndex(firstObject + offset).get(null); + } catch (Exception e) { + if (Minecraft.VERSION.newerThan(Minecraft.Version.v1_9_R1)) { + System.err.println("[ReflectionHelper] Failed to find DataWatcherObject for " + className + " #" + index + " (" + firstObject + "+" + offset + ")"); + } + } + } + + public boolean hasType() { + return getType() != null; + } + + public Object getType() { + return type; + } + } + } + + /** + * Helper class for versions older than 1.8 + */ + public static class V1_8 { + + static final Class WatchableObject = nmsClassResolver.resolveSilent("WatchableObject", "DataWatcher$WatchableObject");//<=1.8 only + + static ConstructorResolver WatchableObjectConstructorResolver;//<=1.8 only + + static FieldResolver WatchableObjectFieldResolver;//<=1.8 only + + public static Object newWatchableObject(int index, Object value) throws ReflectiveOperationException { + return newWatchableObject(getValueType(value), index, value); + } + + public static Object newWatchableObject(int type, int index, Object value) throws ReflectiveOperationException { + if (WatchableObjectConstructorResolver == null) { + WatchableObjectConstructorResolver = new ConstructorResolver(WatchableObject); + } + return WatchableObjectConstructorResolver.resolve(new Class[]{ + int.class, + int.class, + Object.class}).newInstance(type, index, value); + } + + public static Object setValue(Object dataWatcher, int index, Object value) throws ReflectiveOperationException { + int type = getValueType(value); + + Map map = (Map) DataWatcherFieldResolver.resolveByLastType(Map.class).get(dataWatcher); + map.put(index, newWatchableObject(type, index, value)); + + return dataWatcher; + } + + public static Object getValue(Object dataWatcher, int index) throws ReflectiveOperationException { + Map map = (Map) DataWatcherFieldResolver.resolveByLastType(Map.class).get(dataWatcher); + + return map.get(index); + } + + public static int getWatchableObjectIndex(Object object) throws ReflectiveOperationException { + if (WatchableObjectFieldResolver == null) { + WatchableObjectFieldResolver = new FieldResolver(WatchableObject); + } + return WatchableObjectFieldResolver.resolve("b").getInt(object); + } + + public static int getWatchableObjectType(Object object) throws ReflectiveOperationException { + if (WatchableObjectFieldResolver == null) { + WatchableObjectFieldResolver = new FieldResolver(WatchableObject); + } + return WatchableObjectFieldResolver.resolve("a").getInt(object); + } + + public static Object getWatchableObjectValue(Object object) throws ReflectiveOperationException { + if (WatchableObjectFieldResolver == null) { + WatchableObjectFieldResolver = new FieldResolver(WatchableObject); + } + return WatchableObjectFieldResolver.resolve("c").get(object); + } + + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.java new file mode 100644 index 0000000..4d76728 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.java @@ -0,0 +1,228 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ConstructorResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.FieldResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.MethodResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft.NMSClassResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft.OBCClassResolver; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import sun.reflect.ConstructorAccessor; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Helper class to access minecraft/bukkit specific objects + */ +public class Minecraft { + public static final Version VERSION; + static final Pattern NUMERIC_VERSION_PATTERN = Pattern.compile("v(\\d)_(\\d*)_R(\\d)"); + private static final NMSClassResolver nmsClassResolver = new NMSClassResolver(); + private static final OBCClassResolver obcClassResolver = new OBCClassResolver(); + private static final Class NmsEntity; + private static final Class CraftEntity; + + static { + VERSION = Version.getVersion(); + try { + NmsEntity = nmsClassResolver.resolve("Entity"); + CraftEntity = obcClassResolver.resolve("entity.CraftEntity"); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + /** + * @return the current NMS/OBC version (format <version>. + */ + public static String getVersion() { + return VERSION.name() + "."; + } + + public static Object getHandle(Object object) throws ReflectiveOperationException { + Method method; + try { + method = AccessUtil.setAccessible(object.getClass().getDeclaredMethod("getHandle")); + } catch (ReflectiveOperationException e) { + method = AccessUtil.setAccessible(CraftEntity.getDeclaredMethod("getHandle")); + } + return method.invoke(object); + } + + public static Entity getBukkitEntity(Object object) throws ReflectiveOperationException { + Method method; + try { + method = AccessUtil.setAccessible(NmsEntity.getDeclaredMethod("getBukkitEntity")); + } catch (ReflectiveOperationException e) { + method = AccessUtil.setAccessible(CraftEntity.getDeclaredMethod("getHandle")); + } + return (Entity) method.invoke(object); + } + + public static Object getHandleSilent(Object object) { + try { + return getHandle(object); + } catch (Exception e) { + } + return null; + } + + public static Object newEnumInstance(Class clazz, Class[] types, Object[] values) throws ReflectiveOperationException { + Constructor constructor = new ConstructorResolver(clazz).resolve(types); + Field accessorField = new FieldResolver(Constructor.class).resolve("constructorAccessor"); + ConstructorAccessor constructorAccessor = (ConstructorAccessor) accessorField.get(constructor); + if (constructorAccessor == null) { + new MethodResolver(Constructor.class).resolve("acquireConstructorAccessor").invoke(constructor); + constructorAccessor = (ConstructorAccessor) accessorField.get(constructor); + } + return constructorAccessor.newInstance(values); + + } + + public enum Version { + UNKNOWN(-1) { + @Override + public boolean matchesPackageName(String packageName) { + return false; + } + }, + + v1_7_R1(10701), + v1_7_R2(10702), + v1_7_R3(10703), + v1_7_R4(10704), + + v1_8_R1(10801), + v1_8_R2(10802), + v1_8_R3(10803), + //Does this even exists? + v1_8_R4(10804), + + v1_9_R1(10901), + v1_9_R2(10902), + + v1_10_R1(11001), + + v1_11_R1(11101), + + v1_12_R1(11201), + + v1_13_R1(11301), + v1_13_R2(11302), + + v1_14_R1(11401); + + private final int version; + + Version(int version) { + this.version = version; + } + + public static Version getVersion() { + String name = Bukkit.getServer().getClass().getPackage().getName(); + String versionPackage = name.substring(name.lastIndexOf('.') + 1) + "."; + for (Version version : values()) { + if (version.matchesPackageName(versionPackage)) { + return version; + } + } + System.err.println("[ReflectionHelper] Failed to find version enum for '" + name + "'/'" + versionPackage + "'"); + + System.out.println("[ReflectionHelper] Generating dynamic constant..."); + Matcher matcher = NUMERIC_VERSION_PATTERN.matcher(versionPackage); + while (matcher.find()) { + if (matcher.groupCount() < 3) { + continue; + } + + String majorString = matcher.group(1); + String minorString = matcher.group(2); + if (minorString.length() == 1) { + minorString = "0" + minorString; + } + String patchString = matcher.group(3); + if (patchString.length() == 1) { + patchString = "0" + patchString; + } + + String numVersionString = majorString + minorString + patchString; + int numVersion = Integer.parseInt(numVersionString); + String packge = versionPackage.substring(0, versionPackage.length() - 1); + + try { + // Add enum value + Field valuesField = new FieldResolver(Version.class).resolve("$VALUES"); + Version[] oldValues = (Version[]) valuesField.get(null); + Version[] newValues = new Version[oldValues.length + 1]; + System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); + Version dynamicVersion = (Version) newEnumInstance(Version.class, new Class[]{ + String.class, + int.class, + int.class + }, new Object[]{ + packge, + newValues.length - 1, + numVersion + }); + newValues[newValues.length - 1] = dynamicVersion; + valuesField.set(null, newValues); + + System.out.println("[ReflectionHelper] Injected dynamic version " + packge + " (#" + numVersion + ")."); + System.out.println("[ReflectionHelper] Please inform inventivegames about the outdated version, as this is not guaranteed to work."); + return dynamicVersion; + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + return UNKNOWN; + } + + /** + * @return the version-number + */ + public int version() { + return version; + } + + /** + * @param version the version to check + * @return true if this version is older than the specified version + */ + public boolean olderThan(Version version) { + return version() < version.version(); + } + + /** + * @param version the version to check + * @return true if this version is newer than the specified version + */ + public boolean newerThan(Version version) { + return version() >= version.version(); + } + + /** + * @param oldVersion The older version to check + * @param newVersion The newer version to check + * @return true if this version is newer than the oldVersion and older that the newVersion + */ + public boolean inRange(Version oldVersion, Version newVersion) { + return newerThan(oldVersion) && olderThan(newVersion); + } + + public boolean matchesPackageName(String packageName) { + return packageName.toLowerCase().contains(name().toLowerCase()); + } + + @Override + public String toString() { + return name() + " (" + version() + ")"; + } + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.java new file mode 100644 index 0000000..1ff62d0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.java @@ -0,0 +1,42 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.ClassWrapper; + +/** + * Default {@link ClassResolver} + */ +public class ClassResolver extends ResolverAbstract { + + public ClassWrapper resolveWrapper(String... names) { + return new ClassWrapper<>(resolveSilent(names)); + } + + public Class resolveSilent(String... names) { + try { + return resolve(names); + } catch (Exception e) { + } + return null; + } + + public Class resolve(String... names) throws ClassNotFoundException { + ResolverQuery.Builder builder = ResolverQuery.builder(); + for (String name : names) + builder.with(name); + try { + return super.resolve(builder.build()); + } catch (ReflectiveOperationException e) { + throw (ClassNotFoundException) e; + } + } + + @Override + protected Class resolveObject(ResolverQuery query) throws ReflectiveOperationException { + return Class.forName(query.getName()); + } + + @Override + protected ClassNotFoundException notFoundException(String joinedNames) { + return new ClassNotFoundException("Could not resolve class for " + joinedNames); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.java new file mode 100644 index 0000000..0f69040 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.java @@ -0,0 +1,106 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.ConstructorWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; + +import java.lang.reflect.Constructor; + +/** + * Resolver for constructors + */ +public class ConstructorResolver extends MemberResolver { + + public ConstructorResolver(Class clazz) { + super(clazz); + } + + public ConstructorResolver(String className) throws ClassNotFoundException { + super(className); + } + + @Override + public Constructor resolveIndex(int index) throws IndexOutOfBoundsException, ReflectiveOperationException { + return AccessUtil.setAccessible(this.clazz.getDeclaredConstructors()[index]); + } + + @Override + public Constructor resolveIndexSilent(int index) { + try { + return resolveIndex(index); + } catch (IndexOutOfBoundsException | ReflectiveOperationException ignored) { + } + return null; + } + + @Override + public ConstructorWrapper resolveIndexWrapper(int index) { + return new ConstructorWrapper<>(resolveIndexSilent(index)); + } + + public ConstructorWrapper resolveWrapper(Class[]... types) { + return new ConstructorWrapper<>(resolveSilent(types)); + } + + public Constructor resolveSilent(Class[]... types) { + try { + return resolve(types); + } catch (Exception e) { + } + return null; + } + + public Constructor resolve(Class[]... types) throws NoSuchMethodException { + ResolverQuery.Builder builder = ResolverQuery.builder(); + for (Class[] type : types) + builder.with(type); + try { + return super.resolve(builder.build()); + } catch (ReflectiveOperationException e) { + throw (NoSuchMethodException) e; + } + } + + @Override + protected Constructor resolveObject(ResolverQuery query) throws ReflectiveOperationException { + return AccessUtil.setAccessible(this.clazz.getDeclaredConstructor(query.getTypes())); + } + + public Constructor resolveFirstConstructor() throws ReflectiveOperationException { + for (Constructor constructor : this.clazz.getDeclaredConstructors()) { + return AccessUtil.setAccessible(constructor); + } + return null; + } + + public Constructor resolveFirstConstructorSilent() { + try { + return resolveFirstConstructor(); + } catch (Exception e) { + } + return null; + } + + public Constructor resolveLastConstructor() throws ReflectiveOperationException { + Constructor constructor = null; + for (Constructor constructor1 : this.clazz.getDeclaredConstructors()) { + constructor = constructor1; + } + if (constructor != null) { + return AccessUtil.setAccessible(constructor); + } + return null; + } + + public Constructor resolveLastConstructorSilent() { + try { + return resolveLastConstructor(); + } catch (Exception e) { + } + return null; + } + + @Override + protected NoSuchMethodException notFoundException(String joinedNames) { + return new NoSuchMethodException("Could not resolve constructor for " + joinedNames + " in class " + this.clazz); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.java new file mode 100644 index 0000000..beec943 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.java @@ -0,0 +1,162 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.FieldWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; + +import java.lang.reflect.Field; + +/** + * Resolver for fields + */ +public class FieldResolver extends MemberResolver { + + public FieldResolver(Class clazz) { + super(clazz); + } + + public FieldResolver(String className) throws ClassNotFoundException { + super(className); + } + + @Override + public Field resolveIndex(int index) throws IndexOutOfBoundsException, ReflectiveOperationException { + return AccessUtil.setAccessible(this.clazz.getDeclaredFields()[index]); + } + + @Override + public Field resolveIndexSilent(int index) { + try { + return resolveIndex(index); + } catch (IndexOutOfBoundsException | ReflectiveOperationException ignored) { + } + return null; + } + + @Override + public FieldWrapper resolveIndexWrapper(int index) { + return new FieldWrapper<>(resolveIndexSilent(index)); + } + + public FieldWrapper resolveWrapper(String... names) { + return new FieldWrapper<>(resolveSilent(names)); + } + + public Field resolveSilent(String... names) { + try { + return resolve(names); + } catch (Exception e) { + } + return null; + } + + public Field resolve(String... names) throws NoSuchFieldException { + ResolverQuery.Builder builder = ResolverQuery.builder(); + for (String name : names) + builder.with(name); + try { + return super.resolve(builder.build()); + } catch (ReflectiveOperationException e) { + throw (NoSuchFieldException) e; + } + } + + public Field resolveSilent(ResolverQuery... queries) { + try { + return resolve(queries); + } catch (Exception e) { + } + return null; + } + + public Field resolve(ResolverQuery... queries) throws NoSuchFieldException { + try { + return super.resolve(queries); + } catch (ReflectiveOperationException e) { + throw (NoSuchFieldException) e; + } + } + + @Override + protected Field resolveObject(ResolverQuery query) throws ReflectiveOperationException { + if (query.getTypes() == null || query.getTypes().length == 0) { + return AccessUtil.setAccessible(this.clazz.getDeclaredField(query.getName())); + } else { + for (Field field : this.clazz.getDeclaredFields()) { + if (field.getName().equals(query.getName())) { + for (Class type : query.getTypes()) { + if (field.getType().equals(type)) { + return field; + } + } + } + } + } + return null; + } + + /** + * Attempts to find the first field of the specified type + * + * @param type Type to find + * @return the Field + * @throws ReflectiveOperationException (usually never) + * @see #resolveByLastType(Class) + */ + public Field resolveByFirstType(Class type) throws ReflectiveOperationException { + for (Field field : this.clazz.getDeclaredFields()) { + if (field.getType().equals(type)) { + return AccessUtil.setAccessible(field); + } + } + throw new NoSuchFieldException("Could not resolve field of type '" + type.toString() + "' in class " + this.clazz); + } + + /** + * Attempts to find the first field of the specified type + * + * @param type Type to find + * @return the Field + * @see #resolveByLastTypeSilent(Class) + */ + public Field resolveByFirstTypeSilent(Class type) { + try { + return resolveByFirstType(type); + } catch (Exception e) { + } + return null; + } + + /** + * Attempts to find the last field of the specified type + * + * @param type Type to find + * @return the Field + * @throws ReflectiveOperationException (usually never) + * @see #resolveByFirstType(Class) + */ + public Field resolveByLastType(Class type) throws ReflectiveOperationException { + Field field = null; + for (Field field1 : this.clazz.getDeclaredFields()) { + if (field1.getType().equals(type)) { + field = field1; + } + } + if (field == null) { + throw new NoSuchFieldException("Could not resolve field of type '" + type.toString() + "' in class " + this.clazz); + } + return AccessUtil.setAccessible(field); + } + + public Field resolveByLastTypeSilent(Class type) { + try { + return resolveByLastType(type); + } catch (Exception e) { + } + return null; + } + + @Override + protected NoSuchFieldException notFoundException(String joinedNames) { + return new NoSuchFieldException("Could not resolve field for " + joinedNames + " in class " + this.clazz); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.java new file mode 100644 index 0000000..9a0aeae --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.java @@ -0,0 +1,56 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.WrapperAbstract; + +import java.lang.reflect.Member; + +/** + * abstract class to resolve members + * + * @param member type + * @see ConstructorResolver + * @see FieldResolver + * @see MethodResolver + */ +public abstract class MemberResolver extends ResolverAbstract { + + protected Class clazz; + + public MemberResolver(Class clazz) { + if (clazz == null) { + throw new IllegalArgumentException("class cannot be null"); + } + this.clazz = clazz; + } + + public MemberResolver(String className) throws ClassNotFoundException { + this(new ClassResolver().resolve(className)); + } + + /** + * Resolve a member by its index + * + * @param index index + * @return the member + * @throws IndexOutOfBoundsException if the specified index is out of the available member bounds + * @throws ReflectiveOperationException if the object could not be set accessible + */ + public abstract T resolveIndex(int index) throws IndexOutOfBoundsException, ReflectiveOperationException; + + /** + * Resolve member by its index (without exceptions) + * + * @param index index + * @return the member or null + */ + public abstract T resolveIndexSilent(int index); + + /** + * Resolce member wrapper by its index + * + * @param index index + * @return the wrapped member + */ + public abstract WrapperAbstract resolveIndexWrapper(int index); + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.java new file mode 100644 index 0000000..99ee2c4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.java @@ -0,0 +1,130 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper.MethodWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util.AccessUtil; + +import java.lang.reflect.Method; + +/** + * Resolver for methods + */ +public class MethodResolver extends MemberResolver { + + public MethodResolver(Class clazz) { + super(clazz); + } + + public MethodResolver(String className) throws ClassNotFoundException { + super(className); + } + + static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) { + return false; + } + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } + + public Method resolveSignature(String... signatures) throws ReflectiveOperationException { + for (Method method : clazz.getDeclaredMethods()) { + String methodSignature = MethodWrapper.getMethodSignature(method); + for (String s : signatures) { + if (s.equals(methodSignature)) { + return AccessUtil.setAccessible(method); + } + } + } + return null; + } + + public Method resolveSignatureSilent(String... signatures) { + try { + return resolveSignature(signatures); + } catch (ReflectiveOperationException ignored) { + } + return null; + } + + public MethodWrapper resolveSignatureWrapper(String... signatures) { + return new MethodWrapper(resolveSignatureSilent(signatures)); + } + + @Override + public Method resolveIndex(int index) throws IndexOutOfBoundsException, ReflectiveOperationException { + return AccessUtil.setAccessible(this.clazz.getDeclaredMethods()[index]); + } + + @Override + public Method resolveIndexSilent(int index) { + try { + return resolveIndex(index); + } catch (IndexOutOfBoundsException | ReflectiveOperationException ignored) { + } + return null; + } + + @Override + public MethodWrapper resolveIndexWrapper(int index) { + return new MethodWrapper<>(resolveIndexSilent(index)); + } + + public MethodWrapper resolveWrapper(String... names) { + return new MethodWrapper<>(resolveSilent(names)); + } + + public MethodWrapper resolveWrapper(ResolverQuery... queries) { + return new MethodWrapper<>(resolveSilent(queries)); + } + + public Method resolveSilent(String... names) { + try { + return resolve(names); + } catch (Exception e) { + } + return null; + } + + @Override + public Method resolveSilent(ResolverQuery... queries) { + return super.resolveSilent(queries); + } + + public Method resolve(String... names) throws NoSuchMethodException { + ResolverQuery.Builder builder = ResolverQuery.builder(); + for (String name : names) { + builder.with(name); + } + return resolve(builder.build()); + } + + @Override + public Method resolve(ResolverQuery... queries) throws NoSuchMethodException { + try { + return super.resolve(queries); + } catch (ReflectiveOperationException e) { + throw (NoSuchMethodException) e; + } + } + + @Override + protected Method resolveObject(ResolverQuery query) throws ReflectiveOperationException { + for (Method method : this.clazz.getDeclaredMethods()) { + if (method.getName().equals(query.getName()) && (query.getTypes().length == 0 || ClassListEqual(query.getTypes(), method.getParameterTypes()))) { + return AccessUtil.setAccessible(method); + } + } + throw new NoSuchMethodException(); + } + + @Override + protected NoSuchMethodException notFoundException(String joinedNames) { + return new NoSuchMethodException("Could not resolve method for " + joinedNames + " in class " + this.clazz); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.java new file mode 100644 index 0000000..b4b5e98 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.java @@ -0,0 +1,73 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Abstract resolver class + * + * @param resolved type + * @see ClassResolver + * @see ConstructorResolver + * @see FieldResolver + * @see MethodResolver + */ +public abstract class ResolverAbstract { + + protected final Map resolvedObjects = new ConcurrentHashMap(); + + /** + * Same as {@link #resolve(ResolverQuery...)} but throws no exceptions + * + * @param queries Array of possible queries + * @return the resolved object if it was found, null otherwise + */ + protected T resolveSilent(ResolverQuery... queries) { + try { + return resolve(queries); + } catch (Exception e) { + } + return null; + } + + /** + * Attempts to resolve an array of possible queries to an object + * + * @param queries Array of possible queries + * @return the resolved object (if it was found) + * @throws ReflectiveOperationException if none of the possibilities could be resolved + * @throws IllegalArgumentException if the given possibilities are empty + */ + protected T resolve(ResolverQuery... queries) throws ReflectiveOperationException { + if (queries == null || queries.length <= 0) { + throw new IllegalArgumentException("Given possibilities are empty"); + } + for (ResolverQuery query : queries) { + //Object is already resolved, return it directly + if (resolvedObjects.containsKey(query)) { + return resolvedObjects.get(query); + } + + //Object is not yet resolved, try to find it + try { + T resolved = resolveObject(query); + //Store if it was found + resolvedObjects.put(query, resolved); + return resolved; + } catch (ReflectiveOperationException e) { + //Not found, ignore the exception + } + } + + //Couldn't find any of the possibilities + throw notFoundException(Arrays.asList(queries).toString()); + } + + protected abstract T resolveObject(ResolverQuery query) throws ReflectiveOperationException; + + protected ReflectiveOperationException notFoundException(String joinedNames) { + return new ReflectiveOperationException("Objects could not be resolved: " + joinedNames); + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.java new file mode 100644 index 0000000..0a7efd5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.java @@ -0,0 +1,107 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Container class for resolver-queries Used by {@link MethodResolver} + * + * @see org.inventivetalent.reflection.resolver.ResolverQuery.Builder + */ +public class ResolverQuery { + + private String name; + private final Class[] types; + + public ResolverQuery(String name, Class... types) { + this.name = name; + this.types = types; + } + + public ResolverQuery(String name) { + this.name = name; + this.types = new Class[0]; + } + + public ResolverQuery(Class... types) { + this.types = types; + } + + public static Builder builder() { + return new Builder(); + } + + public String getName() { + return name; + } + + public Class[] getTypes() { + return types; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ResolverQuery that = (ResolverQuery) o; + + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + // Probably incorrect - comparing Object[] arrays with Arrays.equals + return Arrays.equals(types, that.types); + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (types != null ? Arrays.hashCode(types) : 0); + return result; + } + + @Override + public String toString() { + return "ResolverQuery{" + + "name='" + name + '\'' + + ", types=" + Arrays.toString(types) + + '}'; + } + + /** + * Builder class for {@link ResolverQuery} Access using {@link ResolverQuery#builder()} + */ + public static class Builder { + + private final List queryList = new ArrayList(); + + private Builder() { + } + + public Builder with(String name, Class[] types) { + queryList.add(new ResolverQuery(name, types)); + return this; + } + + public Builder with(String name) { + queryList.add(new ResolverQuery(name)); + return this; + } + + public Builder with(Class[] types) { + queryList.add(new ResolverQuery(types)); + return this; + } + + public ResolverQuery[] build() { + return queryList.toArray(new ResolverQuery[0]); + } + + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.java new file mode 100644 index 0000000..ab5cd0a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ClassResolver; + +/** + * {@link ClassResolver} for net.minecraft.server.* classes + */ +public class NMSClassResolver extends ClassResolver { + + @Override + public Class resolve(String... names) throws ClassNotFoundException { + for (int i = 0; i < names.length; i++) { + if (!names[i].startsWith("net.minecraft.server")) { + names[i] = "net.minecraft.server." + Minecraft.getVersion() + names[i]; + } + } + return super.resolve(names); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.java new file mode 100644 index 0000000..b09d146 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.minecraft; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.minecraft.Minecraft; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.ClassResolver; + +/** + * {@link ClassResolver} for org.bukkit.craftbukkit.* classes + */ +public class OBCClassResolver extends ClassResolver { + + @Override + public Class resolve(String... names) throws ClassNotFoundException { + for (int i = 0; i < names.length; i++) { + if (!names[i].startsWith("org.bukkit.craftbukkit")) { + names[i] = "org.bukkit.craftbukkit." + Minecraft.getVersion() + names[i]; + } + } + return super.resolve(names); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.java new file mode 100644 index 0000000..412727e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.java @@ -0,0 +1,59 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper; + +public class ClassWrapper extends WrapperAbstract { + + private final Class clazz; + + public ClassWrapper(Class clazz) { + this.clazz = clazz; + } + + @Override + public boolean exists() { + return this.clazz != null; + } + + public Class getClazz() { + return clazz; + } + + public String getName() { + return this.clazz.getName(); + } + + public R newInstance() { + try { + return this.clazz.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public R newInstanceSilent() { + try { + return this.clazz.newInstance(); + } catch (Exception e) { + } + return null; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + + ClassWrapper that = (ClassWrapper) object; + + return clazz != null ? clazz.equals(that.clazz) : that.clazz == null; + + } + + @Override + public int hashCode() { + return clazz != null ? clazz.hashCode() : 0; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.java new file mode 100644 index 0000000..a893fbf --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.java @@ -0,0 +1,61 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper; + +import java.lang.reflect.Constructor; + +public class ConstructorWrapper extends WrapperAbstract { + + private final Constructor constructor; + + public ConstructorWrapper(Constructor constructor) { + this.constructor = constructor; + } + + @Override + public boolean exists() { + return this.constructor != null; + } + + public R newInstance(Object... args) { + try { + return this.constructor.newInstance(args); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public R newInstanceSilent(Object... args) { + try { + return this.constructor.newInstance(args); + } catch (Exception e) { + } + return null; + } + + public Class[] getParameterTypes() { + return this.constructor.getParameterTypes(); + } + + public Constructor getConstructor() { + return constructor; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + + ConstructorWrapper that = (ConstructorWrapper) object; + + return constructor != null ? constructor.equals(that.constructor) : that.constructor == null; + + } + + @Override + public int hashCode() { + return constructor != null ? constructor.hashCode() : 0; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.java new file mode 100644 index 0000000..690da8c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.java @@ -0,0 +1,75 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper; + +import java.lang.reflect.Field; + +public class FieldWrapper extends WrapperAbstract { + + private final Field field; + + public FieldWrapper(Field field) { + this.field = field; + } + + @Override + public boolean exists() { + return this.field != null; + } + + public String getName() { + return this.field.getName(); + } + + public R get(Object object) { + try { + return (R) this.field.get(object); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public R getSilent(Object object) { + try { + return (R) this.field.get(object); + } catch (Exception e) { + } + return null; + } + + public void set(Object object, R value) { + try { + this.field.set(object, value); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void setSilent(Object object, R value) { + try { + this.field.set(object, value); + } catch (Exception e) { + } + } + + public Field getField() { + return field; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + + FieldWrapper that = (FieldWrapper) object; + + return field != null ? field.equals(that.field) : that.field == null; + } + + @Override + public int hashCode() { + return field != null ? field.hashCode() : 0; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.java new file mode 100644 index 0000000..1555dd8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.java @@ -0,0 +1,292 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MethodWrapper extends WrapperAbstract { + + private final Method method; + + public MethodWrapper(Method method) { + this.method = method; + } + + /** + * Generates a method's signature. + * + * @param method the method to get the signature for + * @param fullClassNames whether to use the full class name + * @return the method's signature + */ + public static String getMethodSignature(Method method, boolean fullClassNames) { + // StringBuilder stringBuilder = new StringBuilder(); + // + // Class returnType = method.getReturnType(); + // if (returnType.isPrimitive()) { + // stringBuilder.append(returnType); + // } else { + // stringBuilder.append(fullClassNames ? returnType.getName() : returnType.getSimpleName()); + // } + // stringBuilder.append(" "); + // stringBuilder.append(method.getName()); + // + // stringBuilder.append("("); + // + // boolean first = true; + // for (Class clazz : method.getParameterTypes()) { + // if (!first) { stringBuilder.append(","); } + // stringBuilder.append(fullClassNames ? clazz.getName() : clazz.getSimpleName()); + // first = false; + // } + // return stringBuilder.append(")").toString(); + + return MethodSignature.of(method, fullClassNames).getSignature(); + } + + /** + * @param method Method to get the signature for + * @return the signature + * @see #getMethodSignature(Method, boolean) + */ + public static String getMethodSignature(Method method) { + return getMethodSignature(method, false); + } + + @Override + public boolean exists() { + return this.method != null; + } + + public String getName() { + return this.method.getName(); + } + + public R invoke(Object object, Object... args) { + try { + return (R) this.method.invoke(object, args); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public R invokeSilent(Object object, Object... args) { + try { + return (R) this.method.invoke(object, args); + } catch (Exception e) { + } + return null; + } + + public Method getMethod() { + return method; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + + MethodWrapper that = (MethodWrapper) object; + + return method != null ? method.equals(that.method) : that.method == null; + + } + + @Override + public int hashCode() { + return method != null ? method.hashCode() : 0; + } + + public static class MethodSignature { + static final Pattern SIGNATURE_STRING_PATTERN = Pattern.compile("(.+) (.*)\\((.*)\\)"); + + private final String returnType; + private final Pattern returnTypePattern; + private final String name; + private final Pattern namePattern; + private final String[] parameterTypes; + private final String signature; + + public MethodSignature(String returnType, String name, String[] parameterTypes) { + this.returnType = returnType; + this.returnTypePattern = Pattern.compile(returnType + .replace("?", "\\w") + .replace("*", "\\w*") + .replace("[", "\\[") + .replace("]", "\\]")); + this.name = name; + this.namePattern = Pattern.compile(name.replace("?", "\\w").replace("*", "\\w*")); + this.parameterTypes = parameterTypes; + + StringBuilder builder = new StringBuilder(); + builder.append(returnType).append(" ").append(name).append("("); + boolean first = true; + for (String parameterType : parameterTypes) { + if (!first) { + builder.append(","); + } + builder.append(parameterType); + first = false; + } + this.signature = builder.append(")").toString(); + } + + public static MethodSignature of(Method method, boolean fullClassNames) { + Class returnType = method.getReturnType(); + Class[] parameterTypes = method.getParameterTypes(); + + String returnTypeString; + if (returnType.isPrimitive()) { + returnTypeString = returnType.toString(); + } else { + returnTypeString = fullClassNames ? returnType.getName() : returnType.getSimpleName(); + } + String methodName = method.getName(); + String[] parameterTypeStrings = new String[parameterTypes.length]; + for (int i = 0; i < parameterTypeStrings.length; i++) { + if (parameterTypes[i].isPrimitive()) { + parameterTypeStrings[i] = parameterTypes[i].toString(); + } else { + parameterTypeStrings[i] = fullClassNames ? parameterTypes[i].getName() : parameterTypes[i].getSimpleName(); + } + } + + return new MethodSignature(returnTypeString, methodName, parameterTypeStrings); + } + + public static MethodSignature fromString(String signatureString) { + if (signatureString == null) { + return null; + } + Matcher matcher = SIGNATURE_STRING_PATTERN.matcher(signatureString); + if (matcher.find()) { + if (matcher.groupCount() != 3) { + throw new IllegalArgumentException("invalid signature"); + } + return new MethodSignature(matcher.group(1), matcher.group(2), matcher.group(3).split(",")); + } else { + throw new IllegalArgumentException("invalid signature"); + } + } + + public String getReturnType() { + return returnType; + } + + public boolean isReturnTypeWildcard() { + return "?".equals(returnType) || "*".equals(returnType); + } + + public String getName() { + return name; + } + + public boolean isNameWildcard() { + return "?".equals(name) || "*".equals(name); + } + + public String[] getParameterTypes() { + return parameterTypes; + } + + public String getParameterType(int index) throws IndexOutOfBoundsException { + return parameterTypes[index]; + } + + public boolean isParameterWildcard(int index) throws IndexOutOfBoundsException { + return "?".equals(getParameterType(index)) || "*".equals(getParameterType(index)); + } + + public String getSignature() { + return signature; + } + + /** + * Checks whether this signature matches another signature. Wildcards are checked in this signature, but not the other signature. + * + * @param other signature to check + * @return whether the signatures match + */ + public boolean matches(MethodSignature other) { + if (other == null) { + return false; + } + + // if (!returnType.equals(other.returnType)) { + // if (!isReturnTypeWildcard()) { return false; } + // } + // if (!name.equals(other.name)) { + // if (!isNameWildcard()) { return false; } + // } + // if (parameterTypes.length != other.parameterTypes.length) { return false; } + // for (int i = 0; i < parameterTypes.length; i++) { + // if (!getParameterType(i).equals(other.getParameterType(i))) { + // if (!isParameterWildcard(i)) { return false; } + // } + // } + + if (!returnTypePattern.matcher(other.returnType).matches()) { + return false; + } + if (!namePattern.matcher(other.name).matches()) { + return false; + } + if (parameterTypes.length != other.parameterTypes.length) { + return false; + } + for (int i = 0; i < parameterTypes.length; i++) { + if (!Pattern.compile(getParameterType(i).replace("?", "\\w").replace("*", "\\w*")).matcher(other.getParameterType(i)).matches()) { + return false; + } + } + + return true; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + MethodSignature signature1 = (MethodSignature) o; + + if (!returnType.equals(signature1.returnType)) { + return false; + } + if (!name.equals(signature1.name)) { + return false; + } + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(parameterTypes, signature1.parameterTypes)) { + return false; + } + return signature.equals(signature1.signature); + + } + + @Override + public int hashCode() { + int result = returnType.hashCode(); + result = 31 * result + name.hashCode(); + result = 31 * result + Arrays.hashCode(parameterTypes); + result = 31 * result + signature.hashCode(); + return result; + } + + @Override + public String toString() { + return getSignature(); + } + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.java new file mode 100644 index 0000000..96c6b0f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.java @@ -0,0 +1,12 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.resolver.wrapper; + +public abstract class WrapperAbstract { + + /** + * Check whether the wrapped object exists (i.e. is not null) + * + * @return true if the wrapped object exists + */ + public abstract boolean exists(); + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.java new file mode 100644 index 0000000..d77a2fe --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.reflection.util; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * Helper class to set fields, methods & constructors accessible + */ +public abstract class AccessUtil { + + /** + * Sets the field accessible and removes final modifiers + * + * @param field Field to set accessible + * @return the Field + * @throws ReflectiveOperationException (usually never) + */ + public static Field setAccessible(Field field) throws ReflectiveOperationException { + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & 0xFFFFFFEF); + return field; + } + + /** + * Sets the method accessible + * + * @param method Method to set accessible + * @return the Method + * @throws ReflectiveOperationException (usually never) + */ + public static Method setAccessible(Method method) throws ReflectiveOperationException { + method.setAccessible(true); + return method; + } + + /** + * Sets the constructor accessible + * + * @param constructor Constructor to set accessible + * @return the Constructor + * @throws ReflectiveOperationException (usually never) + */ + public static Constructor setAccessible(Constructor constructor) throws ReflectiveOperationException { + constructor.setAccessible(true); + return constructor; + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.java new file mode 100644 index 0000000..1361bc8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch; + +public enum TouchAction { + + RIGHT_CLICK, + LEFT_CLICK, + UNKNOWN; + + public static TouchAction fromUseAction(Object useAction) { + if (useAction == null) { + return UNKNOWN; + } + int i = ((Enum) useAction).ordinal(); + switch (i) { + case 0: + return RIGHT_CLICK; + case 1: + return LEFT_CLICK; + default: + break; + } + return UNKNOWN; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.java new file mode 100644 index 0000000..77248f0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.java @@ -0,0 +1,12 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.touch; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnull; + +public interface TouchHandler { + + void onTouch(@Nonnull Hologram hologram, @Nonnull Player player, @Nonnull TouchAction action); + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.java new file mode 100644 index 0000000..98cb9e7 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.java @@ -0,0 +1,232 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.types; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.PlayerTop; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.view.ViewHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import lombok.Getter; +import lombok.Setter; +import lombok.val; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +public class SimpleHologram { + + private String name, display; + private DataCategory dataCategory; + private DataType dataType; + private List topList; + private final ViewHandler defaultViewHandler = (hologram, player, string) -> { + int topId = Integer.parseInt(hologram.getName().replace("top", "").replace("-", "").replace(getName(), "")); + + PlayerTop playerTop = getTopList().get(topId - 1); + + return string.replace("%position%", "" + topId).replace("%playerName%", playerTop.getPlayerName()).replace("%value%", "" + playerTop.getValue()); + }; + private boolean created, updating; + private Plugin instance; + + public SimpleHologram(String name, String display, DataCategory dataCategory, DataType dataType, Plugin instance) { + this.name = name; + this.display = display; + this.dataCategory = dataCategory; + this.dataType = dataType; + this.instance = instance; + this.created = false; + this.updating = false; + this.topList = new ArrayList<>(); + } + + public void create() { + create("world"); + } + + public void recreate() { + if (isCreated()) { + for (Hologram holograms : HologramAPI.getHolograms()) { + String holoName = holograms.getName().toLowerCase(); + + if (holoName.equalsIgnoreCase("titulo-" + getName().toLowerCase())) { + holograms.update(); + } else if ((holoName.startsWith("top")) && (holoName.contains(getName().toLowerCase())) && (holoName.contains("-"))) { + holograms.update(); + } else if (holoName.contains("blank") && holoName.contains(getName().toLowerCase())) { + holograms.update(); + } + } + } + + create(); + } + + public void create(final String worldName) { + if (isCreated()) return; + + PluginConfiguration.createLocation(getInstance(), "hologramas." + getName().toLowerCase(), worldName); + + Location location = PluginConfiguration.getLocation(getInstance(), "hologramas." + getName().toLowerCase()); + assert location != null; + + World world = location.getWorld(); + + double y = location.getY(); + + Hologram title = HologramAPI.createHologram("titulo-" + getName().toLowerCase(), location, + "§e§lTOP 10 §b§l" + getDisplay().toUpperCase() + "§7(1/1)"); + y = y -= 0.25; + + title.spawn(); + + title.addLineBelow("blank-" + getName().toLowerCase(), ""); + + y = y -= 0.25; + + Hologram top1 = + HologramAPI.createHologram("top1-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top1.addViewHandler(defaultViewHandler); + + top1.spawn(); + y = y -= 0.25; + + Hologram top2 = + HologramAPI.createHologram("top2-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top2.addViewHandler(defaultViewHandler); + top2.spawn(); + y = y -= 0.25; + + Hologram top3 = + HologramAPI.createHologram("top3-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top3.addViewHandler(defaultViewHandler); + top3.spawn(); + y = y -= 0.25; + + Hologram top4 = + HologramAPI.createHologram("top4-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top4.addViewHandler(defaultViewHandler); + top4.spawn(); + y = y -= 0.25; + + Hologram top5 = + HologramAPI.createHologram("top5-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top5.addViewHandler(defaultViewHandler); + top5.spawn(); + y = y -= 0.25; + + Hologram top6 = + HologramAPI.createHologram("top6-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top6.addViewHandler(defaultViewHandler); + top6.spawn(); + y = y -= 0.25; + + Hologram top7 = + HologramAPI.createHologram("top7-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top7.addViewHandler(defaultViewHandler); + top7.spawn(); + y = y -= 0.25; + + Hologram top8 = + HologramAPI.createHologram("top8-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top8.addViewHandler(defaultViewHandler); + top8.spawn(); + y = y -= 0.25; + + Hologram top9 = + HologramAPI.createHologram("top9-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top9.addViewHandler(defaultViewHandler); + top9.spawn(); + y = y -= 0.25; + + Hologram top10 = + HologramAPI.createHologram("top10-" + getName(), new Location(world, location.getX(), y, location.getZ()), "§e%position%. %playerName% §7- §e%value%"); + top10.addViewHandler(defaultViewHandler); + top10.spawn(); + + setCreated(true); + } + + public void updateValues() { + this.updating = true; + + new Thread(() -> { + List updated = new ArrayList<>(); + + String fieldReference = "data>'$.\"" + getDataType().getField() + "\"" + "'"; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection.prepareStatement( + "SELECT nick,data" + " FROM " + getDataCategory().getTableName() + " ORDER BY " + fieldReference + " DESC"); + + ResultSet result = preparedStatament.executeQuery(); + + int id = 0; + + while (result.next()) { + id++; + + String playerName = result.getString("nick"); + + UUID uniqueId = CommonsGeneral.getUUIDFetcher().getOfflineUUID(playerName); + + GamingProfile profile = CommonsGeneral.getProfileManager().getGamingProfile(uniqueId); + + if (profile == null) { + profile = new GamingProfile(playerName, uniqueId); + + if (getDataCategory() != DataCategory.ACCOUNT) { + if (!profile.getDataHandler().isCategoryLoaded(DataCategory.ACCOUNT)) { + profile.getDataHandler().load(DataCategory.ACCOUNT); + } + } + + profile.getDataHandler().loadFromJSONString(getDataCategory(), result.getString("data")); + } + + Groups group = profile.getGroup(); + val top = new PlayerTop(group.getTag().getColor() + playerName, profile.getInt(getDataType())); + + if(updated.isEmpty()) updated.add(top); + else if(!updated.get(updated.size() - 1).getPlayerName().equals(top.getPlayerName())) updated.add(top); + } + + result.close(); + preparedStatament.close(); + + while (id < 10) { + id++; + updated.add(new PlayerTop("§7Ninguém", 0)); + } + + topList.clear(); + + updated.sort(PlayerTop::compareTo); + topList.addAll(updated.subList(0, 10)); + recreate(); + + updated.clear(); + + this.updating = false; + } catch (SQLException ex) { + BukkitMain.console("§cOcorreu um erro ao tentar atualizar o TOP 10 '" + getName().toUpperCase() + "' -> " + ex.getLocalizedMessage()); + ex.printStackTrace(); + } + }).start(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.java new file mode 100644 index 0000000..233ddcc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.view; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnull; + +public interface ViewHandler { + + /** + * Called when a {@link Hologram} is viewed by a player + * + * @param hologram viewed {@link Hologram} + * @param player viewer + * @param string content of the hologram + * @return The new/modified content of the hologram + */ + String onView(@Nonnull Hologram hologram, @Nonnull Player player, @Nonnull String string); + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.java new file mode 100644 index 0000000..571eed3 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.java @@ -0,0 +1,50 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.item; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack.InteractHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.listeners.CoreListener; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class ActionItemListener implements Listener { + + @EventHandler(priority = EventPriority.LOWEST) + public void onInteract(PlayerInteractEvent event) { + if (event.getItem() == null) + return; + + ItemStack itemStack = event.getItem(); + + try { + if (itemStack == null || itemStack.getType() == Material.AIR) + throw new Exception(); + + Player player = event.getPlayer(); + Action action = event.getAction(); + + if (itemStack.getType() == Material.MUSHROOM_SOUP && action.name().contains("RIGHT")) { + event.setCancelled(CoreListener.handleSoup(player)); + throw new Exception(); + } + + + if (!itemStack.hasItemMeta()) { + throw new Exception(); + } + + final String displayName = itemStack.getItemMeta().getDisplayName(); + InteractHandler handler = ActionItemStack.getHandler(itemStack.getItemMeta().getDisplayName()); + + if (handler == null) { + throw new NullPointerException("Handler com o nome " + displayName + " com InteractHandler nulo!"); + } + event.setCancelled(handler.onInteract(player, itemStack, action, event.getClickedBlock())); + } catch (Exception ex) { + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.java new file mode 100644 index 0000000..66bb3d6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.java @@ -0,0 +1,37 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.item; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; + +public class ActionItemStack { + + private static HashMap handlers = null; + + public static void register(final ItemStack itemStack, final InteractHandler handler) { + register(itemStack.getItemMeta().getDisplayName(), handler); + } + + public static void register(final String itemName, final InteractHandler handler) { + if (handlers == null) + handlers = new HashMap<>(); + + handlers.put(itemName, handler); + } + + public static void unregister(final String itemName) { + handlers.remove(itemName); + } + + public static InteractHandler getHandler(final String itemName) { + return handlers.get(itemName); + } + + public interface InteractHandler { + + boolean onInteract(Player player, ItemStack itemStack, Action action, Block clickedBlock); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.java new file mode 100644 index 0000000..a2f219d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.java @@ -0,0 +1,314 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.item; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.NBTTagList; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; + +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.Map.Entry; + +public class ItemBuilder { + + private Material material; + private int amount; + private short durability; + private boolean useMeta; + private boolean glow; + private String displayName; + private HashMap enchantments; + private List lore; + + private Color color; + private String skinOwner; + private String skinUrl; + + private boolean hideAttributes; + private boolean unbreakable; + + private NBTTagCompound basicNBT; + private NBTTagList enchNBT; + + public ItemBuilder() { + material = Material.STONE; + amount = 1; + durability = 0; + hideAttributes = false; + unbreakable = false; + useMeta = false; + glow = false; + } + + public static ItemBuilder fromStack(ItemStack stack) { + ItemBuilder builder = new ItemBuilder().type(stack.getType()).amount(stack.getAmount()) + .durability(stack.getDurability()); + + if (stack.hasItemMeta()) { + ItemMeta meta = stack.getItemMeta(); + + if (meta.hasDisplayName()) + builder.name(meta.getDisplayName()); + + if (meta.hasLore()) + builder.lore(meta.getLore()); + + if (meta instanceof LeatherArmorMeta) { + Color color = ((LeatherArmorMeta) meta).getColor(); + if (color != null) + builder.color(color); + } + + if (meta instanceof SkullMeta) { + SkullMeta sm = (SkullMeta) meta; + if (sm.hasOwner()) + builder.skin(sm.getOwner()); + } + } + + return builder; + } + + public ItemBuilder type(Material material) { + this.material = material; + return this; + } + + public ItemBuilder material(Material material) { + this.material = material; + return this; + } + + public ItemBuilder amount(int amount) { + if (amount > material.getMaxStackSize()) + amount = material.getMaxStackSize(); + if (amount <= 0) + amount = 1; + this.amount = amount; + return this; + } + + public ItemBuilder durability(short durability) { + this.durability = durability; + return this; + } + + public ItemBuilder durability(int durability) { + this.durability = (short) durability; + return this; + } + + public ItemBuilder name(String text) { + if (!useMeta) { + useMeta = true; + } + this.displayName = text.replace("&", "§"); + return this; + } + + public ItemBuilder enchantment(Enchantment enchantment) { + return enchantment(enchantment, 1); + } + + public ItemBuilder enchantment(Enchantment enchantment, Integer level) { + if (enchantments == null) { + enchantments = new HashMap<>(); + } + + if (level == 0) + return this; + + enchantments.put(enchantment, level); + return this; + } + + public ItemBuilder lore(String... lore) { + return lore(Arrays.asList(lore)); + } + + public ItemBuilder lore(List text) { + if (!this.useMeta) this.useMeta = true; + if (this.lore == null) this.lore = new ArrayList<>(); + + for (String str : text) { + if (str.contains("\n")) { + this.lore.add(str.replace("\n", "")); + + this.lore.add(""); + } else { + this.lore.add(str); + } + } + return this; + } + + public ItemBuilder color(Color color) { + this.useMeta = true; + this.color = color; + return this; + } + + public ItemBuilder skin(String skin) { + this.useMeta = true; + this.skinOwner = skin; + this.durability = 3; + return this; + } + + public ItemBuilder skinURL(String skinURL) { + this.useMeta = true; + this.skinUrl = skinURL; + return this; + } + + public ItemBuilder hideAttributes() { + this.useMeta = true; + this.hideAttributes = true; + return this; + } + + public ItemBuilder showAttributes() { + this.useMeta = true; + this.hideAttributes = false; + return this; + } + + public ItemBuilder unbreakable() { + this.unbreakable = true; + return this; + } + + public ItemStack build() { + ItemStack stack = new ItemStack(material, amount, durability); + + if (enchantments != null && !enchantments.isEmpty()) { + for (Entry entry : enchantments.entrySet()) { + stack.addUnsafeEnchantment(entry.getKey(), entry.getValue()); + } + } + + if (useMeta) { + ItemMeta meta = stack.getItemMeta(); + + if (displayName != null) { + meta.setDisplayName(displayName.replace("&", "§")); + } + + if (lore != null && !lore.isEmpty()) { + meta.setLore(lore); + } + + /** Colored Leather Armor */ + if (color != null) { + if (meta instanceof LeatherArmorMeta) { + ((LeatherArmorMeta) meta).setColor(color); + } + } + + /** Skull Heads */ + if (meta instanceof SkullMeta) { + SkullMeta skullMeta = (SkullMeta) meta; + if (skinUrl != null) { + GameProfile profile = new GameProfile(UUID.randomUUID(), null); + profile.getProperties().put("textures", + new Property("textures", + Base64.getEncoder() + .encodeToString(String.format("{textures:{SKIN:{url:\"%s\"}}}", skinUrl) + .getBytes(StandardCharsets.UTF_8)))); + try { + Field field = skullMeta.getClass().getDeclaredField("profile"); + field.setAccessible(true); + field.set(skullMeta, profile); + } catch (Exception e) { + e.printStackTrace(); + } + } else if (skinOwner != null) { + skullMeta.setOwner(skinOwner); + } + } + + meta.spigot().setUnbreakable(unbreakable); + + /** Item Flags */ + if (hideAttributes) { + meta.addItemFlags(ItemFlag.values()); + } else { + meta.removeItemFlags(ItemFlag.values()); + } + + stack.setItemMeta(meta); + } + + if (glow && (enchantments == null || enchantments.isEmpty())) { + net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); + if (nmsStack.hasTag()) { + nmsStack.getTag().set("ench", this.enchNBT); + } else { + nmsStack.setTag(this.basicNBT); + } + stack = CraftItemStack.asCraftMirror(nmsStack); + } + + material = Material.STONE; + amount = 1; + durability = 0; + + if (useMeta) { + useMeta = false; + } + + if (glow) { + glow = false; + } + + if (hideAttributes) { + hideAttributes = false; + } + + if (unbreakable) { + unbreakable = false; + } + + if (displayName != null) { + displayName = null; + } + + if (enchantments != null) { + enchantments.clear(); + enchantments = null; + } + + if (lore != null) { + lore.clear(); + lore = null; + } + + skinOwner = null; + skinUrl = null; + color = null; + this.basicNBT = null; + this.enchNBT = null; + + return stack; + } + + public ItemBuilder glow() { + this.glow = true; + + this.basicNBT = new NBTTagCompound(); + this.enchNBT = new NBTTagList(); + this.basicNBT.set("ench", this.enchNBT); + + return this; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.java new file mode 100644 index 0000000..dc10f6a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.item; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.inventory.ItemStack; + +@Getter +@Setter +public class ItemChance { + + private int chance; + private ItemStack item; + private int randomStack; + + public ItemChance(ItemStack item, int chance, int randomStack) { + this.item = item; + this.chance = chance; + this.randomStack = randomStack; + } + + public ItemStack getItem() { + if (randomStack != 0) + return new ItemBuilder().type(item.getType()).durability(item.getDurability()). + amount(CommonsConst.RANDOM.nextInt(randomStack) + 1).build(); + return item; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.java new file mode 100644 index 0000000..10d3bc7 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.java @@ -0,0 +1,5 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +public enum ClickType { + LEFT, RIGHT +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.java new file mode 100644 index 0000000..b404f26 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.java @@ -0,0 +1,10 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public interface MenuClickHandler { + + void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.java new file mode 100644 index 0000000..f9d3d94 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.java @@ -0,0 +1,38 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +class MenuHolder implements InventoryHolder { + + private MenuInventory menu; + + public MenuHolder(MenuInventory menuInventory) { + this.menu = menuInventory; + } + + public MenuInventory getMenu() { + return menu; + } + + public void setMenu(MenuInventory menu) { + this.menu = menu; + } + + public boolean isOnePerPlayer() { + return menu.isOnePerPlayer(); + } + + public void destroy() { + menu = null; + } + + @Override + public Inventory getInventory() { + if (isOnePerPlayer()) { + return null; + } else { + return menu.getInventory(); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.java new file mode 100644 index 0000000..0380ba2 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.java @@ -0,0 +1,154 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; + +public class MenuInventory { + + private final HashMap slotItem; + private final int rows; + private String title; + private Inventory inv; + private final boolean onePerPlayer; + + public MenuInventory(String title, int rows) { + this(title, rows, false); + } + + public MenuInventory(String title, int rows, boolean onePerPlayer) { + this.slotItem = new HashMap<>(); + this.rows = rows; + this.title = title; + this.onePerPlayer = onePerPlayer; + if (!onePerPlayer) { + this.inv = Bukkit.createInventory(new MenuHolder(this), rows * 9, this.title); + } + } + + public void addItem(MenuItem item) { + setItem(firstEmpty(), item); + } + + public void addItem(ItemStack item) { + setItem(firstEmpty(), item); + } + + public void setItem(ItemStack item, int slot) { + setItem(slot, new MenuItem(item)); + } + + public void setItem(int slot, ItemStack item) { + setItem(slot, new MenuItem(item)); + } + + public void setItem(int slot, ItemStack item, MenuClickHandler handler) { + setItem(slot, new MenuItem(item, handler)); + } + + public void setItem(MenuItem item, int slot) { + setItem(slot, item); + } + + public void setItem(int slot, MenuItem item) { + this.slotItem.put(slot, item); + if (!onePerPlayer) { + inv.setItem(slot, item.getStack()); + } + } + + public int firstEmpty() { + if (!onePerPlayer) { + return inv.firstEmpty(); + } else { + for (int i = 0; i < rows * 9; i++) { + if (!slotItem.containsKey(i)) { + return i; + } + } + return -1; + } + } + + public boolean hasItem(int slot) { + return this.slotItem.containsKey(slot); + } + + public MenuItem getItem(int slot) { + return this.slotItem.get(slot); + } + + public void clear() { + slotItem.clear(); + if (!onePerPlayer) { + inv.clear(); + } + } + + public void open(Player p) { + if (!onePerPlayer) { + p.openInventory(inv); + } else { + if (p.getOpenInventory() == null// + || p.getOpenInventory().getTopInventory().getType() != InventoryType.CHEST// + || p.getOpenInventory().getTopInventory().getSize() != rows * 9 + || p.getOpenInventory().getTopInventory().getHolder() == null// + || !(p.getOpenInventory().getTopInventory().getHolder() instanceof MenuHolder)// + || !(((MenuHolder) p.getOpenInventory().getTopInventory().getHolder()).isOnePerPlayer())) { + createAndOpenInventory(p); + } else { + // Update the current inventory of player + for (int i = 0; i < rows * 9; i++) { + if (slotItem.containsKey(i)) { + p.getOpenInventory().getTopInventory().setItem(i, slotItem.get(i).getStack()); + } else { + p.getOpenInventory().getTopInventory().setItem(i, null); + } + } + p.updateInventory(); + } + ((MenuHolder) p.getOpenInventory().getTopInventory().getHolder()).setMenu(this); + } + + p = null; + } + + public void setTitle(String title) { + this.title = title; + } + + public void createAndOpenInventory(Player p) { + Inventory playerInventory = Bukkit.createInventory(new MenuHolder(this), rows * 9, this.title); + + slotItem.entrySet().forEach(entry -> playerInventory.setItem(entry.getKey(), entry.getValue().getStack())); + + p.openInventory(playerInventory); + p = null; + } + + public void close(Player p) { + if (onePerPlayer) { + destroy(p); + p = null; + } + } + + public void destroy(Player p) { + if (p.getOpenInventory().getTopInventory().getHolder() != null + && p.getOpenInventory().getTopInventory().getHolder() instanceof MenuHolder) { + ((MenuHolder) p.getOpenInventory().getTopInventory().getHolder()).destroy(); + } + } + + public boolean isOnePerPlayer() { + return onePerPlayer; + } + + public Inventory getInventory() { + return inv; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.java new file mode 100644 index 0000000..e4829d9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class MenuItem { + + private ItemStack stack; + private MenuClickHandler handler; + + public MenuItem(ItemStack itemstack) { + this.stack = itemstack; + + this.handler = new MenuClickHandler() { + @Override + public void onClick(Player p, Inventory inv, ClickType type, ItemStack stack, int slot) { + } + }; + } + + public MenuItem(ItemStack itemstack, MenuClickHandler clickHandler) { + this.stack = itemstack; + this.handler = clickHandler; + } + + public ItemStack getStack() { + return stack; + } + + public MenuClickHandler getHandler() { + return handler; + } + + public void destroy() { + stack = null; + handler = null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.java new file mode 100644 index 0000000..c9cf5ae --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.java @@ -0,0 +1,116 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.menu; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; + +public class MenuListener implements Listener { + + private static Listener listener; + + @Getter + private static boolean openMenus; + + public static void registerListeners() { + if (openMenus) return; + + openMenus = true; + + listener = new Listener() { + + @EventHandler(priority = EventPriority.LOWEST) + public void onInventoryClickListener(InventoryClickEvent event) { + if (event.getInventory() == null) + return; + + Inventory inv = event.getInventory(); + if (inv.getType() != InventoryType.CHEST) + return; + + if (inv.getHolder() == null) + return; + + if (!(inv.getHolder() instanceof MenuHolder)) + return; + + event.setCancelled(true); + + if (event.getClickedInventory() != inv) + return; + + if (!(event.getWhoClicked() instanceof Player)) + return; + + if (event.getSlot() < 0) + return; + + MenuHolder holder = (MenuHolder) inv.getHolder(); + MenuInventory menu = holder.getMenu(); + + if (menu.hasItem(event.getSlot())) { + Player p = (Player) event.getWhoClicked(); + MenuItem item = menu.getItem(event.getSlot()); + + item.getHandler().onClick(p, inv, + ((event.getAction() == InventoryAction.PICKUP_HALF) ? ClickType.RIGHT : ClickType.LEFT), + event.getCurrentItem(), event.getSlot()); + + p = null; + item = null; + } + + holder = null; + menu = null; + inv = null; + } + + @EventHandler + public void onClose(InventoryCloseEvent event) { + if (event.getInventory() == null) + return; + + Inventory inv = event.getInventory(); + if (inv.getType() != InventoryType.CHEST) + return; + + if (inv.getHolder() == null) + return; + + if (!(inv.getHolder() instanceof MenuHolder)) + return; + + if (!(event.getPlayer() instanceof Player)) + return; + + MenuHolder holder = (MenuHolder) inv.getHolder(); + if (holder.isOnePerPlayer()) { + holder.destroy(); + + holder = null; + } + + inv = null; + } + }; + + Bukkit.getServer().getPluginManager().registerEvents(listener, BukkitMain.getInstance()); + } + + public static void unregisterListeners() { + openMenus = false; + + HandlerList.unregisterAll(listener); + + listener = null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.java new file mode 100644 index 0000000..5bea763 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.java @@ -0,0 +1,22 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.NPC_v1_8_R3; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import org.bukkit.ChatColor; + +public class NPCLib { + + public static NPC createNPC(String customName, String color, String name, Skin skin, int itemStackID) { + return new NPC_v1_8_R3(BukkitMain.getInstance(), customName, color, name, skin, itemStackID); + } + + public static NPC createNPC(String customName, String color, String name, Skin skin) { + return createNPC(customName, color, name, skin, 20); + } + + public static NPC createNPC(String customName, String color, String name) { + return createNPC(customName, color, name, null, 20); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.java new file mode 100644 index 0000000..00488ec --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.java @@ -0,0 +1,56 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.listener.NPCListener; +import org.bukkit.Bukkit; + +import java.util.HashSet; +import java.util.Set; + +public final class NPCManager { + + private static Set npcs; + + private static boolean registred = false; + + private NPCManager() { + throw new SecurityException("You cannot initialize this class."); + } + + public static void register() { + if (registred) return; + + registred = true; + npcs = new HashSet<>(); + + Bukkit.getServer().getPluginManager().registerEvents(new NPCListener(), BukkitMain.getInstance()); + + BukkitMain.console("§a[NPCS] has been registred!"); + } + + public static Set getAllNPCs() { + return npcs; + } + + public static void add(NPC npc) { + npcs.add(npc); + } + + public static void remove(NPC npc) { + npcs.remove(npc); + } + + public static NPC getNPCByName(String name) { + NPC finded = null; + + for (NPC npc : npcs) { + if (npc.getCustomName().equalsIgnoreCase(name)) { + finded = npc; + break; + } + } + + return finded; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.java new file mode 100644 index 0000000..2b0528d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.java @@ -0,0 +1,119 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.wrapper.GameProfileWrapper; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public abstract class NPC implements PacketHandler { + + protected final UUID uuid = UUID.randomUUID(); + // Below was previously = (int) Math.ceil(Math.random() * 100000) + 100000 (new is experimental). + protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size(); + protected final Skin skin; + private final Set shown = new HashSet<>(); + protected int itemStackID = 0; + protected final String customName; + protected final String color; + protected final String name; + protected final JavaPlugin plugin; + protected GameProfileWrapper gameProfile; + protected Location location; + + //for players 1.8 + @Getter + protected Hologram nameHologram; + + public NPC(JavaPlugin plugin, String customName, String color, String name, Skin skin, int itemStackID) { + this.plugin = plugin; + this.skin = skin; + this.name = name; + this.customName = customName; + this.color = color; + + this.itemStackID = itemStackID; + + NPCManager.add(this); + } + + protected GameProfileWrapper generateGameProfile(UUID uuid, String name) { + GameProfileWrapper gameProfile = new GameProfileWrapper(uuid, name); + + if (skin != null) { + gameProfile.addSkin(skin); + } + + return gameProfile; + } + + public String getCustomName() { + return customName; + } + + public void destroy() { + NPCManager.remove(this); + + // Destroy NPC for every player that is still seeing it. + for (UUID uuid : shown) { + hide(Bukkit.getPlayer(uuid)); + } + + nameHologram.despawn(); + } + + public void hideAll() { + for (UUID uuid : shown) { + hide(Bukkit.getPlayer(uuid)); + } + } + + public Set getShown() { + return shown; + } + + public Location getLocation() { + return location; + } + + public int getEntityId() { + return entityId; + } + + public void create(Location location) { + this.location = location; + + nameHologram = HologramAPI.createHologram("name", + location.clone().add(0, 2.095, 0), null); + nameHologram.spawn(); + + createPackets(); + } + + public Location getLocationForHologram() { + return location.clone().add(0, 2.05, 0); + } + + public void show(Player player) { + if (shown.contains(player.getUniqueId())) { + return; + } + sendShowPackets(player); + } + + public void hide(Player player) { + if (!shown.contains(player.getUniqueId())) { + return; + } + sendHidePackets(player, false); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.java new file mode 100644 index 0000000..fa07ec7 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.java @@ -0,0 +1,12 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api; + +import org.bukkit.entity.Player; + +interface PacketHandler { + + void createPackets(); + + void sendShowPackets(Player player); + + void sendHidePackets(Player player, boolean scheduler); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.java new file mode 100644 index 0000000..59b9ee0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.wrapper; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.google.common.collect.ForwardingMultimap; +import org.bukkit.Bukkit; + +import java.util.UUID; + +public class GameProfileWrapper { + + // Written because of issue#10 (https://github.com/JitseB/NPCLib/issues/10). + // This class acts as an NMS reflection wrapper for the GameProfileWrapper class. + + // TODO: As of 1.4.2 1.7 support was removed, refactor this class. + + // TODO: This doesn't seem to work well with modified versions of Spigot (see issue #12). + private final boolean is1_7 = Bukkit.getBukkitVersion().contains("1.7"); + private final Class gameProfileClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.GameProfile"); + + final Object gameProfile; + + public GameProfileWrapper(UUID uuid, String name) { + // Only need to check if the version is 1.7, as NPCLib doesn't support any version below this version. + this.gameProfile = Reflection.getConstructor(gameProfileClazz, UUID.class, String.class).invoke(uuid, name); + } + + @SuppressWarnings("rawtypes") + public void addSkin(Skin skin) { + // Create a new property with the skin data. + Class propertyClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.properties.Property"); + Object property = Reflection.getConstructor(propertyClazz, + String.class, String.class, String.class).invoke("textures", skin.getValue(), skin.getSignature()); + + // Get the property map from the GameProfileWrapper object. + Class propertyMapClazz = Reflection.getClass((is1_7 ? "net.minecraft.util." : "") + "com.mojang.authlib.properties.PropertyMap"); + Reflection.FieldAccessor propertyMapGetter = Reflection.getField(gameProfileClazz, "properties", + propertyMapClazz); + Object propertyMap = propertyMapGetter.get(gameProfile); + + // TODO: Won't work on 1.7.10 (as Guava also changed package location). + // Add our new property to the property map. + Reflection.getMethod(ForwardingMultimap.class, "put", Object.class, Object.class) + .invoke(propertyMap, "textures", property); + + // Finally set the property map back in the GameProfileWrapper object. + propertyMapGetter.set(gameProfile, propertyMap); + } + + public Object getGameProfile() { + return gameProfile; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.java new file mode 100644 index 0000000..248b72b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.java @@ -0,0 +1,33 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.click.ClickType; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +public class NPCInteractEvent extends Event { + + private final Player player; + private final ClickType clickType; + private final NPC npc; + + private static final HandlerList handlers = new HandlerList(); + + public NPCInteractEvent(Player player, ClickType clickType, NPC npc) { + this.player = player; + this.clickType = clickType; + this.npc = npc; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.java new file mode 100644 index 0000000..46fac0f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.java @@ -0,0 +1,6 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.click; + +public enum ClickType { + + LEFT_CLICK, RIGHT_CLICK +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.java new file mode 100644 index 0000000..a35e958 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.java @@ -0,0 +1,97 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.listener; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.metadata.FixedMetadataValue; + +public class NPCListener implements Listener { + + private static final String LOCKED_TAG = "LOCKED.NPCS.TIME"; + + public static void lock(Player player) { + lock(player, 2000L); + } + + public static void lock(Player player, Long time) { + player.setMetadata(LOCKED_TAG, new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis() + time)); + } + + public static void removeLock(Player player) { + player.removeMetadata(LOCKED_TAG, BukkitMain.getInstance()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + handleNPC(event.getPlayer(), event.getPlayer().getLocation()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + + for (NPC npc : NPCManager.getAllNPCs()) { + npc.getShown().remove(player.getUniqueId()); + } + } + + @EventHandler + public void onRealMovement(PlayerMoveEvent event) { + if(!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + Player player = event.getPlayer(); + + if (isLocked(player)) return; + + handleNPC(player, event.getTo()); + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + Player player = e.getPlayer(); + + if (isLocked(player)) return; + handleNPC(player, e.getTo()); + } + + public void handleNPC(Player player, Location to) { + lock(player); + + for (NPC npc : NPCManager.getAllNPCs()) { + Location location = npc.getLocation(); + + if (location.getWorld() != to.getWorld()) continue; + + double distancia = location.distance(to); + + if (distancia <= 80) { + if (!npc.getShown().contains(player.getUniqueId())) { + npc.show(player); + npc.getShown().add(player.getUniqueId()); + } + } else { + if (npc.getShown().contains(player.getUniqueId())) { + npc.hide(player); + npc.getShown().remove(player.getUniqueId()); + } + } + } + + removeLock(player); + } + + private boolean isLocked(Player player) { + if (!player.hasMetadata(LOCKED_TAG)) return false; + return player.getMetadata(LOCKED_TAG).get(0).asLong() > System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.java new file mode 100644 index 0000000..181ed82 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.java @@ -0,0 +1,87 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets.PacketPlayOutEntityHeadRotationWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets.PacketPlayOutNamedEntitySpawnWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets.PacketPlayOutPlayerInfoWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets.PacketPlayOutScoreboardTeamWrapper; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import net.minecraft.server.v1_8_R3.*; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class NPC_v1_8_R3 extends NPC { + + private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn; + private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister, packetPlayOutScoreboardTeamUnregister; + private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove; + private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation; + private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy; + + public NPC_v1_8_R3(JavaPlugin plugin, String customName, String color, String name, Skin skin, int itemStackID) { + super(plugin, customName, color, name, skin, itemStackID); + } + + @Override + public void createPackets() { + this.gameProfile = generateGameProfile(uuid, name); + + PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper(); + + // Packets for spawning the NPC: + this.packetPlayOutScoreboardTeamRegister = new PacketPlayOutScoreboardTeamWrapper() + .createRegisterTeam(name, color); // First packet to send. + + this.packetPlayOutPlayerInfoAdd = packetPlayOutPlayerInfoWrapper + .create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, gameProfile, name); // Second packet to send. + + this.packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawnWrapper() + .create(uuid, location, entityId, itemStackID); // Third packet to send. + + this.packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotationWrapper() + .create(location, entityId); // Fourth packet to send. + + this.packetPlayOutPlayerInfoRemove = packetPlayOutPlayerInfoWrapper + .create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, gameProfile, name); // Fifth packet to send (delayed). + + // Packet for destroying the NPC: + this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send. + + // Second packet to send is "packetPlayOutPlayerInfoRemove". + + this.packetPlayOutScoreboardTeamUnregister = new PacketPlayOutScoreboardTeamWrapper() + .createUnregisterTeam(name, color); // Third packet to send. + } + + @Override + public void sendShowPackets(Player player) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + + playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister); + + playerConnection.sendPacket(packetPlayOutPlayerInfoAdd); + playerConnection.sendPacket(packetPlayOutNamedEntitySpawn); + playerConnection.sendPacket(packetPlayOutEntityHeadRotation); + + Bukkit.getScheduler().runTaskLater(plugin, () -> + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 40); + } + + @Override + public void sendHidePackets(Player player, boolean scheduler) { + PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; + + playerConnection.sendPacket(packetPlayOutEntityDestroy); + playerConnection.sendPacket(packetPlayOutPlayerInfoRemove); + + if (scheduler) { + // Sending this a bit later so the player doesn't see the name (for that split second). + Bukkit.getScheduler().runTaskLater(plugin, () -> + playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); + } else { + playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.java new file mode 100644 index 0000000..39aaa46 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation; +import org.bukkit.Location; + +public class PacketPlayOutEntityHeadRotationWrapper { + + public PacketPlayOutEntityHeadRotation create(Location location, int entityId) { + PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotation(); + + Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "a", int.class). + set(packetPlayOutEntityHeadRotation, entityId); + Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "b", byte.class) + .set(packetPlayOutEntityHeadRotation, (byte) ((int) location.getYaw() * 256.0F / 360.0F)); + + return packetPlayOutEntityHeadRotation; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.java new file mode 100644 index 0000000..b389263 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.java @@ -0,0 +1,47 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import net.minecraft.server.v1_8_R3.DataWatcher; +import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn; +import org.bukkit.Location; + +import java.util.UUID; + +public class PacketPlayOutNamedEntitySpawnWrapper { + + public PacketPlayOutNamedEntitySpawn create(UUID uuid, Location location, int entityId, int itemStackID) { + PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn(); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "a", int.class) + .set(packetPlayOutNamedEntitySpawn, entityId); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", UUID.class) + .set(packetPlayOutNamedEntitySpawn, uuid); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "c", int.class) + .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getX() * 32.0D)); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "d", int.class) + .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getY() * 32.0D)); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "e", int.class) + .set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getZ() * 32.0D)); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "f", byte.class) + .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getYaw() * 256.0F / 360.0F))); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "g", byte.class) + .set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getPitch() * 256.0F / 360.0F))); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "h", int.class) + .set(packetPlayOutNamedEntitySpawn, itemStackID); + + DataWatcher dataWatcher = new DataWatcher(null); + dataWatcher.a(10, (byte) 127); + + Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "i", DataWatcher.class) + .set(packetPlayOutNamedEntitySpawn, dataWatcher); + + return packetPlayOutNamedEntitySpawn; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.java new file mode 100644 index 0000000..3d1b0c4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.wrapper.GameProfileWrapper; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.v1_8_R3.IChatBaseComponent; +import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo; +import net.minecraft.server.v1_8_R3.WorldSettings; + +import java.util.List; + +public class PacketPlayOutPlayerInfoWrapper { + + @SuppressWarnings({"unchecked", "rawtypes"}) + public PacketPlayOutPlayerInfo create(PacketPlayOutPlayerInfo.EnumPlayerInfoAction action, GameProfileWrapper gameProfileWrapper, String name) { + GameProfile gameProfile = (GameProfile) gameProfileWrapper.getGameProfile(); + + PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo(); + Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class) + .set(packetPlayOutPlayerInfo, action); + + PacketPlayOutPlayerInfo.PlayerInfoData playerInfoData = packetPlayOutPlayerInfo.new PlayerInfoData(gameProfile, 1, + WorldSettings.EnumGamemode.NOT_SET, IChatBaseComponent.ChatSerializer.a(name)); + + Reflection.FieldAccessor fieldAccessor = Reflection.getField(packetPlayOutPlayerInfo.getClass(), + "b", List.class); + + List list = fieldAccessor.get(packetPlayOutPlayerInfo); + list.add(playerInfoData); + fieldAccessor.set(packetPlayOutPlayerInfo, list); + + return packetPlayOutPlayerInfo; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.java new file mode 100644 index 0000000..bf33cff --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.npc.packets.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardTeam; + +import java.util.Collection; + +public class PacketPlayOutScoreboardTeamWrapper { + + @SuppressWarnings({"unchecked", "rawtypes"}) + public PacketPlayOutScoreboardTeam createRegisterTeam(String name, String color) { + PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class) + .set(packetPlayOutScoreboardTeam, 0); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "b", String.class) + .set(packetPlayOutScoreboardTeam, color + name); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) + .set(packetPlayOutScoreboardTeam, color + name); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "e", String.class) + .set(packetPlayOutScoreboardTeam, "never"); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "i", int.class) + .set(packetPlayOutScoreboardTeam, 1); + // Could not get this working in the PacketPlayOutPlayerInfoWrapper class. + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "c", String.class) + .set(packetPlayOutScoreboardTeam, "" + color); + + Reflection.FieldAccessor collectionFieldAccessor = Reflection.getField( + packetPlayOutScoreboardTeam.getClass(), "g", Collection.class); + + Collection collection = collectionFieldAccessor.get(packetPlayOutScoreboardTeam); + collection.add(name); + collectionFieldAccessor.set(packetPlayOutScoreboardTeam, collection); + + return packetPlayOutScoreboardTeam; + } + + public PacketPlayOutScoreboardTeam createUnregisterTeam(String name, String color) { + PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam(); + + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class) + .set(packetPlayOutScoreboardTeam, 1); + Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class) + .set(packetPlayOutScoreboardTeam, color + name); + + return packetPlayOutScoreboardTeam; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.java new file mode 100644 index 0000000..55bbe19 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.java @@ -0,0 +1,150 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.player; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerUpdateTabEvent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; + +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; + +public class PlayerAPI { + + public static boolean isRealMovement(final PlayerMoveEvent event) { + return (event.getFrom().getBlockX() != event.getTo().getBlockX()) || (event.getFrom().getBlockZ() != event.getTo().getBlockZ()); + } + + public static int getXPKill(final Player player, long doubleXPTime) { + boolean doubleActive = doubleXPTime > System.currentTimeMillis(); + + if (BukkitSettings.DOUBLE_XP_OPTION) + doubleActive = true; + + int xp = CommonsConst.RANDOM.nextInt(16); + + if (xp < 12) + xp = 12; + + if (doubleActive) { + xp = xp * 2; + player.sendMessage(BukkitMessages.KILL_MESSAGE_XP.replace("%quantia%", "" + xp) + " (2x)"); + } else { + player.sendMessage(BukkitMessages.KILL_MESSAGE_XP.replace("%quantia%", "" + xp)); + } + + return xp; + } + + public static int getCoinsKill(final Player player, long doubleCoinsTime) { + boolean doubleActive = doubleCoinsTime > System.currentTimeMillis(); + + if (BukkitSettings.DOUBLE_COINS_OPTION) + doubleActive = true; + + int coins = CommonsConst.RANDOM.nextInt(100); + + if (coins < 80) + coins = 80; + + if (doubleActive) { + coins = coins * 2; + player.sendMessage(BukkitMessages.KILL_MESSAGE_COINS.replace("%quantia%", "" + coins) + " (2x)"); + } else { + player.sendMessage(BukkitMessages.KILL_MESSAGE_COINS.replace("%quantia%", "" + coins)); + } + + return coins; + } + + public static int getPing(final Player player) { + return ((CraftPlayer) player).getHandle().ping; + } + + public static String getHealth(Player player) { + return getHealth(player.getHealth()); + } + + public static String getHealth(double health) { + return NumberFormat.getCurrencyInstance().format(health / 2).replace("$", "").replace("R", "") + .replace(",", "."); + } + + public static String getAddress(final Player player) { + return player.getAddress().getAddress().getHostAddress(); + } + + public static void dropItems(final Player p, final Location l) { + ArrayList itens = new ArrayList<>(); + + for (ItemStack item : p.getPlayer().getInventory().getContents()) { + if ((item != null) && (item.getType() != Material.AIR)) { + if (item.hasItemMeta()) { + if ((item.getItemMeta().hasDisplayName()) && (item.getItemMeta().getDisplayName().contains("Kit"))) { + continue; + } + itens.add(item.clone()); + } else { + itens.add(item); + } + } + } + + for (ItemStack item : p.getPlayer().getInventory().getArmorContents()) { + if ((item != null) && (item.getType() != Material.AIR)) { + itens.add(item.clone()); + } + } + + if ((p.getPlayer().getItemOnCursor() != null) && (p.getPlayer().getItemOnCursor().getType() != Material.AIR)) { + itens.add(p.getPlayer().getItemOnCursor().clone()); + } + + dropItems(p, itens, l); + } + + @SuppressWarnings("deprecation") + public static void dropItems(Player player, List itens, final Location location) { + World world = location.getWorld(); + + for (ItemStack item : itens) { + if ((item != null) && (item.getType() != Material.AIR)) { + if (item.hasItemMeta()) { + world.dropItemNaturally(location, item.clone()).getItemStack().setItemMeta(item.getItemMeta()); + } else { + world.dropItemNaturally(location, item); + } + } + } + + player.getPlayer().getInventory().setArmorContents(new ItemStack[4]); + player.getPlayer().getInventory().clear(); + player.getPlayer().setItemOnCursor(new ItemStack(0)); + + itens.clear(); + } + + public static void clearEffects(Player player) { + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + } + + public static boolean isFull(final Inventory inventory) { + return inventory.firstEmpty() == -1; + } + + public static void updateTab(final Player player) { + Bukkit.getPluginManager().callEvent(new PlayerUpdateTabEvent(player)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.java new file mode 100644 index 0000000..db9f1f5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.java @@ -0,0 +1,59 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.protocol; + +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; + +public class ProtocolGetter { + + //Protocol Support + static Class ProtocolSupportAPI; + static Class ProtocolVersion; + static Method ProtocolSupportAPI_getProtocolVersion; + static Method ProtocolVersion_getId; + + static { + try { + ProtocolSupportAPI = Class.forName("protocolsupport.api.ProtocolSupportAPI"); + ProtocolVersion = Class.forName("protocolsupport.api.ProtocolVersion"); + + ProtocolSupportAPI_getProtocolVersion = getMethod(ProtocolSupportAPI, "getProtocolVersion", Player.class); + ProtocolVersion_getId = getMethod(ProtocolVersion, "getId"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static int getVersion(Player p) { + try { + Object protocolVersion = ProtocolSupportAPI_getProtocolVersion.invoke(null, p); + return (int) ProtocolVersion_getId.invoke(protocolVersion); + } catch (Exception ex) { + return 0; + } + } + + public static Method getMethod(Class clazz, String name, Class... args) { + for (Method m : clazz.getMethods()) { + if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + } + return null; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) { + return false; + } + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.java new file mode 100644 index 0000000..89654f0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.java @@ -0,0 +1,156 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.title; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +public class TitleAPI { + + public static void sendTitles(final Player player, final String... titles) { + for (int i = 0; i < titles.length; i++) { + String line = titles[i]; + + String title = line.split(";")[0], + subtitle = line.split(";")[1]; + + BukkitMain.runLater(() -> { + sendTitle(player, title, subtitle, 0, 0, 2); + }, i == 0 ? 30 : i * 60); + } + } + + public static void sendTitle(Player player, + String titulo, String subtitulo, int fadeInTime, int stayTime, int fadeOutTime) { + sendTitle(player, fadeInTime * 20, stayTime * 20, fadeOutTime * 20, titulo, subtitulo); + } + + public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) { + sendTitle(player, fadeIn, stay, fadeOut, message, null); + } + + @Deprecated + public static void sendSubtitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) { + sendTitle(player, fadeIn, stay, fadeOut, null, message); + } + + @Deprecated + public static void sendFullTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) { + sendTitle(player, fadeIn, stay, fadeOut, title, subtitle); + } + + public static void sendPacket(Player player, Object packet) { + try { + Object handle = player.getClass().getMethod("getHandle").invoke(player); + Object playerConnection = handle.getClass().getField("playerConnection").get(handle); + playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static Class getNMSClass(String name) { + String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + try { + return Class.forName("net.minecraft.server." + version + "." + name); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + return null; + } + } + + @SuppressWarnings("rawtypes") + public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) { + try { + Object e; + Object chatTitle; + Object chatSubtitle; + Constructor subtitleConstructor; + Object titlePacket; + Object subtitlePacket; + + if (title != null) { + title = ChatColor.translateAlternateColorCodes('&', title); + title = title.replaceAll("%player%", player.getDisplayName()); + // Times packets + e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); + chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + titlePacket = subtitleConstructor.newInstance(e, chatTitle, fadeIn, stay, fadeOut); + sendPacket(player, titlePacket); + + e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null); + chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent")); + titlePacket = subtitleConstructor.newInstance(e, chatTitle); + sendPacket(player, titlePacket); + } + + if (subtitle != null) { + subtitle = ChatColor.translateAlternateColorCodes('&', subtitle); + subtitle = subtitle.replaceAll("%player%", player.getDisplayName()); + // Times packets + e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); + chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + title + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeIn, stay, fadeOut); + sendPacket(player, subtitlePacket); + + e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null); + chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke(null, "{\"text\":\"" + subtitle + "\"}"); + subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE); + subtitlePacket = subtitleConstructor.newInstance(e, chatSubtitle, fadeIn, stay, fadeOut); + sendPacket(player, subtitlePacket); + } + } catch (Exception var11) { + var11.printStackTrace(); + } + } + + public static void clearTitle(Player player) { + sendTitle(player, 0, 0, 0, "", ""); + } + + public static void setHeaderAndFooter(Player player, String header, String footer) { + if (header == null) header = ""; + header = ChatColor.translateAlternateColorCodes('&', header); + + if (footer == null) footer = ""; + footer = ChatColor.translateAlternateColorCodes('&', footer); + + header = header.replaceAll("%player%", player.getDisplayName()); + footer = footer.replaceAll("%player%", player.getDisplayName()); + + try { + Object tabHeader = + getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + header + "\"}"); + + Object tabFooter = + getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + footer + "\"}"); + + Constructor titleConstructor = getNMSClass("PacketPlayOutPlayerListHeaderFooter").getConstructor(); + Object packet = titleConstructor.newInstance(); + try { + Field aField = packet.getClass().getDeclaredField("a"); + aField.setAccessible(true); + aField.set(packet, tabHeader); + Field bField = packet.getClass().getDeclaredField("b"); + bField.setAccessible(true); + bField.set(packet, tabFooter); + } catch (Exception e) { + Field aField = packet.getClass().getDeclaredField("header"); + aField.setAccessible(true); + aField.set(packet, tabHeader); + Field bField = packet.getClass().getDeclaredField("footer"); + bField.setAccessible(true); + bField.set(packet, tabFooter); + } + sendPacket(player, packet); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.java new file mode 100644 index 0000000..51a8eed --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.java @@ -0,0 +1,155 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.api.vanish; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerAdminChangeEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerAdminChangeEvent.AdminChangeType; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class VanishAPI { + + private static final List invisiveis = new ArrayList<>(); + private static final List admin = new ArrayList<>(); + + /* + private static final HashMap itens = new HashMap<>(); + private static final HashMap armadura = new HashMap<>();*/ + + public static void hide(Player player) { + if (invisiveis.contains(player)) { + return; + } + + invisiveis.add(player); + + Tag tag = + BukkitMain.getBukkitPlayer(player.getUniqueId()).getGroup().getTag(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (!TagManager.hasPermission(onlines, tag)) { + onlines.hidePlayer(player); + } + } + + player.sendMessage(BukkitMessages.PLAYER_FICOU_INVISIVEL.replace("%grupo%", tag.getColor() + "§l" + tag.getName())); + } + + public static void show(Player player) { + if (!invisiveis.contains(player)) { + return; + } + + invisiveis.remove(player); + + Bukkit.getOnlinePlayers().forEach(onlines -> onlines.showPlayer(player)); + + player.sendMessage(BukkitMessages.PLAYER_FICOU_VISIVEL); + } + + public static void updateInvisibles(Player player) { + for (Player invisible : invisiveis) { + + if (invisible != null && invisible.isOnline()) { + Tag tag = BukkitMain.getBukkitPlayer(invisible.getUniqueId()).getGroup().getTag(); + + if (TagManager.hasPermission(player, tag)) { + player.showPlayer(invisible); + } else { + player.hidePlayer(invisible); + } + } + } + } + + public static void changeAdmin(Player player) { + changeAdmin(player, true); + } + + public static void changeAdmin(Player player, boolean callEvent) { + boolean inAdmin = admin.contains(player); + + Groups playerGroup = BukkitMain.getBukkitPlayer(player.getUniqueId()).getGroup(); + + if (inAdmin) { + //saiu do admin + /* player.getInventory().clear(); + player.getInventory().setArmorContents(null); + + player.getInventory().setContents(itens.get(player.getUniqueId())); + player.getInventory().setArmorContents(armadura.get(player.getUniqueId())); + + armadura.remove(player.getUniqueId()); + itens.remove(player.getUniqueId());*/ + admin.remove(player); + + invisiveis.remove(player); + } else { + if (!admin.contains(player)) { + admin.add(player); + } + + if (!invisiveis.contains(player)) { + invisiveis.add(player); + } + + /* + itens.put(player.getUniqueId(), player.getInventory().getContents()); + armadura.put(player.getUniqueId(), player.getInventory().getArmorContents()); + + player.getInventory().clear(); + player.getInventory().setArmorContents(null);*/ + } + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (player == onlines) { + continue; + } + + if (inAdmin) { + onlines.showPlayer(player); + } + + if (TagManager.hasPermission(onlines, playerGroup)) { + onlines.sendMessage(inAdmin ? BukkitMessages.PLAYER_SAIU_DO_ADMIN.replace("%nick%", player.getName()) : + BukkitMessages.PLAYER_ENTROU_NO_ADMIN.replace("%nick%", player.getName())); + } else { + if (!inAdmin) { + onlines.hidePlayer(player); + } + } + } + + if (callEvent) { + Bukkit.getPluginManager().callEvent(new PlayerAdminChangeEvent(player, inAdmin ? AdminChangeType.SAIU : AdminChangeType.ENTROU)); + } + + player.setGameMode(inAdmin ? GameMode.SURVIVAL : GameMode.CREATIVE); + + player.sendMessage(inAdmin ? BukkitMessages.SAIU_DO_ADMIN : BukkitMessages.ENTROU_NO_ADMIN); + } + + public static void remove(Player player) { + admin.remove(player); + invisiveis.remove(player); + /*itens.remove(uniqueId); + armadura.remove(uniqueId);*/ + } + + public static boolean inAdmin(Player player) { + return admin.contains(player); + } + + public static boolean isInvisible(Player player) { + return invisiveis.contains(player); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.java new file mode 100644 index 0000000..8a07513 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.java @@ -0,0 +1,356 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.command.*; +import org.bukkit.entity.Player; +import org.bukkit.help.GenericCommandHelpTopic; +import org.bukkit.help.HelpTopic; +import org.bukkit.help.HelpTopicComparator; +import org.bukkit.help.IndexHelpTopic; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.SimplePluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.util.Map.Entry; + +public class BukkitCommandFramework implements CommandFramework { + + public static final BukkitCommandFramework INSTANCE = new BukkitCommandFramework(BukkitMain.getInstance()); + + private final Map> commandMap = new HashMap<>(); + private final JavaPlugin plugin; + private CommandMap map; + + public BukkitCommandFramework(JavaPlugin plugin) { + this.plugin = plugin; + + if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) { + SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager(); + try { + Field field = SimplePluginManager.class.getDeclaredField("commandMap"); + field.setAccessible(true); + map = (CommandMap) field.get(manager); + } catch (IllegalArgumentException | NoSuchFieldException | IllegalAccessException | SecurityException e) { + e.printStackTrace(); + } + } + } + + public JavaPlugin getPlugin() { + return plugin; + } + + public boolean handleCommand(org.bukkit.command.CommandSender sender, String label, org.bukkit.command.Command cmd, String[] args) { + StringBuilder line = new StringBuilder(); + + line.append(label); + + for (String arg : args) { + line.append(" ").append(arg); + } + + for (int i = args.length; i >= 0; i--) { + StringBuilder buffer = new StringBuilder(); + buffer.append(label.toLowerCase()); + + for (int x = 0; x < i; x++) { + buffer.append(".").append(args[x].toLowerCase()); + } + + String cmdLabel = buffer.toString(); + + if (commandMap.containsKey(cmdLabel)) { + Entry entry = commandMap.get(cmdLabel); + Command command = entry.getKey().getAnnotation(Command.class); + + if (sender instanceof Player) { + Player p = (Player) sender; + + if (BukkitMain.getServerType() == ServerType.LOGIN) { + if ((command.name().equalsIgnoreCase("login")) || (command.name().equalsIgnoreCase("logar")) + || (command.name().equalsIgnoreCase("register")) || (command.name().equalsIgnoreCase("registrar"))) { + try { + entry.getKey().invoke(entry.getValue(), new BukkitCommandSender(sender), label, args); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + } else { + p.sendMessage("§cEste comando não pode ser executado aqui."); + } + return true; + } + + GamingProfile profile = CommonsGeneral.getProfileManager().getGamingProfile(p.getUniqueId()); + + final String groupName = profile.getGroup().getName(); + + if (command.groupsToUse().length == 1 && command.groupsToUse()[0] == Groups.MEMBRO) { + + } else { + Groups tagPlayer = Groups.getGroup(groupName); + + boolean semPermissao = true; + for (int uses = 0; uses < command.groupsToUse().length; uses++) { + Groups tag = command.groupsToUse()[uses]; + if (tagPlayer.getLevel() >= tag.getLevel()) { + semPermissao = false; + break; + } + } + + if (semPermissao) { + if (hasCommand(p, command.name().toLowerCase())) { + semPermissao = false; + } + } + + if (semPermissao) { + p.sendMessage(BukkitMessages.VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO); + return true; + } + } + } + + if (command.runAsync()) { + BukkitMain.runAsync(() -> { + try { + entry.getKey().invoke(entry.getValue(), new BukkitCommandSender(sender), label, args); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + }); + + } else { + try { + entry.getKey().invoke(entry.getValue(), new BukkitCommandSender(sender), label, args); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + } + return true; + } + } + return true; + } + + public boolean hasCommand(Player player, String command) { + if (player.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd.all")) return true; + + return player.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd." + command); + } + + public void registerCommands(CommandClass commandClass) { + for (Method m : commandClass.getClass().getMethods()) { + if (m.getAnnotation(Command.class) != null) { + Command command = m.getAnnotation(Command.class); + if (m.getParameterTypes().length != 3 + || !BukkitCommandSender.class.isAssignableFrom(m.getParameterTypes()[0]) + && !String.class.isAssignableFrom(m.getParameterTypes()[1]) + && !String[].class.isAssignableFrom(m.getParameterTypes()[2])) { + System.out.println("Unable to register command " + m.getName() + ". Unexpected method arguments"); + continue; + } + registerCommand(command, command.name(), m, commandClass); + for (String alias : command.aliases()) { + registerCommand(command, alias, m, commandClass); + } + } else if (m.getAnnotation(Completer.class) != null) { + Completer comp = m.getAnnotation(Completer.class); + if (m.getParameterTypes().length != 3 + || m.getParameterTypes()[0] != BukkitCommandSender.class + && m.getParameterTypes()[1] != String.class + && m.getParameterTypes()[2] != String[].class) { + System.out.println( + "Unable to register tab completer " + m.getName() + ". Unexpected method arguments"); + continue; + } + if (m.getReturnType() != List.class) { + System.out.println("Unable to register tab completer " + m.getName() + ". Unexpected return type"); + continue; + } + registerCompleter(comp.name(), m, commandClass); + for (String alias : comp.aliases()) { + registerCompleter(alias, m, commandClass); + } + } + } + } + + public void registerHelp() { + Set help = new TreeSet(HelpTopicComparator.helpTopicComparatorInstance()); + for (String s : commandMap.keySet()) { + if (!s.contains(".")) { + org.bukkit.command.Command cmd = map.getCommand(s); + HelpTopic topic = new GenericCommandHelpTopic(cmd); + help.add(topic); + } + } + IndexHelpTopic topic = new IndexHelpTopic(plugin.getName(), "All commands for " + plugin.getName(), null, help, + "Below is a list of all " + plugin.getName() + " commands:"); + Bukkit.getServer().getHelpMap().addTopic(topic); + } + + private void registerCommand(Command command, String label, Method m, Object obj) { + Entry entry = new AbstractMap.SimpleEntry<>(m, obj); + commandMap.put(label.toLowerCase(), entry); + String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase(); + if (map.getCommand(cmdLabel) == null) { + org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, plugin); + map.register(plugin.getName(), cmd); + } + if (!command.description().equalsIgnoreCase("") && cmdLabel.equals(label)) { + map.getCommand(cmdLabel).setDescription(command.description()); + } + if (!command.usage().equalsIgnoreCase("") && cmdLabel.equals(label)) { + map.getCommand(cmdLabel).setUsage(command.usage()); + } + } + + private void registerCompleter(String label, Method m, Object obj) { + String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase(); + if (map.getCommand(cmdLabel) == null) { + org.bukkit.command.Command command = new BukkitCommand(cmdLabel, plugin); + map.register(plugin.getName(), command); + } + if (map.getCommand(cmdLabel) instanceof BukkitCommand) { + BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel); + if (command.completer == null) { + command.completer = new BukkitCompleter(); + } + command.completer.addCompleter(label, m, obj); + } else if (map.getCommand(cmdLabel) instanceof PluginCommand) { + try { + Object command = map.getCommand(cmdLabel); + Field field = command.getClass().getDeclaredField("completer"); + field.setAccessible(true); + if (field.get(command) == null) { + BukkitCompleter completer = new BukkitCompleter(); + completer.addCompleter(label, m, obj); + field.set(command, completer); + } else if (field.get(command) instanceof BukkitCompleter) { + BukkitCompleter completer = (BukkitCompleter) field.get(command); + completer.addCompleter(label, m, obj); + } else { + System.out.println("Unable to register tab completer " + m.getName() + + ". A tab completer is already registered for that command!"); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + class BukkitCommand extends org.bukkit.command.Command { + + private final Plugin owningPlugin; + private final CommandExecutor executor; + protected BukkitCompleter completer; + + protected BukkitCommand(String label, Plugin owner) { + super(label); + this.executor = owner; + this.owningPlugin = owner; + this.usageMessage = ""; + } + + @Override + public boolean execute(org.bukkit.command.CommandSender sender, String commandLabel, String[] args) { + boolean success; + + if (!owningPlugin.isEnabled()) { + return false; + } + + try { + success = handleCommand(sender, commandLabel, this, args); + } catch (Throwable ex) { + throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + + owningPlugin.getDescription().getFullName(), ex); + } + + return success; + } + + @Override + public List tabComplete(org.bukkit.command.CommandSender sender, String alias, String[] args) + throws CommandException, IllegalArgumentException { + Validate.notNull(sender, "Sender cannot be null"); + Validate.notNull(args, "Arguments cannot be null"); + Validate.notNull(alias, "Alias cannot be null"); + + List completions = null; + try { + if (completer != null) { + completions = completer.onTabComplete(sender, this, alias, args); + } + if (completions == null && executor instanceof TabCompleter) { + completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args); + } + } catch (Throwable ex) { + StringBuilder message = new StringBuilder(); + message.append("Unhandled exception during tab completion for command '/").append(alias).append(' '); + for (String arg : args) { + message.append(arg).append(' '); + } + message.deleteCharAt(message.length() - 1).append("' in plugin ") + .append(owningPlugin.getDescription().getFullName()); + throw new CommandException(message.toString(), ex); + } + + if (completions == null) { + return super.tabComplete(sender, alias, args); + } + return completions; + } + + } + + static class BukkitCompleter implements TabCompleter { + + private final Map> completers = new HashMap<>(); + + public void addCompleter(String label, Method m, Object obj) { + completers.put(label, new AbstractMap.SimpleEntry<>(m, obj)); + } + + @SuppressWarnings("unchecked") + @Override + public List onTabComplete(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, + String label, String[] args) { + for (int i = args.length; i >= 0; i--) { + StringBuilder buffer = new StringBuilder(); + buffer.append(label.toLowerCase()); + for (int x = 0; x < i; x++) { + if (!args[x].equals("") && !args[x].equals(" ")) { + buffer.append(".").append(args[x].toLowerCase()); + } + } + String cmdLabel = buffer.toString(); + if (completers.containsKey(cmdLabel)) { + Entry entry = completers.get(cmdLabel); + try { + return (List) entry.getKey().invoke(entry.getValue(), new BukkitCommandSender(sender), + label, args); + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + } + return null; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.java new file mode 100644 index 0000000..a17107f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.java @@ -0,0 +1,160 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.common.command.CommandSender; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; + +import java.util.Set; +import java.util.UUID; + +@RequiredArgsConstructor +public class BukkitCommandSender implements CommandSender, org.bukkit.command.CommandSender { + + @NonNull + private org.bukkit.command.CommandSender commandSender; + + @Override + public UUID getUniqueId() { + if (commandSender instanceof Player) + return ((Player) commandSender).getUniqueId(); + return UUID.randomUUID(); + } + + public Player getPlayer() { + return (Player) commandSender; + } + + public String getNick() { + if (commandSender instanceof Player) { + return commandSender.getName(); + } + return "CONSOLE"; + } + + @Override + public boolean isPlayer() { + if (commandSender instanceof Player) { + return true; + } + commandSender.sendMessage("§cComando disponível apenas para Jogadores."); + return false; + } + + public String getRealNick() { + if (commandSender instanceof Player) { + return CommonsGeneral.getProfileManager().getGamingProfile(((Player) commandSender).getUniqueId()).getNick(); + } + return "CONSOLE"; + } + + @Override + public PermissionAttachment addAttachment(Plugin arg0) { + return commandSender.addAttachment(arg0); + } + + @Override + public PermissionAttachment addAttachment(Plugin arg0, int arg1) { + return commandSender.addAttachment(arg0); + } + + @Override + public PermissionAttachment addAttachment(Plugin arg0, String arg1, boolean arg2) { + return commandSender.addAttachment(arg0, arg1, arg2); + } + + @Override + public PermissionAttachment addAttachment(Plugin arg0, String arg1, boolean arg2, int arg3) { + return commandSender.addAttachment(arg0, arg1, arg2, arg3); + } + + @Override + public Set getEffectivePermissions() { + return commandSender.getEffectivePermissions(); + } + + @Override + public boolean hasPermission(String arg0) { + if (commandSender.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd.all")) { + return true; + } + if (commandSender.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd." + arg0)) { + return true; + } + commandSender.sendMessage(BukkitMessages.VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO); + return false; + } + + @Override + public boolean hasPermission(Permission arg0) { + return commandSender.hasPermission(arg0); + } + + @Override + public boolean isPermissionSet(String arg0) { + return commandSender.isPermissionSet(arg0); + } + + @Override + public boolean isPermissionSet(Permission arg0) { + return commandSender.isPermissionSet(arg0); + } + + @Override + public void recalculatePermissions() { + commandSender.recalculatePermissions(); + } + + @Override + public void removeAttachment(PermissionAttachment arg0) { + commandSender.removeAttachment(arg0); + } + + @Override + public boolean isOp() { + return commandSender.isOp(); + } + + @Override + public void setOp(boolean arg0) { + commandSender.setOp(arg0); + } + + @Override + public String getName() { + return commandSender.getName(); + } + + @Override + public Server getServer() { + return commandSender.getServer(); + } + + @Override + public void sendMessage(String arg0) { + commandSender.sendMessage(arg0); + } + + @Override + public void sendMessage(String[] arg0) { + commandSender.sendMessage(arg0); + } + + public String getArgs(String[] args, int começo) { + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = começo; i < args.length; i++) { + stringBuilder.append(args[i]).append(" "); + } + + return stringBuilder.toString(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.java new file mode 100644 index 0000000..1a05c2b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuListener; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.menu.AccountInventory; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import org.bukkit.entity.Player; + +public class AccountCommand implements CommandClass { + + @Command(name = "account", aliases = {"acc", "perfil", "conta", "stats", "info"}, runAsync = true) + public void account(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (!MenuListener.isOpenMenus()) { + commandSender.sendMessage("§cVocê não pode abrir menus agora."); + return; + } + + Player player = commandSender.getPlayer(); + + final String nickViewer = BukkitServerAPI.getRealNick(player); + + if (args.length == 1) { + if (!commandSender.hasPermission("account")) { + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BukkitMessages.NAO_TEM_CONTA); + return; + } + new AccountInventory(nickViewer, nick).open(player); + } else { + new AccountInventory(nickViewer, nickViewer).open(player); + } + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.java new file mode 100644 index 0000000..1b9c9d0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; + +public class AdminCommand implements CommandClass { + + @Command(name = "admin", aliases = {"adm", "v"}, groupsToUse = Groups.PRIME) + public void admin(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + VanishAPI.changeAdmin(commandSender.getPlayer()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.java new file mode 100644 index 0000000..5ac9657 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.java @@ -0,0 +1,26 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.Bukkit; + +public class BroadCastCommand implements CommandClass { + + @Command(name = "broadcast", aliases = {"bc"}, groupsToUse = {Groups.MOD}) + public void broadcast(BukkitCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage(BukkitMessages.BROADCAST_USAGE); + return; + } + + Bukkit.broadcastMessage(BukkitMessages.BROADCAST_PREFIX + StringUtility.createArgs(0, args).replaceAll("&", "§")); + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " utilizou o BroadCast!]", Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.java new file mode 100644 index 0000000..b28f272 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class ChatCommand implements CommandClass { + + @Command(name = "chat", groupsToUse = {Groups.MOD}) + public void chat(BukkitCommandSender commandSender, String label, String[] args) { + if (BukkitSettings.CHAT_OPTION) { + BukkitSettings.CHAT_OPTION = false; + + Bukkit.broadcastMessage(BukkitMessages.CHAT_DESATIVADO); + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " desativou o Chat!]", Groups.ADMIN); + } + } else { + BukkitSettings.CHAT_OPTION = true; + Bukkit.broadcastMessage(BukkitMessages.CHAT_ATIVADO); + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " ativou o Chat!]", Groups.ADMIN); + } + } + } + + @Command(name = "clearchat", aliases = {"cc"}, groupsToUse = {Groups.MOD}) + public void clearChat(BukkitCommandSender commandSender, String label, String[] args) { + for (Player on : Bukkit.getOnlinePlayers()) { + for (int i = 0; i <= 100; i++) { + on.sendMessage(""); + } + } + Bukkit.broadcastMessage(BukkitMessages.CHAT_LIMPO); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.java new file mode 100644 index 0000000..884c8e1 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; + +import java.util.List; + +public class ClearDropsCommand implements CommandClass { + + @Command(name = "cleardrops", aliases = {"cd"}, groupsToUse = {Groups.MOD}) + public void clearDrops(BukkitCommandSender commandSender, String label, String[] args) { + int removidos = 0; + + for (World world : Bukkit.getWorlds()) { + List items = world.getEntities(); + + for (Entity item : items) { + if (item instanceof Item) { + item.remove(); + removidos++; + } + } + } + + commandSender.sendMessage(BukkitMessages.CLEAR_DROPS.replace("%quantia%", "" + removidos)); + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " limpou o chão!]", Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.java new file mode 100644 index 0000000..338152d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.java @@ -0,0 +1,45 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; + +public class DanoCommand implements CommandClass { + + @Command(name = "dano", groupsToUse = {Groups.MOD}) + public void dano(BukkitCommandSender commandSender, String label, String[] args) { + if (BukkitSettings.DANO_OPTION) { + BukkitSettings.DANO_OPTION = false; + Bukkit.broadcastMessage(BukkitMessages.DANO_DESATIVADO); + } else { + BukkitSettings.DANO_OPTION = true; + Bukkit.broadcastMessage(BukkitMessages.DANO_ATIVADO); + } + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " " + + (BukkitSettings.DANO_OPTION ? "ativou" : "desativou") + " o Dano!]", Groups.ADMIN); + } + } + + @Command(name = "pvp", groupsToUse = {Groups.MOD}) + public void pvp(BukkitCommandSender commandSender, String label, String[] args) { + if (BukkitSettings.PVP_OPTION) { + BukkitSettings.PVP_OPTION = false; + Bukkit.broadcastMessage(BukkitMessages.PVP_DESATIVADO); + } else { + BukkitSettings.PVP_OPTION = true; + Bukkit.broadcastMessage(BukkitMessages.PVP_ATIVADO); + } + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " " + + (BukkitSettings.PVP_OPTION ? "ativou" : "desativou") + " o PvP!]", Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.java new file mode 100644 index 0000000..769e9c5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.java @@ -0,0 +1,230 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.fake.FakeAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.Random; + +public class FakeCommand implements CommandClass { + + private final String[] names = {"Mine", "Craft", "Hyper", "Lord", "Zyper", "Beach", "Actor", "Games", "Nitro", + "Man", "Plays", "Crazy", "Mega", "Mineman", "G0D", "Killer", "Noob", "Gamer", "Blessed", "Scroll", "Money", + "Fish", "Ferrari", "Player", "Super", "Hype", "Net", "Flix", "Flex", "Corsa", "Prata", "Verde", "Rap", + "Astra", "Onix"}; + private final Random random = new Random(); + + @Command(name = "fake", groupsToUse = {Groups.PRIME, Groups.YOUTUBER}, aliases = {"nick"}) + public void fake(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player p = commandSender.getPlayer(); + + if (args.length == 0) { + p.sendMessage(BukkitMessages.FAKE_HELP); + return; + } + + if (args[0].equalsIgnoreCase("#")) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(p.getUniqueId()); + if (!bukkitPlayer.containsFake()) { + p.sendMessage(BukkitMessages.NAO_ESTA_USANDO_FAKE); + return; + } + + if (requestChangeNick(p, false)) { + String realNick = bukkitPlayer.getNick(); + bukkitPlayer.getDataHandler().getData(DataType.FAKE).setValue(""); + + BukkitMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + + FakeAPI.changePlayerName(p, realNick, false); + p.sendMessage(BukkitMessages.TIROU_FAKE); + + TagManager.setTag(p, bukkitPlayer.getGroup().getTag(), bukkitPlayer); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_FAST_SKIN).field(realNick)); + } + } else if (args[0].equalsIgnoreCase("random")) { + boolean finded = false; + + String nick = getRandomFake(); + if (Bukkit.getPlayer(nick) == null) { + finded = true; + } else { + nick = getRandomFake(); + if (Bukkit.getPlayer(nick) == null) { + finded = true; + } else { + nick = getRandomFake(); + if (Bukkit.getPlayer(nick) == null) { + finded = true; + } else { + nick = getRandomFake(); + if (Bukkit.getPlayer(nick) == null) { + finded = true; + } + } + } + } + + if (!finded) { + p.sendMessage(BukkitMessages.NENHUM_FAKE_RANDOM); + return; + } + + if (isOriginal(nick)) { + p.sendMessage(BukkitMessages.FAKE_INDISPONIVEL); + return; + } + + if (requestChangeNick(p, true)) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(p.getUniqueId()); + bukkitPlayer.getDataHandler().getData(DataType.FAKE).setValue(nick); + + BukkitMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + + FakeAPI.changePlayerName(p, nick, false); + p.sendMessage(BukkitMessages.FAKE_SUCESSO.replace("%nick%", nick)); + + TagManager.setTag(p, Groups.MEMBRO.getTag(), bukkitPlayer); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_RANDOM_SKIN)); + } + } else if (args[0].equalsIgnoreCase("list")) { + if (!commandSender.hasPermission("fakelist")) { + return; + } + + int fakes = 0; + + for (GamingProfile profiles : CommonsGeneral.getProfileManager().getGamingProfiles()) { + BukkitPlayer bukkitPlayer = (BukkitPlayer) profiles; + if (bukkitPlayer.containsFake()) { + if (fakes == 0) { + p.sendMessage(""); + p.sendMessage(BukkitMessages.FAKE_LIST_PREFIX); + p.sendMessage(""); + } + p.sendMessage( + BukkitMessages.FAKE_LIST_LINHA.replace("%nickFake%", bukkitPlayer.getPlayer().getName()) + .replace("%nickReal%", bukkitPlayer.getNick())); + fakes++; + } + } + + if (fakes == 0) { + p.sendMessage(BukkitMessages.NENHUM_JOGADOR_COM_FAKE); + } else { + p.sendMessage(""); + } + } else { + String nick = args[0]; + + if (nick.length() < 5) { + p.sendMessage("§cEste nick é muito pequeno!"); + return; + } + if (nick.length() > 16) { + p.sendMessage("§cEste nick é muito grande!"); + return; + } + if (!validString(nick)) { + p.sendMessage("§cEste nick contém caractéres não permitidos."); + return; + } + + Player t = Bukkit.getPlayer(nick); + if (t != null && t.isOnline()) { + p.sendMessage(BukkitMessages.FAKE_INDISPONIVEL); + return; + } + + if (isOriginal(nick)) { + p.sendMessage(BukkitMessages.FAKE_INDISPONIVEL); + return; + } + + if (requestChangeNick(p, true)) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(p.getUniqueId()); + bukkitPlayer.getDataHandler().getData(DataType.FAKE).setValue(nick); + bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT); + + FakeAPI.changePlayerName(p, nick, false); + p.sendMessage(BukkitMessages.FAKE_SUCESSO.replace("%nick%", nick)); + + TagManager.setTag(p, Groups.MEMBRO.getTag(), bukkitPlayer); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_RANDOM_SKIN)); + } + } + } + + private boolean validString(String str) { + return str.matches("[a-zA-Z\\d]+") && !str.toLowerCase().contains(".com") && !str.toLowerCase().contains(".") + && !str.toLowerCase().contains("lixo") && !str.toLowerCase().contains("ez") + && !str.toLowerCase().contains("lag") && !str.toLowerCase().contains("merda") + && !str.toLowerCase().contains("mush") && !str.toLowerCase().contains("server") + && !str.toLowerCase().contains("fdp") + && !str.toLowerCase().contains("zenix") && !str.toLowerCase().contains("empire") + && !str.toLowerCase().contains("battle") && !str.toLowerCase().contains("like") + && (!str.toLowerCase().contains("kits")); + } + + private boolean isOriginal(String nick) { + try { + return CommonsGeneral.getUUIDFetcher().getUUID(nick) != null; + } catch (UUIDFetcherException ex) { + return true; + } + } + + private String getRandomFake() { + String randomNick = ""; + + if (random.nextBoolean()) { + randomNick = names[random.nextInt(names.length - 1)] + random.nextInt(6000) + + names[random.nextInt(names.length - 1)]; + } else { + randomNick = names[random.nextInt(names.length - 1)] + names[random.nextInt(names.length - 1)] + + random.nextInt(6000); + } + + if (randomNick.length() > 16) { + randomNick = getRandomFake(); + } + return randomNick; + } + + private boolean requestChangeNick(Player player, boolean colocar) { + PlayerRequestEvent event = new PlayerRequestEvent(player, "fake"); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + player.sendMessage(BukkitMessages.NAO_PODE_TIRAR_FAKE.replace("%action%", colocar ? "colocar" : "tirar")); + return false; + } + return true; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.java new file mode 100644 index 0000000..05c468c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class FlyCommand implements CommandClass { + + @Command(name = "fly", groupsToUse = {Groups.MOD}) + public void fly(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + changeFly(player); + } else { + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + if (target.getAllowFlight()) { + player.sendMessage(BukkitMessages.FLY_DESATIVADO_PARA.replace("%nick%", target.getName())); + } else { + player.sendMessage(BukkitMessages.FLY_ATIVADO_PARA.replace("%nick%", target.getName())); + } + + changeFly(target); + + target = null; + } + } + + public void changeFly(Player player) { + if (player.getAllowFlight()) { + player.setAllowFlight(false); + player.sendMessage(BukkitMessages.FLY_DESATIVADO); + } else { + player.setAllowFlight(true); + player.sendMessage(BukkitMessages.FLY_ATIVADO); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.java new file mode 100644 index 0000000..3ee7aed --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.java @@ -0,0 +1,80 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +public class GameModeCommand implements CommandClass { + + @Command(name = "gamemode", aliases = {"gm"}, groupsToUse = {Groups.MOD}) + public void gm(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + changeGameMode(player); + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + " alterou o seu GameMode para " + + player.getGameMode().name() + "]", Groups.ADMIN); + return; + } + + if (args.length == 1) { + Player target = BukkitServerAPI.getExactPlayerByNick(args[0]); + + if (target == null) { + if (args[0].equalsIgnoreCase("0")) { + changeGameMode(player, GameMode.SURVIVAL); + } else if (args[0].equalsIgnoreCase("1")) { + changeGameMode(player, GameMode.CREATIVE); + } else if (args[0].equalsIgnoreCase("2")) { + changeGameMode(player, GameMode.ADVENTURE); + } else if (args[0].equalsIgnoreCase("3")) { + changeGameMode(player, GameMode.SPECTATOR); + } else { + changeGameMode(player); + } + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + " alterou o seu GameMode para " + + player.getGameMode().name() + "]", Groups.ADMIN); + return; + } + + changeGameMode(target); + + player.sendMessage(BukkitMessages.GAMEMODE_CHANGE_FOR_SENDER.replace("%nick%", target.getName()).replace("%gamemode%", + target.getGameMode().name())); + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + " alterou o GameMode para de " + BukkitServerAPI.getRealNick(target) + " para " + + target.getGameMode().name() + "]", Groups.ADMIN); + } + } + + private void changeGameMode(Player player) { + changeGameMode(player, null); + } + + private void changeGameMode(Player player, GameMode preference) { + if (preference != null) { + if (preference == player.getGameMode()) { + player.sendMessage(BukkitMessages.VOCE_JA_ESTA_NESSE_GAMEMODE); + return; + } + } + + if(preference == null) { + if(player.getGameMode() == GameMode.CREATIVE) preference = GameMode.SURVIVAL; + else preference = GameMode.CREATIVE; + } + + player.setGameMode(preference); + player.sendMessage(BukkitMessages.GAMEMODE_CHANGED.replace("%gamemode%", preference.name())); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.java new file mode 100644 index 0000000..28d5175 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +public class InvseeCommand implements CommandClass { + + @Command(name = "invsee", aliases = {"inv"}, groupsToUse = {Groups.PRIME}) + public void invsee(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player p = commandSender.getPlayer(); + if (args.length == 0) { + p.sendMessage(BukkitMessages.INVSEE); + } else if (args.length == 1) { + Player d = Bukkit.getPlayer(args[0]); + + if (d == null) { + p.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + if (d == p) { + p.sendMessage(BukkitMessages.VOCE_NAO_PODE_ABRIR_SEU_INVENTARIO); + return; + } + + p.setMetadata("inventory-view", new FixedMetadataValue(BukkitMain.getInstance(), d.getUniqueId().toString())); + p.openInventory(d.getInventory()); + p.sendMessage(BukkitMessages.INVSEE_SUCESSO.replace("%nick%", d.getName())); + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(p) + " abriu o inventário de " + d.getName() + "]", Groups.ADMIN); + } else { + p.sendMessage(BukkitMessages.INVSEE); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.java new file mode 100644 index 0000000..dfe690f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.util.List; + +public class KillMobsCommand implements CommandClass { + + @Command(name = "killmobs", aliases = {"km"}, groupsToUse = {Groups.MOD}) + public void killMobs(BukkitCommandSender commandSender, String label, String[] args) { + int removidos = 0; + + for (World world : Bukkit.getWorlds()) { + List entitys = world.getEntities(); + + for (Entity entity : entitys) { + if ((entity instanceof LivingEntity) && (!(entity instanceof Player))) { + entity.remove(); + removidos++; + } + } + + entitys.clear(); + entitys = null; + } + + commandSender.sendMessage(BukkitMessages.KILL_MOBS.replace("%quantia%", "" + removidos)); + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " limpou os mobs!]", + Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.java new file mode 100644 index 0000000..0df43bb --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.java @@ -0,0 +1,123 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Completer; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.Medals; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import lombok.val; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class MedalsCommand implements CommandClass { + + @Command(name = "medals", aliases = {"medal", "medalha", "medalhas"}) + public void medals(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) return; + + Player player = commandSender.getPlayer(); + + if (args.length >= 1) { + + final String medalName = StringUtility.createArgs(0, args); + + if (Medals.existMedal(medalName)) { + + final Medals medal = Medals.getMedalByName(medalName); + if (player.hasPermission("medals." + medal.getName().toLowerCase()) || (player.hasPermission("medals.all"))) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer.getInt(DataType.MEDAL) == medal.getId()) { + player.sendMessage(BukkitMessages.TIROU_MEDALHA); + bukkitPlayer.set(DataType.MEDAL, 0); + } else { + bukkitPlayer.set(DataType.MEDAL, medal.getId()); + player.sendMessage(BukkitMessages.MEDALHA_SELECIONADA.replace("%medalha%", medal.getColor() + medal.getName())); + } + + BukkitMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + + if (!bukkitPlayer.containsFake()) bukkitPlayer.updateTag(player, bukkitPlayer.getActualTag(), true); + } else { + player.sendMessage(BukkitMessages.NAO_POSSUI_MEDALHA); + } + } else { + sendMedals(player); + } + } else { + sendMedals(player); + } + } + + private void sendMedals(final Player player) { + val playerMedals = getMedals(player); + + val message = new TextComponent(BukkitMessages.SUAS_MEDALHAS); + + for (int i = 0; i < playerMedals.size(); i++) { + message.addExtra(i == 0 ? " " : "§f, "); + if (i == 0) { + message.addExtra(""); + } + + val medal = playerMedals.get(i); + + val baseComponent = new TextComponent(medal.getSymbol()); + baseComponent.setColor(ChatColor.getByChar(medal.getColor().charAt(1))); + + baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new BaseComponent[]{new TextComponent("§eClique para selecionar a " + medal.getColor() + medal.getSymbol())})); + baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/medalha " + medal.getName())); + + message.addExtra(baseComponent); + } + + message.addExtra("§f."); + + player.spigot().sendMessage(message); + } + + private List getMedals(final Player player) { + if(player.hasPermission("medals.all")) return Arrays.asList(Medals.values()); + + return Arrays.stream(Medals.values()) + .filter(medal -> player.hasPermission("medals." + medal.getName().toLowerCase())) + .collect(Collectors.toList()); + } + + @Completer(name = "medals", aliases = {"medal", "medalha", "medalhas"}) + public List medalCompleter(BukkitCommandSender sender, String label, String[] args) { + if (sender.isPlayer()) { + + Player p = sender.getPlayer(); + + if (args.length == 1) { + List list = new ArrayList<>(); + + for (Medals m : Medals.values()) { + if (p.hasPermission("medals." + m.getName().toLowerCase()) || (p.hasPermission("medals.all"))) { + list.add(m.getName()); + } + } + + return list; + } + } + return new ArrayList<>(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.java new file mode 100644 index 0000000..a0c413d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.java @@ -0,0 +1,35 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class PingCommand implements CommandClass { + + @Command(name = "ping", aliases = {"p", "ms", "latencia"}) + public void ping(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + player.sendMessage(BukkitMessages.SEU_PING.replace("%quantia%", "" + PlayerAPI.getPing(player))); + } else if (args.length == 1) { + if (!commandSender.hasPermission("ping")) + return; + + final Player p1 = Bukkit.getPlayer(args[0]); + if (p1 == null) { + player.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + player.sendMessage(BukkitMessages.PING_OUTRO.replace("%nick%", p1.getName()).replace("%quantia%", "" + PlayerAPI.getPing(p1))); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.java new file mode 100644 index 0000000..7c1219e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.java @@ -0,0 +1,84 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.entity.Player; + +public class RankCommand implements CommandClass { + + @Command(name = "rank", aliases = {"rank", "liga", "ligas", "nivel", "level", "nvl", "lvl"}) + public void rank(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + final int XP = bukkitPlayer.getInt(DataType.XP); + League liga = League.getRanking(XP); + final int leftXp = liga.getExperience() - XP; + final int porcentLevel = liga.getExperience() - XP; + final String barExp = this.display(player, leftXp, liga.getExperience()); + League next = liga.getNextLeague(); + player.sendMessage(""); + player.sendMessage("§f" + liga.getColor() + liga.getName() + " §7" + String.valueOf(barExp) + "§7>" + " §f" + next.getNextLeague().getColor() + next.getNextLeague().getName() + " §7" + XP + "§7/" + next.getNextLeague().getExperience() + "§7 XP's" + "§f (" + porcentLevel * 100 / liga.getExperience() + "§f%)"); + + player = null; + bukkitPlayer = null; + liga = null; + } + + @Command(name = "ranklist", aliases = {"ranks", "lvllist", "leaguelist", "ligalist", "ligal"}) + public void rankList(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + final int XP = bukkitPlayer.getInt(DataType.XP); + League liga = League.getRanking(XP); + final int leftXp = liga.getExperience() - XP; + final int porcentLevel = liga.getExperience() + XP; + final String barExp = this.display(player, leftXp, liga.getExperience()); + League next = liga.getNextLeague(); + player.sendMessage(""); + player.sendMessage(""); + player.sendMessage("§aLista de ranks:"); + player.sendMessage(" §4❂ Champion"); + player.sendMessage(" §c✿ Immortal: " + League.ImmortalI.getSymbol() + "§f, §c" + League.ImmortalII.getSymbol() + "§f, §c" + League.ImmortalIII.getSymbol() + "§f, §c" + League.ImmortalIV.getSymbol()); + player.sendMessage(" §5✦ Enderlore: " + League.EnderloreI.getSymbol() + "§f, §5" + League.EnderloreII.getSymbol() + "§f, §5" + League.EnderloreIII.getSymbol() + "§f, §5" + League.EnderloreIV.getSymbol() + "§f, §5" + League.EnderloreV.getSymbol()); + player.sendMessage(" §b❆ Diamond: " + League.DiamondI.getSymbol() + "§f, §b" + League.DiamondII.getSymbol() + "§f, §b" + League.DiamondIII.getSymbol() + "§f, §b" + League.DiamondIV.getSymbol() + "§f, §b" + League.DiamondV.getSymbol()); + player.sendMessage(" §3❖ Platinum: " + League.PlatinumI.getSymbol() + "§f, §3" + League.PlatinumII.getSymbol() + "§f, §3" + League.PlatinumIII.getSymbol() + "§f, §3" + League.PlatinumIV.getSymbol() + "§f, §3" + League.PlatinumV.getSymbol()); + player.sendMessage(" §6✻ Gold: " + League.GoldI.getSymbol() + "§f, §6" + League.GoldII.getSymbol() + "§f, §6" + League.GoldIII.getSymbol() + "§f, §6" + League.GoldIV.getSymbol() + "§f, §6" + League.GoldV.getSymbol()); + player.sendMessage(" §7✯ Bronze: " + League.BronzeI.getSymbol() + "§f, §7" + League.BronzeII.getSymbol() + "§f, §7" + League.BronzeIII.getSymbol() + "§f, §7" + League.BronzeIV.getSymbol() + "§f, §7" + League.BronzeV.getSymbol()); + player.sendMessage(""); + + player = null; + bukkitPlayer = null; + liga = null; + } + + private String display(final Player player, final int remaing, final int total) { + final StringBuilder bar = new StringBuilder(); + final double percentage = remaing * 100 / total; + final double count = 20.0 - Math.max((percentage > 0.0) ? 1 : 0, percentage / 5.0); + for (int a = 0; a < count; ++a) { + bar.append("§a§m-"); + } + for (int a = 0; a < 20.0 - count; ++a) { + bar.append("§7§m-"); + } + return bar.toString(); + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.java new file mode 100644 index 0000000..63077d9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.java @@ -0,0 +1,77 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class SkinCommand implements CommandClass { + + @Command(name = "skin", groupsToUse = {Groups.PRIME}, runAsync = true) + public void skin(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + player.sendMessage(BukkitMessages.SKIN_USAGE); + return; + } + + if (requestChangeSkin(player)) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (!bukkitPlayer.canChangeSkin()) { + player.sendMessage(BukkitMessages.SKIN_AGUARDE_PARA_TROCAR); + return; + } + + bukkitPlayer.setLastChangeSkin(System.currentTimeMillis()); + + if (args[0].equalsIgnoreCase("atualizar")) { + player.sendMessage(BukkitMessages.SKIN_DOWNLOADING); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_UPDATE_SKIN).field(args[0])); + + } else if (args[0].equalsIgnoreCase("random")) { + player.sendMessage(BukkitMessages.SKIN_DOWNLOADING); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_RANDOM_SKIN)); + } else { + if (!MySQLManager.contains("skins", "nick", args[0])) { + player.sendMessage(BukkitMessages.SKIN_DOWNLOADING); + } + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_SKIN).field(args[0])); + } + } else { + player.sendMessage(BukkitMessages.VOCE_NAO_PODE_TROCAR_SUA_SKIN_AGORA); + } + } + + private boolean requestChangeSkin(Player player) { + PlayerRequestEvent event = new PlayerRequestEvent(player, "skin"); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + player.sendMessage("§cVocê não pode trocar sua skin agora!"); + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.java new file mode 100644 index 0000000..51fe781 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.java @@ -0,0 +1,153 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Completer; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.*; + +public class SpyCommand implements CommandClass { + + public static final HashMap> spying = new HashMap<>(); + private final String COMMAND_USAGE = "§a§lSPY §fUtilize: /spy ", + SPYING_ALL = "§a§lSPY §fVocê está espiando todos os §a§lTELLS!", + NOT_SPYING_ALL = "§a§lSPY §fVocê não está espionando mais!", + NOT_SPYING_PLAYER = "§a§lSPY §fVocê não está espiando o jogador §a%nick%", + SPYING_PLAYER = "§a§lSPY §fVocê está espiando o jogador §a%nick%"; + + public static List getSpys() { + List list = new ArrayList<>(); + + for (UUID uuids : spying.keySet()) { + Player target = Bukkit.getPlayer(uuids); + if (target != null && target.isOnline()) { + list.add(target); + } + } + + return list; + } + + public static boolean isSpyingPlayer(Player player, String nick) { + if (!spying.containsKey(player.getUniqueId())) { + return false; + } + + return spying.get(player.getUniqueId()).contains(nick); + } + + public static boolean isSpyingAll(Player player) { + if (!spying.containsKey(player.getUniqueId())) { + return false; + } + + return spying.get(player.getUniqueId()).contains("all"); + } + + @Command(name = "spy", aliases = {"espiar"}, groupsToUse = {Groups.MOD}) + public void spy(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length != 1) { + player.sendMessage(COMMAND_USAGE); + return; + } + + String nick = args[0]; + + if (isAll(nick)) { + if (!spying.containsKey(player.getUniqueId())) { + spying.put(player.getUniqueId(), Collections.singletonList("all")); + player.sendMessage(SPYING_ALL); + } else { + if (!spying.get(player.getUniqueId()).contains("all")) { + spying.put(player.getUniqueId(), Collections.singletonList("all")); + player.sendMessage(SPYING_ALL); + } else { + spying.remove(player.getUniqueId()); + player.sendMessage(NOT_SPYING_ALL); + } + } + + } else { + Player target = Bukkit.getPlayer(nick); + + if (target != null) { + + final String realNick = BukkitMain.getBukkitPlayer(target.getUniqueId()).getNick(); + + if (!spying.containsKey(player.getUniqueId())) { + spying.put(player.getUniqueId(), Collections.singletonList(realNick)); + player.sendMessage(SPYING_PLAYER.replace("%nick%", realNick)); + } else { + if (spying.get(player.getUniqueId()).contains(realNick)) { + List list = spying.get(player.getUniqueId()); + list.remove(realNick); + + if (list.size() == 0) { + spying.remove(player.getUniqueId()); + } else { + spying.put(player.getUniqueId(), list); + } + player.sendMessage(NOT_SPYING_PLAYER.replace("%nick%", realNick)); + + list.clear(); + list = null; + + } else { + List list = spying.get(player.getUniqueId()); + list.add(realNick); + + spying.put(player.getUniqueId(), list); + + player.sendMessage(SPYING_PLAYER.replace("%nick%", realNick)); + + list.clear(); + list = null; + } + } + + target = null; + } else { + player.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + } + } + } + + private boolean isAll(String nick) { + if (nick.equalsIgnoreCase("*")) return true; + if (nick.equalsIgnoreCase("all")) return true; + return nick.equalsIgnoreCase("todos"); + } + + @Completer(name = "spy", aliases = {"espiar"}) + public List tagcompleter(BukkitCommandSender sender, String label, String[] args) { + if (sender.isPlayer()) { + + if (args.length == 1) { + List list = new ArrayList<>(); + list.add("all"); + + for (Player ons : Bukkit.getOnlinePlayers()) { + if (ons.getName().toLowerCase().startsWith(args[0].toLowerCase())) { + list.add(ons.getName()); + } + } + + return list; + } + } + + return new ArrayList<>(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.java new file mode 100644 index 0000000..c39ee2b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.java @@ -0,0 +1,78 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStopEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.PlayerBukkitQueue; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.QueueType; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class StopCommand implements CommandClass { + + @Command(name = "stop", aliases = {"rl", "reload", "parar", "reiniciar", "stop"}, groupsToUse = {Groups.ADMIN}) + public void stop(BukkitCommandSender commandSender, String label, String[] args) { + commandSender.sendMessage(""); + commandSender.sendMessage(BukkitMessages.STOP_PREFIX); + commandSender.sendMessage(""); + + Bukkit.getServer().getPluginManager().callEvent(new ServerStopEvent()); + + if (Bukkit.getOnlinePlayers().size() == 0) { + Bukkit.shutdown(); + return; + } + + BukkitSettings.DANO_OPTION = false; + BukkitSettings.PVP_OPTION = false; + BukkitSettings.CHAT_OPTION = false; + BukkitSettings.LOGIN_OPTION = false; + + commandSender.sendMessage(BukkitMessages.STOP_SENDING_PLAYERS_TO_LOBBY); + + ServerType serverToConnect = ServerType.LOBBY; + + if (BukkitMain.getServerType().isPvP(false)) { + serverToConnect = ServerType.LOBBY_PVP; + } else if (BukkitMain.getServerType().isHardcoreGames(false)) { + serverToConnect = ServerType.LOBBY_HARDCOREGAMES; + } + + if (BukkitMain.getServerType() != ServerType.LOBBY && BukkitMain.getServerType() != ServerType.LOGIN) { + PlayerBukkitQueue queue = new PlayerBukkitQueue(15, true, QueueType.CONNECT); + queue.setStopOnFinish(true); + queue.setDestroyOnFinish(true); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + queue.addToQueue(onlines, serverToConnect.getName()); + + onlines.sendMessage(BukkitMessages.PLAYER_SERVER_RESTARTING); + } + + queue.start(); + } else { + PlayerBukkitQueue queue = new PlayerBukkitQueue(10, true, QueueType.KICK); + queue.setStopOnFinish(true); + queue.setDestroyOnFinish(true); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + queue.addToQueue(onlines); + onlines.sendMessage(BukkitMessages.PLAYER_SERVER_RESTARTING); + } + + queue.start(); + } + commandSender.sendMessage(""); + + if (!commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " executou o comando para parar o servidor!]", Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.java new file mode 100644 index 0000000..a107de5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.ArrayList; + +public class SyncTpallCommand implements CommandClass { + + private boolean running = false; + + @Command(name = "synctpall", aliases = {"stpall"}, groupsToUse = {Groups.MOD}) + public void synctpall(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (running) { + commandSender.sendMessage(BukkitMessages.SYNC_TPALL_RUNNING); + return; + } + + running = true; + startSyncTpall(commandSender.getPlayer()); + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(commandSender.getPlayer()) + " puxou todos os jogadores sincronizadamente]", Groups.ADMIN); + } + + private void startSyncTpall(Player player) { + new BukkitRunnable() { + + final Location loc = player.getLocation(); + final ArrayList players = (ArrayList) player.getWorld().getPlayers(); + final int toTeleport = players.size(); + int teleporteds = 0; + + public void run() { + if (teleporteds >= toTeleport) { + cancel(); + running = false; + if (player.isOnline()) { + player.sendMessage(BukkitMessages.SYNC_TPALL_FINALIZED); + } + return; + } + + for (int i = 0; i < 2; i++) { + try { + Player t = players.get(teleporteds + i); + if ((t != null) && (t != player)) { + t.teleport(loc); + } + } catch (IndexOutOfBoundsException e) { + } catch (NullPointerException e) { + } + } + teleporteds = teleporteds += 2; + } + }.runTaskTimer(BukkitMain.getInstance(), 5L, 5L); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.java new file mode 100644 index 0000000..797d386 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.java @@ -0,0 +1,106 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Completer; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import lombok.val; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class TagCommand implements CommandClass { + + @Command(name = "tag") + public void tag(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) return; + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + sendTags(player); + } else if (args.length == 1) { + String selectedGroup = args[0]; + + if (Groups.existGrupo(selectedGroup)) { + Groups group = Groups.getGroup(selectedGroup); + + if (TagManager.hasPermission(player, group)) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (!bukkitPlayer.getActualTag().getName().equals(group.getTag().getName())) { + bukkitPlayer.updateTag(player, group.getTag(), false); + } else { + player.sendMessage(BukkitMessages.VOCE_JA_ESTA_USANDO_ESTA_TAG); + } + } else { + player.sendMessage(BukkitMessages.NAO_POSSUI_TAG); + + } + } else { + sendTags(player); + } + } + } + + private void sendTags(final Player player) { + List playerGroups = TagManager.getPlayerGroups(player); + + TextComponent message = new TextComponent(BukkitMessages.SUAS_TAGS); + + for (int i = 0; i < playerGroups.size(); i++) { + message.addExtra(i == 0 ? " " : "§f, "); + + if (i == 0) { + message.addExtra(""); + } + + Groups group = playerGroups.get(i); + + BaseComponent baseComponent = new TextComponent(group.getName()); + baseComponent.setColor(ChatColor.getByChar(group.getColor().charAt(1))); + + baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new BaseComponent[]{new TextComponent("§7Prévia: " + group.getColor() + "§l" + group.getTag().getPrefix() + " " + group.getColor() + player.getName() + "\n§eClique para selecionar!")})); + baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tag " + group.getName())); + + message.addExtra(baseComponent); + } + + message.addExtra("§f."); + + player.spigot().sendMessage(message); + } + + @Completer(name = "tag") + public List tagCompleter(BukkitCommandSender sender, String label, String[] args) { + if(!sender.isPlayer()) return Collections.emptyList(); + + val p = sender.getPlayer(); + + if(args.length < 1) return Arrays.stream(Groups.values()) + .filter(group -> TagManager.hasPermission(p, group)) + .map(Groups::getName) + .collect(Collectors.toList()); + + if(args.length > 1) return Collections.emptyList(); + + return Arrays.stream(Groups.values()) + .filter(group -> group.getName().toLowerCase().startsWith(args[0].toLowerCase()) && TagManager.hasPermission(p, group)) + .map(Groups::getName) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.java new file mode 100644 index 0000000..d0442cc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.java @@ -0,0 +1,119 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class TeleportCommand implements CommandClass { + + @Command(name = "tp", aliases = {"teleport"}, groupsToUse = {Groups.PRIME}) + public void tp(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage(BukkitMessages.TELEPORT_USAGE); + } else if (args.length == 1) { + Player target = Bukkit.getServer().getPlayer(args[0]); + + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + Player player = commandSender.getPlayer(); + + player.setFallDistance(-5); + player.teleport(target.getLocation()); + + commandSender.sendMessage(BukkitMessages.TELEPORTED_TO_PLAYER.replace("%nick%", target.getName())); + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + " se teleportou para o " + + BukkitServerAPI.getRealNick(target) + "]", Groups.ADMIN); + + target = null; + player = null; + } else if (args.length == 2) { + Player player1 = Bukkit.getServer().getPlayer(args[0]), player2 = Bukkit.getServer().getPlayer(args[1]); + + if (player1 == null || player2 == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + player1.setFallDistance(-5); + player1.teleport(player2.getLocation()); + + commandSender.sendMessage(BukkitMessages.TELEPORTED_PLAYER_TO_PLAYER.replace("%nick%", player1.getName()) + .replace("%nick1%", player2.getName())); + + BukkitServerAPI.warnStaff( + "§7[" + BukkitServerAPI.getRealNick(player1) + " foi teleportado para o " + + BukkitServerAPI.getRealNick(player2) + " pelo " + commandSender.getNick() + "]", + Groups.ADMIN); + + player1 = null; + player2 = null; + } else if (args.length == 3) { + if (!StringUtility.isInteger(args[0]) || !StringUtility.isInteger(args[1]) + || !StringUtility.isInteger(args[2])) { + commandSender.sendMessage(BukkitMessages.TELEPORT_USAGE); + return; + } + + int x = Integer.parseInt(args[0]), y = Integer.parseInt(args[1]), z = Integer.parseInt(args[2]); + + Player player = commandSender.getPlayer(); + Location loc = new Location(player.getWorld(), x + 0.500, y, z + 0.500); + + player.setFallDistance(-5); + player.teleport(loc); + + commandSender.sendMessage( + BukkitMessages.TELEPORTED_TO_LOCATION.replace("%coords%", "x " + x + ", y " + y + ", z " + z)); + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + + " se teleportou para as coordenadas: " + x + ", " + y + ", " + z + "]", Groups.ADMIN); + + loc = null; + player = null; + } else if (args.length == 4) { + Player target = Bukkit.getServer().getPlayer(args[0]); + + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + if (!StringUtility.isInteger(args[1]) || !StringUtility.isInteger(args[2]) + || !StringUtility.isInteger(args[3])) { + commandSender.sendMessage(BukkitMessages.TELEPORT_USAGE); + return; + } + + int x = Integer.parseInt(args[1]), y = Integer.parseInt(args[2]), z = Integer.parseInt(args[3]); + + Location loc = new Location(target.getWorld(), x + 0.500, y, z + 0.500); + target.setFallDistance(-5); + target.teleport(loc); + + commandSender.sendMessage(BukkitMessages.TELEPORTED_PLAYER_TO_LOCATION.replace("%nick%", target.getName()) + .replace("%coords%", "x " + x + ", y " + y + ", z " + z)); + BukkitServerAPI + .warnStaff("§7[" + BukkitServerAPI.getRealNick(target) + " foi teleportado para as coordenadas: " + + x + ", " + y + ", " + z + " pelo " + commandSender.getNick() + "]", Groups.ADMIN); + + target = null; + loc = null; + } else { + commandSender.sendMessage(BukkitMessages.TELEPORT_USAGE); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.java new file mode 100644 index 0000000..614ab9d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.java @@ -0,0 +1,138 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class TellCommand implements CommandClass { + + @Command(name = "tell", aliases = {"pm"}, runAsync = true) + public void tell(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + player.sendMessage(BukkitMessages.COMMAND_TELL_USAGE); + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("on")) { + DataHandler dataHandler = BukkitMain.getBukkitPlayer(player.getUniqueId()).getDataHandler(); + if (dataHandler.getBoolean(DataType.RECEIVE_PRIVATE_MESSAGES)) { + player.sendMessage(BukkitMessages.TELL_JA_ESTA_ATIVADO); + return; + } + dataHandler.getData(DataType.RECEIVE_PRIVATE_MESSAGES).setValue(true); + player.sendMessage(BukkitMessages.TELL_ATIVADO); + + BukkitMain.runAsync(() -> dataHandler.saveCategory(DataCategory.ACCOUNT)); + } else if (args[0].equalsIgnoreCase("off")) { + DataHandler dataHandler = BukkitMain.getBukkitPlayer(player.getUniqueId()).getDataHandler(); + if (!dataHandler.getBoolean(DataType.RECEIVE_PRIVATE_MESSAGES)) { + player.sendMessage(BukkitMessages.TELL_JA_ESTA_ATIVADO); + return; + } + dataHandler.getData(DataType.RECEIVE_PRIVATE_MESSAGES).setValue(false); + player.sendMessage(BukkitMessages.TELL_DESATIVADO); + + BukkitMain.runAsync(() -> dataHandler.saveCategory(DataCategory.ACCOUNT)); + } else { + player.sendMessage(BukkitMessages.COMMAND_TELL_USAGE); + } + } else { + handleTell(player, Bukkit.getPlayer(args[0]), StringUtility.createArgs(1, args)); + } + } + + private void handleTell(Player sender, Player receiver, String mensagem) { + if (receiver == null) { + sender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + if (receiver == sender) { + sender.sendMessage(BukkitMessages.VOCE_NAO_PODE_ENVIAR_MENSAGEM_PARA_VOCE_MESMO); + return; + } + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(sender.getUniqueId()), + bukkitPlayer1 = BukkitMain.getBukkitPlayer(receiver.getUniqueId()); + + if (VanishAPI.isInvisible(receiver)) { + if (bukkitPlayer.getGroup().getLevel() <= Groups.PRIME.getLevel()) { + sender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + } + + if (!bukkitPlayer1.getBoolean(DataType.RECEIVE_PRIVATE_MESSAGES)) { + sender.sendMessage(BukkitMessages.JOGADOR_COM_TELL_DESATIVADO); + return; + } + + bukkitPlayer.setLastMessage(receiver.getName()); + bukkitPlayer1.setLastMessage(sender.getName()); + + final Tag tag = bukkitPlayer.getGroup().getTag(), tag1 = bukkitPlayer1.getGroup().getTag(); + + sender.sendMessage(BukkitMessages.TELL_PARA_JOGADOR.replace("%nick%", tag1.getColor() + receiver.getName()) + .replace("%mensagem%", mensagem)); + + receiver.sendMessage(BukkitMessages.TELL_DE_JOGADOR.replace("%nick%", tag.getColor() + sender.getName()) + .replace("%mensagem%", mensagem)); + + if (SpyCommand.spying.size() != 0) { + for (Player spys : SpyCommand.getSpys()) { + if (SpyCommand.isSpyingAll(spys)) { + spys.sendMessage(BukkitMessages.TELL_SPY.replace("%nick%", tag.getColor() + sender.getName()) + .replace("%nick1%", tag1.getColor() + receiver.getName()).replace("%mensagem%", mensagem)); + } else { + boolean send = false; + + if (SpyCommand.isSpyingPlayer(spys, bukkitPlayer.getNick())) { + send = true; + } else if (SpyCommand.isSpyingPlayer(spys, bukkitPlayer.getNick())) { + send = true; + } + + if (send) { + spys.sendMessage(BukkitMessages.TELL_SPY.replace("%nick%", tag.getColor() + sender.getName()) + .replace("%nick1%", tag1.getColor() + receiver.getName()) + .replace("%mensagem%", mensagem)); + } + } + } + } + } + + @Command(name = "reply", aliases = {"r"}) + public void reply(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + if (args.length == 0) { + player.sendMessage(BukkitMessages.COMMAND_REPLY_USAGE); + return; + } + final BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + if (bukkitPlayer.getLastMessage().equalsIgnoreCase("")) { + player.sendMessage(BukkitMessages.VOCE_NAO_TEM_NENHUMA_CONVERSA_PARA_RESPONDER); + return; + } + handleTell(player, Bukkit.getPlayer(bukkitPlayer.getLastMessage()), StringUtility.createArgs(0, args)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.java new file mode 100644 index 0000000..20157a4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class TpallCommand implements CommandClass { + + @Command(name = "tpall", groupsToUse = {Groups.ADMIN}) + public void tpall(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + Location loc = player.getLocation(); + + for (Player ons : Bukkit.getOnlinePlayers()) { + if (ons != player) { + ons.setFallDistance(-5); + ons.teleport(loc); + } + } + + player.sendMessage(BukkitMessages.TPALL); + + BukkitServerAPI.warnStaff("§7[" + BukkitServerAPI.getRealNick(player) + " puxou todos os jogadores]", Groups.ADMIN); + + loc = null; + player = null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.java new file mode 100644 index 0000000..e8de9dd --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.java @@ -0,0 +1,155 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.commands.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.Constructions; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class WorldEditCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "worldedit", aliases = {"we"}, groupsToUse = {Groups.ADMIN}) + public void worldedit(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /worldedit "); + commandSender.sendMessage("§cUse: /worldedit set "); + commandSender.sendMessage("§cUse: /worldedit setblockpertick "); + commandSender.sendMessage(""); + return; + } + Player player = commandSender.getPlayer(); + if (args.length == 1) { + if (args[0].equalsIgnoreCase("machado")) { + player.getInventory().addItem(new ItemBuilder().type(Material.WOOD_AXE).name("§e§lWORLDEDIT").build()); + player.sendMessage("§e§lWORLDEDIT §fVocê recebeu o Machado."); + } else if (args[0].equalsIgnoreCase("undo")) { + if (!WorldEditManager.hasRollingConstructionByUUID(player.getUniqueId())) { + commandSender.sendMessage("§e§lWORLDEDIT §fVocê não possuí uma construção."); + return; + } + Constructions construction = WorldEditManager.getConstructionByUUID(player.getUniqueId()); + if (construction.isFinished()) { + commandSender.sendMessage("§e§lWORLDEDIT §fA construção ainda está em andamento."); + return; + } + if (construction.isResetando()) { + commandSender.sendMessage("§e§lWORLDEDIT §fA construção já está em sendo resetada."); + return; + } + construction.startRegress(); + commandSender.sendMessage("§e§lWORLDEDIT §fRetirando blocos..."); + } else { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /worldedit "); + commandSender.sendMessage("§cUse: /worldedit set "); + commandSender.sendMessage("§cUse: /worldedit setblockpertick "); + commandSender.sendMessage(""); + } + } else if (args.length == 2) { + if (args[0].contentEquals("setblockpertick")) { + if (!StringUtility.isInteger(args[1])) { + commandSender.sendMessage("§cUse: /worldedit setblockpertick "); + return; + } + if (!WorldEditManager.hasRollingConstructionByUUID(player.getUniqueId())) { + commandSender.sendMessage("§e§lWORLDEDIT §fVocê não possuí uma construção."); + return; + } + int quantia = Integer.valueOf(args[1]); + if (quantia > 1000) { + commandSender.sendMessage("§e§lWORLDEDIT §fValor máximo de apenas 1,000 blocos."); + return; + } + Constructions construction = WorldEditManager.getConstructionByUUID(player.getUniqueId()); + construction.setBlocksPerTick(quantia); + commandSender.sendMessage("§e§lWORLDEDIT §fValor alterado."); + } else if (args[0].equalsIgnoreCase("set")) { + String idsOriginal = args[1]; + String ids = args[1].replaceAll(",", ""); + if (!StringUtility.isInteger(ids)) { + commandSender.sendMessage("§cUse: /worldedit set "); + return; + } + if (WorldEditManager.hasRollingConstructionByUUID(player.getUniqueId())) { + if (!WorldEditManager.getConstructionByUUID(player.getUniqueId()).isFinished()) { + commandSender.sendMessage("§e§lWORLDEDIT §fVocê já possuí uma construção em andamento."); + return; + } + } + if (WorldEditManager.continueEdit(player)) { + List materiaisIds = new ArrayList<>(); + + if (idsOriginal.contains(",")) { + boolean error = false; + for (String string : idsOriginal.split(",")) { + try { + materiaisIds.add(Material.getMaterial(Integer.valueOf(string))); + } catch (NullPointerException ex) { + error = true; + break; + } + } + if (error) { + player.sendMessage("§e§lWORLDEDIT §fOcorreu um erro ao tentar encontrar o material."); + return; + } + + } else { + try { + materiaisIds.add(Material.getMaterial(Integer.valueOf(args[1]))); + } catch (NullPointerException ex) { + player.sendMessage("§e§lWORLDEDIT §fOcorreu um erro ao tentar encontrar o material."); + return; + } + } + + player.sendMessage("§e§lWORLDEDIT §fProcessando blocos..."); + List locations = null; + try { + locations = WorldEditManager.getLocationsFromTwoPoints( + WorldEditManager.getPos1(player), WorldEditManager.getPos2(player)); + } catch (Exception ex) { + player.sendMessage("§e§lWORLDEDIT §fErro ao processar os blocos..."); + return; + } finally { + player.sendMessage("§e§lWORLDEDIT §e" + StringUtility.formatValue(locations.size()) + " §fblocos processados."); + } + + WorldEditManager.addConstructionByUUID(player, locations); + WorldEditManager.getConstructionByUUID(player.getUniqueId()).setBlocksToSet(materiaisIds); + WorldEditManager.getConstructionByUUID(player.getUniqueId()).start(); + + locations.clear(); + materiaisIds.clear(); + } + } else { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /worldedit "); + commandSender.sendMessage("§cUse: /worldedit set "); + commandSender.sendMessage("§cUse: /worldedit setblockpertick "); + commandSender.sendMessage(""); + } + } else { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /worldedit "); + commandSender.sendMessage("§cUse: /worldedit set "); + commandSender.sendMessage("§cUse: /worldedit setblockpertick "); + commandSender.sendMessage(""); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.java new file mode 100644 index 0000000..18cd6d6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events; + +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +public class BukkitUpdateEvent extends Event { + + public static final HandlerList handlers = new HandlerList(); + private final UpdateType type; + private final long currentTick; + + public BukkitUpdateEvent(UpdateType type) { + this(type, -1); + } + + public BukkitUpdateEvent(UpdateType type, long currentTick) { + this.type = type; + this.currentTick = currentTick; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + public enum UpdateType { + TICK, SEGUNDO, MINUTO, HORA + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.java new file mode 100644 index 0000000..fd9888d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerAdminChangeEvent extends PlayerCancellableEvent { + + private final AdminChangeType changeType; + + public PlayerAdminChangeEvent(Player player, final AdminChangeType changeType) { + super(player); + this.changeType = changeType; + } + + public enum AdminChangeType { + ENTROU, SAIU + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.java new file mode 100644 index 0000000..a51cc12 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.java @@ -0,0 +1,43 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlayerCancellableEvent extends Event implements Cancellable { + public Player player; + + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled = false; + + public PlayerCancellableEvent(Player player) { + this(player, false); + } + + public PlayerCancellableEvent(Player player, boolean async) { + super(async); + this.player = player; + } + + public Player getPlayer() { + return this.player; + } + + public boolean isCancelled() { + return this.cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.java new file mode 100644 index 0000000..1b28857 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.java @@ -0,0 +1,18 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; + +@Getter +@Setter +public class PlayerChangeGroupEvent extends PlayerEvent { + + private Groups group; + + public PlayerChangeGroupEvent(Player player, final Groups group) { + super(player); + setGroup(group); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.java new file mode 100644 index 0000000..d392d2a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerChangeScoreboardEvent extends PlayerCancellableEvent { + + private final ScoreboardChangeType changeType; + + public PlayerChangeScoreboardEvent(Player player, final ScoreboardChangeType changeType) { + super(player); + this.changeType = changeType; + } + + public enum ScoreboardChangeType { + ATIVOU, DESATIVOU + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.java new file mode 100644 index 0000000..4134329 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerChangeTagEvent extends PlayerCancellableEvent { + + private final Tag oldTag; + private final Tag newTag; + private final boolean forced; + + public PlayerChangeTagEvent(Player p, Tag oldTag, Tag newTag, boolean forced) { + super(p); + this.oldTag = oldTag; + this.newTag = newTag; + this.forced = forced; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.java new file mode 100644 index 0000000..c921e9a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.java @@ -0,0 +1,15 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerChangeVisibilityEvent extends PlayerCancellableEvent { + + private final boolean visibility; + + public PlayerChangeVisibilityEvent(Player player, final boolean visibility) { + super(player); + this.visibility = visibility; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.java new file mode 100644 index 0000000..3d7884b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlayerEvent extends Event { + public Player player; + + private static final HandlerList handlers = new HandlerList(); + + public PlayerEvent(Player who) { + this(who, false); + } + + public PlayerEvent(Player who, boolean async) { + super(async); + this.player = who; + } + + public Player getPlayer() { + return this.player; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.java new file mode 100644 index 0000000..5b04862 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import com.br.guilhermematthew.nowly.commons.bukkit.queue.QueueType; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; + +@Getter +@Setter +public class PlayerQueueEvent extends PlayerEvent { + + private QueueType queueType; + private String response; + + public PlayerQueueEvent(Player player, QueueType queueType) { + this(player, queueType, ""); + } + + public PlayerQueueEvent(Player player, QueueType queueType, String response) { + super(player); + this.queueType = queueType; + this.response = response; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.java new file mode 100644 index 0000000..9df3300 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.java @@ -0,0 +1,15 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerRequestEvent extends PlayerCancellableEvent { + + private final String requestType; + + public PlayerRequestEvent(Player player, String requestType) { + super(player); + this.requestType = requestType; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.java new file mode 100644 index 0000000..d423213 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.java @@ -0,0 +1,16 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player; + +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; + +@Getter +@Setter +public class PlayerUpdateTabEvent extends PlayerEvent { + + private String header, footer; + + public PlayerUpdateTabEvent(Player player) { + super(player); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.java new file mode 100644 index 0000000..1847209 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.java @@ -0,0 +1,18 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ServerLoadedEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.java new file mode 100644 index 0000000..ff4e24c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.java @@ -0,0 +1,64 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server; + +import com.google.gson.JsonObject; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import java.util.Arrays; +import java.util.List; + +@Getter +public class ServerStatusUpdateEvent extends Event { + + private static final JsonObject CACHED_JSON = new JsonObject(); + private static final HandlerList handlers = new HandlerList(); + private final List LIST = Arrays.asList("onlines", "maxPlayers", "online", "whiteList", "lastUpdate", "membersSlots", "mapName", + "playersGaming", "tempo", "stage"); + + public ServerStatusUpdateEvent(final int onlines, + final boolean online) { + + for (String name : LIST) { + if (CACHED_JSON.has(name)) CACHED_JSON.remove(name); + } + + CACHED_JSON.addProperty("onlines", onlines); + CACHED_JSON.addProperty("maxPlayers", Bukkit.getMaxPlayers()); + + CACHED_JSON.addProperty("online", online); + CACHED_JSON.addProperty("whiteList", Bukkit.getServer().hasWhitelist()); + CACHED_JSON.addProperty("lastUpdate", System.currentTimeMillis()); + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public void writeMemberSlots(final int membersSlots) { + CACHED_JSON.addProperty("membersSlots", membersSlots); + } + + public void writeSkyWars(final int playersGaming, final int tempo, final String stage, final String mapName, final String skyWarType) { + CACHED_JSON.addProperty("mapName", mapName); + CACHED_JSON.addProperty("playersGaming", playersGaming); + CACHED_JSON.addProperty("tempo", tempo); + CACHED_JSON.addProperty("stage", stage); + } + + public void writeHungerGames(final int playersGaming, final int tempo, final String stage) { + CACHED_JSON.addProperty("playersGaming", playersGaming); + CACHED_JSON.addProperty("tempo", tempo); + CACHED_JSON.addProperty("stage", stage); + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public JsonObject getJson() { + return CACHED_JSON; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.java new file mode 100644 index 0000000..8de388b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.java @@ -0,0 +1,18 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ServerStopEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.java new file mode 100644 index 0000000..c8423e5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.java @@ -0,0 +1,27 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector; + +import io.netty.channel.Channel; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.server.v1_8_R3.Packet; +import org.bukkit.entity.Player; + +@Getter +@Setter +public class PacketObject { + + private boolean cancelled; + private Player player; + private Channel channel; + + @SuppressWarnings("rawtypes") + private Packet packet; + + @SuppressWarnings("rawtypes") + public PacketObject(Player player, Channel channel, Packet packet) { + this.player = player; + this.channel = channel; + this.packet = packet; + this.cancelled = false; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.java new file mode 100644 index 0000000..f17f069 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.java @@ -0,0 +1,10 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.PacketObject; + +public interface PacketListener { + + void onPacketReceiving(PacketObject packetObject); + + void onPacketSending(PacketObject packetObject); +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.java new file mode 100644 index 0000000..0568909 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener; + +import java.util.ArrayList; + +public class PacketListenerAPI { + + private static final ArrayList listeners = new ArrayList<>(); + + public static ArrayList getListeners() { + return listeners; + } + + public static void addListener(PacketListener listener) { + listeners.add(listener); + } + + public static void removeListener(PacketListener listener) { + listeners.remove(listener); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.java new file mode 100644 index 0000000..c001a7d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.NPCInteractEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.click.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.PacketObject; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListener; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListenerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.plugin.Plugin; + +public class NPCPacketInjector { + + private static final Class packetPlayInUseEntityClazz = Reflection.getMinecraftClass("PacketPlayInUseEntity"); + + @SuppressWarnings("rawtypes") + private static final Reflection.FieldAccessor entityIdField = Reflection.getField(packetPlayInUseEntityClazz, "a", int.class); + + @SuppressWarnings("rawtypes") + private static final Reflection.FieldAccessor actionField = Reflection.getField(packetPlayInUseEntityClazz, "action", Object.class); + + private static final String DELAY_TIME_TAG = "DELAY.NPC"; + + public static void inject(Plugin plugin) { + PacketListenerAPI.addListener(new PacketListener() { + + public void onPacketReceiving(PacketObject packetObject) { + if (packetPlayInUseEntityClazz.isInstance(packetObject.getPacket())) { + + NPC npc = NPCManager.getAllNPCs().stream().filter( + check -> check.getEntityId() == (int) entityIdField.get(packetObject.getPacket())) + .findFirst().orElse(null); + + if (npc == null) { + return; + } + + if (hasDelay(packetObject.getPlayer())) { + return; + } + + addDelay(packetObject.getPlayer()); + + ClickType clickType = actionField.get(packetObject.getPacket()).toString() + .equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK; + + Bukkit.getPluginManager().callEvent(new NPCInteractEvent(packetObject.getPlayer(), clickType, npc)); + } + } + + public void onPacketSending(PacketObject packetObject) { + } + }); + } + + private static void addDelay(Player player) { + player.setMetadata(DELAY_TIME_TAG, new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis() + 700)); + } + + private static boolean hasDelay(Player player) { + if (!player.hasMetadata(DELAY_TIME_TAG)) return false; + return player.getMetadata(DELAY_TIME_TAG).get(0).asLong() > System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.java new file mode 100644 index 0000000..92a313f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.java @@ -0,0 +1,68 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.packets; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.PacketObject; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListener; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.listener.PacketListenerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.protocol.CommonProtocol; +import io.netty.channel.Channel; +import net.minecraft.server.v1_8_R3.Packet; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.Iterator; +import java.util.List; + +public class ServerPacketInjector { + + public static void inject(final Plugin plugin) { + BukkitMain.console("§a[ServerPacketInjector] has been injected!"); + + new CommonProtocol(plugin) { + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public Object onPacketOutAsync(final Player reciever, Channel channel, Object packet) { + if (!(packet instanceof Packet)) + return super.onPacketOutAsync(reciever, channel, packet); + + if (channel == null) { + return super.onPacketOutAsync(reciever, channel, packet); + } + + PacketObject object = new PacketObject(reciever, channel, (Packet) packet); + + Iterator iterator = ((List) PacketListenerAPI.getListeners().clone()).iterator(); + while (iterator.hasNext()) { + iterator.next().onPacketSending(object); + } + + if (object.isCancelled()) + return null; + return object.getPacket(); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public Object onPacketInAsync(Player sender, Channel channel, Object packet) { + if (!(packet instanceof Packet)) + return super.onPacketInAsync(sender, channel, packet); + + if (channel == null) { + return super.onPacketInAsync(sender, channel, packet); + } + + PacketObject object = new PacketObject(sender, channel, (Packet) packet); + + Iterator iterator = ((List) PacketListenerAPI.getListeners().clone()).iterator(); + while (iterator.hasNext()) { + iterator.next().onPacketReceiving(object); + } + + if (object.isCancelled()) + return null; + return object.getPacket(); + } + }; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.java new file mode 100644 index 0000000..d988872 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.java @@ -0,0 +1,329 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.protocol; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection.FieldAccessor; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.Reflection.MethodInvoker; +import com.google.common.collect.Lists; +import com.google.common.collect.MapMaker; +import com.mojang.authlib.GameProfile; +import io.netty.channel.*; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; + +public class CommonProtocol { + + private static final AtomicInteger ID = new AtomicInteger(0); + + private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle"); + private static final FieldAccessor getConnection = Reflection.getField("{nms}.EntityPlayer", "playerConnection", Object.class); + private static final FieldAccessor getManager = Reflection.getField("{nms}.PlayerConnection", "networkManager", Object.class); + private static final FieldAccessor getChannel = Reflection.getField("{nms}.NetworkManager", Channel.class, 0); + + private static final Class minecraftServerClass = Reflection.getUntypedClass("{nms}.MinecraftServer"); + private static final Class serverConnectionClass = Reflection.getUntypedClass("{nms}.ServerConnection"); + private static final FieldAccessor getMinecraftServer = Reflection.getField("{obc}.CraftServer", minecraftServerClass, 0); + private static final FieldAccessor getServerConnection = Reflection.getField(minecraftServerClass, serverConnectionClass, 0); + private static final MethodInvoker getNetworkMarkers = Reflection.getTypedMethod(serverConnectionClass, null, List.class, serverConnectionClass); + + private static final Class PACKET_LOGIN_IN_START = Reflection.getMinecraftClass("PacketLoginInStart"); + private static final FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0); + protected volatile boolean closed; + protected final Plugin plugin; + private final Map channelLookup = new MapMaker().weakValues().makeMap(); + private Listener listener; + private final Set uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap()); + private List networkManagers; + private final List serverChannels = Lists.newArrayList(); + private ChannelInboundHandlerAdapter serverChannelHandler; + private ChannelInitializer beginInitProtocol; + private ChannelInitializer endInitProtocol; + private final String handlerName; + + public CommonProtocol(final Plugin plugin) { + this.plugin = plugin; + + this.handlerName = getHandlerName(); + + registerBukkitEvents(); + + try { + registerChannelHandler(); + registerPlayers(plugin); + } catch (IllegalArgumentException ex) { + new BukkitRunnable() { + @Override + public void run() { + registerChannelHandler(); + registerPlayers(plugin); + } + }.runTask(plugin); + } + } + + private void createServerChannelHandler() { + endInitProtocol = new ChannelInitializer() { + + @Override + protected void initChannel(Channel channel) { + try { + synchronized (networkManagers) { + if (!closed) { + injectChannelInternal(channel); + } + } + } catch (Exception e) { + plugin.getLogger().log(Level.SEVERE, "Cannot inject incomming channel " + channel, e); + } + } + }; + + beginInitProtocol = new ChannelInitializer() { + + @Override + protected void initChannel(Channel channel) { + channel.pipeline().addLast(endInitProtocol); + } + }; + + serverChannelHandler = new ChannelInboundHandlerAdapter() { + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) { + Channel channel = (Channel) msg; + + channel.pipeline().addFirst(beginInitProtocol); + ctx.fireChannelRead(msg); + } + }; + } + + private void registerBukkitEvents() { + listener = new Listener() { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerLogin(PlayerLoginEvent event) { + if (event.getResult() != Result.ALLOWED) + return; + + if (closed) return; + + try { + Channel channel = getChannel(event.getPlayer()); + + if (!uninjectedChannels.contains(channel)) { + injectPlayer(event.getPlayer()); + } + } catch (Exception ex) { + event.disallow(Result.KICK_OTHER, "§cNão foi possivel injetar pacotes em seu cliente!"); + } + } + + @EventHandler + public void onPluginDisable(PluginDisableEvent e) { + close(); + } + }; + + plugin.getServer().getPluginManager().registerEvents(listener, plugin); + } + + @SuppressWarnings("unchecked") + private void registerChannelHandler() { + Object mcServer = getMinecraftServer.get(Bukkit.getServer()); + Object serverConnection = getServerConnection.get(mcServer); + boolean looking = true; + + networkManagers = (List) getNetworkMarkers.invoke(null, serverConnection); + createServerChannelHandler(); + + for (int i = 0; looking; i++) { + List list = Reflection.getField(serverConnection.getClass(), List.class, i).get(serverConnection); + + for (Object item : list) { + if (!(item instanceof ChannelFuture)) + break; + + Channel serverChannel = ((ChannelFuture) item).channel(); + + serverChannels.add(serverChannel); + serverChannel.pipeline().addFirst(serverChannelHandler); + looking = false; + } + } + } + + private void unregisterChannelHandler() { + if (serverChannelHandler == null) + return; + + for (Channel serverChannel : serverChannels) { + final ChannelPipeline pipeline = serverChannel.pipeline(); + + serverChannel.eventLoop().execute(() -> { + try { + pipeline.remove(serverChannelHandler); + } catch (NoSuchElementException ignored) { + } + }); + } + } + + private void registerPlayers(Plugin plugin) { + for (Player player : Bukkit.getOnlinePlayers()) { + injectPlayer(player); + } + } + + public Object onPacketOutAsync(Player reciever, Channel channel, Object packet) { + return packet; + } + + public Object onPacketInAsync(Player sender, Channel channel, Object packet) { + return packet; + } + + public void sendPacket(Player player, Object packet) { + sendPacket(getChannel(player), packet); + } + + public void sendPacket(Channel channel, Object packet) { + channel.pipeline().writeAndFlush(packet); + } + + public void receivePacket(Player player, Object packet) { + receivePacket(getChannel(player), packet); + } + + public void receivePacket(Channel channel, Object packet) { + channel.pipeline().context("encoder").fireChannelRead(packet); + } + + protected String getHandlerName() { + return "common-" + plugin.getName() + "-" + ID.incrementAndGet(); + } + + public void injectPlayer(Player player) { + injectChannelInternal(getChannel(player)).player = player; + } + + public void injectChannel(Channel channel) { + injectChannelInternal(channel); + } + + private PacketInterceptor injectChannelInternal(Channel channel) { + try { + PacketInterceptor interceptor = (PacketInterceptor) channel.pipeline().get(handlerName); + + if (interceptor == null) { + interceptor = new PacketInterceptor(); + channel.pipeline().addBefore("packet_handler", handlerName, interceptor); + uninjectedChannels.remove(channel); + } + + return interceptor; + } catch (IllegalArgumentException e) { + return (PacketInterceptor) channel.pipeline().get(handlerName); + } + } + + public Channel getChannel(Player player) { + Channel channel = channelLookup.get(player.getName()); + + if (channel == null) { + Object connection = getConnection.get(getPlayerHandle.invoke(player)); + Object manager = getManager.get(connection); + + channelLookup.put(player.getName(), channel = getChannel.get(manager)); + } + + return channel; + } + + public void uninjectPlayer(Player player) { + uninjectChannel(getChannel(player)); + } + + public void uninjectChannel(final Channel channel) { + if (!closed) { + uninjectedChannels.add(channel); + } + + channel.eventLoop().execute(() -> channel.pipeline().remove(handlerName)); + } + + public boolean hasInjected(Player player) { + return hasInjected(getChannel(player)); + } + + public boolean hasInjected(Channel channel) { + return channel.pipeline().get(handlerName) != null; + } + + public final void close() { + if (!closed) { + closed = true; + + for (Player player : plugin.getServer().getOnlinePlayers()) { + uninjectPlayer(player); + } + + HandlerList.unregisterAll(listener); + unregisterChannelHandler(); + } + } + + private final class PacketInterceptor extends ChannelDuplexHandler { + + public volatile Player player; + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + final Channel channel = ctx.channel(); + + handleLoginStart(channel, msg); + + try { + msg = onPacketInAsync(player, channel, msg); + } catch (Exception e) { + plugin.getLogger().log(Level.SEVERE, "Error in onPacketInAsync().", e); + } + + if (msg != null) { + super.channelRead(ctx, msg); + } + } + + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + try { + msg = onPacketOutAsync(player, ctx.channel(), msg); + } catch (Exception e) { + plugin.getLogger().log(Level.SEVERE, "Error in onPacketOutAsync().", e); + } + + if (msg != null) { + super.write(ctx, msg, promise); + } + } + + private void handleLoginStart(Channel channel, Object packet) { + if (PACKET_LOGIN_IN_START.isInstance(packet)) { + GameProfile profile = getGameProfile.get(packet); + channelLookup.put(profile.getName(), channel); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.java new file mode 100644 index 0000000..2ebe18e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.java @@ -0,0 +1,29 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.custom.scheduler; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import org.bukkit.Bukkit; + +public class BukkitUpdateScheduler implements Runnable { + + private static Integer currentTick = 0; + + public static Integer getCurrentTick() { + return currentTick; + } + + @Override + public void run() { + currentTick++; + + Bukkit.getPluginManager().callEvent(new BukkitUpdateEvent(UpdateType.TICK, currentTick)); + + if (currentTick % 20 == 0) { + Bukkit.getPluginManager().callEvent(new BukkitUpdateEvent(UpdateType.SEGUNDO, currentTick)); + } + + if (currentTick % 1200 == 0) { + Bukkit.getPluginManager().callEvent(new BukkitUpdateEvent(UpdateType.MINUTO, currentTick)); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.java new file mode 100644 index 0000000..5903ff9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.java @@ -0,0 +1,60 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class AfkListener implements Listener { + + /* HashMap playerAfkHashList = new HashMap<>(); + ArrayList removePlayer = new ArrayList<>(); + + public void checkPlayerAfk() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(BukkitMain.getInstance(), () -> { + for (Map.Entry entry : playerAfkHashList.entrySet()) { + + if ((System.currentTimeMillis() - entry.getValue()) > 5 * 20) { + Player player = entry.getKey(); + removePlayer.add(player); + connectMessage(player, "afk"); + } + } + for (Player removePlayer : removePlayer) { + playerAfkHashList.remove(removePlayer); + } + }, 0, 20); + + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + playerAfkHashList.put(event.getPlayer(), System.currentTimeMillis()); + } + + public void findServer(Player p, ServerType serverType) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("FindServer"); + out.writeUTF(serverType.name()); + p.sendPluginMessage(BukkitMain.getInstance(), "BungeeCord", out.toByteArray()); + } + + public void connectMessage(Player p, String serverName) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Connect"); + out.writeUTF(serverName); + p.sendPluginMessage(BukkitMain.getInstance(), "BungeeCord", out.toByteArray()); + } +*/ + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.java new file mode 100644 index 0000000..1501a8c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.java @@ -0,0 +1,213 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.common.clan.Clan; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.Medals; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.help.HelpTopic; +import org.bukkit.metadata.FixedMetadataValue; + +public class ChatListener implements Listener { + + private final String CHAT_COOLDOWN_TAG = "chat-cooldown"; + private final String DELAY_COMMAND_TAG = "command-cooldown"; + private final Long CHAT_COOLDOWN_TIME = 2000L; + private final Long COMMAND_COOLDOWN_TIME = 1000L; + + private final String[] cmdsBlockeds = {"/?", "/bukkit:", "/say", "/kill", "/msg", "/me", "/w", "/help", + "minecraft:", "/calc", "//calc", "calc"}; + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + + BukkitPlayer profile = (BukkitPlayer) CommonsGeneral.getProfileManager().getGamingProfile(player.getUniqueId()); + + if (!BukkitSettings.CHAT_OPTION && (profile.getGroup().getLevel() < Groups.TRIAL.getLevel())) { + event.setCancelled(true); + player.sendMessage(BukkitMessages.CHAT_ESTA_DESATIVADO); + return; + } + + if (profile.getGroup().getLevel() < Groups.TRIAL.getLevel()) { // MOD + event.setCancelled(inChatCooldown(player)); + } + + if (event.isCancelled()) { + return; + } + + event.setCancelled(true); + + String message = event.getMessage(); + + if (message.contains("%")) { + message = message.replaceAll("%", "%%"); + } + + if (message.contains("&")) { + if (profile.getGroup().getLevel() > Groups.MEMBRO.getLevel()) { + message = message.replaceAll("&", "§"); + } + } + + String prefix = ""; + + Medals medal = Medals.getMedalById(profile.getInt(DataType.MEDAL)); + if (medal != null) prefix = medal.getColor() + medal.getSymbol() + " "; + + if (!profile.getString(DataType.CLAN).equalsIgnoreCase("Nenhum")) { + Clan clan = ClanManager.getClan(profile.getString(DataType.CLAN)); + prefix = prefix + "§7[" + (clan.isPremium() ? "§6" : "") + clan.getTag() + "] "; + } + + League league = League.getRanking(profile.getInt(DataType.XP)); + + if (profile.getActualTag().getLevel() != Groups.MEMBRO.getLevel()) { + prefix = prefix + profile.getActualTag().getColor() + "§l" + profile.getActualTag().getPrefix() + + profile.getActualTag().getColor() + " " + player.getName(); + } else { + prefix = prefix + "§7" + player.getName(); + } + if (BukkitMain.getServerType() == ServerType.LOBBY || BukkitMain.getServerType() == ServerType.LOBBY_PVP || BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES || BukkitMain.getServerType() == ServerType.LOBBY_DUELS) { + prefix = prefix + ""; + + String formattedMessage = prefix + "§7 » §f" + message; + + for (Player onlines : event.getRecipients()) { + onlines.sendMessage(formattedMessage); + } + } else { + prefix = "§7[" + league.getColor() + league.getSymbol() + "§7] " + prefix; + + String formattedMessage = prefix + "§7 » §f" + message; + + for (Player onlines : event.getRecipients()) { + onlines.sendMessage(formattedMessage); + } + } + } + + private boolean inChatCooldown(Player player) { + boolean cooldown = false; + + if (player.hasMetadata(CHAT_COOLDOWN_TAG)) { + if (player.getMetadata(CHAT_COOLDOWN_TAG).get(0).asLong() + CHAT_COOLDOWN_TIME > System + .currentTimeMillis()) { + player.sendMessage(BukkitMessages.CHAT_COOLDOWN); + cooldown = true; + } else { + player.setMetadata(CHAT_COOLDOWN_TAG, + new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis())); + } + } else { + player.setMetadata(CHAT_COOLDOWN_TAG, + new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis())); + } + + return cooldown; + } + + private boolean inCommandDelay(Player player) { + boolean cooldown = false; + + if (player.hasMetadata(DELAY_COMMAND_TAG)) { + if (player.getMetadata(DELAY_COMMAND_TAG).get(0).asLong() + COMMAND_COOLDOWN_TIME > System + .currentTimeMillis()) { + player.sendMessage(BukkitMessages.VOCE_ESTA_TENTANDO_EXECUTAR_COMANDOS_MUITO_RAPIDO); + cooldown = true; + } else { + player.setMetadata(DELAY_COMMAND_TAG, + new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis())); + } + } else { + player.setMetadata(DELAY_COMMAND_TAG, + new FixedMetadataValue(BukkitMain.getInstance(), System.currentTimeMillis())); + } + + return cooldown; + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + if (event.getPlayer().hasMetadata(CHAT_COOLDOWN_TAG)) { + event.getPlayer().removeMetadata(CHAT_COOLDOWN_TAG, BukkitMain.getInstance()); + } + + if (event.getPlayer().hasMetadata(DELAY_COMMAND_TAG)) { + event.getPlayer().removeMetadata(DELAY_COMMAND_TAG, BukkitMain.getInstance()); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + if (!event.isCancelled()) { + if (!event.getPlayer().isOp() && inCommandDelay(event.getPlayer())) { + event.setCancelled(true); + return; + } + + String cmd = event.getMessage().split(" ")[0]; + + HelpTopic topic = Bukkit.getServer().getHelpMap().getHelpTopic(cmd); + + if (topic == null) { + event.setCancelled(true); + event.getPlayer().sendMessage(BukkitMessages.COMANDO_INEXISTENTE); + } + } + } + + @EventHandler + public void onPlayerCommandPreprocess2(PlayerCommandPreprocessEvent event) { + final String message = event.getMessage().toLowerCase(); + + if (message.equals("stop")) { + event.setCancelled(true); + event.getPlayer().chat("/parar"); + return; + } + + if ((message.equals("/pl")) || (message.equals("/plugin")) || (message.startsWith("ver")) + || (message.startsWith("icanhasbukkit")) || (message.equals("/plugins")) + || (message.startsWith("/help")) || (message.startsWith("/bukkit:"))) { + event.setCancelled(true); + //event.getPlayer().chat("/criador"); + return; + } + + boolean block = false; + + for (String cmds : cmdsBlockeds) { + if (message.startsWith(cmds)) { + if ((cmds.equalsIgnoreCase("/w")) || (message.equalsIgnoreCase("/killmobs")) + || (message.equalsIgnoreCase("/whitelist")) || (message.contains("medal")) + || (message.contains("memory")) || (message.equalsIgnoreCase("/wand"))) + continue; + block = true; + break; + } + } + + if (block) { + event.setCancelled(true); + event.getPlayer().sendMessage(BukkitMessages.COMANDO_BLOQUEADO); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.java new file mode 100644 index 0000000..4c395dc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.java @@ -0,0 +1,395 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.fake.FakeAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeGroupEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerQueueEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerUpdateTabEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerLoadedEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStatusUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.PlayerBukkitQueue; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.QueueType; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditManager; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.google.gson.JsonElement; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.player.*; +import org.bukkit.inventory.EnchantingInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.material.Dye; + +import java.util.Map.Entry; + +@SuppressWarnings("deprecation") +public class CoreListener implements Listener { + + private static ItemStack lapis; + int MINUTES = 0; + + public static void init() { + ItemStack sopa = new ItemBuilder().material(Material.MUSHROOM_SOUP).build(); + ShapelessRecipe cocoa = new ShapelessRecipe(sopa); + ShapelessRecipe cactus = new ShapelessRecipe(sopa); + + cactus.addIngredient(Material.BOWL); + cactus.addIngredient(1, Material.CACTUS); + + cocoa.addIngredient(Material.BOWL); + cocoa.addIngredient(Material.INK_SACK, 3); + + Bukkit.addRecipe(cocoa); + Bukkit.addRecipe(cactus); + + Dye d = new Dye(); + d.setColor(DyeColor.BLUE); + lapis = d.toItemStack(); + lapis.setAmount(3); + } + + public static boolean handleSoup(Player player) { + boolean tomou = false; + + if (player.getHealth() < player.getMaxHealth()) { + double life = player.getHealth(); + player.setHealth(Math.min(life + 7D, 20.0D)); + tomou = true; + } else if (player.getFoodLevel() < 20) { + player.setFoodLevel(player.getFoodLevel() + 7); + tomou = true; + } + + if (tomou) { + player.setItemInHand(new ItemStack(Material.BOWL)); + player.updateInventory(); + } + + return tomou; + } + + @EventHandler + public void openInventoryEvent(InventoryOpenEvent e) { + if (e.getInventory() instanceof EnchantingInventory) { + e.getInventory().setItem(1, lapis); + } + } + + @EventHandler + public void onDeath(PlayerDeathEvent e) { + Bukkit.getScheduler().runTaskLater(BukkitMain.getInstance(), () -> { + e.getEntity().spigot().respawn(); + }, 6L); + } + + @EventHandler + public void closeInventoryEvent(InventoryCloseEvent e) { + if (e.getInventory() instanceof EnchantingInventory) { + e.getInventory().setItem(1, null); + } + } + + @EventHandler + public void inventoryClickEvent(InventoryClickEvent e) { + if (e.getClickedInventory() instanceof EnchantingInventory) { + if (e.getSlot() == 1) e.setCancelled(true); + } + } + + @EventHandler + public void enchantItemEvent(EnchantItemEvent event) { + event.getInventory().setItem(1, lapis); + } + + @EventHandler + public void onGroupChange(PlayerChangeGroupEvent event) { + Player player = event.getPlayer(); + Groups group = event.getGroup(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer.getString(DataType.FAKE).equalsIgnoreCase("")) { + bukkitPlayer.updateTag(player, bukkitPlayer.getGroup().getTag(), true); + } else { + TagManager.setTag(player, bukkitPlayer.getActualTag(), bukkitPlayer); + } + + //TitleAPI.sendTitle(player, 1, 2, 3, "§6§lGRUPO", + // "§fVocê recebeu o grupo " + group.getColor() + group.getName().toUpperCase()); + } + + @EventHandler + public void onJoin(final PlayerJoinEvent event) { + Player player = event.getPlayer(); + + VanishAPI.updateInvisibles(player); + + BukkitPlayer profile = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + String fake = profile.getString(DataType.FAKE); + Groups actualGroup = profile.getGroup(); + boolean save = false; + + if (!TagManager.hasPermission(player, actualGroup)) { + profile.set(DataType.GROUP, "Membro"); + actualGroup = Groups.MEMBRO; + save = true; + } + + if(actualGroup != Groups.MEMBRO) { + val tag = profile.getString(DataType.TAG); + if(tag != null) { + val group = Groups.getGroup(tag); + + if(group != null && TagManager.hasPermission(player, group)) actualGroup = group; + } + } + + profile.setActualTag(actualGroup.getTag()); + + boolean resetFake = false; + + if (!fake.equalsIgnoreCase("")) { + if (profile.getGroup().getLevel() > Groups.MEMBRO.getLevel()) { + if (Bukkit.getPlayer(fake) == null) { + FakeAPI.changePlayerName(player, fake, true); + + player.sendMessage(BukkitMessages.VOCE_ENTROU_NO_SERVIDOR_COM_O_FAKE); + } else { + resetFake = true; + } + } else { + resetFake = true; + } + } + + if (resetFake) { + profile.set(DataType.FAKE, ""); + + save = true; + } + + TagManager.setTag(player, actualGroup); + + if (save) { + BukkitMain.runAsync(() -> profile.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + } + + PlayerAPI.updateTab(player); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void injectPermissions(PlayerLoginEvent event) { + if (!CommonsGeneral.getProfileManager().containsProfile(event.getPlayer().getUniqueId())) { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, BukkitMessages.THE_SERVER_NOT_RECEIVED_PLAYER_DATA); + return; + } + + BukkitMain.getBukkitPlayer(event.getPlayer().getUniqueId()).injectPermissions(event.getPlayer()); + } + + @EventHandler + public void onLogin(PlayerLoginEvent event) { + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + return; + } + + Player player = event.getPlayer(); + + GamingProfile profile = CommonsGeneral.getProfileManager().getGamingProfile(player.getUniqueId()); + + /* + if (Bukkit.hasWhitelist()) { + boolean kick = true; + + if (profile.getGroup().getLevel() > Groups.PRIME.getLevel()) { + kick = false; + } else if (player.hasPermission(CommonsConst.PERMISSION_PREFIX + ".whitelist")) { + kick = false; + } + + if (kick) { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, BukkitMessages.THE_SERVER_WITH_WHITELIST); + } + }*/ + + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + CommonsGeneral.getProfileManager().removeGamingProfile(player.getUniqueId()); + return; + } + + if (profile.getGroup().getLevel() >= Groups.ADMIN.getLevel()) { + if (!player.isOp()) { + player.setOp(true); + } + } else { + if (player.isOp()) { + player.setOp(false); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + + if (player.isOp()) { + player.setOp(false); + } + + VanishAPI.remove(player); + WorldEditManager.checkAndRemove(player); + } + + @EventHandler + public void onLoad(ServerLoadedEvent event) { + BukkitMain.console("--------------------------------------------------"); + BukkitMain.console("Servidor carregado no tipo: " + BukkitMain.getServerType().getName()); + BukkitMain.console("Servidor com ID #" + BukkitMain.getServerID()); + BukkitMain.console("Servidor totalmente carregado e estabilizado."); + BukkitMain.console("---------------------------------------------------"); + + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(BukkitMain.getServerType(), BukkitMain.getServerID()) + .type(PacketType.BUKKIT_SEND_INFO).field("bukkit-server-turn-on")); + + BukkitMain.setLoaded(true); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onServerUpdate(ServerStatusUpdateEvent event) { + CPacketCustomAction PACKET = new CPacketCustomAction(BukkitMain.getServerType(), BukkitMain.getServerID()) + .type(PacketType.BUKKIT_SEND_SERVER_DATA); + + for (Entry entry : event.getJson().entrySet()) { + PACKET.getJson().add(entry.getKey(), entry.getValue()); + } + + Client.getInstance().getClientConnection().sendPacket(PACKET); + } + + @EventHandler + public void onPlayerQueue(PlayerQueueEvent event) { + Player player = event.getPlayer(); + + if (event.getQueueType() == QueueType.CONNECT) { + BukkitPlayer bukkitPlayer = (BukkitPlayer) CommonsGeneral.getProfileManager() + .getGamingProfile(player.getUniqueId()); + bukkitPlayer.getDataHandler() + .sendCategoryToBungeecord(bukkitPlayer.getDataHandler().getListDataCategorysLoadeds()); + + BukkitServerAPI.redirectPlayer(player, event.getResponse()); + } else if (event.getQueueType() == QueueType.KICK) { + BukkitMain.runSync(() -> player.kickPlayer("§cVocê foi expulso do servidor.")); + } else if (event.getQueueType() == QueueType.SAVE) { + BukkitMain.runAsync(() -> { + BukkitPlayer bukkitPlayer = (BukkitPlayer) CommonsGeneral.getProfileManager() + .getGamingProfile(player.getUniqueId()); + bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT); + }); + } else if (event.getQueueType() == QueueType.CHECK_TIME) { + BukkitPlayer bukkitPlayer = (BukkitPlayer) CommonsGeneral.getProfileManager().getGamingProfile(player.getUniqueId()); + bukkitPlayer.validateGroups(); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerUpdateTabEvent(PlayerUpdateTabEvent event) { + TitleAPI.setHeaderAndFooter(event.getPlayer(), event.getHeader(), event.getFooter()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDamage(EntityDamageEvent event) { + if (!BukkitSettings.DANO_OPTION) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDamageByEntityLow(EntityDamageByEntityEvent event) { + if (!BukkitSettings.PVP_OPTION) { + event.setCancelled(true); + } + } + + @EventHandler + public void onClick(PlayerInteractEntityEvent event) { + if ((event.getPlayer() != null) && (event.getRightClicked() instanceof Player)) { + + Player player = event.getPlayer(), clicked = (Player) event.getRightClicked(); + + if ((player.getItemInHand().getType().equals(Material.AIR)) && (VanishAPI.inAdmin(player))) { + player.performCommand("invsee " + clicked.getName()); + } + } + } + + @EventHandler + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != BukkitUpdateEvent.UpdateType.MINUTO) return; + + MINUTES++; + + if (MINUTES % 2 == 0) { + PlayerBukkitQueue queue = new PlayerBukkitQueue(30, true, QueueType.CHECK_TIME); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + queue.addToQueue(onlines); + } + + queue.start(); + } + } + + @EventHandler + public void worldEditListener(PlayerInteractEvent event) { + if (event.getAction() == Action.PHYSICAL) { + return; + } + if (event.getClickedBlock() != null) { + Player player = event.getPlayer(); + if (player.getItemInHand() != null && player.getItemInHand().getType() == Material.WOOD_AXE) { + if (player.getItemInHand().hasItemMeta()) { + if (player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§e§lWORLDEDIT")) { + if (event.getAction().name().contains("LEFT")) { + event.setCancelled(true); + WorldEditManager.setPos1(player, event.getClickedBlock().getLocation()); + } else { + WorldEditManager.setPos2(player, event.getClickedBlock().getLocation()); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.java new file mode 100644 index 0000000..e231b97 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.java @@ -0,0 +1,72 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.HashMap; + +public class DamageListener implements Listener { + + public static final HashMap damageMaterial = new HashMap<>(); + public static boolean CRITICAL = true; + public static int CHANCE_DE_CRITICAL = 30; + + @EventHandler(priority = EventPriority.LOWEST) + public void onDamageByEntity(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player)) return; + + Player damager = (Player) event.getDamager(); + + double dano = 1.0; + ItemStack itemStack = damager.getItemInHand(); + + if (itemStack != null) { + dano = damageMaterial.get(itemStack.getType()); + + if (itemStack.containsEnchantment(Enchantment.DAMAGE_ALL)) { + dano += itemStack.getEnchantmentLevel(Enchantment.DAMAGE_ALL); + } + } + + for (PotionEffect effect : damager.getActivePotionEffects()) { + if (effect.getType().equals(PotionEffectType.INCREASE_DAMAGE)) { + dano += ((effect.getAmplifier() + 1) * 2); + } else if (effect.getType().equals(PotionEffectType.WEAKNESS)) { + dano -= (effect.getAmplifier() + 1); + } + } + + if (CRITICAL) { + if (isCritical(damager)) { + dano += 1.0D; + } + } + + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + + for (PotionEffect effect : player.getActivePotionEffects()) { + if (effect.getType().equals(PotionEffectType.WEAKNESS)) { + dano += (effect.getAmplifier() + 1); + } + } + } + + event.setDamage(dano); + } + + @SuppressWarnings("deprecation") + private boolean isCritical(final Player p) { + return (p.getFallDistance() > 0.0F) && (!p.isOnGround()) && + (CommonsConst.RANDOM.nextInt(100) <= CHANCE_DE_CRITICAL) && (!p.hasPotionEffect(PotionEffectType.BLINDNESS)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.java new file mode 100644 index 0000000..ac159e9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.java @@ -0,0 +1,107 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.token.AcessToken; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.UUID; + +public class LoginListener implements Listener { + + public final static HashMap connectionQueue = new HashMap<>(); + + @EventHandler(priority = EventPriority.LOWEST) + public void onLoad(AsyncPlayerPreLoginEvent event) { + if (!isRunning()) { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, BukkitMessages.THE_SERVER_IS_LOADING); + return; + } + + UUID uniqueId = event.getUniqueId(); + + if (Bukkit.getPlayer(uniqueId) == null) { + GamingProfile profile; + + connectionQueue.put(uniqueId, profile = new BukkitPlayer(event.getName(), "", uniqueId)); + + profile.setTokenListener(accessToken -> { + profile.setAcessToken(accessToken); + + synchronized (profile) { + profile.notifyAll(); + } + }); + + profile.sendPacket(new CPacketCustomAction(event.getName(), uniqueId). + type(PacketType.BUKKIT_REQUEST_ACCOUNT_TO_BUNGEECORD)); + + synchronized (profile) { + try { + profile.wait(6000); + } catch (InterruptedException e) { + connectionQueue.remove(uniqueId); + + event.setKickMessage("§cFalha no login: " + e); + event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); + + e.printStackTrace(); + } + } + + if (profile.getAcessToken() != null) { + if (profile.getAcessToken() == AcessToken.REJECTED) { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "§cSeu acesso foi invalidado pelo servidor."); + } else { + CommonsGeneral.getProfileManager().addGamingProfile(uniqueId, profile); + } + } else { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, + String.format(BukkitMessages.THE_SERVER_NOT_RECEIVED_PLAYER_DATA, BukkitMain.getServerType().getName())); + } + + connectionQueue.remove(uniqueId); + } else { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "§cVocê já está conectado ao servidor."); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onRemoveAccount(AsyncPlayerPreLoginEvent event) { + if (event.getLoginResult() == AsyncPlayerPreLoginEvent.Result.KICK_OTHER) { + return; + } + + if (!CommonsGeneral.getProfileManager().containsProfile(event.getUniqueId())) { + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, + String.format(BukkitMessages.THE_SERVER_NOT_RECEIVED_PLAYER_DATA, BukkitMain.getServerType().getName())); + + CommonsGeneral.getProfileManager().removeGamingProfile(event.getUniqueId()); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onLeave(PlayerQuitEvent event) { + CommonsGeneral.getProfileManager().removeGamingProfile(event.getPlayer().getUniqueId()); + } + + private boolean isRunning() { + if (!BukkitMain.isLoaded()) return false; + if (!BukkitSettings.LOGIN_OPTION) return false; + + return Client.getInstance().getClientConnection().isConnected(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.java new file mode 100644 index 0000000..7da0267 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.java @@ -0,0 +1,75 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeTagEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag.TagManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +public class ScoreboardListener implements Listener { + + @EventHandler(priority = EventPriority.LOWEST) + public void onJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); + + event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); + + SidebarManager.handleJoin(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + + Scoreboard board = event.getPlayer().getScoreboard(); + + if (board != null) { + for (Team t : board.getTeams()) t.unregister(); + for (Objective ob : board.getObjectives()) ob.unregister(); + } + + SidebarManager.handleQuit(event.getPlayer().getUniqueId()); + + event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + + TagManager.removePlayerTag(event.getPlayer().getName()); + } + + @EventHandler + public void onPlayerChangeTagCancelEvent(PlayerChangeTagEvent event) { + if (!TagManager.USE_TAGS) { + event.setCancelled(true); + return; + } + + Player player = event.getPlayer(); + + if (event.isCancelled()) { + player.sendMessage(BukkitMessages.VOCE_NAO_PODE_TROCAR_A_TAG); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerChangeTag(PlayerChangeTagEvent event) { + Player player = event.getPlayer(); + + if (player == null) return; + + if (!event.isForced()) { + player.sendMessage(BukkitMessages.TAG_SELECIONADA. + replace("%tag%", event.getNewTag().getColor() + event.getNewTag().getName())); + } + + TagManager.setTag(player, event.getNewTag()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.java new file mode 100644 index 0000000..04e199a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; + +public class WorldDListener implements PluginMessageListener { + + @Override + public void onPluginMessageReceived(String channel, Player p, byte[] msg) { + + if (channel.equals("WDL|INIT")) { + + p.kickPlayer( + "§cSaudações!\n\n§cDetectamos o uso indevido de\n§cWorldDownloader via canal alternativo.\n§cPedimos que, para iniciar sua jogatina\n§cretire o client atual para isso.\n\n§cAtenciosamente, Equipe LeagueMC."); + + } + + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.java new file mode 100644 index 0000000..99f0806 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.java @@ -0,0 +1,70 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.manager; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramInjector; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramListeners; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.listener.NPCListener; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.packets.NPCPacketInjector; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.injector.packets.ServerPacketInjector; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.BukkitConfigurationManager; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +@Getter +public class BukkitManager { + + private final BukkitConfigurationManager configurationManager; + + private boolean NPC_EVENTS = false, + PACKET_INJECTOR = false, + HOLOGRAM_EVENTS = false; + + public BukkitManager() { + this.configurationManager = new BukkitConfigurationManager(); + } + + public void disable() { + if (NPC_EVENTS) { + + } + + if (HOLOGRAM_EVENTS) { + HologramAPI.getHolograms().forEach(holograms -> HologramAPI.removeHologram(holograms)); + } + } + + public void enablePacketInjector(Plugin plugin) { + if (PACKET_INJECTOR) return; + + PACKET_INJECTOR = true; + + ServerPacketInjector.inject(plugin); + + BukkitMain.console("§a[BukkitManager] ServerPacketInjector has been enabled!"); + } + + public void enableNPC(Plugin plugin) { + if (!NPC_EVENTS) { + NPC_EVENTS = true; + NPCPacketInjector.inject(plugin); + NPCManager.register(); + + Bukkit.getServer().getPluginManager().registerEvents(new NPCListener(), plugin); + } + } + + public void enableHologram(Plugin plugin) { + if (HOLOGRAM_EVENTS) return; + + HOLOGRAM_EVENTS = true; + + HologramAPI.packetsEnabled = true; + HologramListeners.registerListeners(); + HologramInjector.inject(plugin); + + BukkitMain.console("§a[BukkitManager] HologramAPI has been enabled!"); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.java new file mode 100644 index 0000000..dc8ef7d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.java @@ -0,0 +1,167 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.listeners.DamageListener; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl.BukkitConfiguration; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import lombok.Getter; +import org.bukkit.Material; + +import java.util.Arrays; +import java.util.Collections; + +@Getter +public class BukkitConfigurationManager { + + private final BukkitConfiguration permissionsConfiguration; + private final BukkitConfiguration globalConfiguration; + private final BukkitConfiguration damageConfiguration; + + public BukkitConfigurationManager() { + this.permissionsConfiguration = new BukkitConfiguration("bukkit-permissions", true); + this.globalConfiguration = new BukkitConfiguration("global-config", true); + this.damageConfiguration = new BukkitConfiguration("damages", true); + } + + public void init() { + getPermissionsConfiguration().load(); + getGlobalConfiguration().load(); + getDamageConfiguration().load(); + } + + public void refreshConfig(String configName) { + boolean hasUpdate = false; + + if (configName.equalsIgnoreCase("bukkit-permissions")) { + for (Groups groups : Groups.values()) { + if (groups != Groups.DEVELOPER) { + + if (!permissionsConfiguration.getConfiguration().contains("permissions." + groups.getName().toLowerCase())) { + + permissionsConfiguration.getConfiguration().set("permissions." + groups.getName().toLowerCase(), + (groups == Groups.MEMBRO ? Collections.singletonList("tag.membro") : Arrays.asList("tag.membro", "tag." + groups.getName().toLowerCase()))); + + hasUpdate = true; + } else { + groups.setPermissions(permissionsConfiguration.getConfiguration().getStringList( + "permissions." + groups.getName().toLowerCase())); + } + } + } + + + if (hasUpdate) { + getPermissionsConfiguration().save(); + } + + getPermissionsConfiguration().unload(); + + Groups.DEVELOPER.setPermissions(Groups.ADMIN.getPermissions()); + } else if (configName.equalsIgnoreCase("global-config")) { + for (ValuesGlobalConfig values : ValuesGlobalConfig.values()) { + if (!getGlobalConfiguration().getConfiguration().contains(values.getKey())) { + getGlobalConfiguration().getConfiguration().set(values.getKey(), + StringUtility.convertValue(values.getValue(), values.getClassExpected())); + hasUpdate = true; + } + } + + if (hasUpdate) { + getGlobalConfiguration().save(); + } + } else if (configName.equalsIgnoreCase("damages")) { + for (ValuesDano values : ValuesDano.values()) { + if (!getDamageConfiguration().getConfiguration().contains(values.getKey())) { + getDamageConfiguration().getConfiguration().set(values.getKey(), StringUtility. + convertValue(values.getValue(), values.getClassExpected())); + hasUpdate = true; + } + } + + for (Material materiais : Material.values()) { + String name = materiais.name().toLowerCase(); + if ((name.contains("sword")) || (name.contains("pickaxe")) || (name.contains("spade")) || (name.contains("axe"))) { + if (!getDamageConfiguration().getConfiguration().contains("dano.materiais." + name)) { + hasUpdate = true; + getDamageConfiguration().getConfiguration().set("dano.materiais." + name, 1.0D); + } + } + } + + if (hasUpdate) { + getDamageConfiguration().save(); + } + } + + + apply(configName); + } + + private void apply(String configName) { + if (configName.equalsIgnoreCase("global-config")) { + CommonsGeneral.getMySQL().setHost(getStringByGlobalConfig("MySQL.Host")); + CommonsGeneral.getMySQL().setDatabase(getStringByGlobalConfig("MySQL.Database")); + CommonsGeneral.getMySQL().setUsuario(getStringByGlobalConfig("MySQL.Usuario")); + CommonsGeneral.getMySQL().setSenha(getStringByGlobalConfig("MySQL.Senha")); + CommonsGeneral.getMySQL().setPorta(getStringByGlobalConfig("MySQL.Porta")); + } else if (configName.equalsIgnoreCase("damages")) { + DamageListener.CRITICAL = getDamageConfiguration().getConfiguration().getBoolean("dano.critical"); + DamageListener.CHANCE_DE_CRITICAL = getDamageConfiguration().getConfiguration().getInt("dano.critical_chance"); + + for (Material materiais : Material.values()) { + String name = materiais.name().toLowerCase(); + if ((!name.contains("sword")) && (!name.contains("pickaxe")) && (!name.contains("spade")) && (!name.contains("axe"))) { + DamageListener.damageMaterial.put(materiais, 1.0D); + continue; + } + DamageListener.damageMaterial.put(materiais, getDamageConfiguration().getConfiguration().getDouble("dano.materiais." + name)); + } + } + } + + private String getStringByGlobalConfig(String type) { + return getGlobalConfiguration().getConfiguration().getString(type); + } + + public enum ValuesGlobalConfig { + + MYSQL_HOST("MySQL.Host", "localhost", "String"), + MYSQL_PORTA("MySQL.Porta", "3306", "String"), + MYSQL_DATABASE("MySQL.Database", "database", "String"), + MYSQL_USUARIO("MySQL.Usuario", "root", "String"), + MYSQL_SENHA("MySQL.Senha", "senha", "String"); + + @Getter + private final String key; + @Getter + private final String value; + @Getter + private final String classExpected; + + ValuesGlobalConfig(String key, String value, String classExpected) { + this.key = key; + this.value = value; + this.classExpected = classExpected; + } + } + + public enum ValuesDano { + + CRITICAL("dano.critical", "true", "Boolean"), + CRITICAL_CHANCE("dano.critical_chance", "35", "Integer"); + + @Getter + private final String key; + @Getter + private final String value; + @Getter + private final String classExpected; + + ValuesDano(String key, String value, String classExpected) { + this.key = key; + this.value = value; + this.classExpected = classExpected; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.java new file mode 100644 index 0000000..83acae4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.java @@ -0,0 +1,74 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.HashMap; + +public class PluginConfiguration { + + public static final HashMap CACHE_LOCATIONS = new HashMap<>(); + + public static Location setLocation(Plugin instance, String nome, Player player) { + instance.getConfig().set("locs." + nome + ".world", player.getLocation().getWorld().getName()); + instance.getConfig().set("locs." + nome + ".x", player.getLocation().getBlockX() + 0.5); + instance.getConfig().set("locs." + nome + ".y", Double.valueOf(player.getLocation().getY())); + instance.getConfig().set("locs." + nome + ".z", player.getLocation().getBlockZ() + 0.5); + instance.getConfig().set("locs." + nome + ".yaw", Float.valueOf(player.getLocation().getYaw())); + instance.getConfig().set("locs." + nome + ".pitch", Float.valueOf(player.getLocation().getPitch())); + instance.saveConfig(); + + CACHE_LOCATIONS.remove(nome); + + return getLocation(instance, nome); + } + + public static Location getLocation(Plugin instance, String nome) { + if (CACHE_LOCATIONS.containsKey(nome)) { + return CACHE_LOCATIONS.get(nome); + } + + if (!instance.getConfig().contains("locs." + nome + ".world")) { + BukkitMain.console("Local inválido."); + return null; + } + + double x = instance.getConfig().getDouble("locs." + nome + ".x"), + y = instance.getConfig().getDouble("locs." + nome + ".y"), + z = instance.getConfig().getDouble("locs." + nome + ".z"); + + Location loc = new Location(Bukkit.getWorld(instance.getConfig().getString("locs." + nome + ".world")), x, y, z, + (float) instance.getConfig().getLong("locs." + nome + ".yaw"), + (float) instance.getConfig().getLong("locs." + nome + ".pitch")); + CACHE_LOCATIONS.put(nome, loc); + + return loc; + } + + public static Location createLocation(Plugin instance, String nome) { + return createLocation(instance, nome, "world"); + } + + public static void createLocations(Plugin instance, String... nomes) { + for (String name : nomes) { + createLocation(instance, name, "world"); + } + } + + public static Location createLocation(Plugin instance, String nome, String world) { + if (!instance.getConfig().contains("locs." + nome + ".world")) { + instance.getConfig().set("locs." + nome + ".world", world); + instance.getConfig().set("locs." + nome + ".x", 0.5); + instance.getConfig().set("locs." + nome + ".y", 80.5); + instance.getConfig().set("locs." + nome + ".z", 0.5); + instance.getConfig().set("locs." + nome + ".yaw", 0); + instance.getConfig().set("locs." + nome + ".pitch", 0); + instance.saveConfig(); + } + + return getLocation(instance, nome); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.java new file mode 100644 index 0000000..673723d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.java @@ -0,0 +1,93 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.common.utility.system.Machine; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.io.IOException; + +@Getter +@Setter +public class BukkitConfiguration { + + private String configName; + private File file, dir; + private FileConfiguration configuration; + + public BukkitConfiguration(final String configName, File dir, final boolean createDefaultDir) { + this.configName = configName; + + if (createDefaultDir) { + createDir(); + } + + if (dir != null) { + this.dir = dir; + } + } + + public BukkitConfiguration(final String configName, final boolean createDefaultDir) { + this(configName, null, createDefaultDir); + } + + public void load() { + if (file != null) { + console("§c" + this.configName + " has already loaded!"); + return; + } + + this.file = dir == null ? new File(Machine.getDiretorio(), configName + ".yml") : + new File(dir, configName + ".yml"); + + if (!this.file.exists()) { + try { + this.file.createNewFile(); + } catch (IOException ex) { + ex.printStackTrace(); + console("§cAn error ocurred on create Configuration ''" + this.configName + "' > " + ex.getLocalizedMessage()); + } + } + + this.configuration = Utf8YamlConfiguration.loadConfiguration(file); + + BukkitMain.getManager().getConfigurationManager().refreshConfig(configName); + } + + public void save() { + if (file == null) { + console("§c" + this.configName + " has not loaded!"); + return; + } + + try { + configuration.save(file); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + private void createDir() { + File dir = new File(Machine.getDiretorio()); + + if (!dir.exists()) { + dir.mkdir(); + } + + dir = null; + } + + public void unload() { + if (this.file != null) { + + this.file = null; + this.configuration = null; + } + } + + private void console(final String message) { + BukkitMain.console("[BukkitConfiguration] " + message); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.java new file mode 100644 index 0000000..be72ef0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.java @@ -0,0 +1,38 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.*; + +public class Utf8YamlConfiguration extends YamlConfiguration { + + @Override @SuppressWarnings("UnstableApiUsage") + public void save(File file) throws IOException { + Validate.notNull(file, "File cannot be null"); + Files.createParentDirs(file); + String data = this.saveToString(); + Writer writer = new OutputStreamWriter(java.nio.file.Files.newOutputStream(file.toPath()), Charsets.UTF_8); + try { + writer.write(data); + } finally { + writer.close(); + } + } + + @Override + public void load(File file) throws IOException, InvalidConfigurationException { + Validate.notNull(file, "File cannot be null"); + this.load(new InputStreamReader(java.nio.file.Files.newInputStream(file.toPath()), Charsets.UTF_8)); + } + + @Override + @Deprecated + public void load(InputStream stream) throws IOException, InvalidConfigurationException { + Validate.notNull(stream, "Stream cannot be null"); + this.load(new InputStreamReader(stream, Charsets.UTF_8)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.java new file mode 100644 index 0000000..d48506c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.java @@ -0,0 +1,114 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.menu; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; + +public class AccountInventory extends MenuInventory { + + public AccountInventory(String nick) { + this(nick, nick); + } + + public AccountInventory(final String nickViewer, final String nickAlvo) { + super(nickAlvo.equalsIgnoreCase(nickViewer) ? "Seu perfil" : "Perfil do jogador " + nickAlvo, 5); + + Player target = BukkitServerAPI.getExactPlayerByNick(nickAlvo); + + GamingProfile profile = getProfile(target, nickAlvo); + if (profile == null) + return; + + Groups playerGroup = profile.getGroup(); + League playerLeague = League.getRanking(profile.getInt(DataType.XP)); + + ItemBuilder itemBuilder = new ItemBuilder(); + + String firstLogin = "Nunca", lastLogin = "Nunca"; + + if (profile.getLong(DataType.FIRST_LOGGED_IN) != 0) { + firstLogin = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss") + .format(profile.getLong(DataType.FIRST_LOGGED_IN)); + } + + if (profile.getLong(DataType.LAST_LOGGED_IN) != 0) { + lastLogin = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss") + .format(profile.getLong(DataType.LAST_LOGGED_IN)); + } + + + setItem(13, itemBuilder.type(Material.SKULL_ITEM).skin(nickAlvo).name("§a" + nickAlvo).lore( + "§7Rank: " + playerGroup.getTag().getColor() + playerGroup.getTag().getName(), + "§7Primeiro Login: " + firstLogin, + "§7Último Login: " + lastLogin).build()); + + setItem(30, new MenuItem(itemBuilder.type(Material.PAPER).name("§aSuas estatísticas").lore("§7Veja suas estatísticas.").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + new PlayerStatisticsInventory(nickViewer, nickAlvo, profile).open(player); + } + })); + + setItem(31, new MenuItem(itemBuilder.type(Material.ITEM_FRAME).name("§aBiblioteca de skins").lore("§7Escolha uma nova skin, e altere a velha.").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + new LibraryInventory(nickViewer, nickAlvo).open(player); + } + })); + + setItem(32, new MenuItem(itemBuilder.type(Material.NAME_TAG).name("§aSuas medalhas").lore("§7Veja suas medalhas.").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + player.chat("/medals"); + } + })); + } + + private GamingProfile getProfile(Player target, final String nickAlvo) { + GamingProfile profile; + + if (target != null) { + profile = BukkitMain.getBukkitPlayer(target.getUniqueId()); + } else { + profile = new BukkitPlayer(nickAlvo, "", CommonsGeneral.getUUIDFetcher().getOfflineUUID(nickAlvo)); + } + + if (!profile.getDataHandler().isCategoryLoaded(DataCategory.ACCOUNT)) { + try { + profile.getDataHandler().load(DataCategory.ACCOUNT); + } catch (SQLException e) { + e.printStackTrace(); + profile = null; + } + } + + return profile; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.java new file mode 100644 index 0000000..1775d20 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.java @@ -0,0 +1,113 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.menu; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.sql.SQLException; + +public class DuelsInfoInventory extends MenuInventory { + + public DuelsInfoInventory(final String nickViewer, final String nickAlvo, GamingProfile profile) { + super(nickAlvo.equalsIgnoreCase(nickViewer) ? "Suas estatísticas (Duels)" : "Estatísticas de " + nickAlvo + " (Duels)", 3); + Player target = BukkitServerAPI.getExactPlayerByNick(nickAlvo); + GamingProfile profile2 = getProfile(target, nickAlvo); + if (profile2 == null) + return; + final DataCategory[] CATEGORYS_TO_LOAD = {DataCategory.HARDCORE_GAMES, DataCategory.KITPVP, DataCategory.GLADIATOR}; + + for (DataCategory data : CATEGORYS_TO_LOAD) { + if(profile == null) break; + + try { + profile.getDataHandler().load(data); + } catch (SQLException e) { + e.printStackTrace(); + profile = null; + } + } + + if (profile == null) return; + + ItemBuilder itemBuilder = new ItemBuilder(); + + setItem(10, itemBuilder.type(Material.IRON_FENCE).name("§aGladiator").lore( + "§7Solo Wins: §a" + profile.getIntFormatted(DataType.GLADIATOR_WINS), + "§7Solo Losses: §a" + profile.getIntFormatted(DataType.GLADIATOR_LOSES), + "§7Solo Winstreak: §a" + profile.getIntFormatted(DataType.GLADIATOR_WINSTREAK), + "§7Solo Maior Winstreak: §a" + profile.getIntFormatted(DataType.GLADIATOR_MAXWINSTREAK), + "", + "§7Duplas Wins: §a0", + "§7Duplas Losses: §a0", + "§7Duplas Winstreak: §a0", + "§7Duplas Maior Winstreak: §a0").build()); + + setItem(12, itemBuilder.type(Material.MUSHROOM_SOUP).name("§aSopa").lore( + "§7Solo Wins: §a0", + "§7Solo Losses: §a0", + "§7Solo Winstreak: §a0", + "§7Solo Maior Winstreak: §a0", + "", + "§7Duplas Wins: §a0", + "§7Duplas Losses: §a0", + "§7Duplas Winstreak: §a0", + "§7Duplas Maior Winstreak: §a0").build()); + + setItem(11, itemBuilder.type(Material.WEB).name("§aSimulator").lore( + "§7Solo Wins: §a0", + "§7Solo Losses: §a0", + "§7Solo Winstreak: §a0", + "§7Solo Maior Winstreak: §a0", + "", + "§7Duplas Wins: §a0", + "§7Duplas Losses: §a0", + "§7Duplas Winstreak: §a0", + "§7Duplas Maior Winstreak: §a0").build()); + + setItem(22, itemBuilder.type(Material.ARROW).name("§eRetornar").lore( + "§7a Suas estatísticas").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + new PlayerStatisticsInventory(nickViewer, nickAlvo, profile2).open(player); + } + }); + + } + + private GamingProfile getProfile(Player target, final String nickAlvo) { + GamingProfile profile2; + + if (target != null) { + profile2 = BukkitMain.getBukkitPlayer(target.getUniqueId()); + } else { + profile2 = new BukkitPlayer(nickAlvo, "", CommonsGeneral.getUUIDFetcher().getOfflineUUID(nickAlvo)); + } + + if (!profile2.getDataHandler().isCategoryLoaded(DataCategory.ACCOUNT)) { + try { + profile2.getDataHandler().load(DataCategory.ACCOUNT); + } catch (SQLException e) { + e.printStackTrace(); + profile2 = null; + } + } + + return profile2; + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.java new file mode 100644 index 0000000..a087af3 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.java @@ -0,0 +1,121 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.menu; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.sql.SQLException; + +public class LibraryInventory extends MenuInventory { + + public LibraryInventory(final String nickViewer, String nickAlvo) { + super("Biblioteca de Skins", 5); + + Player target = BukkitServerAPI.getExactPlayerByNick(nickAlvo); + GamingProfile profile = getProfile(target, nickAlvo); + if (profile == null) + return; + + Groups playerGroup = profile.getGroup(); + League playerLeague = League.getRanking(profile.getInt(DataType.XP)); + + ItemBuilder itemBuilder = new ItemBuilder(); + + setItem(10, itemBuilder.type(Material.SKULL_ITEM).durability(3) + .skinURL("http://textures.minecraft.net/texture/a7af2b86c73a493e1ef2eac449de5c080e01586d34c682c78a5638dbf76ed9d1") + .name("§aBiel") + .lore("§eClique para selecionar") + .build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + player.closeInventory(); + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_SKIN).field("biel")); + } + }); + + setItem(11, itemBuilder.type(Material.SKULL_ITEM).durability(3) + .skinURL("http://textures.minecraft.net/texture/548a43d56f2940a43ebdacf142d5c90a005685f930247420646280c4af60e03e") + .name("§aTh") + .lore("§eClique para selecionar") + .build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + player.closeInventory(); + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_SKIN).field("zFlint")); + } + }); + + setItem(12, itemBuilder.type(Material.SKULL_ITEM).durability(3) + .skinURL("http://textures.minecraft.net/texture/7ebbe3ad08ac92f1bfafa132e1be48f5ad41a67aac16bba325669190d2f21523") + .name("§atheoow") + .lore("§eClique para selecionar") + .build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + player.closeInventory(); + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick()) + .type(PacketType.BUNGEE_SET_SKIN).field("theoow")); + } + }); + + GamingProfile finalProfile = profile; + + setItem(26, itemBuilder.type(Material.ARROW).name("§eRetornar").lore( + "§7a Meu perfil").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + new AccountInventory(nickViewer).open(player); + } + }); + + } + + private GamingProfile getProfile(Player target, final String nickAlvo) { + GamingProfile profile2; + + if (target != null) { + profile2 = BukkitMain.getBukkitPlayer(target.getUniqueId()); + } else { + profile2 = new BukkitPlayer(nickAlvo, "", CommonsGeneral.getUUIDFetcher().getOfflineUUID(nickAlvo)); + } + + if (!profile2.getDataHandler().isCategoryLoaded(DataCategory.ACCOUNT)) { + try { + profile2.getDataHandler().load(DataCategory.ACCOUNT); + } catch (SQLException e) { + e.printStackTrace(); + profile2 = null; + } + } + + return profile2; + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.java new file mode 100644 index 0000000..5f8be86 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.java @@ -0,0 +1,113 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.menu; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.sql.SQLException; + +public class PlayerStatisticsInventory extends MenuInventory { + + public PlayerStatisticsInventory(final String nickViewer, final String nickAlvo, GamingProfile profile) { + super(nickAlvo.equalsIgnoreCase(nickViewer) ? "Suas estatísticas" : "Estatísticas de " + nickAlvo, 3); + + final DataCategory[] CATEGORYS_TO_LOAD = {DataCategory.HARDCORE_GAMES, DataCategory.KITPVP, DataCategory.GLADIATOR}; + Player target = BukkitServerAPI.getExactPlayerByNick(nickAlvo); + GamingProfile profile2 = getProfile(target, nickAlvo); + if (profile2 == null) + return; + for (DataCategory data : CATEGORYS_TO_LOAD) { + if(profile == null) break; + + try { + profile.getDataHandler().load(data); + } catch (SQLException e) { + e.printStackTrace(); + profile = null; + } + } + + if (profile == null) return; + + ItemBuilder itemBuilder = new ItemBuilder(); + + setItem(11, itemBuilder.type(Material.IRON_CHESTPLATE).name("§aEstatísticas do PvP").lore( + "§7Arena Kills: §a" + profile.getIntFormatted(DataType.PVP_KILLS), + "§7Arena Deaths: §a" + profile.getIntFormatted(DataType.PVP_DEATHS), + "§7Arena Maior Killstreak: §a" + profile.getIntFormatted(DataType.PVP_MAXKILLSTREAK), + "", + "§7Fps Kills: §a" + profile.getIntFormatted(DataType.FPS_KILLS), + "§7Fps Deaths: §a" + profile.getIntFormatted(DataType.FPS_DEATHS), + "§7Fps Maior Killstreak: §a" + profile.getIntFormatted(DataType.FPS_MAXKILLSTREAK), + "", + "§7Coins: §6" + profile.getIntFormatted(DataType.COINS)).build()); + + setItem(10, itemBuilder.type(Material.MUSHROOM_SOUP).name("§aEstatísticas do HG").lore( + "§7HG Wins: §a" + profile.getIntFormatted(DataType.HG_WINS), + "§7HG Kills: §a" + profile.getIntFormatted(DataType.HG_KILLS), + "§7HG Deaths: §a" + profile.getIntFormatted(DataType.HG_DEATHS), + "", + "§7Champions Wins: §a" + profile.getIntFormatted(DataType.HG_EVENT_WINS), + "§7Champions Kills: §a" + profile.getIntFormatted(DataType.HG_EVENT_KILLS), + "§7Champions Deaths: §a" + profile.getIntFormatted(DataType.HG_EVENT_DEATHS), + "", + "§7Coins: §6" + profile.getIntFormatted(DataType.COINS)).build()); + + setItem(12, itemBuilder.type(Material.DIAMOND_SWORD).name("§aEstatísticas do Duels").lore( + "§eClique para ver mais!").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + new DuelsInfoInventory(nickViewer, nickAlvo, profile2).open(player); + } + }); + + setItem(22, itemBuilder.type(Material.ARROW).name("§eRetornar").lore( + "§7a Suas estatísticas").build(), new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inventory, ClickType type, ItemStack itemStack, int slot) { + player.closeInventory(); + + new AccountInventory(nickViewer, nickAlvo).open(player); + } + }); + + } + + private GamingProfile getProfile(Player target, final String nickAlvo) { + GamingProfile profile2; + + if (target != null) { + profile2 = BukkitMain.getBukkitPlayer(target.getUniqueId()); + } else { + profile2 = new BukkitPlayer(nickAlvo, "", CommonsGeneral.getUUIDFetcher().getOfflineUUID(nickAlvo)); + } + + if (!profile2.getDataHandler().isCategoryLoaded(DataCategory.ACCOUNT)) { + try { + profile2.getDataHandler().load(DataCategory.ACCOUNT); + } catch (SQLException e) { + e.printStackTrace(); + profile2 = null; + } + } + + return profile2; + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.java new file mode 100644 index 0000000..36cdf67 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.java @@ -0,0 +1,238 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.networking; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.fake.FakeAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeGroupEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.listeners.LoginListener; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.token.AcessToken; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import com.br.guilhermematthew.nowly.commons.custompackets.CommonPacketHandler; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.google.gson.JsonObject; +import com.mojang.authlib.properties.Property; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import java.net.Socket; + +public class BukkitPacketsHandler extends CommonPacketHandler { + + @Override + public void handleCPacketAction(CPacketAction packet, final Socket socket) { + if (packet.getType().equalsIgnoreCase("TimedOut")) { + Client.getInstance().getClientConnection().debug("Connection timed out!"); + } + } + + @Override + public void handleCPacketPlayerAction(CPacketCustomAction packet, Socket socket) { + PacketType type = packet.getPacketType(); + + if (type != null) { + switch (type) { + case BUKKIT_RECEIVE_ACCOUNT_FROM_BUNGEECORD: + handleAccountReceive(packet); + break; + case BUKKIT_PLAYER_RESPAWN: + handleRespawnPlayer(packet); + break; + case BUKKIT_RECEIVE_SKIN_DATA: + handleSkinData(packet); + break; + case BUKKIT_GO: + handleGo(packet); + break; + case BUNGEE_SEND_UPDATED_STATS: + handleBungeeSendStats(packet); + break; + case BUNGEE_SEND_KICK: + handleKick(packet); + break; + case BUNGEE_SEND_PLAYER_ACTION: + handleBungeeSendPlayerAction(packet); + break; + case BUNGEE_SEND_INFO: + handleReceiveInfo(packet); + break; + default: + break; + } + } + } + + private void handleGo(CPacketCustomAction packet) { + val staff = Bukkit.getPlayerExact(packet.getField()); + + if(staff != null) { + if (!VanishAPI.inAdmin(staff)) VanishAPI.changeAdmin(staff); + staff.teleport(Bukkit.getPlayer(packet.getUniqueId())); + } + } + + private void handleReceiveInfo(CPacketCustomAction packet) { + if (packet.getField().equalsIgnoreCase("bukkit-server-turn-on")) { + for (Player onlines : Bukkit.getOnlinePlayers()) { + onlines.sendMessage(packet.getFieldValue()); + onlines.playSound(onlines.getLocation(), Sound.ARROW_HIT, 1, 1); + } + } else if (packet.getField().equalsIgnoreCase("teleport-player-from-report")) { + Player target = BukkitServerAPI.getExactPlayerByNick(packet.getNick()); + + if (target != null) { + Player reportado = BukkitServerAPI.getExactPlayerByNick(packet.getField()); + + if (reportado == null) { + target.sendMessage("§cJogador offline."); + return; + } + + if (!VanishAPI.inAdmin(target)) { + VanishAPI.changeAdmin(target, true); + } + + BukkitMain.runLater(() -> target.teleport(reportado), 12); + } + } else if (packet.getField().equalsIgnoreCase("bungee-send-servers-info")) { + + for (NetworkServer networkServers : CommonsGeneral.getServersManager().getServers()) { + String prefix = networkServers.getServerType().getName().toLowerCase() + "-" + networkServers.getServerId(); + + if (!packet.getJson().has(prefix)) { + CommonsGeneral.error("Erro ao tentar processar informaçőes de um servidor -> " + networkServers.getServerType().getName() + "-" + networkServers.getServerId()); + continue; + } + + JsonObject INFO; + + try { + INFO = CommonsConst.PARSER.parse(packet.getJson().get(prefix).getAsString()).getAsJsonObject(); + + if (networkServers instanceof GameServer) { + CommonsGeneral.getServersManager().getGameServer(networkServers.getServerType(), networkServers.getServerId()).updateData(INFO); + } else { + CommonsGeneral.getServersManager().updateServerData(networkServers.getServerType(), networkServers.getServerId(), INFO); + } + } catch (Exception ex) { + CommonsGeneral.error("Error on update server data! -> " + ex.getLocalizedMessage()); + } + } + + } + } + + private void handleKick(CPacketCustomAction packet) { + Player target = BukkitServerAPI.getExactPlayerByNick(packet.getNick()); + + BukkitMain.runSync(() -> { + if (target != null && target.isOnline()) { + target.kickPlayer(packet.getField()); + } + }); + } + + private void handleRespawnPlayer(final CPacketCustomAction packet) { + Player target = BukkitServerAPI.getExactPlayerByNick(packet.getNick()); + + if (target != null && target.isOnline()) FakeAPI.respawnPlayer(target); + } + + private void handleSkinData(final CPacketCustomAction packet) { + val player = BukkitMain.getBukkitPlayer(packet.getUniqueId()); + if (player == null) return; + + player.setLastSkin(new Property(packet.getFieldValue(), packet.getExtraValue(), packet.getExtraValue2())); + if (packet.getField() != null && packet.getField().equals("sendPacket")) { + if (player.getPlayer() != null) FakeAPI.respawnPlayer(player.getPlayer()); + } + } + + private void handleAccountReceive(final CPacketCustomAction packet) { + GamingProfile profile = LoginListener.connectionQueue.get(packet.getUniqueId()); + + if (profile != null) { + for (int i = 1; i < 10; i++) { + if (packet.getJson().has("dataCategory-" + i)) { + JsonObject json = CommonsConst.PARSER.parse(packet.getJson().get("dataCategory-" + i).getAsString()) + .getAsJsonObject(); + + profile.getDataHandler().loadFromJSON( + DataCategory.getCategoryByName(json.get("dataCategory-name").getAsString()), json); + } + } + + profile.getTokenListener().onAcessToken(AcessToken.ACCEPTED); + } + } + + private void handleBungeeSendPlayerAction(final CPacketCustomAction packet) { + Player player = BukkitServerAPI.getExactPlayerByNick(packet.getNick()); + if (player == null) { + BukkitMain.console(packet.getNick() + " recebeu uma atualizaçao de categoria e nao possui profile"); + return; + } + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer == null) { + BukkitMain.console(packet.getNick() + " recebeu uma atualizaçao e nao possui profile"); + return; + } + + if (packet.getField().equals("update-data")) { + if (packet.getFieldValue().equals("clan")) { + bukkitPlayer.set(DataType.CLAN, packet.getExtraValue()); + bukkitPlayer.updateTag(bukkitPlayer.getPlayer(), bukkitPlayer.getActualTag(), true); + + BukkitMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + } + } + } + + private void handleBungeeSendStats(final CPacketCustomAction packet) { + Player player = BukkitServerAPI.getExactPlayerByNick(packet.getNick()); + if (player == null) { + BukkitMain.console(packet.getNick() + " recebeu uma atualizaçao de categoria e nao possui profile"); + return; + } + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer == null) { + BukkitMain.console(packet.getNick() + " recebeu uma atualizaçao de categoria e nao possui profile"); + return; + } + + JsonObject json = CommonsConst.PARSER.parse(packet.getJson().get("dataCategory-1").getAsString()) + .getAsJsonObject(); + + bukkitPlayer.getDataHandler() + .loadFromJSON(DataCategory.getCategoryByName(json.get("dataCategory-name").getAsString()), json); + + if (!packet.getField().isEmpty()) { + if (packet.getField().equalsIgnoreCase("group")) { + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeGroupEvent(player, bukkitPlayer.getGroup())); + bukkitPlayer.injectPermissions(player); + } else if (packet.getField().equalsIgnoreCase("add-perm")) { + final String permission = packet.getFieldValue(); + + bukkitPlayer.getPlayerAttachment().addPermission(permission); + bukkitPlayer.getData(DataType.PERMISSIONS).getList().add(permission); + BukkitMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT)); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.java new file mode 100644 index 0000000..72827e7 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.java @@ -0,0 +1,120 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.queue; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerQueueEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.player.PlayerQueue; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +public class PlayerBukkitQueue { + + private Listener bukkitListener; + private List players; + private boolean destroyOnFinish, stopOnFinish; + private int ticks; + private QueueType queueType; + + public PlayerBukkitQueue(int ticks, QueueType queueType) { + this(ticks, true, queueType); + } + + public PlayerBukkitQueue(int ticks, boolean destroyOnFinish, QueueType queueType) { + this.players = new ArrayList<>(); + + this.destroyOnFinish = destroyOnFinish; + this.ticks = ticks; + this.queueType = queueType; + } + + public void start() { + this.bukkitListener = new Listener() { + + @EventHandler + public void onSecond(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.TICK) return; + + if (event.getCurrentTick() % ticks != 0) return; + + if (getPlayers().size() == 0) { + if (isDestroyOnFinish()) { + destroy(); + } + return; + } + + if (getPlayers().size() == 0) { + return; + } + + PlayerQueue current = getPlayers().get(0); + if (current == null || !current.getPlayer().isOnline()) { + getPlayers().remove(current); + + current.destroy(); + current = null; + return; + } + + getPlayers().remove(current); + + Bukkit.getServer().getPluginManager().callEvent(new PlayerQueueEvent(current.getPlayer(), queueType, current.getServer())); + + current.destroy(); + current = null; + } + }; + + Bukkit.getServer().getPluginManager().registerEvents(bukkitListener, BukkitMain.getInstance()); + } + + public void destroy() { + if (bukkitListener != null) { + HandlerList.unregisterAll(bukkitListener); + + bukkitListener = null; + } + + if (isStopOnFinish()) { + Client.getInstance().getClientConnection().sendPacket( + new CPacketAction(BukkitMain.getServerType().getName(), BukkitMain.getServerID()).writeType("Loggout")); + + BukkitMain.runLater(() -> { + for (Player onlines : Bukkit.getOnlinePlayers()) { + onlines.kickPlayer("§cNão foi possível conectar-se ao servidor."); + } + + Bukkit.shutdown(); + }, 30); + } + } + + public boolean addToQueue(final Player player) { + return addToQueue(player, ""); + } + + public boolean addToQueue(final Player player, final String server) { + if (getQueuePlayer(player) != null) + return false; + + getPlayers().add(new PlayerQueue(player, server)); + return true; + } + + public PlayerQueue getQueuePlayer(Player player) { + return this.players.stream().filter(qp -> qp.player.equals(player)).findFirst().orElse(null); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.java new file mode 100644 index 0000000..21e1d4a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.java @@ -0,0 +1,6 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.queue; + +public enum QueueType { + + SAVE, CONNECT, CHECK_TIME, KICK +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.java new file mode 100644 index 0000000..0158a29 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.java @@ -0,0 +1,25 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.queue.player; + +import lombok.Getter; +import org.bukkit.entity.Player; + +@Getter +public class PlayerQueue { + + public Player player; + public String server; + + public PlayerQueue(Player player, String server) { + this.player = player; + this.server = server; + } + + public PlayerQueue(Player player) { + this(player, ""); + } + + public void destroy() { + this.player = null; + this.server = null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.java new file mode 100644 index 0000000..7f548b1 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.java @@ -0,0 +1,19 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.addons; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Line { + + private String name, prefix, suffix; + private int lineId; + + public Line(String name, String prefix, String suffix, int lineId) { + this.name = name; + this.prefix = prefix; + this.suffix = suffix; + this.lineId = lineId; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.java new file mode 100644 index 0000000..fa4a329 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.java @@ -0,0 +1,210 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar; + +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.addons.Line; +import lombok.Getter; +import org.bukkit.ChatColor; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +@Getter +public class Sidebar { + + private final Scoreboard scoreboard; + private Objective objective; + + private boolean hided = true; + + private final HashMap lines; + + public Sidebar(Scoreboard scoreboard) { + this.scoreboard = scoreboard; + this.lines = new HashMap<>(); + + show(); + } + + public void show() { + if (!hided) + return; + + hided = false; + this.objective = scoreboard.registerNewObjective("sidebar", "dummy"); + this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); + } + + public void hide() { + if (hided) + return; + + hided = true; + + for (int i = 1; i < 16; i++) { + Team team = scoreboard.getTeam("sidebar-" + i); + if (team != null) { + team.unregister(); + team = null; + } + } + + Objective sidebar = scoreboard.getObjective("sidebar"); + if (sidebar != null) { + sidebar.unregister(); + sidebar = null; + } + + this.lines.clear(); + this.objective = null; + sidebar = null; + } + + public void showHealth() { + if (this.scoreboard.getObjective("showhealth") == null) { + Objective obj = this.scoreboard.registerNewObjective("showhealth", "health"); + obj.setDisplaySlot(DisplaySlot.BELOW_NAME); + obj.setDisplayName("§c❤"); + } + } + + public void addBlankLine() { + int size = this.lines.size(); + addLine("blank-line-" + size, randomChar(size)); + } + + public void addLine(String text) { + int size = this.lines.size(); + addLine("random-line-" + size, text); + } + + public void addLine(String name, String prefix, String suffix) { + this.lines.put(name.toLowerCase(), new Line(name, prefix, suffix, (this.lines.size() + 1))); + } + + public void update() { + if (isHided()) { + return; + } + + int size = Math.min(16, lines.size()); + + int added = 0; + + List lineList = new ArrayList<>(this.lines.values()); + + lineList.sort(Comparator.comparing(Line::getLineId)); + + for (Line line : lineList) { + String name = line.getName(); + + if (name.length() > 16) { + name = name.substring(0, 16); + } + + int slot = size - added; + + line.setLineId(slot); + setText(slot, line.getPrefix(), line.getSuffix()); + added++; + } + } + + public void updateLine(String lineName, String text) { + String prefix = ""; + String suffix = ""; + + if (text.length() <= 16) { + prefix = text; + } else { + prefix = text.substring(0, 16); + + suffix = ChatColor.getLastColors(prefix) + text.substring(16); + + if (suffix.length() > 16) { + suffix = suffix.substring(0, 16); + } + } + + updateLine(lineName, prefix, suffix); + } + + public void addLine(String name, String text) { + String prefix = "", suffix = ""; + + if (text.length() <= 16) { + prefix = text; + } else { + prefix = text.substring(0, 16); + + suffix = ChatColor.getLastColors(prefix) + text.substring(16); + + if (suffix.length() > 16) { + suffix = suffix.substring(0, 16); + } + } + + addLine(name, prefix, suffix); + } + + + public void updateLine(String lineName, String prefix, String suffix) { + if (isHided()) { + return; + } + + Line line = this.lines.getOrDefault(lineName.toLowerCase(), null); + + if (line == null) { + return; + } + + line.setPrefix(prefix); + line.setSuffix(suffix); + + setText(line.getLineId(), line.getPrefix(), line.getSuffix()); + + line = null; + } + + private void setText(int line, String prefix, String suffix) { + Team team = getScoreboard().getTeam("sidebar-" + line); + + if (team == null) { + team = createTeam(line); + } + + team.setPrefix(prefix); + team.setSuffix(suffix); + + suffix = null; + prefix = null; + } + + private Team createTeam(int line) { + Team team = getScoreboard().registerNewTeam("sidebar-" + line); + + String score = ChatColor.values()[line - 1].toString(); + + getObjective().getScore(score).setScore(line); + + if (!team.hasEntry(score)) { + team.addEntry(score); + } + + score = null; + return team; + } + + public void setTitle(String name) { + objective.setDisplayName(name); + } + + public String randomChar(int slot) { + return ChatColor.values()[slot].toString() + ChatColor.RESET; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.java new file mode 100644 index 0000000..624d750 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.java @@ -0,0 +1,27 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar; + +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.UUID; + +public class SidebarManager { + + private static final HashMap sidebars = new HashMap<>(); + + public static void handleJoin(final Player player) { + sidebars.put(player.getUniqueId(), new Sidebar(player.getScoreboard())); + } + + public static Sidebar getSidebar(final Player player) { + return sidebars.get(player.getUniqueId()); + } + + public static Sidebar getSidebar(final UUID uniqueId) { + return sidebars.get(uniqueId); + } + + public static void handleQuit(UUID uniqueId) { + sidebars.remove(uniqueId); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.java new file mode 100644 index 0000000..8bf5cb9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.java @@ -0,0 +1,163 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.tag; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.common.clan.Clan; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.Medals; +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; + +import java.util.ArrayList; +import java.util.List; + +public class TagManager { + + public static final boolean USE_TAGS = true; + + public static void setTag(final Player player, final Groups group) { + if (!USE_TAGS) return; + + setTag(player, group.getTag()); + } + + public static void setTag(final Player player, final Tag tag) { + if (!USE_TAGS) return; + + setTag(player, tag, CommonsGeneral.getProfileManager().getGamingProfile(player.getUniqueId())); + } + + public static void setTag(final Player player, final Tag playerTag, GamingProfile playerProfile) { + if (!USE_TAGS) return; + + String playerTeamID = playerTag.getTeamCharacter() + player.getUniqueId().toString().substring(0, 12); + String playerPrefix = playerTag.getColor() + (playerTag.getLevel() == Groups.MEMBRO.getLevel() ? "" : "§l" + playerTag.getPrefix() + + playerTag.getColor() + " "); + String playerSuffix = getSuffix(playerProfile); + + Team playerTeam = createTeamIfNotExists(player, player.getName(), playerTeamID, playerPrefix, playerSuffix); + + cleanOldersTeam(player, player.getName(), playerTeam.getName()); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (onlines.getUniqueId() == player.getUniqueId()) continue; + + BukkitPlayer bp = BukkitMain.getBukkitPlayer(onlines.getUniqueId()); + + String onlineTeamID = bp.getActualTag().getTeamCharacter() + + onlines.getUniqueId().toString().substring(0, 12); + + String onlinePrefix = bp.getActualTag().getColor() + (bp.getActualTag().getLevel() == Groups.MEMBRO.getLevel() ? "" : "§l" + bp.getActualTag().getPrefix() + + bp.getActualTag().getColor() + " "); + + String onlineSuffix = getSuffix(bp); + + Team onlineTeam = createTeamIfNotExists(player, onlines.getName(), onlineTeamID, onlinePrefix, onlineSuffix); + + cleanOldersTeam(player, onlines.getName(), onlineTeam.getName()); + + createTeamIfNotExists(onlines, player.getName(), playerTeam.getName(), playerTeam.getPrefix(), playerTeam.getSuffix()); + } + } + + private static String getSuffix(final GamingProfile profile) { + String suffix = ""; + + if (BukkitMain.getServerType().useSuffixRank()) { + League league = League.getRanking(profile.getInt(DataType.XP)); + + if (profile.containsFake()) league = League.BronzeI; + + suffix = " " + league.getColor() + league.getSymbol(); + } else { + if (!profile.containsFake() && !profile.getString(DataType.CLAN).equalsIgnoreCase("Nenhum")) { + if (profile.getBoolean(DataType.CLAN_TAG_DISPLAY)) { + Clan clan = ClanManager.getClan(profile.getString(DataType.CLAN)); + suffix = " §7[" + clan.getTag() + "]"; + } + } + } + + Medals medal = Medals.getMedalById(profile.getInt(DataType.MEDAL)); + + if (medal != null) { + suffix = suffix + " " + medal.getColor() + medal.getSymbol(); + } + + return suffix; + } + + private static void cleanOldersTeam(final Player player, final String entryName, final String teamName) { + for (Team team : player.getScoreboard().getTeams()) { + if (team.hasEntry(entryName) && !team.getName().equals(teamName)) { + team.unregister(); + } + } + } + + public static void removePlayerTag(final String name) { + for (Player players : Bukkit.getOnlinePlayers()) { + Team entryTeam = players.getScoreboard().getEntryTeam(name); + + if (entryTeam != null && entryTeam.getEntries().contains(name)) { + entryTeam.removeEntry(name); + + if (entryTeam.getEntries().isEmpty()) entryTeam.unregister(); + } + } + } + + private static Team createTeamIfNotExists(Player p, String entrie, String teamID, String prefix, String suffix) { + if (p.getScoreboard() == null) { + p.setScoreboard(Bukkit.getServer().getScoreboardManager().getNewScoreboard()); + } + + Team team = p.getScoreboard().getTeam(teamID); + if (team == null) team = p.getScoreboard().registerNewTeam(teamID); + + if (!team.hasEntry(entrie)) team.addEntry(entrie); + + team.setPrefix(prefix); + team.setSuffix(suffix); + return team; + } + + public static boolean hasPermission(final Player player, final Groups group) { + return hasPermission(player, group.getTag()); + } + + public static boolean hasPermission(final Player player, final Tag tag) { + if (tag.getLevel() == Groups.MEMBRO.getLevel()) { + return true; + } else { + if (player.hasPermission("tag.all")) + return true; + if (player.hasPermission("tag." + tag.getName().toLowerCase())) + return true; + + return CommonsGeneral.getProfileManager().getGamingProfile(player.getUniqueId()).getGroup().getLevel() >= tag + .getLevel(); + } + } + + public static List getPlayerGroups(Player player) { + List list = new ArrayList<>(); + + for (int i = Groups.values().length; i > 0; i--) { + Groups tag = Groups.values()[i - 1]; + + if (hasPermission(player, tag)) { + list.add(tag); + } + } + + return list; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.java new file mode 100644 index 0000000..7bd48bc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.java @@ -0,0 +1,78 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.utility; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.filter.AbstractFilter; +import org.apache.logging.log4j.message.Message; + +public final class BukkitLogFilter extends AbstractFilter { + + public void registerFilter() { + Logger logger = (Logger) LogManager.getRootLogger(); + logger.addFilter(this); + } + + @Override + public Result filter(LogEvent event) { + return event == null ? Result.NEUTRAL : isLoggable(event.getMessage().getFormattedMessage()); + } + + @Override + public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + return isLoggable(msg.getFormattedMessage()); + } + + @Override + public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) { + return isLoggable(msg); + } + + @Override + public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) { + return msg == null ? Result.NEUTRAL : isLoggable(msg.toString()); + } + + private Result isLoggable(String msg) { + if (msg != null) { + if (msg.contains("Commons")) { + return Result.NEUTRAL; + } + + if (msg.contains("PACKET")) { + return Result.NEUTRAL; + } + + if (msg.contains("twice")) { + return Result.DENY; + } else if (msg.contains("handleDisconnection")) { + return Result.DENY; + } else if (msg.contains("com.mojang.authlib.GameProfile@")) { + return Result.DENY; + } else if (msg.contains("lost connection: Disconnected")) { + return Result.DENY; + } else if (msg.contains("left the game.")) { + return Result.DENY; + } else if (msg.contains("logged in with entity id")) { + return Result.DENY; + } else if (msg.contains("lost connection: Timed out")) { + return Result.DENY; + } else if (msg.contains("UUID of player")) { + return Result.DENY; + } else if (msg.contains("Internal Exception")) { + return Result.DENY; + } else if (msg.contains("lost connection")) { + return Result.DENY; + } else if (msg.contains("has disconnected")) { + return Result.DENY; + } else if (msg.contains("reason")) { + return Result.DENY; + } else if (msg.contains("disconnected with")) { + return Result.DENY; + } + } + return Result.NEUTRAL; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.java new file mode 100644 index 0000000..53a0051 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.java @@ -0,0 +1,11 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.utility; + +import org.bukkit.Location; + +public class LocationUtil { + + public static boolean isRealMovement(Location from, Location to) { + return !(from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()); + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.java new file mode 100644 index 0000000..7cd504e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.java @@ -0,0 +1,381 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.utility; + +import org.bukkit.Bukkit; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class Reflection { + + private static final String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName(); + private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", ""); + private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^}]+)}"); + private Reflection() { + } + + public static void setValue(String field, Class clazz, Object instance, Object value) { + try { + Field f = clazz.getDeclaredField(field); + f.setAccessible(true); + f.set(instance, value); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + + public static Object getValue(String field, Class clazz, Object instance) { + try { + Field f = clazz.getDeclaredField(field); + f.setAccessible(true); + return f.get(instance); + } catch (Exception exception) { + exception.printStackTrace(); + } + return null; + } + + public static void setValue(String field, Object instance, Object value) { + try { + Field f = instance.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(instance, value); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + + public static Object getValue(String field, Object instance) { + try { + Field f = instance.getClass().getDeclaredField(field); + f.setAccessible(true); + return f.get(instance); + } catch (Exception exception) { + exception.printStackTrace(); + } + return null; + } + + /** + * public static Constructor getConstructor1(Class clazz, Class... parameterTypes) throws NoSuchMethodException { + * Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); + * for (Constructor constructor : clazz.getConstructors()) { + * if (!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) { + * continue; + * } + * return constructor; + * } + * throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types"); + * } + *

+ * public static Method getMethod1(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException { + * Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); + * for (Method method : clazz.getMethods()) { + * if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) { + * continue; + * } + * return method; + * } + * throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types"); + * } + *

+ * public static Method getMethod1(String className, PackageType packageType, String methodName, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException { + * return getMethod1(packageType.getClass(className), methodName, parameterTypes); + * } + *

+ * public static Field getField1(Class clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException { + * Field field = declared ? clazz.getDeclaredField(fieldName) : clazz.getField(fieldName); + * field.setAccessible(true); + * return field; + * } + *

+ * public static Field getField1(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException { + * return getField1(packageType.getClass(className), declared, fieldName); + * } + *

+ * public static void setValue1(String field, Class clazz, Object instance, Object value) { + * try { + * Field f = clazz.getDeclaredField(field); + * f.setAccessible(true); + * f.set(instance, value); + * } catch (Exception exception) { + * exception.printStackTrace(); + * } + * } + *

+ * public static void setValue1(Object instance, Class clazz, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { + * getField1(clazz, declared, fieldName).set(instance, value); + * } + *

+ * public static void setValue1(Object instance, String className, PackageType packageType, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException { + * setValue1(instance, packageType.getClass(className), declared, fieldName, value); + * } + *

+ * public static void setValue1(Object instance, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { + * setValue1(instance, instance.getClass(), declared, fieldName, value); + * } + */ + + //PARTICLES END + public static FieldAccessor getField(Class target, String name, Class fieldType) { + return getField(target, name, fieldType, 0); + } + + public static FieldAccessor getField(String className, String name, Class fieldType) { + return getField(getClass(className), name, fieldType, 0); + } + + public static FieldAccessor getField(Class target, Class fieldType, int index) { + return getField(target, null, fieldType, index); + } + + //PARTICLES START + + public static FieldAccessor getField(String className, Class fieldType, int index) { + return getField(getClass(className), fieldType, index); + } + + private static FieldAccessor getField(Class target, String name, Class fieldType, int index) { + for (final Field field : target.getDeclaredFields()) { + if ((name == null || field.getName().equals(name)) && fieldType.isAssignableFrom(field.getType()) && index-- <= 0) { + field.setAccessible(true); + + return new FieldAccessor() { + + @SuppressWarnings("unchecked") + public T get(Object target) { + try { + return (T) field.get(target); + } catch (IllegalAccessException e) { + throw new RuntimeException("Cannot access reflection.", e); + } + } + + public void set(Object target, Object value) { + try { + field.set(target, value); + } catch (IllegalAccessException e) { + throw new RuntimeException("Cannot access reflection.", e); + } + } + + public boolean hasField(Object target) { + return field.getDeclaringClass().isAssignableFrom(target.getClass()); + } + }; + } + } + + if (target.getSuperclass() != null) + return getField(target.getSuperclass(), name, fieldType, index); + + throw new IllegalArgumentException("Cannot find field with type " + fieldType); + } + + public static MethodInvoker getMethod(String className, String methodName, Class... params) { + return getTypedMethod(getClass(className), methodName, null, params); + } + + public static MethodInvoker getMethod(Class clazz, String methodName, Class... params) { + return getTypedMethod(clazz, methodName, null, params); + } + + public static MethodInvoker getTypedMethod(Class clazz, String methodName, Class returnType, Class... params) { + for (final Method method : clazz.getDeclaredMethods()) { + if ((methodName == null || method.getName().equals(methodName)) && (returnType == null) || method.getReturnType().equals(returnType) && Arrays.equals(method.getParameterTypes(), params)) { + method.setAccessible(true); + + return new MethodInvoker() { + + public Object invoke(Object target, Object... arguments) { + try { + return method.invoke(target, arguments); + } catch (Exception e) { + throw new RuntimeException("Cannot invoke method " + method, e); + } + } + + }; + } + } + + if (clazz.getSuperclass() != null) + return getMethod(clazz.getSuperclass(), methodName, params); + + throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); + } + + public static ConstructorInvoker getConstructor(String className, Class... params) { + return getConstructor(getClass(className), params); + } + + public static ConstructorInvoker getConstructor(Class clazz, Class... params) { + for (final Constructor constructor : clazz.getDeclaredConstructors()) { + if (Arrays.equals(constructor.getParameterTypes(), params)) { + constructor.setAccessible(true); + + return new ConstructorInvoker() { + + public Object invoke(Object... arguments) { + try { + return constructor.newInstance(arguments); + } catch (Exception e) { + throw new RuntimeException("Cannot invoke constructor " + constructor, e); + } + } + + }; + } + } + + throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params))); + } + + public static Class getUntypedClass(String lookupName) { + @SuppressWarnings({"rawtypes", "unchecked"}) + Class clazz = (Class) getClass(lookupName); + return clazz; + } + + public static Class getClass(String lookupName) { + return getCanonicalClass(expandVariables(lookupName)); + } + + public static Class getMinecraftClass(String name) { + return getCanonicalClass(NMS_PREFIX + "." + name); + } + + public static Class getCraftBukkitClass(String name) { + return getCanonicalClass(OBC_PREFIX + "." + name); + } + + private static Class getCanonicalClass(String canonicalName) { + try { + return Class.forName(canonicalName); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Cannot find " + canonicalName, e); + } + } + + private static String expandVariables(String name) { + StringBuffer output = new StringBuffer(); + Matcher matcher = MATCH_VARIABLE.matcher(name); + + while (matcher.find()) { + String variable = matcher.group(1); + String replacement = ""; + + // Expand all detected variables + if ("nms".equalsIgnoreCase(variable)) + replacement = NMS_PREFIX; + else if ("obc".equalsIgnoreCase(variable)) + replacement = OBC_PREFIX; + else if ("version".equalsIgnoreCase(variable)) + replacement = VERSION; + else + throw new IllegalArgumentException("Unknown variable: " + variable); + + if (replacement.length() > 0 && matcher.end() < name.length() && name.charAt(matcher.end()) != '.') + replacement += "."; + matcher.appendReplacement(output, Matcher.quoteReplacement(replacement)); + } + + matcher.appendTail(output); + return output.toString(); + } + + public static String getVersion() { + String name = Bukkit.getServer().getClass().getPackage().getName(); + return name.substring(name.lastIndexOf('.') + 1) + "."; + } + + public static Class getNMSClass(String className) { + String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Class getNMSClassWithException(String className) throws Exception { + String fullName = "net.minecraft.server." + getVersion() + className; + return Class.forName(fullName); + } + + public static Class getOBCClass(String className) { + String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Object getHandle(Object obj) { + try { + return getMethod(obj.getClass(), "getHandle").invoke(obj); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static Field getField(Class clazz, String name) { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static Field getFieldWithException(Class clazz, String name) throws Exception { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) { + return false; + } + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } + + public interface ConstructorInvoker { + + Object invoke(Object... arguments); + } + + public interface MethodInvoker { + + Object invoke(Object target, Object... arguments); + } + + public interface FieldAccessor { + + T get(Object target); + + void set(Object target, Object value); + + boolean hasField(Object target); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.java new file mode 100644 index 0000000..3c66513 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.java @@ -0,0 +1,22 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.utility.loader; + +import com.br.guilhermematthew.nowly.commons.common.utility.ClassGetter; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; + +public class BukkitListeners { + + public static void loadListeners(Object instance, String packageName) { + for (Class classes : ClassGetter.getClassesForPackage(instance, packageName)) { + try { + if (Listener.class.isAssignableFrom(classes)) { + Bukkit.getPluginManager().registerEvents((Listener) classes.newInstance(), (Plugin) instance); + } + } catch (Exception exception) { + exception.printStackTrace(); + } + } + } +} + diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.java new file mode 100644 index 0000000..bfd169f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.java @@ -0,0 +1,204 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.actionbar.ActionBarAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.protocol.ProtocolGetter; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.IBlockData; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +@Getter +@Setter +public class Constructions { + + private Player owner; + private int blocksPerTick, maxBlocks, blockAtual, blocksPerSecond; + private List locations; + private List blocksToSet; + private boolean finished, resetando, cancelTask, in18; + private Random random; + private Long started, startedNano; + private HashMap blocksToReset; + + public Constructions(Player owner, List locations) { + this.owner = owner; + this.blocksPerTick = 2; + this.blockAtual = 0; + this.blocksPerSecond = blocksPerTick * 20; + this.finished = false; + this.resetando = false; + this.cancelTask = false; + this.locations = new ArrayList<>(); + this.blocksToReset = new HashMap<>(); + this.blocksToSet = new ArrayList<>(); + + this.locations.addAll(locations); + + this.in18 = ProtocolGetter.getVersion(owner) > 5; + this.maxBlocks = locations.size(); + this.random = new Random(); + } + + public void processBlocks() { + for (int i = 0; i < maxBlocks; i++) { + Location location = locations.get(this.blockAtual + i); + String formated = location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(); + if (this.blocksToReset.containsKey(formated)) { + continue; + } + Block block = location.getBlock(); + this.blocksToReset.put(formated, block.getType()); + } + } + + public void start() { + processBlocks(); + + this.started = System.currentTimeMillis(); + this.startedNano = System.nanoTime(); + + new BukkitRunnable() { + public void run() { + if (cancelTask) { + cancel(); + sendMessageIfPlayerIsOnline("§e§lWORLDEDIT §fConstrução concluída em: §e" + DateUtils.getElapsed(started, startedNano), true); + blockAtual = 0; + finished = true; + return; + } + putBlock(); + } + }.runTaskTimer(BukkitMain.getInstance(), 1L, 1L); + } + + public void startRegress() { + this.blockAtual = 0; + this.resetando = true; + new BukkitRunnable() { + public void run() { + if (cancelTask) { + cancel(); + sendMessageIfPlayerIsOnline("§e§lWORLDEDIT §fConstrução resetada com sucesso.", true); + finished = true; + WorldEditManager.removeConstructionByUUID(getOwner().getUniqueId()); + return; + } + regressBlock(); + } + }.runTaskTimer(BukkitMain.getInstance(), 1L, 1L); + } + + public void sendMessageIfPlayerIsOnline(String mensagem, boolean msg) { + if (getOwner() != null && getOwner().isOnline()) { + if (isIn18()) { + ActionBarAPI.send(getOwner(), mensagem); + } + if (msg) { + getOwner().sendMessage(mensagem); + } + } + } + + @SuppressWarnings("deprecation") + public void putBlock() { + if (this.finished) { + return; + } + if (this.blockAtual >= maxBlocks) { + this.cancelTask = true; + return; + } + + int atualBlocksPertick = this.blocksPerTick; + for (int i = 0; i < atualBlocksPertick; i++) { + try { + Location location = locations.get(this.blockAtual + i); + Material escolhido = getRandomOurExactBlock(); + setAsyncBlock(location.getWorld(), location, escolhido.getId()); + } catch (IndexOutOfBoundsException e) { + } catch (NullPointerException e) { + } + } + + sendMessageIfPlayerIsOnline("§e§lWORLDEDIT §fConstrução em andamento... §e(" + + StringUtility.formatValue(blockAtual) + "/" + StringUtility.formatValue(maxBlocks) + ") " + StringUtility.formatValue(blocksPerSecond) + "b/ps", false); + + this.blockAtual += atualBlocksPertick; + } + + @SuppressWarnings({"deprecation", "unused"}) + public void regressBlock() { + if (this.finished) { + return; + } + if (this.blockAtual >= maxBlocks) { + this.cancelTask = true; + return; + } + int atualBlocksPertick = this.blocksPerTick; + for (int i = 0; i < atualBlocksPertick; i++) { + try { + Location location = locations.get(this.blockAtual + i); + Block block = location.getBlock(); + + String formated = location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(); + Material material = blocksToReset.get(formated); + setAsyncBlock(location.getWorld(), location, material.getId()); + } catch (IndexOutOfBoundsException e) { + } catch (NullPointerException e) { + } + } + sendMessageIfPlayerIsOnline("§e§lWORLDEDIT §fResetando construção... §e(" + + StringUtility.formatValue(blockAtual) + "/" + StringUtility.formatValue(maxBlocks) + ") " + StringUtility.formatValue(blocksPerSecond) + "b/ps", false); + this.blockAtual += atualBlocksPertick; + } + + public void setAsyncBlock(World world, Location location, int blockId) { + setAsyncBlock(world, location, blockId, (byte) 0); + } + + public void setAsyncBlock(World world, Location location, int blockId, byte data) { + setAsyncBlock(world, location.getBlockX(), location.getBlockY(), location.getBlockZ(), blockId, data); + } + + public void setAsyncBlock(World world, int x, int y, int z, int blockId, byte data) { + net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); + net.minecraft.server.v1_8_R3.Chunk chunk = w.getChunkAt(x >> 4, z >> 4); + BlockPosition bp = new BlockPosition(x, y, z); + int i = blockId + (data << 12); + IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getByCombinedId(i); + chunk.a(bp, ibd); + w.notify(bp); + } + + public Material getRandomOurExactBlock() { + if (blocksToReset.size() == 1) { + return blocksToSet.get(0); + } + return blocksToSet.get(random.nextInt(blocksToSet.size())); + } + + public void setBlocksPerTick(int blocksPerTick) { + this.blocksPerTick = blocksPerTick; + this.blocksPerSecond = blocksPerTick * 20; + } + + public void setBlocksToSet(List blocksToSet) { + this.blocksToSet.addAll(blocksToSet); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.java new file mode 100644 index 0000000..6ab233b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit; + +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.IBlockData; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; + +public class WorldEditAPI { + + public static void setAsyncBlock(World world, Location location, int blockId) { + setAsyncBlock(world, location, blockId, (byte) 0); + } + + public static void setAsyncBlock(World world, Location location, int blockId, byte data) { + setAsyncBlock(world, location.getBlockX(), location.getBlockY(), location.getBlockZ(), blockId, data); + } + + public static void setAsyncBlock(World world, int x, int y, int z, int blockId, byte data) { + net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); + net.minecraft.server.v1_8_R3.Chunk chunk = w.getChunkAt(x >> 4, z >> 4); + BlockPosition bp = new BlockPosition(x, y, z); + int i = blockId + (data << 12); + IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getByCombinedId(i); + chunk.a(bp, ibd); + w.notify(bp); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.java new file mode 100644 index 0000000..e2ceb66 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.java @@ -0,0 +1,98 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class WorldEditManager { + + private static HashMap pos1, pos2; + private static HashMap construçőes; + + public static void check() { + if (pos1 == null) + pos1 = new HashMap<>(); + + if (pos2 == null) + pos2 = new HashMap<>(); + + if (construçőes == null) + construçőes = new HashMap<>(); + } + + public static void addConstructionByUUID(Player owner, List locations) { + construçőes.put(owner.getUniqueId(), new Constructions(owner, locations)); + } + + public static void removeConstructionByUUID(UUID uuid) { + construçőes.remove(uuid); + } + + public static boolean hasRollingConstructionByUUID(UUID uuid) { + return construçőes.containsKey(uuid); + } + + public static Constructions getConstructionByUUID(UUID uuid) { + return construçőes.get(uuid); + } + + public static Location getPos1(Player player) { + return pos1.get(player.getUniqueId()); + } + + public static Location getPos2(Player player) { + return pos2.get(player.getUniqueId()); + } + + public static boolean continueEdit(Player player) { + if (!pos1.containsKey(player.getUniqueId())) { + player.sendMessage("§e§lWORLDEDIT §fA primeira localização não foi setada."); + return false; + } + if (!pos2.containsKey(player.getUniqueId())) { + player.sendMessage("§e§lWORLDEDIT §fA segunda localização não foi setada."); + return false; + } + return true; + } + + public static void setPos1(Player player, Location loc) { + pos1.put(player.getUniqueId(), loc); + player.sendMessage("§e§lWORLDEDIT §fPrimeira localização setada em: (§7" + loc.getBlockX() + "§f,§7" + loc.getBlockY() + "§f,§7" + loc.getBlockZ() + "§f)."); + } + + public static void setPos2(Player player, Location loc) { + pos2.put(player.getUniqueId(), loc); + player.sendMessage("§e§lWORLDEDIT §fSegunda localização setada em: (§7" + loc.getBlockX() + "§f,§7" + loc.getBlockY() + "§f,§7" + loc.getBlockZ() + "§f)."); + } + + public static List getLocationsFromTwoPoints(Location location1, Location location2) { + List locations = new ArrayList<>(); + int topBlockX = (location1.getBlockX() < location2.getBlockX() ? location2.getBlockX() : location1.getBlockX()), + bottomBlockX = (location1.getBlockX() > location2.getBlockX() ? location2.getBlockX() : location1.getBlockX()), + topBlockY = (location1.getBlockY() < location2.getBlockY() ? location2.getBlockY() : location1.getBlockY()), + bottomBlockY = (location1.getBlockY() > location2.getBlockY() ? location2.getBlockY() : location1.getBlockY()), + topBlockZ = (location1.getBlockZ() < location2.getBlockZ() ? location2.getBlockZ() : location1.getBlockZ()), + bottomBlockZ = (location1.getBlockZ() > location2.getBlockZ() ? location2.getBlockZ() : location1.getBlockZ()); + + for (int x = bottomBlockX; x <= topBlockX; x++) { + for (int z = bottomBlockZ; z <= topBlockZ; z++) { + for (int y = bottomBlockY; y <= topBlockY; y++) { + locations.add(new Location(location1.getWorld(), x, y, z)); + } + } + } + + return locations; + } + + public static void checkAndRemove(Player player) { + check(); + + construçőes.remove(player.getUniqueId()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.java new file mode 100644 index 0000000..3d2184e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.java @@ -0,0 +1,253 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.object; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Region; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Vector; +import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.NBTTagList; +import net.minecraft.server.v1_8_R3.NBTTagString; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.scheduler.BukkitTask; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class Schematic { + + private final List blockList = new ArrayList<>(); + private final List locationList = new ArrayList<>(); + + private final Region region; + + private BukkitTask task; + + @SuppressWarnings("deprecation") + public Schematic(Region region) { + this.region = region; + + World world = region.getWorld(); + Vector min = region.getMinLocation(); + Vector max = region.getMaxLocation(); + + //blocks ========================================================================================= + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { + for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { + for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { + Block block = world.getBlockAt(x, y, z); + Vector location = new Vector(x, y, z).subtract(min); + SchematicBlock schematicBlock = new SchematicBlock(location, block.getTypeId(), block.getData()); + blockList.add(schematicBlock); + } + } + } + } + + public Schematic(String nome, File file) throws IOException { + FileInputStream stream = new FileInputStream(file); + + NBTTagCompound nbt = NBTCompressedStreamTools.a(stream); + + stream.close(); + + short width = nbt.getShort("Width"); + short height = nbt.getShort("Height"); + short length = nbt.getShort("Length"); + + int offsetX = nbt.getInt("WEOffsetX"); + int offsetY = nbt.getInt("WEOffsetY"); + int offsetZ = nbt.getInt("WEOffsetZ"); + Vector offset = new Vector(offsetX, offsetY, offsetZ); + + int originX = nbt.getInt("WEOriginX"); + int originY = nbt.getInt("WEOriginY"); + int originZ = nbt.getInt("WEOriginZ"); + Vector origin = new Vector(originX, originY, originZ); + + region = new Region(origin, offset, width, height, length); + + //blocks ========================================================================================= + byte[] blockId = nbt.getByteArray("Blocks"); + byte[] blockData = nbt.getByteArray("Data"); + + byte[] addId = new byte[0]; + short[] blocks = new short[blockId.length]; + + if (nbt.hasKey("AddBlocks")) { + addId = nbt.getByteArray("AddBlocks"); + } + + for (int index = 0; index < blockId.length; index++) { + if ((index >> 1) >= addId.length) { + blocks[index] = (short) (blockId[index] & 0xFF); + } else { + if ((index & 1) == 0) { + blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF)); + } else { + blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF)); + } + } + } + + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + for (int z = 0; z < length; ++z) { + int index = y * width * length + z * width + x; + SchematicBlock block = new SchematicBlock(new Vector(x, y, z), blocks[index], blockData[index]); + blockList.add(block); + } + } + } + + //locations ========================================================================================= + NBTTagList locations = nbt.getList("Locations", 8); + for (int i = 0; i < locations.size(); i++) { + SchematicLocation location = new SchematicLocation(locations.getString(i)); + locationList.add(location); + } + } + + public Region getRegion() { + return region; + } + + public void addLocation(SchematicLocation location) { + locationList.add(location); + } + + public List getConvertedLocation(String key, Location pasteLocation) { + List result = new ArrayList<>(); + for (SchematicLocation locations : locationList) { + if (locations.getKey().equals(key)) { + Vector vector = locations.getLocation().clone().add(new Vector(pasteLocation).add(region.getOffset()).subtract(region.getMinLocation())); + result.add(vector.toLocation(pasteLocation.getWorld())); + } + } + return result; + } + + public File save(File file) throws IOException { + NBTTagCompound nbt = new NBTTagCompound(); + + short width = (short) region.getWidth(); + short height = (short) region.getHeight(); + short length = (short) region.getLength(); + + nbt.setShort("Width", width); + nbt.setShort("Height", height); + nbt.setShort("Length", length); + + nbt.setInt("WEOffsetX", region.getOffset().getBlockX()); + nbt.setInt("WEOffsetY", region.getOffset().getBlockY()); + nbt.setInt("WEOffsetZ", region.getOffset().getBlockZ()); + + nbt.setInt("WEOriginX", region.getMinLocation().getBlockX()); + nbt.setInt("WEOriginY", region.getMinLocation().getBlockY()); + nbt.setInt("WEOriginZ", region.getMinLocation().getBlockZ()); + + //blocks ========================================================================================= + byte[] blocks = new byte[width * height * length]; + byte[] blockData = new byte[width * height * length]; + byte[] addBlocks = null; + for (SchematicBlock block : blockList) { + Vector location = block.getLocation(); + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + + int index = y * width * length + z * width + x; + + if (block.getID() > 255) { + if (addBlocks == null) { + addBlocks = new byte[(blocks.length >> 1) + 1]; + } + addBlocks[index >> 1] = (byte) (((index & 1) == 0) + ? addBlocks[index >> 1] & 0xF0 | (block.getID() >> 8) & 0xF + : addBlocks[index >> 1] & 0xF | ((block.getID() >> 8) & 0xF) << 4); + } + + blocks[index] = (byte) block.getID(); + blockData[index] = block.getData(); + + } + + nbt.setByteArray("Blocks", blocks); + nbt.setByteArray("Data", blockData); + if (addBlocks != null) { + nbt.setByteArray("AddBlocks", addBlocks); + } + + //locations ========================================================================================= + NBTTagList locations = new NBTTagList(); + for (SchematicLocation location : locationList) { + locations.add(new NBTTagString(location.toString())); + } + + if (locations != null) { + nbt.set("Locations", locations); + } + + FileOutputStream stream = new FileOutputStream(file); + NBTCompressedStreamTools.a(nbt, stream); + stream.close(); + + return file; + } + + public void paste(String nome, Location location, int bpt) { + Vector finalLocation = new Vector(location).add(region.getOffset()); + World world = location.getWorld(); + + pasteBlocks(nome, world, finalLocation, bpt, false); + } + + public void paste(String nome, Location location, int bpt, boolean force) { + Vector finalLocation = new Vector(location).add(region.getOffset()); + World world = location.getWorld(); + + pasteBlocks(nome, world, finalLocation, bpt, force); + } + + //blocks ========================================================================================= + private void pasteBlocks(String nome, World world, Vector pasteLocation, int bpt, boolean force) { + if (force) { + Iterator iterator = blockList.iterator(); + + while (iterator.hasNext()) { + SchematicBlock schemBlock = iterator.next(); + Vector finalLocation = schemBlock.getLocation().clone().add(pasteLocation); + WorldEditAPI.setAsyncBlock(world, new Location(world, finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()), + schemBlock.getID()); + iterator.remove(); + } + return; + } + + task = Bukkit.getScheduler().runTaskTimer(BukkitMain.getInstance(), () -> { + + Iterator iterator = blockList.iterator(); + + for (int i = 0; i < bpt; i++) { + if (!iterator.hasNext()) { + task.cancel(); + return; + } + + SchematicBlock schemBlock = iterator.next(); + Vector finalLocation = schemBlock.getLocation().clone().add(pasteLocation); + WorldEditAPI.setAsyncBlock(world, new Location(world, finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()), + schemBlock.getID()); + iterator.remove(); + } + }, 0L, 1L); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.java new file mode 100644 index 0000000..0fdf9d5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.java @@ -0,0 +1,30 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.object; + +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Vector; + +public class SchematicBlock { + + private final Vector location; + + private final int id; + + private final byte data; + + public SchematicBlock(Vector location, int id, byte data) { + this.location = location; + this.id = id; + this.data = data; + } + + public Vector getLocation() { + return location; + } + + public int getID() { + return id; + } + + public byte getData() { + return data; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.java new file mode 100644 index 0000000..baeed0d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.object; + +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Vector; + +public class SchematicLocation { + + private final String key; + + private final Vector location; + + public SchematicLocation(String key, Vector location) { + this.key = key; + this.location = location; + } + + public SchematicLocation(String string) { + String[] data = string.split(";"); + this.key = data[0]; + this.location = new Vector(data[1]); + } + + public String getKey() { + return key; + } + + public Vector getLocation() { + return location; + } + + @Override + public String toString() { + return key + ";" + location.toString(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.java new file mode 100644 index 0000000..baa21f4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.java @@ -0,0 +1,26 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils; + +public class Positions { + + private Vector position1, position2; + + public Vector getPosition1() { + return position1; + } + + public void setPosition1(Vector position1) { + this.position1 = position1; + } + + public Vector getPosition2() { + return position2; + } + + public void setPosition2(Vector position2) { + this.position2 = position2; + } + + public boolean isIncomplete() { + return position1 == null || position2 == null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.java new file mode 100644 index 0000000..68fb13e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.java @@ -0,0 +1,167 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; + +public class Region { + + private final Vector minLocation, maxLocation; + private final Vector offset; + private final Vector origin; + private World world; + + public Region(World world, Vector origin, Vector position1, Vector position2) { + this.world = world; + + double minX = Math.min(position1.getX(), position2.getX()); + double minY = Math.min(position1.getY(), position2.getY()); + double minZ = Math.min(position1.getZ(), position2.getZ()); + minLocation = new Vector(minX, minY, minZ); + + double maxX = Math.max(position1.getX(), position2.getX()); + double maxY = Math.max(position1.getY(), position2.getY()); + double maxZ = Math.max(position1.getZ(), position2.getZ()); + maxLocation = new Vector(maxX, maxY, maxZ); + + offset = minLocation.clone().subtract(origin); + this.origin = origin; + } + + public Region(Vector minLocation, Vector offset, int width, int height, int length) { + this.minLocation = minLocation; + + double maxX = width + minLocation.getX() - 1; + double maxY = height + minLocation.getY() - 1; + double maxZ = length + minLocation.getZ() - 1; + this.maxLocation = new Vector(maxX, maxY, maxZ); + + this.offset = offset; + origin = minLocation.clone().subtract(offset); + } + + public Vector origin() { + return origin; + } + + public World getWorld() { + return world; + } + + public Vector getMinLocation() { + return minLocation; + } + + public Vector getMaxLocation() { + return maxLocation; + } + + public Vector getOffset() { + return offset; + } + + public int getWidth() { + return maxLocation.getBlockX() - minLocation.getBlockX() + 1; + } + + public int getHeight() { + return maxLocation.getBlockY() - minLocation.getBlockY() + 1; + } + + public int getLength() { + return maxLocation.getBlockZ() - minLocation.getBlockZ() + 1; + } + + public int getSize() { + return getWidth() * getHeight() * getLength(); + } + + public boolean isInside(Vector location) { + return location.getX() >= minLocation.getX() && location.getX() <= maxLocation.getX() + && location.getY() >= minLocation.getY() && location.getY() <= maxLocation.getY() + && location.getZ() >= minLocation.getZ() && location.getZ() <= maxLocation.getZ(); + } + + public Region getWithoutAir() { + int lowestX = Integer.MAX_VALUE; + int lowestY = Integer.MAX_VALUE; + int lowestZ = Integer.MAX_VALUE; + + int highestX = Integer.MIN_VALUE; + int highestY = Integer.MIN_VALUE; + int highestZ = Integer.MIN_VALUE; + + for (int x = minLocation.getBlockX(); x < maxLocation.getBlockX(); x++) { + for (int y = minLocation.getBlockY(); y < maxLocation.getBlockY(); y++) { + for (int z = minLocation.getBlockZ(); z < maxLocation.getBlockZ(); z++) { + + if (world.getBlockAt(x, y, z).getType() == Material.AIR) { + continue; + } + + if (x < lowestX) { + lowestX = x; + } + if (y < lowestY) { + lowestY = y; + } + if (z < lowestZ) { + lowestZ = z; + } + + if (x > highestX) { + highestX = x; + } + if (y > highestY) { + highestY = y; + } + if (z > highestZ) { + highestZ = z; + } + } + } + } + + for (Entity entities : world.getEntities()) { + + if (entities instanceof Item || entities instanceof Player) { + continue; + } + + Vector location = new Vector(entities.getLocation()); + if (!isInside(location)) { + continue; + } + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + + if (x < lowestX) { + lowestX = x; + } + if (y < lowestY) { + lowestY = y; + } + if (z < lowestZ) { + lowestZ = z; + } + + if (x > highestX) { + highestX = x; + } + if (y > highestY) { + highestY = y; + } + if (z > highestZ) { + highestZ = z; + } + } + + Vector lowest = new Vector(lowestX, lowestY, lowestZ); + Vector highest = new Vector(highestX, highestY, highestZ); + + return new Region(world, origin, lowest, highest); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.java new file mode 100644 index 0000000..e4fee60 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.java @@ -0,0 +1,110 @@ +package com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils; + +import org.bukkit.Location; +import org.bukkit.World; + +public class Vector { + + private double x, y, z; + private float yaw, pitch; + + public Vector(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vector(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vector(double x, double y, double z, float yaw, float pitch) { + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + public Vector(Location location) { + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); + this.yaw = location.getYaw(); + this.pitch = location.getPitch(); + } + + public Vector(String string) { + String[] data = string.split(","); + this.x = Double.parseDouble(data[0]); + this.y = Double.parseDouble(data[1]); + this.z = Double.parseDouble(data[2]); + this.yaw = Float.parseFloat(data[3]); + this.pitch = Float.parseFloat(data[4]); + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + private int round(double d) { + return (int) Math.round(d); + } + + public int getBlockX() { + return round(x); + } + + public int getBlockY() { + return round(y); + } + + public int getBlockZ() { + return round(z); + } + + public float getYaw() { + return yaw; + } + + public float getPitch() { + return pitch; + } + + public Vector add(Vector vector) { + this.x += vector.getX(); + this.y += vector.getY(); + this.z += vector.getZ(); + return this; + } + + public Vector subtract(Vector vector) { + this.x -= vector.getX(); + this.y -= vector.getY(); + this.z -= vector.getZ(); + return this; + } + + public Vector clone() { + return new Vector(x, y, z, yaw, pitch); + } + + @Override + public String toString() { + return x + "," + y + "," + z + "," + yaw + "," + pitch; + } + + public Location toLocation(World world) { + return new Location(world, x, y, z, yaw, pitch); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.java new file mode 100644 index 0000000..db7188d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.java @@ -0,0 +1,205 @@ +package com.br.guilhermematthew.nowly.commons.bungee; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandFramework; +import com.br.guilhermematthew.nowly.commons.bungee.manager.BungeeManager; +import com.br.guilhermematthew.nowly.commons.bungee.networking.BungeePacketsHandler; +import com.br.guilhermematthew.nowly.commons.bungee.scheduler.BungeeUpdateScheduler; +import com.br.guilhermematthew.nowly.commons.bungee.utility.BungeeListeners; +import com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter.LogFilterBungee; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Plugin; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +public class BungeeMain extends Plugin { + + private List messagesBroadcast = Arrays.asList( + "§eParticipe da nossa §6comunidade §eem §bdiscord.gg/leaguemc_", + "§eAcompanhe suas §6estatísticas §eusando o §b/stats", + "§eCansado de usar sempre a mesma §6skin§e? Confira nosso sistema §b/skin", + "§eCompre §6ranks e mais§e em nossa loja §bleaguemc.com.br/loja", + "§eEncontrou um jogador usando §6trapaças§e? Utilize §b/report " + ); + + @Getter + @Setter + private static BungeeMain instance; + + @Getter + @Setter + private static BungeeMain api; + + public static BungeeMain getApi() { + return api; + } + + @Getter + @Setter + private static boolean loaded = false; + + @Getter + @Setter + private static BungeeManager manager; + + @Getter + @Setter + private static String socketServerHost; + + private int messagesIndex = 0; + + public static void shutdown() { + ProxyServer.getInstance().stop(); + } + + @SuppressWarnings("deprecation") + public static void console(String msg) { + ProxyServer.getInstance().getConsole().sendMessage("[Commons] " + msg); + } + + public static void runAsync(Runnable runnable) { + ProxyServer.getInstance().getScheduler().runAsync(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + ProxyServer.getInstance().getScheduler().schedule(getInstance(), runnable, 500, TimeUnit.MILLISECONDS); + } + + public static void runLater(Runnable runnable, long ms) { + ProxyServer.getInstance().getScheduler().schedule(getInstance(), runnable, ms, TimeUnit.MILLISECONDS); + } + + public static void runLater(Runnable runnable, int tempo, TimeUnit timeUnit) { + ProxyServer.getInstance().getScheduler().schedule(getInstance(), runnable, tempo, timeUnit); + } + + @SuppressWarnings("deprecation") + public static boolean registerServer(String serverName, String address, int port) { + if (ProxyServer.getInstance().getServers().containsKey(serverName)) { + console("[DynamicServers] " + serverName + " error on register this server! (" + address + ":" + port + ")"); + return false; + } + + ProxyServer.getInstance().getServers().put(serverName, ProxyServer.getInstance().constructServerInfo(serverName, + new InetSocketAddress(address, port), "Unknown MOTD", false)); + + console("[DynamicServers] " + serverName + " registred! (" + address + ":" + port + ")"); + return true; + } + + @SuppressWarnings("deprecation") + public static void removeServer(String serverName) { + if (!ProxyServer.getInstance().getServers().containsKey(serverName)) { + return; + } + + TextComponent reason = new TextComponent("You were kicked because " + "the server was removed."); + + ServerInfo info = ProxyServer.getInstance().getServerInfo(serverName); + + if (info == null) { + return; + } + + for (ProxiedPlayer player : info.getPlayers()) { + player.disconnect(reason); + } + + console("[DynamicServers] " + serverName + " removed! (" + info.getAddress().getAddress().getHostAddress() + ":" + + info.getAddress().getPort() + ")"); + + ProxyServer.getInstance().getServers().remove(info.getName()); + } + + public static boolean isValid(ProxiedPlayer proxiedPlayer) { + if (proxiedPlayer == null) + return false; + if (proxiedPlayer.getServer() == null) + return false; + if (proxiedPlayer.getServer().getInfo().getName().equalsIgnoreCase("Login")) + return false; + + return CommonsGeneral.getProfileManager().containsProfile(proxiedPlayer.getName()); + } + + public static BungeePlayer getBungeePlayer(final UUID uniqueId) { + return (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(uniqueId); + } + + public static BungeePlayer getBungeePlayer(final String name) { + return (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(name); + } + + public void onLoad() { + setInstance(this); + + CommonsGeneral.setPluginInstance(PluginInstance.BUNGEECORD); + + if (!getDataFolder().exists()) { + getDataFolder().mkdir(); + } + + setManager(new BungeeManager()); + getManager().getConfigManager().getBungeeConfig().load(); + getManager().getConfigManager().getPermissionsConfig().load(); + + CommonsGeneral.getMySQL().openConnection(); + } + + public void onEnable() { + if (CommonsGeneral.correctlyStarted()) { + LogFilterBungee.load(getInstance()); + + CommonsGeneral.getMySQL().createTables(); + + ServerCommunication.setPacketHandler(new BungeePacketsHandler()); + + ServerCommunication.startServer(socketServerHost); + + CommonsGeneral.getServersManager().init(); + + new BungeeCommandFramework(this) + .loadCommands(this, "com.br.guilhermematthew.nowly.commons.bungee.commands.register"); + + BungeeListeners.loadListeners(getInstance(), "com.br.guilhermematthew.nowly.commons.bungee.listeners"); + + getProxy().getScheduler().schedule(getInstance(), new BungeeUpdateScheduler(), 1, 1, TimeUnit.SECONDS); + + getProxy().getScheduler().schedule(this, () -> { + if (messagesIndex >= messagesBroadcast.size()) + messagesIndex = 0; + getProxy().broadcast(TextComponent + .fromLegacyText("§2§lLEAGUE §7» " + messagesBroadcast.get(messagesIndex))); + ++messagesIndex; + }, 2, 2, TimeUnit.MINUTES); + getManager().init(); + } else { + shutdown(); + } + } + + public void onDisable() { + CommonsGeneral.getMySQL().closeConnection(); + + if (Server.getInstance() != null) { + try { + Server.getInstance().getServerGeneral().disconnect(); + } catch (IOException e) { + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.java new file mode 100644 index 0000000..19fbac1 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.java @@ -0,0 +1,254 @@ +package com.br.guilhermematthew.nowly.commons.bungee; + +import static com.br.guilhermematthew.nowly.commons.CommonsConst.*; + +public class BungeeMessages { + + private static final String PREFIXO = PREFIX + "\n\n"; + + public static final String + + AGORA_VOCE_TEM_UMA_SESSãO_NO_SERVIDOR = "§f", + ROOM_STARTED = "§aAtenção! Uma sala de %sala% foi liberada para acesso.", + //MENSAGEM GLOBAL DE BAN START + JOGADOR_FOI_BANIDO_TEMPORARIAMENTE = "§cUm jogador foi punido por Uso de trapaças em sua sala.", + JOGADOR_FOI_BANIDO_PERMANENTEMENTE = "§cUm jogador foi punido por Uso de trapaças em sua sala.", + //MENSAGEM GLOBAL DE BAN END + + CONTA_JA_MUTADA = "§cEsta conta já está mutada.", + CONTA_MUTADA = "§aJogador mutado com sucesso!", + + CONTA_NAO_ESTA_MUTADA = "§cEste jogador não está mutado.", + CONTA_DESMUTADA = "§aJogador desmutado com sucesso!", + + CONTA_DESBANIDA = "§aJogador desbanido com sucesso!", + CONTA_NAO_ESTA_BANIDA = "§cEsta conta não está banida.", + + MUTADO_PERMANENTEMENTE = + "\n" + + "§cVocê está mutado permanentemente.\n" + + "§eVocê pode ser desmutado adquirindo unmute em: " + LOJA + "\n", + + MUTADO_TEMPORARIAMENTE = + "\n§cVocê está mutado temporariamente.\n" + + "§cTempo restante: §e%tempo%\n" + + "§eVocê pode ser desmutado adquirindo unmute em: " + LOJA + "\n", + + VOCE_FOI_MUTADO_PERMANENTEMENTE = "§cVocê foi mutado permanentemente!\n" + + "§cMotivo: %motivo%\n", + + VOCE_FOI_MUTADO_TEMPORARIAMENTE = "§cVocê foi mutado temporariamente!\n" + + "§cMotivo: %motivo%\n" + + "§cDuração: %duração%\n", + + JOGADOR_BANIDO_PERMANENTEMENTE = "§aJogador banido permanentemente com sucesso!", + JOGADOR_BANIDO_TEMPORARIAMENTE = "§aJogador banido temporariamente com sucesso!", + DONT_BAN_PLAYER_ABOVE_YOU = "§cVocê não pode banir alguém com o cargo superior ao seu.", + JOGADOR_JA_BANIDO = "§cEste jogador já está banido!", + JOGADOR_JA_MUTADO = "§cEste jogador já está mutado!", + DONT_MUTE_ABOVE_YOU = "§cVocê não pode mutar este jogador!", + JOGADOR_MUTADO_PERMANENTEMENTE = "§aJogador mutado permanentemente com sucesso!", + JOGADOR_MUTADO_TEMPORARIAMENTE = "§aJogador mutado temporariamente com sucesso!", + + MUTE = "§cUtilize /mute (player) (motivo)", + TEMPMUTE = "§cUtilize /tempmute (player) (tempo) (motivo)", + BAN = "§cUtilize /ban (player) (motivo)", + TEMPBAN = "§cUtilize /tempban (player) (tempo) (motivo)", + UNBAN = "§cUtilize /unban (player)", + UNMUTE = "§cUtilize /unmute (player)", + + PERMISSION_ADDED_FOR_PLAYER = "§aVocê adicionou a permissão §f%permissao% para §a%nick%", + GRUPO_INEXISTENTE = "§cEsse grupo não existe!", + GRUPO_ALTO = "§cEsse cargo é maior do que o seu.", + + //MESAGENS PARA STAFFERS START + JOGADOR_FOI_MUTADO_PARA_STAFFER = "§7[O jogador %nick% foi mutado %duração% pelo %mutou%]", + JOGADOR_FOI_BANIDO_PARA_STAFFER = "§7[O jogador %nick% foi banido %duração% pelo %baniu%]", + JOGADOR_FOI_DESBANIDO_PARA_STAFFER = "§7[O jogador %nick% foi desbanido por %staffer%]", + JOGADOR_TEVE_GRUPO_ATUALIZADO_PARA_STAFFER = "§7[O jogador %nick% recebeu o cargo %cargo% §7pelo %setou% com duração %duração%]", + //MENSAGENS PARA STAFFERS END + + VOCE_RECEBEU_UM_GRUPO = "§aVocê recebeu o rank %cargo% §acom a duração %duração%", + VOCE_ATUALIZOU_O_CARGO = "§aVocê adicionou o rank %cargo% §ano jogador %nick%", + VOCE_NAO_PODE_ADICIONAR_UM_CARGO_MAIOR = "§cVocê não pode setar um rank maior que o seu!", + SEU_GRUPO_EXPIROU = "§cO seu rank %cargo% §cfoi expirado.", + + COMMAND_GROUP_USAGE = + "§cUtilize: /setgroup " + + "§cUtilize: /setgroup ", + + //EVENTO START + + EVENTO_MANAGER_USAGE = "§cUtilize o comando /eventomanager (on) ou (off) para liberar a entrada de players.", + + EVENTO_MANAGER_ONLINE = "§aO evento já está liberado.", + EVENTO_MANAGER_OFFLINE = "§cO evento não está liberado.", + EVENTO_OFFLINE = "§eNenhum evento está disponivel.", + VOCE_LIBEROU_A_ENTRADA_NO_EVENTO = "§aVocê liberou a entrada de jogadores.", + VOCE_LIBEROU_A_ENTRADA_APENAS_PARA_STAFFERS = "§aVocê liberou apenas staffers para entrarem na sala de eventos.", + EVENTO_LIBERADO = "\n§eO servidor de §b§lEVENTO §e foi liberado!\n\n§aevento.leaguemc.com.br\n\n§7Clique para conectar-se.", + + //EVENTO END + + ALERT = "§cUtilize para anunciar em todos os servidores /alert ", + ALERT_PREFIX = "§4§lALERTA §f", + COMMAND_GO_USAGE = "§cUtilize: /go ", + PLAYER_FINDED = "§eJogador encontrado!\n§eOnline no servidor: §b%servidor%", + PLAYER_KICKED = "§aJogador(a) expulso(a) com sucesso!", + DONT_KICK_PLAYER_ABOVE_YOU = "§cVocê não pode expulsar alguém com o grupo §6§lSUPERIOR §cque o seu.", + KICKING_ALL_PLAYERS = "§aExpulsando todos os jogadores online...", + KICK_USAGE = "§cUtilize /kick (player) (motivo)", + + + CONNECTING = "§aConectando...", + VOCE_JA_ESTA_NESTE_SERVIDOR = "§cVocê ja está neste servidor.", + + //REPORT START + + AGUARDE_PARA_REPORTAR_NOVAMENTE = "§cAguarde alguns segundos para reportar um jogador novamente.", + COMMAND_REPORT_USAGE = "§cUtilize: /report ", + VOCE_NAO_PODE_SE_REPORTAR = "§cVocê não pode reportar a si mesmo!", + JOGADOR_REPORTADO_COM_SUCESSO = "§aJogador reportado com sucesso!", + REPORT_ENABLED = "§aVocê agora receberá as notificações de report.", + REPORT_DISABLED = "§cVocê agora não receberá as notificações de report.", + NEW_REPORT = "§cNOVO REPORT: %target% (Reportado pelo: %from%) - Motivo: %cause%", + + //REPORT END + + //COMMAND SEND START + + COMMAND_SEND_USAGE = "\n" + + "§cUtilize: /send \n" + + "§cUtilize: /send todos \n" + + "§cUtilize: /send local \n" + + "§cUtilize: /send \n", + + SERVER_NOT_EXIST = "§cEste servidor não existe!", + VOCE_NAO_PODE_ENVIAR_PARA_ESTE_SERVIDOR = "§cVocê não pode enviar ninguém para este servidor.", + VOCE_NAO_PODE_PUXAR_DESTE_SERVIDOR = "§cVocê não pode puxar ninguém deste servidor.", + + SENDED_FOR_OTHER_SERVER = "§aVocê foi redirecionado para outro servidor!", + TRYING_SEND_PLAYER_FOR_SERVER = "§aTentando enviar o(a) jogador(a) %nick% §apara o servidor: §a%destino%", + TRYING_SEND_ALL_FOR_SERVER = "§aTentando enviar todos os JOGADORES §aonline para o servidor: §a%destino%", + TRING_SEND_LOCAL_FOR_SERVER = "§aTentando enviar todos os JOGADORES §aonline no seu servidor para o: §a%destino%", + TRYING_SEND_SERVER_TO_SERVER = "§aTentando enviar todos os JOGADORES §ado servidor §a%servidor% §apara o §a%destino%", + + //COMMAND SEND STOP + + //STAFFCHAT START + + VOCE_ENTROU_NO_STAFFCHAT = "§aVocê entrou no staffchat.", + VOCE_SAIU_DO_STAFFCHAT = "§cVocê saiu do staffchat.", + VOCE_DESATIVOU_O_STAFFCHAT = "§cVocê desativou o StaffChat.", + VOCE_ATIVOU_O_STAFFCHAT = "§aVocê ativou o StaffChat.", + STAFFCHAT_JA_ESTA_ATIVADO = "§aO StaffChat já está ativado!", + STAFFCHAT_JA_ESTA_DESATIVADO = "§cO StaffChat já está desativado!", + VOCE_ESTA_TENTANDO_FALAR_NO_STAFFCHAT_COM_ELE_DESATIVADO = "§cVocê está no StaffChat, mas não está vendo as mensagens. Ative-as.", + STAFFCHAT_PREFIX = "§e§l(STAFF)", + + //STAFCHAT END + + CLAN_CHAT_PREFIX = "§e§l(CLAN)", + STAFFLIST_PREFIX = "§6§lLISTA DE STAFFERS ONLINE", + STAFFLIST_PLAYER = "§f- %nick% §7: %servidor%", + + SKIN_ATUALIZADA = "§aSua skin foi atualizada com sucesso!", + ERROR_ON_UPDATE_SKIN = "§cOcorreu um erro ao tentar atualizar sua skin!", + ERROR_ON_CHANGE_SKIN = "§cOcorreu um erro ao tentar trocar sua skin!", + + VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO = "§cVocê não tem permissão para usar este comando.", + + PREMIUM_MAP_NOT_LOADED = "§fO seu registro não foi verificado, tente entrar novamente.", + + ERROR_ON_LOAD_PREMIUM_MAP = "§cNão foi possivel verificar sua conta, tente entrar novamente.", + + PREMIUM_MAP_DETECT_NICK_CHANGE = "§cDetectamos uma alteração em seu nickname, espere até que os dados sejam transferidos.", + + INVALID_NICKNAME = PREFIX + "\n§cO seu nickname deve ser no mínimo 3, e no máximo 16 caracteres, e não pode conter caracteres especiais.", + + BUNGEECORD_CARREGANDO = "§cO servidor está carregando, aguarde para poder entrar.", + SERVIDOR_EM_MANUTENÇãO ="§cEste servidor está disponivel somente para membros da equipe.", + + SUA_CONTA_ESTA_SENDO_DESCARREGADA = "§cErro ao carregar sua sessão, tente novamente mais tarde.", + + ERROR_ON_APPLY_SKIN = "§cHouve um erro ao carregar sua skin em nossa API-MINESKIN.", + + ERROR_ON_LOAD_ACCOUNT = "Não foi possivel carregar sua conta, tente novamente mais tarde.", + + ERROR_ON_CONNECT_TO_X_SERVER = "§cNão foi possivel conectar-se a uma sala LB.", + + // PUNIÇŐES + + VOCE_FOI_BANIDO = "§cVocê foi banido do servidor.\n" + "§cPor: %baniu%\n" + + "§cMotivo: %motivo%\n" + "\n" + "§cSolicite seu appeal no nosso discord: " + DISCORD + "\n" + + "§cAdquira unban em nossa loja: " + LOJA, + + VOCE_ESTA_PERMANENTEMENTE_BANIDO = "§cVocê está permanentemente banido.\n\n" + + "§cMotivo: %motivo%\n" + "§cAutor: %baniu%\n\n" + "§cSolicite seu appeal no nosso discord: " + + DISCORD + "\n" + "§cAdquira unban em nossa loja: " + LOJA, + + VOCE_ESTA_TEMPORARIAMENTE_BANIDO = "§cVocê está temporariamente banido.\n\n" + + "§cDuração: %tempo%\n\n" + "§cMotivo: %motivo%\n" + "§cAutor: %baniu%\n\n" + + "§cSolicite seu appeal no nosso discord: " + DISCORD + "\n" + + "§cAdquira unban em nossa loja: " + LOJA, + // PUNIÇŐES END; + + JOGADOR_NAO_POSSUI_SESSAO = "§cEste jogador não possuí uma sessão valida no servidor.", + NAO_POSSUI_SESSAO = "§cO jogador não tem uma sessão válida no servidor.", + JOGADOR_OFFLINE = "§fJogador offline!", + TEMPO_INVALIDO = "§cTempo inválido.", + NAO_TEM_CONTA = "§cO jogador não possuí um registro na rede.", + + VOCE_FOI_EXPULSO = PREFIXO + + "§cVocê foi expulso.\n" + + "§cExpulso por: %expulsou%\n" + + "§cMotivo: %motivo%", + + //clan + CLAN_NOME_INVALIDO = "§cEste nome é invalido!", + CLAN_INEXISTENTE = "§cEste clan não existe.", + CLAN_FULL = "§cEste clan está lotado!", + CLAN_CRIADO = "§aClan criado com sucesso!", + VOCE_NAO_ESTA_EM_UM_CLAN = "§cVocê não possui um clan.", + VOCE_JA_ESTA_EM_UM_CLAN = "§cVocê ja está em um clan.", + VOCE_SAIU_DO_CHAT_DO_CLAN = "§cVocê saiu do Chat do clan!", + VOCE_ENTROU_NO_CHAT_DO_CLAN = "§aVocê entrou do Chat do clan!", + CLAN_NAME_INVALIDO = "§cVocê não pode criar um clan com este nome.", + CLAN_NAME_INVALIDO2 = "§cO Nome do clan deve possuir entre 5 a 20 caracteres.", + CLAN_EXIST = "§cEste clan já existe, escolha outro nome.", + CLAN_TAG_INVALIDA = "§cA tag do clan deve possuir entre 3 a 5 caracteres.", + VOCE_NAO_PODE_DELETAR = "§cApenas o §4§lDONO §cdo clan pode deletar o clan.", + CLAN_DESFEITO = "§fO seu clan foi deletado.", + VOCE_NAO_PODE_SAIR = "§cVocê não pode sair do clan!", + VOCE_SAIU_DO_CLAN = "§cVocê saiu do clan!", + PLAYER_SAIU_DO_CLAN = "§c%nick% §csaiu do clan!", + PLAYER_É_O_NOVO_DONO = "§a%nick% §aé o novo dono do clan!", + VOCE_NAO_PODE_EXPULSAR = "§cVocê não pode expulsar alguém do clan.", + JOGADOR_NAO_ESTA_NO_SEU_CLAN = "§cEste jogador não está no seu clan.", + JOGADOR_EXPULSO_CLAN = "§aJogador expulso do clan!", + VOCE_NAO_PODE_SE_CONVIDAR = "§cVocê não pode convidar a sí mesmo.", + VOCE_NAO_PODE_CONVIDAR = "§cVocê não possui permissão para convidar alguém para o clan.", + JA_TEM_CONVITE = "§cO jogador já possui um convite.", + VOCE_ENTROU_NO_CLAN = "§aVocê entrou no clan!", + VOCE_NAO_TEM_CONVITE_PENDENTE = "§cVocê não possui um convite de um clan.", + VOCE_NAO_PODE_SE_EXPULSAR = "§cVocê não pode expulsar a sí mesmo.", + VOCE_NAO_PODE_EXPULSAR_O_DONO = "§cVocê não pode expulsar o §4§lDONO §cdo clan.", + VOCE_FOI_EXPULSO_DO_CLAN = "§cVocê foi expulso do clan!", + PLAYER_EXPULSO_DO_CLAN = "§c%nick% §cfoi expulso do clan!", + PLAYER_ENTROU_NO_CLAN = "§a%nick% §ajuntou-se ao clan!", + JOGADOR_JA_ESTA_EM_UM_CLAN = "§cO jogador já possui um clan.", + VOCE_CONVIDOU = "§aVocê convidou %nick% para o clan", + VOCE_RECEBEU_CONVITE = "§eVocê recebeu um convite para juntar-se ao clan: %clan%\n" + + "§cUtilize: /clan aceitar para entrar!", + APENAS_O_DONO_PODE_PROMOVER = "§cApenas o §4§lDONO §cdo clan pode promover alguém.", + VOCE_NAO_PODE_SE_REBAIXAR = "§cVocê não pode rebaixar a sí mesmo.", + VOCE_NAO_PODE_SE_PROMOVER = "§cVocê não pode promover a sí mesmo.", + JA_ESTA_PROMOVIDO = "§cEste jogador já é um administrador §cdo clan.", + VOCE_FOI_PROMOVIDO = "§aVocê foi promovido para administração do clan.", + VOCE_PROMOVEU = "§aVocê promoveu %nick% para administrador do clan.", + VOCE_REBAIXOU = "§cVocê rebaixou %nick% para membro do clan.", + APENAS_O_DONO_PODE_REBAIXAR = "§fApenas o §4§lDONO §fdo clan pode promover alguém.", + NAO_ESTA_PROMOVIDO = "§cEste jogador não é um administrador do clan.", + VOCE_FOI_REBAIXADO = "§cVocê foi rebaixado para membro do clan.", + VOCE_NAO_TEM_COINS_O_SUFICIENTE_PARA_CRIAR_CLAN = "§cVocê precisa de mais %coins% §cpara criar um clan."; +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.java new file mode 100644 index 0000000..dc5cf91 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.java @@ -0,0 +1,73 @@ +package com.br.guilhermematthew.nowly.commons.bungee.account; + +import com.br.guilhermematthew.nowly.commons.bungee.account.permission.BungeePlayerPermissions; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.SQLException; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +@Getter +@Setter +public class BungeePlayer extends GamingProfile { + + private boolean inStaffChat = false, + inClanChat = false; + + private long lastReport; + private long lastLoggedOut; + + private String loginOnServer; + + public BungeePlayer(String nick, String address, UUID uniqueId) { + super(nick, address, uniqueId); + setLastReport(0L); + setLastLoggedOut(0L); + setLoginOnServer("Lobby"); + } + + public void handleLogin(final ProxiedPlayer proxiedPlayer) { + BungeePlayerPermissions.injectPermissions(proxiedPlayer, getGroup().getName()); + + if (!getString(DataType.CLAN).equalsIgnoreCase("Nenhum")) { + ClanManager.getClan(getString(DataType.CLAN)).addOnline(proxiedPlayer); + } + + try { + getPunishmentHistoric().loadMutes(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void handleQuit() { + set(DataType.LAST_LOGGED_OUT, System.currentTimeMillis()); + setLastLoggedOut(System.currentTimeMillis()); + } + + public boolean isValidSession() { + return System.currentTimeMillis() < getLong(DataType.LAST_LOGGED_IN) + TimeUnit.HOURS.toMillis(4); + } + + public boolean isAvailableToJoin() { + return System.currentTimeMillis() > getLastLoggedOut() + TimeUnit.SECONDS.toMillis(4); + } + + public boolean podeReportar() { + return getLastReport() + TimeUnit.SECONDS.toMillis(30) < System.currentTimeMillis(); + } + + public boolean isValidPlayer() { + return getPlayer() != null && getPlayer().getServer() != null; + } + + public ProxiedPlayer getPlayer() { + return ProxyServer.getInstance().getPlayer(getUniqueId()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.java new file mode 100644 index 0000000..a7326aa --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.commons.bungee.account.permission; + +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import lombok.val; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.List; + +public class BungeePlayerPermissions { + + public static void addPermission(final ProxiedPlayer proxiedPlayer, final String permission) { + proxiedPlayer.setPermission(permission, true); + } + + public static void injectPermissions(final ProxiedPlayer proxiedPlayer, final String grupo) { + List permissions = Groups.getGroup(grupo).getPermissions(); + + permissions.forEach(permission -> proxiedPlayer.setPermission(permission, true)); + } + + public static void clearPermissions(ProxiedPlayer proxiedPlayer) { + val clone = new ArrayList<>(proxiedPlayer.getPermissions()); + + clone.forEach(permission -> proxiedPlayer.setPermission(permission, false)); + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.java new file mode 100644 index 0000000..9cc54b9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.java @@ -0,0 +1,228 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import lombok.val; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.TabCompleteEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.event.EventHandler; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; +import java.util.Map.Entry; + +public class BungeeCommandFramework implements CommandFramework { + + private final Map> commandMap = new HashMap>(); + private final Map> completers = new HashMap>(); + private final Plugin plugin; + + public BungeeCommandFramework(Plugin plugin) { + this.plugin = plugin; + this.plugin.getProxy().getPluginManager().registerListener(plugin, new BungeeCompleter()); + } + + @SuppressWarnings("deprecation") + public boolean handleCommand(CommandSender sender, String label, String[] args) { + StringBuilder line = new StringBuilder(); + + line.append(label); + + for (int i = 0; i < args.length; i++) { + line.append(" ").append(args[i]); + } + + for (int i = args.length; i >= 0; i--) { + StringBuilder buffer = new StringBuilder(); + buffer.append(label.toLowerCase()); + + for (int x = 0; x < i; x++) { + buffer.append(".").append(args[x].toLowerCase()); + } + + String cmdLabel = buffer.toString(); + if (commandMap.containsKey(cmdLabel)) { + Entry entry = commandMap.get(cmdLabel); + Command command = entry.getKey().getAnnotation(Command.class); + + if (sender instanceof ProxiedPlayer) { + ProxiedPlayer p = (ProxiedPlayer) sender; + + if (!BungeeMain.isValid(p)) { + p.sendMessage(BungeeMessages.VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO); + return true; + } + + Groups tagPlayer = CommonsGeneral.getProfileManager().getGamingProfile(p.getName()).getGroup(); + + boolean semPermissao = true; + for (int uses = 0; uses < command.groupsToUse().length; uses++) { + Groups tag = command.groupsToUse()[uses]; + if (tagPlayer.getLevel() >= tag.getLevel()) { + semPermissao = false; + break; + } + } + + tagPlayer = null; + + if (semPermissao) { + if (hasCommand(p, command.name().toLowerCase())) { + semPermissao = false; + } + } + + if (semPermissao) { + p.sendMessage(BungeeMessages.VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO); + return true; + } + p = null; + } + + if (command.runAsync()) { + CommonsGeneral.runAsync(() -> { + try { + entry.getKey().invoke(entry.getValue(), new BungeeCommandSender(sender), label, args); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + }); + } else { + try { + entry.getKey().invoke(entry.getValue(), new BungeeCommandSender(sender), label, args); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + } + return true; + } + } + return true; + } + + public boolean hasCommand(ProxiedPlayer proxiedPlayer, String command) { + if (proxiedPlayer.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd.all")) { + return true; + } + return proxiedPlayer.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd." + command); + } + + @Override + public void registerCommands(CommandClass cls) { + for (Method m : cls.getClass().getMethods()) { + if (m.getAnnotation(Command.class) != null) { + Command command = m.getAnnotation(Command.class); + if (m.getParameterTypes().length != 3 + || !BungeeCommandSender.class.isAssignableFrom(m.getParameterTypes()[0]) + && !String.class.isAssignableFrom(m.getParameterTypes()[1]) + && !String[].class.isAssignableFrom(m.getParameterTypes()[2])) { + System.out.println("Unable to register command " + m.getName() + ". Unexpected method arguments"); + continue; + } + registerCommand(command, command.name(), m, cls); + for (String alias : command.aliases()) { + registerCommand(command, alias, m, cls); + } + } else if (m.getAnnotation(Completer.class) != null) { + Completer comp = m.getAnnotation(Completer.class); + if (m.getParameterTypes().length != 3 + || m.getParameterTypes()[0] != ProxiedPlayer.class + && m.getParameterTypes()[1] != String.class + && m.getParameterTypes()[2] != String[].class) { + System.out.println( + "Unable to register tab completer " + m.getName() + ". Unexpected method arguments"); + continue; + } + if (m.getReturnType() != List.class) { + System.out.println("Unable to register tab completer " + m.getName() + ". Unexpected return type"); + continue; + } + registerCompleter(comp.name(), m, cls); + for (String alias : comp.aliases()) { + registerCompleter(alias, m, cls); + } + } + } + } + + /** + * Registers all the commands under the plugin's help + */ + + private void registerCommand(Command command, String label, Method m, Object obj) { + Entry entry = new AbstractMap.SimpleEntry<>(m, obj); + commandMap.put(label.toLowerCase(), entry); + String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase(); + + net.md_5.bungee.api.plugin.Command cmd; + if (command.permission().isEmpty()) + cmd = new BungeeCommand(cmdLabel); + else + cmd = new BungeeCommand(cmdLabel, command.permission()); + plugin.getProxy().getPluginManager().registerCommand(plugin, cmd); + } + + private void registerCompleter(String label, Method m, Object obj) { + completers.put(label, new AbstractMap.SimpleEntry(m, obj)); + } + + @Override + public Plugin getPlugin() { + return plugin; + } + + class BungeeCommand extends net.md_5.bungee.api.plugin.Command { + + protected BungeeCommand(String label) { + super(label); + } + + protected BungeeCommand(String label, String permission) { + super(label, permission); + } + + @Override + public void execute(net.md_5.bungee.api.CommandSender sender, String[] args) { + handleCommand(sender, getName(), args); + } + + } + + public class BungeeCompleter implements Listener { + + @SuppressWarnings("unchecked") + @EventHandler + public void onTabComplete(TabCompleteEvent event) { + if (!(event.getSender() instanceof ProxiedPlayer)) return; + + val pp = (ProxiedPlayer) event.getSender(); + + if(!event.getCursor().contains(" ")) return; + + val split = event.getCursor().split(" "); + + val label = split[0].toLowerCase().substring(1); + val args = split.length < 2 ? new String[]{} : Arrays.copyOfRange(split, 1, split.length); + + if (completers.containsKey(label)) { + try { + val entry = completers.get(label); + + event.getSuggestions().clear(); + event.getSuggestions().addAll((List) entry.getKey().invoke(entry.getValue(), pp, label, args)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.java new file mode 100644 index 0000000..231340d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.java @@ -0,0 +1,109 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.common.command.CommandSender; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.Collection; +import java.util.UUID; + +@RequiredArgsConstructor +public class BungeeCommandSender implements CommandSender, net.md_5.bungee.api.CommandSender { + + @NonNull + private net.md_5.bungee.api.CommandSender sender; + + @Override + public void addGroups(String... arg0) { + sender.addGroups(arg0); + } + + @Override + public Collection getGroups() { + return sender.getGroups(); + } + + @Override + public String getName() { + return sender.getName(); + } + + @Override + public Collection getPermissions() { + return sender.getPermissions(); + } + + @SuppressWarnings("deprecation") + @Override + public boolean hasPermission(String arg0) { + if (sender.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd.all")) { + return true; + } + if (sender.hasPermission(CommonsConst.PERMISSION_PREFIX + ".cmd." + arg0)) { + return true; + } + sender.sendMessage(BungeeMessages.VOCE_NAO_TEM_PERMISSãO_PARA_USAR_ESTE_COMANDO); + return false; + } + + @Override + public void removeGroups(String... arg0) { + sender.removeGroups(arg0); + } + + @Override + public void sendMessage(String arg0) { + sender.sendMessage(TextComponent.fromLegacyText(arg0)); + } + + @Override + public void sendMessage(BaseComponent... arg0) { + sender.sendMessage(arg0); + } + + @Override + public void sendMessage(BaseComponent arg0) { + sender.sendMessage(arg0); + } + + @SuppressWarnings("deprecation") + @Override + public void sendMessages(String... arg0) { + sender.sendMessages(arg0); + } + + @Override + public void setPermission(String arg0, boolean arg1) { + sender.setPermission(arg0, arg1); + } + + @Override + public UUID getUniqueId() { + return sender instanceof ProxiedPlayer ? ((ProxiedPlayer) sender).getUniqueId() : UUID.randomUUID(); + } + + public String getNick() { + if (sender instanceof ProxiedPlayer) { + return sender.getName(); + } + return "CONSOLE"; + } + + @SuppressWarnings("deprecation") + public boolean isPlayer() { + if (sender instanceof ProxiedPlayer) { + return true; + } + sender.sendMessage("§cComando disponível apenas para Jogadores."); + return false; + } + + public ProxiedPlayer getPlayer() { + return (ProxiedPlayer) sender; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.java new file mode 100644 index 0000000..1644f49 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.java @@ -0,0 +1,83 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.SQLException; +import java.util.List; + +public class AddPermCommand implements CommandClass { + + @Command(name = "addperm", groupsToUse = {Groups.ADMIN}, runAsync = true) + public void addperm(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 2) { + commandSender.sendMessage("§cUse: /addperm "); + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + final String permission = args[1].toLowerCase(); + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + String replace = BungeeMessages.PERMISSION_ADDED_FOR_PLAYER.replace("%permissao%", permission).replace("%nick%", nick); + if (target == null) { + DataHandler dataHandler = new DataHandler(nick, null); + + try { + dataHandler.load(DataCategory.ACCOUNT); + } catch (SQLException ex) { + commandSender.sendMessage("§cOcorreu um erro ao tentar carregar a conta do jogador."); + BungeeMain.console("Ocorreu um erro ao tentar carregar a conta de um jogador (AddPermCommand) -> " + ex.getLocalizedMessage()); + return; + } + + List playerPermissionsList = dataHandler.getData(DataType.PERMISSIONS).getList(); + + if (!playerPermissionsList.contains(permission)) { + playerPermissionsList.add(permission); + + dataHandler.saveCategory(DataCategory.ACCOUNT); + } + commandSender.sendMessage(replace); + } else { + BungeePlayer bungeePlayer = BungeeMain.getBungeePlayer(target.getName()); + + List playerPermissions = bungeePlayer.getData(DataType.PERMISSIONS).getList(); + + if (!playerPermissions.contains(permission)) { + playerPermissions.add(permission); + + bungeePlayer.getData(DataType.PERMISSIONS).setValue(playerPermissions); + + CPacketCustomAction PACKET = new CPacketCustomAction(target.getName(), target.getUniqueId()). + type(PacketType.BUNGEE_SEND_UPDATED_STATS).field("add-perm").fieldValue(permission); + + PACKET.getJson().addProperty("dataCategory-1", bungeePlayer.getDataHandler().buildJSON(DataCategory.ACCOUNT, true).toString()); + + Server.getInstance().sendPacket(target.getServer().getInfo().getName(), PACKET); + + } + commandSender.sendMessage(replace); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.java new file mode 100644 index 0000000..85c566a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; + +public class AlertCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "alert", aliases = {"aviso"}, groupsToUse = {Groups.ADMIN}) + public void alert(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage(BungeeMessages.ALERT); + return; + } + StringBuilder builder = new StringBuilder(); + + builder.append(BungeeMessages.ALERT_PREFIX); + + for (String s : args) { + builder.append(ChatColor.translateAlternateColorCodes('&', s)); + builder.append(" "); + } + + String message = builder.substring(0, builder.length() - 1); + ProxyServer.getInstance().broadcast(message); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.java new file mode 100644 index 0000000..f8ffebf --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.java @@ -0,0 +1,26 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Completer; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class BungeeCompleter implements CommandClass { + + @Completer(name = "ban", aliases = {"mute", "find", "kick", "premium", "setgroup", "group", "unmute", "report", "tempban", "go", "addcoins", "addxp", "addperm"}) + public List multiCompleter(ProxiedPlayer p, String label, String[] args) { + if(args.length < 1) return BungeeCord.getInstance().getPlayers().stream().map(CommandSender::getName).collect(Collectors.toList()); + if(args.length > 1) return Collections.emptyList(); + + return BungeeCord.getInstance().getPlayers() + .stream() + .map(CommandSender::getName) + .filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase())) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.java new file mode 100644 index 0000000..7694719 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.java @@ -0,0 +1,31 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; + +public class BungeeInfoCommand implements CommandClass { + + @Command(name = "bungeeinfo", groupsToUse = {Groups.ADMIN}) + public void bungeeinfo(BungeeCommandSender commandSender, String label, String[] args) { + long total = Runtime.getRuntime().totalMemory(); + long free = Runtime.getRuntime().freeMemory(); + long used = total - free; + double usedPercentage = (used * 100) / total; + + commandSender.sendMessage(""); + commandSender.sendMessage("§e§lBUNGEECORD - INFOS"); + commandSender.sendMessage(""); + commandSender.sendMessage("§7UUIDS no Cache -> §e" + CommonsGeneral.getUUIDFetcher().getCacheSize()); + commandSender.sendMessage(""); + commandSender.sendMessage("§e§lRAM"); + commandSender.sendMessage(" Memória total: §e" + total / 1048576L + " MB"); + commandSender.sendMessage(" Memória usada: §c" + (used / 1048576L) + " MB"); + commandSender.sendMessage(" Memória livre: §a" + (free / 1048576L) + " MB"); + commandSender.sendMessage(" Memória em uso: " + StringUtility.ramQuality(usedPercentage) + "%"); + commandSender.sendMessage(""); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.java new file mode 100644 index 0000000..65db783 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.java @@ -0,0 +1,40 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class ChampionCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "champions") + public void handlecommand(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) return; + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + if (!ProxyServer.getInstance().getServers().containsKey("Champions")) { + proxiedPlayer.sendMessage("§cO servidor não existe."); + return; + } + + if (proxiedPlayer.getServer().getInfo().getName().equalsIgnoreCase("Champions")) { + commandSender.sendMessage("§cVocê já está no servidor da Champions."); + return; + } + + GameServer server = CommonsGeneral.getServersManager().getHardcoreGamesServer("Champions", 1); + + if (!server.isOnline()) { + proxiedPlayer.sendMessage("§cO Quartel ainda não está liberado."); + } else { + proxiedPlayer.sendMessage(BungeeMessages.CONNECTING); + proxiedPlayer.connect(ProxyServer.getInstance().getServerInfo("Champions")); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.java new file mode 100644 index 0000000..4b1b1c8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.java @@ -0,0 +1,82 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.SQLException; +import java.util.concurrent.TimeUnit; + +public class ClearAccountCommand implements CommandClass { + + private final static String[] tablesToRemove = {"registros", "accounts", "hardcoregames", "kitpvp", "premium_map", + "accounts_to_delete", "cosmetics", "preferences"}; + + public static void clearAccount(final String nick) { + BungeeMain.runLater(() -> { + BungeeMain.runAsync(() -> { + for (String table : tablesToRemove) { + MySQLManager.deleteFromTable(table, "nick", nick); + } + }); + }, 1, TimeUnit.SECONDS); + + } + + @SuppressWarnings("deprecation") + @Command(name = "clearaccount", aliases = {"removeaccount"}, groupsToUse = {Groups.ADMIN}) + public void clearaccount(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 1) { + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage("§cEste jogador não possuí uma conta no servidor."); + return; + } + + DataHandler dataHandler = null; + + if (CommonsGeneral.getProfileManager().containsProfile(nick)) { + dataHandler = BungeeMain.getBungeePlayer(nick).getDataHandler(); + } else { + dataHandler = new DataHandler(nick, null); + + try { + dataHandler.load(DataCategory.ACCOUNT); + } catch (SQLException ex) { + dataHandler = null; + ex.printStackTrace(); + commandSender.sendMessage("§cOcorreu um erro ao tentar carregar a conta do jogador."); + } + } + + if (dataHandler == null) + return; + + CommonsGeneral.getProfileManager() + .removeGamingProfile(CommonsGeneral.getUUIDFetcher().getOfflineUUID(nick)); + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + if (target != null) { + target.disconnect("§4§lAVISO\n\n§fTodos os seus dados foram apagados do servidor."); + } + + BungeeMain.console(commandSender.getNick() + " deletou todos os dados do usuario: §7" + nick); + + commandSender.sendMessage("§aConta de §7'§a" + nick + "§7' apagada com sucesso!"); + + clearAccount(nick); + } else { + commandSender.sendMessage("§cUtilize: /clearaccount "); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.java new file mode 100644 index 0000000..50ef96c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.java @@ -0,0 +1,56 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.concurrent.TimeUnit; + +public class ConnectCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "connect", aliases = {"server", "play", "conectar"}) + public void server(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + if (args.length == 0) { + proxiedPlayer.sendMessage("§cUse: /connect "); + return; + } + + if (!proxiedPlayer.getServer().getInfo().getName().equalsIgnoreCase(args[0])) { + if (ProxyServer.getInstance().getServers().containsKey(args[0])) { + if (args[0].toLowerCase().equalsIgnoreCase("Login")) { + proxiedPlayer.sendMessage("§cVocê não pode se conectar no servidor de Login."); + return; + } + if (args[0].toLowerCase().equalsIgnoreCase("ScreenShare")) { + proxiedPlayer.sendMessage("§cVocê não pode se conectar no servidor de ScreenShare."); + return; + } + if (args[0].equalsIgnoreCase("evento")) { + proxiedPlayer.sendMessage("§cUtilize: /evento"); + return; + } + + proxiedPlayer.sendMessage(BungeeMessages.CONNECTING); + + BungeeMain.runLater(() -> { + proxiedPlayer.connect(ProxyServer.getInstance().getServerInfo(args[0])); + }, 333, TimeUnit.MILLISECONDS); + } else { + proxiedPlayer.sendMessage("§cO servidor não existe."); + } + } else { + proxiedPlayer.sendMessage(BungeeMessages.VOCE_JA_ESTA_NESTE_SERVIDOR); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.java new file mode 100644 index 0000000..e65fe15 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.java @@ -0,0 +1,45 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; + +import java.sql.SQLException; + +public class CreateAccountCommand implements CommandClass { + + @Command(name = "createaccount", aliases = {"createacc"}, groupsToUse = {Groups.ADMIN}, runAsync = true) + public void createaccount(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 1) { + + final String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + + if (!nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage("§cJá existe uma conta criada com este nick."); + return; + } + + try { + DataHandler dataHandler = new DataHandler(nick, CommonsGeneral.getUUIDFetcher().getUUID(nick)); + dataHandler.load(DataCategory.ACCOUNT); + + PremiumMapManager.load(nick); + } catch (UUIDFetcherException | SQLException ex) { + commandSender.sendMessage("§cOcorreu um erro ao tentar criar a conta, tente novamente."); + ex.printStackTrace(); + return; + } + + commandSender.sendMessage("§aConta criada com sucesso."); + } else { + commandSender.sendMessage("§cUtilize: /createaccount "); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.java new file mode 100644 index 0000000..bfb5609 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.java @@ -0,0 +1,82 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class EventoCommand implements CommandClass { + + public static boolean hasEvento = false; + + @SuppressWarnings("deprecation") + @Command(name = "evento") + public void evento(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + if (!hasEvento && !BungeeMain.getBungeePlayer(proxiedPlayer.getName()).isStaffer()) { + commandSender.sendMessage(BungeeMessages.EVENTO_OFFLINE); + return; + } + + if (proxiedPlayer.getServer().getInfo().getName().equalsIgnoreCase("evento")) { + commandSender.sendMessage("§cVocê já está no evento."); + return; + } + + if (ProxyServer.getInstance().getServers().containsKey("Evento")) { + proxiedPlayer.sendMessage(BungeeMessages.CONNECTING); + proxiedPlayer.connect(ProxyServer.getInstance().getServerInfo("Evento")); + } else { + proxiedPlayer.sendMessage("§cO servidor não existe."); + } + } + + @Command(name = "eventomanager", groupsToUse = {Groups.MOD_PLUS}) + public void eventomanager(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage(BungeeMessages.EVENTO_MANAGER_USAGE); + return; + } + if (args.length == 1) { + if (args[0].equalsIgnoreCase("on")) { + if (hasEvento) { + commandSender.sendMessage(BungeeMessages.EVENTO_MANAGER_ONLINE); + return; + } + hasEvento = true; + + commandSender.sendMessage(BungeeMessages.VOCE_LIBEROU_A_ENTRADA_NO_EVENTO); + + TextComponent message = new TextComponent(BungeeMessages.EVENTO_LIBERADO); + message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/evento")); + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§aClique para se conectar")})); + + BungeeCord.getInstance().broadcast(TextComponent.fromLegacyText("")); + BungeeCord.getInstance().broadcast(message); + BungeeCord.getInstance().broadcast(TextComponent.fromLegacyText("")); + } else if (args[0].equalsIgnoreCase("off")) { + if (!hasEvento) { + commandSender.sendMessage(BungeeMessages.EVENTO_MANAGER_OFFLINE); + return; + } + hasEvento = false; + commandSender.sendMessage(BungeeMessages.VOCE_LIBEROU_A_ENTRADA_APENAS_PARA_STAFFERS); + } else { + commandSender.sendMessage(BungeeMessages.EVENTO_MANAGER_USAGE); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.java new file mode 100644 index 0000000..6b4a326 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class FindCommand implements CommandClass { + + @Command(name = "find", aliases = {"procurar"}, groupsToUse = {Groups.PRIME}) + public void find(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage("§cUse: /find "); + return; + } + + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[0]); + + if ((player == null) || (player.getServer() == null)) { + commandSender.sendMessage(BungeeMessages.JOGADOR_OFFLINE); + } else { + commandSender.sendMessage(BungeeMessages.PLAYER_FINDED.replace("%servidor%", player.getServer().getInfo().getName())); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.java new file mode 100644 index 0000000..74ad57b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.java @@ -0,0 +1,70 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.Util; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GlobalListCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "globallist", aliases = {"glist", "gl"}, groupsToUse = {Groups.ADMIN}, runAsync = true) + public void glist(BungeeCommandSender commandSender, String label, String[] args) { + int crackeds = 0, + premiums = 0; + + commandSender.sendMessage(""); + + for (ServerInfo server : ProxyServer.getInstance().getServers().values()) { + List players = new ArrayList<>(); + + for (ProxiedPlayer player : server.getPlayers()) { + boolean premium = PremiumMapManager.getPremiumMap(player.getName()).isPremium(); + + if (premium) { + premiums++; + } else { + crackeds++; + } + + if (CommonsGeneral.getProfileManager().containsProfile(player.getName())) { + final BungeePlayer proxyPlayer = BungeeMain.getBungeePlayer(player.getName()); + + if (premium) { + players.add(proxyPlayer.getGroup().getColor() + player.getDisplayName()); + } else { + players.add(proxyPlayer.getGroup().getColor() + player.getDisplayName()); + } + + } else { + players.add("§7" + player.getDisplayName()); + } + } + + Collections.sort(players, String.CASE_INSENSITIVE_ORDER); + + commandSender.sendMessage("§6" + server.getName() + " [" + server.getPlayers().size() + "] " + + Util.format(players, ChatColor.RESET + ", ")); + } + + commandSender.sendMessage(""); + commandSender.sendMessage("§fNo momento há §a" + ProxyServer.getInstance().getPlayers().size() + " §fjogadores em toda rede!"); + commandSender.sendMessage(""); + commandSender.sendMessage("§fNo momento há §6" + premiums + " §fjogadores §6§lORIGINAIS §fonline."); + commandSender.sendMessage("§fNo momento há §c" + crackeds + " §fjogadores §c§lPIRATAS §fonline."); + commandSender.sendMessage(""); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.java new file mode 100644 index 0000000..2ede11b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.concurrent.TimeUnit; + +public class GoCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "go", aliases = {"ir"}, groupsToUse = {Groups.PRIME}) + public void go(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + if (args.length != 1) { + proxiedPlayer.sendMessage(BungeeMessages.COMMAND_GO_USAGE); + return; + } + + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[0]); + if ((player == null) || (player.getServer() == null)) { + proxiedPlayer.sendMessage(BungeeMessages.JOGADOR_OFFLINE); + } else { + proxiedPlayer.sendMessage(BungeeMessages.CONNECTING); + + if(proxiedPlayer.getServer().getInfo().getName().equals(player.getServer().getInfo().getName())) { + Server.getInstance().sendPacket(player.getServer().getInfo().getName(), new CPacketCustomAction(player.getName(), player.getUniqueId()) + .type(PacketType.BUKKIT_GO) + .field(proxiedPlayer.getName())); + } else { + proxiedPlayer.connect(ProxyServer.getInstance().getServerInfo(player.getServer().getInfo().getName()), (ignored, throwable) -> { + BungeeMain.runLater(() -> Server.getInstance().sendPacket(player.getServer().getInfo().getName(), new CPacketCustomAction(player.getName(), player.getUniqueId()) + .type(PacketType.BUKKIT_GO) + .field(proxiedPlayer.getName())), 333, TimeUnit.MILLISECONDS); + }); + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.java new file mode 100644 index 0000000..d334a50 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.java @@ -0,0 +1,136 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.permission.BungeePlayerPermissions; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.val; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.SQLException; + +public class GroupCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "group", aliases = {"groups", "setgroup", "groupset"}, groupsToUse = {Groups.ADMIN}, runAsync = true) + public void group(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length < 2) { + commandSender.sendMessage(BungeeMessages.COMMAND_GROUP_USAGE); + } else { + String playerNick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + + if (playerNick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + } else { + if (!Groups.existGrupo(args[1])) { + commandSender.sendMessage(BungeeMessages.GRUPO_INEXISTENTE); + return; + } + + Groups group = Groups.getGroup(args[1]); + if(commandSender.isPlayer()) { + val bp = BungeeMain.getBungeePlayer(commandSender.getPlayer().getName()); + if(group.getLevel() > bp.getGroup().getLevel()) { + commandSender.sendMessage(BungeeMessages.GRUPO_ALTO); + return; + } + } + + long tempo = 0L; + if (args.length > 2) { + try { + tempo = DateUtils.parseDateDiff(args[2], true); + } catch (Exception ex) { + commandSender.sendMessage(BungeeMessages.TEMPO_INVALIDO); + return; + } + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(playerNick); + DataHandler dataHandler; + + boolean sucess; + + if (target != null) { + dataHandler = CommonsGeneral.getProfileManager().getGamingProfile(target.getName()).getDataHandler(); + + dataHandler.set(DataType.GROUP, group.getName()); + dataHandler.set(DataType.GROUP_TIME, tempo); + dataHandler.set(DataType.GROUP_CHANGED_BY, commandSender.getNick()); + + CPacketCustomAction PACKET = new CPacketCustomAction(target.getName(), target.getUniqueId()). + type(PacketType.BUNGEE_SEND_UPDATED_STATS).field("group"); + + PACKET.getJson().addProperty("dataCategory-1", dataHandler.buildJSON(DataCategory.ACCOUNT, true).toString()); + Server.getInstance().sendPacket(target.getServer().getInfo().getName(), PACKET); + + target.sendMessage(BungeeMessages.VOCE_RECEBEU_UM_GRUPO. + replace("%cargo%", group.getColor() + group.getName().toUpperCase()).replace("%duração%", + (tempo == 0L ? "§aETERNA" : "de §a" + DateUtils.formatDifference(tempo)))); + + BungeePlayerPermissions.clearPermissions(target); + BungeePlayerPermissions.injectPermissions(target, group.getName()); + + dataHandler.saveCategory(DataCategory.ACCOUNT); + } else { + dataHandler = getDataHandlerByPlayer(playerNick); + if (dataHandler == null) { + commandSender.sendMessage("§cOcorreu um erro!"); + return; + } + + dataHandler.set(DataType.GROUP, group.getName()); + dataHandler.set(DataType.GROUP_TIME, tempo); + dataHandler.set(DataType.GROUP_CHANGED_BY, commandSender.getNick()); + + dataHandler.saveCategory(DataCategory.ACCOUNT); + sucess = true; + } + + String message = BungeeMessages.JOGADOR_TEVE_GRUPO_ATUALIZADO_PARA_STAFFER.replace("%nick%", playerNick). + replace("%setou%", commandSender.getName()).replace("%cargo%", group.getColor() + group.getName().toUpperCase()). + replace("%duração%", (tempo == 0L ? "§aETERNA" : "de §a" + DateUtils.formatDifference(tempo))); + + commandSender.sendMessage(BungeeMessages.VOCE_ATUALIZOU_O_CARGO. + replace("%cargo%", group.getColor() + group.getName().toUpperCase()). + replace("%nick%", playerNick)); + + BungeeMain.getManager().warnStaff(message, Groups.MEMBRO); + } + } + } + + private DataHandler getDataHandlerByPlayer(final String nick) { + DataHandler dataHandler = null; + + try { + dataHandler = new DataHandler(nick, CommonsGeneral.getUUIDFetcher().getUUID(nick)); + } catch (UUIDFetcherException e) { + e.printStackTrace(); + return null; + } + + try { + dataHandler.load(DataCategory.ACCOUNT); + } catch (SQLException ex) { + BungeeMain.console("§cOcorreu um erro ao tentar carregar a categoria 'ACCOUNT' de um jogador -> " + ex.getLocalizedMessage()); + dataHandler = null; + } + + return dataHandler; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.java new file mode 100644 index 0000000..ffa2b5a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.concurrent.TimeUnit; + +public class KickAllCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "kickall", aliases = {"kall"}, groupsToUse = {Groups.ADMIN}) + public void kickAll(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage("§cUtilize: /kickall "); + return; + } + + final String motivo = StringUtility.createArgs(0, args); + + commandSender.sendMessage(BungeeMessages.KICKING_ALL_PLAYERS); + + int delay = 500; + + for (ProxiedPlayer proxiedPlayer : ProxyServer.getInstance().getPlayers()) { + if (BungeeMain.isValid(proxiedPlayer)) { + if (BungeeMain.getBungeePlayer(proxiedPlayer.getName()).getGroup().getLevel() >= Groups.ADMIN + .getLevel()) { + continue; + } + } + + BungeeMain.runLater(() -> proxiedPlayer.disconnect(BungeeMessages.VOCE_FOI_EXPULSO.replace("%expulsou%", commandSender.getNick()) + .replace("%motivo%", motivo)), delay, TimeUnit.MILLISECONDS); + delay += 500; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.java new file mode 100644 index 0000000..6d3a9f8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.java @@ -0,0 +1,58 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class KickCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "kick", aliases = {"expulsar"}, groupsToUse = {Groups.PRIME}) + public void kick(BungeeCommandSender commandSender, String label, String[] args) { + String expulsou = commandSender.getNick(); + + if (args.length == 0) { + commandSender.sendMessage(BungeeMessages.KICK_USAGE); + return; + } + + String nick = args[0]; + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + if (target == null) { + commandSender.sendMessage(BungeeMessages.JOGADOR_OFFLINE); + return; + } + + boolean kick = true; + if (!expulsou.equalsIgnoreCase("CONSOLE")) { + if (BungeeMain.isValid(target)) { + BungeePlayer proxyPlayer = BungeeMain.getBungeePlayer(target.getName()), + proxyExpulsou = BungeeMain.getBungeePlayer(commandSender.getPlayer().getName()); + + if (proxyPlayer.getGroup().getLevel() > proxyExpulsou.getGroup().getLevel()) { + commandSender.sendMessage(BungeeMessages.DONT_KICK_PLAYER_ABOVE_YOU); + kick = false; + } + } + } + + if (!kick) { + return; + } + String motivo = "Não especificado"; + if (args.length >= 2) { + motivo = StringUtility.createArgs(1, args); + } + + commandSender.sendMessage(BungeeMessages.PLAYER_KICKED); + target.disconnect(BungeeMessages.VOCE_FOI_EXPULSO.replace("%expulsou%", expulsou).replace("%motivo%", motivo)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.java new file mode 100644 index 0000000..f6cfa28 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.java @@ -0,0 +1,55 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class LobbyCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "lobby", aliases = {"L", "hub"}) + public void lobby(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + String serverToConnect = "Lobby"; + + ServerType serverConnected = ServerType.getServer(proxiedPlayer.getServer().getInfo().getName().toLowerCase()); + + BungeeMain.console(proxiedPlayer.getName() + " executou o /lobby. ele esta no servidor: " + serverConnected.getName()); + + if (serverConnected != ServerType.UNKNOWN) { + if (serverConnected.isHardcoreGames()) { + BungeeMain.console(proxiedPlayer.getName() + " executou o /lobby. ele esta no HG!!!!"); + serverToConnect = "LobbyHardcoreGames"; + } + + if (serverConnected.isPvP()) { + serverToConnect = "LobbyPvP"; + } + } + + if (!CommonsGeneral.getServersManager().getNetworkServer(serverToConnect).isOnline()) { + BungeeMain.console(proxiedPlayer.getName() + " executou o /lobby. e o servidor em que ele ia se conectar esta offline. (" + serverToConnect + ")"); + serverToConnect = "Lobby"; + } + + if (serverConnected.getName().equalsIgnoreCase(serverToConnect)) { + proxiedPlayer.sendMessage(BungeeMessages.VOCE_JA_ESTA_NESTE_SERVIDOR); + return; + } + + proxiedPlayer.sendMessage(BungeeMessages.CONNECTING); + + proxiedPlayer.connect(ProxyServer.getInstance().getServerInfo(serverToConnect)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.java new file mode 100644 index 0000000..30cd451 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.java @@ -0,0 +1,105 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; + +public class MaintenanceCommand implements CommandClass { + + @Command(name = "maintenance", aliases = {"wg", "manu", "manutenção"}, groupsToUse = {Groups.ADMIN}, runAsync = true) + public void globalWhitelist(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage(""); + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("on")) { + changeGlobalWhite(commandSender, true); + } else if (args[0].equalsIgnoreCase("off")) { + changeGlobalWhite(commandSender, false); + } else if (args[0].equalsIgnoreCase("lista")) { + commandSender.sendMessage(""); + + String formated = StringUtility.formatArrayToString(BungeeMain.getManager().getWhitelistPlayers(), false); + + commandSender.sendMessage("§aJogadores na WhiteList: " + formated); + } else { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage(""); + } + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("add")) { + String nick = args[1]; + + if (BungeeMain.getManager().getWhitelistPlayers().contains(nick.toLowerCase())) { + commandSender.sendMessage("§cEste jogador ja está na WhiteList!"); + return; + } + + BungeeMain.getManager().getWhitelistPlayers().add(nick.toLowerCase()); + commandSender.sendMessage("§7" + nick + " §afoi adicionado na WhiteList!"); + + MySQLManager.updateStats("global_whitelist", "nicks", "identify", "default", + StringUtility.formatArrayToStringWithoutSpace(BungeeMain.getManager().getWhitelistPlayers(), true)); + } else if (args[0].equalsIgnoreCase("remove")) { + String nick = args[1]; + + if (!BungeeMain.getManager().getWhitelistPlayers().contains(nick.toLowerCase())) { + commandSender.sendMessage("§cEste jogador não está na WhiteList!"); + return; + } + BungeeMain.getManager().getWhitelistPlayers().remove(nick.toLowerCase()); + + commandSender.sendMessage("§7" + nick + " §afoi removido da WhiteList!"); + + MySQLManager.updateStats("global_whitelist", "nicks", "identify", "default", + StringUtility.formatArrayToStringWithoutSpace(BungeeMain.getManager().getWhitelistPlayers(), true)); + } else { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage("§cUtilize: /" + label + " "); + commandSender.sendMessage(""); + } + } + } + + private void changeGlobalWhite(BungeeCommandSender commandSender, boolean ativar) { + boolean ativada = BungeeMain.getManager().isGlobalWhitelist(); + + if (ativada) { + if (ativar) { + commandSender.sendMessage("§cA WhiteList global ja está ativada!"); + return; + } + + MySQLManager.updateStats("global_whitelist", "actived", "identify", "default", "false"); + + commandSender.sendMessage("§aWhiteList global desativada!"); + + BungeeMain.getManager().setGlobalWhitelist(false); + + BungeeMain.getManager().warnStaff("§aA WhiteList global foi desativada!", Groups.ADMIN); + } else { + if (!ativar) { + commandSender.sendMessage("§cA WhiteList global ja está desativada!"); + return; + } + + MySQLManager.updateStats("global_whitelist", "actived", "identify", "default", "true"); + + BungeeMain.getManager().setGlobalWhitelist(true); + + commandSender.sendMessage("§aWhiteList global ativada!"); + BungeeMain.getManager().warnStaff("§aA WhiteList global foi ativada!", Groups.ADMIN); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.java new file mode 100644 index 0000000..2327622 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.java @@ -0,0 +1,41 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; + +public class PremiumCommand implements CommandClass { + + @Command(name = "premium", aliases = {"checkpremium", "pmap", "premiummap"}, groupsToUse = {Groups.ADMIN}) + public void premium(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage(""); + commandSender.sendMessage("Total de PremiumMap: §a" + PremiumMapManager.getPremiumMaps()); + commandSender.sendMessage("Jogadores Piratas: §c" + PremiumMapManager.getCrackedAmount()); + commandSender.sendMessage("Jogadores Originais: §a" + PremiumMapManager.getPremiumAmount()); + commandSender.sendMessage(""); + return; + } + if (args.length == 1) { + String nick = args[0]; + + try { + PremiumMapManager.load(nick); + } catch (UUIDFetcherException ex) { + commandSender.sendMessage("§cOcorreu um erro ao obter a UUID do jogador."); + return; + } + + if (!PremiumMapManager.containsMap(nick)) { + commandSender.sendMessage("§cConta ainda não carregada..."); + return; + } + + commandSender.sendMessage("Jogador: " + + (PremiumMapManager.getPremiumMap(nick).isPremium() ? "§aOriginal" : "§cPirata")); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.java new file mode 100644 index 0000000..8abe993 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.java @@ -0,0 +1,558 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.clan.Clan; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.punishment.PunishmentHistoric; +import com.br.guilhermematthew.nowly.commons.common.punishment.PunishmentManager; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Ban; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Mute; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.Getter; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.jetbrains.annotations.NotNull; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.logging.Logger; + +public class PunishCommand implements CommandClass { + + public static void handleBan(ProxiedPlayer banned, String nick, String address, String motive, String baniu, + Long tempo, String clan, String data) { + + String message = BungeeMessages.JOGADOR_FOI_BANIDO_PARA_STAFFER.replace("%baniu%", baniu) + .replace("%nick%", nick).replace("%duração%", (tempo == 0L ? "PERMANENTEMENTE" : "TEMPORARIAMENTE")); + + BungeeMain.getManager().warnStaff(message, Groups.MEMBRO); + + Ban ban = new Ban(nick, address, baniu, motive, tempo); + ban.ban(); + + PunishmentManager.addCache(nick.toLowerCase(), ban); + + BungeeMain.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection + .prepareStatement("INSERT INTO accounts_to_delete_(nick, timestamp) VALUES (?, ?)"); + + insert.setString(1, nick); + insert.setString(2, String.valueOf(System.currentTimeMillis())); + + insert.close(); + insert = null; + + } catch (SQLException ex) { + CommonsGeneral.error("Ocorreu um erro ao tentar inserir um nick para ser deletado."); + } + + if (!clan.equalsIgnoreCase("Nenhum")) { + removePlayerFromClan(banned, nick, clan); + } + }); + } + + public static void handleKickBan(ProxiedPlayer target, String motivo, String baniu, String data) { + target.disconnect(TextComponent.fromLegacyText(BungeeMessages.VOCE_FOI_BANIDO.replace("%baniu%", baniu).replace("%motivo%", motivo) + .replace("%data%", data))); + } + + @SuppressWarnings("deprecation") + public static void handleMute(String nick, String motive, BungeeCommandSender commandSender, Long tempo) { + Mute mute = new Mute(nick, commandSender.getNick(), motive, tempo); + mute.mute(); + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + if (target != null) { + if (mute.isPermanent()) { + target.sendMessage(BungeeMessages.VOCE_FOI_MUTADO_PERMANENTEMENTE.replace("%motivo%", motive)); + } else { + target.sendMessage(BungeeMessages.VOCE_FOI_MUTADO_TEMPORARIAMENTE.replace("%motivo%", motive) + .replace("%duração%", DateUtils.formatDifference(tempo))); + } + + BungeeMain.getBungeePlayer(target.getName()).getPunishmentHistoric().getMuteHistory().add(mute); + } + + String message = BungeeMessages.JOGADOR_FOI_MUTADO_PARA_STAFFER.replace("%nick%", nick) + .replace("%mutou%", commandSender.getNick()).replace("%duração%", (tempo == 0L ? "PERMANENTEMENTE" : "TEMPORARIAMENTE")); + + BungeeMain.getManager().warnStaff(message, Groups.MEMBRO); + mute = null; + } + + @SuppressWarnings("deprecation") + public static void removePlayerFromClan(final ProxiedPlayer quit, final String playerNick, final String clanName) { + boolean removeClan = false, deleteClan = false; + + if (!ClanManager.hasClanData(clanName)) { + removeClan = true; + + ClanManager.load(clanName); + } + + Clan clan = ClanManager.getClan(clanName); + + if (clan != null) { + + if (clan.getMemberList().size() == 1) { + removeClan = true; + deleteClan = true; + } else { + clan.removePlayer(playerNick); + + if (clan.getOwner().equalsIgnoreCase(playerNick)) { + String newOwner = ""; + + if (clan.getAdminList().size() == 0) { + removeClan = true; + deleteClan = true; + + for (Object object : clan.getOnlines()) { + ProxiedPlayer onlines = (ProxiedPlayer) object; + onlines.sendMessage(BungeeMessages.CLAN_DESFEITO); + + BungeePlayer bungeePlayer = BungeeMain.getBungeePlayer(onlines.getName()); + bungeePlayer.set(DataType.CLAN, "Nenhum"); + bungeePlayer.setInClanChat(false); + + Server.getInstance().getServerGeneral().sendPacket(onlines.getServer().getInfo().getName(), + new CPacketCustomAction(onlines.getName(), onlines.getUniqueId()) + .type(PacketType.BUNGEE_SEND_PLAYER_ACTION).field("update-data") + .fieldValue("clan").extraValue("Nenhum")); + + onlines = null; + } + } else { + newOwner = clan.getAdminList().get(0); + + clan.setOwner(newOwner); + + for (Object object : clan.getOnlines()) { + ProxiedPlayer onlines = (ProxiedPlayer) object; + onlines.sendMessage(BungeeMessages.PLAYER_É_O_NOVO_DONO.replace("%nick%", newOwner)); + onlines = null; + } + } + } else { + for (Object object : clan.getOnlines()) { + ProxiedPlayer onlines = (ProxiedPlayer) object; + onlines.sendMessage(BungeeMessages.PLAYER_SAIU_DO_CLAN.replace("%nick%", playerNick)); + onlines = null; + } + + if (quit != null) { + clan.removeOnline(quit); + } + } + } + + clan = null; + } else { + CommonsGeneral.error("Erro ao remover um jogador de um clan. CLAN = NULO?"); + } + + if (removeClan) { + ClanManager.saveClan(clanName, true); + } + + final boolean finalClan = deleteClan; + BungeeMain.runAsync(() -> { + MySQLManager.executeUpdate( + "UPDATE accounts SET data = JSON_SET(data, '$.clan', 'Nenhum') where nick='" + playerNick + "'"); + if (finalClan) { + MySQLManager.deleteFromTable("clans", "nome", clanName); + } + }); + } + + @Command(name = "unmute", aliases = {"desmutar"}, groupsToUse = {Groups.MOD_PLUS}, runAsync = true) + public void unmute(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage(BungeeMessages.UNMUTE); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); + + if (target != null) { + BungeePlayer bungeePlayer = BungeeMain.getBungeePlayer(target.getName()); + + if (bungeePlayer != null) { + if (bungeePlayer.getPunishmentHistoric().getActualMute() == null) { + commandSender.sendMessage(BungeeMessages.CONTA_NAO_ESTA_MUTADA); + return; + } + + if (!bungeePlayer.getPunishmentHistoric().getActualMute().isPunished()) { + commandSender.sendMessage(BungeeMessages.CONTA_NAO_ESTA_MUTADA); + return; + } + + bungeePlayer.getPunishmentHistoric().getActualMute().unmute(commandSender.getNick()); + + commandSender.sendMessage(BungeeMessages.CONTA_DESMUTADA); + + bungeePlayer = null; + } + + target = null; + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + PunishmentHistoric punishHistoric = new PunishmentHistoric(nick); + + try { + punishHistoric.loadMutes(); + } catch (Exception ex) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + BungeeMain.console( + "§cOcorreu um erro ao tentar carregar um punimento (Unmute) -> " + ex.getLocalizedMessage()); + return; + } + + Mute mute = punishHistoric.getActualMute(); + + if (mute == null) { + commandSender.sendMessage(BungeeMessages.CONTA_NAO_ESTA_MUTADA); + } else { + if (mute.isPunished()) { + + mute.unmute(commandSender.getNick()); + + commandSender.sendMessage(BungeeMessages.CONTA_DESMUTADA); + punishHistoric = null; + } + } + } + + @Command(name = "unban", aliases = {"desbanir"}, groupsToUse = {Groups.MOD_PLUS}, runAsync = true) + public void unban(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage(BungeeMessages.UNBAN); + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + DataHandler dataHandler = getDataHandlerByPlayer(null, nick); + + if (dataHandler == null) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + return; + } + + Ban ban = PunishmentManager.getBanCache(nick); + + if (ban == null) { + PunishmentHistoric punishHistoric = getPunishmentHistoric(nick, dataHandler); + + try { + punishHistoric.loadBans(); + } catch (Exception ex) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + BungeeMain.console( + "§cOcorreu um erro ao tentar carregar um punimento (Unban) -> " + ex.getLocalizedMessage()); + return; + } finally { + ban = punishHistoric.getActualBan(); + } + } + + if (ban != null && !ban.isPunished()) { + commandSender.sendMessage(BungeeMessages.CONTA_NAO_ESTA_BANIDA); + return; + } + + if (ban != null) { + ban.unban(commandSender.getNick()); + PunishmentManager.removeCache(nick); + } + + commandSender.sendMessage(BungeeMessages.CONTA_DESBANIDA); + + BungeeMain.getManager().warnStaff(BungeeMessages.JOGADOR_FOI_DESBANIDO_PARA_STAFFER + .replace("%nick%", nick).replace("%staffer%", commandSender.getNick()), + Groups.MEMBRO); + + dataHandler = null; + } + + @Command(name = "mute", aliases = {"mutar"}, groupsToUse = {Groups.PRIME}, runAsync = true) + public void mute(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length < 2) { + commandSender.sendMessage(BungeeMessages.MUTE); + return; + } + + if (!MySQLManager.contains("accounts", "nick", args[0])) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); + + boolean continuar = continueProcess(commandSender, target); + if (!continuar) { + commandSender.sendMessage(BungeeMessages.DONT_MUTE_ABOVE_YOU); + return; + } + + handleMute(args[0], StringUtility.createArgs(1, args), commandSender, 0L); + commandSender.sendMessage(BungeeMessages.JOGADOR_MUTADO_PERMANENTEMENTE); + } + + @Command(name = "tempmute", groupsToUse = {Groups.PRIME}, runAsync = true) + public void tempmute(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length < 3) { + commandSender.sendMessage(BungeeMessages.TEMPMUTE); + return; + } + + if (!MySQLManager.contains("accounts", "nick", args[0])) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); + + boolean continuar = continueProcess(commandSender, target); + if (!continuar) { + commandSender.sendMessage(BungeeMessages.DONT_MUTE_ABOVE_YOU); + return; + } + + long tempo = 0; + try { + tempo = DateUtils.parseDateDiff(args[1], true); + } catch (Exception ex) { + commandSender.sendMessage(BungeeMessages.TEMPO_INVALIDO); + return; + } + + handleMute(args[0], StringUtility.createArgs(2, args), commandSender, tempo); + commandSender.sendMessage( + BungeeMessages.JOGADOR_MUTADO_TEMPORARIAMENTE); + } + + @SuppressWarnings("deprecation") + @Command(name = "tempban", groupsToUse = {Groups.MOD}, runAsync = true) + public void tempban(BungeeCommandSender commandSender, String label, String[] args) { + String baniu = commandSender.getNick(); + + if (args.length < 3) { + commandSender.sendMessage(BungeeMessages.TEMPBAN); + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + DataHandler dataHandler = getDataHandlerByPlayer(target, nick); + + if (dataHandler == null) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + return; + } + + String lastAddress = dataHandler.getString(DataType.LAST_IP), clan = dataHandler.getString(DataType.CLAN); + + int codeBan = isBanned(nick, lastAddress); + if (codeBan == -1) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + return; + } + + if (codeBan == 1) { + commandSender.sendMessage(BungeeMessages.JOGADOR_JA_BANIDO); + return; + } + + String motivo = StringUtility.createArgs(2, args); + + boolean continuar = continueProcess(commandSender, target); + if (!continuar) { + commandSender.sendMessage(BungeeMessages.DONT_BAN_PLAYER_ABOVE_YOU); + return; + } + + long tempo; + try { + tempo = DateUtils.parseDateDiff(args[1], true); + } catch (Exception ex) { + commandSender.sendMessage(BungeeMessages.TEMPO_INVALIDO); + return; + } + + commandSender.sendMessage( + BungeeMessages.JOGADOR_BANIDO_TEMPORARIAMENTE.replace("%duração%", DateUtils.formatDifference(tempo))); + + final String data = DateUtils.getActualDate(false); + handleBan(target, nick, lastAddress, motivo, baniu, tempo, clan, data); + + ProxyServer.getInstance().broadcast(BungeeMessages.JOGADOR_FOI_BANIDO_TEMPORARIAMENTE.replace("%nick%", nick)); + + if (target != null) handleKickBan(target, motivo, baniu, data); + } + + @SuppressWarnings("deprecation") + @Command(name = "ban", groupsToUse = {Groups.MOD}, runAsync = true) + public void ban(BungeeCommandSender commandSender, String label, String[] args) { + String baniu = commandSender.getNick(); + + if (args.length < 2) { + commandSender.sendMessage(BungeeMessages.BAN); + return; + } + + String nick = MySQLManager.getString("accounts", "nick", args[0], "nick"); + if (nick.equalsIgnoreCase("N/A")) { + commandSender.sendMessage(BungeeMessages.NAO_TEM_CONTA); + return; + } + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + + DataHandler dataHandler = getDataHandlerByPlayer(target, nick); + + if (dataHandler == null) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + return; + } + + String lastAddress = dataHandler.getString(DataType.LAST_IP), clan = dataHandler.getString(DataType.CLAN); + + int codeBan = isBanned(nick, lastAddress); + if (codeBan == -1) { + commandSender.sendMessage("§cOcorreu um erro, tente novamente."); + return; + } + + if (codeBan == 1) { + commandSender.sendMessage(BungeeMessages.JOGADOR_JA_BANIDO); + return; + } + + String motivo = StringUtility.createArgs(1, args); + + boolean continuar = continueProcess(commandSender, target); + if (!continuar) { + commandSender.sendMessage(BungeeMessages.DONT_BAN_PLAYER_ABOVE_YOU); + return; + } + + commandSender.sendMessage(BungeeMessages.JOGADOR_BANIDO_PERMANENTEMENTE); + + final String data = DateUtils.getActualDate(false); + handleBan(target, nick, lastAddress, motivo, baniu, 0L, clan, data); + + ProxyServer.getInstance().broadcast(BungeeMessages.JOGADOR_FOI_BANIDO_PERMANENTEMENTE.replace("%nick%", nick)); + + if (target != null) handleKickBan(target, motivo, baniu, data); + } + + private int isBanned(final String nick, final String lastAddress) { + PunishmentHistoric punish = new PunishmentHistoric(nick, lastAddress); + + try { + punish.loadBans(); + } catch (Exception ex) { + return -1; + } + + if (punish.getActualBan() == null) + return 0; + + return punish.getActualBan().isPunished() ? 1 : 0; + } + + private boolean continueProcess(final BungeeCommandSender commandSender, final ProxiedPlayer target) { + if (commandSender.getNick().equalsIgnoreCase("CONSOLE")) + return true; + if (!BungeeMain.isValid(target)) + return true; + + final BungeePlayer proxyPlayer = BungeeMain.getBungeePlayer(target.getName()), + proxyExpulsou = BungeeMain.getBungeePlayer(commandSender.getNick()); + + return proxyPlayer.getGroup().getLevel() <= proxyExpulsou.getGroup().getLevel(); + } + + private DataHandler getDataHandlerByPlayer(final ProxiedPlayer target, final String nick) { + DataHandler dataHandler = null; + + if (BungeeMain.isValid(target)) { + dataHandler = BungeeMain.getBungeePlayer(target.getName()).getDataHandler(); + } else { + try { + dataHandler = new DataHandler(nick, CommonsGeneral.getUUIDFetcher().getUUID(nick)); + } catch (UUIDFetcherException e) { + e.printStackTrace(); + return null; + } + + try { + dataHandler.load(DataCategory.ACCOUNT); + } catch (SQLException ex) { + BungeeMain.console("§cOcorreu um erro ao tentar carregar a categoria 'ACCOUNT' de um jogador -> " + + ex.getLocalizedMessage()); + dataHandler = null; + } + } + return dataHandler; + } + + private PunishmentHistoric getPunishmentHistoric(String nick, DataHandler dataHandler) { + PunishmentHistoric punishmentHistoric = null; + + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(nick); + if (BungeeMain.isValid(target)) { + punishmentHistoric = BungeeMain.getBungeePlayer(nick).getPunishmentHistoric(); + } else { + punishmentHistoric = new PunishmentHistoric(nick, dataHandler.getString(DataType.LAST_IP)); + } + + + return punishmentHistoric; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.java new file mode 100644 index 0000000..749dff5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.java @@ -0,0 +1,97 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import lombok.val; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class ReportCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "report", aliases = {"reportar", "rp"}) + public void execute(BungeeCommandSender commandSender, String ignored, String[] args) { + if (!commandSender.isPlayer()) return; + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + if (args.length < 1) { + proxiedPlayer.sendMessage(BungeeMessages.COMMAND_REPORT_USAGE); + return; + } + + if(args[0].equalsIgnoreCase("toggle") && proxiedPlayer.hasPermission(CommonsConst.PERMISSION_PREFIX + ".receivereport")) { + val bp = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + if(bp.getBoolean(DataType.RECEIVE_REPORTS)) { + bp.set(DataType.RECEIVE_REPORTS, false); + proxiedPlayer.sendMessage(BungeeMessages.REPORT_DISABLED); + } else { + bp.set(DataType.RECEIVE_REPORTS, true); + proxiedPlayer.sendMessage(BungeeMessages.REPORT_ENABLED); + } + + BungeeMain.runAsync(() -> bp.getDataHandler().saveCategory(DataCategory.PREFERENCES)); + return; + } + + if (args.length < 2) { + proxiedPlayer.sendMessage(BungeeMessages.COMMAND_REPORT_USAGE); + return; + } + + BungeePlayer proxyPlayer = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + if (!proxyPlayer.podeReportar()) { + proxiedPlayer.sendMessage(BungeeMessages.AGUARDE_PARA_REPORTAR_NOVAMENTE); + return; + } + + ProxiedPlayer reportado = ProxyServer.getInstance().getPlayer(args[0]); + + if ((reportado == null) || (reportado.getServer() == null)) { + proxiedPlayer.sendMessage(BungeeMessages.JOGADOR_OFFLINE); + return; + } + + if (reportado == proxiedPlayer) { + proxiedPlayer.sendMessage(BungeeMessages.VOCE_NAO_PODE_SE_REPORTAR); + return; + } + + proxiedPlayer.sendMessage(BungeeMessages.JOGADOR_REPORTADO_COM_SUCESSO); + proxyPlayer.setLastReport(System.currentTimeMillis()); + + notifyStaffers(proxiedPlayer.getName(), reportado.getName(), StringUtility.createArgs(1, args)); + } + + private void notifyStaffers(String from, String target, String cause) { + val components = TextComponent.fromLegacyText(BungeeMessages.NEW_REPORT + .replace("%from%", from) + .replace("%target%", target) + .replace("%cause%", cause)); + + for (val component : components) { + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/go " + target)); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClique para ver a lista de reports"))); + } + + ProxyServer.getInstance().getPlayers() + .stream() + .filter(pp -> pp.hasPermission(CommonsConst.PERMISSION_PREFIX + ".receivereport") + && BungeeMain.isValid(pp) + && BungeeMain.getBungeePlayer(pp.getName()).getBoolean(DataType.RECEIVE_REPORTS)) + .forEach(pp -> pp.sendMessage(components)); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.java new file mode 100644 index 0000000..b277e3a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.java @@ -0,0 +1,123 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.concurrent.TimeUnit; + +public class SendCommand implements CommandClass { + + @Command(name = "send", aliases = {"enviar"}, groupsToUse = {Groups.ADMIN}, runAsync = true) + public void send(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 2) { + commandSender.sendMessage(BungeeMessages.COMMAND_SEND_USAGE); + return; + } + ServerInfo target = ProxyServer.getInstance().getServerInfo(args[1]); + if (target == null) { + commandSender.sendMessage(BungeeMessages.SERVER_NOT_EXIST); + return; + } + if (target.getName().equalsIgnoreCase("Login")) { + commandSender.sendMessage(BungeeMessages.VOCE_NAO_PODE_ENVIAR_PARA_ESTE_SERVIDOR); + return; + } + if (ProxyServer.getInstance().getServerInfo(args[0]) != null) { + if ((args[0].equalsIgnoreCase("Login")) || (args[0].equalsIgnoreCase("ScreenShare"))) { + commandSender.sendMessage(BungeeMessages.VOCE_NAO_PODE_PUXAR_DESTE_SERVIDOR); + return; + } + ServerInfo from = ProxyServer.getInstance().getServerInfo(args[0]); + + commandSender.sendMessage(BungeeMessages.TRYING_SEND_SERVER_TO_SERVER.replace("%servidor%", from.getName()) + .replace("%destino%", target.getName())); + + int delay = 0; + + for (ProxiedPlayer inServer : from.getPlayers()) { + BungeeMain.runLater(() -> { + enviar(inServer, target); + }, delay, TimeUnit.MILLISECONDS); + delay += 333; + } + return; + } + if (args[0].equalsIgnoreCase("local")) { + if (commandSender.getNick().equalsIgnoreCase("CONSOLE")) { + commandSender.sendMessage("§cVocê não está em um servidor."); + return; + } + ProxiedPlayer p = (ProxiedPlayer) commandSender; + + commandSender + .sendMessage(BungeeMessages.TRING_SEND_LOCAL_FOR_SERVER.replace("%destino%", target.getName())); + + int delay = 0; + + for (ProxiedPlayer inLocal : p.getServer().getInfo().getPlayers()) { + BungeeMain.runLater(() -> { + enviar(inLocal, target); + }, delay, TimeUnit.MILLISECONDS); + delay += 333; + } + } else if (args[0].equalsIgnoreCase("todos") || (args[0].equalsIgnoreCase("*"))) { + commandSender.sendMessage(BungeeMessages.TRYING_SEND_ALL_FOR_SERVER.replace("%destino%", target.getName())); + + int delay = 0; + + for (ProxiedPlayer p1 : ProxyServer.getInstance().getPlayers()) { + if (p1.getServer().getInfo().getName().equalsIgnoreCase("Login")) { + continue; + } + if (p1.getServer().getInfo().getName().equalsIgnoreCase("ScreenShare")) { + continue; + } + + BungeeMain.runLater(() -> { + enviar(p1, target); + }, delay, TimeUnit.MILLISECONDS); + delay += 333; + } + } else { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[0]); + if (player == null) { + commandSender.sendMessage(BungeeMessages.JOGADOR_OFFLINE); + return; + } + + commandSender.sendMessage(BungeeMessages.TRYING_SEND_PLAYER_FOR_SERVER.replace("%nick%", player.getName()) + .replace("%destino%", target.getName())); + + BungeeMain.runLater(() -> { + enviar(player, target); + }, 333, TimeUnit.MILLISECONDS); + } + } + + @SuppressWarnings("deprecation") + private void enviar(ProxiedPlayer player, ServerInfo target) { + if ((player.getServer() != null) && (!player.getServer().getInfo().getName().equals("login")) + && (!player.getServer().getInfo().getName().equalsIgnoreCase("screenshare")) + && (!player.getServer().getInfo().equals(target))) { + player.connect(target); + player.sendMessage(BungeeMessages.SENDED_FOR_OTHER_SERVER); + } + } + + /** + * + * + * BungeeClient.sendPacketToServer(player, new + * PacketRequirePlayerData(player.getName(), player.getUniqueId().toString(), + * Core.getUuidFetcher().getOfflineUUID(player.getName()).toString(), false)); + * + * + */ +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.java new file mode 100644 index 0000000..e69a851 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.java @@ -0,0 +1,81 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.List; + +public class ServersInfoCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "serverInfo", aliases = {"si", "svinfo", "server"}, groupsToUse = {Groups.ADMIN}) + public void serverInfo(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage("§cUtilize: /serverinfo list"); + return; + } + + if (args[0].equalsIgnoreCase("list")) { + if (!commandSender.isPlayer()) + return; + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + proxiedPlayer.sendMessage(""); + + List networks = new ArrayList<>(CommonsGeneral.getServersManager().getServers()); + + for (NetworkServer networkServer : networks) { + if (networkServer.getServerId() != 1) + continue; + + TextComponent component = new TextComponent("§e[" + + networkServer.getServerType().getName().toUpperCase() + networkServer.getServerId() + "]"); + + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + (new ComponentBuilder("Online: " + (networkServer.isOnline() ? "§aSim" : "§cNão") + "\n" + + "Onlines: §7" + networkServer.getOnlines() + "/" + networkServer.getMaxPlayers())) + .create())); + + proxiedPlayer.sendMessage(component); + } + + for (NetworkServer networkServer : networks) { + if (!(networkServer instanceof GameServer)) + continue; + + if (networkServer.getServerType() != ServerType.HARDCORE_GAMES) + continue; + + GameServer hardcoreGamesServer = (GameServer) networkServer; + + TextComponent component = new TextComponent("§e[HG" + hardcoreGamesServer.getServerId() + "]"); + + component + .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + (new ComponentBuilder("Online: " + (hardcoreGamesServer.isOnline() ? "§aSim" : "§cNão") + + "\n" + "Onlines: §7" + hardcoreGamesServer.getOnlines() + "/" + + hardcoreGamesServer.getMaxPlayers() + "\n" + "Jogadores: §7" + + hardcoreGamesServer.getPlayersGaming() + "\n" + "Tempo: §7" + + DateUtils.formatSeconds(hardcoreGamesServer.getTempo()) + "\n" + "Estágio: §7" + + hardcoreGamesServer.getStage().getNome())).create())); + + proxiedPlayer.sendMessage(component); + } + + proxiedPlayer.sendMessage(""); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.java new file mode 100644 index 0000000..ad92322 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.java @@ -0,0 +1,84 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; + +public class ServiceCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "addserver", aliases = {"ds", "dsv"}, groupsToUse = {Groups.ADMIN}) + public void serverInfo(BungeeCommandSender commandSender, String label, String[] args) { + if (args.length == 2) { + if (args[0].equalsIgnoreCase("remove")) { + String serverName = args[1]; + + if (ProxyServer.getInstance().getServers().containsKey(serverName)) { + ServerInfo info = ProxyServer.getInstance().getServerInfo(serverName); + if (info != null) { + if (info.getPlayers().size() == 0) { + commandSender.sendMessage("§a[DynamicServers] §f" + info.getName() + " §afoi removido. (§f" + info.getAddress().getAddress().getHostAddress() + ":" + info.getAddress().getPort() + ")"); + + ProxyServer.getInstance().getServers().remove(info.getName()); + } else { + commandSender.sendMessage("§cNão é possivel remover um servidor com jogadores online."); + } + info = null; + } else { + commandSender.sendMessage("§cNão foi possível obter as informaçőes deste servidor."); + } + } else { + commandSender.sendMessage("§cEste servidor não está registrado."); + } + + serverName = null; + } else { + sendHelp(commandSender); + } + } else if (args.length == 4) { + if (args[0].equalsIgnoreCase("create")) { + String serverName = args[1]; + + if (!ProxyServer.getInstance().getServers().containsKey(serverName)) { + String address = args[2]; + String portString = args[3]; + + if (address.length() > 7) { + if (StringUtility.isInteger(portString)) { + int port = Integer.parseInt(portString); + + if (BungeeMain.registerServer(serverName, address, port)) { + commandSender.sendMessage("§a[DynamicServers] §f" + serverName + " §afoi registrado. (§f" + address + ":" + port + ")"); + } else { + commandSender.sendMessage("§cOcorreu um erro ao tentar registrar o servidor."); + } + } else { + commandSender.sendMessage("§cPorta invalida."); + } + } else { + commandSender.sendMessage("§cEndereço invalida."); + } + address = null; + portString = null; + } else { + commandSender.sendMessage("§cEste servidor já está registrado."); + } + serverName = null; + } else { + sendHelp(commandSender); + } + } else { + sendHelp(commandSender); + } + } + + private void sendHelp(BungeeCommandSender commandSender) { + commandSender.sendMessage("§cUtilize: /dynamicservers create
"); + commandSender.sendMessage("§cUtilize: /dynamicservers remove "); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.java new file mode 100644 index 0000000..17faa2a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.java @@ -0,0 +1,70 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class StaffChatCommand implements CommandClass { + + @SuppressWarnings("deprecation") + @Command(name = "staffchat", aliases = {"sc"}, groupsToUse = {Groups.PRIME}) + public void staffchat(BungeeCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + ProxiedPlayer proxiedPlayer = commandSender.getPlayer(); + + BungeePlayer proxyPlayer = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + if (args.length == 1) { + if (args[0].equalsIgnoreCase("on")) { + if (proxyPlayer.getBoolean(DataType.RECEIVE_STAFFCHAT_MESSAGES)) { + proxiedPlayer.sendMessage(BungeeMessages.STAFFCHAT_JA_ESTA_ATIVADO); + return; + } + proxyPlayer.set(DataType.RECEIVE_STAFFCHAT_MESSAGES, true); + + BungeeMain.runAsync(() -> { + proxyPlayer.getDataHandler().saveCategory(DataCategory.PREFERENCES); + }); + + proxiedPlayer.sendMessage(BungeeMessages.VOCE_ATIVOU_O_STAFFCHAT); + } else if (args[0].equalsIgnoreCase("off")) { + if (!proxyPlayer.getBoolean(DataType.RECEIVE_STAFFCHAT_MESSAGES)) { + proxiedPlayer.sendMessage(BungeeMessages.STAFFCHAT_JA_ESTA_DESATIVADO); + return; + } + + proxyPlayer.set(DataType.RECEIVE_STAFFCHAT_MESSAGES, false); + + BungeeMain.runAsync(() -> { + proxyPlayer.getDataHandler().saveCategory(DataCategory.PREFERENCES); + }); + + proxiedPlayer.sendMessage(BungeeMessages.VOCE_DESATIVOU_O_STAFFCHAT); + } else { + proxiedPlayer.sendMessage(""); + proxiedPlayer.sendMessage("§cUse: /staffchat"); + proxiedPlayer.sendMessage("§cUse: /staffchat "); + proxiedPlayer.sendMessage(""); + } + return; + } + + if (proxyPlayer.isInStaffChat()) { + proxyPlayer.setInStaffChat(false); + proxiedPlayer.sendMessage(BungeeMessages.VOCE_SAIU_DO_STAFFCHAT); + } else { + proxyPlayer.setInStaffChat(true); + proxiedPlayer.sendMessage(BungeeMessages.VOCE_ENTROU_NO_STAFFCHAT); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.java new file mode 100644 index 0000000..0fc4d90 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.java @@ -0,0 +1,47 @@ +package com.br.guilhermematthew.nowly.commons.bungee.commands.register; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.commands.BungeeCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import lombok.val; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class StaffListCommand implements CommandClass { + + @Command(name = "stafflist", aliases = {"staff", "sl", "slist"}, groupsToUse = {Groups.PRIME}) + public void stafflist(BungeeCommandSender commandSender, String label, String[] args) { + commandSender.sendMessage(""); + commandSender.sendMessage(BungeeMessages.STAFFLIST_PREFIX); + commandSender.sendMessage(""); + + for (ProxiedPlayer proxiedPlayer : ProxyServer.getInstance().getPlayers()) { + if (!BungeeMain.isValid(proxiedPlayer)) continue; + + if (proxiedPlayer.hasPermission(CommonsConst.PERMISSION_PREFIX + ".staff")) { + val bungeePlayer = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + val tag = bungeePlayer.getGroup().getTag(); + + val components = TextComponent.fromLegacyText(BungeeMessages.STAFFLIST_PLAYER.replace("%nick%", tag.getColor() + "§l" + tag.getPrefix() + "§f " + tag.getColor() + + proxiedPlayer.getName()).replace("%servidor%", proxiedPlayer.getServer().getInfo().getName())); + + for (BaseComponent message : components) { + message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/connect " + proxiedPlayer.getServer().getInfo().getName().toLowerCase())); + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent("§aClique para conectar")})); + } + + commandSender.sendMessage(components); + } + } + + commandSender.sendMessage(""); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.java new file mode 100644 index 0000000..6b6445d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.java @@ -0,0 +1,26 @@ +package com.br.guilhermematthew.nowly.commons.bungee.events; + +import net.md_5.bungee.api.plugin.Event; + +public class BungeeUpdateEvent extends Event { + + private final BungeeUpdateType type; + private final long seconds; + + public BungeeUpdateEvent(BungeeUpdateType type, long seconds) { + this.type = type; + this.seconds = seconds; + } + + public BungeeUpdateType getType() { + return type; + } + + public long getSeconds() { + return seconds; + } + + public enum BungeeUpdateType { + SEGUNDO, MINUTO, HORA + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.java new file mode 100644 index 0000000..c374a8d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.java @@ -0,0 +1,208 @@ +package com.br.guilhermematthew.nowly.commons.bungee.events; + +public enum MotdCentralizer { + + A('A', 5), + a('a', 5), + B('B', 5), + b('b', 5), + C('C', 5), + c('c', 5), + D('D', 5), + d('d', 5), + E('E', 5), + e('e', 5), + F('F', 5), + f('f', 4), + G('G', 5), + g('g', 5), + H('H', 5), + h('h', 5), + I('I', 3), + i('i', 1), + J('J', 5), + j('j', 5), + K('K', 5), + k('k', 4), + L('L', 5), + l('l', 1), + M('M', 5), + m('m', 5), + N('N', 5), + n('n', 5), + O('O', 5), + o('o', 5), + P('P', 5), + p('p', 5), + Q('Q', 5), + q('q', 5), + R('R', 5), + r('r', 5), + S('S', 5), + s('s', 5), + T('T', 5), + t('t', 4), + U('U', 5), + u('u', 5), + V('V', 5), + v('v', 5), + W('W', 5), + w('w', 5), + X('X', 5), + x('x', 5), + Y('Y', 5), + y('y', 5), + Z('Z', 5), + z('z', 5), + NUM_1('1', 5), + NUM_2('2', 5), + NUM_3('3', 5), + NUM_4('4', 5), + NUM_5('5', 5), + NUM_6('6', 5), + NUM_7('7', 5), + NUM_8('8', 5), + NUM_9('9', 5), + NUM_0('0', 5), + EXCLAMATION_POINT('!', 1), + AT_SYMBOL('@', 6), + NUM_SIGN('#', 5), + DOLLAR_SIGN('$', 5), + PERCENT('%', 5), + UP_ARROW('^', 5), + AMPERSAND('&', 5), + ASTERISK('*', 5), + LEFT_PARENTHESIS('(', 4), + RIGHT_PERENTHESIS(')', 4), + MINUS('-', 5), + UNDERSCORE('_', 5), + PLUS_SIGN('+', 5), + EQUALS_SIGN('=', 5), + LEFT_CURL_BRACE('{', 4), + RIGHT_CURL_BRACE('}', 4), + LEFT_BRACKET('[', 3), + RIGHT_BRACKET(']', 3), + COLON(':', 1), + SEMI_COLON(';', 1), + DOUBLE_QUOTE('"', 3), + SINGLE_QUOTE('\'', 1), + LEFT_ARROW('<', 4), + RIGHT_ARROW('>', 4), + QUESTION_MARK('?', 5), + SLASH('/', 5), + BACK_SLASH('\\', 5), + LINE('|', 1), + TILDE('~', 5), + TICK('`', 2), + PERIOD('.', 1), + COMMA(',', 1), + SPACE(' ', 3), + DEFAULT('a', 4), + COLORCODE('§', 0); + + private char character; + private int length; + + private final static int CENTER_MOTD_PX = 132; + + private final static int CENTER_CHAT_PX = 154; + + private MotdCentralizer(char character, int length) { + this.character = character; + this.length = length; + } + + public char getCharacter(){ + return this.character; + } + + public int getLength(){ + return this.length; + } + + public int getBoldLength() { + if(this == SPACE) { + return this.getLength(); + } + return this.length + 1; + } + + public static MotdCentralizer getDefaultFontInfo(char c){ + for(MotdCentralizer dFI : values()){ + if(dFI.getCharacter() == c) { + return dFI; + } + } + return DEFAULT; + } + + public static String makeCenteredMotd(String message) { + int messagePxSize = 0; + boolean previousCode = false; + boolean isBold = false; + char[] arrayOfChar; + int i = (arrayOfChar = message.toCharArray()).length; + for (int j = 0; j < i; j++) { + char c = arrayOfChar[j]; + if (c == '§') { + previousCode = true; + } else if (previousCode) { + previousCode = false; + if ((c == 'l') || (c == 'L')) { + isBold = true; + } else { + isBold = false; + } + } else { + MotdCentralizer dFI = getDefaultFontInfo(c); + messagePxSize += (isBold ? dFI.getBoldLength() : dFI.getLength()); + messagePxSize++; + } + } + int halvedMessageSize = messagePxSize / 2; + int toCompensate = CENTER_MOTD_PX - halvedMessageSize; + int spaceLength = SPACE.getLength() + 1; + int compensated = 0; + StringBuilder sb = new StringBuilder(); + while (compensated < toCompensate) { + sb.append(" "); + compensated += spaceLength; + } + return sb.toString() + message; + } + + public static String makeCenteredMessage(String message){ + int messagePxSize = 0; + boolean previousCode = false; + boolean isBold = false; + char[] arrayOfChar; + int i = (arrayOfChar = message.toCharArray()).length; + for (int j = 0; j < i; j++) { + char c = arrayOfChar[j]; + if (c == '§') { + previousCode = true; + } else if (previousCode) { + previousCode = false; + if ((c == 'l') || (c == 'L')) { + isBold = true; + } else { + isBold = false; + } + } else { + MotdCentralizer dFI = getDefaultFontInfo(c); + messagePxSize += (isBold ? dFI.getBoldLength() : dFI.getLength()); + messagePxSize++; + } + } + int halvedMessageSize = messagePxSize / 2; + int toCompensate = CENTER_CHAT_PX - halvedMessageSize; + int spaceLength = SPACE.getLength() + 1; + int compensated = 0; + StringBuilder sb = new StringBuilder(); + while (compensated < toCompensate) { + sb.append(" "); + compensated += spaceLength; + } + return sb.toString() + message; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.java new file mode 100644 index 0000000..bfcc915 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.java @@ -0,0 +1,113 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.common.clan.Clan; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Mute; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.ChatEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +public class ChatListener implements Listener { + + @SuppressWarnings("deprecation") + @EventHandler + public void onChatMessage(ChatEvent event) { + if (event.isCommand() && !event.getMessage().toLowerCase().startsWith("/tell")) return; + if (event.isCancelled()) return; + + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) event.getSender(); + + if (!CommonsGeneral.getProfileManager().containsProfile(proxiedPlayer.getName())) { + proxiedPlayer.disconnect(TextComponent.fromLegacyText("§4§lERRO\n\n§fVocê não possuí uma sessão no servidor.")); + event.setCancelled(true); + return; + } + + BungeePlayer bungeePlayer = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + Mute mute = bungeePlayer.getPunishmentHistoric().getActualMute(); + + if (mute != null) { + if (mute.isExpired()) { + mute.unmute("CONSOLE > Punição expirada"); + } else { + if (mute.isPermanent()) { + event.setCancelled(true); + proxiedPlayer.sendMessage(BungeeMessages.MUTADO_PERMANENTEMENTE); + } else { + event.setCancelled(true); + proxiedPlayer.sendMessage(BungeeMessages.MUTADO_TEMPORARIAMENTE.replace("%tempo%", + DateUtils.formatDifference(mute.getPunishmentTime()))); + } + } + } + + if (!event.isCancelled() && !event.getMessage().toLowerCase().startsWith("/tell")) { + String message = event.getMessage(); + + if (message.contains("%")) { + message = message.replaceAll("%", "%%"); + } + + Groups playerGroup = bungeePlayer.getGroup(); + + if (!event.isCancelled()) { + + if (message.contains("&")) { + if (playerGroup.getLevel() > Groups.MEMBRO.getLevel()) { + message = message.replaceAll("&", "§"); + } + } + + if (bungeePlayer.isInClanChat()) { + event.setCancelled(true); + + Clan clan = ClanManager.getClan(bungeePlayer.getString(DataType.CLAN)); + + String colorNick = (clan.getOwner().equals(proxiedPlayer.getName()) ? "§4" : + clan.getAdminList().contains(proxiedPlayer.getName()) ? "§c" : "§7"); + + String formatado = BungeeMessages.CLAN_CHAT_PREFIX + " " + colorNick + proxiedPlayer.getName() + ": §f" + message; + + for (Object object : clan.getOnlines()) { + ProxiedPlayer onlines = (ProxiedPlayer) object; + onlines.sendMessage(formatado); + } + } else if (bungeePlayer.isInStaffChat()) { + event.setCancelled(true); + + if (!bungeePlayer.getBoolean(DataType.RECEIVE_STAFFCHAT_MESSAGES)) { + event.setCancelled(true); + proxiedPlayer.sendMessage(BungeeMessages.VOCE_ESTA_TENTANDO_FALAR_NO_STAFFCHAT_COM_ELE_DESATIVADO); + } else { + final String formatado = + BungeeMessages.STAFFCHAT_PREFIX + " " + playerGroup.getColor() + "§l" + playerGroup.getName().toUpperCase() + " " + playerGroup.getColor() + + proxiedPlayer.getName() + ": §f" + message; + + for (ProxiedPlayer proxiedPlayers : ProxyServer.getInstance().getPlayers()) { + if (bungeePlayer.getGroup().getLevel() >= Groups.TRIAL.getLevel()) { + if (BungeeMain.isValid(proxiedPlayers)) { + if (bungeePlayer.getBoolean(DataType.RECEIVE_STAFFCHAT_MESSAGES)) { + proxiedPlayer.sendMessage(formatado); + } + } + } + return; + } + } + } + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.java new file mode 100644 index 0000000..d6b523f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.java @@ -0,0 +1,115 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.commands.register.ClearAccountCommand; +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent.BungeeUpdateType; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.bungee.skins.SkinStorage; +import com.br.guilhermematthew.nowly.commons.common.punishment.PunishmentManager; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class GeneralListeners implements Listener { + + private int MINUTES = 0; + + @EventHandler + public void onSecond(BungeeUpdateEvent event) { + if (event.getType() != BungeeUpdateType.SEGUNDO) { + return; + } + + if (event.getSeconds() % 2 == 0) { + NetworkServer bungee = CommonsGeneral.getServersManager().getNetworkServer("bungeecord"); + bungee.setOnline(true); + bungee.setLastUpdate(System.currentTimeMillis()); + bungee.setOnlines(ProxyServer.getInstance().getOnlineCount()); + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onMinute(BungeeUpdateEvent event) { + if (event.getType() != BungeeUpdateType.MINUTO) return; + + MINUTES++; + + if (MINUTES % BungeeMain.getManager().getMinutos() == 0) { + if (BungeeMain.getManager().getMessages().size() == 0) { + return; + } + + int actualID = BungeeMain.getManager().getActualMessageID(); + + if (actualID >= BungeeMain.getManager().getMessages().size()) { + actualID = 0; + } + + final String message = BungeeMain.getManager().getMessages().get(actualID); + + ProxyServer.getInstance().getPlayers().forEach(onlines -> onlines.sendMessage(message)); + BungeeMain.getManager().setActualMessageID(actualID + 1); + } else if (MINUTES % 30 == 0) { + CommonsGeneral.getUUIDFetcher().checkCache(() -> SkinStorage.checkCache(() -> PremiumMapManager.checkCache(PunishmentManager::checkCache))); + } + } + + @EventHandler + public void onHour(BungeeUpdateEvent event) { + if (event.getType() != BungeeUpdateType.HORA) { + return; + } + + BungeeMain.runAsync(() -> { + List toRemove = new ArrayList<>(); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM accounts_to_delete"); + ResultSet result = preparedStatement.executeQuery(); + + while (result.next()) { + String time = result.getString("timestamp"); + + long timestamp = 0L; + + try { + timestamp = Long.parseLong(time); + } catch (Exception ex) { + toRemove.add(result.getString("nick")); + } + + if (timestamp + TimeUnit.DAYS.toMillis(7) < System.currentTimeMillis()) { + toRemove.add(result.getString("nick")); + } + } + + result.close(); + preparedStatement.close(); + + } catch (SQLException e) { + BungeeMain.console("§cOcorreu um erro ao tentar checar a lista de jogadores banidos para serem removidos -> " + e.getLocalizedMessage()); + e.printStackTrace(); + } + + if (toRemove.size() != 0) { + for (String nick : toRemove) { + ClearAccountCommand.clearAccount(nick); + } + } + + toRemove.clear(); + }); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.java new file mode 100644 index 0000000..4429182 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.java @@ -0,0 +1,223 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.account.permission.BungeePlayerPermissions; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.bungee.skins.SkinApplier; +import com.br.guilhermematthew.nowly.commons.bungee.skins.SkinStorage; +import com.br.guilhermematthew.nowly.commons.common.clan.ClanManager; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.punishment.PunishmentManager; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Ban; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.LoginEvent; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.event.EventPriority; + +import java.sql.SQLException; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +public class LoginListener implements Listener { + + @SuppressWarnings("deprecation") + @EventHandler + public void onLogin(final LoginEvent event) { + if (event.isCancelled()) { + return; + } + + String nick = event.getConnection().getName(), + address = event.getConnection().getAddress().getAddress().getHostAddress(); + + if (!PremiumMapManager.containsMap(nick)) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.PREMIUM_MAP_NOT_LOADED); + return; + } + + if (BungeeMain.getManager().isGlobalWhitelist()) { + if (!BungeeMain.getManager().getWhitelistPlayers().contains(nick.toLowerCase())) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.SERVIDOR_EM_MANUTENÇãO); + return; + } + } + + event.registerIntent(BungeeMain.getInstance()); + + BungeeMain.runAsync(() -> { + UUID uniqueId = CommonsGeneral.getUUIDFetcher().getOfflineUUID(event.getConnection().getName()); + BungeePlayer profile = (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(uniqueId); + + if (profile != null && !profile.isAvailableToJoin()) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.SUA_CONTA_ESTA_SENDO_DESCARREGADA); + event.completeIntent(BungeeMain.getInstance()); + return; + } + + if (event.isCancelled()) { + event.completeIntent(BungeeMain.getInstance()); + return; + } + + if (profile == null) profile = new BungeePlayer(event.getConnection().getName(), address, uniqueId); + + Ban ban = PunishmentManager.getBanCache(nick); + + if (ban == null) { + try { + profile.getPunishmentHistoric().loadBans(); + } catch (SQLException ex) { + CommonsGeneral.error("onLogin() : loadBans() : LoginListener.Java -> " + ex.getLocalizedMessage()); + event.setCancelled(true); + event.completeIntent(BungeeMain.getInstance()); + return; + } + ban = profile.getPunishmentHistoric().getActualBan(); + if (ban != null) { + PunishmentManager.addCache(nick, ban); + } + } + + if (ban != null && ban.isPunished()) { + if (!ban.isExpired()) { + event.setCancelled(true); + + if (ban.isPermanent()) { + event.setCancelReason(TextComponent.fromLegacyText(BungeeMessages.VOCE_ESTA_PERMANENTEMENTE_BANIDO + .replace("%motivo%", ban.getMotive()).replace("%baniu%", ban.getBannedBy()))); + } else { + event.setCancelReason(TextComponent.fromLegacyText(BungeeMessages.VOCE_ESTA_TEMPORARIAMENTE_BANIDO + .replace("%motivo%", ban.getMotive()).replace("%baniu%", ban.getBannedBy()) + .replace("%tempo%", DateUtils.formatDifference(ban.getPunishmentTime())))); + } + } else { + ban.unban("CONSOLE - BAN EXPIRADO"); + PunishmentManager.removeCache(nick); + } + } + + if (event.isCancelled()) { + event.completeIntent(BungeeMain.getInstance()); + return; + } + + + try { + SkinApplier.handleSkin(event.getConnection()); + } catch (Exception ex) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.ERROR_ON_APPLY_SKIN); + + BungeeMain.console("Ocorreu um erro ao tentar setar a skin de um jogador -> " + ex.getLocalizedMessage()); + + ex.printStackTrace(); + + event.completeIntent(BungeeMain.getInstance()); + return; + } + + if (availableToLoad(profile, uniqueId, address, event.getConnection().isOnlineMode())) { + try { + profile.getDataHandler().load(DataCategory.ACCOUNT, DataCategory.PREFERENCES); + } catch (SQLException ex) { + BungeeMain.console("§cOcorreu um erro ao tentar carregar as categorias principais de um player -> " + + ex.getLocalizedMessage()); + event.setCancelled(true); + event.setCancelReason(BungeeMessages.ERROR_ON_LOAD_ACCOUNT); + event.completeIntent(BungeeMain.getInstance()); + return; + } + + profile.getDataHandler().getData(DataType.LAST_IP).setValue(address); + profile.getDataHandler().getData(DataType.LAST_LOGGED_IN).setValue(System.currentTimeMillis()); + profile.setAddress(address); + + if (!profile.getDataHandler().getString(DataType.CLAN).equalsIgnoreCase("Nenhum")) { + ClanManager.load(profile.getString(DataType.CLAN)); + } + } else { + profile.getDataHandler().loadDefault(DataCategory.ACCOUNT); + } + + CommonsGeneral.getProfileManager().addGamingProfile(uniqueId, profile); + + event.completeIntent(BungeeMain.getInstance()); + }); + } + + @EventHandler + public void onPostLogin(PostLoginEvent event) { + ProxiedPlayer proxiedPlayer = event.getPlayer(); + + BungeeMain.runAsync(() -> BungeeMain.runLater(() -> { + if (proxiedPlayer == null || proxiedPlayer.getServer() == null) { + return; + } + + if (BungeeMain.getBungeePlayer(proxiedPlayer.getName()) != null) { + BungeeMain.getBungeePlayer(proxiedPlayer.getName()).handleLogin(proxiedPlayer); + } + }, 1, TimeUnit.SECONDS)); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onDisconnect(final PlayerDisconnectEvent event) { + BungeeMain.runAsync(() -> { + ProxiedPlayer proxiedPlayer = event.getPlayer(); + + SkinStorage.removeFromHash(proxiedPlayer.getName()); + + if (proxiedPlayer.getServer() != null) { + BungeePlayerPermissions.clearPermissions(proxiedPlayer); + + BungeePlayer profile = (BungeePlayer) CommonsGeneral.getProfileManager() + .getGamingProfile(proxiedPlayer.getName()); + + if (profile != null) { + profile.handleQuit(); + + final String serverName = proxiedPlayer.getServer().getInfo().getName().toLowerCase(); + if (serverName.equals("login")) { + return; + } + + if(profile.getGroup() != null && profile.getGroup().getLevel() > Groups.MEMBRO.getLevel() || !serverName.equalsIgnoreCase("lobby")) { + if (serverName.contains("hg") || serverName.equals("evento") || serverName.contains("hardcoregames")) { + profile.setLoginOnServer("LobbyHardcoreGames"); + } else if (serverName.contains("sw")) { + profile.setLoginOnServer("LobbySW"); + } else if (serverName.contains("tb")) { + profile.setLoginOnServer("LobbyTB"); + } else if (serverName.contains("bw")) { + profile.setLoginOnServer("LobbyBW"); + } else { + profile.setLoginOnServer("LobbyPvP"); + } + } else { + profile.setLoginOnServer("Lobby"); + } + } + } + }); + } + + private boolean availableToLoad(final BungeePlayer profile, final UUID uniqueId, final String address, boolean premium) { + if (premium) return true; + if (!CommonsGeneral.getProfileManager().containsProfile(uniqueId)) return false; + + return profile.isValidSession() && profile.getAddress().equals(address); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.java new file mode 100644 index 0000000..3fdb60a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.AsyncPremiumCheck; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import lombok.val; +import net.md_5.bungee.api.event.PreLoginEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +public class PremiumMapListener implements Listener { + + @SuppressWarnings("deprecation") + @EventHandler + public void onPreLogin(PreLoginEvent event) { + if (event.isCancelled()) { + return; + } + + if (!BungeeMain.isLoaded()) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.BUNGEECORD_CARREGANDO); + return; + } + + if (!CommonsGeneral.getServersManager().getNetworkServer("Lobby").isOnline()) { + event.setCancelReason(BungeeMessages.ERROR_ON_CONNECT_TO_X_SERVER.replace("%servidor%", "Lobby")); + event.setCancelled(true); + return; + } + + val name = event.getConnection().getName(); + if (name.length() < 3 || name.length() > 16 || !event.getConnection().getName().matches("^\\w*$")) { + event.setCancelled(true); + event.setCancelReason(BungeeMessages.INVALID_NICKNAME); + return; + } + + val data = PremiumMapManager.getPremiumMap(event.getConnection().getName()); + if (data != null) { + event.getConnection().setOnlineMode(data.isPremium()); + } else { + event.registerIntent(BungeeMain.getInstance()); + + AsyncPremiumCheck asyncPremiumCheck = new AsyncPremiumCheck(event, event.getConnection()); + BungeeMain.runAsync(asyncPremiumCheck); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.java new file mode 100644 index 0000000..81cb09a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.events.MotdCentralizer; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.ServerPing; +import net.md_5.bungee.api.event.ProxyPingEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +public class ProxyPingListener implements Listener +{ + private List motds = Arrays.asList( + "§d§lTODOS OS KITS GRATIS!", + "§b§lMIX HG §e§lADICIONADO!", + "§c§lNOVOS KITS NO HG!"); + public static HashMap ping = new HashMap(); + + @EventHandler( + priority = -64 + ) + public void onProxyPing(ProxyPingEvent event) { + String ipAddress = event.getConnection().getAddress().getHostString(); + if (ping.containsKey(ipAddress)) { + ping.put(ipAddress, (Integer) ping.get(ipAddress) + 1); + } else { + ping.put(ipAddress, 1); + } + + if ((Integer) ping.get(ipAddress) > 20) { + event.setResponse((ServerPing) null); + + } else if (!BungeeMain.getManager().isGlobalWhitelist() == true) { + String motd = ((String)this.motds.get((new Random()).nextInt(this.motds.size() - 1))); + event.setResponse(new ServerPing(event.getResponse().getVersion(), new ServerPing.Players(60, BungeeCord.getInstance().getOnlineCount(), new ServerPing.PlayerInfo[]{new ServerPing.PlayerInfo("", "")}), MotdCentralizer.makeCenteredMotd("§2§lLEAGUE §8★ §aleaguemc.com.br") + "\n" + MotdCentralizer.makeCenteredMotd(motd), event.getResponse().getFaviconObject())); + } else { + event.setResponse(new ServerPing(event.getResponse().getVersion(), new ServerPing.Players(1, BungeeCord.getInstance().getOnlineCount(), new ServerPing.PlayerInfo[]{new ServerPing.PlayerInfo("", "")}), MotdCentralizer.makeCenteredMotd("§2§lLEAGUE §8★ §aleaguemc.com.br") + "\n" + MotdCentralizer.makeCenteredMotd("§c25/03 às 14:00"), event.getResponse().getFaviconObject())); + } + } + +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.java new file mode 100644 index 0000000..18b072c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.java @@ -0,0 +1,110 @@ +package com.br.guilhermematthew.nowly.commons.bungee.listeners; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.commands.register.EventoCommand; +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent.BungeeUpdateType; +import com.br.guilhermematthew.nowly.commons.common.profile.GamingProfile; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import lombok.val; +import net.md_5.bungee.api.event.ServerConnectEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SessionListener implements Listener { + + @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.LOWEST) + public void onServerConnect(ServerConnectEvent event) { + val proxiedPlayer = event.getPlayer(); + + if(event.getTarget().getName().equals(ServerType.EVENTO.getName())) { + val bp = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + if (!EventoCommand.hasEvento && !bp.isStaffer()) { + event.setCancelled(true); + BungeeMain.runLater(() -> proxiedPlayer.sendMessage(BungeeMessages.EVENTO_OFFLINE), 200); + return; + } + } + + if (event.getReason() != ServerConnectEvent.Reason.JOIN_PROXY) return; + String serverToConnect = "Login"; + + String address = proxiedPlayer.getAddress().getAddress().getHostAddress(); + UUID uniqueId = CommonsGeneral.getUUIDFetcher().getOfflineUUID(proxiedPlayer.getName()); + BungeePlayer profile; + + if (CommonsGeneral.getProfileManager().containsProfile(uniqueId)) { + profile = BungeeMain.getBungeePlayer(proxiedPlayer.getName()); + + if (!proxiedPlayer.getPendingConnection().isOnlineMode()) { + if (profile.isValidSession() && profile.getAddress().equals(address)) { + serverToConnect = profile.getLoginOnServer(); + } + } else { + serverToConnect = profile.getLoginOnServer(); + } + } + + if (!CommonsGeneral.getServersManager().getNetworkServer(serverToConnect).isOnline() && + !serverToConnect.equalsIgnoreCase("Lobby") && !serverToConnect.equalsIgnoreCase("Login")) { + serverToConnect = "Lobby"; + } + + if (CommonsGeneral.getServersManager().getNetworkServer(serverToConnect).isOnline()) { + if (!event.getTarget().getName().equalsIgnoreCase(serverToConnect)) { + event.setTarget(BungeeMain.getInstance().getProxy().getServerInfo(serverToConnect)); + } + } else { + event.setCancelled(true); + + proxiedPlayer.disconnect(BungeeMessages.ERROR_ON_CONNECT_TO_X_SERVER.replace("%servidor%", serverToConnect)); + } + } + + @EventHandler + public void onUpdate(BungeeUpdateEvent event) { + if (event.getType() != BungeeUpdateType.HORA) { + return; + } + + List profilesToRemove = new ArrayList<>(); + + for (GamingProfile profile : CommonsGeneral.getProfileManager().getGamingProfiles()) { + BungeePlayer bungeePlayer = (BungeePlayer) profile; + + if (bungeePlayer != null) { + if (!bungeePlayer.isValidSession()) { + if (!bungeePlayer.isValidPlayer()) { + profilesToRemove.add(profile.getUniqueId()); + } + } + + bungeePlayer = null; + } else { + BungeeMain.console("Um BungeePlayer foi detectado como nulo."); + } + + profile = null; + } + + for (UUID uuid : profilesToRemove) { + CommonsGeneral.getProfileManager().removeGamingProfile(uuid); + } + + if (profilesToRemove.size() != 0) { + BungeeMain.console("[Cache] Foram removidas " + profilesToRemove.size() + " contas do cache"); + } + + profilesToRemove.clear(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.java new file mode 100644 index 0000000..f78283e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.java @@ -0,0 +1,104 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.manager.config.BungeeConfigurationManager; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Getter +@Setter +public class BungeeManager { + + private int actualMessageID, minutos; + + private BungeeConfigurationManager configManager; + + private boolean globalWhitelist; + private List whitelistPlayers; + private ArrayList messages; + + public BungeeManager() { + this.configManager = new BungeeConfigurationManager(); + this.whitelistPlayers = new ArrayList<>(); + this.messages = new ArrayList<>(); + + this.globalWhitelist = false; + } + + public void init() { + loadDefaults(); + } + + private void loadDefaults() { + BungeeMain.runLater(() -> { + BungeeMain.runAsync(() -> { + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM skins WHERE nick='0171'"); + ResultSet result = preparedStatement.executeQuery(); + + if (!result.next()) { + PreparedStatement insert = connection.prepareStatement("INSERT INTO skins (nick, lastUse, value, signature, timestamp) VALUES (?, ?, ?, ?, ?)"); + + insert.setString(1, "0171"); + insert.setString(2, String.valueOf(System.currentTimeMillis())); + insert.setString(3, "eyJ0aW1lc3RhbXAiOjE1NzUxNTE1Mjg5OTcsInByb2ZpbGVJZCI6IjM2NTBlMzZhZmU0ZjRmMGRiYTQ4NDAxY2VkYjE1MGUxIiwicHJvZmlsZU5hbWUiOiIwMTcxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9kYWFmOWZhZGQ3ZWQyMDAxZmUwYTlmZjI3ZmQxYmY3YjBhNjMyZjJlZmY3MGYxMjkzMGIzNGIzNWJlYWE4NjFkIn19fQ=="); + insert.setString(4, "iEPj+++vKgJsMDXvgqjMZpag/Wzz/LLOjEK+OlUlf1Fn4vRFrfylMYlH+KopzX1TcdoY5vt1fEbgradTJEFUuFOXL7AI+RZYUoZ9mMbPpXn3Xbkhcw+Q5D9+EDV1WHVLXpnM3sMZPApMAGNMzOAUUChxQbz0HVrB3OjHtbbmkns2hecABaomRC9Gd4b8mWK/5u1gYUQEwF2I+VmJNuwkzOCUhMhMp4Z4RKg8vfePEXqi+cXD4p+phUU+CGxorHr3VakOI2RuGig8JQAI9L92q6C6yFL1j61nCUn1CVokHtGNFtLxE1ow6PuofLsWjR8+F0ksv/qk1jzYY3tucaXGuuz+QRiWTQiXGd+jp5oHFMx5IF77zU7naRJ4fNunhn3Z/AWQpV4v5huRemHe2QLSfPaICNe6cs9P11R/+EsEJs1R7cO9k3rfulMQPlKLHntI2vxVRnl3VqarD4r3o0sZJWfOp9g3xiKg3KTwx5d28zd7uZqmx+i2ien8Vz8J42/II8bGNP9GIxgbWAPRT2bERJca+lRwDnkS5CGA6QZB3euuWubBLPVV/oG7Q28Ij/MCMTOLoVrBIqM39punuEtULK57u/ERS4YkTIh7+j55tAl0lB9Vpo7Uu3yAPjOsG6OPMrZMUNgzi/PtC3KhWyYgFfGVUBNoIAdSuKs5C2JH1ps="); + insert.setString(5, String.valueOf(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(8))); + + insert.executeUpdate(); + } + + preparedStatement.close(); + result.close(); + + preparedStatement = connection.prepareStatement("SELECT * FROM global_whitelist WHERE identify='default'"); + result = preparedStatement.executeQuery(); + + if (result.next()) { + this.globalWhitelist = result.getBoolean("actived"); + + for (String nick : StringUtility.formatStringToArrayWithoutSpace(result.getString("nicks"))) { + getWhitelistPlayers().add(nick.toLowerCase()); + } + } + + result.close(); + preparedStatement.close(); + + } catch (SQLException ex) { + BungeeMain.console("Ocorreu um erro ao tentar carregar coisas necessarias -> " + ex.getLocalizedMessage()); + } + + BungeeMain.setLoaded(true); + }); + }, 2, TimeUnit.SECONDS); + } + + @SuppressWarnings("deprecation") + public void warnStaff(String message, Groups tag) { + for (ProxiedPlayer proxiedPlayer : ProxyServer.getInstance().getPlayers()) { + if (proxiedPlayer.hasPermission(CommonsConst.PERMISSION_PREFIX + ".receivewarn")) { + if (BungeeMain.isValid(proxiedPlayer)) { + if (BungeeMain.getBungeePlayer(proxiedPlayer.getName()).getGroup().getLevel() >= tag.getLevel()) { + proxiedPlayer.sendMessage(message); + } + } + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.java new file mode 100644 index 0000000..0df0e56 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.java @@ -0,0 +1,65 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager.config; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import lombok.Getter; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; + +import java.io.File; +import java.io.IOException; + +@Getter +public class BungeeConfiguration { + + private final String configName; + private Configuration configuration; + private File file; + + public BungeeConfiguration(final String configName) { + this.configName = configName; + } + + public void load() { + this.file = new File(BungeeMain.getInstance().getDataFolder(), this.configName + ".yml"); + + if (!this.file.exists()) { + try { + this.file.createNewFile(); + } catch (Exception ex) { + return; + } + } + + try { + this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file); + } catch (IOException ex) { + ex.printStackTrace(); + } + + BungeeMain.getManager().getConfigManager().refreshConfig(configName); + } + + public void save() { + if (this.file == null) { + return; + } + + try { + ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, file); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void unload() { + if (this.file != null) { + this.file = null; + this.configuration = null; + } + } + + public boolean isLoaded() { + return this.file != null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.java new file mode 100644 index 0000000..6041a7e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.java @@ -0,0 +1,108 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager.config; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import lombok.Getter; + +import java.util.Collections; + +@Getter +public class BungeeConfigurationManager { + + private final BungeeConfiguration permissionsConfig; + private final BungeeConfiguration bungeeConfig; + + public BungeeConfigurationManager() { + this.permissionsConfig = new BungeeConfiguration("bungee-permissions"); + this.bungeeConfig = new BungeeConfiguration("bungee-config"); + } + + public void refreshConfig(final String configName) { + if (configName.equalsIgnoreCase("bungee-permissions")) { + + boolean hasUpdate = false; + + for (Groups groups : Groups.values()) { + if (groups != Groups.DEVELOPER) { + + if (!permissionsConfig.getConfiguration().contains("permissions." + groups.getName().toLowerCase())) { + permissionsConfig.getConfiguration().set("permissions." + groups.getName().toLowerCase(), Collections.singletonList("teste.permission")); + + hasUpdate = true; + } else { + groups.setPermissions(permissionsConfig.getConfiguration().getStringList( + "permissions." + groups.getName().toLowerCase())); + } + + } + } + + + if (hasUpdate) { + getPermissionsConfig().save(); + } + + getPermissionsConfig().unload(); + + Groups.DEVELOPER.setPermissions(Groups.ADMIN.getPermissions()); + } else if (configName.equalsIgnoreCase("bungee-config")) { + + boolean hasUpdate = false; + + for (ValuesBungeeConfig values : ValuesBungeeConfig.values()) { + if (!getBungeeConfig().getConfiguration().contains(values.getKey())) { + getBungeeConfig().getConfiguration().set(values.getKey(), StringUtility.convertValue(values.getValue(), values.getClassExpected())); + hasUpdate = true; + } + } + + if (hasUpdate) { + getBungeeConfig().save(); + } + + apply(configName); + } + } + + private void apply(String configName) { + if (configName.equalsIgnoreCase("bungee-config")) { + CommonsGeneral.getMySQL().setHost(getBungeeConfig().getConfiguration().getString("MySQL.Host")); + CommonsGeneral.getMySQL().setDatabase(getBungeeConfig().getConfiguration().getString("MySQL.Database")); + CommonsGeneral.getMySQL().setUsuario(getBungeeConfig().getConfiguration().getString("MySQL.Usuario")); + CommonsGeneral.getMySQL().setSenha(getBungeeConfig().getConfiguration().getString("MySQL.Senha")); + CommonsGeneral.getMySQL().setPorta(getBungeeConfig().getConfiguration().getString("MySQL.Porta")); + + BungeeMain.getManager().setMinutos(getBungeeConfig().getConfiguration().getInt("AutoMSG.Minutos")); + BungeeMain.setSocketServerHost(getBungeeConfig().getConfiguration().getString("Socket.Host")); + + getBungeeConfig().unload(); + } + } + + public enum ValuesBungeeConfig { + + MYSQL_HOST("MySQL.Host", "localhost", "String"), + MYSQL_PORTA("MySQL.Porta", "3306", "String"), + MYSQL_DATABASE("MySQL.Database", "dustmc", "String"), + MYSQL_USUARIO("MySQL.Usuario", "root", "String"), + MYSQL_SENHA("MySQL.Senha", "vooiid", "String"), + + AUTO_MSG_MINUTOS("AutoMSG.Minutos", "3", "Integer"), + SOCKET_HOST("Socket.Host", "127.0.0.1", "String"); + + @Getter + private final String key; + @Getter + private final String value; + @Getter + private final String classExpected; + + ValuesBungeeConfig(String key, String value, String classExpected) { + this.key = key; + this.value = value; + this.classExpected = classExpected; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.java new file mode 100644 index 0000000..a9fcd49 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.java @@ -0,0 +1,49 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager.premium; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import lombok.val; +import net.md_5.bungee.api.connection.PendingConnection; +import net.md_5.bungee.api.event.PreLoginEvent; + +public class AsyncPremiumCheck implements Runnable { + + private final PendingConnection connection; + private final PreLoginEvent preLoginEvent; + + public AsyncPremiumCheck(PreLoginEvent event, PendingConnection connection) { + this.preLoginEvent = event; + this.connection = connection; + } + + @SuppressWarnings("deprecation") + public void run() { + try { + if (!connection.isConnected()) return; + + try { + PremiumMapManager.load(connection.getName()); + } catch (UUIDFetcherException ex) { + preLoginEvent.setCancelled(true); + preLoginEvent.setCancelReason(BungeeMessages.ERROR_ON_LOAD_PREMIUM_MAP); + } + + if (preLoginEvent.isCancelled()) return; + val data = PremiumMapManager.getPremiumMap(connection.getName()); + + if (data != null) { + connection.setOnlineMode(data.isPremium()); + } + + if (PremiumMapManager.getChangedNicks().contains(connection.getName())) { + PremiumMapManager.getChangedNicks().remove(connection.getName()); + + preLoginEvent.setCancelled(true); + preLoginEvent.setCancelReason(BungeeMessages.PREMIUM_MAP_DETECT_NICK_CHANGE); + } + } finally { + preLoginEvent.completeIntent(BungeeMain.getInstance()); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.java new file mode 100644 index 0000000..957dbc4 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.java @@ -0,0 +1,21 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager.premium; + +import lombok.Getter; +import lombok.Setter; + +import java.util.UUID; + +@Getter +@Setter +public class PremiumMap { + + private boolean premium; + private String nick; + private UUID uniqueId; + + public PremiumMap(UUID uniqueId, String nick, boolean premium) { + this.nick = nick; + this.premium = premium; + this.uniqueId = uniqueId; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.java new file mode 100644 index 0000000..67b3d04 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.java @@ -0,0 +1,198 @@ +package com.br.guilhermematthew.nowly.commons.bungee.manager.premium; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.utility.Cache; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import lombok.Getter; +import lombok.val; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class PremiumMapManager { + + private static final HashMap CACHE = new HashMap<>(); + + @Getter + private final static List changedNicks = new ArrayList<>(); + private static final String[] tabelasToUpdate = {"accounts", "hardcoregames", "kitpvp", "gladiator", "premium_map", + "bans", "mutes"}; + + public static boolean load(String nick) throws UUIDFetcherException { + boolean premium = false; + + UUID uuidProfile = null; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM `premium_map` WHERE nick='" + nick + "'"); + + ResultSet result = preparedStatament.executeQuery(); + + if (result.next()) { + premium = result.getBoolean("premium"); + uuidProfile = UUID.fromString(result.getString("uuid")); + } else { + UUID uuid = CommonsGeneral.getUUIDFetcher().getUUID(nick); + premium = uuid != null; + + uuidProfile = (uuid != null ? uuid + : UUID.nameUUIDFromBytes(("OfflinePlayer:" + nick).getBytes(Charsets.UTF_8))); + + if (premium) { + if (hasChangedNick(uuidProfile, nick)) { + result.close(); + preparedStatament.close(); + changedNicks.add(nick); + return true; + } + } + + if (!changedNicks.contains(nick)) { + PreparedStatement insert = connection + .prepareStatement("INSERT INTO premium_map(nick, uuid, premium) VALUES (?, ?, ?)"); + + insert.setString(1, nick); + insert.setString(2, String.valueOf(uuidProfile)); + insert.setBoolean(3, premium); + + insert.executeUpdate(); + insert.close(); + } + } + + result.close(); + preparedStatament.close(); + + } catch (SQLException ex) { + ex.printStackTrace(); + } + + CACHE.put(nick.toLowerCase(), new Cache(nick, new PremiumMap(uuidProfile, nick, premium), 3)); + return true; + } + + public static boolean hasChangedNick(UUID uuid, String newNick) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM `premium_map` WHERE uuid='" + uuid.toString() + "'"); + + ResultSet result = preparedStatament.executeQuery(); + + if (result.next()) { + final String olderNick = result.getString("nick"); + + result.close(); + preparedStatament.close(); + + if (!olderNick.equalsIgnoreCase(newNick)) { + updateNick(uuid, olderNick, newNick); + } + return true; + } + result.close(); + preparedStatament.close(); + return false; + } catch (SQLException ex) { + return false; + } + } + + private static void updateNick(final UUID uuid, final String oldNick, final String newNick) { + CACHE.put(newNick.toLowerCase(), new Cache(newNick, new PremiumMap(uuid, newNick, true), 3)); + + if (!oldNick.equalsIgnoreCase(newNick)) { + BungeeMain.console("[PremiumMap] detectou a mudança de Nick de " + oldNick + " para " + newNick + "!"); + + CommonsGeneral.runAsync(() -> { + for (String table : tabelasToUpdate) { + MySQLManager.containsAndUpdate(table, "nick", oldNick, + "UPDATE " + table + " SET nick='" + newNick + "' where nick='" + oldNick + "';"); + } + }); + + MySQLManager.containsAndUpdate("registros", "nick", oldNick, + "DELETE FROM registros WHERE nick='" + oldNick + "';"); + } + } + + public static void removePremiumMap(String nickTarget) { + CACHE.remove(nickTarget.toLowerCase()); + } + + public static int getCrackedAmount() { + int crackedAmount = 0; + + for (Cache cache : CACHE.values()) { + if (cache != null && cache.getValue1() != null && !((PremiumMap)cache.getValue1()).isPremium()) { + crackedAmount++; + } + } + + return crackedAmount; + } + + public static int getPremiumAmount() { + int premiumAmont = 0; + + for (Cache cache : CACHE.values()) { + if (cache != null && cache.getValue1() != null && ((PremiumMap)cache.getValue1()).isPremium()) { + premiumAmont++; + } + } + + return premiumAmont; + } + + public static PremiumMap getPremiumMap(String nick) { + val data = CACHE.get(nick.toLowerCase()); + if (data == null) return null; + + return (PremiumMap) data.getValue1(); + } + + public static boolean containsMap(String nick) { + return CACHE.containsKey(nick.toLowerCase()); + } + + public static long getPremiumMaps() { + return CACHE.size(); + } + + public static void checkCache() { + checkCache(null); + } + + public static void checkCache(Runnable callback) { + List keys = Lists.newArrayList(); + + for (Cache cache : CACHE.values()) { + if (cache.isExpired()) { + keys.add(cache.getName()); + } + } + + if (keys.size() != 0) { + for (String key : keys) { + CACHE.remove(key); + } + } + + keys.clear(); + keys = null; + + if (callback != null) { + callback.run(); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.java new file mode 100644 index 0000000..b3ee60f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.java @@ -0,0 +1,337 @@ +package com.br.guilhermematthew.nowly.commons.bungee.networking; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMessages; +import com.br.guilhermematthew.nowly.commons.bungee.account.BungeePlayer; +import com.br.guilhermematthew.nowly.commons.bungee.skins.MojangAPI.SkinRequestException; +import com.br.guilhermematthew.nowly.commons.bungee.skins.SkinApplier; +import com.br.guilhermematthew.nowly.commons.bungee.skins.SkinStorage; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.custompackets.CommonPacketHandler; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import com.google.gson.JsonObject; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.net.Socket; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class BungeePacketsHandler extends CommonPacketHandler { + + /** + * CACHE RESPONSE SERVERS INFO + */ + private Long lastUpdate = 0L; + private CPacketCustomAction lastResponse; + + @Override + public void handleCPacketAction(CPacketAction packet, final Socket socket) { + if (packet.getType().equalsIgnoreCase("HandShake")) { + Server.getInstance().getServerGeneral().registerClient(packet.getField(), + Integer.valueOf(packet.getFieldValue()), socket); + } + + if (packet.getType().equalsIgnoreCase("Loggout")) { + Server.getInstance().getServerGeneral().unregisterClient(socket); + } + } + + @Override + public void handleCPacketPlayerAction(CPacketCustomAction packet, Socket socket) { + PacketType type = packet.getPacketType(); + + if (type != null) { + switch (type) { + case BUKKIT_REQUEST_ACCOUNT_TO_BUNGEECORD: + handleBukkitAccountRequest(packet, socket); + break; + case BUKKIT_SEND_UPDATED_DATA: + handleBukkitSendDatas(packet); + break; + case BUKKIT_SEND_SERVER_DATA: + handleReceivedServerData(packet); + break; + case BUNGEE_SET_FAST_SKIN: + handleSetFastSkin(packet, socket); + break; + case BUNGEE_SET_RANDOM_SKIN: + handleSetRandomSkin(packet); + break; + case BUNGEE_SET_SKIN: + handleSetSkin(packet); + break; + case BUNGEE_UPDATE_SKIN: + handleUpdateSkin(packet, socket); + break; + case BUKKIT_SEND_INFO: + handleReceiveInfo(packet, socket); + break; + default: + break; + } + } + } + + @SuppressWarnings("deprecation") + private void handleReceiveInfo(CPacketCustomAction packet, Socket socket) { + if (packet.getField().equalsIgnoreCase("bukkit-register-server")) { + if (StringUtility.isInteger(packet.getExtraValue())) { + boolean useId = packet.getServerType() == ServerType.HARDCORE_GAMES; + + BungeeMain.registerServer(packet.getServerType().getName() + (useId ? packet.getServerID() : ""), + packet.getFieldValue(), Integer.parseInt(packet.getExtraValue())); + } + } else if (packet.getField().equalsIgnoreCase("bukkit-server-turn-on")) { + + ServerType serverType = packet.getServerType(); + + if (serverType.isPvP(false)) { + Server.getInstance().sendPacket(ServerType.LOBBY_PVP.getName(), + new CPacketCustomAction(ServerType.BUNGEECORD, 1).type(PacketType.BUNGEE_SEND_INFO) + .field(packet.getField()) + .fieldValue(BungeeMessages.ROOM_STARTED.replace("%prefix%", "§6§lPVP").replace("%sala%", + serverType.getName().toUpperCase()))); + } else if (serverType.isHardcoreGames(false) && serverType != ServerType.CHAMPIONS && serverType != ServerType.EVENTO) { + Server.getInstance().sendPacket(ServerType.LOBBY_HARDCOREGAMES.getName(), + new CPacketCustomAction(ServerType.BUNGEECORD, 1).type(PacketType.BUNGEE_SEND_INFO) + .field(packet.getField()) + .fieldValue(BungeeMessages.ROOM_STARTED.replace("%prefix%", "§6§lHG").replace("%sala%", + serverType.getName().toUpperCase()))); + } + } else if (packet.getField().equalsIgnoreCase("bukkit-server-turn-off")) { + ServerType serverType = packet.getServerType(); + int id = packet.getServerID(); + + lastUpdate = 0L; + + NetworkServer networkServer = CommonsGeneral.getServersManager().getServerByType(serverType, id); + if (networkServer != null) { + networkServer.setLastUpdate(-1L); + networkServer.setOnline(false); + networkServer.setOnlines(0); + } + } else if (packet.getField().equalsIgnoreCase("add-perm")) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), + "addperm " + proxiedPlayer.getName() + " " + packet.getFieldValue()); + } else if (packet.getField().equalsIgnoreCase("player-authenticated")) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + BungeePlayer profile = (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(packet.getNick()); + + if (profile != null) { + BungeeMain.runAsync(() -> { + try { + profile.getDataHandler().load(DataCategory.ACCOUNT, DataCategory.PREFERENCES); + } catch (SQLException e) { + e.printStackTrace(); + } + }); + + String address = proxiedPlayer.getAddress().getAddress().getHostAddress(); + + profile.set(DataType.LAST_IP, address); + profile.setAddress(address); + + proxiedPlayer.sendMessage(BungeeMessages.AGORA_VOCE_TEM_UMA_SESSãO_NO_SERVIDOR); + } + } else if (packet.getField().equalsIgnoreCase("require-servers-info")) { + CPacketCustomAction RESPONSE = lastResponse; + + if ((lastUpdate < System.currentTimeMillis()) || (RESPONSE == null)) { + RESPONSE = new CPacketCustomAction().type(PacketType.BUNGEE_SEND_INFO) + .field("bungee-send-servers-info"); + + for (NetworkServer networkServers : CommonsGeneral.getServersManager().getServers()) { + String prefix = networkServers.getServerType().getName().toLowerCase() + "-" + + networkServers.getServerId(); + if (networkServers instanceof GameServer) { + RESPONSE.getJson().addProperty(prefix, ((GameServer) networkServers).toJsonGame().toString()); + } else { + RESPONSE.getJson().addProperty(prefix, networkServers.toJson().toString()); + } + } + + lastUpdate = System.currentTimeMillis() + 200; + lastResponse = RESPONSE; + } else { + RESPONSE.setTimestamp(System.currentTimeMillis()); + } + + Server.getInstance().sendPacket(socket, RESPONSE); + } + } + + @SuppressWarnings("deprecation") + private void handleUpdateSkin(CPacketCustomAction packet, final Socket socket) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + BungeeMain.runAsync(() -> { + try { + SkinStorage.createSkin(packet.getField()); + + SkinStorage.getOrCreateSkinForPlayer(packet.getField()); + SkinStorage.setPlayerSkin(packet.getNick(), packet.getField()); + + BungeeMain.runLater(() -> { + SkinApplier.fastApply(proxiedPlayer, packet.getField(), false); + + Server.getInstance().sendPacket(socket, + new CPacketCustomAction(proxiedPlayer.getName()).type(PacketType.BUKKIT_PLAYER_RESPAWN)); + + proxiedPlayer.sendMessage(BungeeMessages.SKIN_ATUALIZADA); + }); + } catch (SkinRequestException e) { + proxiedPlayer.sendMessage(BungeeMessages.ERROR_ON_UPDATE_SKIN); + } + }); + } + + @SuppressWarnings("deprecation") + private void handleSetSkin(CPacketCustomAction packet) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + BungeeMain.runAsync(() -> { + try { + SkinStorage.getOrCreateSkinForPlayer(packet.getField()); + SkinStorage.setPlayerSkin(packet.getNick(), packet.getField()); + + SkinApplier.applySkin(proxiedPlayer, packet.getField()); + BungeeMain.runLater(() -> proxiedPlayer.sendMessage(BungeeMessages.SKIN_ATUALIZADA)); + } catch (SkinRequestException e) { + proxiedPlayer.sendMessage(BungeeMessages.ERROR_ON_CHANGE_SKIN); + } + }); + } + + @SuppressWarnings("deprecation") + private void handleSetRandomSkin(CPacketCustomAction packet) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + BungeeMain.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection + .prepareStatement("SELECT nick FROM skins ORDER BY RAND() LIMIT 1"); + ResultSet result = preparedStatement.executeQuery(); + + if (result.next()) { + SkinApplier.fastApply(proxiedPlayer, result.getString("nick")); + } + + BungeeMain.runLater(() -> proxiedPlayer.sendMessage(BungeeMessages.SKIN_ATUALIZADA)); + + result.close(); + preparedStatement.close(); + } catch (SQLException ex) { + proxiedPlayer.sendMessage(BungeeMessages.ERROR_ON_CHANGE_SKIN); + } + }); + } + + private void handleSetFastSkin(CPacketCustomAction packet, Socket socket) { + ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(packet.getNick()); + + if (proxiedPlayer == null) + return; + + SkinApplier.fastApply(proxiedPlayer, packet.getField(), false); + + Server.getInstance().sendPacket(socket, + new CPacketCustomAction(proxiedPlayer.getName()).type(PacketType.BUKKIT_PLAYER_RESPAWN)); + } + + private void handleReceivedServerData(final CPacketCustomAction packet) { + CommonsGeneral.getServersManager().updateServerData(packet.getJson()); + } + + private void handleBukkitAccountRequest(final CPacketCustomAction packet, final Socket socket) { + BungeePlayer profile = (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(packet.getNick()); + + if (profile == null) { + BungeeMain.console(packet.getNick() + + " requisitou que sua conta fosse carregada, e o mesmo nao se encontra no servidor."); + return; + } + + CPacketCustomAction PACKET = new CPacketCustomAction(packet.getNick(), packet.getUniqueId()) + .type(PacketType.BUKKIT_RECEIVE_ACCOUNT_FROM_BUNGEECORD); + + List datasToSend = new ArrayList<>(); + + datasToSend.add(DataCategory.ACCOUNT); + datasToSend.add(DataCategory.PREFERENCES); + + if (packet.getServerType().isPvP()) { + datasToSend.add(DataCategory.KITPVP); + } + + if (packet.getServerType().isHardcoreGames(true)) { + datasToSend.add(DataCategory.HARDCORE_GAMES); + } + + if (packet.getServerType() == ServerType.GLADIATOR) { + datasToSend.add(DataCategory.GLADIATOR); + } + + if (packet.getServerType() == ServerType.LOGIN) { + datasToSend.add(DataCategory.REGISTER); + } + + int categoryID = 1; + + for (DataCategory datas : datasToSend) { + PACKET.getJson().addProperty("dataCategory-" + categoryID, + profile.getDataHandler().buildJSON(datas, profile.isValidSession()).toString()); + categoryID++; + } + + Server.getInstance().getServerGeneral().sendPacket(socket, PACKET); + + datasToSend.clear(); + } + + private void handleBukkitSendDatas(final CPacketCustomAction packet) { + BungeePlayer profile = (BungeePlayer) CommonsGeneral.getProfileManager().getGamingProfile(packet.getNick()); + + if (profile == null) { + BungeeMain.console(packet.getNick() + " recebeu uma atualizaçao de categoria e nao possui profile"); + return; + } + + JsonObject json = CommonsConst.PARSER.parse(packet.getJson().get("dataCategory-1").getAsString()) + .getAsJsonObject(); + + profile.getDataHandler().loadFromJSON(DataCategory.getCategoryByName(json.get("dataCategory-name").getAsString()), json); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.java new file mode 100644 index 0000000..e143ef9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.java @@ -0,0 +1,25 @@ +package com.br.guilhermematthew.nowly.commons.bungee.scheduler; + +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bungee.events.BungeeUpdateEvent.BungeeUpdateType; +import net.md_5.bungee.BungeeCord; + +public class BungeeUpdateScheduler implements Runnable { + + private long seconds; + + @Override + public void run() { + BungeeCord.getInstance().getPluginManager().callEvent(new BungeeUpdateEvent(BungeeUpdateType.SEGUNDO, seconds)); + + if (seconds % 60 == 0) { + BungeeCord.getInstance().getPluginManager().callEvent(new BungeeUpdateEvent(BungeeUpdateType.MINUTO, seconds)); + } + + if (seconds % 3600 == 0) { + BungeeCord.getInstance().getPluginManager().callEvent(new BungeeUpdateEvent(BungeeUpdateType.HORA, seconds)); + } + + seconds++; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.java new file mode 100644 index 0000000..976802b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.java @@ -0,0 +1,276 @@ +package com.br.guilhermematthew.nowly.commons.bungee.skins; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.utility.mojang.UUIDFetcher.UUIDFetcherException; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import lombok.val; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +@SuppressWarnings("all") +public class MojangAPI { + + private static final String uuidurl = "https://api.minetools.eu/uuid/%name%"; + private static final String uuidurl_mojang = "https://api.mojang.com/users/profiles/minecraft/%name%"; + private static final String uuidurl_backup = "https://api.ashcon.app/mojang/v2/user/%name%"; + + private static final String skinurl = "https://api.minetools.eu/profile/%uuid%"; + private static final String skinurl_mojang = "https://sessionserver.mojang.com/session/minecraft/profile/%uuid%?unsigned=false"; + private static final String skinurl_backup = "https://api.ashcon.app/mojang/v2/user/%uuid%"; + + public static Object getSkinProperty(String uuid, boolean tryNext) { + String output; + + try { + output = readURL(skinurl.replace("%uuid%", uuid)); + JsonElement element = new JsonParser().parse(output); + JsonObject obj = element.getAsJsonObject(); + + Property property = new Property(); + + if (obj.has("raw")) { + JsonObject raw = obj.getAsJsonObject("raw"); + + if (property.valuesFromJson(raw)) { + return SkinStorage.createProperty("textures", property.getValue(), property.getSignature()); + } + } + return null; + } catch (Exception e) { + if (tryNext) + return getSkinPropertyMojang(uuid); + } + return null; + } + + public static Object getSkinProperty(String uuid) { + return getSkinProperty(uuid, true); + } + + public static Object getSkinPropertyMojang(String uuid, boolean tryNext) { + String output; + try { + output = readURL(skinurl_mojang.replace("%uuid%", uuid)); + JsonElement element = new JsonParser().parse(output); + JsonObject obj = element.getAsJsonObject(); + + Property property = new Property(); + + if (property.valuesFromJson(obj)) { + return SkinStorage.createProperty("textures", property.getValue(), property.getSignature()); + } + + return null; + } catch (Exception e) { + if (tryNext) + return getSkinPropertyBackup(uuid); + } + return null; + } + + public static Object getSkinPropertyMojang(String uuid) { + return getSkinPropertyMojang(uuid, true); + } + + public static Object getSkinPropertyBackup(String uuid) { + String output; + try { + output = readURL(skinurl_backup.replace("%uuid%", uuid), 10000); + JsonElement element = new JsonParser().parse(output); + JsonObject obj = element.getAsJsonObject(); + JsonObject textures = obj.get("textures").getAsJsonObject(); + JsonObject rawTextures = textures.get("raw").getAsJsonObject(); + + Property property = new Property(); + property.setValue(rawTextures.get("value").getAsString()); + property.setSignature(rawTextures.get("signature").getAsString()); + + return SkinStorage.createProperty("textures", property.getValue(), property.getSignature()); + + } catch (Exception e) { + return null; + } + } + + public static String getUUID(String name, boolean tryNext) throws SkinRequestException { + if (name == null) return null; + + try { + val uuid = CommonsGeneral.getUUIDFetcher().getUUID(name); + if (uuid != null) return uuid.toString(); + } catch (UUIDFetcherException e) { + e.printStackTrace(); + } + + return null; + } + + public static String getUUID(String name) throws SkinRequestException { + return getUUID(name, true); + } + + public static String getUUIDMojang(String name, boolean tryNext) throws SkinRequestException { + String output; + try { + output = readURL(uuidurl_mojang.replace("%name%", name)); + + if (output.isEmpty()) + throw new SkinRequestException("not premium"); + + JsonElement element = new JsonParser().parse(output); + JsonObject obj = element.getAsJsonObject(); + + if (obj.has("error")) { + if (tryNext) + return getUUIDBackup(name); + return null; + } + + return obj.get("id").getAsString(); + } catch (IOException e) { + if (tryNext) return getUUIDBackup(name); + } + return null; + } + + public static String getUUIDMojang(String name) throws SkinRequestException { + return getUUIDMojang(name, true); + } + + public static String getUUIDBackup(String name) throws SkinRequestException { + String output; + try { + output = readURL(uuidurl_backup.replace("%name%", name), 10000); + + JsonElement element = new JsonParser().parse(output); + JsonObject obj = element.getAsJsonObject(); + + if (obj.has("code")) { + if (obj.get("code").getAsInt() == 404) { + throw new SkinRequestException("not premium"); + } + throw new SkinRequestException("api falha"); + } + + return obj.get("uuid").getAsString().replace("-", ""); + } catch (IOException e) { + throw new SkinRequestException(e.getMessage()); + } + } + + private static String readURL(String url) throws IOException { + return readURL(url, 5000); + } + + private static String readURL(String url, int timeout) throws IOException { + HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); + + con.setRequestMethod("GET"); + con.setRequestProperty("User-Agent", "SkinsRestorer"); + con.setConnectTimeout(timeout); + con.setReadTimeout(timeout); + con.setDoOutput(true); + + String line; + StringBuilder output = new StringBuilder(); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + + while ((line = in.readLine()) != null) + output.append(line); + + in.close(); + return output.toString(); + } + + public static class SkinRequestException extends Exception { + + private String reason; + + public SkinRequestException(String reason) { + this.reason = reason; + } + + public String getReason() { + return reason; + } + + public String getMessage() { + return reason; + } + } + + private static class Property { + private String name; + private String value; + private String signature; + + boolean valuesFromJson(JsonObject obj) { + if (obj.has("properties")) { + JsonArray properties = obj.getAsJsonArray("properties"); + JsonObject propertiesObject = properties.get(0).getAsJsonObject(); + + String signature = propertiesObject.get("signature").getAsString(); + String value = propertiesObject.get("value").getAsString(); + + this.setSignature(signature); + this.setValue(value); + + return true; + } + + return false; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + String getValue() { + return value; + } + + void setValue(String value) { + this.value = value; + } + + String getSignature() { + return signature; + } + + void setSignature(String signature) { + this.signature = signature; + } + } + + private static class HTTPResponse { + private String output; + private int status; + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.java new file mode 100644 index 0000000..60df43e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.java @@ -0,0 +1,162 @@ +package com.br.guilhermematthew.nowly.commons.bungee.skins; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +public class ReflectionUtil { + + public static Class getBungeeClass(String path, String clazz) throws Exception { + return Class.forName("net.md_5.bungee." + path + "." + clazz); + } + + public static Constructor getConstructor(Class clazz, Class... args) throws Exception { + Constructor c = clazz.getConstructor(args); + c.setAccessible(true); + return c; + } + + public static Enum getEnum(Class clazz, String constant) throws Exception { + Class c = Class.forName(clazz.getName()); + Enum[] econstants = (Enum[]) c.getEnumConstants(); + for (Enum e : econstants) + if (e.name().equalsIgnoreCase(constant)) + return e; + throw new Exception("Enum constant not found " + constant); + } + + public static Enum getEnum(Class clazz, String enumname, String constant) throws Exception { + Class c = Class.forName(clazz.getName() + "$" + enumname); + Enum[] econstants = (Enum[]) c.getEnumConstants(); + + for (Enum e : econstants) { + if (e.name().equalsIgnoreCase(constant)) { + return e; + } + } + + throw new Exception("Enum constant not found " + constant); + } + + public static Field getField(Class clazz, String fname) throws Exception { + Field f = null; + try { + f = clazz.getDeclaredField(fname); + } catch (Exception e) { + f = clazz.getField(fname); + } + setFieldAccessible(f); + return f; + } + + public static Object getFirstObject(Class clazz, Class objclass, Object instance) throws Exception { + Field f = null; + for (Field fi : clazz.getDeclaredFields()) + if (fi.getType().equals(objclass)) { + f = fi; + break; + } + + if (f == null) + for (Field fi : clazz.getFields()) + if (fi.getType().equals(objclass)) { + f = fi; + break; + } + + setFieldAccessible(f); + return f.get(instance); + } + + public static Method getMethod(Class clazz, String mname) throws Exception { + Method m = null; + try { + m = clazz.getDeclaredMethod(mname); + } catch (Exception e) { + try { + m = clazz.getMethod(mname); + } catch (Exception ex) { + return m; + } + } + m.setAccessible(true); + return m; + } + + public static Field getField(Class target, String name, Class fieldType, int index) { + for (final Field field : target.getDeclaredFields()) { + if ((name == null || field.getName().equals(name)) && fieldType.isAssignableFrom(field.getType()) && index-- <= 0) { + field.setAccessible(true); + return field; + } + } + + if (target.getSuperclass() != null) + return getField(target.getSuperclass(), name, fieldType, index); + throw new IllegalArgumentException("Cannot find field with type " + fieldType); + } + + public static Method getMethod(Class clazz, String mname, Class... args) throws Exception { + Method m = null; + try { + m = clazz.getDeclaredMethod(mname, args); + } catch (Exception e) { + try { + m = clazz.getMethod(mname, args); + } catch (Exception ex) { + return m; + } + } + m.setAccessible(true); + return m; + } + + public static Object getObject(Class clazz, Object obj, String fname) throws Exception { + return getField(clazz, fname).get(obj); + } + + public static Object getObject(Object obj, String fname) throws Exception { + return getField(obj.getClass(), fname).get(obj); + } + + public static Object invokeConstructor(Class clazz, Class[] args, Object... initargs) throws Exception { + return getConstructor(clazz, args).newInstance(initargs); + } + + public static Object invokeMethod(Class clazz, Object obj, String method) throws Exception { + return getMethod(clazz, method).invoke(obj); + } + + public static Object invokeMethod(Class clazz, Object obj, String method, Class[] args, Object... initargs) + throws Exception { + return getMethod(clazz, method, args).invoke(obj, initargs); + } + + public static Object invokeMethod(Class clazz, Object obj, String method, Object... initargs) throws Exception { + return getMethod(clazz, method).invoke(obj, initargs); + } + + public static Object invokeMethod(Object obj, String method) throws Exception { + return getMethod(obj.getClass(), method).invoke(obj); + } + + public static Object invokeMethod(Object obj, String method, Object[] initargs) throws Exception { + return getMethod(obj.getClass(), method).invoke(obj, initargs); + } + + public static void setFieldAccessible(Field f) throws Exception { + f.setAccessible(true); + Field modifiers = Field.class.getDeclaredField("modifiers"); + modifiers.setAccessible(true); + modifiers.setInt(f, f.getModifiers() & ~Modifier.FINAL); + } + + public static void setObject(Class clazz, Object obj, String fname, Object value) throws Exception { + getField(clazz, fname).set(obj, value); + } + + public static void setObject(Object obj, String fname, Object value) throws Exception { + getField(obj.getClass(), fname).set(obj, value); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.java new file mode 100644 index 0000000..fedc644 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.java @@ -0,0 +1,98 @@ +package com.br.guilhermematthew.nowly.commons.bungee.skins; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.val; +import net.md_5.bungee.api.connection.PendingConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.connection.InitialHandler; +import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.connection.LoginResult.Property; + +public class SkinApplier { + + public static void handleSkin(PendingConnection pendingConnection) throws Exception { + val textures = (Property) SkinStorage.getOrCreateSkinForPlayer(pendingConnection.getName()); + val handler = (InitialHandler) pendingConnection; + if (textures == null) return; + + if (handler.isOnlineMode()) { + handler.getLoginProfile().setProperties(new Property[]{textures}); + } else { + val profile = getLoginProfile(pendingConnection.getName(), pendingConnection.getUniqueId().toString(), textures); + ReflectionUtil.setObject(InitialHandler.class, pendingConnection, "loginProfile", profile); + } + } + + public static void fastApply(ProxiedPlayer proxiedPlayer, String skinToApply) { + fastApply(proxiedPlayer, skinToApply, true); + } + + public static void fastApply(ProxiedPlayer proxiedPlayer, String skinToApply, boolean sendPacket) { + try { + if (proxiedPlayer == null || proxiedPlayer.getServer() == null) + return; + + Property textures = (Property) SkinStorage.getOrCreateSkinForPlayer(skinToApply); + if (textures == null) return; + + val handler = (InitialHandler) proxiedPlayer.getPendingConnection(); + if (handler.isOnlineMode()) { + handler.getLoginProfile().setProperties(new Property[]{textures}); + } else { + val profile = getLoginProfile(handler.getName(), handler.getUniqueId().toString(), textures); + ReflectionUtil.setObject(InitialHandler.class, handler, "loginProfile", profile); + } + + if (sendPacket) { + if (proxiedPlayer.getServer() == null) + return; + + Server.getInstance().sendPacket(proxiedPlayer.getServer().getInfo().getName(), + new CPacketCustomAction(proxiedPlayer.getUniqueId()).type(PacketType.BUKKIT_RECEIVE_SKIN_DATA) + .field("sendPacket") + .fieldValue(textures.getName()) + .extraValue(textures.getValue()) + .extraValue2(textures.getSignature())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void applySkin(ProxiedPlayer proxiedPlayer, String skinToApply) { + BungeeMain.runAsync(() -> { + try { + if (proxiedPlayer == null || proxiedPlayer.getServer() == null) + return; + + Property textures = (Property) SkinStorage.getOrCreateSkinForPlayer(skinToApply); + if (textures == null) return; + + val handler = (InitialHandler) proxiedPlayer.getPendingConnection(); + if (handler.isOnlineMode()) { + handler.getLoginProfile().setProperties(new Property[]{textures}); + } else { + val profile = getLoginProfile(handler.getName(), handler.getUniqueId().toString(), textures); + ReflectionUtil.setObject(InitialHandler.class, handler, "loginProfile", profile); + } + + Server.getInstance().sendPacket(proxiedPlayer.getServer().getInfo().getName(), + new CPacketCustomAction(proxiedPlayer.getUniqueId()).type(PacketType.BUKKIT_RECEIVE_SKIN_DATA) + .field("sendPacket") + .fieldValue(textures.getName()) + .extraValue(textures.getValue()) + .extraValue2(textures.getSignature())); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + + private static LoginResult getLoginProfile(final String name, final String uniqueId, final Property textures) { + return new LoginResult(uniqueId, name, new Property[]{textures}); + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.java new file mode 100644 index 0000000..28519c6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.java @@ -0,0 +1,346 @@ +package com.br.guilhermematthew.nowly.commons.bungee.skins; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.bungee.manager.premium.PremiumMapManager; +import com.br.guilhermematthew.nowly.commons.bungee.skins.MojangAPI.SkinRequestException; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.utility.Cache; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.google.common.collect.Lists; +import lombok.val; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class SkinStorage { + + private static final HashMap CACHE = new HashMap<>(); + public static final HashMap PLAYER_SKIN = new HashMap<>(); + private static Class property; + private static Object DEFAULT_SKIN = null; + + static { + try { + property = Class.forName("com.mojang.authlib.properties.Property"); + } catch (Exception e) { + try { + property = Class.forName("net.md_5.bungee.connection.LoginResult$Property"); + } catch (Exception ex) { + try { + property = Class.forName("net.minecraft.util.com.mojang.authlib.properties.Property"); + } catch (Exception exc) { + System.out.println( + "[SkinsRestorer] Could not find a valid Property class! Plugin will not work properly"); + } + } + } + } + + public static void checkCache(Runnable callback) { + List keys = Lists.newArrayList(); + + for (Cache cache : CACHE.values()) { + if (cache.isExpired()) { + keys.add(cache.getName()); + } + } + + if (keys.size() != 0) { + for (String key : keys) { + CACHE.remove(key); + } + } + + keys.clear(); + + if (callback != null) { + callback.run(); + } + } + + public static Object getDefaultSkin() { + if (DEFAULT_SKIN == null) + DEFAULT_SKIN = getSkinData("0171"); + + return DEFAULT_SKIN; + } + + public static void removeFromHash(final String nick) { + PLAYER_SKIN.remove(nick); + } + + public static Object createProperty(String name, String value, String signature) { + try { + return ReflectionUtil.invokeConstructor(property, + new Class[]{String.class, String.class, String.class}, name, value, signature); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static Object createSkinIfNotCreated(final String nick) { + try { + return getOrCreateSkinForPlayer(nick); + } catch (SkinRequestException e) { + e.printStackTrace(); + } + return null; + } + + public static Object getOrCreateSkinForPlayer(final String name) throws SkinRequestException { + String skin = getPlayerSkin(name); + + if (skin == null) skin = name.toLowerCase(); + + Object textures = getSkinData(skin); + + if (textures != null) return textures; + + val premium = PremiumMapManager.getPremiumMap(name); + if (premium != null && !premium.isPremium()) textures = getDefaultSkin(); + + if (textures != null) return textures; + + String uuid = "N/A"; + val data = PremiumMapManager.getPremiumMap(name); + if (data != null) uuid = String.valueOf(data.getUniqueId()).replaceAll("-", ""); + + final String sname = skin; + if (uuid.equals("N/A")) { + uuid = MojangAPI.getUUID(sname); + } + + textures = MojangAPI.getSkinProperty(uuid); + + setSkinData(sname, textures); + return textures; + } + + public static void createSkin(String name) throws SkinRequestException { + Object textures; + + String uuid = "N/A"; + val data = PremiumMapManager.getPremiumMap(name); + if (data != null) uuid = String.valueOf(data.getUniqueId()).replaceAll("-", ""); + + try { + if (uuid.equals("N/A")) { + uuid = MojangAPI.getUUID(name); + } + + textures = MojangAPI.getSkinProperty(uuid); + + setSkinData(name, textures); + } catch (SkinRequestException e) { + throw new SkinRequestException(e.getReason()); + } catch (Exception e2) { + throw new SkinRequestException("aguarde"); + } + } + + public static String getPlayerSkin(String name) { + name = name.toLowerCase(); + + if (PLAYER_SKIN.containsKey(name)) return PLAYER_SKIN.get(name); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM playerSkin where nick='" + name + "';"); + + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + PLAYER_SKIN.put(name, name); + return name; + } + + String skinUsing = result.getString("skin"); + result.close(); + preparedStatament.close(); + + PLAYER_SKIN.put(name, skinUsing); + return skinUsing; + } catch (SQLException ex) { + CommonsGeneral.console("Ocorreu um erro ao tentar obter a skin do jogador -> " + ex.getLocalizedMessage()); + } + return name; + } + + public static Object getSkinData(String name) { + name = name.toLowerCase(); + + Skin cachedSkin = null; + + if (CACHE.containsKey(name)) { + cachedSkin = (Skin) CACHE.get(name).getValue1(); + } + + if (cachedSkin != null) { + return createProperty("textures", cachedSkin.getValue(), cachedSkin.getSignature()); + } + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM skins where nick='" + name + "';"); + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + return null; + } + + String value = result.getString("value"), signature = result.getString("signature"), + timestamp = result.getString("timestamp"); + + result.close(); + preparedStatament.close(); + + if (isOld(Long.parseLong(timestamp))) { + Object skin = MojangAPI.getSkinProperty(MojangAPI.getUUID(name)); + if (skin != null) { + SkinStorage.setSkinData(name, skin); + } + } else { + CACHE.put(name, new Cache(name, new Skin(name, value, signature), 3)); + } + return createProperty("textures", value, signature); + } catch (SQLException ex) { + BungeeMain.console("Ocorreu um erro ao tentar obter a data de uma skin (SQL) -> " + ex.getLocalizedMessage()); + ex.printStackTrace(); + } catch (SkinRequestException ex) { + ex.printStackTrace(); + } + + return getSkinData("0171"); + } + + public static boolean isOld(long timestamp) { + return timestamp + TimeUnit.MINUTES.toMillis(1584) <= System.currentTimeMillis(); + } + + public static void removePlayerSkin(String name) { + name = name.toLowerCase(); + + PLAYER_SKIN.remove(name); + + MySQLManager.deleteFromTable("playerSkin", "nick", name); + } + + public static void removeSkinData(String name) { + final String name1 = name.toLowerCase(); + + CACHE.remove(name); + + CommonsGeneral.runAsync(() -> MySQLManager.deleteFromTable("skins", "nick", name1)); + } + + public static void setPlayerSkin(String name, String skin) { + name = name.toLowerCase(); + + PLAYER_SKIN.put(name, skin); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM playerSkin where nick='" + name + "';"); + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + + PreparedStatement set = connection + .prepareStatement("INSERT INTO playerSkin (nick, skin) VALUES (?, ?)"); + + set.setString(1, name); + set.setString(2, skin); + + set.executeUpdate(); + set.close(); + return; + } + + result.close(); + preparedStatament.close(); + + PreparedStatement set = connection + .prepareStatement("UPDATE playerSkin SET skin=? where nick='" + name + "'"); + + set.setString(1, skin); + + set.executeUpdate(); + set.close(); + } catch (SQLException ex) { + CommonsGeneral.error("Erro ao setar skin de um jogador no MySQL -> " + ex.getLocalizedMessage()); + } + } + + public static void setSkinData(String name, Object textures) { + String name1 = name.toLowerCase(); + + String value, signature, timestamp; + + try { + value = (String) ReflectionUtil.invokeMethod(textures, "getValue"); + signature = (String) ReflectionUtil.invokeMethod(textures, "getSignature"); + timestamp = String.valueOf(System.currentTimeMillis()); + } catch (Exception ex) { + return; + } + + CACHE.put(name1, new Cache(name1, new Skin(name1, value, signature), 3)); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM skins where nick='" + name1 + "';"); + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + + PreparedStatement set = connection.prepareStatement( + "INSERT INTO skins (nick, lastUse, value, signature, timestamp) VALUES (?, ?, ?, ?, ?)"); + + set.setString(1, name1); + set.setString(2, "" + System.currentTimeMillis()); + set.setString(3, value); + set.setString(4, signature); + set.setString(5, timestamp); + + set.executeUpdate(); + set.close(); + return; + } + + result.close(); + preparedStatament.close(); + + PreparedStatement set = connection.prepareStatement( + "UPDATE skins SET lastUse=?, value=?, signature=?, timestamp=? where nick='" + name1 + "'"); + + set.setString(1, "" + System.currentTimeMillis()); + set.setString(2, value); + set.setString(3, signature); + set.setString(4, timestamp); + + set.executeUpdate(); + set.close(); + } catch (SQLException ex) { + CommonsGeneral.console("Erro ao setar skin no MySQL -> " + ex.getLocalizedMessage()); + } + } + + public void checkCache() { + checkCache(null); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.java new file mode 100644 index 0000000..676834d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.java @@ -0,0 +1,29 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility; + +import com.br.guilhermematthew.nowly.commons.common.utility.ClassGetter; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.api.plugin.Plugin; + +public class BungeeListeners { + + public static void loadListeners(Plugin instance, String packageName) { + for (Class classes : ClassGetter.getClassesForPackage(instance, packageName)) { + try { + if (Listener.class.isAssignableFrom(classes)) { + Listener listener = (Listener) classes.newInstance(); + + if (listener == null) + continue; + + ProxyServer.getInstance().getPluginManager().registerListener(instance, listener); + + listener = null; + } + } catch (Exception exception) { + exception.printStackTrace(); + } + } + } +} + diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.java new file mode 100644 index 0000000..10c7333 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import com.google.common.base.Preconditions; + +import java.util.logging.Filter; +import java.util.logging.Logger; + +public abstract class AbstractInjectableFilter implements InjectableFilter { + + private final Logger logger; + protected Filter previousFilter = null; + + protected AbstractInjectableFilter(Logger logger) { + Preconditions.checkNotNull(logger, "logger"); + this.logger = logger; + } + + @Override + public boolean isInjected() { + return logger.getFilter() == this; + } + + @Override + public Filter inject() { + if (isInjected()) { + return logger.getFilter(); + } + + previousFilter = logger.getFilter(); + logger.setFilter(this); + return logger.getFilter(); + } + + @Override + public boolean reset() { + if (!isInjected()) { + return false; + } else { + logger.setFilter(previousFilter); + return true; + } + } + + @Override + public Filter getPreviousFilter() { + return previousFilter; + } + + @Override + public Logger getLogger() { + return logger; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.java new file mode 100644 index 0000000..92675f7 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.java @@ -0,0 +1,56 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Filter; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +public class CompoundFilter extends AbstractInjectableFilter { + + private final List filters; + + public CompoundFilter(Logger logger) { + this(logger, new LinkedList()); + } + + public CompoundFilter(Logger logger, List filters) { + super(logger); + this.filters = new ArrayList<>(filters); + } + + @Override + public boolean isLoggable(LogRecord record) { + for (Filter filter : filters) { + if (!filter.isLoggable(record)) { + return false; + } + } + return true; + } + + public void addFilter(Filter filter) { + filters.add(filter); + } + + public void removeFilter(Filter filter) { + filters.remove(filter); + } + + public boolean hasFilter(Filter filter) { + return filters.contains(filter); + } + + public List getFilters() { + return Collections.unmodifiableList(filters); + } + + @Override + public String toString() { + return "CompoundFilter{" + + "filters=" + filters + + '}'; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.java new file mode 100644 index 0000000..60ccfd2 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.java @@ -0,0 +1,63 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; + +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +public class Filters extends PropagatingFilter { + + private final String[] messages = {"hasconnected", "hasdisconnected", "disconnectedwith", "nstoprocess!", "readtimedout", + "connectionresetbypeer", "pinging", "initialhandler", "connectionwasaborted", "pluginviolation", "<->", + "warning", "upstreambridge", "ioexception", "illegalthread", "bungeesecuritymanager", "plugin", "performed", + "restricted", "action", "pinghandler", "peer", "readaddress", "(..)", "native", "upstream", "pinged", "remoto", + "packet!", "to_server", "with:{1}", "[{0}]disconnectedwith:{1}", "{0}hasdisconnected", "{0}-badpacketid,aremodsinuse!?{1}", + "{0}-corruptedframe:{1}", "{0}", "{0}-{1}:{2}", "{2}", "{1}", "event{0}", "mstoprocess!"}; + + public Filters(BungeeMain plugin) { + super(plugin.getProxy().getLogger()); + } + + Filters(Logger logger) { + super(logger); + } + + @Override + public boolean isLoggable(LogRecord record) { + String message = record.getMessage().toLowerCase(); + + boolean canLog = true; + + if (message.length() > 2) { + if (message.contains("license")) { + return true; + } + if (message.contains("commons")) { + return true; + } + if (message.contains(" ")) { + message = message.replaceAll(" ", ""); + } + + for (String filteredsMsgs : messages) { + if (message.contains(filteredsMsgs)) { + canLog = false; + break; + } + if (message.equalsIgnoreCase(filteredsMsgs)) { + canLog = false; + break; + } + if (message.startsWith(filteredsMsgs)) { + canLog = false; + break; + } + if (message.endsWith(filteredsMsgs)) { + canLog = false; + break; + } + } + } + return canLog; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.java new file mode 100644 index 0000000..5102112 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import java.util.logging.Filter; +import java.util.logging.Logger; + +public interface InjectableFilter extends Filter { + + Logger getLogger(); + + Filter getPreviousFilter(); + + boolean isInjected(); + + Filter inject(); + + boolean reset(); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.java new file mode 100644 index 0000000..23088b0 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.java @@ -0,0 +1,27 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; + +import java.util.LinkedList; +import java.util.List; + +public class LogFilterBungee { + + private static final List filters = new LinkedList<>(); + + public static void load(BungeeMain plugin) { + filters.clear(); + + filters.add(new Filters(plugin)); + + for (InjectableFilter filter : filters) { + filter.inject(); + } + } + + public static void unload() { + for (InjectableFilter filter : filters) { + filter.reset(); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.java new file mode 100644 index 0000000..d97c0e5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.java @@ -0,0 +1,61 @@ +package com.br.guilhermematthew.nowly.commons.bungee.utility.logfilter; + +import java.util.Arrays; +import java.util.logging.Filter; +import java.util.logging.Logger; + +public abstract class PropagatingFilter extends AbstractInjectableFilter { + + protected PropagatingFilter(Logger logger) { + super(logger); + } + + @Override + public boolean isInjected() { + return super.isInjected() || inCompound(); + } + + @Override + public Filter inject() { + if (isInjected()) { + } else if (isCompound()) { + ((CompoundFilter) getLogger().getFilter()).addFilter(this); + } else if (getLogger().getFilter() != null) { + previousFilter = getLogger().getFilter(); + getLogger().setFilter(new CompoundFilter( + getLogger(), + Arrays.asList(this, previousFilter) + )); + } else { + return super.inject(); + } + return getLogger().getFilter(); + } + + @Override + public boolean reset() { + if (inCompound()) { + CompoundFilter compound = (CompoundFilter) getLogger().getFilter(); + compound.removeFilter(this); + if (compound.getFilters().size() == 1 && + compound.getFilters().get(0) == previousFilter) { + getLogger().setFilter(previousFilter); + } else if (compound.getFilters().isEmpty()) { + getLogger().setFilter(null); + } + return !isCompound(); + } else if (isCompound()) { + return false; + } else { + return super.reset(); + } + } + + protected boolean inCompound() { + return isCompound() && ((CompoundFilter) getLogger().getFilter()).hasFilter(this); + } + + protected boolean isCompound() { + return getLogger().getFilter() instanceof CompoundFilter; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/PluginInstance.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/PluginInstance.java new file mode 100644 index 0000000..9750015 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/PluginInstance.java @@ -0,0 +1,14 @@ +package com.br.guilhermematthew.nowly.commons.common; + +public enum PluginInstance { + + BUNGEECORD, BUKKIT, UNKNOWN; + + public boolean isBukkit() { + return this == BUKKIT; + } + + public boolean isBungee() { + return this == BUNGEECORD; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/Clan.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/Clan.java new file mode 100644 index 0000000..3ac276b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/Clan.java @@ -0,0 +1,100 @@ +package com.br.guilhermematthew.nowly.commons.common.clan; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +public class Clan { + + private String name, tag, owner; + private boolean premium; + private int maxParticipants; + + private List memberList, adminList; + private List onlines; + + public Clan(String clanName, String tag) { + this.name = clanName; + this.tag = tag; + + this.memberList = new ArrayList<>(); + this.adminList = new ArrayList<>(); + this.onlines = new ArrayList<>(); + } + + public void addMember(String name) { + if (!memberList.contains(name)) { + memberList.add(name); + } + } + + public void removePlayer(String name) { + adminList.remove(name); + + memberList.remove(name); + } + + public void promote(String name) { + if (!adminList.contains(name)) { + adminList.add(name); + } + } + + public void unpromote(String name) { + adminList.remove(name); + } + + public boolean isAdmin(String name) { + if (getOwner().equalsIgnoreCase(name)) return true; + return adminList.contains(name); + } + + public void removeOnline(Object object) { + getOnlines().remove(object); + } + + public void addOnline(Object object) { + if (!getOnlines().contains(object)) { + getOnlines().add(object); + } + } + + public JsonObject getJSON() { + JsonObject json = new JsonObject(); + + json.addProperty("dono", getOwner()); + json.addProperty("tag", getTag()); + json.addProperty("premium", isPremium()); + + json.addProperty("maxParticipants", getMaxParticipants()); + + json.addProperty("admins", StringUtility.formatStringToArrayWithoutSpace(getAdminList())); + json.addProperty("membros", StringUtility.formatStringToArrayWithoutSpace(getMemberList())); + return json; + } + + @SuppressWarnings("deprecation") + public void message(String message) { + if (CommonsGeneral.getPluginInstance() == PluginInstance.BUKKIT) { + for (Object players : onlines) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) players; + player.sendMessage(message); + player = null; + } + } else { + for (Object players : onlines) { + net.md_5.bungee.api.connection.ProxiedPlayer player = (net.md_5.bungee.api.connection.ProxiedPlayer) players; + player.sendMessage(message); + player = null; + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.java new file mode 100644 index 0000000..4b46309 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.java @@ -0,0 +1,112 @@ +package com.br.guilhermematthew.nowly.commons.common.clan; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bungee.BungeeMain; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.google.gson.JsonObject; +import lombok.Getter; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; + +public class ClanManager { + + @Getter + private static final HashMap clans = new HashMap<>(); + + public static void load(String name) { + if (hasClanData(name)) return; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection.prepareStatement( + "SELECT * FROM clans WHERE (nome='" + name + "');"); + + ResultSet result = preparedStatament.executeQuery(); + + if (result.next()) { + loadFromJSON(result.getString("nome"), CommonsConst.PARSER.parse(result.getString("data")).getAsJsonObject()); + } + + result.close(); + preparedStatament.close(); + } catch (SQLException ex) { + CommonsGeneral.error("§cOcorreu um erro ao tentar carregar um clan... -> " + ex.getLocalizedMessage()); + } + } + + private static void loadFromJSON(final String name, final JsonObject json) { + if (json == null) return; + + Clan clan = hasClanData(name) ? getClan(name) : new Clan(name, json.get("tag").getAsString()); + + clan.setOwner(json.get("dono").getAsString()); + clan.setTag(json.get("tag").getAsString()); + + clan.setAdminList(StringUtility.formatStringToArrayWithoutSpace(json.get("admins").getAsString())); + clan.setMemberList(StringUtility.formatStringToArrayWithoutSpace(json.get("membros").getAsString())); + clan.setPremium(json.get("premium").getAsBoolean()); + + if (!hasClanData(name)) { + putClan(name, clan); + } + + clan = null; + } + + public static void removeClanData(String nome) { + clans.remove(nome); + } + + public static Clan getClan(String name) { + if (!clans.containsKey(name)) { + load(name); + } + + return clans.get(name.toLowerCase()); + } + + public static void putClan(String name, Clan clan) { + clans.put(name.toLowerCase(), clan); + } + + public static void unloadClan(String name) { + clans.remove(name.toLowerCase()); + } + + public static boolean hasClanData(String nome) { + return clans.containsKey(nome.toLowerCase()); + } + + public static void saveClan(String clanName) { + saveClan(clanName, false); + } + + public static void saveClan(String clanName, boolean remove) { + if (!hasClanData(clanName)) return; + + BungeeMain.runAsync(() -> { + final Clan clan = getClan(clanName); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection.prepareStatement( + "UPDATE clans SET data=? WHERE nome='" + clanName + "'"); + + preparedStatament.setString(1, clan.getJSON().toString()); + preparedStatament.execute(); + + preparedStatament.close(); + preparedStatament = null; + } catch (SQLException ex) { + CommonsGeneral.error("Ocorreu um erro ao tentar salvar as estatistícas do clan " + clanName + " > " + ex.getLocalizedMessage()); + } + }); + + if (remove) { + removeClanData(clanName); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.java new file mode 100644 index 0000000..358eac5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.java @@ -0,0 +1,4 @@ +package com.br.guilhermematthew.nowly.commons.common.command; + +public interface CommandClass { +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.java new file mode 100644 index 0000000..9d91f79 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.java @@ -0,0 +1,58 @@ +package com.br.guilhermematthew.nowly.commons.common.command; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.ClassGetter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +public interface CommandFramework { + + Object getPlugin(); + + void registerCommands(CommandClass commandClass); + + default CommandFramework loadCommands(Object plugin, String packageName) { + for (Class commandClass : ClassGetter.getClassesForPackage(plugin, packageName)) + if (CommandClass.class.isAssignableFrom(commandClass)) { + try { + registerCommands((CommandClass) commandClass.newInstance()); + } catch (Exception e) { + CommonsGeneral.console("Error when loading command from " + commandClass.getSimpleName() + "!"); + e.printStackTrace(); + } + } + + return this; + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @interface Command { + + String name(); + + Groups[] groupsToUse() default {Groups.MEMBRO}; + + String permission() default ""; + + String[] aliases() default {}; + + String description() default ""; + + String usage() default ""; + + boolean runAsync() default false; + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @interface Completer { + String name(); + + String[] aliases() default {}; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.java new file mode 100644 index 0000000..e939dd8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.java @@ -0,0 +1,10 @@ +package com.br.guilhermematthew.nowly.commons.common.command; + +import java.util.UUID; + +public interface CommandSender { + + UUID getUniqueId(); + + boolean isPlayer(); +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/commons - Shortcut.lnk b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/commons - Shortcut.lnk new file mode 100644 index 0000000..bd5982b Binary files /dev/null and b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/commons - Shortcut.lnk differ diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.java new file mode 100644 index 0000000..44375b2 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.java @@ -0,0 +1,96 @@ +package com.br.guilhermematthew.nowly.commons.common.connections.mysql; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import lombok.Getter; +import lombok.Setter; + +import java.sql.Connection; +import java.sql.SQLException; + +public class MySQL { + + private HikariDataSource dataSource; + + @Getter + @Setter + private String host, porta, database, usuario, senha; + + public void openConnection() { + CommonsGeneral.console("§eTentando estabelecer conexao com o MySQL..."); + + if (dataSource != null) + throw new IllegalStateException("Hikari already initialized"); + + HikariConfig configuration = new HikariConfig(); + configuration.setJdbcUrl("jdbc:mysql://" + host + ":3306/" + "leaguemc" + "?characterEncoding=utf8&useSSL=false&useConfigs=maxPerformance"); + configuration.setUsername("root"); + configuration.setPassword(senha); + + configuration.setMaximumPoolSize(10); + configuration.setMaxLifetime(3000000L); + configuration.setLeakDetectionThreshold(50000000L); + + configuration.addDataSourceProperty("cachePrepStmts", "true"); + configuration.addDataSourceProperty("prepStmtCacheSize", "250"); + configuration.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + + dataSource = new HikariDataSource(configuration); + } + + public void createTables() { + String[] categorysList = new String[DataCategory.values().length]; + + int id = 0; + for (DataCategory categorys : DataCategory.values()) { + categorysList[id] = categorys.buildTableQuery(); + id++; + } + + CommonsGeneral.runAsync(() -> { + MySQLManager.executeUpdate(categorysList); + + MySQLManager.executeUpdate( + "CREATE TABLE IF NOT EXISTS global_whitelist(identify varchar(20), actived boolean, nicks text);", + "CREATE TABLE IF NOT EXISTS accounts_to_delete(nick varchar(20), timestamp varchar(100));", + "CREATE TABLE IF NOT EXISTS clans(nome varchar(20), data JSON);", + "CREATE TABLE IF NOT EXISTS premium_map(nick varchar(20), uuid varchar(100), premium boolean);", + "CREATE TABLE IF NOT EXISTS playerSkin(nick varchar(16), skin varchar(16));", + "CREATE TABLE IF NOT EXISTS bans(nick varchar(20), address varchar(100), data JSON);", + "CREATE TABLE IF NOT EXISTS mutes(nick varchar(20), data JSON);", + "CREATE TABLE IF NOT EXISTS skins(nick varchar(16), lastUse varchar(100), value text, signature text, timestamp text);"); + }); + } + + public void closeConnection() { + try { + if (getConnection() != null) { + getConnection().close(); + + dataSource.close(); + dataSource = null; + + CommonsGeneral.console("§aConexao com o MySQL encerrada."); + } + } catch (SQLException ex) { + CommonsGeneral.error("closeConnection() : MySQL.Java -> " + ex.getLocalizedMessage()); + } + } + + public boolean isConnected() { + try { + getConnection(); + return true; + } catch (SQLException e) { + return false; + } + } + + public Connection getConnection() throws SQLException { + if (dataSource == null) openConnection(); + + return dataSource.getConnection(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.java new file mode 100644 index 0000000..b1dd42c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.java @@ -0,0 +1,213 @@ +package com.br.guilhermematthew.nowly.commons.common.connections.mysql; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import lombok.val; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MySQLManager { + + public static int getPlayerPositionRanking(String name) { + return getPlayerPosition("accounts", "xp", "nick", name); + } + + public static int getPlayerPosition(String table, String field, String where, String name) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection.prepareStatement( + "SELECT COUNT(*) FROM " + table + " WHERE data>'$." + field + "' > (SELECT data>'$." + field + + "' from " + table + " WHERE " + where + "='" + name + "')"); + + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + return 0; + } + + int pos = Integer.parseInt(result.getString("COUNT(*)")) + 1; + + result.close(); + preparedStatament.close(); + return pos; + } catch (SQLException ex) { + CommonsGeneral.console("Ocorreu um erro ao tentar obter uma posição. -> " + ex.getLocalizedMessage()); + return 0; + } + } + + public static int getPlayerPositionByColumn(String table, String field, String where, String name) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT COUNT(*) FROM " + table + " WHERE " + field + " > (SELECT " + field + + " from " + table + " WHERE " + where + "='" + name + "')"); + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + result.close(); + preparedStatament.close(); + return 0; + } + + int pos = Integer.parseInt(result.getString("COUNT(*)")) + 1; + + result.close(); + preparedStatament.close(); + return pos; + } catch (SQLException ex) { + CommonsGeneral.console("Ocorreu um erro ao tentar obter uma posiçao. -> " + ex.getLocalizedMessage()); + return 0; + } + } + + public static String getStringFromJSON(String table, String where, String whereValue, String field) { + String string = "N/A"; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement( + "SELECT data->'$." + field + "' FROM " + table + " WHERE " + where + "='" + whereValue + "'"); + + ResultSet result = preparedStatement.executeQuery(); + + if (result.next()) { + string = result.getString("data->'$." + field + "'").replace("\"", ""); + } + + preparedStatement.close(); + result.close(); + } catch (SQLException ex) { + CommonsGeneral.error("getString() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + + return string; + } + + public static String getString(String table, String where, String who, String toGet) { + String string = "N/A"; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + val statement = connection.prepareStatement("SELECT * FROM `" + table + "` WHERE `" + where + "`=?"); + statement.setString(1, who); + val result = statement.executeQuery(); + + if (result.next()) string = result.getString(toGet); + + statement.close(); + result.close(); + } catch (SQLException ex) { + CommonsGeneral.error("getString() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + + return string; + } + + public static void deleteFromTable(String table, String where, String who) { + containsAndUpdate(table, where, who, "DELETE FROM " + table + " WHERE " + where + "='" + who + "';"); + } + + public static boolean contains(String table, String where, String who) { + boolean contains = false; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection + .prepareStatement("SELECT * FROM `" + table + "` WHERE `" + where + "`='" + who + "';"); + + ResultSet result = preparedStatement.executeQuery(); + + contains = result.next(); + + preparedStatement.close(); + result.close(); + } catch (SQLException ex) { + CommonsGeneral.error("contains() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + + return contains; + } + + public static boolean updateIfNotExists(String table, String where, String who, String update) { + boolean updated = false; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection + .prepareStatement("SELECT * FROM `" + table + "` WHERE `" + where + "`='" + who + "';"); + + ResultSet result = preparedStatement.executeQuery(); + + if (!result.next()) { + PreparedStatement updateStatement = connection.prepareStatement(update); + + updateStatement.executeUpdate(); + updateStatement.close(); + updated = true; + } + + result.close(); + preparedStatement.close(); + } catch (SQLException ex) { + CommonsGeneral.error("updateIfNotExists() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + + return updated; + } + + public static void containsAndUpdate(String table, String where, String who, String update) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection + .prepareStatement("SELECT * FROM `" + table + "` WHERE `" + where + "`=?"); + preparedStatement.setString(1, who); + + ResultSet result = preparedStatement.executeQuery(); + + if (result.next()) { + PreparedStatement updateStatement = connection.prepareStatement(update); + + updateStatement.executeUpdate(); + updateStatement.close(); + } + + result.close(); + preparedStatement.close(); + } catch (SQLException ex) { + CommonsGeneral.error("containsAndUpdate() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + } + + public static void updateValue(DataCategory dataCategory, DataType dataType, String value, String nick) { + executeUpdate("UPDATE " + dataCategory.getTableName() + " SET " + dataType.getField() + "='" + value + + "' where nick='" + nick + "';"); + } + + public static void updateStats(String table, String stats, String where, String who, String value) { + executeUpdate("UPDATE " + table + " SET " + stats + "='" + value + "' where '" + where + "'='" + who + "';"); + } + + public static void updateStats(String table, String stats, String nick, String value) { + executeUpdate("UPDATE " + table + " SET " + stats + "='" + value + "' where nick='" + nick + "';"); + } + + public static void executeUpdate(String... commands) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + + //onHandleCommand + for (String command : commands) { + try { + PreparedStatement preparedStatement = connection.prepareStatement(command); + preparedStatement.executeUpdate(); + + preparedStatement.close(); + } catch (SQLException ex) { + CommonsGeneral.error("executeUpdate() : onHandleCommand : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + } + + } catch (SQLException ex) { + CommonsGeneral.error("executeUpdate() : MySQLManager.Java -> " + ex.getLocalizedMessage()); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/Data.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/Data.java new file mode 100644 index 0000000..2104a46 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/Data.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.commons.common.data; + +import java.util.List; + +public class Data { + + private Object data; + + public Data(final Object data) { + this.data = data; + } + + public void add() { + add(1); + } + + public void add(int quantia) { + setValue(getInt() + quantia); + } + + public void remove() { + remove(1); + } + + public void remove(int quantia) { + int atual = getInt(); + + if (atual - quantia < 0) { + setValue(0); + return; + } + + setValue(atual - quantia); + } + + public void setValue(Object data) { + this.data = data; + } + + public Object getObject() { + return data; + } + + public String getString() { + return (String) data; + } + + public Integer getInt() { + return (Integer) data; + } + + public Long getLong() { + return (Long) data; + } + + public Boolean getBoolean() { + return (Boolean) data; + } + + @SuppressWarnings("unchecked") + public List getList() { + return (List) data; + } + + @Override + public String toString() { + if (data != null) + return data.toString(); + return "null"; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.java new file mode 100644 index 0000000..fd1a08a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.java @@ -0,0 +1,347 @@ +package com.br.guilhermematthew.nowly.commons.common.data; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import lombok.Getter; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +@Getter +public class DataHandler { + + private final String nick; + private final UUID uniqueId; + + private final Map datas; + private final Map loadedCategories; + + public DataHandler(final String nick, final UUID uniqueId) { + this.nick = nick; + this.uniqueId = uniqueId; + + this.datas = new ConcurrentHashMap<>(); + this.loadedCategories = new ConcurrentHashMap<>(); + + for (DataCategory dataCategory : DataCategory.values()) { + this.loadedCategories.put(dataCategory, false); + } + } + + public void load(final DataCategory... dataCategory) throws SQLException { + for (int i = 0; i < dataCategory.length; i++) { + DataCategory current = dataCategory[i]; + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement( + "SELECT * FROM `" + current.getTableName() + "` WHERE `nick`='" + getNick() + "';"); + + ResultSet result = preparedStatement.executeQuery(); + + if (result.next()) { + loadFromJSONString(current, result.getString("data")); + } else { + if (current.create()) { + insertOnTable(current); + + datas.put(DataType.FIRST_LOGGED_IN, new Data(System.currentTimeMillis())); + + for (DataType dataType : current.getDataTypes()) { + if (dataType == DataType.FIRST_LOGGED_IN) { + datas.put(dataType, new Data(System.currentTimeMillis())); + } else { + datas.put(dataType, new Data(dataType.getDefaultValue())); + } + } + } + + getLoadedCategories().put(current, true); + } + + preparedStatement.close(); + result.close(); + } + } + } + + private void insertOnTable(final DataCategory category) { + CommonsGeneral.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection.prepareStatement(createInsertIntoStringQuery(category)); + + insert.execute(); + insert.close(); + + insert = null; + } catch (SQLException e) { + CommonsGeneral.error("load() : insertOnTable() : DataHandler.java -> " + e.getLocalizedMessage()); + } + }); + } + + public void saveCategorys(final DataCategory... dataCategorys) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + for (int i = 0; i < dataCategorys.length; i++) { + DataCategory dataCategory = dataCategorys[i]; + + try { + PreparedStatement save = connection.prepareStatement( + "UPDATE " + dataCategory.getTableName() + " SET data=? where nick='" + getNick() + "'"); + + save.setString(1, createJSON(dataCategory, false).toString()); + + save.execute(); + save.close(); + + save = null; + } catch (SQLException ex) { + CommonsGeneral.error("Ocorreu um erro ao tentar salvar a categoria '" + dataCategory.getTableName() + + "' de " + getNick() + " -> " + ex.getLocalizedMessage()); + } + } + } catch (SQLException ex) { + CommonsGeneral.error("Ocorreu um erro ao tentar abrir um pool de conexao " + ex.getLocalizedMessage()); + } + + sendCategoryToBungeecord(dataCategorys); + } + + public void saveCategory(final DataCategory dataCategory) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement save = connection.prepareStatement( + "UPDATE " + dataCategory.getTableName() + " SET data=? where nick='" + getNick() + "'"); + + save.setString(1, createJSON(dataCategory, false).toString()); + + save.execute(); + save.close(); + + save = null; + } catch (SQLException ex) { + CommonsGeneral.error("Ocorreu um erro ao tentar salvar a categoria '" + dataCategory.getTableName() + + "' de " + getNick() + " -> " + ex.getLocalizedMessage()); + } + + sendCategoryToBungeecord(dataCategory); + } + + public void sendCategoryToBungeecord(final DataCategory... dataCategorys) { + if (CommonsGeneral.getPluginInstance() == PluginInstance.BUKKIT) { + + CPacketCustomAction PACKET = new CPacketCustomAction(nick, uniqueId) + .type(PacketType.BUKKIT_SEND_UPDATED_DATA); + + int id = 1; + + for (int i = 0; i < dataCategorys.length; i++) { + DataCategory dataCategory = dataCategorys[i]; + PACKET.getJson().addProperty("dataCategory-" + id, buildJSON(dataCategory, true).toString()); + id++; + } + + Client.getInstance().getClientConnection().sendPacket(PACKET); + } + } + + public void loadFromJSON(final DataCategory dataCategory, final JsonObject json) { + if (json == null) + return; + + for (Entry entry : json.entrySet()) { + final DataType data = DataType.getDataTypeByField(entry.getKey()); + + if (data == null) { + continue; + } + + if (!getDatas().containsKey(data)) { + datas.put(data, new Data(data.getDefaultValue())); + } + + final String classExpected = data.getClassExpected(); + + if (data == DataType.PERMISSIONS) { + getData(data).setValue(StringUtility.formatStringToArrayWithoutSpace(entry.getValue().getAsString())); + } else { + if (classExpected.equalsIgnoreCase("Boolean")) { + getData(data).setValue(entry.getValue().getAsBoolean()); + } else if (classExpected.equalsIgnoreCase("Int")) { + getData(data).setValue(entry.getValue().getAsInt()); + } else if (classExpected.equalsIgnoreCase("Long")) { + getData(data).setValue(entry.getValue().getAsLong()); + } else { + getData(data).setValue(entry.getValue().getAsString()); + } + } + } + + getLoadedCategories().put(dataCategory, true); + + for (DataType data : dataCategory.getDataTypes()) { + if (!getDatas().containsKey(data)) { + datas.put(data, new Data(data.getDefaultValue())); // FIX NOVAS COISAS NO JSON + } + } + } + + public void loadFromJSONString(final DataCategory dataCategory, final String jsonString) { + if (jsonString == null) + return; + + if (jsonString.isEmpty()) + return; + + loadFromJSON(dataCategory, CommonsConst.PARSER.parse(jsonString).getAsJsonObject()); + } + + /** + * SENDO USADO PARA ENVIAR CATEGORIAS ENTRE SERVER-CLIENT + */ + public JsonObject buildJSON(final DataCategory dataCategory, boolean checkIfIsNotLoadedAndLoad) { + JsonObject json = createJSON(dataCategory, checkIfIsNotLoadedAndLoad); + json.addProperty("dataCategory-name", dataCategory.getTableName()); + return json; + } + + public JsonObject createJSON(final DataCategory dataCategory, boolean checkIfIsNotLoadedAndLoad) { + JsonObject json = new JsonObject(); + + boolean loaded = isCategoryLoaded(dataCategory); + + if (checkIfIsNotLoadedAndLoad && !loaded) { + try { + load(dataCategory); + } catch (SQLException ex) { + } + } + + for (DataType dataType : dataCategory.getDataTypes()) { + if (dataType == DataType.PERMISSIONS) { + json.addProperty(dataType.getField(), + loaded ? StringUtility.formatStringToArrayWithoutSpace(getData(dataType).getList()) : ""); + } else { + if (dataType.getClassExpected().equalsIgnoreCase("Boolean")) { + json.addProperty(dataType.getField(), loaded ? getData(dataType).getBoolean() : false); + } else if (dataType.getClassExpected().equalsIgnoreCase("Int")) { + json.addProperty(dataType.getField(), loaded ? getData(dataType).getInt() : 0); + } else if (dataType.getClassExpected().equalsIgnoreCase("Long")) { + json.addProperty(dataType.getField(), loaded ? getData(dataType).getLong() : 0L); + } else { + json.addProperty(dataType.getField(), + loaded ? getData(dataType).getString() : "" + dataType.getDefaultValue()); + } + } + } + return json; + } + + public void loadDefault(final DataCategory dataCategory) { + for (DataType dataType : dataCategory.getDataTypes()) { + if (!isCategoryLoaded(dataCategory)) { + datas.put(dataType, new Data(dataType.getDefaultValue())); + } + } + } + + public void reset() { + for (DataCategory dataCategory : DataCategory.values()) { + if (isCategoryLoaded(dataCategory)) { + for (DataType data : dataCategory.getDataTypes()) { + datas.put(data, new Data(data.getDefaultValue())); + } + getLoadedCategories().put(dataCategory, false); + } + } + } + + public String getIntFormatted(DataType dataType) { + return StringUtility.formatValue(getInt(dataType)); + } + + public List getListDataCategorysLoadeds() { + List list = new ArrayList<>(); + + for (DataCategory datas : DataCategory.values()) { + if (isCategoryLoaded(datas)) { + list.add(datas); + } + } + return list; + } + + public void remove(DataType dataType) { + remove(dataType, 1); + } + + public void remove(DataType dataType, int value) { + getData(dataType).remove(value); + } + + public void add(DataType dataType) { + add(dataType, 1); + } + + public void add(DataType dataType, int value) { + getData(dataType).add(value); + } + + public void set(DataType dataType, Object value) { + getData(dataType).setValue(value); + } + + public boolean isCategoryLoaded(DataCategory category) { + return this.loadedCategories.get(category); + } + + public Data getData(DataType dataType) { + return this.datas.get(dataType); + } + + public int getInt(DataType dataType) { + return this.datas.get(dataType).getInt(); + } + + public String getString(DataType dataType) { + return this.datas.get(dataType).getString(); + } + + public Boolean getBoolean(DataType dataType) { + return this.datas.get(dataType).getBoolean(); + } + + public Long getLong(DataType dataType) { + return this.datas.get(dataType).getLong(); + } + + public String createInsertIntoStringQuery(final DataCategory category) { + return "INSERT INTO `" + category.getTableName() + "` (`nick`, `data`) VALUES ('" + getNick() + "', '" + + createJSON(category, false).toString() + "');"; + } + + public void sendCategoryToBungeecord(final List list) { + CPacketCustomAction PACKET = new CPacketCustomAction(nick, uniqueId).type(PacketType.BUKKIT_SEND_UPDATED_DATA); + + for (int i = 0; i < list.size(); i++) { + PACKET.getJson().addProperty("dataCategory-" + (i + 1), buildJSON(list.get(i), true).toString()); + } + + Client.getInstance().getClientConnection().sendPacket(PACKET); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.java new file mode 100644 index 0000000..8622b37 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.java @@ -0,0 +1,55 @@ +package com.br.guilhermematthew.nowly.commons.common.data.category; + +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import lombok.Getter; + +import static com.br.guilhermematthew.nowly.commons.common.data.type.DataType.*; + +@Getter +public enum DataCategory { + + ACCOUNT("accounts", GROUP, GROUP_TIME, GROUP_CHANGED_BY, CLAN, MEDAL, TAG, PERMISSIONS, FAKE, DOUBLEXP, DOUBLEXP_TIME, DOUBLECOINS, DOUBLECOINS_TIME, + XP, COINS, CASH, LAST_IP, FIRST_LOGGED_IN, LAST_LOGGED_IN, LAST_LOGGED_OUT), + + KITPVP("kitpvp", PVP_KILLS, PVP_DEATHS, PVP_KILLSTREAK, PVP_MAXKILLSTREAK, + FPS_KILLS, FPS_DEATHS, FPS_KILLSTREAK, FPS_MAXKILLSTREAK, + PVP_LAVACHALLENGE_FACIL, PVP_LAVACHALLENGE_MEDIO, PVP_LAVACHALLENGE_DIFICIL, PVP_LAVACHALLENGE_EXTREMO, PVP_LAVACHALLENGE_MORTES), + + GLADIATOR("gladiator", GLADIATOR_WINS, GLADIATOR_LOSES, GLADIATOR_WINSTREAK, GLADIATOR_MAXWINSTREAK, GLADIATOR_SLOTS), + + HARDCORE_GAMES("hardcoregames", HG_KILLS, HG_DEATHS, HG_WINS, HG_EVENT_WINS, HG_EVENT_KILLS, HG_EVENT_DEATHS, HG_DAILY_KIT, HG_DAILY_KIT_TIME), + + PREFERENCES("preferences", RECEIVE_PRIVATE_MESSAGES, RECEIVE_STAFFCHAT_MESSAGES, RECEIVE_REPORTS, PLAYERS_VISIBILITY, + ANNOUNCEMENT_JOIN, CLAN_TAG_DISPLAY), + + REGISTER("registros", REGISTRO_SENHA, REGISTRO_DATA); + + private final String tableName; + private final DataType[] dataTypes; + + DataCategory(String tableName, DataType... dataTypes) { + this.tableName = tableName; + this.dataTypes = dataTypes; + } + + public static DataCategory getCategoryByName(String name) { + DataCategory finded = DataCategory.ACCOUNT; + + for (DataCategory datas : DataCategory.values()) { + if (datas.getTableName().equalsIgnoreCase(name)) { + finded = datas; + break; + } + } + + return finded; + } + + public boolean create() { + return this != REGISTER; + } + + public String buildTableQuery() { + return "CREATE TABLE IF NOT EXISTS `" + getTableName() + "` (nick varchar(20), data JSON);"; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.java new file mode 100644 index 0000000..e84dade --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.java @@ -0,0 +1,104 @@ +package com.br.guilhermematthew.nowly.commons.common.data.type; + +import lombok.Getter; + +import java.util.ArrayList; + +@Getter +public enum DataType { + + //ACCOUNT + GROUP("membro", "String", "group", "VARCHAR(20)"), + GROUP_TIME(0L, "Long", "grupo_time", "VARCHAR(100)"), + GROUP_CHANGED_BY("", "String", "grupo_changed_by", "VARCHAR(20)"), + CLAN("Nenhum", "String", "clan", "VARCHAR(20)"), + FAKE("", "String", "fake", "VARCHAR(20)"), + MEDAL(0, "Int", "medal", "int"), + TAG("Membro", "String", "tag", "VARCHAR(64)"), + DOUBLEXP(0, "Int", "double_xp_amount", "VARCHAR(100)"), + DOUBLEXP_TIME(0L, "Long", "doublexp_time", "VARCHAR(100)"), + DOUBLECOINS(0, "Int", "double_coins_amount", "int"), + DOUBLECOINS_TIME(0L, "Long", "doublecoins_time", "VARCHAR(100)"), + PERMISSIONS(new ArrayList<>(), "String", "permissions", "VARCHAR(2000)"), + XP(0, "Int", "xp", "int"), + COINS(0, "Int", "coins", "int"), + CASH(0, "Int", "cash", "int"), + LAST_IP("", "String", "last_ip", "VARCHAR(20)"), + FIRST_LOGGED_IN(0L, "Long", "first_logged_in", "VARCHAR(100)"), + LAST_LOGGED_IN(0L, "Long", "last_logged_in", "VARCHAR(100)"), + LAST_LOGGED_OUT(0L, "Long", "last_logged_out", "VARCHAR(100)"), + + //HG + HG_KILLS(0, "Int", "hg_kills", "int"), + HG_DEATHS(0, "Int", "hg_deaths", "int"), + HG_WINS(0, "Int", "hg_wins", "int"), + HG_EVENT_WINS(0, "Int", "hg_events_wins", "int"), + HG_EVENT_KILLS(0, "Int", "hg_events_kills", "int"), + HG_EVENT_DEATHS(0, "Int", "hg_events_deaths", "int"), + HG_DAILY_KIT("Nenhum", "String", "daily_kit", "VARCHAR(20)"), + HG_DAILY_KIT_TIME(0L, "Long", "daily_kit_time", "VARCHAR(100)"), + + //GLADIATOR + GLADIATOR_WINS(0, "Int", "gladiator_wins", "int"), + GLADIATOR_LOSES(0, "Int", "gladiator_loses", "int"), + GLADIATOR_WINSTREAK(0, "Int", "gladiator_winstreak", "int"), + GLADIATOR_MAXWINSTREAK(0, "Int", "gladiator_max_killstreak", "int"), + GLADIATOR_SLOTS("276:139:282:282:282:282:282:326:327:" + + "306:307:308:309:281:351:351:351:274:" + + "306:307:308:309:281:351:351:351:275:" + + "327:327:282:282:282:282:282:282:5", "String", "slots", "VARCHAR(250)"), + + //KITPVP + PVP_KILLS(0, "Int", "pvp_kills", "int"), + PVP_DEATHS(0, "Int", "pvp_deaths", "int"), + PVP_KILLSTREAK(0, "Int", "pvp_killstreak", "int"), + PVP_MAXKILLSTREAK(0, "Int", "pvp_max_killstreak", "int"), + FPS_KILLS(0, "Int", "fps_kills", "int"), + FPS_DEATHS(0, "Int", "fps_deaths", "int"), + FPS_KILLSTREAK(0, "Int", "fps_killstreak", "int"), + FPS_MAXKILLSTREAK(0, "Int", "fps_max_killstreak", "int"), + PVP_LAVACHALLENGE_FACIL(0, "Int", "pvp_lavachallenge_facil", "int"), + PVP_LAVACHALLENGE_MEDIO(0, "Int", "pvp_lavachallenge_medio", "int"), + PVP_LAVACHALLENGE_DIFICIL(0, "Int", "pvp_lavachallenge_dificil", "int"), + PVP_LAVACHALLENGE_EXTREMO(0, "Int", "pvp_lavachallenge_extremo", "int"), + PVP_LAVACHALLENGE_MORTES(0, "Int", "pvp_lavachallenge_mortes", "int"), + + //REGISTRO START + REGISTRO_SENHA("", "String", "senha", "VARCHAR(150)"), + REGISTRO_DATA("", "String", "registrado", "VARCHAR(25)"), + //REGISTRO END + + //PREFERENCIAS START + RECEIVE_PRIVATE_MESSAGES(true, "Boolean", "receiveMessages", "boolean"), + RECEIVE_STAFFCHAT_MESSAGES(true, "Boolean", "receiveStaffchatMessages", "boolean"), + RECEIVE_REPORTS(true, "Boolean", "receiveReports", "boolean"), + PLAYERS_VISIBILITY(true, "Boolean", "playersVisibility", "boolean"), + ANNOUNCEMENT_JOIN(true, "Boolean", "announcementJoin", "boolean"), + CLAN_TAG_DISPLAY(true, "Boolean", "clanTagDisplay", "boolean"); + //PREFERENCIAS END; + + private final Object defaultValue; + private final String classExpected; + private final String field; + private final String tableType; + + DataType(Object defaultValue, String classExpected, String field, String tableType) { + this.defaultValue = defaultValue; + this.field = field; + this.classExpected = classExpected; + this.tableType = tableType; + } + + public static DataType getDataTypeByField(String field) { + DataType finded = null; + + for (DataType datas : DataType.values()) { + if (datas.getField().equalsIgnoreCase(field)) { + finded = datas; + break; + } + } + + return finded; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/group/Groups.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/group/Groups.java new file mode 100644 index 0000000..90c2c2d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/group/Groups.java @@ -0,0 +1,96 @@ +package com.br.guilhermematthew.nowly.commons.common.group; + +import com.br.guilhermematthew.nowly.commons.common.tag.Tag; +import lombok.Getter; + +import java.util.Arrays; +import java.util.List; + +@Getter +public enum Groups { + + MEMBRO(new Tag("Membro", "", "§7", "Default")), + + VIP(new Tag("VIP", "VIP", "§a")), + PRO(new Tag("Pro", "PRO", "§6")), + ULTRA(new Tag("Ultra", "ULTRA", "§d")), + LEAGUE(new Tag("League", "LEAGUE", "§a")), + BETA(new Tag("Beta", "BETA", "§1")), + + PARTNER(new Tag("Partner", "PARTNER", "§b")), + STREAMER(new Tag("Streamer", "STREAMER", "§3", "stream")), + YOUTUBER(new Tag("Youtuber", "YT", "§b", "YT")), + PRIME(new Tag("Prime", "Prime", "§3", "prime", "yt+", "ytplus")), + TRIAL(new Tag("Trial", "TRIAL", "§d", "TRIAL")), + MOD(new Tag("Mod", "MOD", "§5", "moderador")), + MOD_PLUS(new Tag("Mod+", "MOD+", "§5", "moderador+")), + DEVELOPER(new Tag("Developer", "DEV", "§4", "Dev", "Desenvolvedor")), + + ADMIN(new Tag("Admin", "ADMIN", "§4", "adm", "Administrador")); + + private final Tag tag; + private List permissions; + + Groups(Tag tag, List permissions) { + this.tag = tag; + this.permissions = permissions; + } + + Groups(Tag tag, String... permissions) { + this.tag = tag; + this.permissions = Arrays.asList(permissions); + } + + public static Groups getGroup(String name) { + Groups groupFinded = MEMBRO; + + for (Groups groups : values()) { + if (groups.getTag().getName().equalsIgnoreCase(name)) { + groupFinded = groups; + break; + } + for (String aliases : groups.getTag().getAliases()) { + if (aliases.equalsIgnoreCase(name)) { + groupFinded = groups; + break; + } + } + } + + return groupFinded; + } + + public static Boolean existGrupo(String grupo) { + boolean existe = false; + + for (Groups groups : values()) { + if (groups.getTag().getName().equalsIgnoreCase(grupo)) { + existe = true; + break; + } + for (String aliases : groups.getTag().getAliases()) { + if (aliases.equalsIgnoreCase(grupo)) { + existe = true; + break; + } + } + } + return existe; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + public int getLevel() { + return getTag().getLevel(); + } + + public String getColor() { + return getTag().getColor(); + } + + public String getName() { + return getTag().getName(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.java new file mode 100644 index 0000000..8fd8f05 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.java @@ -0,0 +1,135 @@ +package com.br.guilhermematthew.nowly.commons.common.profile; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.data.Data; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.profile.token.AcessToken; +import com.br.guilhermematthew.nowly.commons.common.profile.token.AcessTokenListener; +import com.br.guilhermematthew.nowly.commons.common.punishment.PunishmentHistoric; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import lombok.Getter; +import lombok.Setter; +import net.md_5.bungee.api.chat.BaseComponent; + +import java.util.UUID; + +@Getter +@Setter +public class GamingProfile { + + private String nick; + private UUID uniqueId; + private String address; + + private DataHandler dataHandler; + + private AcessToken acessToken; + private AcessTokenListener tokenListener; + + private PunishmentHistoric punishmentHistoric; + + public GamingProfile(final String nick, final String address, final UUID uniqueId) { + this.nick = nick; + this.uniqueId = uniqueId; + this.address = address; + + this.dataHandler = new DataHandler(nick, uniqueId); + } + + public GamingProfile(final String nick, final UUID uniqueId) { + this(nick, "Unknown", uniqueId); + } + + public Groups getGroup() { + return Groups.getGroup(getString(DataType.GROUP)); + } + + public boolean isStaffer() { + return getGroup().getLevel() >= Groups.PRIME.getLevel(); + } + + public boolean isVIP() { + return getGroup().getLevel() > Groups.MEMBRO.getLevel(); + } + + public void sendPacket(final CommonPacket packet) { + if (!CommonsGeneral.getPluginInstance().isBukkit()) return; + + Client.getInstance().getClientConnection().sendPacket(packet); + } + + public PunishmentHistoric getPunishmentHistoric() { + if (punishmentHistoric == null) { + this.punishmentHistoric = new PunishmentHistoric(getNick(), getAddress()); + } + return punishmentHistoric; + } + + public boolean isExpired(final DataType dataType) { + return isExpired(false, dataType); + } + + public boolean isExpired(boolean update, final DataType dataType) { + if (getLong(dataType) != 0L) { + if (System.currentTimeMillis() > getLong(dataType)) { + if (update) { + getData(dataType).setValue(0L); + } + return true; + } + } + return false; + } + + public boolean containsFake() { + return !getString(DataType.FAKE).equals(""); + } + + public Data getData(DataType dataType) { + return getDataHandler().getData(dataType); + } + + public int getInt(DataType dataType) { + return getDataHandler().getInt(dataType); + } + + public String getIntFormatted(DataType dataType) { + return StringUtility.formatValue(getDataHandler().getInt(dataType)); + } + + public String getString(DataType dataType) { + return getDataHandler().getString(dataType); + } + + public Boolean getBoolean(DataType dataType) { + return getDataHandler().getBoolean(dataType); + } + + public Long getLong(DataType dataType) { + return getDataHandler().getLong(dataType); + } + + public void remove(DataType dataType) { + remove(dataType, 1); + } + + public void remove(DataType dataType, int value) { + getDataHandler().getData(dataType).remove(value); + } + + public void add(DataType dataType) { + add(dataType, 1); + } + + public void add(DataType dataType, int value) { + getDataHandler().getData(dataType).add(value); + } + + public void set(DataType dataType, Object value) { + getDataHandler().getData(dataType).setValue(value); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.java new file mode 100644 index 0000000..2e5c223 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.java @@ -0,0 +1,45 @@ +package com.br.guilhermematthew.nowly.commons.common.profile; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; + +import java.util.Collection; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +public class ProfileManager { + + private final Map profiles = new ConcurrentHashMap<>(); + + public void addGamingProfile(final UUID uniqueId, final GamingProfile profile) { + profiles.put(uniqueId, profile); + } + + public void removeGamingProfile(final UUID uniqueId) { + profiles.remove(uniqueId); + } + + public GamingProfile getGamingProfile(final String nick) { + UUID uniqueId = CommonsGeneral.getUUIDFetcher().getOfflineUUID(nick); + + if (containsProfile(uniqueId)) return getGamingProfile(uniqueId); + + return null; + } + + public GamingProfile getGamingProfile(final UUID uniqueId) { + return profiles.get(uniqueId); + } + + public boolean containsProfile(final UUID uniqueId) { + return profiles.containsKey(uniqueId); + } + + public Collection getGamingProfiles() { + return profiles.values(); + } + + public boolean containsProfile(String name) { + return containsProfile(CommonsGeneral.getUUIDFetcher().getOfflineUUID(name)); + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.java new file mode 100644 index 0000000..0352881 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.java @@ -0,0 +1,90 @@ +package com.br.guilhermematthew.nowly.commons.common.profile.addons; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum League { + + BronzeI("§7", "I✯", "Bronze I", 1000), + BronzeII("§7", "II✯", "Bronze II", 2000), + BronzeIII("§7", "III✯", "Bronze III", 3000), + BronzeIV("§7", "IV✯", "Bronze IV", 3500), + BronzeV("§7", "V✯", "Bronze V", 4000), + + GoldI("§6", "I✻", "Gold I", 4500), + GoldII("§6", "II✻", "Gold II", 5800), + GoldIII("§6", "III✻", "Gold III", 7000), + GoldIV("§6", "IV✻", "Gold IV", 10000), + GoldV("§6", "V✻", "Gold V", 13000), + + PlatinumI("§3", "I❖", "Platinum I", 17000), + PlatinumII("§3", "II❖", "Platinum II", 20000), + PlatinumIII("§3", "III❖", "Platinum III", 25000), + PlatinumIV("§3", "IV❖", "Platinum IV", 28000), + PlatinumV("§3", "V❖", "Platinum V", 30000), + + DiamondI("§b", "I❆", "Diamond I", 33000), + DiamondII("§b", "II❆", "Diamond II", 35000), + DiamondIII("§b", "III❆", "Diamond III", 40000), + DiamondIV("§b", "IV❆", "Diamond IV", 46000), + DiamondV("§b", "V❆", "Diamond IV", 50000), + + EnderloreI("§5", "I✦", "Enderlore I", 53000), + EnderloreII("§5", "II✦", "Enderlore II", 56000), + EnderloreIII("§5", "III✦", "Enderlore III", 58000), + EnderloreIV("§5", "IV✦", "Enderlore IV", 60000), + EnderloreV("§5", "IV✦", "Enderlore V", 63000), + + ImmortalI("§c", "I✿", "Immortal I", 67000), + ImmortalII("§c", "II✿", "Immortal II", 70000), + ImmortalIII("§c", "III✿", "Immortal III", 73000), + ImmortalIV("§c", "IV✿", "Immortal IV", 75000), + Champion("§4", "❂", "Champion", 80000); + + private String color, symbol, name; + private int experience; + + public static League getRanking(String ligaNome) { + League liga = League.BronzeI; + + for (League rank : values()) { + if (rank.getName().equalsIgnoreCase(ligaNome)) { + liga = rank; + break; + } + } + return liga; + } + + public static League getRanking(int xp) { + if (xp >= Champion.getExperience()) return ImmortalIV; + if (xp < BronzeI.getExperience()) return BronzeI; + + League liga = BronzeI; + for (League rank : values()) { + if (xp <= rank.experience && xp > rank.getMin()) { + liga = rank; + } + } + return liga; + } + + public int getMin() { + int min = 0; + + if (this.ordinal() > 0) min = League.values()[this.ordinal() - 1].getExperience(); + + return min; + } + + public League getPreviousLeague() { + return this == BronzeI ? BronzeI : League.values()[ordinal() - 1]; + } + + public League getNextLeague() { + return this == Champion ? Champion : League.values()[ordinal() + 1]; + } + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.java new file mode 100644 index 0000000..e2ae631 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.java @@ -0,0 +1,72 @@ +package com.br.guilhermematthew.nowly.commons.common.profile.addons; + +import lombok.Getter; + +@Getter +public enum Medals { + + BETA(1, "BETA", "§e", "❝"), + CAFE(2, "CAFE", "§8", "☕"); + + @Getter + private final int id; + + @Getter + private final String name; + @Getter + private final String color; + @Getter + private final String symbol; + + Medals(int id, String name, String color, String symbol) { + this.id = id; + this.name = name; + this.color = color; + this.symbol = symbol; + } + + public static Medals getMedalById(int id) { + if (id == 0) return null; //FAST RESULT + + Medals medal = null; + + for (Medals medals : values()) { + if (medals.getId() == id) { + medal = medals; + break; + } + } + + return medal; + } + + public static Medals getMedalByName(String name) { + Medals medal = null; + + for (Medals medals : values()) { + if (medals.getName().equalsIgnoreCase(name)) { + medal = medals; + break; + } + if (medals.getName().startsWith(name)) { + medal = medals; + break; + } + } + + return medal; + } + + public static Boolean existMedal(String name) { + boolean existe = false; + + for (Medals medals : values()) { + if (medals.getName().equalsIgnoreCase(name)) { + existe = true; + break; + } + } + + return existe; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.java new file mode 100644 index 0000000..f0d6183 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.java @@ -0,0 +1,6 @@ +package com.br.guilhermematthew.nowly.commons.common.profile.token; + +public enum AcessToken { + + ACCEPTED, REJECTED +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.java new file mode 100644 index 0000000..9ae80a6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.java @@ -0,0 +1,6 @@ +package com.br.guilhermematthew.nowly.commons.common.profile.token; + +public interface AcessTokenListener { + + void onAcessToken(AcessToken acessToken); +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.java new file mode 100644 index 0000000..3472c4b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.java @@ -0,0 +1,147 @@ +package com.br.guilhermematthew.nowly.commons.common.punishment; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Ban; +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Mute; +import com.google.gson.JsonObject; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class PunishmentHistoric { + + private final String nick; + private final String address; + + private final List banHistory; + private final List muteHistory; + + public PunishmentHistoric(final String nick, final String address) { + this.banHistory = new ArrayList<>(); + this.muteHistory = new ArrayList<>(); + + this.nick = nick; + this.address = address; + } + + public PunishmentHistoric(final String nick) { + this(nick, ""); + } + + public void loadMutes() throws SQLException { + this.muteHistory.clear(); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + + PreparedStatement preparedStatement = connection + .prepareStatement("SELECT * FROM mutes WHERE nick='" + getNick() + "'"); + + ResultSet result = preparedStatement.executeQuery(); + + while (result.next()) { + JsonObject json = CommonsConst.PARSER.parse(result.getString("data")).getAsJsonObject(); + + this.muteHistory.add(new Mute(result.getString("nick"), json.get("mutedBy").getAsString(), + json.get("motive").getAsString(), json.get("mutedDate").getAsString(), + + json.get("unmutedBy").getAsString(), json.get("unmutedDate").getAsString(), + + json.get("punishmentTime").getAsLong(), json.get("unmutedTime").getAsLong())); + + json = null; + } + + result.close(); + preparedStatement.close(); + + result = null; + preparedStatement = null; + + } + } + + public void loadBans() throws SQLException { + loadBans(false); + } + + public void loadBans(boolean fromAddress) throws SQLException { + this.banHistory.clear(); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM bans WHERE " + + (fromAddress ? "address='" + getAddress() : "nick='" + getNick()) + "'"); + + ResultSet result = preparedStatement.executeQuery(); + + int FINDEDS = 0; + + while (result.next()) { + JsonObject json = CommonsConst.PARSER.parse(result.getString("data")).getAsJsonObject(); + + this.banHistory.add(new Ban(result.getString("nick"), result.getString("address"), + json.get("bannedBy").getAsString(), json.get("motive").getAsString(), + json.get("bannedDate").getAsString(), + + json.get("unbannedBy").getAsString(), json.get("unbannedDate").getAsString(), + + json.get("punishmentTime").getAsLong(), json.get("unbannedTime").getAsLong())); + + json = null; + FINDEDS++; + } + + preparedStatement.close(); + result.close(); + + preparedStatement = null; + result = null; + + if (FINDEDS == 0 && !fromAddress) { + loadBans(true); + } + } + } + + public Ban getActualBan() { + for (Ban ban : banHistory) { + if (!ban.isPunished()) + continue; + if (ban.isExpired()) + continue; + return ban; + } + return null; + } + + public Mute getActualMute() { + for (Mute mute : muteHistory) { + if (!mute.isPunished()) + continue; + if (mute.isExpired()) + continue; + return mute; + } + return null; + } + + public List getBanHistory() { + return banHistory; + } + + public List getMuteHistory() { + return muteHistory; + } + + public String getNick() { + return nick; + } + + public String getAddress() { + return address; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.java new file mode 100644 index 0000000..519fe0b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.java @@ -0,0 +1,56 @@ +package com.br.guilhermematthew.nowly.commons.common.punishment; + +import com.br.guilhermematthew.nowly.commons.common.punishment.types.Ban; +import com.br.guilhermematthew.nowly.commons.common.utility.Cache; +import com.google.common.collect.Lists; + +import java.util.HashMap; +import java.util.List; + +public class PunishmentManager { + + private static final HashMap CACHE = new HashMap<>(); + + public static Ban getBanCache(String nick) { + if (CACHE.containsKey(nick.toLowerCase())) { + return (Ban) CACHE.get(nick.toLowerCase()).getValue1(); + } + + return null; + } + + public static void addCache(String nick, Ban ban) { + CACHE.put(nick.toLowerCase(), new Cache(nick, ban, 1)); + } + + public static void removeCache(String nick) { + CACHE.remove(nick.toLowerCase()); + } + + public static void checkCache() { + checkCache(null); + } + + public static void checkCache(Runnable callback) { + List keys = Lists.newArrayList(); + + for (Cache cache : CACHE.values()) { + if (cache.isExpired()) { + keys.add(cache.getName()); + } + } + + if (keys.size() != 0) { + for (String key : keys) { + CACHE.remove(key); + } + } + + keys.clear(); + keys = null; + + if (callback != null) { + callback.run(); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.java new file mode 100644 index 0000000..6ece8c6 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.java @@ -0,0 +1,129 @@ +package com.br.guilhermematthew.nowly.commons.common.punishment.types; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.google.gson.JsonObject; +import lombok.Getter; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +@Getter +public class Ban { + + private final String nick; + private final String address; + + private final String bannedBy; + private final String motive; + private String bannedDate; + private final long punishmentTime; + + private String unbannedBy; + private String unbannedDate; + private long unbannedTime; + + private boolean punished; + + public Ban(final String nick, final String address, final String bannedBy, final String motive, final long punishmentTime) { + this.nick = nick; + this.address = address; + + this.bannedBy = bannedBy; + this.motive = motive; + this.punishmentTime = punishmentTime; + + this.unbannedBy = ""; + this.unbannedDate = ""; + this.unbannedTime = 0L; + } + + public Ban(final String nick, final String address, final String bannedBy, final String motive, final String bannedDate, + final String unbannedBy, final String unbannedDate, final long punishmentTime, final long unbannedTime) { + this.nick = nick; + this.address = address; + + this.bannedBy = bannedBy; + this.motive = motive; + this.bannedDate = bannedDate; + this.punishmentTime = punishmentTime; + + this.unbannedBy = unbannedBy; + this.unbannedDate = unbannedDate; + this.unbannedTime = unbannedTime; + } + + public void ban() { + if (!this.punished) { + this.punished = true; + + this.bannedDate = DateUtils.getActualDate(false); + + CommonsGeneral.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection.prepareStatement( + "INSERT INTO bans(nick, address, data) VALUES (?, ?, ?);"); + + insert.setString(1, this.nick); + insert.setString(2, this.address); + insert.setString(3, buildData()); + insert.execute(); + + insert.close(); + insert = null; + } catch (SQLException ex) { + CommonsGeneral.error("ban() : Ban.java -> " + ex.getLocalizedMessage()); + } + }); + } + } + + private String buildData() { + JsonObject json = new JsonObject(); + + json.addProperty("bannedBy", bannedBy); + json.addProperty("motive", motive); + json.addProperty("bannedDate", bannedDate); + json.addProperty("punishmentTime", punishmentTime); + + json.addProperty("unbannedBy", unbannedBy); + json.addProperty("unbannedDate", unbannedDate); + json.addProperty("unbannedTime", unbannedTime); + + return json.toString(); + } + + public void unban(final String unbannedBy) { + if (this.punished) { + this.punished = false; + + this.unbannedBy = unbannedBy; + this.unbannedDate = DateUtils.getActualDate(false); + this.unbannedTime = System.currentTimeMillis(); + + CommonsGeneral.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection.prepareStatement( + "UPDATE bans SET data=? WHERE nick='" + getNick() + "'"); + + insert.setString(1, buildData()); + insert.execute(); + + insert.close(); + insert = null; + } catch (SQLException ex) { + CommonsGeneral.error("unban() : Ban.java -> " + ex.getLocalizedMessage()); + } + }); + } + } + + public boolean isExpired() { + return !isPermanent() && getPunishmentTime() < System.currentTimeMillis(); + } + + public boolean isPermanent() { + return getPunishmentTime() == 0; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.java new file mode 100644 index 0000000..d991d40 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.java @@ -0,0 +1,127 @@ +package com.br.guilhermematthew.nowly.commons.common.punishment.types; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.google.gson.JsonObject; +import lombok.Getter; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +@Getter +public class Mute { + + private final String nick; + + private final String mutedBy; + private final String motive; + private String mutedDate; + private final long punishmentTime; + + private String unmutedBy; + private String unmutedDate; + private long unmutedTime; + + private boolean punished; + + public Mute(final String nick, final String mutedBy, final String motive, final long punishmentTime) { + this.nick = nick; + + this.mutedBy = mutedBy; + this.motive = motive; + this.punishmentTime = punishmentTime; + + this.unmutedBy = ""; + this.unmutedDate = ""; + this.unmutedTime = 0L; + } + + public Mute(final String nick, final String mutedBy, final String motive, final String mutedDate, + final String unmutedBy, final String unmutedDate, final long punishmentTime, final long unmutedTime) { + this.nick = nick; + + this.mutedBy = mutedBy; + this.motive = motive; + this.mutedDate = mutedDate; + this.punishmentTime = punishmentTime; + + this.unmutedBy = unmutedBy; + this.unmutedDate = unmutedDate; + this.unmutedTime = unmutedTime; + } + + public void mute() { + if (!this.punished) { + this.punished = true; + + this.mutedDate = DateUtils.getActualDate(false); + + CommonsGeneral.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection + .prepareStatement("INSERT INTO mutes(nick, data) VALUES (?, ?);"); + + insert.setString(1, this.nick); + insert.setString(2, buildData()); + + insert.execute(); + + insert.close(); + insert = null; + } catch (SQLException ex) { + CommonsGeneral.error("mute() : Mute.java -> " + ex.getLocalizedMessage()); + } + }); + } + } + + private String buildData() { + JsonObject json = new JsonObject(); + + json.addProperty("mutedBy", mutedBy); + json.addProperty("motive", motive); + json.addProperty("mutedDate", mutedDate); + json.addProperty("punishmentTime", punishmentTime); + + json.addProperty("unmutedBy", unmutedBy); + json.addProperty("unmutedDate", unmutedDate); + json.addProperty("unmutedTime", unmutedTime); + + return json.toString(); + } + + public void unmute(final String unmutedBy) { + if (this.punished) { + this.punished = false; + + this.unmutedBy = unmutedBy; + this.unmutedDate = DateUtils.getActualDate(false); + this.unmutedTime = System.currentTimeMillis(); + + CommonsGeneral.runAsync(() -> { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection + .prepareStatement("UPDATE mutes SET data=? WHERE nick='" + getNick() + "'"); + + insert.setString(1, buildData()); + insert.execute(); + + insert.close(); + + insert = null; + } catch (SQLException ex) { + CommonsGeneral.error("unmute() : Mute.java -> " + ex.getLocalizedMessage()); + } + }); + } + } + + public boolean isExpired() { + return !isPermanent() && getPunishmentTime() < System.currentTimeMillis(); + } + + public boolean isPermanent() { + return getPunishmentTime() == 0; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.java new file mode 100644 index 0000000..ddc183c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.java @@ -0,0 +1,151 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo; + +import lombok.Getter; + +import java.util.Arrays; +import java.util.List; + +@Getter +public enum ServerType { + + BUNGEECORD("BungeeCord", 2), + LOGIN("Login", 2), + LOBBY("Lobby", 2, "hub"), + LOBBY_HARDCOREGAMES("LobbyHardcoreGames", 2, "LobbyHG", "lhg", "hubhg"), + LOBBY_PVP("LobbyPvP", 2, "lpvp", "hubpvp", "LobbyPvP"), + LOBBY_DUELS("LobbyDuels", 2, "lduel", "LobbyDuels", "hubduel"), + + DUELS_GLADIATOR("Gladiator", 2, "glad", "glading"), + DUELS_SIMULATOR("Simulator", 2, "sim", "simulation"), + + PARTY_GAMES("PartyGames", 2, "pgames", "party", "gamesparty"), + + PVP_ARENA("Arena", 2), + PVP_FPS("FPS", 2), + PVP_LAVACHALLENGE("LavaChallenge", 2), + + GLADIATOR("Gladiator", 3, "glad"), + + HARDCORE_GAMES("HardcoreGames", 2, "hg", "HungerGames"), + CHAMPIONS("Champions", 3, "champions", "champion"), + EVENTO("Evento", 3, "evnt", "evento"), + SKYWARS("SkyWars", 2, "sw"), + BEDWARS("BedWars", 2, "bw"), + THEBRIDGE("TheBridge", 2, "tb"), + + UNKNOWN("Unknown"); + + private final String name; + private final List aliases; + private final int secondsToStabilize; + private final int secondsUpdateStatus; + + ServerType(String name, int secondsToStabilize, int secondsUpdateStatus, String... aliases) { + this.name = name; + this.aliases = Arrays.asList(aliases); + this.secondsToStabilize = secondsToStabilize; + this.secondsUpdateStatus = secondsUpdateStatus; + } + + ServerType(String name, int secondsToStabilize) { + this(name, secondsToStabilize, 2, "Unknown"); + } + + ServerType(String name) { + this(name, 3, 2, "Unknown"); + } + + ServerType(String name, String... aliases) { + this(name, 3, 2, aliases); + } + + ServerType(String name, int secondsUpdateStatus, String... aliases) { + this(name, 3, secondsUpdateStatus, aliases); + } + + public static ServerType getServer(String serverName) { + serverName = serverName.replaceAll("\\d", ""); + + ServerType finded = ServerType.UNKNOWN; + + for (ServerType servers : ServerType.values()) { + if (servers.getName().equalsIgnoreCase(serverName)) { + finded = servers; + break; + } + if (servers.containsAlias(serverName)) { + finded = servers; + break; + } + if (servers.getName().startsWith(serverName)) { + finded = servers; + break; + } + } + return finded; + } + + public boolean useActionItem() { + if (isLobby()) return true; + if (this == SKYWARS) return true; + if (isPvP()) return true; + if (this == GLADIATOR) return true; + return isHardcoreGames(); + } + + public boolean useMenuListener() { + if (isLobby()) return true; + if (this == SKYWARS) return true; + if (isPvP()) return true; + return isHardcoreGames(); + } + + public boolean isLobby() { + return this.getName().startsWith("Lobby"); + } + + public boolean isPvP() { + return isPvP(false); + } + + public boolean isPvP(boolean lobby) { + if (lobby) { + if (this == LOBBY_PVP) { + return true; + } + } + return this == PVP_ARENA || this == PVP_FPS || this == PVP_LAVACHALLENGE; + } + + public boolean isHardcoreGames() { + return isHardcoreGames(false); + } + + public boolean isHardcoreGames(boolean lobby) { + if (lobby) { + if (this == LOBBY_HARDCOREGAMES) { + return true; + } + } + return this == HARDCORE_GAMES || this == EVENTO || this == CHAMPIONS; + } + + public boolean containsAlias(String serverName) { + if (getAliases() == null) return false; + + boolean finded = false; + + for (String alias : getAliases()) { + if (alias.equalsIgnoreCase(serverName)) { + finded = true; + break; + } + } + + return finded; + } + + public boolean useSuffixRank() { + return isPvP(true) || isHardcoreGames(true); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.java new file mode 100644 index 0000000..23db678 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.java @@ -0,0 +1,194 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.google.gson.JsonObject; + +import java.util.*; + +public class ServersManager { + + private final int HARDCOREGAMES_SERVIDORES = 6; + private Map serverMap; + + public void init() { + this.serverMap = new HashMap<>(); + + registerServers( + new NetworkServer(ServerType.LOBBY), + new NetworkServer(ServerType.LOBBY_DUELS), + new NetworkServer(ServerType.LOBBY_PVP), + new NetworkServer(ServerType.LOBBY_HARDCOREGAMES), + new NetworkServer(ServerType.LOGIN), + + new NetworkServer(ServerType.BUNGEECORD), + + new NetworkServer(ServerType.DUELS_SIMULATOR), + new NetworkServer(ServerType.DUELS_GLADIATOR), + + new NetworkServer(ServerType.PVP_ARENA), + new NetworkServer(ServerType.PVP_FPS), + new NetworkServer(ServerType.PVP_LAVACHALLENGE), + new NetworkServer(ServerType.GLADIATOR)); + + for (int i = 1; i <= HARDCOREGAMES_SERVIDORES; i++) { + registerServer(new GameServer(ServerType.HARDCORE_GAMES, i)); + } + + registerServer(new GameServer(ServerType.CHAMPIONS, 1)); + registerServer(new GameServer(ServerType.EVENTO, 1)); + } + + public NetworkServer getServerByType(final ServerType serverType) { + return getServerByType(serverType, 1); + } + + public NetworkServer getServerByType(final ServerType serverType, int serverId) { + NetworkServer server = serverMap.getOrDefault(serverType.getName().toLowerCase() + "-" + serverId, null); + + if (server == null) { + for (NetworkServer servers : serverMap.values()) { + if (servers.getServerType() == serverType && servers.getServerId() == serverId) { + server = servers; + break; + } + } + } + + return server; + } + + public void registerServers(final NetworkServer... servers) { + for (NetworkServer server : servers) + registerServer(server); + } + + public NetworkServer getNetworkServer(final String name) { + return getNetworkServer(name, 1); + } + + public NetworkServer getNetworkServer(final String name, final int id) { + return serverMap.get(name.toLowerCase() + "-" + id); + } + + public NetworkServer getNetworkServer(final ServerType type, final int id) { + return getNetworkServer(type.getName(), id); + } + + public void registerServer(final NetworkServer server) { + serverMap.put(server.getServerType().getName().toLowerCase() + "-" + server.getServerId(), server); + } + + public NetworkServer getServer(final String serverId) { + return serverMap.getOrDefault(serverId.toLowerCase(), null); + } + + public List getServersList(ServerType serverType) { + List servers = new ArrayList<>(); + + for (NetworkServer networkServer : serverMap.values()) { + if (networkServer.getServerType() == serverType) { + servers.add(networkServer); + } + } + + return servers; + } + + public Collection getServers() { + return serverMap.values(); + } + + public int getAmountOnNetwork() { + return getNetworkServer("bungeecord").getOnlines(); + } + + public void sendRequireUpdate() { + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(). + type(PacketType.BUKKIT_SEND_INFO).field("require-servers-info")); + } + + public void updateServerData(JsonObject json) { + ServerType serverType = ServerType.getServer(json.get("serverType").getAsString()); + int serverId = json.get("serverID").getAsInt(); + updateServerData(serverType, serverId, json); + } + + public void updateServerData(ServerType serverType, int serverId, JsonObject json) { + if (serverType != ServerType.UNKNOWN) { + if (serverType.isHardcoreGames(false)) { + getHardcoreGamesServer(serverType.getName(), serverId).updateData(json); + } else if (serverType == ServerType.BEDWARS) { + // getNetworkServer(serverType.getName(), serverId).update(json); + } else { + getNetworkServer(serverType.getName(), serverId).update(json); + } + } + } + + public int getAmountOnlinePvP(boolean getLobby) { + int onlines = 0; + + onlines += getNetworkServer("arena").getOnlines(); + onlines += getNetworkServer("fps").getOnlines(); + onlines += getNetworkServer("lavachallenge").getOnlines(); + + if (getLobby) { + onlines += getNetworkServer("lobbypvp").getOnlines(); + } + return onlines; + } + + public int getAmountOnlineDuels(boolean getLobby) { + int onlines = 0; + + onlines += getNetworkServer("gladiator").getOnlines(); + onlines += getNetworkServer("simulator").getOnlines(); + if (getLobby) { + onlines += getNetworkServer("LobbyDuels").getOnlines(); + } + return onlines; + } + + public int getAmountOnlineHardcoreGames(boolean getLobby) { + int onlines = 0; + + for (GameServer server : getHardcoreGamesServers()) { + onlines += server.getOnlines(); + } + + if (getLobby) { + onlines += getNetworkServer("lobbyhardcoregames").getOnlines(); + } + return onlines; + } + + public GameServer getGameServer(String text) { + return (GameServer) getServer(text); + } + + public List getHardcoreGamesServers() { + List list = new ArrayList<>(); + + for (int i = 1; i <= HARDCOREGAMES_SERVIDORES; i++) { + list.add(getHardcoreGamesServer(i)); + } + + return list; + } + + public GameServer getGameServer(ServerType serverType, int serverId) { + return (GameServer) getServer(serverType.getName().toLowerCase() + "-" + serverId); + } + + public GameServer getHardcoreGamesServer(int id) { + return (GameServer) getServer("hardcoregames" + "-" + id); + } + + public GameServer getHardcoreGamesServer(String name, int id) { + return (GameServer) getServer(name + "-" + id); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.java new file mode 100644 index 0000000..92e9bce --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.java @@ -0,0 +1,40 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo.enums; + +public enum GameStages { + + UNKNOWN(0, "Unknown"), + LOADING(1, "Carregando"), + WAITING(2, "Waiting"), + INVINCIBILITY(3, "Invincibility"), + PLAYING(4, "Playing"), + END(5, "End"), + OFFLINE(0, "Offline"); + + private final String nome; + private final int id; + + GameStages(final int id, final String nome) { + this.nome = nome; + this.id = id; + } + + public static GameStages getStage(String nome) { + GameStages finded = GameStages.UNKNOWN; + + for (GameStages estagios : GameStages.values()) { + if (nome.equalsIgnoreCase(estagios.getNome())) { + finded = estagios; + break; + } + } + return finded; + } + + public String getNome() { + return nome; + } + + public int getId() { + return id; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.java new file mode 100644 index 0000000..7211b95 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.java @@ -0,0 +1,18 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo.enums; + +public enum GameType { + + UNKNOWN("Unknown"), + SOLO("Solo"), + DUO("Duo"); + + private final String name; + + GameType(final String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.java new file mode 100644 index 0000000..ef2ad9c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.java @@ -0,0 +1,54 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo.types; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameType; +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class GameServer extends NetworkServer { + + private int playersGaming; + private int tempo; + private GameStages stage; + private String mapName; + private GameType gameType; + + public GameServer(ServerType serverType, int serverId) { + super(serverType, serverId); + + this.playersGaming = 0; + this.tempo = 0; + this.stage = GameStages.OFFLINE; + this.mapName = "Unknown"; + this.gameType = GameType.UNKNOWN; + } + + public void updateData(final JsonObject json) { + update(json); + + setGameType(json.has("gameType") + ? (json.get("gameType").getAsString().equalsIgnoreCase("SOLO") ? GameType.SOLO : GameType.DUO) + : GameType.UNKNOWN); + + setMapName(json.has("mapName") ? json.get("mapName").getAsString() : "Unknown"); + setPlayersGaming(json.has("playersGaming") ? json.get("playersGaming").getAsInt() : 0); + setTempo(json.has("tempo") ? json.get("tempo").getAsInt() : 0); + setStage(json.has("stage") ? GameStages.getStage(json.get("stage").getAsString()) : GameStages.OFFLINE); + } + + public JsonObject toJsonGame() { + JsonObject json = toJson(); + + json.addProperty("playersGaming", getPlayersGaming()); + json.addProperty("tempo", getTempo()); + json.addProperty("stage", getStage().getNome()); + json.addProperty("mapName", getMapName()); + json.addProperty("gameType", getGameType().getName()); + + return json; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.java new file mode 100644 index 0000000..c9d4fb3 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.java @@ -0,0 +1,84 @@ +package com.br.guilhermematthew.nowly.commons.common.serverinfo.types; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class NetworkServer { + + private ServerType serverType; + private int maxPlayers, onlines, membersSlots, serverId, sequence; + private boolean online, whiteList; + private Long lastUpdate; + + public NetworkServer(ServerType serverType, int serverId) { + this.serverId = serverId; + this.serverType = serverType; + + this.maxPlayers = 80; + this.onlines = 0; + this.sequence = 0; + + this.membersSlots = 80; + + this.online = false; + this.whiteList = false; + + this.lastUpdate = 0L; + } + + public NetworkServer(ServerType serverType) { + this(serverType, 1); + } + + public void update(final JsonObject json) { + setOnlines(json.has("onlines") ? json.get("onlines").getAsInt() : 0); + setMembersSlots(json.has("memberSlots") ? json.get("memberSlots").getAsInt() : 80); + setMaxPlayers(json.has("maxPlayers") ? json.get("maxPlayers").getAsInt() : 80); + setWhiteList(json.has("whiteList") && json.get("whiteList").getAsBoolean()); + setOnline(json.has("online") && json.get("online").getAsBoolean()); + + if (json.has("lastUpdate") && isOnline()) { + final Long now = json.get("lastUpdate").getAsLong(); + + if (now == -1L) { + setOnline(false); + setOnlines(0); + setSequence(10); + } + + if (now.equals(getLastUpdate())) { + setSequence(getSequence() + 1); + if (getSequence() > 8) { + setOnline(false); + } + } else { + setLastUpdate(now); + setSequence(0); + setOnline(true); + } + } + + if (!isOnline()) { + setOnlines(0); + } + } + + public JsonObject toJson() { + JsonObject json = new JsonObject(); + + json.addProperty("onlines", getOnlines()); + json.addProperty("maxPlayers", getMaxPlayers()); + + json.addProperty("online", isOnline()); + json.addProperty("whiteList", isWhiteList()); + json.addProperty("lastUpdate", getLastUpdate()); + + json.addProperty("membersSlots", getMembersSlots()); + + return json; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/tag/Tag.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/tag/Tag.java new file mode 100644 index 0000000..99cbfcc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/tag/Tag.java @@ -0,0 +1,41 @@ +package com.br.guilhermematthew.nowly.commons.common.tag; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Tag { + + public static final char[] chars = new char[]{'1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; + public static int globalLevels = 0; + private String name, prefix, color, teamCharacter; + private int level; + private String[] aliases; + + public Tag(final String name, final String prefix, final String color, final String... aliases) { + this.name = name; + this.prefix = prefix; + this.color = color; + + this.aliases = aliases; + + globalLevels++; + this.level = globalLevels; + this.teamCharacter = chars[33 - globalLevels] + ""; + } + + public Tag(final String name, final String prefix, final String color) { + this(name, prefix, color, name); + } + + public Tag(final String name, final String prefix) { + this(name, prefix, prefix, name); + } + + public boolean hasPrefix() { + return !prefix.isEmpty() && prefix.length() > 1; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/Cache.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/Cache.java new file mode 100644 index 0000000..c18aaac --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/Cache.java @@ -0,0 +1,76 @@ +package com.br.guilhermematthew.nowly.commons.common.utility; + +import lombok.Getter; +import lombok.Setter; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +@Getter +@Setter +public class Cache { + + private String name; + + private Object value1; + private Object value2; + + private long createdTime; + private long expireAfter; + private int used; + + public Cache(String name, Object value1, Object value2, int expireAfter) { + this.name = name; + this.value1 = value1; + this.value2 = value2; + this.createdTime = System.currentTimeMillis(); + this.used = 0; + this.expireAfter = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(expireAfter); + } + + public Cache(String name, Object value1) { + this(name, value1, null, 1); + } + + public Cache(String name, Object value1, int expireAfter) { + this(name, value1, null, expireAfter); + } + + public Cache(String name, Object value1, Object value2) { + this(name, value1, value2, 1); + } + + public Boolean getBoolean1() { + used++; + this.expireAfter = expireAfter + TimeUnit.MINUTES.toMillis(5); + return (Boolean) value1; + } + + public Boolean getBoolean2() { + used++; + this.expireAfter = expireAfter + TimeUnit.MINUTES.toMillis(5); + return (Boolean) value2; + } + + public String getString1() { + used++; + this.expireAfter = expireAfter + TimeUnit.MINUTES.toMillis(5); + return (String) value1; + } + + public String getString2() { + used++; + this.expireAfter = expireAfter + TimeUnit.MINUTES.toMillis(5); + return (String) value2; + } + + public UUID getUUID() { + used++; + this.expireAfter = expireAfter + TimeUnit.MINUTES.toMillis(5); + return (UUID) value1; + } + + public boolean isExpired() { + return expireAfter < System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.java new file mode 100644 index 0000000..0f01cf5 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.java @@ -0,0 +1,92 @@ +package com.br.guilhermematthew.nowly.commons.common.utility; + +import java.io.IOException; +import java.net.URL; +import java.security.CodeSource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class ClassGetter { + + public static ArrayList> getClassesForPackage(Object instance, String packageName) { + CodeSource source = instance.getClass().getProtectionDomain().getCodeSource(); + + ArrayList> classes = new ArrayList>(); + + ArrayList> processedClasses = new ArrayList>(); + + ArrayList names = new ArrayList(); + + if (source != null) { + processJarfile(source.getLocation(), packageName, classes); + } + + for (Class simpleClass : classes) { + names.add(simpleClass.getSimpleName()); + processedClasses.add(simpleClass); + } + + classes.clear(); + Collections.sort(names, String.CASE_INSENSITIVE_ORDER); + + for (String name : names) { + for (Class simpleClass : processedClasses) { + if (simpleClass.getSimpleName().equals(name)) { + classes.add(simpleClass); + break; + } + } + } + + processedClasses.clear(); + processedClasses = null; + + names.clear(); + names = null; + source = null; + + return classes; + } + + private static Class loadClass(String className) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'"); + } + } + + private static void processJarfile(URL resource, String packageName, ArrayList> classes) { + JarFile jarFile; + String relPath = packageName.replace('.', '/'), resPath = resource.getPath().replace("%20", " "), jarPath = resPath.replaceFirst("[.]jar!.*", ".jar").replaceFirst("file:", ""); + + try { + jarFile = new JarFile(jarPath); + } catch (IOException e) { + throw new RuntimeException("Unexpected IOException reading JAR File '" + jarPath + "'", e); + } + + Enumeration entries = jarFile.entries(); + + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + String entryName = entry.getName(), className = null; + + if (entryName.endsWith(".class") && entryName.startsWith(relPath) && entryName.length() > (relPath.length() + "/".length())) + className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); + + if (className != null) { + classes.add(loadClass(className)); + } + } + + try { + jarFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.java new file mode 100644 index 0000000..8650b2c --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.java @@ -0,0 +1,146 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.mojang; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.common.utility.Cache; +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class UUIDFetcher { + + private static final HashMap CACHE = new HashMap<>(); + private final List apis = new ArrayList<>(); + + public UUIDFetcher() { + this.apis.add("https://api.mojang.com/users/profiles/minecraft/%s"); + this.apis.add("https://api.minetools.eu/uuid/%s"); + } + + public int getCacheSize() { + return CACHE.size(); + } + + public void cleanCache() { + CACHE.clear(); + } + + private UUID request(final String name) throws UUIDFetcherException { + return this.request(0, this.apis.get(0), name); + } + + public UUID getOfflineUUID(final String nick) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + nick).getBytes(Charsets.UTF_8)); + } + + private UUID request(int idx, String api, final String name) throws UUIDFetcherException { + try { + + final URLConnection con = new URL(String.format(api, name)).openConnection(); + final JsonElement element = CommonsConst.PARSER.parse(new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))); + + if (element instanceof JsonObject) { + final JsonObject object = (JsonObject) element; + + if (object.has("error") && object.has("errorMessage")) { + throw new Exception(object.get("errorMessage").getAsString()); + } + + if (object.has("id")) { + return UUIDParser.parse(object.get("id")); + } + + if (object.has("uuid")) { + final JsonObject uuid = object.getAsJsonObject("uuid"); + if (uuid.has("formatted")) { + return UUIDParser.parse(object.get("formatted")); + } + } + } + } catch (Exception e) { + if (++idx < this.apis.size()) { + api = this.apis.get(idx); + return this.request(idx, api, name); + } else { + throw new UUIDFetcherException("Failed"); + } + } + return null; + } + + public UUID getUUID(final String name) throws UUIDFetcherException { + if (CACHE.containsKey(name)) return CACHE.get(name).getUUID(); + + if (name.matches("\\w{3,16}")) { + if (CACHE.containsKey(name)) return CACHE.get(name).getUUID(); + + UUID uniqueId; + + try { + uniqueId = request(name); + + if (uniqueId != null) { + CACHE.put(name, new Cache(name, uniqueId)); + return uniqueId; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + return UUIDParser.parse(name); + } + + public void checkCache() { + checkCache(null); + } + + public void checkCache(Runnable callback) { + List keys = Lists.newArrayList(); + + for (Cache cache : CACHE.values()) { + if (cache.isExpired()) { + keys.add(cache.getName()); + } + } + + if (keys.size() != 0) { + for (String key : keys) { + CACHE.remove(key); + } + } + + keys.clear(); + if (callback != null) { + callback.run(); + } + } + + public static class UUIDFetcherException extends Exception { + + private static final long serialVersionUID = 1L; + private final String reason; + + public UUIDFetcherException(String reason) { + this.reason = reason; + } + + public String getReason() { + return reason; + } + + public String getMessage() { + return reason; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.java new file mode 100644 index 0000000..5b06554 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.java @@ -0,0 +1,25 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.mojang; + +import com.google.gson.JsonElement; + +import java.util.UUID; + +public class UUIDParser { + + public static UUID parse(final JsonElement element) { + return parse(element.getAsString()); + } + + public static UUID parse(final String string) { + if (string != null && !string.isEmpty()) { + if (string.matches("[\\da-fA-F]{32}")) { + return UUID.fromString(string.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); + } + if (string.matches("[\\da-fA-F]{8}-[\\da-fA-F]{4}-[34][\\da-fA-F]{3}-[89ab][\\da-fA-F]{3}-[\\da-fA-F]{12}")) { + return UUID.fromString(string); + } + } + + return null; + } +} diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.java new file mode 100644 index 0000000..a23d3c8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.java @@ -0,0 +1,16 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.skin; + +import lombok.Getter; + +@Getter +public class Skin { + + private final String value, signature; + private final String name; + + public Skin(String name, String value, String signature) { + this.name = name; + this.value = value; + this.signature = signature; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.java new file mode 100644 index 0000000..1f56bfc --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.java @@ -0,0 +1,93 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.skin; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import java.net.URL; +import java.net.URLConnection; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Scanner; + +public class SkinFetcher { + + public static Skin fetchSkinByNick(String nick, String uuid, boolean defaultSkin) { + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement preparedStatament = connection + .prepareStatement("SELECT * FROM skins where nick='" + nick + "'"); + + ResultSet result = preparedStatament.executeQuery(); + + if (!result.next()) { + CommonsGeneral.console("Skin de '" + nick + "' nao existe no banco de Dados."); + + result.close(); + preparedStatament.close(); + + fetchSkinAndPut(nick, uuid); + + if (defaultSkin) { + return fetchSkinByNick("0171", "3650e36a-fe4f-4f0d-ba48-401cedb150e1", false); + } + return null; + } + + String value = result.getString("value"), signature = result.getString("signature"); + + result.close(); + preparedStatament.close(); + + return new Skin(nick, value, signature); + } catch (SQLException ex) { + CommonsGeneral.console("Ocorreu um erro ao tentar obter a skin."); + return null; + } + } + + public static void fetchSkinAndPut(String nick, String uuid) { + new Thread(() -> { + try { + URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + + uuid.replaceAll("-", "") + "?unsigned=false"); + URLConnection uc = url.openConnection(); + uc.setUseCaches(false); + uc.setDefaultUseCaches(false); + uc.addRequestProperty("User-Agent", "Mozilla/5.0"); + uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); + uc.addRequestProperty("Pragma", "no-cache"); + + String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next(); + JSONParser parser = new JSONParser(); + Object obj = parser.parse(json); + JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties"); + for (int i = 0; i < properties.size(); i++) { + try { + JSONObject property = (JSONObject) properties.get(i); + String value = (String) property.get("value"); + String signature = property.containsKey("signature") ? (String) property.get("signature") + : null; + + if (MySQLManager.updateIfNotExists("skins", "nick", nick, + "INSERT INTO skins(nick,lastUse,value,signature,timestamp) VALUES" + " ('" + nick + + "', '" + System.currentTimeMillis() + "', '" + value + "','" + signature + + "','" + (System.currentTimeMillis() + 60 * 60 * 24 * 3 * 1000) + "');")) { + + CommonsGeneral.console("Skin '" + nick + "' foi adicionada ao Banco de Dados."); + } + + } catch (Exception e) { + CommonsGeneral.console("Ocorreu um erro ao tentar parcelar as propriedades..."); + } + } + } catch (Exception e) { + CommonsGeneral.console( + "§cOcorreu um erro ao tentar conectar-se ao link para obter as informaçőes da Skin -> " + nick); + } + }).start(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.java new file mode 100644 index 0000000..ecc4869 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.java @@ -0,0 +1,181 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.string; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class StringUtility { + + public static final DecimalFormat decimalFormat = new DecimalFormat("###,###.##"); + + public static String cpuQuality(final double percentage) { + if (percentage <= 60.0D) return "§a" + percentage; + if (percentage > 60.0D && percentage < 90.0D) return "§e" + percentage; + return "§c" + percentage; + } + + public static String ramQuality(double percentage) { + if (percentage <= 60.0D) return "§a" + percentage; + if (percentage > 60.0D && percentage < 90.0D) return "§e" + percentage; + return "§c" + percentage; + } + + public static String toMillis(double d) { + String string = String.valueOf(d); + StringBuilder sb = new StringBuilder(); + boolean stop = false; + + for (char c : string.toCharArray()) { + if (stop) + return sb.append(c).toString(); + if (c == '.') + stop = true; + sb.append(c); + } + return sb.toString(); + } + + public static String reformuleMegaBytes(Long megaBytes) { + if (megaBytes <= 999) return megaBytes + " MB"; + + long mb = megaBytes; + long gigas = (megaBytes / 1000); + + mb = (mb - (gigas * 1000)); + + if (mb != 0) { + String mbFormatted = String.valueOf(mb).substring(0, 1); + return gigas + "." + mbFormatted + " GB"; + } else { + return gigas + " GB"; + } + } + + public static String formatStringToArrayWithoutSpace(final List array) { + return formatArrayToString(array, false); + } + + public static String formatArrayToString(List array, boolean lowerCase) { + if (array.size() == 1) return array.get(0); + + final StringBuilder toReturn = new StringBuilder(); + + for (int i = 0; i < array.size(); i++) { + String string = array.get(i); + + if (lowerCase) { + toReturn.append(string.toLowerCase()).append(array.size() - i > 1 ? ", " : ""); + } else { + toReturn.append(string).append(array.size() - i > 1 ? ", " : ""); + } + + string = null; + } + + return toReturn.toString(); + } + + public static String formatArrayToStringWithoutSpace(List array, boolean lowerCase) { + if (array.size() == 1) return array.get(0); + + + final StringBuilder toReturn = new StringBuilder(); + + for (int i = 0; i < array.size(); i++) { + String string = array.get(i); + + if (lowerCase) { + toReturn.append(string.toLowerCase()).append(array.size() - i > 1 ? "," : ""); + } else { + toReturn.append(string).append(array.size() - i > 1 ? "," : ""); + } + string = null; + } + + return toReturn.toString(); + } + + public static boolean isInteger(final String string) { + try { + Integer.parseInt(string); + } catch (NumberFormatException ex) { + return false; + } + return true; + } + + public static String createArgs(int index, String[] args) { + return createArgs(index, args, "", false); + } + + public static String createArgs(int index, String[] args, String defaultArgs, boolean color) { + StringBuilder sb = new StringBuilder(); + + for (int i = index; i < args.length; i++) + sb.append(args[i]).append((i + 1 >= args.length ? "" : " ")); + + if (sb.length() == 0) + sb.append(defaultArgs); + + return color ? sb.toString().replace("&", "§") : sb.toString(); + } + + public static String replace(String message, String[] old, String[] now) { + String replaced = message; + for (int i = 0; i < old.length; i++) + replaced = replaced.replace(old[i], now[i]); + return replaced; + } + + public static String formatValue(int valor) { + return decimalFormat.format(valor); + } + + public static List formatStringToArrayWithoutSpace(String formatted) { + List lista = new ArrayList<>(); + + if (formatted.equals("") || (formatted.equals(" ") || (formatted.isEmpty()))) { + return lista; + } + + if (formatted.contains(" ")) { + formatted = formatted.replaceAll(" ", ""); + } + + if (formatted.contains(",")) { + lista.addAll(Arrays.asList(formatted.split(","))); + } else { + lista.add(formatted); + } + return lista; + } + + public static List formatStringToArray(String formatted) { + List lista = new ArrayList<>(); + if (formatted.equals("") || (formatted.equals(" ") || (formatted.isEmpty()))) { + return lista; + } + if (formatted.contains(",")) { + lista.addAll(Arrays.asList(formatted.split(","))); + } else { + lista.add(formatted); + } + return lista; + } + + public static Object convertValue(String value, String classExpected) { + if (classExpected.equalsIgnoreCase("String")) + return value; + else if (classExpected.equalsIgnoreCase("Integer")) + return Integer.valueOf(value); + else if (classExpected.equalsIgnoreCase("Long")) + return Long.valueOf(value); + else if (classExpected.equalsIgnoreCase("Boolean")) + return Boolean.valueOf(value); + else if (classExpected.equalsIgnoreCase("List")) { + return "?"; + } + return value; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.java new file mode 100644 index 0000000..9e725e1 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.java @@ -0,0 +1,260 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.system; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DateUtils { + + public static String getActualDate() { + return getActualDate(true); + } + + public static String getActualDate(boolean withFormat) { + Calendar cal = Calendar.getInstance(); + + int year = cal.get(Calendar.YEAR), mon = cal.get(Calendar.MONTH) + 1, day = cal.get(Calendar.DAY_OF_MONTH), + hour = cal.get(Calendar.HOUR_OF_DAY), min = cal.get(Calendar.MINUTE), sec = cal.get(Calendar.SECOND); + + StringBuilder newString = new StringBuilder(); + newString.append(day < 10 ? "0" : "").append(day).append("/"); + newString.append(mon < 10 ? "0" : "").append(mon).append("/"); + newString.append(year).append(" - "); + newString.append(hour < 10 ? "0" : "").append(hour).append(":"); + newString.append(min < 10 ? "0" : "").append(min).append(":"); + newString.append(sec); + + cal = null; + + return (withFormat ? "[" : "") + newString + (withFormat ? "] " : ""); + } + + public static String formatTime(Integer i) { + if (i.intValue() >= 60) { + Integer time = Integer.valueOf(i.intValue() / 60); + String add = ""; + + if (time.intValue() > 1) { + add = "s"; + } + return time + " minuto" + add; + } + + String add = ""; + if (i.intValue() > 1) { + add = "s"; + } + return i + " segundo" + add; + } + + public static String formatSecondsScore(Integer i) { + return formatSecondsScore(i, true); + } + + public static String formatSecondsScore(final Integer i, final boolean useSuffix) { + int minutes = i.intValue() / 60; + int seconds = i.intValue() % 60; + + String disMinu = ("") + minutes; + + String disSec = (seconds < 10 ? "0" : "") + seconds; + + String formattedTime = disMinu + ":" + disSec; + + if (useSuffix) { + formattedTime = disMinu + ":" + disSec; + } + + return formattedTime; + } + + + public static String formatSeconds(Integer i) { + return formatSeconds(i, true); + } + + public static String formatSeconds(final Integer i, final boolean useSuffix) { + int minutes = i.intValue() / 60; + int seconds = i.intValue() % 60; + + String disMinu = ("") + minutes; + + String disSec = (seconds < 10 ? "0" : "") + seconds; + + String formattedTime = disMinu + ":" + disSec; + + if (useSuffix) { + formattedTime = disMinu + "m " + disSec + "s"; + } + + return formattedTime; + } + + public static String getElapsed(Long started, Long nanoStarted) { + Long now = System.currentTimeMillis(); + Long actualNano = System.nanoTime(); + + long elapsed = now - started; + + long seconds = elapsed / 1000L % 60L; + long minutes = elapsed / (60L * 1000L) % 60L; + long hours = elapsed / (60L * 60L * 1000L) % 24L; + long days = elapsed / (24L * 60L * 60L * 1000L); + + StringBuilder stringBuilder = new StringBuilder(); + + if (days != 0L) { + stringBuilder.append(days).append("dia").append(days > 1 ? "s" : "").append(", "); + } + + if (hours != 0L) { + stringBuilder.append(hours).append("hora").append(days > 1 ? "s" : "").append(", "); + } + + if (minutes != 0L) { + if (seconds != 0L) { + stringBuilder.append(minutes).append("minuto").append(days > 1 ? "s" : "").append(" e ").append(seconds).append(" segundo").append(seconds > 1 ? "s" : ""); + } else { + stringBuilder.append(minutes).append("minuto").append(days > 1 ? "s" : ""); + } + } else { + stringBuilder.append(seconds).append(" segundo").append(seconds > 1 ? "s" : ""); + } + + if (days == 0L && hours == 0L && minutes == 0L && seconds == 0L) { + String ms = String.valueOf(started - now).replaceAll("-", ""); + + if (ms.equals("0")) { + return String.valueOf((nanoStarted - actualNano)).replace("-", "") + "ns"; + } + + return ms + "ms"; + } + return stringBuilder.toString().replaceAll("-", "") + "."; + } + + private static String fromLong(long lenth) { + int days = (int) TimeUnit.SECONDS.toDays(lenth); + long hours = TimeUnit.SECONDS.toHours(lenth) - days * 24; + long minutes = TimeUnit.SECONDS.toMinutes(lenth) - TimeUnit.SECONDS.toHours(lenth) * 60L; + long seconds = TimeUnit.SECONDS.toSeconds(lenth) - TimeUnit.SECONDS.toMinutes(lenth) * 60L; + + String totalDay = days + (days == 1 ? " dia " : " dias "); + String totalHours = hours + (hours == 1 ? " hora " : " horas "); + String totalMinutes = minutes + (minutes == 1 ? " minuto " : " minutos "); + String totalSeconds = seconds + (seconds == 1 ? " segundo" : " segundos"); + + if (days == 0) + totalDay = ""; + + if (hours == 0L) + totalHours = ""; + + if (minutes == 0L) + totalMinutes = ""; + + if (seconds == 0L) + totalSeconds = ""; + + String restingTime = totalDay + totalHours + totalMinutes + totalSeconds; + restingTime = restingTime.trim(); + + if (restingTime.equals("")) + restingTime = "0 segundos"; + + return restingTime; + } + + public static String formatDifference(long time) { + long timeLefting = time - System.currentTimeMillis(); + long seconds = timeLefting / 1000L; + return fromLong(seconds); + } + + public static long parseDateDiff(String time, boolean future) throws Exception { + Pattern timePattern = Pattern.compile("(?:(\\d+)\\s*y[a-z]*[,\\s]*)?" + "(?:(\\d+)\\s*mo[a-z]*[,\\s]*)?" + + "(?:(\\d+)\\s*w[a-z]*[,\\s]*)?" + "(?:(\\d+)\\s*d[a-z]*[,\\s]*)?" + + "(?:(\\d+)\\s*h[a-z]*[,\\s]*)?" + "(?:(\\d+)\\s*m[a-z]*[,\\s]*)?" + + "(?:(\\d+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); + + Matcher m = timePattern.matcher(time); + + int years = 0; + int months = 0; + int weeks = 0; + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + + boolean found = false; + while (m.find()) { + if (m.group() == null || m.group().isEmpty()) { + continue; + } + for (int i = 0; i < m.groupCount(); i++) { + if (m.group(i) != null && !m.group(i).isEmpty()) { + found = true; + break; + } + } + if (found) { + if (m.group(1) != null && !m.group(1).isEmpty()) { + years = Integer.parseInt(m.group(1)); + } + if (m.group(2) != null && !m.group(2).isEmpty()) { + months = Integer.parseInt(m.group(2)); + } + if (m.group(3) != null && !m.group(3).isEmpty()) { + weeks = Integer.parseInt(m.group(3)); + } + if (m.group(4) != null && !m.group(4).isEmpty()) { + days = Integer.parseInt(m.group(4)); + } + if (m.group(5) != null && !m.group(5).isEmpty()) { + hours = Integer.parseInt(m.group(5)); + } + if (m.group(6) != null && !m.group(6).isEmpty()) { + minutes = Integer.parseInt(m.group(6)); + } + if (m.group(7) != null && !m.group(7).isEmpty()) { + seconds = Integer.parseInt(m.group(7)); + } + break; + } + } + if (!found) { + throw new Exception("Illegal Date"); + } + + if (years > 20) { + throw new Exception("Illegal Date"); + } + + Calendar c = new GregorianCalendar(); + if (years > 0) { + c.add(Calendar.YEAR, years * (future ? 1 : -1)); + } + if (months > 0) { + c.add(Calendar.MONTH, months * (future ? 1 : -1)); + } + if (weeks > 0) { + c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1)); + } + if (days > 0) { + c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1)); + } + if (hours > 0) { + c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1)); + } + if (minutes > 0) { + c.add(Calendar.MINUTE, minutes * (future ? 1 : -1)); + } + if (seconds > 0) { + c.add(Calendar.SECOND, seconds * (future ? 1 : -1)); + } + return c.getTimeInMillis(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.java new file mode 100644 index 0000000..a369764 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.java @@ -0,0 +1,122 @@ +package com.br.guilhermematthew.nowly.commons.common.utility.system; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import java.lang.management.ManagementFactory; +import java.net.URL; +import java.net.URLConnection; +import java.util.Scanner; + +public class Machine { + + private static final String OS = System.getProperty("os.name").toLowerCase(); + private static final String USER_HOME = System.getProperty("user.home"); + private static String machineIP = "NOT LOADED"; + + public static void initialize() { + machineIP = getRealIP(); + CommonsGeneral.console("§a[Machine] -> Address: " + machineIP); + } + + public static Long getRamUsage() { + return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 2L / 1048576L; + } + + public static double getCPUUse() { + try { + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem"); + AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"}); + + if (list.isEmpty()) { + return Double.NaN; + } + + Attribute att = (Attribute) list.get(0); + Double value = (Double) att.getValue(); + + if (value == -1.0) { + return Double.NaN; + } + + return (int) (value * 1000) / 10.0; + } catch (Exception e) { + return 0.0; + } + } + + public static String getMachineIP() { + return machineIP; + } + + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + + public static boolean isMac() { + return (OS.indexOf("mac") >= 0); + } + + public static boolean isUnix() { + return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0); + } + + public static boolean isSolaris() { + return (OS.indexOf("sunos") >= 0); + } + + public static String getOS() { + if (isWindows()) { + return "win"; + } else if (isMac()) { + return "osx"; + } else if (isUnix()) { + return "uni"; + } else if (isSolaris()) { + return "sol"; + } else { + return "err"; + } + } + + public static String getDiretorio() { + return (isUnix() ? "/" + getUserHome() + "/" : "C:\\") + CommonsConst.DIR_CONFIG_NAME; + } + + public static String getSeparador() { + return isUnix() ? "/" : "\\"; + } + + private static String getRealIP() { + try { + URLConnection connect = new URL("http://checkip.amazonaws.com/").openConnection(); + connect.addRequestProperty("User-Agent", + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"); + + Scanner scan = new Scanner(connect.getInputStream()); + StringBuilder sb = new StringBuilder(); + + while (scan.hasNext()) { + sb.append(scan.next()); + } + + scan.close(); + scan = null; + + connect = null; + + return sb.toString(); + } catch (Exception ex) { + return "Erro"; + } + } + + public static String getUserHome() { + return USER_HOME; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.java new file mode 100644 index 0000000..dda6a50 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.java @@ -0,0 +1,13 @@ +package com.br.guilhermematthew.nowly.commons.custompackets; + +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; + +import java.net.Socket; + +public abstract class CommonPacketHandler { + + public abstract void handleCPacketAction(final CPacketAction packet, final Socket socket); + + public abstract void handleCPacketPlayerAction(final CPacketCustomAction cPacketPlayerAction, final Socket socket); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.java new file mode 100644 index 0000000..dd1d578 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.commons.custompackets; + +public enum PacketType { + + UNKNOWN, + BUKKIT_RECEIVE_SKIN_DATA, + BUKKIT_RECEIVE_ACCOUNT_FROM_BUNGEECORD, + BUKKIT_REQUEST_ACCOUNT_TO_BUNGEECORD, + BUKKIT_SEND_UPDATED_DATA, + BUKKIT_PLAYER_RESPAWN, + BUKKIT_SEND_SERVER_DATA, + BUKKIT_SEND_INFO, + + BUNGEE_SET_FAST_SKIN, + BUNGEE_SET_RANDOM_SKIN, + BUNGEE_SET_SKIN, + BUNGEE_UPDATE_SKIN, + BUKKIT_GO, + BUNGEE_SEND_UPDATED_STATS, + BUNGEE_SEND_KICK, + BUNGEE_SEND_PLAYER_ACTION, + BUNGEE_SEND_INFO; + + public static PacketType getType(String name) { + PacketType type = PacketType.UNKNOWN; + + for (PacketType types : values()) { + if (types.name().equalsIgnoreCase(name)) { + type = types; + break; + } + } + + return type; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.java new file mode 100644 index 0000000..bd6bdac --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.nowly.commons.custompackets; + +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; + +import java.util.HashMap; +import java.util.Map; + +public class PacketsManager { + + private static final Map> MAP_CLASS = new HashMap>(); + + static { + register(CPacketAction.class); + register(CPacketCustomAction.class); + } + + public static void register(Class packetClass) { + MAP_CLASS.put(packetClass.getSimpleName(), packetClass); + } + + public static CommonPacket getPacket(final String packetName) { + try { + return (CommonPacket) MAP_CLASS.get(packetName).newInstance(); + } catch (Exception ex) { + ServerCommunication.debug("PACKET MANAGER", "An error ocurred on trying get packet with the name -> " + packetName); + return null; + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.java new file mode 100644 index 0000000..70cad0e --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.java @@ -0,0 +1,143 @@ +package com.br.guilhermematthew.nowly.commons.custompackets.registry; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; + +@Getter +@Setter +public class CPacketAction extends CommonPacket { + + private String type, field, fieldValue, extraValue, extraValue2; + + public CPacketAction() { + } + + public CPacketAction(final String serverName, final int serverID) { + setServerName(serverName); + setServerID(serverID); + + setJson(new JsonObject()); + + write(); + } + + @Override + public void read(final JsonObject json) { + setJson(json); + + setServerName(json.get("serverName").getAsString()); + setServerID(json.get("serverID").getAsInt()); + + if (json.has("type")) { + this.type = json.get("type").getAsString(); + } + + if (json.has("field")) { + this.field = json.get("field").getAsString(); + } + + if (json.has("fieldValue")) { + this.fieldValue = json.get("fieldValue").getAsString(); + } + + if (json.has("extraValue")) { + this.extraValue = json.get("extraValue").getAsString(); + } + + if (json.has("extraValue2")) { + this.extraValue2 = json.get("extraValue2").getAsString(); + } + + if (json.has("timeStamp")) { + setTimestamp(json.get("timeStamp").getAsLong()); + } + } + + public CPacketAction writeType(String value) { + getJson().addProperty("type", value); + return this; + } + + public CPacketAction writeField(String value) { + getJson().addProperty("field", value); + return this; + } + + public CPacketAction writeFieldValue(String value) { + getJson().addProperty("fieldValue", value); + return this; + } + + public CPacketAction writeExtraValue(String value) { + getJson().addProperty("extraValue", value); + return this; + } + + public CPacketAction writeExtraValue2(String value) { + getJson().addProperty("extraValue2", value); + return this; + } + + @Override + public void write() { + getJson().addProperty("packetName", getPacketName()); + getJson().addProperty("serverID", getServerID()); + getJson().addProperty("serverName", getServerName()); + getJson().addProperty("timeStamp", System.currentTimeMillis()); + } + + @Override + public void handle(final Socket socket) { + ServerCommunication.getPacketHandler().handleCPacketAction(this, socket); + } + + @Override + public String getPacketName() { + return getClass().getSimpleName(); + } + + @Override + public String getJSONString() { + return getJson().toString(); + } + + public String getValues() { + StringBuilder stringBuilder = new StringBuilder(); + + if (getType() != null) { + stringBuilder.append("type: ").append(getType()); + } + + if (getField() != null) { + stringBuilder.append(", field: ").append(getField()); + } + + if (getFieldValue() != null) { + stringBuilder.append(", fieldValue: ").append(getFieldValue()); + } + + if (getExtraValue() != null) { + stringBuilder.append(", extraValue: ").append(getExtraValue()); + } + + if (getExtraValue2() != null) { + stringBuilder.append(", extraValue2: ").append(getExtraValue2()); + } + + return stringBuilder.toString(); + } + + @Override + public String getDebugReceived() { + final String from = getServerName() + "-" + getServerID(); + + final long time = (System.currentTimeMillis() - getTimestamp()); + + return "(" + getPacketName() + ") has been received! (" + time + " ms) from: (" + from + ") with values: (" + getValues() + ")"; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.java b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.java new file mode 100644 index 0000000..b5feaf9 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.java @@ -0,0 +1,236 @@ +package com.br.guilhermematthew.nowly.commons.custompackets.registry; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.common.PluginInstance; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; +import java.util.UUID; + +@Getter +@Setter +public class CPacketCustomAction extends CommonPacket { + + private UUID uniqueId; + private String nick, field, fieldValue, extraValue, extraValue2; + + private PacketType packetType; + private ServerType serverType; + + public CPacketCustomAction() { + } + + public CPacketCustomAction(String nick, final UUID uniqueId) { + this.nick = nick; + this.uniqueId = uniqueId; + + setJson(new JsonObject()); + + getJson().addProperty("uniqueId", uniqueId == null ? "INVALID UUID" : uniqueId.toString()); + getJson().addProperty("nick", nick == null ? "INVALID NICK" : nick); + + write(); + } + + public CPacketCustomAction(String nick) { + this(nick, null); + } + + public CPacketCustomAction(UUID uniqueId) { + this(null, uniqueId); + } + + public CPacketCustomAction(ServerType type, int serverId) { + this.serverType = type; + setServerID(serverId); + setServerName(type.getName()); + setJson(new JsonObject()); + + getJson().addProperty("uniqueId", uniqueId == null ? "INVALID UUID" : uniqueId.toString()); + getJson().addProperty("nick", nick == null ? "INVALID NICK" : nick); + + write(); + } + + @Override + public void read(final JsonObject json) { + setJson(json); + + this.uniqueId = null; + this.nick = null; + + setServerName(json.get("serverName").getAsString()); + setServerID(json.get("serverID").getAsInt()); + + if (json.has("nick")) { + if (!json.get("nick").getAsString().equalsIgnoreCase("INVALID NICK")) { + this.nick = json.get("nick").getAsString(); + } + } + + if (json.has("uniqueId")) { + String uuidString = json.get("uniqueId").getAsString(); + if (!uuidString.equalsIgnoreCase("INVALID UUID")) { + this.uniqueId = UUID.fromString(uuidString); + } + } + + if (json.has("packetType")) { + this.packetType = PacketType.getType(json.get("packetType").getAsString()); + } + + if (json.has("field")) { + this.field = json.get("field").getAsString(); + } + + if (json.has("fieldValue")) { + this.fieldValue = json.get("fieldValue").getAsString(); + } + + if (json.has("extraValue")) { + this.extraValue = json.get("extraValue").getAsString(); + } + + if (json.has("extraValue2")) { + this.extraValue2 = json.get("extraValue2").getAsString(); + } + + if (json.has("timeStamp")) { + setTimestamp(json.get("timeStamp").getAsLong()); + } + + if (json.has("serverType")) { + this.serverType = ServerType.getServer(json.get("serverType").getAsString()); + } + } + + public CPacketCustomAction type(PacketType type) { + check(); + + getJson().addProperty("packetType", type.name().toUpperCase()); + return this; + } + + private CPacketCustomAction check() { + if (getJson() == null) { + setJson(new JsonObject()); + } + + if (this.serverType == null) { + if (CommonsGeneral.getPluginInstance() == PluginInstance.BUNGEECORD) { + setServerID(1); + this.serverType = ServerType.BUNGEECORD; + } else { + this.serverType = com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain.getServerType(); + setServerID(com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain.getServerID()); + } + } + + setServerName(getServerType().getName()); + + if (!getJson().has("serverName")) { + getJson().addProperty("serverName", getServerName()); + } + + if (!getJson().has("serverID")) { + getJson().addProperty("serverID", getServerID()); + } + + if (!getJson().has("packetName")) { + getJson().addProperty("packetName", getPacketName()); + } + if (!getJson().has("timeStamp")) { + getJson().addProperty("timeStamp", System.currentTimeMillis()); + } + + if (!getJson().has("serverType")) { + getJson().addProperty("serverType", getServerType().getName()); + } + + return this; + } + + public CPacketCustomAction field(String value) { + check(); + + getJson().addProperty("field", value); + return this; + } + + public CPacketCustomAction fieldValue(String value) { + getJson().addProperty("fieldValue", value); + return this; + } + + public CPacketCustomAction extraValue(String value) { + getJson().addProperty("extraValue", value); + return this; + } + + public CPacketCustomAction extraValue2(String value) { + getJson().addProperty("extraValue2", value); + return this; + } + + @Override + public void write() { + check(); + } + + @Override + public void handle(final Socket socket) { + ServerCommunication.getPacketHandler().handleCPacketPlayerAction(this, socket); + } + + @Override + public String getPacketName() { + return "CPacketCustomAction"; + } + + @Override + public String getJSONString() { + return getJson().toString(); + } + + public String getValues() { + StringBuilder stringBuilder = new StringBuilder(); + + if (getPacketType() != null) { + stringBuilder.append("packetType: ").append(getPacketType().name().toUpperCase()); + } + + if (getField() != null) { + stringBuilder.append(", field: ").append(getField()); + } + + if (getFieldValue() != null) { + stringBuilder.append(", fieldValue: ").append(getFieldValue()); + } + + if (getExtraValue() != null) { + stringBuilder.append(", extraValue: ").append(getExtraValue()); + } + + if (getExtraValue2() != null) { + stringBuilder.append(", extraValue2: ").append(getExtraValue2()); + } + + return stringBuilder.toString(); + } + + @Override + public String getDebugReceived() { + final String from = getServerName() + "-" + getServerID(); + + final long time = (System.currentTimeMillis() - getTimestamp()); + + return "(" + getPacketName() + ") has been received! (" + time + " ms) from: (" + from + ") with values: (" + + getValues() + ")"; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java new file mode 100644 index 0000000..d6bfb8f --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java @@ -0,0 +1,81 @@ +package com.br.guilhermematthew.servercommunication; + +import com.br.guilhermematthew.nowly.commons.custompackets.CommonPacketHandler; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.common.packet.PacketListenerManager; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.Getter; +import lombok.Setter; + +import java.io.IOException; + +public class ServerCommunication { + + public static final int TIMEOUT_TIME = 10; //TIMEOUT CLIENTS + + public static final int PORT = 30001; //SERVER PORT + + @Getter + private static final PacketListenerManager packetListener = new PacketListenerManager(); + public static ServerCommunicationInstance INSTANCE = ServerCommunicationInstance.UNKNOWN; + // START DEBUGS + public static final boolean DEBUG_CLIENT_CONNECTED = false; + public static final boolean DEBUG_CLIENT_DROPED = false; + public static final boolean DEBUG_CLIENT_AUTHENTICATED = false; + public static final boolean DEBUG_PACKET_RECEIVED = false; + public static boolean DEBUG_PACKET_SEND = false; + @Getter + @Setter + private static CommonPacketHandler packetHandler = null; + @Getter + private static UpdateListener updateListener; + //END DEBUGS + + static { + new Thread(updateListener = new UpdateListener()).start(); + } + + public static void startClient(final String clientName, final int clientID, final String hostName) { + Client client = new Client(hostName, clientName, clientID); + + debug("CLIENT", "Connecting on: " + hostName); + + try { + client.getClientConnection().connect(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public static void startServer(final String hostName) { + new Server(hostName); + } + + public static void main(final String[] args) { + if (args.length > 1) { + new Thread(updateListener = new UpdateListener()).start(); + + if (args[1].equalsIgnoreCase("server")) { + startServer(args[0]); + } else { + startClient("KitPvP", 1, args[0]); + } + } else { + debug("ERROR", "Correct usage: ServerCommunication.jar HostName"); + } + } + + + public static void debug(final String message) { + debug(null, message); + } + + public static void debug(final String prefix, final String message) { + if (prefix == null) { + System.out.println("[Debug] " + message); + } else { + System.out.println("[" + prefix + "] " + message); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java new file mode 100644 index 0000000..7439930 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java @@ -0,0 +1,7 @@ +package com.br.guilhermematthew.servercommunication; + +public enum ServerCommunicationInstance { + + UNKNOWN, CLIENT, SERVER + +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java new file mode 100644 index 0000000..ef26ef3 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.servercommunication.client; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.ServerCommunicationInstance; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Client { + + @Getter + private static Client instance; + + private String clientName; + private int clientID; + + private ClientConnection clientConnection; + + public Client(final String hostName, final String clientName, final int clientID) { + instance = this; + + ServerCommunication.INSTANCE = ServerCommunicationInstance.CLIENT; + + setClientName(clientName); + setClientID(clientID); + + setClientConnection(new ClientConnection(hostName)); + } + + public static boolean isInstanced() { + return instance != null; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java new file mode 100644 index 0000000..6a10b2b --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java @@ -0,0 +1,124 @@ +package com.br.guilhermematthew.servercommunication.client; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.CommonClient; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.listener.PacketListener; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener.UpdateEvent; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener.UpdateType; +import lombok.Getter; +import lombok.Setter; + +import java.io.IOException; +import java.net.Socket; + +@Getter +@Setter +public class ClientConnection implements IConnection { + + private String hostName; + private int port; + + private Socket socket; + private CommonClient connectionListen; + + public ClientConnection(final String hostName) { + setHostName(hostName); + setPort(ServerCommunication.PORT); + } + + public void connect() throws IOException { + socket = new Socket(getHostName(), ServerCommunication.PORT); + + setConnectionListen(new CommonClient(socket)); + ServerCommunication.getPacketListener().register(new PacketListener()); + debug("Connected to " + hostName + ":" + port + "!"); + + sendPacket(new CPacketAction(Client.getInstance().getClientName(), Client.getInstance().getClientID()). + writeType("HandShake").writeField(Client.getInstance().getClientName()).writeFieldValue("" + Client.getInstance().getClientID())); + + if (CommonsGeneral.getPluginInstance().isBukkit() && BukkitServerAPI.isRegisteredServer()) + BukkitServerAPI.registerServer(); + + ServerCommunication.getUpdateListener().register(new UpdateEvent() { + + int seconds = 0; + + @Override + public void onUpdate(UpdateType updateType) { + if (updateType != UpdateType.SECOND) return; + + seconds++; + + if (seconds % 10 == 0) { + sendPacket(new CPacketAction(Client.getInstance().getClientName(), Client.getInstance().getClientID()). + writeType("KeepAlive")); + } + } + }); + } + + public void sendPacket(final CommonPacket packet) { + connectionListen.sendPacket(packet); + } + + public void debug(String string) { + ServerCommunication.debug("CLIENT - " + Client.getInstance().getClientName() + ":" + Client.getInstance().getClientID(), string); + } + + public boolean isConnected() { + return socket != null && socket.isConnected(); + } + + @Override + public String getAddress() { + return hostName + ":" + port; + } + + @Override + public void disconnect() { + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + socket = null; + } + } + + @Override + public Socket getSocket() { + return socket; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return null; + } + + public void reconnect(Runnable callback) { + if (socket != null) disconnect(); + if (connectionListen != null) connectionListen.disconnect(); + + try { + connect(); + } catch (Exception ex) { + debug("Failed to reconnect, retrying... (" + ex.getLocalizedMessage() + ")."); + + try { + Thread.sleep(1000 * 5); + } catch (Exception ignored) { + } + + reconnect(callback); + return; + } + + if (callback != null) callback.run(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java new file mode 100644 index 0000000..0ec03ca --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java @@ -0,0 +1,74 @@ +package com.br.guilhermematthew.servercommunication.common.connection; + +import com.br.guilhermematthew.servercommunication.common.connection.handle.InputHandler; +import com.br.guilhermematthew.servercommunication.common.connection.handle.OutputHandler; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import lombok.Getter; +import lombok.Setter; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; + +@Getter +@Setter +public class CommonClient implements IConnection { + + private Socket socket; + + private InputHandler inputHandler; + private OutputHandler outputHandler; + + private String clientName; + private int clientID; + + //NEWS + private int time; + + public CommonClient(final Socket socket) throws IOException { + setSocket(socket); + + setInputHandler(new InputHandler(this, new DataInputStream(socket.getInputStream()))); + setOutputHandler(new OutputHandler(new DataOutputStream(socket.getOutputStream()))); + + getInputHandler().start(); + getOutputHandler().start(); + } + + public void sendPacket(final CommonPacket packet) { + getOutputHandler().sendPacket(packet); + } + + public void disconnect() { + if (!socket.isClosed()) { + try { + inputHandler.close(); + outputHandler.close(); + socket.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + inputHandler.stopThread(); + outputHandler.stopThread(); + } + + public String getAddress() { + return socket.getInetAddress().getHostName() + ":" + socket.getPort(); + } + + public boolean isAuthenticated() { + return getClientName() != null; + } + + public void incrementTimeout() { + time++; + } + + @Override + public String getServerName() { + return clientName + "-" + clientID; + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java new file mode 100644 index 0000000..ba060df --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java @@ -0,0 +1,15 @@ +package com.br.guilhermematthew.servercommunication.common.connection; + +import java.io.IOException; +import java.net.Socket; + +public interface IConnection { + + String getAddress(); + + void disconnect() throws IOException; + + Socket getSocket(); + + String getServerName(); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java new file mode 100644 index 0000000..4cbab45 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java @@ -0,0 +1,62 @@ +package com.br.guilhermematthew.servercommunication.common.connection.handle; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import lombok.Getter; +import lombok.Setter; + +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.net.SocketException; + +@Getter +@Setter +public class InputHandler extends Thread { + + private IConnection connection; + private DataInputStream data; + + private boolean running; + + public InputHandler(final IConnection connection, DataInputStream data) { + setConnection(connection); + setData(data); + } + + @Override + public void run() { + running = true; + + while (isRunning()) { + try { + String message = data.readUTF(); + + if (message != null) { + ServerCommunication.getPacketListener().call(message, connection.getSocket()); + message = null; + } + } catch (EOFException ex) { + running = false; + } catch (SocketException ex) { + //TODO nothing to do + } catch (IOException ex) { + ex.printStackTrace(); + try { + connection.disconnect(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + public void stopThread() { + running = false; + } + + public void close() throws IOException { + data.close(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java new file mode 100644 index 0000000..cab7434 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java @@ -0,0 +1,93 @@ +package com.br.guilhermematthew.servercommunication.common.connection.handle; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.List; + +public class OutputHandler extends Thread { + + private final Object LOCK = new Object(); + private final List packetQueue = new ArrayList<>(); + private final DataOutputStream data; + private boolean running; + private int serverOutOfReach; + + public OutputHandler(DataOutputStream data) { + this.data = data; + } + + @Override + public void run() { + running = true; + + while (running) { + try { + synchronized (packetQueue) { + while (packetQueue.size() > 0) { + CommonPacket packet = packetQueue.get(0); + + if (packet != null) { + try { + data.writeUTF(packet.getJSONString()); + } catch (SocketException ex) { + serverOutOfReach++; + + if (serverOutOfReach == 1) { + ServerCommunication.debug("PACKET SEND", "Server is offline!"); + } + + if (serverOutOfReach % 5 == 0) { + Client.getInstance().getClientConnection().reconnect(null); + } + + if (serverOutOfReach >= 30) { + stopThread(); + close(); + serverOutOfReach = 0; + } + } + + packet = null; + } + + packetQueue.remove(0); + } + } + synchronized (LOCK) { + LOCK.wait(3250); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (Exception e) { + packetQueue.remove(0); + e.printStackTrace(); + } + } + } + + public void sendPacket(final CommonPacket packet) { + synchronized (packetQueue) { + packet.write(); + + packetQueue.add(packet); + } + + synchronized (LOCK) { + LOCK.notifyAll(); + } + } + + public void stopThread() { + running = false; + } + + public void close() throws IOException { + data.close(); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java new file mode 100644 index 0000000..cc16422 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java @@ -0,0 +1,30 @@ +package com.br.guilhermematthew.servercommunication.common.packet; + +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; + +@Getter +@Setter +public abstract class CommonPacket { + + private JsonObject json; + + private String serverName; + private int serverID; + private Long timestamp; + + public abstract void read(final JsonObject json); + + public abstract void write(); + + public abstract void handle(final Socket socket); + + public abstract String getJSONString(); + + public abstract String getPacketName(); + + public abstract String getDebugReceived(); +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java new file mode 100644 index 0000000..f0b337d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.servercommunication.common.packet; + +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +public class PacketListenerManager { + + private final List packetMap; + + public PacketListenerManager() { + packetMap = new ArrayList<>(); + } + + public void register(PacketEvent packetEvent) { + this.packetMap.add(packetEvent); + } + + public void unregister(PacketEvent packetEvent) { + this.packetMap.remove(packetEvent); + } + + public void call(final String packetString, final Socket socket) { + this.packetMap.forEach(packetEvent -> packetEvent.onPacketReceive(packetString, socket)); + } + + public interface PacketEvent { + + void onPacketReceive(final String packetString, final Socket socket); + + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java new file mode 100644 index 0000000..17e1c0d --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.servercommunication.common.packet.listener; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketsManager; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.PacketListenerManager.PacketEvent; +import com.google.gson.JsonObject; + +import java.net.Socket; + +public class PacketListener implements PacketEvent { + + @Override + public void onPacketReceive(final String packetString, final Socket socket) { + JsonObject json = null; + + try { + json = CommonsConst.PARSER.parse(packetString).getAsJsonObject(); + } catch (Exception ex) { + ServerCommunication.debug("PACKET PARSER", "An error ocurred while trying to parse packet! (" + ex.getLocalizedMessage() + ")"); + } finally { + if (json != null) { + if (json.has("packetName")) { + String packetName = json.get("packetName").getAsString(); + + CommonPacket packet = PacketsManager.getPacket(packetName); + + if (packet != null) { + packet.read(json); + + if (ServerCommunication.DEBUG_PACKET_RECEIVED) { + ServerCommunication.debug("PACKET RECEIVE", packet.getDebugReceived()); + } + + try { + packet.handle(socket); + } catch (Exception ex) { + ServerCommunication.debug("PACKET HANDLER", "An error ocurred while trying to handle packet! (" + ex.getLocalizedMessage() + ")"); + ex.printStackTrace(); + } + + packet = null; + } + packetName = null; + } else { + ServerCommunication.debug("I received a Invalid Packet! (#1)"); + } + json = null; + } + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java new file mode 100644 index 0000000..2e7a02a --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java @@ -0,0 +1,57 @@ +package com.br.guilhermematthew.servercommunication.common.update; + +import java.util.concurrent.ConcurrentLinkedQueue; + +public class UpdateListener implements Runnable { + + private long seconds; + + private final ConcurrentLinkedQueue list; + + private boolean running; + + public UpdateListener() { + list = new ConcurrentLinkedQueue<>(); + } + + public void register(UpdateEvent updateEvent) { + list.add(updateEvent); + } + + public void unregister(UpdateEvent updateEvent) { + list.remove(updateEvent); + } + + @Override + public void run() { + running = true; + + while (running) { + try { + Thread.sleep(1000); + } catch (Exception ex) { + } + + seconds++; + + call(UpdateType.SECOND); + + if (seconds % 60 == 0) + call(UpdateType.MINUTE); + } + } + + private void call(UpdateType updateEvent) { + list.forEach(update -> update.onUpdate(updateEvent)); + } + + public enum UpdateType { + SECOND, MINUTE + } + + public interface UpdateEvent { + + void onUpdate(UpdateType updateType); + + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java new file mode 100644 index 0000000..e719832 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java @@ -0,0 +1,23 @@ +package com.br.guilhermematthew.servercommunication.server; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ConnectionInfo { + + private String address; + private int connectionsPerSecond; + + public ConnectionInfo(String address) { + this.address = address; + } + + public void addConnection() { + this.connectionsPerSecond++; + if (this.connectionsPerSecond >= 6) { + //Server.getInstance().getServerGeneral().adToBlackList(address); + } + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java new file mode 100644 index 0000000..dcbde15 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java @@ -0,0 +1,50 @@ +package com.br.guilhermematthew.servercommunication.server; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.ServerCommunicationInstance; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.listener.PacketListener; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; + +public class Server { + + @Getter + @Setter + private static Server instance; + + @Getter + private ServerGeneral serverGeneral; + + public Server(final String hostName) { + setInstance(this); + + ServerCommunication.debug("[ServerCommunication] The server has started on: " + hostName); + + ServerCommunication.INSTANCE = ServerCommunicationInstance.SERVER; + + ServerCommunication.getPacketListener().register(new PacketListener()); + + try { + serverGeneral = new ServerGeneral(hostName); + serverGeneral.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(0); + } + } + + public void sendPacket(final String text, final CommonPacket packet) { + getServerGeneral().sendPacket(text, packet); + } + + public void sendPacket(final String name, final int id, final CommonPacket packet) { + getServerGeneral().sendPacket(name, id, packet); + } + + public void sendPacket(final Socket socket, final CommonPacket packet) { + getServerGeneral().sendPacket(socket, packet); + } +} \ No newline at end of file diff --git a/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java new file mode 100644 index 0000000..78d31f8 --- /dev/null +++ b/commons/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java @@ -0,0 +1,259 @@ +package com.br.guilhermematthew.servercommunication.server; + +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.CommonClient; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import lombok.Getter; +import lombok.Setter; +import lombok.val; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Getter +@Setter +public class ServerGeneral extends Thread implements IConnection { + + private String hostName; + private int port; + + private ServerSocket serverSocket; + + private ConcurrentHashMap socketToRegister; + private Map clientMap; + + private boolean RUNNING; + + public ServerGeneral(final String hostName) throws Exception { + setHostName(hostName); + setPort(ServerCommunication.PORT); + + setServerSocket(new ServerSocket()); + getServerSocket().bind(new InetSocketAddress(hostName, getPort())); + + setSocketToRegister(new ConcurrentHashMap<>()); + setClientMap(new HashMap<>()); + + debug("Connection to " + hostName + ":" + port + " established!"); + + ServerCommunication.getUpdateListener().register(updateType -> { + for (CommonClient connections : getSocketToRegister().values()) { + if (!connections.isAuthenticated()) { + connections.incrementTimeout(); + + if (connections.getTime() == ServerCommunication.TIMEOUT_TIME + 3) { + connections.disconnect(); + + socketToRegister.remove(connections.getSocket()); + + if (ServerCommunication.DEBUG_CLIENT_DROPED) { + debug("Connection " + connections.getAddress() + " dropped!"); + } + } + + if (connections.getTime() == ServerCommunication.TIMEOUT_TIME) { + connections.sendPacket(new CPacketAction("Server", 0).writeType("TimedOut")); + + if (ServerCommunication.DEBUG_CLIENT_DROPED) { + debug("Connection " + connections.getAddress() + " timeout!"); + } + } + } + } + }); + } + + @Override + public void run() { + RUNNING = true; + + while (RUNNING) { + if (serverSocket == null) { + RUNNING = false; + return; + } + + if (getServerSocket().isClosed()) { + try { + getServerSocket().bind(new InetSocketAddress(getHostName(), getPort())); + } catch (IOException e1) { + e1.printStackTrace(); + break; + } + } + + try { + Socket socket = serverSocket.accept(); + String clientHost = socket.getInetAddress().getHostName(); + int clientPort = socket.getPort(); + + socketToRegister.put(socket, new CommonClient(socket)); + + if (ServerCommunication.DEBUG_CLIENT_CONNECTED) { + debug("Connection from " + clientHost + ":" + clientPort + " accepted!"); + } + + } catch (SocketException ex) { + if (!ex.getLocalizedMessage().equals("Socket closed")) ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + try { + disconnect(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void sendPacket(final Socket socket, final CommonPacket packet) { + CommonClient connection = getConnectionByPort(socket.getPort()); + + if (connection != null) { + connection.sendPacket(packet); + } + } + + public void sendPacket(final String text, final CommonPacket packet) { + val name = text.replaceAll("\\d", ""); + val id = name.length() != text.length() ? Integer.parseInt(text.replaceAll("\\D+","")) : 1; + + sendPacket(name, id, packet); + } + + public void sendPacket(final String name, final int id, final CommonPacket packet) { + CommonClient connection = getConnectionListen(name, id); + if (connection != null) { + connection.sendPacket(packet); + } + } + + public CommonClient getConnectionListen(final String name, final int id) { + CommonClient connection = getClientMap().getOrDefault(name.toLowerCase() + "," + id, null); + + if (connection != null) return connection; + + for (CommonClient connections : getClientMap().values()) { + if ((connections.getClientName().equalsIgnoreCase(name)) && (connections.getClientID() == id)) { + connection = connections; + break; + } + } + + return connection; + } + + public CommonClient getConnectionListenByPort(int port) { + CommonClient connection = null; + + for (CommonClient connectionListen : socketToRegister.values()) { + if (connectionListen.getSocket().getPort() == port) { + connection = connectionListen; + break; + } + } + + return connection; + } + + public CommonClient getConnectionByPort(int port) { + CommonClient connection = null; + + for (CommonClient connectionListen : getClientMap().values()) { + if (connectionListen.getSocket().getPort() == port) { + connection = connectionListen; + break; + } + } + + return connection; + } + + public Socket getSocketByPort(int port) { + Socket socket = null; + + for (Socket sockets : socketToRegister.keySet()) { + if (sockets.getPort() == port) { + socket = sockets; + break; + } + } + + return socket; + } + + public void registerClient(final String clientName, final Integer clientID, final Socket socket) { + CommonClient connection = getConnectionListenByPort(socket.getPort()); + + if (connection != null) { + connection.setClientName(clientName); + connection.setClientID(clientID); + + clientMap.put(clientName + "," + clientID, connection); + + if (ServerCommunication.DEBUG_CLIENT_AUTHENTICATED) { + debug(clientName + " (" + clientID + ") authenticated!"); + } + } + + socketToRegister.remove(socket); + } + + public void unregisterClient(Socket socket) { + CommonClient connection = getConnectionListenByPort(socket.getPort()); + + if (connection != null) { + String clientName = connection.getClientName(); + + int clientId = connection.getClientID(); + + clientMap.remove(clientName.toLowerCase() + "," + clientId); + + if (ServerCommunication.DEBUG_CLIENT_AUTHENTICATED) { + debug(clientName + " (" + clientId + ") loggout!"); + } + + } + } + + public void debug(final String string) { + ServerCommunication.debug("SERVER", string); + } + + @Override + public String getAddress() { + return hostName + ":" + port; + } + + @Override + public void disconnect() throws IOException { + RUNNING = false; + + if (getServerSocket() != null) { + getServerSocket().close(); + } + + serverSocket = null; + } + + @Override + public Socket getSocket() { + return null; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return "SERVER"; + } +} \ No newline at end of file diff --git a/commons/src/main/resources/bungee.yml b/commons/src/main/resources/bungee.yml new file mode 100644 index 0000000..d6c229c --- /dev/null +++ b/commons/src/main/resources/bungee.yml @@ -0,0 +1,4 @@ +name: Commons +main: com.br.guilhermematthew.nowly.commons.bungee.BungeeMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 \ No newline at end of file diff --git a/commons/src/main/resources/config.yml b/commons/src/main/resources/config.yml new file mode 100644 index 0000000..cb11d16 --- /dev/null +++ b/commons/src/main/resources/config.yml @@ -0,0 +1,5 @@ +Servidor: Unknown +ServidorID: 0 + +Socket: + Host: 127.0.0.1 \ No newline at end of file diff --git a/commons/src/main/resources/plugin.yml b/commons/src/main/resources/plugin.yml new file mode 100644 index 0000000..0cfa86b --- /dev/null +++ b/commons/src/main/resources/plugin.yml @@ -0,0 +1,4 @@ +name: BukkitCommons +main: com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 \ No newline at end of file diff --git a/commons/target/classes/bungee.yml b/commons/target/classes/bungee.yml new file mode 100644 index 0000000..d6c229c --- /dev/null +++ b/commons/target/classes/bungee.yml @@ -0,0 +1,4 @@ +name: Commons +main: com.br.guilhermematthew.nowly.commons.bungee.BungeeMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 \ No newline at end of file diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsConst.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsConst.class new file mode 100644 index 0000000..08f4cff Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsConst.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsGeneral.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsGeneral.class new file mode 100644 index 0000000..a133650 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/CommonsGeneral.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.class new file mode 100644 index 0000000..5a50892 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMain.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.class new file mode 100644 index 0000000..f9e8070 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitMessages.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.class new file mode 100644 index 0000000..be6126f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/BukkitSettings.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.class new file mode 100644 index 0000000..0a7af8a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/BukkitPlayer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.class new file mode 100644 index 0000000..22f1962 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/account/permission/PlayerAttachment.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.class new file mode 100644 index 0000000..13f392b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/BukkitServerAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.class new file mode 100644 index 0000000..22b31ab Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/actionbar/ActionBarAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.class new file mode 100644 index 0000000..52f5927 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBar.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI$1.class new file mode 100644 index 0000000..6e1f0e7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.class new file mode 100644 index 0000000..b1b8949 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/bossbar/BossBarAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI$1.class new file mode 100644 index 0000000..8a88dff Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.class new file mode 100644 index 0000000..8b906ba Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/CooldownAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.class new file mode 100644 index 0000000..f38c9b3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/cooldown/types/Cooldown.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.class new file mode 100644 index 0000000..327a223 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/fake/FakeAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram$1.class new file mode 100644 index 0000000..7a415e3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.class new file mode 100644 index 0000000..3b2b5ff Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/CraftHologram.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$1.class new file mode 100644 index 0000000..b0dccff Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$2.class new file mode 100644 index 0000000..2d90f53 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.class new file mode 100644 index 0000000..94a7c7c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/DefaultHologram.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.class new file mode 100644 index 0000000..e452fea Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/Hologram.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.class new file mode 100644 index 0000000..b28980a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector$1.class new file mode 100644 index 0000000..39df0ca Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.class new file mode 100644 index 0000000..633abcb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramInjector.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners$1.class new file mode 100644 index 0000000..8a523c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.class new file mode 100644 index 0000000..aa714cf Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramListeners.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.class new file mode 100644 index 0000000..7331d23 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/HologramOffsets.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.class new file mode 100644 index 0000000..59ac81b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/PlayerTop.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.class new file mode 100644 index 0000000..233b58c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/ClassBuilder.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.class new file mode 100644 index 0000000..b3ee5aa Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/MathUtil.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.class new file mode 100644 index 0000000..2498a6a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMSClass.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.class new file mode 100644 index 0000000..055a599 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/NMUClass.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.class new file mode 100644 index 0000000..25acaa5 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/Reflection.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.class new file mode 100644 index 0000000..1e301ac Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Class.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.class new file mode 100644 index 0000000..8d74ff1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Field.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.class new file mode 100644 index 0000000..6b962fb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/Method.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.class new file mode 100644 index 0000000..367e903 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/annotation/ReflectionAnnotations.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_8.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_8.class new file mode 100644 index 0000000..05c40db Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_8.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9$ValueType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9$ValueType.class new file mode 100644 index 0000000..f48bd4e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9$ValueType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9.class new file mode 100644 index 0000000..0808301 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher$V1_9.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.class new file mode 100644 index 0000000..de25945 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/DataWatcher.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$1.class new file mode 100644 index 0000000..7a1acaa Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version$1.class new file mode 100644 index 0000000..98b20d6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version.class new file mode 100644 index 0000000..efcfaa6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft$Version.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.class new file mode 100644 index 0000000..2cf7cc8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/minecraft/Minecraft.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.class new file mode 100644 index 0000000..34df2a8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ClassResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.class new file mode 100644 index 0000000..712b33a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ConstructorResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.class new file mode 100644 index 0000000..574b067 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/FieldResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.class new file mode 100644 index 0000000..8e9e7b6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MemberResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.class new file mode 100644 index 0000000..4479d5d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/MethodResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.class new file mode 100644 index 0000000..7bb2020 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverAbstract.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$1.class new file mode 100644 index 0000000..1144516 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$Builder.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$Builder.class new file mode 100644 index 0000000..c65a240 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery$Builder.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.class new file mode 100644 index 0000000..03ecbde Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/ResolverQuery.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.class new file mode 100644 index 0000000..870dc06 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/NMSClassResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.class new file mode 100644 index 0000000..63d01d8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/minecraft/OBCClassResolver.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.class new file mode 100644 index 0000000..5f29cc0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ClassWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.class new file mode 100644 index 0000000..8230cf1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/ConstructorWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.class new file mode 100644 index 0000000..b326a9a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/FieldWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper$MethodSignature.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper$MethodSignature.class new file mode 100644 index 0000000..5e9c845 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper$MethodSignature.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.class new file mode 100644 index 0000000..bbcdc86 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/MethodWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.class new file mode 100644 index 0000000..6259761 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/resolver/wrapper/WrapperAbstract.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.class new file mode 100644 index 0000000..0b143cd Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/reflection/util/AccessUtil.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.class new file mode 100644 index 0000000..31ebf8e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchAction.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.class new file mode 100644 index 0000000..3416784 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/touch/TouchHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.class new file mode 100644 index 0000000..4c81b9a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/types/SimpleHologram.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.class new file mode 100644 index 0000000..c3dc148 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/hologram/view/ViewHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.class new file mode 100644 index 0000000..e4a6632 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack$InteractHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack$InteractHandler.class new file mode 100644 index 0000000..f39bede Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack$InteractHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.class new file mode 100644 index 0000000..bb33c8d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ActionItemStack.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.class new file mode 100644 index 0000000..f2f7f88 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemBuilder.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.class new file mode 100644 index 0000000..bf52cd3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/item/ItemChance.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.class new file mode 100644 index 0000000..d72a3a8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/ClickType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.class new file mode 100644 index 0000000..1e1481e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuClickHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.class new file mode 100644 index 0000000..3eff2ce Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuHolder.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.class new file mode 100644 index 0000000..9df9915 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuInventory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem$1.class new file mode 100644 index 0000000..5f29c02 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.class new file mode 100644 index 0000000..a22bbc6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuItem.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener$1.class new file mode 100644 index 0000000..c4aa826 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.class new file mode 100644 index 0000000..69bb989 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/menu/MenuListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.class new file mode 100644 index 0000000..04ec15e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCLib.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.class new file mode 100644 index 0000000..8d9c9c2 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/NPCManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.class new file mode 100644 index 0000000..9f82270 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/NPC.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.class new file mode 100644 index 0000000..3a2f0ca Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/PacketHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.class new file mode 100644 index 0000000..a6f5397 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/api/wrapper/GameProfileWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.class new file mode 100644 index 0000000..a8bd5ae Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/NPCInteractEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.class new file mode 100644 index 0000000..23686eb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/events/click/ClickType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.class new file mode 100644 index 0000000..3b17b8b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/listener/NPCListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.class new file mode 100644 index 0000000..f9c9489 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/NPC_v1_8_R3.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.class new file mode 100644 index 0000000..186cc98 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutEntityHeadRotationWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.class new file mode 100644 index 0000000..b567aeb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutNamedEntitySpawnWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.class new file mode 100644 index 0000000..8628f32 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutPlayerInfoWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.class new file mode 100644 index 0000000..d7fd534 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/npc/packets/packets/PacketPlayOutScoreboardTeamWrapper.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.class new file mode 100644 index 0000000..730ff7f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/player/PlayerAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.class new file mode 100644 index 0000000..d8aa63b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/protocol/ProtocolGetter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.class new file mode 100644 index 0000000..20844a0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/title/TitleAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.class new file mode 100644 index 0000000..deeb1bc Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/api/vanish/VanishAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCommand.class new file mode 100644 index 0000000..472ef85 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCompleter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCompleter.class new file mode 100644 index 0000000..03440a8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework$BukkitCompleter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.class new file mode 100644 index 0000000..9ea4877 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandFramework.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.class new file mode 100644 index 0000000..dde9940 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/BukkitCommandSender.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.class new file mode 100644 index 0000000..a7a22fa Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AccountCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.class new file mode 100644 index 0000000..239bdd8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/AdminCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.class new file mode 100644 index 0000000..1f53d65 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/BroadCastCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.class new file mode 100644 index 0000000..6d97a03 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ChatCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.class new file mode 100644 index 0000000..2e7d839 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/ClearDropsCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.class new file mode 100644 index 0000000..8e8e477 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/DanoCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.class new file mode 100644 index 0000000..195e149 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FakeCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.class new file mode 100644 index 0000000..969ccde Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/FlyCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.class new file mode 100644 index 0000000..3f1c43a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/GameModeCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.class new file mode 100644 index 0000000..c572d38 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/InvseeCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.class new file mode 100644 index 0000000..cfbfe18 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/KillMobsCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.class new file mode 100644 index 0000000..0666c55 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/MedalsCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.class new file mode 100644 index 0000000..b467d48 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/PingCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.class new file mode 100644 index 0000000..48c713f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/RankCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.class new file mode 100644 index 0000000..0857e8d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SkinCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.class new file mode 100644 index 0000000..db9f5c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SpyCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.class new file mode 100644 index 0000000..3f00662 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/StopCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand$1.class new file mode 100644 index 0000000..ca74117 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.class new file mode 100644 index 0000000..3827890 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/SyncTpallCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.class new file mode 100644 index 0000000..f55ad81 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TagCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.class new file mode 100644 index 0000000..433847f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TeleportCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.class new file mode 100644 index 0000000..d43127b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TellCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.class new file mode 100644 index 0000000..b510c66 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/TpallCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.class new file mode 100644 index 0000000..b18098e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/commands/register/WorldEditCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent$UpdateType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent$UpdateType.class new file mode 100644 index 0000000..92ca0b1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent$UpdateType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.class new file mode 100644 index 0000000..50d7988 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/BukkitUpdateEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent$AdminChangeType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent$AdminChangeType.class new file mode 100644 index 0000000..a729d0d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent$AdminChangeType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.class new file mode 100644 index 0000000..7006114 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerAdminChangeEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.class new file mode 100644 index 0000000..0b5e37b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerCancellableEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.class new file mode 100644 index 0000000..89c7c8d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeGroupEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent$ScoreboardChangeType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent$ScoreboardChangeType.class new file mode 100644 index 0000000..b7b31e5 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent$ScoreboardChangeType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.class new file mode 100644 index 0000000..d969e5e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeScoreboardEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.class new file mode 100644 index 0000000..fa78fcb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeTagEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.class new file mode 100644 index 0000000..278a97a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerChangeVisibilityEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.class new file mode 100644 index 0000000..144002d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.class new file mode 100644 index 0000000..070a64a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerQueueEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.class new file mode 100644 index 0000000..b8838b6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerRequestEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.class new file mode 100644 index 0000000..d6aacf4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/player/PlayerUpdateTabEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.class new file mode 100644 index 0000000..80d3c56 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerLoadedEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.class new file mode 100644 index 0000000..0abf781 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStatusUpdateEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.class new file mode 100644 index 0000000..0b2fc60 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/events/server/ServerStopEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.class new file mode 100644 index 0000000..b88da95 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/PacketObject.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.class new file mode 100644 index 0000000..29ba241 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.class new file mode 100644 index 0000000..203ab4c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/listener/PacketListenerAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector$1.class new file mode 100644 index 0000000..bf8ca6b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.class new file mode 100644 index 0000000..9b7e171 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/NPCPacketInjector.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector$1.class new file mode 100644 index 0000000..00fbb19 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.class new file mode 100644 index 0000000..007b349 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/packets/ServerPacketInjector.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$1.class new file mode 100644 index 0000000..8bad44a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$2.class new file mode 100644 index 0000000..106d362 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$3.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$3.class new file mode 100644 index 0000000..2a60cbd Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$3.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$4.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$4.class new file mode 100644 index 0000000..e4747c0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$4.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$5.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$5.class new file mode 100644 index 0000000..1955523 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$5.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$PacketInterceptor.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$PacketInterceptor.class new file mode 100644 index 0000000..12a3b66 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol$PacketInterceptor.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.class new file mode 100644 index 0000000..91d93f7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/injector/protocol/CommonProtocol.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.class new file mode 100644 index 0000000..ac9b1c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/custom/scheduler/BukkitUpdateScheduler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.class new file mode 100644 index 0000000..db8c51f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/AfkListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.class new file mode 100644 index 0000000..30fbfdf Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ChatListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.class new file mode 100644 index 0000000..e7ae77c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/CoreListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.class new file mode 100644 index 0000000..c249368 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/DamageListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.class new file mode 100644 index 0000000..873bbba Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/LoginListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.class new file mode 100644 index 0000000..86315d8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/ScoreboardListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.class new file mode 100644 index 0000000..abca79b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/listeners/WorldDListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.class new file mode 100644 index 0000000..29e28ae Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/BukkitManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesDano.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesDano.class new file mode 100644 index 0000000..328e482 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesDano.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesGlobalConfig.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesGlobalConfig.class new file mode 100644 index 0000000..bb9adac Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager$ValuesGlobalConfig.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.class new file mode 100644 index 0000000..e6c2d88 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/BukkitConfigurationManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.class new file mode 100644 index 0000000..26dc3aa Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/PluginConfiguration.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.class new file mode 100644 index 0000000..1323b0c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/BukkitConfiguration.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.class new file mode 100644 index 0000000..76387c3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/manager/configuration/impl/Utf8YamlConfiguration.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$1.class new file mode 100644 index 0000000..9bdedb8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$2.class new file mode 100644 index 0000000..96711bf Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$3.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$3.class new file mode 100644 index 0000000..47e56a1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory$3.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.class new file mode 100644 index 0000000..3fe6e16 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/AccountInventory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory$1.class new file mode 100644 index 0000000..b20e1c0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.class new file mode 100644 index 0000000..cead1bc Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/DuelsInfoInventory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$1.class new file mode 100644 index 0000000..1e36817 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$2.class new file mode 100644 index 0000000..2087279 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$3.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$3.class new file mode 100644 index 0000000..0266c78 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$3.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$4.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$4.class new file mode 100644 index 0000000..8504066 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory$4.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.class new file mode 100644 index 0000000..5dd3dd2 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/LibraryInventory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$1.class new file mode 100644 index 0000000..1b1d0d1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$2.class new file mode 100644 index 0000000..5c44400 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.class new file mode 100644 index 0000000..6c8e1a1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/menu/PlayerStatisticsInventory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler$1.class new file mode 100644 index 0000000..230c4d4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.class new file mode 100644 index 0000000..3c0c051 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/networking/BukkitPacketsHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue$1.class new file mode 100644 index 0000000..2074a0a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.class new file mode 100644 index 0000000..a6b8e41 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/PlayerBukkitQueue.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.class new file mode 100644 index 0000000..8b427c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/QueueType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.class new file mode 100644 index 0000000..d414d1e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/queue/player/PlayerQueue.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.class new file mode 100644 index 0000000..15663e3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/addons/Line.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.class new file mode 100644 index 0000000..96d4d48 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/Sidebar.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.class new file mode 100644 index 0000000..f4c3177 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/sidebar/SidebarManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.class new file mode 100644 index 0000000..3d67fd0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/scoreboard/tag/TagManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.class new file mode 100644 index 0000000..2eb787d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/BukkitLogFilter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.class new file mode 100644 index 0000000..da6f2a8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/LocationUtil.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$1.class new file mode 100644 index 0000000..1c622b7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$2.class new file mode 100644 index 0000000..9380378 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$3.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$3.class new file mode 100644 index 0000000..7eddfac Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$3.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$ConstructorInvoker.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$ConstructorInvoker.class new file mode 100644 index 0000000..e3c9f89 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$ConstructorInvoker.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$FieldAccessor.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$FieldAccessor.class new file mode 100644 index 0000000..3980ace Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$FieldAccessor.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$MethodInvoker.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$MethodInvoker.class new file mode 100644 index 0000000..77d0fdb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection$MethodInvoker.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.class new file mode 100644 index 0000000..146996e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/Reflection.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.class new file mode 100644 index 0000000..64dce9e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/utility/loader/BukkitListeners.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$1.class new file mode 100644 index 0000000..f54db99 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$2.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$2.class new file mode 100644 index 0000000..44783c4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions$2.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.class new file mode 100644 index 0000000..82f6f77 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/Constructions.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.class new file mode 100644 index 0000000..b4565ae Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.class new file mode 100644 index 0000000..594876f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/WorldEditManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.class new file mode 100644 index 0000000..abd452f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/Schematic.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.class new file mode 100644 index 0000000..473b21d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicBlock.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.class new file mode 100644 index 0000000..09e311a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/object/SchematicLocation.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.class new file mode 100644 index 0000000..7015f5d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Positions.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.class new file mode 100644 index 0000000..a1d39cc Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Region.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.class new file mode 100644 index 0000000..3f971af Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bukkit/worldedit/schematic/utils/Vector.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.class new file mode 100644 index 0000000..e423565 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMain.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.class new file mode 100644 index 0000000..2c7c9ec Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/BungeeMessages.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.class new file mode 100644 index 0000000..ce040b4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/BungeePlayer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.class new file mode 100644 index 0000000..b7f0256 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/account/permission/BungeePlayerPermissions.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCommand.class new file mode 100644 index 0000000..3824896 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCompleter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCompleter.class new file mode 100644 index 0000000..715de8a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework$BungeeCompleter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.class new file mode 100644 index 0000000..764b0fb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandFramework.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.class new file mode 100644 index 0000000..58a0276 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/BungeeCommandSender.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.class new file mode 100644 index 0000000..3a32c04 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AddPermCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.class new file mode 100644 index 0000000..25db680 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/AlertCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.class new file mode 100644 index 0000000..52d9d47 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeCompleter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.class new file mode 100644 index 0000000..c3a4068 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/BungeeInfoCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.class new file mode 100644 index 0000000..607ac92 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ChampionCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.class new file mode 100644 index 0000000..796fdca Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ClearAccountCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.class new file mode 100644 index 0000000..8a7ac0d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ConnectCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.class new file mode 100644 index 0000000..9574f25 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/CreateAccountCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.class new file mode 100644 index 0000000..4b3eb9b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/EventoCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.class new file mode 100644 index 0000000..3335b92 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/FindCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.class new file mode 100644 index 0000000..a63220d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GlobalListCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.class new file mode 100644 index 0000000..351e392 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GoCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.class new file mode 100644 index 0000000..0c0afc8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/GroupCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.class new file mode 100644 index 0000000..3a8f917 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickAllCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.class new file mode 100644 index 0000000..5164b40 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/KickCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.class new file mode 100644 index 0000000..695b5b1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/LobbyCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.class new file mode 100644 index 0000000..3a2ee8d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/MaintenanceCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.class new file mode 100644 index 0000000..1e58eee Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PremiumCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.class new file mode 100644 index 0000000..36dd2c7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/PunishCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.class new file mode 100644 index 0000000..85f420d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ReportCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.class new file mode 100644 index 0000000..16f4dac Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/SendCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.class new file mode 100644 index 0000000..cb6b68c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServersInfoCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.class new file mode 100644 index 0000000..efdb3d1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/ServiceCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.class new file mode 100644 index 0000000..64f39e0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffChatCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.class new file mode 100644 index 0000000..a9d714d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/commands/register/StaffListCommand.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent$BungeeUpdateType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent$BungeeUpdateType.class new file mode 100644 index 0000000..1b26de1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent$BungeeUpdateType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.class new file mode 100644 index 0000000..27565ff Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/BungeeUpdateEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.class new file mode 100644 index 0000000..d22f50a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/events/MotdCentralizer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.class new file mode 100644 index 0000000..8b0db69 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ChatListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.class new file mode 100644 index 0000000..515b742 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/GeneralListeners.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.class new file mode 100644 index 0000000..a77c827 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/LoginListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.class new file mode 100644 index 0000000..e9ff1c6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/PremiumMapListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.class new file mode 100644 index 0000000..7d5e79b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/ProxyPingListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.class new file mode 100644 index 0000000..7a181f3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/listeners/SessionListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.class new file mode 100644 index 0000000..61816b7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/BungeeManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.class new file mode 100644 index 0000000..3322583 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfiguration.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager$ValuesBungeeConfig.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager$ValuesBungeeConfig.class new file mode 100644 index 0000000..61a279d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager$ValuesBungeeConfig.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.class new file mode 100644 index 0000000..9d2c9a6 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/config/BungeeConfigurationManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.class new file mode 100644 index 0000000..0b365b0 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/AsyncPremiumCheck.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.class new file mode 100644 index 0000000..3d4e2ba Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMap.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.class new file mode 100644 index 0000000..cbaff80 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/manager/premium/PremiumMapManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler$1.class new file mode 100644 index 0000000..e145fe2 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.class new file mode 100644 index 0000000..2a7cee9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/networking/BungeePacketsHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.class new file mode 100644 index 0000000..f5113d4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/scheduler/BungeeUpdateScheduler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$1.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$1.class new file mode 100644 index 0000000..5d35f6c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$HTTPResponse.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$HTTPResponse.class new file mode 100644 index 0000000..0443379 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$HTTPResponse.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$Property.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$Property.class new file mode 100644 index 0000000..b5e242f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$Property.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$SkinRequestException.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$SkinRequestException.class new file mode 100644 index 0000000..e602a45 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI$SkinRequestException.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.class new file mode 100644 index 0000000..c206454 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/MojangAPI.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.class new file mode 100644 index 0000000..bd03776 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/ReflectionUtil.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.class new file mode 100644 index 0000000..6f474b7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinApplier.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.class new file mode 100644 index 0000000..6885181 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/skins/SkinStorage.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.class new file mode 100644 index 0000000..5d3de31 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/BungeeListeners.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.class new file mode 100644 index 0000000..474d2e3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/AbstractInjectableFilter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.class new file mode 100644 index 0000000..8a3cb32 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/CompoundFilter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.class new file mode 100644 index 0000000..edff220 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/Filters.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.class new file mode 100644 index 0000000..dee0ca8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/InjectableFilter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.class new file mode 100644 index 0000000..de66257 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/LogFilterBungee.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.class new file mode 100644 index 0000000..5dea099 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/bungee/utility/logfilter/PropagatingFilter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/PluginInstance.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/PluginInstance.class new file mode 100644 index 0000000..57751d4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/PluginInstance.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/Clan.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/Clan.class new file mode 100644 index 0000000..b6b15c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/Clan.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.class new file mode 100644 index 0000000..8b1765a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/clan/ClanManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.class new file mode 100644 index 0000000..da41a99 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandClass.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Command.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Command.class new file mode 100644 index 0000000..c6c3117 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Command.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Completer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Completer.class new file mode 100644 index 0000000..dfa4d9b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework$Completer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.class new file mode 100644 index 0000000..0efd4a3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandFramework.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.class new file mode 100644 index 0000000..a50f12a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/command/CommandSender.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.class new file mode 100644 index 0000000..0703657 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQL.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.class new file mode 100644 index 0000000..4274bc3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/connections/mysql/MySQLManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/Data.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/Data.class new file mode 100644 index 0000000..a8638f4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/Data.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.class new file mode 100644 index 0000000..bf1ad5c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/DataHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.class new file mode 100644 index 0000000..493bae4 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/category/DataCategory.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.class new file mode 100644 index 0000000..06809c9 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/data/type/DataType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/group/Groups.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/group/Groups.class new file mode 100644 index 0000000..ba71fd3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/group/Groups.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.class new file mode 100644 index 0000000..ba144d3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/GamingProfile.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.class new file mode 100644 index 0000000..2d13977 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/ProfileManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.class new file mode 100644 index 0000000..c8f8316 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/League.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.class new file mode 100644 index 0000000..908b97e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/addons/Medals.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.class new file mode 100644 index 0000000..5298fd5 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessToken.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.class new file mode 100644 index 0000000..b8ed6ed Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/profile/token/AcessTokenListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.class new file mode 100644 index 0000000..620b590 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentHistoric.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.class new file mode 100644 index 0000000..b874edc Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/PunishmentManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.class new file mode 100644 index 0000000..8550bc8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Ban.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.class new file mode 100644 index 0000000..4ec82f3 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/punishment/types/Mute.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.class new file mode 100644 index 0000000..1ae8038 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServerType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.class new file mode 100644 index 0000000..2fd454a Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/ServersManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.class new file mode 100644 index 0000000..1e95e74 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameStages.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.class new file mode 100644 index 0000000..ac28e91 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/enums/GameType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.class new file mode 100644 index 0000000..3fe16ab Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/GameServer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.class new file mode 100644 index 0000000..1792ae8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/serverinfo/types/NetworkServer.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/tag/Tag.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/tag/Tag.class new file mode 100644 index 0000000..9306837 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/tag/Tag.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/Cache.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/Cache.class new file mode 100644 index 0000000..2770dba Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/Cache.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.class new file mode 100644 index 0000000..7152214 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/ClassGetter.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher$UUIDFetcherException.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher$UUIDFetcherException.class new file mode 100644 index 0000000..98bb3a5 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher$UUIDFetcherException.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.class new file mode 100644 index 0000000..17d3144 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDFetcher.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.class new file mode 100644 index 0000000..efdba75 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/mojang/UUIDParser.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.class new file mode 100644 index 0000000..d086a9c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/Skin.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.class new file mode 100644 index 0000000..e4d7fca Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/skin/SkinFetcher.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.class new file mode 100644 index 0000000..92ec514 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/string/StringUtility.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.class new file mode 100644 index 0000000..780405e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/DateUtils.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.class new file mode 100644 index 0000000..d887a29 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/common/utility/system/Machine.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.class new file mode 100644 index 0000000..bad978c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/CommonPacketHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.class new file mode 100644 index 0000000..0baa1a8 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.class new file mode 100644 index 0000000..25c7d3e Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/PacketsManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.class new file mode 100644 index 0000000..e41cd75 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketAction.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.class b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.class new file mode 100644 index 0000000..da04d05 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/nowly/commons/custompackets/registry/CPacketCustomAction.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunication.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunication.class new file mode 100644 index 0000000..893adf7 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunication.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.class new file mode 100644 index 0000000..453e6de Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/client/Client.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/Client.class new file mode 100644 index 0000000..868f815 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/Client.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection$1.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection$1.class new file mode 100644 index 0000000..c78004c Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection$1.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection.class new file mode 100644 index 0000000..3dbc37d Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/client/ClientConnection.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.class new file mode 100644 index 0000000..539314f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/IConnection.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/IConnection.class new file mode 100644 index 0000000..f6ec1c1 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/IConnection.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.class new file mode 100644 index 0000000..807e16f Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.class new file mode 100644 index 0000000..c10fc15 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.class new file mode 100644 index 0000000..47d2e21 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager$PacketEvent.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager$PacketEvent.class new file mode 100644 index 0000000..2e8079b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager$PacketEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.class new file mode 100644 index 0000000..44209bb Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.class new file mode 100644 index 0000000..bf07845 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateEvent.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateEvent.class new file mode 100644 index 0000000..04f2403 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateEvent.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateType.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateType.class new file mode 100644 index 0000000..d5b7f69 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener$UpdateType.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.class new file mode 100644 index 0000000..545cd68 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.class new file mode 100644 index 0000000..21c50c5 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/server/Server.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/Server.class new file mode 100644 index 0000000..4335e52 Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/Server.class differ diff --git a/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ServerGeneral.class b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ServerGeneral.class new file mode 100644 index 0000000..82ece6b Binary files /dev/null and b/commons/target/classes/com/br/guilhermematthew/servercommunication/server/ServerGeneral.class differ diff --git a/commons/target/classes/config.yml b/commons/target/classes/config.yml new file mode 100644 index 0000000..cb11d16 --- /dev/null +++ b/commons/target/classes/config.yml @@ -0,0 +1,5 @@ +Servidor: Unknown +ServidorID: 0 + +Socket: + Host: 127.0.0.1 \ No newline at end of file diff --git a/commons/target/classes/plugin.yml b/commons/target/classes/plugin.yml new file mode 100644 index 0000000..0cfa86b --- /dev/null +++ b/commons/target/classes/plugin.yml @@ -0,0 +1,4 @@ +name: BukkitCommons +main: com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 \ No newline at end of file diff --git a/commons/target/commons-1.0-SNAPSHOT-shaded.jar b/commons/target/commons-1.0-SNAPSHOT-shaded.jar new file mode 100644 index 0000000..022c0b0 Binary files /dev/null and b/commons/target/commons-1.0-SNAPSHOT-shaded.jar differ diff --git a/commons/target/commons-1.0-SNAPSHOT.jar b/commons/target/commons-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..022c0b0 Binary files /dev/null and b/commons/target/commons-1.0-SNAPSHOT.jar differ diff --git a/commons/target/maven-archiver/pom.properties b/commons/target/maven-archiver/pom.properties new file mode 100644 index 0000000..0125d6c --- /dev/null +++ b/commons/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Feb 24 01:39:30 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=commons diff --git a/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..1d90ed5 --- /dev/null +++ b/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,19 @@ +com\br\guilhermematthew\nowly\commons\bukkit\menu\AccountInventory$3.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory$3.class +com\br\guilhermematthew\nowly\commons\bukkit\listeners\WorldDListener.class +com\br\guilhermematthew\nowly\commons\bungee\skins\MojangAPI$1.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\PlayerStatisticsInventory$2.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory$2.class +com\br\guilhermematthew\nowly\commons\bukkit\networking\BukkitPacketsHandler$1.class +com\br\guilhermematthew\nowly\commons\bungee\commands\register\ChampionCommand.class +com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\ResolverQuery$1.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory$1.class +com\br\guilhermematthew\nowly\commons\bungee\commands\register\MaintenanceCommand.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\DuelsInfoInventory$1.class +com\br\guilhermematthew\nowly\commons\bungee\commands\register\ServiceCommand.class +com\br\guilhermematthew\nowly\commons\bungee\networking\BungeePacketsHandler$1.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\PlayerStatisticsInventory$1.class +com\br\guilhermematthew\nowly\commons\bukkit\listeners\AfkListener.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory$4.class +com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\minecraft\Minecraft$1.class +com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory.class diff --git a/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..4629ef8 --- /dev/null +++ b/commons/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,279 @@ +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\custompackets\CommonPacketHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\MenuInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\player\PlayerAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\CompoundFilter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\utils\Positions.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\KickCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\ClearDropsCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ServiceCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\item\ActionItemStack.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\TeleportCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\clan\ClanManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\FieldResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\handle\InputHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\Constructions.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\premium\PremiumMapManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\AdminCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\annotation\Method.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\LoginListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\addons\Medals.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\ClassBuilder.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\touch\TouchHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\packets\packets\PacketPlayOutPlayerInfoWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\events\NPCInteractEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\WorldEditCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\account\BungeePlayer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\packets\ServerPacketInjector.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\BroadCastCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\ChatCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\custompackets\PacketType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\connections\mysql\MySQL.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\punishment\PunishmentHistoric.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\protocol\CommonProtocol.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\LobbyCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\Filters.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\types\SimpleHologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\minecraft\DataWatcher.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ServersInfoCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\ScoreboardListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\manager\configuration\BukkitConfigurationManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\InjectableFilter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\wrapper\ClassWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerChangeScoreboardEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\wrapper\MethodWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\GamingProfile.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\GlobalListCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\api\PacketHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\networking\BukkitPacketsHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\ResolverQuery.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\EventoCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\minecraft\NMSClassResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\BungeeMain.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\scoreboard\sidebar\Sidebar.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\PropagatingFilter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\token\AcessToken.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\client\Client.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\BukkitSettings.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerChangeVisibilityEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\HologramOffsets.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\BukkitUpdateEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\PremiumMapListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerUpdateTabEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\ChatListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ChampionCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\enums\GameType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\FlyCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\object\SchematicBlock.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\Cache.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\LoginListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\GroupCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\StaffListCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\protocol\ProtocolGetter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\account\permission\PlayerAttachment.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\DefaultHologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\CreateAccountCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\MenuHolder.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\BukkitMain.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\WorldDListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\bossbar\BossBar.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\account\BukkitPlayer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\ProxyPingListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\ConstructorResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\HologramAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerCancellableEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\MemberResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\config\BungeeConfigurationManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\skins\ReflectionUtil.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\DanoCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\Hologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\update\UpdateListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\packets\packets\PacketPlayOutEntityHeadRotationWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\TpallCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ReportCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\PlayerTop.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\CommonsConst.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\queue\QueueType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\scoreboard\tag\TagManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\system\DateUtils.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\KickAllCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\command\CommandClass.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\punishment\PunishmentManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\ResolverAbstract.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\events\click\ClickType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\item\ActionItemListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\AccountCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\CommonClient.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\packets\packets\PacketPlayOutNamedEntitySpawnWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\custompackets\PacketsManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\BungeeInfoCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\BukkitCommandSender.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\manager\configuration\impl\BukkitConfiguration.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\title\TitleAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ConnectCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\BungeeListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\menu\LibraryInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\types\NetworkServer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\CoreListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\utility\BukkitLogFilter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\server\Server.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\CommonPacket.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\PacketListenerManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\ProfileManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\command\CommandSender.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\FindCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\server\ServerLoadedEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\SyncTpallCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\tag\Tag.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\DamageListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\queue\player\PlayerQueue.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\ServerCommunicationInstance.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\ClearAccountCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\FakeCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\ServersManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\manager\configuration\impl\Utf8YamlConfiguration.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\manager\BukkitManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\actionbar\ActionBarAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\util\AccessUtil.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\touch\TouchAction.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\data\category\DataCategory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\enums\GameStages.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\api\NPC.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\WorldEditManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\HologramInjector.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\BungeeCommandFramework.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\server\ServerGeneral.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\bossbar\BossBarAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\AddPermCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\BungeeCommandSender.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\handle\OutputHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\types\GameServer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\client\ClientConnection.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\minecraft\Minecraft.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\AfkListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\listener\NPCListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\scheduler\BukkitUpdateScheduler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\queue\PlayerBukkitQueue.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\GeneralListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\fake\FakeAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\skin\SkinFetcher.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\server\ServerStatusUpdateEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\NPCManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\BukkitCommandFramework.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\SendCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\PluginInstance.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\packets\packets\PacketPlayOutScoreboardTeamWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\server\ConnectionInfo.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\group\Groups.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\string\StringUtility.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\token\AcessTokenListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\command\CommandFramework.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\annotation\Class.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\punishment\types\Mute.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\KillMobsCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\CraftHologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\StaffChatCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\events\BungeeUpdateEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\item\ItemBuilder.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\punishment\types\Ban.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerRequestEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\scoreboard\sidebar\SidebarManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\RankCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\premium\PremiumMap.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\annotation\ReflectionAnnotations.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\BukkitMessages.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\SkinCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\utils\Vector.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\ClassResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\MethodResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\connections\mysql\MySQLManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\BukkitServerAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\clan\Clan.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\NPCLib.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerQueueEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\cooldown\CooldownAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\menu\PlayerStatisticsInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\system\Machine.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\StopCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\scoreboard\addons\Line.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\listeners\SessionListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\LogFilterBungee.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\utility\LocationUtil.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\minecraft\OBCClassResolver.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\listener\PacketListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\events\MotdCentralizer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\HologramListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\skins\SkinApplier.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\menu\AccountInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\PingCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\CommonsGeneral.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\listener\PacketListenerAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\view\ViewHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\InvseeCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerChangeGroupEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\TagCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\NMUClass.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\networking\BungeePacketsHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\Reflection.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\listeners\ChatListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\profile\addons\League.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\utility\loader\BukkitListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\utility\logfilter\AbstractInjectableFilter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\PunishCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\data\Data.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\GameModeCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\utility\Reflection.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\listener\PacketListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\GoCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\scheduler\BungeeUpdateScheduler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\skins\MojangAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\ServerCommunication.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\utils\Region.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\wrapper\ConstructorWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\MedalsCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\BungeeManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\skins\SkinStorage.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\WorldEditAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\BungeeMessages.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\data\DataHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\wrapper\WrapperAbstract.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\ClickType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\MenuClickHandler.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\vanish\VanishAPI.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\menu\DuelsInfoInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\TellCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\item\ItemChance.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\commands\register\SpyCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\MaintenanceCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\account\permission\BungeePlayerPermissions.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\packets\NPCPacketInjector.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\manager\configuration\PluginConfiguration.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\serverinfo\ServerType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\mojang\UUIDParser.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\custompackets\registry\CPacketAction.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\object\SchematicLocation.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\data\type\DataType.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\skin\Skin.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\IConnection.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\resolver\wrapper\FieldWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\premium\AsyncPremiumCheck.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\NMSClass.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\mojang\UUIDFetcher.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\MathUtil.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\injector\PacketObject.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\AlertCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\MenuItem.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\api\wrapper\GameProfileWrapper.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\server\ServerStopEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerAdminChangeEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\custom\events\player\PlayerChangeTagEvent.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\PremiumCommand.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\menu\MenuListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\custompackets\registry\CPacketCustomAction.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\npc\packets\NPC_v1_8_R3.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\cooldown\types\Cooldown.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\manager\config\BungeeConfiguration.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\worldedit\schematic\object\Schematic.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bukkit\api\hologram\reflection\annotation\Field.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\common\utility\ClassGetter.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\commons\src\main\java\com\br\guilhermematthew\nowly\commons\bungee\commands\register\BungeeCompleter.java diff --git a/commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/commons/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/commons/target/original-commons-1.0-SNAPSHOT.jar b/commons/target/original-commons-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..4a28d70 Binary files /dev/null and b/commons/target/original-commons-1.0-SNAPSHOT.jar differ diff --git a/hardcoregames/.idea/.gitignore b/hardcoregames/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/hardcoregames/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/hardcoregames/.idea/compiler.xml b/hardcoregames/.idea/compiler.xml new file mode 100644 index 0000000..966895e --- /dev/null +++ b/hardcoregames/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hardcoregames/.idea/gradle.xml b/hardcoregames/.idea/gradle.xml new file mode 100644 index 0000000..cabf132 --- /dev/null +++ b/hardcoregames/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/hardcoregames/.idea/jarRepositories.xml b/hardcoregames/.idea/jarRepositories.xml new file mode 100644 index 0000000..e284c41 --- /dev/null +++ b/hardcoregames/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/hardcoregames/.idea/misc.xml b/hardcoregames/.idea/misc.xml new file mode 100644 index 0000000..c299b59 --- /dev/null +++ b/hardcoregames/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/hardcoregames/.idea/modules/hardcoregames.main.iml b/hardcoregames/.idea/modules/hardcoregames.main.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/hardcoregames/.idea/modules/hardcoregames.main.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/hardcoregames/jars/hardcoregames-1.0-SNAPSHOT.jar b/hardcoregames/jars/hardcoregames-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..7cc7676 Binary files /dev/null and b/hardcoregames/jars/hardcoregames-1.0-SNAPSHOT.jar differ diff --git a/hardcoregames/pom.xml b/hardcoregames/pom.xml new file mode 100644 index 0000000..ae4634a --- /dev/null +++ b/hardcoregames/pom.xml @@ -0,0 +1,28 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + hardcoregames + + + 8 + 8 + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + Project + + + + \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.java new file mode 100644 index 0000000..901009a --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.java @@ -0,0 +1,196 @@ +package com.br.guilhermematthew.nowly.hardcoregames; + +import java.io.File; + +import com.br.guilhermematthew.nowly.hardcoregames.game.GameManager; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.BorderListener; +import org.bukkit.Bukkit; +import org.bukkit.Difficulty; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuListener; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandFramework; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerLoadedEvent; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.hardcoregames.game.types.AutomaticEventType; +import com.br.guilhermematthew.nowly.hardcoregames.game.types.NormalType; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.GeneralListeners; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.PreGameListeners; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.ScoreboardListeners; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitLoader; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.timer.TimerManager; + +import lombok.Getter; + +public class HardcoreGamesMain extends JavaPlugin { + + @Getter + private static HardcoreGamesMain instance; + + @Getter + private static final TimerManager timerManager = new TimerManager(); + + @Getter + private static final GameManager gameManager = new GameManager(); + + public void onLoad() { + instance = this; + + saveDefaultConfig(); + Bukkit.getServer().unloadWorld("world", false); + deleteDir(new File("world")); + } + + public void onEnable() { + if (CommonsGeneral.correctlyStarted()) { + BukkitServerAPI.registerServer(); + + Bukkit.setDefaultGameMode(GameMode.ADVENTURE); + + if (CommonsConst.RANDOM.nextBoolean()) { + String value = getConfig().getString("DOUBLE_KIT"); + HardcoreGamesOptions.DOUBLE_KIT = value.isEmpty(); + console("Partida iniciada no modo DOUBLE KIT!"); + } + + getGameManager().setGameType(BukkitMain.getServerType() == ServerType.CHAMPIONS ? new AutomaticEventType() : new NormalType()); + + KitLoader.load(); + + BukkitCommandFramework.INSTANCE.loadCommands(this, "com.br.guilhermematthew.nowly.hardcoregames.commands"); + + getGameManager().setStage(GameStages.WAITING); + getGameManager().getGameType().initialize(); + + PluginManager pluginManager = getServer().getPluginManager(); + pluginManager.registerEvents(new BorderListener(), this); + pluginManager.registerEvents(new GeneralListeners(), this); + pluginManager.registerEvents(new PreGameListeners(), this); + pluginManager.registerEvents(new ScoreboardListeners(), this); + + StructuresManager.loadItens(); + HardcoreGamesScoreboard.init(); + MenuListener.registerListeners(); + + cleanWorld(); + } else { + Bukkit.shutdown(); + } + } + + public void onDisable() { + + } + + public static void console(String msg) { + Bukkit.getConsoleSender().sendMessage("[HardcoreGames] " + msg); + } + + public static void runAsync(Runnable runnable) { + Bukkit.getScheduler().runTaskAsynchronously(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + runLater(runnable, 5); + } + + public static void runLater(Runnable runnable, long ticks) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, ticks); + } + + private void cleanWorld() { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(getInstance(), () -> { + World world = getServer().getWorld("world"); + world.setDifficulty(Difficulty.NORMAL); + world.setAutoSave(false); + + org.bukkit.WorldBorder border = world.getWorldBorder(); + border.setCenter(0, 0); + border.setSize(806); + + world.setSpawnLocation(0, getServer().getWorlds().get(0).getHighestBlockYAt(0, 0) + 5, 0); + world.setAutoSave(false); + + ((CraftWorld) world).getHandle().savingDisabled = true; + + long time = System.currentTimeMillis(); + + try { + for (int x = 0; x <= 28; x++) { + for (int z = 0; z <= 28; z++) { + world.getSpawnLocation().clone().add(x * 16, 0, z * 16).getChunk().load(true); + world.getSpawnLocation().clone().add(x * -16, 0, z * -16).getChunk().load(true); + world.getSpawnLocation().clone().add(x * 16, 0, z * -16).getChunk().load(true); + world.getSpawnLocation().clone().add(x * -16, 0, z * 16).getChunk().load(true); + } + + if (x % 2 == 0) + console("[World] Loading chunks! " + DateUtils.formatSeconds((int) ((System.currentTimeMillis() - time) / 1000)) + + " have passed! - used mem: " + + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 2L + / 1048576L)); + } + } catch (OutOfMemoryError ex) { + ex.printStackTrace(); + } + + world.setDifficulty(Difficulty.NORMAL); + + if (world.hasStorm()) + world.setStorm(false); + + world.setTime(0L); + world.setWeatherDuration(999999999); + world.setGameRuleValue("doDaylightCycle", "false"); + world.setGameRuleValue("announceAdvancements", "false"); + + console("Criando bordas..."); + + time = System.currentTimeMillis(); + + for (int x = -401; x <= 401; x++) + if ((x == -401) || (x == 401)) + for (int z = -401; z <= 401; z++) + for (int y = 0; y <= 150; y++) { + world.getBlockAt(x, y, z).setType(Material.BEDROCK); + } + + for (int z = -401; z <= 401; z++) + if ((z == -401) || (z == 401)) + for (int x = -401; x <= 401; x++) + for (int y = 0; y <= 150; y++) { + world.getBlockAt(x, y, z).setType(Material.BEDROCK); + } + + console("Bordas criadas " + DateUtils.formatSeconds((int) ((System.currentTimeMillis() - time) / 1000))); + + world.getEntities().forEach(Entity::remove); + + getServer().getPluginManager().callEvent(new ServerLoadedEvent()); + }); + } + + public void deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (String child : children) { + deleteDir(new File(dir, child)); + } + } + dir.delete(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.java new file mode 100644 index 0000000..8b07c3f --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.hardcoregames; + +public class HardcoreGamesOptions { + + public static boolean BREAK_OPTION = true; + public static boolean PLACE_OPTION = true; + public static boolean DROP_OPTION = true; + public static boolean SPEC_OPTION = true; + public static boolean SPEC_FREE_OPTION = false; + public static boolean RELOG_OPTION = true; + + public static boolean DOUBLE_KIT = false; + + public static boolean FEAST = true; + public static boolean MINIFEAST = true; + + public static boolean KITS_DISABLEDS = false; + public static boolean KITS_FREE = false; + + public static final int FINAL_BATTLE_SPAWN = 2400; // SEGUNDOS 2.400 = 40 MINUTOS. + public static final int MAX_TIME = 3600; // SEGUNDOS 3.600 = 60 MINUTOS. + public static final int FEAST_SPAWN = 600; // SEGUNDOS 600 = 10 MINUTOS. + public static final int MIN_PLAYERS = 10; +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.java new file mode 100644 index 0000000..35940ad --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.java @@ -0,0 +1,143 @@ +package com.br.guilhermematthew.nowly.hardcoregames; + +public class StringUtils { + + public static final String + + VOCE_NAO_PODE_USAR_ESTA_COMBINACAO_DE_KIT = "§cEsta combinação de kit está bloqueada!", + VOCE_COMPROU_O_KIT = "§eVocê comprou o kit §b%kit%!", + VOCE_NAO_TEM_COINS_O_SUFICIENTE_PARA_COMPRAR_O_KIT = "§cVocê precisa de mais %valor% coins para comprar este kit!", + + ARENA_FINAL_SPAWNED = "§aA arena final foi criada", + COMBINACAO_BLOQUEADA = "§cEsta combinação de kits está bloqueada.", + VOCE_NAO_PODE_PEGAR_DOIS_KITS_IGUAIS = "§cVocê já está com esse kit", + CREATING_ARENA = "§aArena sendo criada...", + ARENA_CREATED = "§aA arena foi criada com sucesso!", + ARENA_CLEANED = "§aA arena foi limpa com sucesso!", + ARENA_NOT_CLEANED = "§cNão tem nenhuma arena para limpar.", + + PLAYER_WIN = "§a%nick% venceu a partida!", + + COMMAND_TEMPO_USAGE = "§cUtilize o comando: /tempo ", + TEMPO_CHANGED = "§aO tempo foi alterado para %tempo%", + + COMMAND_ARENA_USAGE = + "§cUtilize: /arena \n" + + "§cUtilize: /arena limpar\n" + + "§cUtilize: /arena final", + + COMMAND_START_FAILED = "§eA partida já iniciou.", + + COMMAND_SKIT_USAGE = "\n"+ + "§cUtilize: /skit criar \n" + + "§cUtilize: /skit aplicar \n" + + "§cUtilize: /skit lista\n", + + COMMAND_SKIT_NENHUM_CRIADO = "§cNenhum kit foi criado.", + COMMAND_SKIT_LISTA = "§aSetKits criados: §a", + COMMAND_SKIT_JA_EXISTE = "§cEste kit já foi criado.", + COMMAND_SKIT_NAO_EXISTE = "§cEste kit não existe!", + COMMAND_SKIT_CRIADO = "§aVocê criou o kit §a%nome%", + COMMAND_SKIT_SUCESSO_ALL_PLAYERS = "§aVocê aplicou o kit §a%nome% para todos os jogadores vivos na partida.", + COMMAND_SKIT_SUCESSO_PLAYER = "§aVocê aplicou o kit %nome% para o %nick%", + + O_KIT_SURPRISE_ESCOLHEU_O_KIT = "§eO Surprise escolheu o kit %kit%", + VOCE_NAO_POSSUI_ESTE_KIT = "§cVocê não possui este kit!", + VOCE_JA_POSSUI_ESTE_KIT = "§cVocê já possui este kit!", + + COMMAND_FORCEKIT_USAGE = "§cUtilize: /forcekit ", + COMMAND_FORCEKIT_KIT_NAO_EXISTE = "§cEste kit não existe", + COMMAND_FORCEKIT_SUCESS_ALL_PLAYERS = "§aVocê setou o kit %kit% para todos os jogadores.", + COMMAND_FORCEKIT_SUCESS_PLAYER = "§aVocê setou o kit %kit% para %nick%.", + + SEU_KIT_FOI_DESATIVADO = "§cO seu kit %kit% foi desativado na partida!", + KIT_ATIVADO = "§aVocê ativou o kit %kit%", + KIT_DESATIVADO = "§cVocê desativou o kit %kit%", + KIT_JA_ESTA_ATIVADO = "§aO kit §a%kit% ja está ativado!", + KIT_JA_ESTA_DESATIVADO = "§cO kit §a%kit% ja está desativado!", + + TODOS_OS_KITS_FORAM_DESATIVADOS = "§cTodos os kits foram desativados!", + TODOS_OS_KITS_FORAM_ATIVADOS = "§aTodos os kis foram ativados!", + + FEAST_ATIVADO = "§aO feast foi ativado!", + FEAST_DESATIVADO = "§cO feast foi desativado!", + FEAST_JA_ATIVADO = "§aO feast já está ativado!", + FEAST_JA_DESATIVADO = "§cO feast já está desativado!", + + MINIFEAST_ATIVADO = "§aO mini-feast foi ativado!", + MINIFEAST_DESATIVADO = "§cO mini-feast foi desativado!", + MINIFEAST_JA_ATIVADO = "§aO mini-feast já está ativado!", + MINIFEAST_JA_DESATIVADO = "§cO mini-feast já está desativado!", + + DROPS_ATIVADO = "§aOs drops foram ativados!", + DROPS_DESATIVADO = "§cOs drops foram desativados!", + DROPS_JA_ATIVADO = "§aOs drops já estão ativados!", + DROPS_JA_DESATIVADO = "§cOs drops já estão desativados!", + + BREAK_ATIVADO = "§aO break foi ativado!", + BREAK_DESATIVADO = "§cO break foi desativado!", + BREAK_JA_ATIVADO = "§aO break já está ativado!", + BREAK_JA_DESATIVADO = "§cO break já está desativado!", + + PLACE_ATIVADO = "§aO place foi ativado!", + PLACE_DESATIVADO = "§cO place foi desativado!", + PLACE_JA_ATIVADO = "§aO place já está ativado!", + PLACE_JA_DESATIVADO = "§cO place já está desativado!", + + + TITLE_ON_KIT_SELECTED = "§b%kit%", + SUBTITLE_ON_KIT_SELECTED = "§aSelecionado!", + + COMMAND_KIT_NAO_EXISTE = "§cEste kit não existe!", + COMMAND_KIT_TODOS_KITS_DESATIVADOS = "§cTodos os kits estão desativados!", + COMMAND_KIT_KIT_DESATIVADO = "§cEste kit está desativado!!", + COMMAND_KIT_SUCESS = "§aVocê selecionou o kit §b%kit%", + + COMMAND_KIT_SEM_PERM_PARA_PEGAR_DEPOIS_DO_JOGO_TER_INICIADO = + "§cVocê não tem permissão para pegar kit após a partida ter iniciado!", + + COMMAND_KIT_TEMPO_ESGOTADO = "§cO tempo para pegar kit sendo VIP esgotou.", + COMMAND_KIT_VOCE_JA_ESTA_COM_KIT = "§cVocê já está com um kit selecionado!", + COMMAND_DESISTIR_O_JOGO_AINDA_NAO_INICIOU = "§cO jogo ainda não iniciou!", + COMMAND_DESISTIR_SUCESSO = "§aVocê desistiu da partida!", + COMMAND_DESISTIR_NAO_ESTA_JOGANDO = "§eVocê não está jogando!", + + COMMAND_FEAST_O_JOGO_AINDA_NAO_INICIOU = "§cO jogo ainda não iniciou!", + COMMAND_FEAST_NAO_TEM_BUSSOLA = "§cVocê precisa ter uma bússola no inventário!", + COMMAND_FEAST_NAO_SPAWNOU = "§cO FEAST ainda não spawnou!", + COMMAND_FEAST_SUCESSO = "§eBússola apontada para o FEAST!", + + COMMANDS_SPECS_USAGE = "§cUtilize: /specs ", + SPECS_ATIVADOS = "§aEspectadores agora estão visiveis!", + SPECS_DESATIVADOS = "§cEspectadores agora estão invisiveis!", + COMMAND_SPECS_GAME_DONT_STARTED = "§cO jogo ainda não iniciou!", + NENHUM_SPEC_ENCONTRADO = "§cNenhum espectador encontrado!", + + BUSSOLA_NOT_FINDED = "§cNenhum jogador foi encontrado! Bússola apontando para o spawn.", + BUSSOLA_FINDED = "§eSua bússola está sendo apontada para o jogador §7%nick%", + + PLAYER_KILL_IN_GAME = "§aVocê matou %morreu%!", + PLAYER_DEATH_FOR_PLAYER = "§b%matou% (%matouKit%) matou %morreu% (%morreuKit%) usando sua %item%. \n§c%restantes% jogadores restantes.", + PLAYER_DEATH = "§b%morreu% (%kit%) §emorreu %causa% \n§c%restantes% jogadores restantes.", + + PLAYER_RETURNED = "§a%nick% voltou ao jogo.", + PLAYER_DESISTIU = "§c%nick% (%kit%) desistiu da partida.\n§a%restantes% jogadores restantes.", + PLAYER_SAIU = "§c%nick% saiu do servidor.", + PLAYER_DEMOROU_PARA_RELOGAR = "§c%nick% (%kit%) demorou muito para retornar e foi eliminado.\n§a%restantes% jogadores restantes.", + LOGGOUT_IN_COMBAT = "§c%nick% (%kit%) saiu em combate.\n§a%restantes% jogadores restantes.", + + INVENCIBILITY_ENDED = "§aA invencibilidade acabou. Agora é a hora que a verdadeira batalha começa!", + THE_GAME_HAS_STARTED = "§aA partida foi iniciada!", + FINAL_ARENA_IN = "§aA Arena final irá spawnar em: §7%tempo%", + GAME_END_IN = "§aA partida irá acabar em: §7%tempo%", + GAME_START_IN = "§eA partida irá iniciar em §c%tempo%.", + INVENCIBILITY_END_IN = "§eA invencibilidade irá acabar em §c%tempo%.", + + MINIFEAST_SPAWNED = "§cUm mini-feast spawnou entre: (%x% x, %z% z e x %x1%, z %z1%)", + FEAST_SPAWN_IN = "§cO feast irá spawnar em %coords% em %tempo%.", + FEAST_SPAWNED = "§aO feast spawnou em %coords%!", + + //TELA DE LOGIN (Mensagem ao tentar entrar) + GAME_HAS_STARTED = "§cA partida já começou, compre VIP para poder espectar a partida.", + YOUR_HAVE_BEEN_ELIMINATED = "§cVocê foi eliminado! Compre VIP para que Você possa espectar as partidas."; +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.java new file mode 100644 index 0000000..78ebf64 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.java @@ -0,0 +1,213 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.CooldownAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.types.Cooldown; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.protocol.ProtocolGetter; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStartedEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitLoader; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public abstract class Kit implements Listener { + + private String name; + private List description; + private ItemStack icon; + private int price, cooldownSeconds; + private ItemStack[] itens; + + private final String itemColor = "§b"; + + private boolean useInvincibility, callEventRegisterPlayer = false; + private boolean listenerRegistred; + private int amountUsing; + + public void initialize(String kitName) { + setName(kitName); + + ItemStack icone = new ItemBuilder().type(Material.getMaterial( + getKitsConfig().getString("kits." + getName() + ".icon.material"))). + durability(getKitsConfig().getInt("kits." + getName() + ".icon.durability")). + amount(getKitsConfig().getInt("kits." + getName() + ".icon.amount")) + .build(); + + setIcon(icone); + + setItens(new ItemStack(Material.AIR)); + + setPrice(getKitsConfig().getInt("kits." + getName() + ".price")); + setCooldownSeconds(getKitsConfig().getInt("kits." + getName() + ".cooldown")); + updateDescription(getKitsConfig().getStringList("kits." + getName() + ".icon.description")); + setUseInvincibility(false); + + icone = null; + } + + public void updateDescription(List list) { + this.description = list; + + ItemMeta meta = getIcon().getItemMeta(); + + List lore = new ArrayList(); + + for (String descriptionL : this.description) { + lore.add(descriptionL.replaceAll("&", "§")); + } + + meta.setDisplayName("§a" + getName()); + meta.setLore(lore); + + getIcon().setItemMeta(meta); + setAmountUsing(0); + + lore.clear(); + + meta = null; + lore = null; + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + if (containsHability(event.getEntity())) { + clean(event.getEntity()); + } + } + + @EventHandler + public void onStart(GameStartedEvent event) { + setIcon(null); + } + + public void setItens(ItemStack... itens) { + this.itens = itens; + } + + protected boolean containsHability(Player player) { + return GamerManager.getGamer(player.getUniqueId()).containsKit(getName()); + } + + protected boolean useAbility(Player player) { + if (HardcoreGamesMain.getGameManager().isPreGame()) return false; + if (HardcoreGamesOptions.KITS_DISABLEDS) return false; + if (KitManager.getKitsDesativados().contains(getName().toLowerCase())) return false; + + if (HardcoreGamesMain.getGameManager().isInvencibilidade()) { + if (!isUseInvincibility()) { + return false; + } + } + + return containsHability(player); + } + + public void registerListener() { + if (!listenerRegistred) { + listenerRegistred = true; + Bukkit.getPluginManager().registerEvents(this, HardcoreGamesMain.getInstance()); + HardcoreGamesMain.console(getName() + " Listener has been registred!"); + } + } + + public void addUsing() { + this.amountUsing++; + } + + public void registerPlayer() { + this.amountUsing++; + + if (this.amountUsing == 1) { + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + registerListener(); + } + } + } + + public void cleanPlayer(Player player) { + CooldownAPI.removeAllCooldowns(player); + + clean(player); + } + + public void unregisterPlayer(Player player) { + CooldownAPI.removeAllCooldowns(player); + + clean(player); + + this.amountUsing--; + + if (this.amountUsing == 0) { + if (isListenerRegistred()) { + HardcoreGamesMain.console(getName() + " Listener has been unregistred!"); + HandlerList.unregisterAll(this); + listenerRegistred = false; + } + } + } + + protected abstract void clean(Player player); + + protected boolean hasCooldown(Player player) { + return CooldownAPI.hasCooldown(player, "Kit"); + } + + protected boolean hasCooldown(Player player, String cooldown) { + return CooldownAPI.hasCooldown(player, cooldown); + } + + protected void sendMessageCooldown(Player player) { + CooldownAPI.sendMessage(player, "Kit"); + } + + protected void sendMessageCooldown(Player player, String cooldown) { + CooldownAPI.sendMessage(player, cooldown); + } + + protected void addCooldown(Player player, String cooldownName, long time) { + if (CooldownAPI.hasCooldown(player, cooldownName)) { + CooldownAPI.removeCooldown(player, cooldownName); + } + CooldownAPI.addCooldown(player, new Cooldown(cooldownName, time, playerOn18(player))); + } + + protected void addCooldown(Player player, long time) { + if (CooldownAPI.hasCooldown(player, "Kit")) { + CooldownAPI.removeCooldown(player, "Kit"); + } + CooldownAPI.addCooldown(player, new Cooldown("Kit", time, playerOn18(player))); + } + + public boolean playerOn18(final Player player) { + return ProtocolGetter.getVersion(player) > 5; + } + + public FileConfiguration getKitsConfig() { + return KitLoader.getKitsConfig().getConfiguration(); + } + + public boolean checkItem(ItemStack item, String display) { + return (item != null && item.getType() != Material.AIR && item.hasItemMeta() && item.getItemMeta().hasDisplayName() + && item.getItemMeta().getDisplayName().startsWith(display)); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.java new file mode 100644 index 0000000..e88efb8 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.java @@ -0,0 +1,42 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Achilles extends Kit { + + public Achilles() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (event.isCancelled()) + return; + + if (useAbility(event.getDamaged())) { + ItemStack inHand = event.getPlayer().getItemInHand(); + + if (inHand == null || inHand.getType() == Material.AIR) + return; + + if (inHand.getType().name().contains("WOOD") || inHand.getType() == Material.STICK) { + event.setDamage(Math.max(7, event.getDamage() + 4)); + } else { + event.setDamage(2); + event.getPlayer().sendMessage("§c" + event.getDamaged().getName() + + " está usando o kit Achilles, itens de madeira causam mais dano."); + } + inHand = null; + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.java new file mode 100644 index 0000000..8752464 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.java @@ -0,0 +1,43 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Anchor extends Kit { + + public Anchor() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getDamaged())) { + handle(event.getDamaged(), event.getPlayer()); + } else if (useAbility(event.getPlayer())) { + handle(event.getDamaged(), event.getPlayer()); + } + } + + public void handle(Player player1, Player player2) { + player1.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + player2.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + + player1.playSound(player1.getLocation(), Sound.ANVIL_LAND, 1, 1); + player2.playSound(player2.getLocation(), Sound.ANVIL_LAND, 1, 1); + + HardcoreGamesMain.runLater(() -> { + player1.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + player2.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + }, 1L); + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.java new file mode 100644 index 0000000..c5d401f --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.java @@ -0,0 +1,76 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Barbarian extends Kit { + + public Barbarian() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.WOOD_SWORD).name(getItemColor() + "Barbarian Sword").unbreakable().build()); + } + + private HashMap kills = new HashMap(); + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + final Player morreu = event.getEntity(), killer = morreu.getKiller(); + + if (killer == null) { + return; + } + + if (!(killer instanceof Player)) { + return; + } + + if (this.kills.containsKey(killer.getUniqueId())) { + this.kills.put(killer.getUniqueId(), this.kills.get(killer.getUniqueId()) + 1); + } else { + this.kills.put(killer.getUniqueId(), 1); + } + + if (checkItem(killer.getItemInHand(), getItemColor() + "Barbarian Sword")) { + switch (this.kills.get(killer.getUniqueId())) { + case 1: + killer.getItemInHand().setType(Material.STONE_SWORD); + killer.getItemInHand().setDurability((short) 0); + break; + case 5: + killer.getItemInHand().setType(Material.IRON_SWORD); + killer.getItemInHand().setDurability((short) 0); + break; + case 8: + killer.getItemInHand().setType(Material.DIAMOND_SWORD); + killer.getItemInHand().setDurability((short) 0); + break; + case 10: + killer.getItemInHand().addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1); + killer.getItemInHand().setDurability((short) 0); + break; + case 12: + killer.getItemInHand().addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 1); + killer.getItemInHand().setDurability((short) 0); + break; + } + } + } + + @Override + protected void clean(Player player) { + if (kills.containsKey(player.getUniqueId())) { + kills.remove(player.getUniqueId()); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.java new file mode 100644 index 0000000..51251bb --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Berserker extends Kit { + + public Berserker() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onKilledPlayer(PlayerDeathEvent event) { + Player player = event.getEntity(); + if (containsHability(player.getKiller())) { + if (player.isDead()) { + if(player.getKiller() instanceof Player) { + player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 150, 1)); + player.sendMessage("§aVocê recebeu a força de um BERSERKER por um tempo valido de 10 segundos!"); + } + } + } + } + + @Override + protected void clean(Player player) { + } + +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.java new file mode 100644 index 0000000..85d3827 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.java @@ -0,0 +1,70 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Blink extends Kit { + + public Blink() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.NETHER_STAR).name(getItemColor() + "Kit " + getName()).build()); + } + + public HashMap blink = new HashMap<>(); + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + if ((player.getItemInHand().getType().equals(Material.NETHER_STAR)) && (containsHability(player))) { + if (hasCooldown(player)) { + sendMessageCooldown(player); + return; + } + + @SuppressWarnings("deprecation") + Block block = player.getTargetBlock((HashSet) null, 10); + + if (block.getType().equals(Material.AIR)) { + + blink.put(player.getUniqueId(), + blink.containsKey(player.getUniqueId()) ? blink.get(player.getUniqueId()) + 1 : 1); + + if (blink.get(player.getUniqueId()).equals(4)) { + blink.remove(player.getUniqueId()); + addCooldown(player, getCooldownSeconds()); + } + + block.setType(Material.LEAVES); + + Vector v = player.getEyeLocation().getDirection(); + + player.teleport(block.getLocation().add(0, 2, 0).setDirection(v)); + player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1); + + v = null; + } + block = null; + } + } + + @Override + protected void clean(Player player) { + if (blink.containsKey(player.getUniqueId())) { + blink.remove(player.getUniqueId()); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.java new file mode 100644 index 0000000..eb066b2 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.java @@ -0,0 +1,25 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Boxer extends Kit { + + public Boxer() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (containsHability(event.getDamaged())) { + event.setDamage(event.getDamage() - 1.0D); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.java new file mode 100644 index 0000000..3ab7392 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.java @@ -0,0 +1,37 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Cannibal extends Kit { + + public Cannibal() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getPlayer()) && Math.random() <= 0.35) { + int hungry = event.getPlayer().getFoodLevel(); + hungry++; + if (hungry <= 20) { + event.getPlayer().setFoodLevel(hungry); + } + + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 160, 1)); + event.getDamaged().setFoodLevel((int) (event.getDamaged().getFoodLevel() - 1.0)); + event.getDamaged().getLocation().getWorld().playEffect( + event.getDamaged().getLocation().add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.java new file mode 100644 index 0000000..c3648b5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.java @@ -0,0 +1,110 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Checkpoint extends Kit { + + public Checkpoint() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.NETHER_FENCE).name(getItemColor() + "Kit " + getName()).build(), + new ItemBuilder().material(Material.FLOWER_POT_ITEM).name(getItemColor() + "Kit " + getName()).build()); + } + + private HashMap checkpoints = new HashMap(); + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void colocar(BlockPlaceEvent e) { + Player p = e.getPlayer(); + Block b = e.getBlock(); + + if (b.getType() == Material.NETHER_FENCE) { + if (containsHability(p)) { + if (hasCooldown(p)) { + sendMessageCooldown(p); + e.setBuild(false); + e.setCancelled(true); + return; + } + p.setItemInHand(e.getItemInHand()); + p.updateInventory(); + if (checkpoints.containsKey(p.getUniqueId())) { + Location loc = checkpoints.get(p.getUniqueId()); + loc.getBlock().setType(Material.AIR); + } + checkpoints.put(p.getUniqueId(), e.getBlock().getLocation()); + p.sendMessage("§aPosição setada."); + } + } + } + + @EventHandler + public void teleportCheckpoint(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack i = p.getItemInHand(); + + if (i.getType() == Material.FLOWER_POT_ITEM) { + e.setCancelled(true); + + if (p.getLocation().getY() > 128) { + return; + } + + if (!containsHability(p)) { + return; + } + + if (!checkpoints.containsKey(p.getUniqueId())) { + p.sendMessage("§cVocê não ainda não salvou nenhuma localização."); + } else { + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + p.teleport(this.checkpoints.get(p.getUniqueId())); + p.sendMessage("§aTeleportado"); + p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0F, 1.0F); + addCooldown(p, getCooldownSeconds()); + } + } + } + + @EventHandler + public void blockDamage(BlockDamageEvent e) { + if (this.checkpoints.containsValue(e.getBlock().getLocation()) + && e.getBlock().getType() == Material.NETHER_FENCE) { + e.setCancelled(true); + for (UUID p : this.checkpoints.keySet()) { + if (this.checkpoints.get(p) == e.getBlock().getLocation()) { + if (Bukkit.getPlayer(p) != null) + Bukkit.getPlayer(p).sendMessage("§cO seu Checkpoint foi destruído."); + this.checkpoints.remove(p); + } + } + e.getBlock().setType(Material.AIR); + e.getPlayer().sendMessage("§cVocê destruiu um checkpoint."); + e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.EXPLODE, 1.0F, 1.0F); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.java new file mode 100644 index 0000000..3fbf6a6 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.TreeType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.material.CocoaPlant; + +public class Cultivator extends Kit { + + public Cultivator() { + initialize(getClass().getSimpleName()); + } + + @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlace(BlockPlaceEvent e) { + if (e.getBlock().getType() == Material.SAPLING && containsHability(e.getPlayer())) { + e.getBlock().setType(Material.AIR); + e.getBlock().getWorld().generateTree(e.getBlock().getLocation(), TreeType.TREE); + } else if (e.getBlock().getType() == Material.CROPS && containsHability(e.getPlayer())) { + e.getBlock().setData((byte) 7); + } else if (e.getBlock().getType() == Material.COCOA && containsHability(e.getPlayer())) { + CocoaPlant bean = (CocoaPlant) e.getBlock().getState().getData(); + if (bean.getSize() != CocoaPlant.CocoaPlantSize.LARGE) { + bean.setSize(CocoaPlant.CocoaPlantSize.LARGE); + e.getBlock().setData(bean.getData()); + } + bean = null; + } + } + + @Override + protected void clean(Player player) { + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.java new file mode 100644 index 0000000..51e50c6 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.java @@ -0,0 +1,75 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import lombok.val; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.metadata.FixedMetadataValue; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + + +public class Demoman extends Kit { + + public Demoman() { + initialize(getClass().getSimpleName()); + + setItens( + new ItemBuilder().material(Material.GRAVEL).amount(8).name(getItemColor() + "Kit " + getName()).build(), + new ItemBuilder().material(Material.STONE_PLATE).name(getItemColor() + "Kit " + getName()).amount(8) + .build()); + } + + @EventHandler + public void onPlace(BlockPlaceEvent e) { + if (e.isCancelled()) + return; + + if (e.getBlock().getType().name().contains("PLATE") && containsHability(e.getPlayer())) { + e.getBlock().setMetadata("demoman", new FixedMetadataValue(HardcoreGamesMain.getInstance(), e.getPlayer())); + } + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if (event.isCancelled()) + return; + + if (event.getAction() == Action.PHYSICAL && event.getClickedBlock() != null + && event.getClickedBlock().hasMetadata("demoman") + && event.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.GRAVEL) { + + event.getClickedBlock().getMetadata("demoman").stream() + .findFirst() + .ifPresent(rawMetadata -> { + val player = (Player) rawMetadata.value(); + + if(!player.equals(event.getPlayer())) event.getPlayer().getWorld().createExplosion(event.getClickedBlock().getLocation(), 4.1F); + }); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.getCause().toString().contains("EXPLOSION") && event.getEntity() instanceof Player + && containsHability((Player) event.getEntity())) { + double damage = event.getDamage(); + double porcent = 50.0D; + if (((Player) event.getEntity()).isBlocking()) { + porcent = 75.0D; + } + event.setDamage(event.getDamage() - ((damage / 100) * porcent)); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.java new file mode 100644 index 0000000..c95e187 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Digger extends Kit { + + public Digger() { + initialize(getClass().getSimpleName()); + + setUseInvincibility(true); + + setItens(new ItemBuilder().material(Material.DRAGON_EGG).name(getItemColor() + "Kit " + getName()).amount(5) + .build()); + } + + @SuppressWarnings("deprecation") + @EventHandler(ignoreCancelled = true) + public void onPlace(BlockPlaceEvent event) { + ItemStack item = event.getItemInHand(); + + if (item != null && item.getTypeId() == Material.DRAGON_EGG.getId() && useAbility(event.getPlayer())) { + if (hasCooldown(event.getPlayer())) { + sendMessageCooldown(event.getPlayer()); + return; + } + if (event.getBlock().getY() > 110) { + return; + } + addCooldown(event.getPlayer(), getCooldownSeconds()); + + final Block b = event.getBlock(); + b.setType(Material.AIR); + + new BukkitRunnable() { + public void run() { + int dist = (int) Math.ceil((5 - 1) / 2.0D); + + for (int y = -1; y >= -5; y--) { + for (int x = -dist; x <= dist; x++) { + for (int z = -dist; z <= dist; z++) { + + if (b.getY() + y > 0) { + Block block = b.getWorld().getBlockAt(b.getX() + x, b.getY() + y, b.getZ() + z); + if (block.getType() != Material.BEDROCK) { + block.setType(Material.AIR); + } + block = null; + } + } + } + } + } + }.runTaskLater(HardcoreGamesMain.getInstance(), 20); + } + item = null; + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.java new file mode 100644 index 0000000..0987d2c --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.java @@ -0,0 +1,162 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.ArrayList; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; + +public class Endermage extends Kit { + + public Endermage() { + initialize(getClass().getSimpleName()); + setUseInvincibility(true); + + setItens(new ItemBuilder().material(Material.NETHER_BRICK_ITEM).name(getItemColor() + "Kit " + getName()) + .build()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if (!event.getAction().name().contains("RIGHT")) + return; + + if ((event.getPlayer().getItemInHand().getType().equals(Material.NETHER_BRICK_ITEM)) + && (containsHability(event.getPlayer()))) { + + if (event.getClickedBlock().getType() != Material.ENDER_PORTAL_FRAME) { + Player player = event.getPlayer(); + + if (hasCooldown(player)) { + sendMessageCooldown(player); + return; + } + + final Block b = event.getClickedBlock(); + final BlockState bs = b.getState(); + + if (b.getType().equals(Material.BEDROCK)) { + player.sendMessage("§cVocê não pode puxar neste bloco."); + return; + } + if (player.getLocation().getBlockY() > 115) { + player.sendMessage("§cVocê não pode puxar nesta altura."); + return; + } + + b.setType(Material.ENDER_PORTAL_FRAME); + addCooldown(player, getCooldownSeconds()); + + new BukkitRunnable() { + int segundos = 5; + final Location portal2 = b.getLocation().clone().add(0.5, 1.5, 0.5); + + public void run() { + ArrayList players = getNearbyPlayers(player, portal2); + + if (!player.isOnline() || calculateDistance(player.getLocation(), portal2) > 50) { + if (!player.isOnline()) { + cancel(); + } + resetBlock(b, bs); + } + + if (!players.isEmpty()) { + for (Player pl : players) { + pl.setFallDistance(0); + pl.setNoDamageTicks(110); + pl.teleport(portal2); + player.sendMessage("§aVocê puxou: " + pl.getName()); + pl.sendMessage("§aVocê foi puxado pelo " + player.getName()); + pl.sendMessage("§aVocê esta invencível por 5 segundos"); + } + player.setFallDistance(0); + player.setNoDamageTicks(110); + player.teleport(portal2); + player.sendMessage("§cVocê esta invencível por 5 segundos"); + resetBlock(b, bs); + cancel(); + } + + if (segundos == 0) { + resetBlock(b, bs); + cancel(); + } + segundos--; + } + }.runTaskTimer(HardcoreGamesMain.getInstance(), 20L, 20L); + } + } + } + + @SuppressWarnings("deprecation") + private void resetBlock(Block b, BlockState bs) { + HardcoreGamesMain.runLater(() -> b.setTypeIdAndData(bs.getTypeId(), bs.getRawData(), false), 100); + } + + private ArrayList getNearbyPlayers(Player p2, Location portal) { + ArrayList players = new ArrayList<>(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (onlines == p2) + continue; + if (!isEnderable(portal, onlines.getLocation())) + continue; + if (onlines.getLocation().getBlockY() > 128) + continue; + if (VanishAPI.isInvisible(onlines)) + continue; + Gamer gamer = GamerManager.getGamer(onlines.getUniqueId()); + + if (!gamer.containsKit("Endermage") && gamer.isPlaying()) { + players.add(onlines); + } + } + return players; + } + + private boolean isEnderable(Location portal, Location player) { + return (Math.abs(portal.getX() - player.getX()) < 2.0D) && (Math.abs(portal.getZ() - player.getZ()) < 2.0D) + && (Math.abs(portal.getY() - player.getY()) > 2.0D); + } + + public int calculateDistance(Location a, Location b) { + int distance = 0, x1 = a.getBlockX(), x2 = b.getBlockX(), z1 = a.getBlockZ(), z2 = b.getBlockZ(); + if (x1 != x2) { + if (x1 < x2) { + for (int i = x1; i <= x2 - 1; i++) + distance++; + } else { + for (int i = x2; i <= x1 - 1; i++) + distance++; + } + } + if (z1 != z2) { + if (z1 < z2) { + for (int i = z1; i <= z2 - 1; i++) + distance++; + } else { + for (int i = z2; i <= z1 - 1; i++) + distance++; + } + } + return distance; + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.java new file mode 100644 index 0000000..1add3bf --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.java @@ -0,0 +1,38 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; + +public class Fireman extends Kit { + + public Fireman() { + initialize(getClass().getSimpleName()); + + setItens(new ItemStack(Material.WATER_BUCKET)); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.isCancelled()) + return; + + if (event.getEntity() instanceof Player) { + if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK + || event.getCause() == DamageCause.LAVA) { + if (containsHability((Player) event.getEntity())) { + event.setCancelled(true); + event.getEntity().setFireTicks(0); + } + } + } + } + + @Override + protected void clean(Player player) { + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.java new file mode 100644 index 0000000..eebc840 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.java @@ -0,0 +1,65 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import lombok.val; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerFishEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import org.bukkit.metadata.FixedMetadataValue; + +public class Fisherman extends Kit { + + public Fisherman() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.FISHING_ROD).name(getItemColor() + "Kit " + getName()) + .unbreakable().build()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onDamage(EntityDamageByEntityEvent e) { + if(!(e.getEntity() instanceof Player)) return; + + val damager = e.getDamager(); + + if(damager != null && damager.hasMetadata("fisherman")) { + e.setDamage(0); + + damager.getMetadata("fisherman").stream().findFirst().ifPresent(rawMeta -> { + val player = (Player) rawMeta.value(); + + player.sendMessage(ChatColor.GREEN + "Você fisgou " + e.getEntity().getName()); + }); + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerFishListener(PlayerFishEvent event) { + if(event.getState() == PlayerFishEvent.State.FISHING) { + if(containsHability(event.getPlayer())) event.getHook().setMetadata("fisherman", new FixedMetadataValue(HardcoreGamesMain.getInstance(), event.getPlayer())); + } + + if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY && event.getCaught() instanceof Player) { + final Player player = event.getPlayer(); + if (containsHability(player)) { + Player caughtPlayer = (Player) event.getCaught(); + if (caughtPlayer == player) { + return; + } + caughtPlayer.teleport(player.getLocation()); + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.java new file mode 100644 index 0000000..71df435 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.java @@ -0,0 +1,88 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class Forger extends Kit { + + public Forger() { + initialize(getClass().getSimpleName()); + setUseInvincibility(true); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + ItemStack currentItem = event.getCurrentItem(); + if ((currentItem != null) && (currentItem.getType() != Material.AIR)) { + Player p = (Player) event.getWhoClicked(); + if (containsHability(p)) { + int coalAmount = 0; + Inventory inv = event.getView().getBottomInventory(); + for (ItemStack item : inv.getContents()) + if ((item != null) && (item.getType() == Material.COAL)) + coalAmount += item.getAmount(); + + if (coalAmount == 0) + return; + + int hadCoal = coalAmount; + if (currentItem.getType() == Material.COAL) { + for (int slot = 0; slot < inv.getSize(); slot++) { + ItemStack item = inv.getItem(slot); + if ((item != null) && (item.getType().name().contains("ORE"))) { + while ((item.getAmount() > 0) && (coalAmount > 0) && ((item.getType() == Material.IRON_ORE) + || (item.getType() == Material.GOLD_ORE))) { + item.setAmount(item.getAmount() - 1); + coalAmount--; + if (item.getType() == Material.IRON_ORE) { + p.getInventory().addItem(new ItemStack(Material.IRON_INGOT)); + } else if (item.getType() == Material.GOLD_ORE) { + p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT)); + } + } + if (item.getAmount() == 0) + inv.setItem(slot, new ItemStack(0)); + } + } + } else if (currentItem.getType().name().contains("ORE")) { + while ((currentItem.getAmount() > 0) && (coalAmount > 0) + && ((currentItem.getType() == Material.IRON_ORE) + || (currentItem.getType() == Material.GOLD_ORE))) { + currentItem.setAmount(currentItem.getAmount() - 1); + coalAmount--; + if (currentItem.getType() == Material.IRON_ORE) { + p.getInventory().addItem(new ItemStack(Material.IRON_INGOT)); + } else if (currentItem.getType() == Material.GOLD_ORE) { + p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT)); + } + } + if (currentItem.getAmount() == 0) + event.setCurrentItem(new ItemStack(0)); + } + if (coalAmount != hadCoal) { + for (int slot = 0; slot < inv.getSize(); slot++) { + ItemStack item = inv.getItem(slot); + if ((item != null) && (item.getType() == Material.COAL)) { + while ((coalAmount < hadCoal) && (item.getAmount() > 0)) { + item.setAmount(item.getAmount() - 1); + coalAmount++; + } + if (item.getAmount() == 0) + inv.setItem(slot, new ItemStack(0)); + } + } + } + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.java new file mode 100644 index 0000000..bdb0c08 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.java @@ -0,0 +1,272 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.GameListener; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditAPI; +import com.br.guilhermematthew.nowly.hardcoregames.ability.utility.GladiatorFight; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Gladiator extends Kit { + + public Gladiator() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.IRON_FENCE).name(getItemColor() + "Kit " + getName()).build()); + } + + public static ConcurrentHashMap gladiatorFights = new ConcurrentHashMap<>(); + public static HashMap gladArena = new HashMap<>(); + + @EventHandler + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (inGlad(event.getDamaged())) { + + if (!inGlad(event.getPlayer())) { + event.setCancelled(true); + } else { + if (!getGladArena(event.getDamaged()).equals(getGladArena(event.getPlayer()))) { + event.setCancelled(true); + } + } + } else if (inGlad(event.getPlayer())) { + if (!inGlad(event.getDamaged())) { + event.setCancelled(true); + } else { + if (!getGladArena(event.getDamaged()).equals(getGladArena(event.getPlayer()))) { + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onSecond(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + for (GladiatorFight glads : gladiatorFights.values()) { + if (!glads.isEnded()) { + glads.onSecond(); + } + } + } + + @EventHandler + public void onInteractEntity(PlayerInteractEntityEvent event) { + if (!(event.getRightClicked() instanceof Player)) + return; + + Player player = event.getPlayer(); + + if ((player.getItemInHand().getType().equals(Material.IRON_FENCE)) && (useAbility(player))) { + if (inGlad(player)) { + player.sendMessage("§cVocê já esta em um gladiator."); + return; + } + Player player1 = (Player) event.getRightClicked(); + if (inGlad(player1)) { + player.sendMessage("§cEste jogador já está em um Gladiator."); + return; + } + + Location toGlad = getLocationForGlad(player.getLocation()); + if (toGlad == null) { + player.sendMessage("§cVocê não pode criar sua arena aqui."); + return; + } + + int id = getArenaID(); + if ((gladiatorFights.containsKey("arena" + id)) || (id == 0)) { + player.sendMessage("§cVocê não pode criar sua arena aqui."); + return; + } + + gladiatorFights.put("arena" + id, new GladiatorFight(toGlad.getBlock(), id, player, player1)); + + gladArena.put(player.getUniqueId(), "arena" + id); + gladArena.put(player1.getUniqueId(), "arena" + id); + + // removerBlocos(toGlad); + criarGladiator(toGlad); + + Location l1 = new Location(toGlad.getWorld(), toGlad.getX() + 6.5D, toGlad.getY() + 1.500, + toGlad.getZ() + 6.5D); + l1.setYaw(135.0F); + Location l2 = new Location(toGlad.getWorld(), toGlad.getX() - 5.5D, toGlad.getY() + 1.500, + toGlad.getZ() - 5.5D); + l2.setYaw(315.0F); + + player.setFallDistance(-5); + player1.setFallDistance(-5); + + player.teleport(l1); + player1.teleport(l2); + + l1 = null; + l2 = null; + } + } + + private int getArenaID() { + int id = 0; + + try { + id = CommonsConst.RANDOM.nextInt(2000) + 3; + } catch (Exception ex) { + id = 0; + } + + return id; + } + + public static String getGladArena(Player player) { + return gladArena.getOrDefault(player.getUniqueId(), "0"); + } + + public static boolean inGlad(Player player) { + return gladArena.containsKey(player.getUniqueId()); + } + + public static GladiatorFight getGladiatorFight(Player player) { + return gladiatorFights.get(getGladArena(player)); + } + + @EventHandler + public void onBreak(BlockBreakEvent event) { + if (event.getBlock().getType() == Material.GLASS) { + if (gladArena.containsKey(event.getPlayer().getUniqueId())) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent e) { + if ((e.getBlock().getType().equals(Material.IRON_FENCE)) && (containsHability(e.getPlayer()))) { + e.setCancelled(true); + } + } + + public static Location getLocationForGlad(Location loc) { + loc.setY(110); + + boolean hasGladi = true; + while (hasGladi) { + + hasGladi = false; + boolean stop = false; + + for (double x = -8.0D; x <= 8.0D; x += 1.0D) { + for (double z = -8.0D; z <= 8.0D; z += 1.0D) { + for (double y = 0.0D; y <= 10.0D; y += 1.0D) { + Location location = new Location(loc.getWorld(), loc.getX() + x, 110.0D + y, loc.getZ() + z); + + if (location.getBlock().getType() != Material.AIR) { + hasGladi = true; + loc = new Location(loc.getWorld(), loc.getX() + 30.0D, 110.0D, loc.getZ()); + stop = true; + } + if (stop) + break; + } + if (stop) + break; + } + if (stop) + break; + } + } + return loc; + } + + public static void criarGladiator(Location loc) { + List cuboid = new ArrayList<>(); + + for (int bX = -8; bX <= 8; bX++) { + for (int bZ = -8; bZ <= 8; bZ++) { + for (int bY = -1; bY <= 10; bY++) { + if (bY == -1) { + cuboid.add(loc.clone().add(bX, bY, bZ)); + } else if ((bX == -8) || (bZ == -8) || (bX == 8) || (bZ == 8)) { + cuboid.add(loc.clone().add(bX, bY, bZ)); + } + } + } + } + + for (Location loc1 : cuboid) { + WorldEditAPI.setAsyncBlock(loc1.getWorld(), loc1, 20); + } + + cuboid.clear(); + cuboid = null; + } + + public static void removerBlocos(Location loc) { + List cuboid = new ArrayList<>(); + + for (int bX = -8; bX <= 8; bX++) { + for (int bZ = -8; bZ <= 8; bZ++) { + for (int bY = -1; bY <= 10; bY++) { + cuboid.add(loc.clone().add(bX, bY, bZ)); + } + } + } + + for (Location loc1 : cuboid) { + WorldEditAPI.setAsyncBlock(loc1.getWorld(), loc1, 0); + } + + cuboid.clear(); + cuboid = null; + } + + public static boolean isQuitedOnGladiator(Player player) { + if (inGlad(player)) { + GladiatorFight glad = getGladiatorFight(player); + + glad.teleportBack(); + + Player winner = null; + + if (glad.getPlayers()[0].getUniqueId().equals(player.getUniqueId())) { + winner = glad.getPlayers()[1]; + } else { + winner = glad.getPlayers()[0]; + } + + PlayerAPI.dropItems(player, glad.getBackForPlayer(player).add(0, 0.5, 0)); + + glad.cancelGlad(); + + GameListener.handleStats(winner, player); + + glad = null; + return true; + } + return false; + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.java new file mode 100644 index 0000000..2cd7aae --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.java @@ -0,0 +1,22 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Grandpa extends Kit { + + public Grandpa() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.STICK).name(getItemColor() + "Kit " + getName()) + .enchantment(Enchantment.KNOCKBACK, 3).build()); + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.java new file mode 100644 index 0000000..58459ab --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.java @@ -0,0 +1,270 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.Map; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowball; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Firework; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PlayerLeashEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +import net.minecraft.server.v1_8_R3.EntityFishingHook; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntitySnowball; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; + +public class Grappler extends Kit { + + public Grappler() { + initialize(getClass().getSimpleName()); + setUseInvincibility(true); + + setItens(new ItemBuilder().material(Material.LEASH).name(getItemColor() + "Kit " + getName()).build()); + } + + private Map hooks = new HashMap<>(); + private HashMap leftClickGrappler = new HashMap(); + private HashMap rightClickGrappler = new HashMap(); + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if (hooks.containsKey(event.getPlayer())) { + ((Cordinha) hooks.get(event.getPlayer())).remove(); + hooks.remove(event.getPlayer()); + } + } + + @EventHandler + public void onFall(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + + if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { + Player player = (Player) event.getEntity(); + + if ((hooks.containsKey(player)) && (((Cordinha) hooks.get(player)).isHooked()) + && (event.getDamage() > 5.0D)) { + event.setCancelled(true); + } + + player = null; + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) + return; + + if ((hooks.containsKey(event.getPlayer())) + && (!event.getPlayer().getItemInHand().getType().equals(Material.LEASH))) { + ((Cordinha) hooks.get(event.getPlayer())).remove(); + hooks.remove(event.getPlayer()); + } + } + + @EventHandler + public void onLeash(PlayerLeashEntityEvent e) { + if (containsHability(e.getPlayer())) { + e.setCancelled(true); + e.getPlayer().updateInventory(); + } + } + + @EventHandler + public void usar(PlayerInteractEvent e) { + Player p = e.getPlayer(); + + if ((p.getItemInHand().getType().equals(Material.LEASH)) && (containsHability(p))) { + + e.setCancelled(true); + if (hasCooldown(p, "CombatLog")) { + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 5), true); + p.sendMessage("§cVocê levou um hit recentemente, aguarde para usar a habilidade novamente."); + return; + } + + if ((e.getAction() == Action.LEFT_CLICK_AIR) || (e.getAction() == Action.LEFT_CLICK_BLOCK)) { + if (leftClickGrappler.containsKey(p) && leftClickGrappler.get(p) > System.currentTimeMillis()) + return; + + if (hooks.containsKey(p)) + ((Cordinha) hooks.get(p)).remove(); + + Cordinha nmsHook = new Cordinha(p.getWorld(), ((CraftPlayer) p).getHandle()); + nmsHook.spawn(p.getEyeLocation().add(p.getLocation().getDirection().getX(), + p.getLocation().getDirection().getY(), p.getLocation().getDirection().getZ())); + + nmsHook.move(p.getLocation().getDirection().getX() * 2.5D, p.getLocation().getDirection().getY() * 2.5D, + p.getLocation().getDirection().getZ() * 2.5D); + + hooks.put(p, nmsHook); + leftClickGrappler.put(p, System.currentTimeMillis() + 250L); + } else { + if (!hooks.containsKey(p)) + return; + + if (rightClickGrappler.containsKey(p) && rightClickGrappler.get(p) > System.currentTimeMillis()) + return; + + if (!((Cordinha) hooks.get(p)).isHooked()) + return; + + // DamageListener.addBypassVelocity(p); + rightClickGrappler.put(p, System.currentTimeMillis() + 150L); + double d = ((Cordinha) hooks.get(p)).getBukkitEntity().getLocation().distance(p.getLocation()); + double t = d; + double v_x = (1.0D + 0.07000000000000001D * t) + * (((Cordinha) hooks.get(p)).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) + / t; + double v_y = (1.0D + 0.03D * t) + * (((Cordinha) hooks.get(p)).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) + / t; + double v_z = (1.0D + 0.07000000000000001D * t) + * (((Cordinha) hooks.get(p)).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) + / t; + Vector v = p.getVelocity(); + v.setX(v_x); + v.setY(v_y); + v.setZ(v_z); + p.setVelocity(v); + p.playSound(p.getLocation(), Sound.STEP_GRAVEL, 10.0F, 10.0F); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (containsHability(event.getDamaged())) { + addCooldown(event.getDamaged(), "CombatLog", 3); + } + } + + public class Cordinha extends EntityFishingHook { + + private Snowball sb; + private EntitySnowball controller; + public EntityHuman owner; + public Entity hooked; + public boolean lastControllerDead, isHooked; + + public Cordinha(org.bukkit.World world, EntityHuman entityhuman) { + super(((CraftWorld) world).getHandle(), entityhuman); + this.owner = entityhuman; + } + + protected void c() { + } + + public void t_() { + + if ((!this.lastControllerDead) && (this.controller.dead)) + ((Player) this.owner.getBukkitEntity()).sendMessage("§aSua corda prendeu em algo."); + + this.lastControllerDead = this.controller.dead; + for (Entity entity : this.controller.world.getWorld().getEntities()) { + if (!(entity instanceof LivingEntity)) { + continue; + } + if ((!(entity instanceof Firework)) && (entity.getEntityId() != getBukkitEntity().getEntityId()) + && (entity.getEntityId() != this.owner.getBukkitEntity().getEntityId()) + && (entity.getEntityId() != this.controller.getBukkitEntity().getEntityId()) + && ((entity.getLocation().distance(this.controller.getBukkitEntity().getLocation()) < 2.0D) + || (((entity instanceof Player)) && (((Player) entity).getEyeLocation() + .distance(this.controller.getBukkitEntity().getLocation()) < 2.0D)))) { + this.controller.die(); + this.hooked = entity; + this.isHooked = true; + this.locX = entity.getLocation().getX(); + this.locY = entity.getLocation().getY(); + this.locZ = entity.getLocation().getZ(); + this.motX = 0.0D; + this.motY = 0.04D; + this.motZ = 0.0D; + } + } + try { + this.locX = this.hooked.getLocation().getX(); + this.locY = this.hooked.getLocation().getY(); + this.locZ = this.hooked.getLocation().getZ(); + this.motX = 0.0D; + this.motY = 0.04D; + this.motZ = 0.0D; + this.isHooked = true; + } catch (Exception e) { + if (this.controller.dead) + this.isHooked = true; + this.locX = this.controller.locX; + this.locY = this.controller.locY; + this.locZ = this.controller.locZ; + } + } + + public void die() { + } + + public void remove() { + super.die(); + } + + public void spawn(Location location) { + this.sb = ((Snowball) this.owner.getBukkitEntity().launchProjectile(Snowball.class)); + this.sb.setVelocity(this.sb.getVelocity().multiply(2.25D)); + this.controller = ((CraftSnowball) this.sb).getHandle(); + + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { this.controller.getId() }); + + for (Player p : Bukkit.getOnlinePlayers()) + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + + ((CraftWorld) location.getWorld()).getHandle().addEntity(this); + } + + public boolean isHooked() { + return this.isHooked; + } + + public void setHookedEntity(Entity damaged) { + this.hooked = damaged; + } + } + + @Override + protected void clean(Player player) { + if (hooks.containsKey(player)) { + ((Cordinha) hooks.get(player)).remove(); + hooks.remove(player); + } + + if (leftClickGrappler.containsKey(player)) { + leftClickGrappler.remove(player); + } + + if (rightClickGrappler.containsKey(player)) { + rightClickGrappler.remove(player); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.java new file mode 100644 index 0000000..62fa11c --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.java @@ -0,0 +1,63 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Hulk extends Kit { + + public Hulk() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent e) { + if (e.getPlayer() instanceof Player && e.getRightClicked() instanceof Player) { + Player p = (Player) e.getPlayer(); + + if (containsHability(p)) { + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + addCooldown(p, getCooldownSeconds()); + + Player d = (Player) e.getRightClicked(); + p.setPassenger(d); + } + } + } + + @EventHandler + public void onDeath(EntityDeathEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + if (p.isInsideVehicle()) { + p.leaveVehicle(); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(PlayerDamagePlayerEvent event) { + Player damaged = event.getDamaged(), damager = event.getPlayer(); + + if ((damaged.isInsideVehicle()) && (containsHability(damager))) { + event.setCancelled(true); + + damaged.leaveVehicle(); + + damaged.setVelocity(new Vector(damager.getLocation().getDirection().getX() + 0.3, 1.5, + damager.getLocation().getDirection().getZ() + 0.3)); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.java new file mode 100644 index 0000000..f5ccc50 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.java @@ -0,0 +1,48 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; + +public class Ironman extends Kit { + + public Ironman() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + final Player morreu = event.getEntity(), killer = morreu.getKiller(); + + if (killer == null) { + return; + } + + if (!(killer instanceof Player)) { + return; + } + + if (containsHability(killer)) { + if (Math.random() <= 0.45) { + + if (PlayerAPI.isFull(killer.getInventory())) { + killer.getWorld().dropItem(killer.getLocation(), new ItemStack(Material.IRON_INGOT)); + } else { + killer.getInventory().addItem(new ItemStack(Material.IRON_INGOT)); + } + } + } + } + + @Override + protected void clean(Player player) { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.java new file mode 100644 index 0000000..4ec13f2 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.java @@ -0,0 +1,80 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class JackHammer extends Kit { + + public JackHammer() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.STONE_AXE).name(getItemColor() + "Kit " + getName()).build()); + } + + private HashMap blocos = new HashMap<>(); + + @EventHandler(priority = EventPriority.HIGHEST) + public void onBreak(BlockBreakEvent e) { + if (e.isCancelled()) { + return; + } + + if ((e.getPlayer().getItemInHand().getType().equals(Material.STONE_AXE)) && (containsHability(e.getPlayer()))) { + if (hasCooldown(e.getPlayer())) { + sendMessageCooldown(e.getPlayer()); + return; + } + blocos.put(e.getPlayer().getUniqueId(), + blocos.containsKey(e.getPlayer().getUniqueId()) ? blocos.get(e.getPlayer().getUniqueId()) + 1 : 1); + if (blocos.get(e.getPlayer().getUniqueId()).equals(4)) { + addCooldown(e.getPlayer(), getCooldownSeconds()); + blocos.remove(e.getPlayer().getUniqueId()); + return; + } + if (e.getBlock().getRelative(BlockFace.UP).getType() != Material.AIR) { + quebrar(e.getBlock(), BlockFace.UP); + } else { + quebrar(e.getBlock(), BlockFace.DOWN); + } + } + } + + void quebrar(final Block b, final BlockFace face) { + new BukkitRunnable() { + Block block = b; + + @SuppressWarnings("deprecation") + public void run() { + if (block.getType() != Material.BEDROCK && block.getType() != Material.ENDER_PORTAL_FRAME + && block.getY() <= 128) { + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType().getId(), 30); + block.setType(Material.AIR); + block = block.getRelative(face); + } else { + cancel(); + } + } + }.runTaskTimer(HardcoreGamesMain.getInstance(), 2L, 2L); + } + + @Override + protected void clean(Player player) { + if (blocos.containsKey(player.getUniqueId())) { + blocos.remove(player.getUniqueId()); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.java new file mode 100644 index 0000000..74e8cef --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.java @@ -0,0 +1,109 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashSet; +import java.util.Set; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Kangaroo extends Kit { + + private Set doubleJump; + + public Kangaroo() { + initialize(getClass().getSimpleName()); + setUseInvincibility(true); + + setItens(new ItemBuilder().material(Material.FIREWORK).name(getItemColor() + "Kit " + getName()).build()); + + this.doubleJump = new HashSet<>(); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if ((!event.getAction().equals(Action.PHYSICAL)) + && (event.getPlayer().getItemInHand().getType().equals(Material.FIREWORK)) + && (containsHability(event.getPlayer()))) { + + event.setCancelled(true); + Player p = event.getPlayer(); + + if (hasCooldown(p, "CombatLog")) { + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 5), true); + p.sendMessage("§cVocê levou um hit recentemente, aguarde para usar a habilidade novamente."); + return; + } + + if (!doubleJump.contains(p)) { + org.bukkit.util.Vector velocity = p.getEyeLocation().getDirection(); + if (p.isSneaking()) { + velocity = velocity.multiply(2.45F).setY(0.5F); + } else { + velocity = velocity.multiply(0.5F).setY(1.0F); + } + p.setFallDistance(-1.0F); + p.setVelocity(velocity); + doubleJump.add(p); + velocity = null; + } + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void removeOnMove(PlayerMoveEvent e) { + if (!LocationUtil.isRealMovement(e.getFrom(), e.getTo())) + return; + + if (!doubleJump.contains(e.getPlayer())) + return; + if (!e.getPlayer().isOnGround()) + return; + doubleJump.remove(e.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamageEvent(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + final Player player = (Player) event.getEntity(); + if (event.getCause() == EntityDamageEvent.DamageCause.FALL && containsHability(player)) { + final double damage = event.getDamage(); + if (damage > 7.0D) { + event.setDamage(4.0D); + } else { + event.setCancelled(true); + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (containsHability(event.getDamaged())) { + addCooldown(event.getDamaged(), "CombatLog", 3); + } + } + + @Override + protected void clean(Player player) { + if (doubleJump.contains(player)) { + doubleJump.remove(player); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.java new file mode 100644 index 0000000..6bd1364 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.java @@ -0,0 +1,95 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Launcher extends Kit { + + public Launcher() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.SPONGE).name(getItemColor() + "Kit" + getName()).amount(20) + .build()); + } + + private final String NOFALL_TAG = "nofall", NOFALL_TAG_TIME = "nofall.time"; + + @EventHandler(priority = EventPriority.MONITOR) + public void onRealMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) + return; + + if (event.isCancelled()) + return; + + Material material = event.getTo().getBlock().getRelative(BlockFace.DOWN).getType(); + + if (material.equals(Material.SPONGE)) { + Player player = event.getPlayer(); + + Location loc = event.getTo().getBlock().getLocation(); + + // DamageListener.addBypassVelocity(player); + Vector sponge = player.getLocation().getDirection().multiply(0).setY(3); + player.setVelocity(sponge); + + player.setMetadata(NOFALL_TAG, new FixedMetadataValue(HardcoreGamesMain.getInstance(), true)); + player.setMetadata(NOFALL_TAG_TIME, + new FixedMetadataValue(HardcoreGamesMain.getInstance(), System.currentTimeMillis())); + + player.playSound(loc, Sound.FIREWORK_LAUNCH, 6.0F, 1.0F); + } + + material = null; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDamage(EntityDamageEvent event) { + if (event.getCause() != DamageCause.FALL) + return; + if (!(event.getEntity() instanceof Player)) + return; + + Player p = (Player) event.getEntity(); + + if (p.hasMetadata(NOFALL_TAG)) { + p.removeMetadata(NOFALL_TAG, HardcoreGamesMain.getInstance()); + + if (!p.hasMetadata(NOFALL_TAG_TIME)) { + event.setCancelled(true); + return; + } + if (GamerManager.getGamer(p.getUniqueId()).containsKit("Stomper")) { + p.removeMetadata(NOFALL_TAG_TIME, HardcoreGamesMain.getInstance()); + return; + } + + Long time = p.getMetadata(NOFALL_TAG_TIME).get(0).asLong(); + if (time + 6200 > System.currentTimeMillis()) { + event.setCancelled(true); + } + + p.removeMetadata(NOFALL_TAG_TIME, HardcoreGamesMain.getInstance()); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.java new file mode 100644 index 0000000..220f526 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.java @@ -0,0 +1,47 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class LumberJack extends Kit { + + public LumberJack() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.WOOD_AXE).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onBreak(BlockBreakEvent event) { + if (event.isCancelled() || HardcoreGamesMain.getGameManager().isInvencibilidade()) + return; + + if ((event.getPlayer().getItemInHand().getType().equals(Material.WOOD_AXE)) + && (containsHability(event.getPlayer()))) { + + Block b = event.getBlock().getRelative(BlockFace.UP), b1 = event.getBlock().getRelative(BlockFace.DOWN); + + while (b.getType().name().contains("LOG")) { + b.breakNaturally(); + b = b.getRelative(BlockFace.UP); + } + while (b1.getType().name().contains("LOG")) { + b1.breakNaturally(); + b1 = b1.getRelative(BlockFace.DOWN); + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.java new file mode 100644 index 0000000..57821b5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.java @@ -0,0 +1,133 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.bossbar.BossBarAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerRegisterKitEvent; + +public class Madman extends Kit { + + public Madman() { + initialize(getClass().getSimpleName()); + + setCallEventRegisterPlayer(true); + } + + private final ConcurrentHashMap efeitoMadman = new ConcurrentHashMap<>(); + private final ArrayList madmans = new ArrayList<>(); + + @EventHandler(priority = EventPriority.MONITOR) + public void onSecond(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) + return; + + if (madmans.size() > 0) { + + for (UUID uuidMadmans : madmans) { + Player madman = Bukkit.getPlayer(uuidMadmans); + + if (madman != null) { + List lista = getNearbyPlayers(madman, 15); + + if (lista.size() > 1) { + for (Player perto : lista) { + int efeito = lista.size() * 2; + addEffect(perto, efeito); + } + } + + lista.clear(); + lista = null; + + madman = null; + } + } + } + + if (efeitoMadman.size() > 0) { + for (UUID uuidInfectados : efeitoMadman.keySet()) { + removeEffect(uuidInfectados); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (efeitoMadman.containsKey(event.getDamaged().getUniqueId())) { + double dano = event.getDamage(); + event.setDamage(dano + ((dano / 100.0D) * efeitoMadman.get(event.getDamaged().getUniqueId()))); + } + } + + @EventHandler + public void onRegister(PlayerRegisterKitEvent event) { + if (event.getKitName().equalsIgnoreCase(getName())) { + if (!madmans.contains(event.getPlayer().getUniqueId())) { + madmans.add(event.getPlayer().getUniqueId()); + } + } + } + + private void removeEffect(UUID u) { + int effect = efeitoMadman.get(u); + effect = effect - 10; + efeitoMadman.put(u, effect); + if (effect <= 0) { + efeitoMadman.remove(u); + } + } + + private void addEffect(final Player player, int efeito) { + int effect = (efeitoMadman.containsKey(player.getUniqueId()) ? efeitoMadman.get(player.getUniqueId()) : 0); + + if (effect == 0) { + player.sendMessage("§cTem um §lMADMAN §cpor perto!"); + } + + effect = effect + (efeito + 10); + + BossBarAPI.send(player, "EFEITO DO MADMAN " + effect + "%", 5); + + efeitoMadman.put(player.getUniqueId(), effect); + } + + private List getNearbyPlayers(Player p, int i) { + List players = new ArrayList(); + List entities = p.getPlayer().getNearbyEntities(i, i, i); + + for (Entity e : entities) { + if (!(e instanceof Player)) { + continue; + } + if (!GamerManager.getGamer(((Player) e).getUniqueId()).isPlaying()) { + continue; + } + players.add((Player) e); + } + + entities.clear(); + entities = null; + return players; + } + + @Override + protected void clean(Player player) { + if (efeitoMadman.containsKey(player.getUniqueId())) { + efeitoMadman.remove(player.getUniqueId()); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.java new file mode 100644 index 0000000..7a478e2 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.java @@ -0,0 +1,74 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Magma extends Kit { + + public Magma() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + if (event.isCancelled()) + return; + + if (event.getTo().getBlock().getType().equals(Material.WATER) + || event.getTo().getBlock().getType().equals(Material.STATIONARY_WATER)) { + + if (containsHability(event.getPlayer())) { + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0), true); + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0), true); + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0), true); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getPlayer()) && Math.random() <= 0.35) { + event.getDamaged().setFireTicks(140); + event.getDamaged().getLocation().getWorld().playEffect( + event.getDamaged().getLocation().add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.isCancelled()) + return; + + if (event.getEntity() instanceof Player) { + if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK + || event.getCause() == DamageCause.LAVA) { + if (containsHability((Player) event.getEntity())) { + event.setCancelled(true); + event.getEntity().setFireTicks(0); + + ((Player) event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 0), + true); + ((Player) event.getEntity()) + .addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 0), true); + } + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.java new file mode 100644 index 0000000..93d85fb --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.java @@ -0,0 +1,102 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.ExperienceOrb; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Miner extends Kit { + + public Miner() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.STONE_PICKAXE).unbreakable() + .name(getItemColor() + "Kit " + getName()).enchantment(Enchantment.DIG_SPEED) + .enchantment(Enchantment.DURABILITY, 5).build(), + new ItemBuilder().material(Material.APPLE).amount(2).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBreak(BlockBreakEvent event) { + ItemStack hand = event.getPlayer().getInventory().getItemInHand(); + + if (containsHability(event.getPlayer()) && hand != null && hand.getType().name().contains("PICKAXE")) { + Location spawn = event.getBlock().getLocation().clone().add(0.5, 0.5, 0.5); + Material mat = event.getBlock().getType(); + if (!mat.name().contains("ORE")) { + return; + } + + event.setCancelled(true); + + Map drops = new HashMap<>(); + for (Block b : getNearbyBlocks(event.getBlock(), 1)) { + if (b.getType() == mat + || mat == Material.REDSTONE_ORE && b.getType() == Material.GLOWING_REDSTONE_ORE) { + b.getDrops().forEach(drop -> { + drops.put(drop.getType(), drops.getOrDefault(drop.getType(), 0) + drop.getAmount()); + }); + b.setType(Material.AIR); + } + } + + int xp = drops.entrySet().stream().filter($ -> !$.getKey().name().endsWith("_ORE")) + .mapToInt($ -> $.getValue() * 2).sum(); + drops.forEach((material, q) -> { + int i = q; + while (i > 0) { + spawn.getWorld().dropItem(spawn, new ItemStack(material, i)); + i -= Math.min(i, 64); + } + }); + + if (xp > 0) { + ExperienceOrb orb = event.getBlock().getWorld().spawn(spawn, ExperienceOrb.class); + orb.setExperience(xp); + } + } + } + + private List getNearbyBlocks(Block block, int i) { + List blocos = new ArrayList(); + for (int x = -i; x <= i; x++) { + for (int y = -i; y <= i; y++) { + for (int z = -i; z <= i; z++) { + blocos.add(block.getLocation().clone().add(x, y, z).getBlock()); + } + } + } + return blocos; + } + + @EventHandler + public void onEat(PlayerItemConsumeEvent event) { + if (!containsHability(event.getPlayer())) + return; + + if (event.getItem().getType() == Material.APPLE) { + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 600, 1)); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.java new file mode 100644 index 0000000..8fd83ff --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Monk extends Kit { + + public Monk() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.BLAZE_ROD).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent e) { + if (e.getRightClicked() instanceof Player) { + Player p = e.getPlayer(); + if ((p.getItemInHand().getType().equals(Material.BLAZE_ROD)) && (useAbility(p))) { + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + Player d = (Player) e.getRightClicked(); + final ItemStack item = d.getItemInHand(); + final int r = CommonsConst.RANDOM.nextInt(35); + final ItemStack i = d.getInventory().getItem(r); + d.getInventory().setItem(r, item); + d.setItemInHand(i); + addCooldown(p, getCooldownSeconds()); + p.sendMessage("§aMonkado!"); + d.sendMessage("§aVocê foi monkado!"); + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.java new file mode 100644 index 0000000..e6faa53 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class Neo extends Kit { + + public Neo() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onProjectDamage(EntityDamageByEntityEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + Player p = (Player) event.getEntity(); + if (!containsHability(p)) + return; + if (event.getDamager() instanceof Projectile) { + event.setCancelled(true); + Projectile projectile = (Projectile) event.getDamager(); + if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { + Player projectator = (Player) projectile.getShooter(); + projectator.sendMessage("§cO jogador está utilizando o kit Neo!"); + } + } + } + + @Override + protected void clean(Player player) { + } + +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.java new file mode 100644 index 0000000..94f0fd6 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.java @@ -0,0 +1,106 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.HashMap; +import java.util.Map; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +import lombok.Getter; + +public class Ninja extends Kit { + + private Map ninja; + + public Ninja() { + initialize(getClass().getSimpleName()); + + this.ninja = new HashMap<>(); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamagePlayerEvent(PlayerDamagePlayerEvent event) { + if (containsHability(event.getPlayer())) { + + NinjaHit ninjaHit = ninja.get(event.getPlayer()); + if (ninjaHit == null) { + ninjaHit = new NinjaHit(event.getDamaged()); + ninja.put(event.getPlayer(), ninjaHit); + } else { + ninjaHit.setTarget(event.getDamaged()); + } + } + } + + @EventHandler + public void onPlayerToggleSneakEvent(PlayerToggleSneakEvent event) { + final Player player = event.getPlayer(); + + if (event.isSneaking() && this.ninja.containsKey(player) && containsHability(player)) { + + NinjaHit hit = this.ninja.get(player); + if (hit == null) + return; + + if (hit.getTargetExpires() < System.currentTimeMillis()) + return; + + Player target = hit.getTarget(); + if (target.isOnline()) { + if (player.getLocation().distance(target.getLocation()) > 40) { + player.sendMessage("§cJogador muito longe!"); + return; + } + // Check gladiator + + if (!hasCooldown(player)) { + player.teleport(target.getLocation()); + + addCooldown(player, getCooldownSeconds()); + + player.getWorld().playSound(player.getLocation().add(0.0, 0.5, 0.0), Sound.ENDERMAN_TELEPORT, 0.3F, + 1.0F); + } + } + } + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) { + clean(event.getEntity()); + + if (event.getEntity().getKiller() != null) { + clean(event.getEntity().getKiller()); + } + } + + protected void clean(Player player) { + if (this.ninja.containsKey(player)) { + this.ninja.remove(player); + } + } + + @Getter + private static class NinjaHit { + + private Player target; + private long targetExpires; + + public NinjaHit(Player target) { + this.target = target; + this.targetExpires = System.currentTimeMillis() + 15000; + } + + public void setTarget(Player player) { + this.target = player; + this.targetExpires = System.currentTimeMillis() + 15000; + } + + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.java new file mode 100644 index 0000000..69d3b5b --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class Noob extends Kit { + + public Noob() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.STONE_AXE).name("§bMachado Noob").build()); + setItens(new ItemBuilder().material(Material.STONE_PICKAXE).name("§bPicareta Noob").build()); + setItens(new ItemBuilder().material(Material.STONE_HOE).name("§bFoice Noob").build()); + setItens(new ItemBuilder().material(Material.STONE_SWORD).name("§bEspada Noob").build()); + setItens(new ItemBuilder().material(Material.MUSHROOM_SOUP).amount(24).build()); + } + + @Override + protected void clean(Player player) { + } + +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.java new file mode 100644 index 0000000..10f3334 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.java @@ -0,0 +1,62 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Phantom extends Kit { + + public Phantom() { + initialize(getClass().getSimpleName()); + setUseInvincibility(true); + + setItens(new ItemBuilder().material(Material.FEATHER).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + if ((player.getItemInHand().getType().equals(Material.FEATHER)) && (useAbility(player))) { + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (hasCooldown(player)) { + sendMessageCooldown(player); + return; + } + addCooldown(player, getCooldownSeconds()); + player.setAllowFlight(true); + player.setFlying(true); + player.getWorld().playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 2.0F, 1.0F); + + for (Entity c : player.getNearbyEntities(30, 30, 30)) { + if (c instanceof Player && c != player) { + Player d = (Player) c; + d.sendMessage("§4Há um phantom por perto!"); + } + } + + HardcoreGamesMain.runLater(() -> { + if (!player.isOnline()) { + return; + } + player.setFallDistance(-10); + player.playSound(player.getLocation(), Sound.AMBIENCE_RAIN, 3.0F, 4.0F); + player.setAllowFlight(false); + player.setFlying(false); + }, 142L); + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.java new file mode 100644 index 0000000..0ba1119 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.java @@ -0,0 +1,50 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Poseidon extends Kit { + + public Poseidon() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) + return; + + if (event.isCancelled()) + return; + + if (event.getTo().getBlock().getType().equals(Material.WATER) + || event.getTo().getBlock().getType().equals(Material.STATIONARY_WATER)) { + + if (containsHability(event.getPlayer())) { + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 0), true); + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 0), true); + event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 0), true); + } + } + } + + @EventHandler + public void onDamage(EntityDamageEvent e) { + if (e.getEntity() instanceof Player && containsHability((Player) e.getEntity()) + && e.getCause() == DamageCause.DROWNING) { + e.setCancelled(true); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.java new file mode 100644 index 0000000..4ce0a31 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.java @@ -0,0 +1,45 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Fireball; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Pyro extends Kit { + + public Pyro() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().name(getItemColor() + "Kit " + getName()).material(Material.FIREBALL) + .build(), new ItemStack(Material.FLINT_AND_STEEL)); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + ItemStack item = event.getItem(); + Player player = event.getPlayer(); + + if (event.getAction() == Action.RIGHT_CLICK_AIR && item != null && item.getType() == Material.FIREBALL + && containsHability(player)) { + + event.setCancelled(true); + + if(!hasCooldown(player)) addCooldown(player, "Pyro", 5); + else return; + + Fireball fireball = player.launchProjectile(Fireball.class); + fireball.setIsIncendiary(true); + fireball.setYield(fireball.getYield() * 1.5F); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.java new file mode 100644 index 0000000..9ed75e7 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.java @@ -0,0 +1,45 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Scout extends Kit { + + public Scout() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.getMaterial(373)).durability(34).name( + getItemColor() + "Kit " + getName()).build()); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.PHYSICAL) return; + Player player = event.getPlayer(); + if ((player.getItemInHand().getType().equals(Material.getMaterial(373))) && + (containsHability(player))) { + + if (hasCooldown(player)) { + sendMessageCooldown(player); + return; + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 30, 2)); + player.sendMessage("§aVocê recebeu velocidade por um tempo valido de 30 segundos!"); + addCooldown(player, getCooldownSeconds()); + } + } + + @Override + protected void clean(Player player) { + + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.java new file mode 100644 index 0000000..a6b9ec6 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.java @@ -0,0 +1,31 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Snail extends Kit { + + public Snail() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getPlayer()) && Math.random() <= 0.33) { + + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 120, 1)); + event.getDamaged().getLocation().getWorld().playEffect( + event.getDamaged().getLocation().add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.java new file mode 100644 index 0000000..e1bda41 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.java @@ -0,0 +1,76 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.PlayerDeathEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class Specialist extends Kit { + + private final ItemStack item; + + public Specialist() { + initialize(getClass().getSimpleName()); + + item = new ItemBuilder().material(Material.ENCHANTMENT_TABLE).name(getItemColor() + "Kit " + getName()) + .build(); + + setItens(item); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + final Player morreu = event.getEntity(), killer = morreu.getKiller(); + + if (killer == null) { + return; + } + + if (containsHability(killer)) killer.setLevel(killer.getLevel() + 1); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onInteract(PlayerInteractEvent e) { + if(e.getAction() == Action.PHYSICAL) return; + + val player = e.getPlayer(); + + if(!containsHability(player)) return; + if(!item.equals(e.getItem())) return; + + e.setCancelled(true); + player.openEnchanting(null, true); + } + + /*@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onBreak(BlockBreakEvent event) { + if (event.getBlock().getType() == Material.ENCHANTMENT_TABLE) { + if (containsHability(event.getPlayer())) { + + if (!PlayerAPI.isFull(event.getPlayer().getInventory())) { + event.getBlock().setType(Material.AIR); + event.getPlayer().getInventory().addItem(new ItemBuilder().material(Material.ENCHANTMENT_TABLE).name(getItemColor() + "Kit " + getName()).build()); + } + + } + } + }*/ + + @Override + protected void clean(Player player) { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.java new file mode 100644 index 0000000..be0c9ca --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.java @@ -0,0 +1,81 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import java.util.List; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.GameMode; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; + +public class Stomper extends Kit { + + private final double STOMPER_FALL_NERF = 3.5D; + + public Stomper() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onFall(EntityDamageEvent event) { + if (event.isCancelled()) + return; + + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + + if ((event.getCause() == EntityDamageEvent.DamageCause.FALL) && (containsHability(p))) { + + if (event.getDamage() <= 4.0) { + return; + } + + List entity = p.getNearbyEntities(6.0D, 3.0D, 6.0D); + boolean stomped = false; + + for (Entity en : entity) { + if (en instanceof Player) { + Player stompados = (Player) en; + + if ((!GamerManager.getGamer(stompados.getUniqueId()).isPlaying()) + || (!stompados.getGameMode().equals(GameMode.SURVIVAL))) { + continue; + } + + stomped = true; + + double damage = 4.0D, life = stompados.getHealth(); + + if (!stompados.isSneaking()) { + damage = p.getFallDistance() - STOMPER_FALL_NERF; + } + + stompados.playSound(stompados.getLocation(), Sound.ANVIL_BREAK, 1.0F, 1.0F); + + if (life - damage <= 0.0D) { + stompados.setHealth(1.0D); + stompados.damage(4.0, p); + } else { + stompados.setHealth(life - damage); + } + } + } + + if (stomped) { + p.playSound(p.getLocation(), Sound.ANVIL_BREAK, 1.0F, 1.0F); + } + + if (event.getDamage() > 4.0D) { + event.setDamage(4.0D); + } + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.java new file mode 100644 index 0000000..bae6415 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.java @@ -0,0 +1,15 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; + +public class Surprise extends Kit { + + public Surprise() { + initialize(getClass().getSimpleName()); + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.java new file mode 100644 index 0000000..efb25f8 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.java @@ -0,0 +1,67 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.metadata.FixedMetadataValue; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Switcher extends Kit { + + public Switcher() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.SNOW_BALL).name(getItemColor() + "Kit " + getName()).amount(16) + .build()); + } + + @EventHandler + public void onProjectileLaunch(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Player player = event.getPlayer(); + if (containsHability(player) && checkItem(player.getItemInHand(), getItemColor() + "Kit " + getName())) { + event.setCancelled(true); + player.updateInventory(); + + if (hasCooldown(player)) + return; + + Snowball ball = (Snowball) player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.SNOWBALL); + ball.setShooter(player); + ball.setVelocity(player.getLocation().getDirection().multiply(1.5)); + + ball.setMetadata("switch", new FixedMetadataValue(HardcoreGamesMain.getInstance(), player)); + ball.setVelocity(player.getVelocity().multiply(1.5D)); + addCooldown(player, 5); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof Player && event.getDamager().hasMetadata("switch")) { + Player player = (Player) event.getDamager().getMetadata("switch").get(0).value(); + + if (player == null) + return; + + Location loc = event.getEntity().getLocation().clone(); + event.getEntity().teleport(player.getLocation().clone()); + player.teleport(loc); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.java new file mode 100644 index 0000000..3202e7a --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.java @@ -0,0 +1,52 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PlayerDeathEvent; + +public class Tank extends Kit { + + public Tank() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + if ((event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) + || (event.getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)) { + + if (containsHability(p)) { + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + final Player morreu = event.getEntity(), killer = morreu.getKiller(); + + if (killer == null) { + return; + } + + if (!(killer instanceof Player)) { + return; + } + + if (containsHability(killer)) { + World world = morreu.getWorld(); + world.createExplosion(morreu.getLocation(), 2.0F); + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.java new file mode 100644 index 0000000..b6e11e0 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.java @@ -0,0 +1,79 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LightningStrike; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerInteractEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Thor extends Kit { + + public Thor() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().material(Material.WOOD_AXE).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if ((event.getPlayer().getItemInHand().getType().equals(Material.WOOD_AXE)) + && (event.getAction() == Action.RIGHT_CLICK_BLOCK) && (containsHability(event.getPlayer()))) { + + if (hasCooldown(event.getPlayer())) { + sendMessageCooldown(event.getPlayer()); + return; + } + addCooldown(event.getPlayer(), getCooldownSeconds()); + + Location loc = new Location( + event.getPlayer().getWorld(), event.getClickedBlock().getX(), (event.getPlayer().getWorld() + .getHighestBlockYAt(event.getClickedBlock().getX(), event.getClickedBlock().getZ())), + event.getClickedBlock().getZ()); + + loc = loc.subtract(0, 1, 0); + if (loc.getBlock().getType() == Material.AIR) { + loc = loc.subtract(0, 1, 0); + } + + LightningStrike strike = loc.getWorld().strikeLightning(loc); + + for (Entity nearby : strike.getNearbyEntities(4.0D, 4.0D, 4.0D)) { + if ((nearby instanceof Player)) { + nearby.setFireTicks(100); + } + event.getPlayer().setFireTicks(0); + } + + strike = null; + + loc.getBlock().getRelative(BlockFace.UP).setType(Material.FIRE); + loc = null; + } + } + + @EventHandler + public void damage(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (event.getCause() == DamageCause.LIGHTNING) { + if (containsHability(player)) { + player.setFireTicks(0); + event.setCancelled(true); + } + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.java new file mode 100644 index 0000000..dff421b --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.meta.ItemMeta; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Viking extends Kit { + + public Viking() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + Player player = event.getPlayer(); + if (containsHability(player)) { + if (player.getItemInHand() != null && player.getItemInHand().getType().name().contains("AXE")) { + event.setDamage(event.getDamage() + 2.0D); + player.getItemInHand().setDurability((short) 0); + ItemMeta meta = player.getItemInHand().getItemMeta(); + if (!meta.spigot().isUnbreakable()) { + meta.spigot().setUnbreakable(true); + player.getItemInHand().setItemMeta(meta); + player.updateInventory(); + } + } + } + } + + @Override + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.java new file mode 100644 index 0000000..665474c --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.java @@ -0,0 +1,29 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class Viper extends Kit { + + public Viper() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getPlayer()) && Math.random() <= 0.33) { + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0)); + event.getDamaged().getLocation().getWorld().playEffect( + event.getDamaged().getLocation().add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.java new file mode 100644 index 0000000..6deb749 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.java @@ -0,0 +1,29 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; + +public class WeakHand extends Kit { + + public WeakHand() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (useAbility(event.getPlayer()) && Math.random() <= 0.15) { + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100, 1)); + event.getDamaged().getLocation().getWorld().playEffect( + event.getDamaged().getLocation().add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + protected void clean(Player player) { + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.java new file mode 100644 index 0000000..3d5d8fb --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.java @@ -0,0 +1,61 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.register; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Worm extends Kit { + + public Worm() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void entityDamage(EntityDamageEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + if ((e.getCause().equals(DamageCause.FALL)) && (containsHability(p))) { + if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.DIRT)) { + if (e.getDamage() >= 8.0D) { + e.setDamage(8D); + } + } + } + } + } + + @EventHandler + public void onBlockDamage(BlockDamageEvent e) { + if ((e.getBlock().getType().equals(Material.DIRT)) && (containsHability(e.getPlayer()))) { + e.setInstaBreak(true); + + if (e.getPlayer().getHealth() < 20) { + double value = e.getPlayer().getHealth() + 2.0; + if (value > 20) + value = 20.0; + e.getPlayer().setHealth(value); + } + + if (e.getPlayer().getFoodLevel() < 20) { + int value = e.getPlayer().getFoodLevel() + 1; + if (value > 20) + value = 20; + + e.getPlayer().setFoodLevel(value); + } + + e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 60, 1)); + } + } + + @Override + protected void clean(Player player) { + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.java new file mode 100644 index 0000000..3b503d5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.java @@ -0,0 +1,105 @@ +package com.br.guilhermematthew.nowly.hardcoregames.ability.utility; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.register.Gladiator; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class GladiatorFight { + + private Player[] players; + private Location[] locations; + private Block mainBlock; + private int seconds, id; + private boolean ended; + + public GladiatorFight(Block mainBlock, int id, Player... players) { + setSeconds(201); + setEnded(false); + setId(id); + + setPlayers(players); + + setMainBlock(mainBlock); + + this.locations = new Location[2]; + + this.players[0] = players[0]; + this.players[1] = players[1]; + + this.locations[0] = players[0].getLocation(); + this.locations[1] = players[1].getLocation(); + } + + public void onSecond() { + if (isEnded()) return; + + for (Player player : getPlayers()) { + if (!player.isOnline()) continue; + + if (player.getLocation().getBlockY() > mainBlock.getLocation().getBlockY() + 9) { + cancelGlad(); + } else if (player.getLocation().getBlockY() < mainBlock.getLocation().getBlockY() - 2) { + cancelGlad(); + } + } + + if (getSeconds() == 80) { + for (Player player : getPlayers()) { + if (!player.isOnline()) continue; + + player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 9999999, 3)); + } + } else if (this.seconds == 0) { + cancelGlad(); + return; + } + + this.seconds--; + } + + public void teleportBack() { + for (Player player : getPlayers()) { + if (!player.isOnline()) continue; + + player.setFallDistance(-5); + player.setNoDamageTicks(40); + + player.teleport(getBackForPlayer(player)); + } + } + + public Location getBackForPlayer(Player player) { + if (player.getUniqueId().equals(players[0].getUniqueId())) { + return locations[0]; + } else { + return locations[1]; + } + } + + public void cancelGlad() { + this.ended = true; + + for (Player player : getPlayers()) { + if (!player.isOnline()) continue; + + if (player.hasPotionEffect(PotionEffectType.WITHER)) { + player.removePotionEffect(PotionEffectType.WITHER); + } + + Gladiator.gladArena.remove(player.getUniqueId()); + } + + teleportBack(); + + Gladiator.removerBlocos(mainBlock.getLocation()); + + Gladiator.gladiatorFights.remove("arena" + id); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.java new file mode 100644 index 0000000..7b53225 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.java @@ -0,0 +1,212 @@ +package com.br.guilhermematthew.nowly.hardcoregames.base; + +import java.util.Random; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.EndListener; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerSpectateEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerSpectateEvent.SpectateAction; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.timer.TimerType; + +public abstract class GameType { + + public abstract void initialize(); + public abstract void checkWin(); + public abstract void choiceWinner(); + public abstract void registerListeners(); + public abstract void start(); + + public void setGamer(Player player) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + gamer.setPlaying(true); + + if (!isPreGame()) { + player.setNoDamageTicks(100); + player.setExp(0F); + player.setLevel(0); + player.setFireTicks(0); + player.setFoodLevel(20); + + PlayerInventory playerInventory = player.getInventory(); + playerInventory.clear(); + playerInventory.setArmorContents(null); + + player.setAllowFlight(false); + player.setFlying(false); + + if (player.getGameMode() != GameMode.SURVIVAL) + player.setGameMode(GameMode.SURVIVAL); + + KitManager.give(player, gamer.getKit1(), true); + KitManager.give(player, gamer.getKit2(), false); + + playerInventory.addItem(new ItemBuilder().type(Material.COMPASS).name("§6Bússola").build()); + } + + HardcoreGamesScoreboard.createScoreboard(gamer); + + Bukkit.getServer().getPluginManager().callEvent(new PlayerSpectateEvent(player, SpectateAction.SAIU)); + HardcoreGamesScoreboard.getScoreBoardCommon().updatePlayerMode(gamer); + + gamer = null; + } + + public void setEspectador(Player player) { + setEspectador(player, false); + } + + public void setEspectador(Player player, boolean adminChange) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + gamer.setEliminado(true); + gamer.setPlaying(false); + + Kit playerKit1 = KitManager.getKitInfo(gamer.getKit1()), + playerKit2 = KitManager.getKitInfo(gamer.getKit2()); + + if (playerKit1 != null) { + playerKit1.unregisterPlayer(player); + playerKit1 = null; + } + + if (playerKit2 != null) { + playerKit2.unregisterPlayer(player); + playerKit2 = null; + } + + if (player.getGameMode() != GameMode.ADVENTURE) + player.setGameMode(GameMode.ADVENTURE); + + player.setHealth(20.0D); + player.setFireTicks(0); + player.setFoodLevel(20); + player.setAllowFlight(true); + player.setFlying(true); + player.setExp(0F); + player.setLevel(0); + + if (!adminChange) { + for (Player ons : Bukkit.getOnlinePlayers()) { + ons.hidePlayer(player); + } + + if (BukkitMain.getBukkitPlayer(player.getUniqueId()).getGroup().getLevel() >= Groups.PRIME.getLevel()) { + + VanishAPI.changeAdmin(player, false); + } + + player.getInventory().addItem(new ItemBuilder().type(Material.COMPASS).name("§aJogadores Vivos").build()); + } + + HardcoreGamesScoreboard.createScoreboard(gamer); + + Bukkit.getServer().getPluginManager().callEvent(new PlayerSpectateEvent(player, SpectateAction.ENTROU)); + + HardcoreGamesScoreboard.getScoreBoardCommon().updatePlayerMode(gamer); + gamer = null; + + checkWin(); + } + + protected boolean isLoading() { + return HardcoreGamesMain.getGameManager().isLoading(); + } + + protected boolean isPreGame() { + return HardcoreGamesMain.getGameManager().isPreGame(); + } + + protected boolean isInvencibilidade() { + return HardcoreGamesMain.getGameManager().isInvencibilidade(); + } + + protected boolean isGaming() { + return HardcoreGamesMain.getGameManager().isGaming(); + } + + protected boolean isEnd() { + return HardcoreGamesMain.getGameManager().isEnd(); + } + + protected Random getRandom() { + return CommonsConst.RANDOM; + } + + protected UUID getMVP() { + return getMVP(false); + } + + protected UUID getMVP(boolean allGamers) { + UUID ganhador = null; + + int kills = -1; + + if (allGamers) { + for (Gamer gamer : GamerManager.getGamers()) { + int killsPlayer = gamer.getKills(); + + if (killsPlayer >= kills) { + ganhador = gamer.getUniqueId(); + kills = killsPlayer; + } + } + } else { + for (Player player : GamerManager.getAliveGamers()) { + int killsPlayer = GamerManager.getGamer(player.getUniqueId()).getKills(); + + if (killsPlayer >= kills) { + ganhador = player.getUniqueId(); + kills = killsPlayer; + } + } + } + + return ganhador; + } + + protected void callEnd() { + HardcoreGamesMain.getGameManager().setStage(GameStages.END); + HardcoreGamesMain.getTimerManager().setTimerType(TimerType.COUNTDOWN); + + HardcoreGamesMain.getInstance().getServer().getPluginManager().callEvent(new GameStageChangeEvent( + HardcoreGamesMain.getGameManager().getStage(), GameStages.END)); + + HardcoreGamesMain.getTimerManager().updateTime(15); + + //BUKKIT OPTIONS (COMMONS PLUGIN) + BukkitSettings.PVP_OPTION = false; + BukkitSettings.DANO_OPTION = false; + + //HARDCOREGAMES OPTIONS + HardcoreGamesOptions.BREAK_OPTION = false; + HardcoreGamesOptions.PLACE_OPTION = false; + HardcoreGamesOptions.DROP_OPTION = false; + + HardcoreGamesMain.getInstance().getServer().getPluginManager().registerEvents(new EndListener(), + BukkitMain.getInstance()); + + HardcoreGamesMain.getTimerManager().updateTime(15); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.java new file mode 100644 index 0000000..6b0df10 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.java @@ -0,0 +1,96 @@ +package com.br.guilhermematthew.nowly.hardcoregames.commands; + +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; + +public class ChampionsCommand implements CommandClass { + + private final List types = Arrays.asList( + "lava", "minicopa", "ultrafast", "gladiator", + "arenafeast", "arenadamage", "arenapvp", "arenaold", "champions", "minichampions", "championstraining"); + private final List modes = Arrays.asList("solo", "dupla"); + + @CommandFramework.Command(name = "explainevent", aliases = {"explicarevento", "eventoexplicar"}, groupsToUse= {Groups.MOD}) + public void explainevent(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + sendHelp(commandSender); + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 1) { + if (args[0].equalsIgnoreCase("champions")) { + + for (Player allUsers : Bukkit.getOnlinePlayers()) { + allUsers.sendMessage("§6§lCHAMPIONS §7» §fSejam bem-vindos(as) a §eChampions§f!"); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fTodos irão iniciar o jogo com um kit de itens."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fVocês terão §e1 minuto §fde invencibilidade para se\n§forganizarem."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fÉ §cproibido §finterferir na luta de jogadores que não fazem parte de seu time."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fÉ §cproibido §faguardar que uma luta seja finalizada com intuito de atacar os vencedores."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fNão é permitido fazer spawn traps."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fAos §e30 minutos §fde partida, vocês serão teleportados para uma Arena Final."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fAlguns kits estarão desativados durante todo o evento."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fDúvidas, reclamações e revisões de kick devem ser solicitados em nosso §9Discord§f!"); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fIniciaremos em alguns instantes! Bom jogo e boa sorte."); + } + } else { + sendHelp(commandSender); + } + if (args.length == 1) { + if (args[0].equalsIgnoreCase("arenapvp")) { + + for (Player allUsers : Bukkit.getOnlinePlayers()) { + allUsers.sendMessage("§6§lCHAMPIONS §7» §fSejam bem-vindos(as) a §eChampions§f!"); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fTodos irão iniciar o jogo com um kit de itens."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fVocês terão §e1 minuto §fde invencibilidade para se\n§forganizarem."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fÉ §cproibido §finterferir na luta de jogadores que não fazem parte de seu time."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fÉ §cproibido §faguardar que uma luta seja finalizada com intuito de atacar os vencedores."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fNão é permitido fazer spawn traps."); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fAos §e30 minutos §fde partida, vocês serão teleportados para uma Arena Final."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fAlguns kits estarão desativados durante todo o evento."); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fDúvidas, reclamações e revisões de kick devem ser solicitados em nosso §9Discord§f!"); + allUsers.sendMessage("§f"); + allUsers.sendMessage("§6§lCHAMPIONS §7» §fIniciaremos em alguns instantes! Bom jogo e boa sorte."); + } + } else { + sendHelp(commandSender); + } + } + } + + player = null; + } + + private void sendHelp(BukkitCommandSender commandSender) { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /explicarevento <" + StringUtils.join(types, "§c, ") + ">"); + commandSender.sendMessage(" §cExplicação do comando:"); + commandSender.sendMessage(" §cEle anunciará todas as informações e instruções do evento"); + commandSender.sendMessage(" §cpara os jogadores presentes na sala com clareza e bem"); + commandSender.sendMessage(" §ctabelado para intuição."); + commandSender.sendMessage(""); + } + +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.java new file mode 100644 index 0000000..8c6845b --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.java @@ -0,0 +1,400 @@ +package com.br.guilhermematthew.nowly.hardcoregames.commands; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Completer; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + +public class PlayerCommand implements CommandClass { + + @Command(name = "spawn") + public void spawn(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer())return; + + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + commandSender.sendMessage("§cO jogo já iniciou!"); + return; + } + + if (HardcoreGamesMain.getTimerManager().getTime().get() <= 11) { + commandSender.sendMessage("§cVocê não pode ir para o spawn agora!"); + return; + } + + Player player = commandSender.getPlayer(); + + player.teleport(HardcoreGamesUtility.getRandomLocation(30)); + + player = null; + } + + @Command(name = "specs", groupsToUse = {Groups.BETA}) + public void specs(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + player.sendMessage(StringUtils.COMMAND_SPECS_GAME_DONT_STARTED); + return; + } + + if (args.length != 1) { + commandSender.sendMessage(StringUtils.COMMANDS_SPECS_USAGE); + return; + } + + if (args[0].equalsIgnoreCase("on")) { + int vendo = 0; + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if ((VanishAPI.inAdmin(onlines)) || (VanishAPI.isInvisible(onlines))) { + continue; + } + if (!GamerManager.getGamer(onlines.getUniqueId()).isPlaying()) { + vendo++; + player.showPlayer(onlines); + } + } + + if (vendo != 0) { + player.sendMessage(StringUtils.SPECS_ATIVADOS); + } else { + player.sendMessage(StringUtils.NENHUM_SPEC_ENCONTRADO); + } + } else if (args[0].equalsIgnoreCase("off")) { + int escondidos = 0; + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (!GamerManager.getGamer(onlines.getUniqueId()).isPlaying()) { + escondidos++; + player.hidePlayer(onlines); + } + } + + if (escondidos != 0) { + player.sendMessage(StringUtils.SPECS_DESATIVADOS); + } else { + player.sendMessage(StringUtils.NENHUM_SPEC_ENCONTRADO); + } + } else { + commandSender.sendMessage(StringUtils.COMMANDS_SPECS_USAGE); + } + } + + @Command(name = "desistir", groupsToUse = {Groups.BETA}) + public void desistir(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) return; + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + commandSender.sendMessage(StringUtils.COMMAND_DESISTIR_O_JOGO_AINDA_NAO_INICIOU); + return; + } + + Player player = commandSender.getPlayer(); + + if (GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + player.sendMessage(StringUtils.COMMAND_DESISTIR_SUCESSO); + + PlayerAPI.dropItems(player, player.getLocation()); + + HardcoreGamesMain.getGameManager().getGameType().setEspectador(player, false); + } else { + player.sendMessage(StringUtils.COMMAND_DESISTIR_NAO_ESTA_JOGANDO); + } + + player = null; + } + + @Command(name = "feast") + public void feast(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) return; + + + Player player = commandSender.getPlayer(); + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + player.sendMessage(StringUtils.COMMAND_FEAST_O_JOGO_AINDA_NAO_INICIOU); + return; + } + if (!player.getInventory().contains(Material.COMPASS)) { + player.sendMessage(StringUtils.COMMAND_FEAST_NAO_TEM_BUSSOLA); + return; + } + + if (StructuresManager.getFeast().getLocation() == null) { + player.sendMessage(StringUtils.COMMAND_FEAST_NAO_SPAWNOU); + return; + } + + player.setCompassTarget(StructuresManager.getFeast().getLocation()); + player.sendMessage(StringUtils.COMMAND_FEAST_SUCESSO); + + player = null; + } + + @Command(name = "kit") + public void kit(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + List kits = null; + + if (!HardcoreGamesOptions.DOUBLE_KIT) { + kits = KitManager.getPlayerKits(player).stream().map(Kit::getName).collect(Collectors.toList()); + } else { + kits = KitManager.getAllKits().stream().map(Kit::getName).collect(Collectors.toList()); + } + + TextComponent text = new TextComponent("§a" + (HardcoreGamesOptions.DOUBLE_KIT ? "Todos os Kits" : "Seus Kits") + + " (" + kits.size() + "): "); + + for (int i = 0; i < kits.size(); i++) { + String kit = kits.get(i); + text.addExtra(i == 0 ? "" : ", "); + text.addExtra(buildKitComponent(KitManager.getKitInfo(kit.toLowerCase()), true)); + } + + player.spigot().sendMessage(text); + player.sendMessage(""); + + text = null; + + kits.clear(); + kits = null; + } else if (args.length == 1) { + String kit = args[0].toLowerCase(); + + if (!KitManager.getKits().containsKey(kit)) { + player.sendMessage(StringUtils.COMMAND_KIT_NAO_EXISTE); + return; + } + + if (HardcoreGamesOptions.KITS_DISABLEDS) { + player.sendMessage(StringUtils.COMMAND_KIT_TODOS_KITS_DESATIVADOS); + return; + } + if (KitManager.getKitsDesativados().contains(kit.toLowerCase())) { + player.sendMessage(StringUtils.COMMAND_KIT_KIT_DESATIVADO); + return; + } + + + if (KitManager.isSameKit(kit, GamerManager.getGamer(player.getUniqueId()).getKit1())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_PEGAR_DOIS_KITS_IGUAIS); + return; + } + + if (KitManager.isSameKit(kit, GamerManager.getGamer(player.getUniqueId()).getKit2())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_PEGAR_DOIS_KITS_IGUAIS); + return; + } + + if (KitManager.hasCombinationOp(kit, GamerManager.getGamer(player.getUniqueId()).getKit2())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_ESTA_COMBINACAO_DE_KIT); + return; + } + + boolean hasPermission = true; + + if (!HardcoreGamesOptions.DOUBLE_KIT) { + hasPermission = KitManager.hasPermissionKit(player, kit, true); + } + + if (!hasPermission) { + return; + } + + kit = KitManager.getKitInfo(kit).getName(); + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + GamerManager.getGamer(player.getUniqueId()).setKit1(kit); + + player.sendMessage(StringUtils.COMMAND_KIT_SUCESS.replace("%kit%", kit)); + + TitleAPI.sendTitle(player, StringUtils.TITLE_ON_KIT_SELECTED.replace("%kit%", kit), + StringUtils.SUBTITLE_ON_KIT_SELECTED, 0, 0, 5); + + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit1(player, kit); + } else { + if (player.hasPermission("hardcoregames.pegarkit")) { + if (HardcoreGamesMain.getTimerManager().getTime().get() <= 300) { + if (GamerManager.getGamer(player.getUniqueId()).getKit1().equalsIgnoreCase("Nenhum")) { + player.sendMessage(StringUtils.COMMAND_KIT_SUCESS.replace("%kit%", kit)); + + TitleAPI.sendTitle(player, StringUtils.TITLE_ON_KIT_SELECTED.replace("%kit%", kit), + StringUtils.SUBTITLE_ON_KIT_SELECTED, 0, 0, 5); + + KitManager.handleKitSelect(player, true, kit); + } else { + player.sendMessage(StringUtils.COMMAND_KIT_VOCE_JA_ESTA_COM_KIT); + } + } else { + player.sendMessage(StringUtils.COMMAND_KIT_TEMPO_ESGOTADO); + } + } else { + player.sendMessage(StringUtils.COMMAND_KIT_SEM_PERM_PARA_PEGAR_DEPOIS_DO_JOGO_TER_INICIADO); + } + } + } + } + + @Command(name = "kit2") + public void kit2(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (!HardcoreGamesOptions.DOUBLE_KIT) { + commandSender.sendMessage("§cEsta partida está habilitada apenas o primeiro KIT."); + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 0) { + List kits = KitManager.getPlayerKits(player).stream().map(Kit::getName).collect(Collectors.toList()); + + TextComponent text = new TextComponent("§aSeus Kits (" + kits.size() + "): "); + + for (int i = 0; i < kits.size(); i++) { + String kit = kits.get(i); + text.addExtra(i == 0 ? "" : ", "); + text.addExtra(buildKitComponent(KitManager.getKitInfo(kit.toLowerCase()), false)); + } + + player.spigot().sendMessage(text); + player.sendMessage(""); + + kits.clear(); + } else if (args.length == 1) { + String kit = args[0].toLowerCase(); + + if (!KitManager.getKits().containsKey(kit)) { + player.sendMessage(StringUtils.COMMAND_KIT_NAO_EXISTE); + return; + } + + if (HardcoreGamesOptions.KITS_DISABLEDS) { + player.sendMessage(StringUtils.COMMAND_KIT_TODOS_KITS_DESATIVADOS); + return; + } + if (KitManager.getKitsDesativados().contains(kit.toLowerCase())) { + player.sendMessage(StringUtils.COMMAND_KIT_KIT_DESATIVADO); + return; + } + + + if (KitManager.isSameKit(kit, GamerManager.getGamer(player.getUniqueId()).getKit1())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_PEGAR_DOIS_KITS_IGUAIS); + return; + } + + if (KitManager.isSameKit(kit, GamerManager.getGamer(player.getUniqueId()).getKit2())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_PEGAR_DOIS_KITS_IGUAIS); + return; + } + + if (KitManager.hasCombinationOp(kit, GamerManager.getGamer(player.getUniqueId()).getKit1())) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_ESTA_COMBINACAO_DE_KIT); + return; + } + + if (!KitManager.hasPermissionKit(player, kit, true)) { + return; + } + + kit = KitManager.getKitInfo(kit).getName(); + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + GamerManager.getGamer(player.getUniqueId()).setKit2(kit); + + player.sendMessage(StringUtils.COMMAND_KIT_SUCESS.replace("%kit%", kit)); + + TitleAPI.sendTitle(player, StringUtils.TITLE_ON_KIT_SELECTED.replace("%kit%", kit), + StringUtils.SUBTITLE_ON_KIT_SELECTED, 0, 0, 5); + + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit2(player, kit); + } else { + if (player.hasPermission("hardcoregames.pegarkit")) { + if (HardcoreGamesMain.getTimerManager().getTime().get() <= 300) { + if (GamerManager.getGamer(player.getUniqueId()).getKit2().equalsIgnoreCase("Nenhum")) { + player.sendMessage(StringUtils.COMMAND_KIT_SUCESS.replace("%kit%", kit)); + + TitleAPI.sendTitle(player, StringUtils.TITLE_ON_KIT_SELECTED.replace("%kit%", kit), + StringUtils.SUBTITLE_ON_KIT_SELECTED, 0, 0, 5); + + KitManager.handleKitSelect(player, false, kit); + } else { + player.sendMessage(StringUtils.COMMAND_KIT_VOCE_JA_ESTA_COM_KIT); + } + } else { + player.sendMessage(StringUtils.COMMAND_KIT_TEMPO_ESGOTADO); + } + } else { + player.sendMessage(StringUtils.COMMAND_KIT_SEM_PERM_PARA_PEGAR_DEPOIS_DO_JOGO_TER_INICIADO); + } + } + } + } + + @Completer(name = "kit", aliases = "kit2") + public List kitCompleter(BukkitCommandSender sender, String label, String[] args) { + List list = new ArrayList<>(); + + if (args.length == 1) { + String search = args[0].toLowerCase(); + for (Kit kit : KitManager.getAllKits()) { + if (kit.getName().toLowerCase().startsWith(search)) { + list.add(kit.getName()); + } + } + } + + return list; + } + + private BaseComponent buildKitComponent(Kit kit, boolean primary) { + BaseComponent baseComponent = new TextComponent("§6" + kit.getName()); + BaseComponent descComponent = new TextComponent("§eDescrição: \n"); + for (String desc : kit.getDescription()) + descComponent.addExtra(desc.replaceAll("&", "§") + "\n"); + + baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new BaseComponent[] { descComponent, new TextComponent("\n"), new TextComponent("§aClique para selecionar!") })); + baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (primary ? "/kit " : "/kit2 ") + kit.getName())); + return baseComponent; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.java new file mode 100644 index 0000000..8618a2e --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.java @@ -0,0 +1,709 @@ +package com.br.guilhermematthew.nowly.hardcoregames.commands; + +import java.util.*; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditAPI; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; +import com.br.guilhermematthew.nowly.hardcoregames.utility.InventoryStore; + +public class StafferCommand implements CommandClass { + + private final HashMap Skits = new HashMap<>(); + + @Command(name = "reviver", aliases= {"respawn"}, groupsToUse= {Groups.ADMIN}) + public void reviver(BukkitCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage("§cUtilize: /reviver "); + return; + } + + Player target = Bukkit.getPlayer(args[0]); + + if (target != null) { + if (!GamerManager.getGamer(target.getUniqueId()).isPlaying()) { + HardcoreGamesMain.getGameManager().getGameType().setGamer(target); + + commandSender.sendMessage("§aVocê reviveu o jogador §7" + target.getName()); + target.sendMessage("§aVocê foi revivido!"); + } else { + commandSender.sendMessage("§cEste jogador não está eliminado."); + } + } else { + commandSender.sendMessage("§cJogador offline."); + } + } + + @Command(name = "hginfo", groupsToUse= {Groups.ADMIN}) + public void hginfo(BukkitCommandSender commandSender, String label, String[] args) { + commandSender.sendMessage(""); + + int vivos = 0, onlines = 0, espectando = 0, relog = 0; + + for (Gamer gamers : GamerManager.getGamers()) { + onlines++; + + if (gamers.isPlaying()) { + vivos++; + } + + if (gamers.isOnline() && !gamers.isPlaying()) { + espectando++; + } + + if (gamers.isRelogar()) { + relog++; + } + } + + commandSender.sendMessage(""); + commandSender.sendMessage("§fJogadores jogando: §a" + vivos); + commandSender.sendMessage("§fJogadores espectando: §a" + espectando); + commandSender.sendMessage("§fJogadores para relogar: §a" + relog); + commandSender.sendMessage("§fJogadores online: §a" + onlines); + commandSender.sendMessage(""); + } + + @Command(name = "toggle", groupsToUse= {Groups.MOD_PLUS}) + public void toggle(BukkitCommandSender commandSender, String label, String[] args) { + if (args.length == 0) { + commandSender.sendMessage("§cUse /toggle "); + commandSender.sendMessage("§cUse /toggle kit "); + commandSender.sendMessage("§cUse /toggle kit * - para desativar/ativar todos os kits."); + } else if (args.length == 2) { + if(args[0].equalsIgnoreCase("doublekit")) { + if(args[1].equalsIgnoreCase("on")) { + HardcoreGamesOptions.DOUBLE_KIT = true; + HardcoreGamesScoreboard.init(); + + if(HardcoreGamesMain.getGameManager().isGaming()) return; + + Bukkit.getOnlinePlayers().forEach(player -> { + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + playerInventory.setItem(0, itemBuilder.type(Material.CHEST).name("§aEscolher Kit").build()); + + if (HardcoreGamesOptions.DOUBLE_KIT) { + playerInventory.setItem(1, itemBuilder.type(Material.CHEST).amount(2).name("§aEscolher Kit 2").build()); + } + + playerInventory.addItem(itemBuilder.type(Material.EMERALD).name("§6Loja de Kits").build()); + + playerInventory.setItem(8, itemBuilder.type(Material.BED).name("§cVoltar ao Lobby").build()); + }); + } else if(args[1].equalsIgnoreCase("off")) { + GamerManager.getGamers().forEach(gamer -> gamer.setKit2("Nenhum")); + + HardcoreGamesOptions.DOUBLE_KIT = false; + HardcoreGamesScoreboard.init(); + + if(HardcoreGamesMain.getGameManager().isGaming()) return; + + Bukkit.getOnlinePlayers().forEach(player -> { + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + playerInventory.setItem(0, itemBuilder.type(Material.CHEST).name("§aEscolher Kit").build()); + + if (HardcoreGamesOptions.DOUBLE_KIT) { + playerInventory.setItem(1, itemBuilder.type(Material.CHEST).amount(2).name("§aEscolher Kit 2").build()); + } + + playerInventory.addItem(itemBuilder.type(Material.EMERALD).name("§6Loja de Kits").build()); + + playerInventory.setItem(8, itemBuilder.type(Material.BED).name("§cVoltar ao Lobby").build()); + }); + } + } else if (args[0].equalsIgnoreCase("feast")) { + if (args[1].equalsIgnoreCase("on")) { + if (!HardcoreGamesOptions.FEAST) { + HardcoreGamesOptions.FEAST = true; + Bukkit.broadcastMessage(StringUtils.FEAST_ATIVADO); + } else { + commandSender.sendMessage(StringUtils.FEAST_JA_ATIVADO); + } + } else if (args[1].equalsIgnoreCase("off")) { + if (HardcoreGamesOptions.FEAST) { + Bukkit.broadcastMessage(StringUtils.FEAST_DESATIVADO); + HardcoreGamesOptions.FEAST = false; + } else { + commandSender.sendMessage(StringUtils.FEAST_JA_DESATIVADO); + } + } + } else if (args[0].equalsIgnoreCase("minifeast")) { + if (args[1].equalsIgnoreCase("on")) { + if (!HardcoreGamesOptions.MINIFEAST) { + HardcoreGamesOptions.MINIFEAST = true; + Bukkit.broadcastMessage(StringUtils.MINIFEAST_ATIVADO); + } else { + commandSender.sendMessage(StringUtils.MINIFEAST_JA_ATIVADO); + } + } else if (args[1].equalsIgnoreCase("off")) { + if (HardcoreGamesOptions.MINIFEAST) { + HardcoreGamesOptions.MINIFEAST = false; + Bukkit.broadcastMessage(StringUtils.MINIFEAST_DESATIVADO); + } else { + commandSender.sendMessage(StringUtils.MINIFEAST_JA_DESATIVADO); + } + } + } else if (args[0].equalsIgnoreCase("drops")) { + if (args[1].equalsIgnoreCase("on")) { + if (!HardcoreGamesOptions.DROP_OPTION) { + HardcoreGamesOptions.DROP_OPTION = true; + Bukkit.broadcastMessage(StringUtils.DROPS_ATIVADO); + } else { + commandSender.sendMessage(StringUtils.DROPS_JA_ATIVADO); + } + } else if (args[1].equalsIgnoreCase("off")) { + if (HardcoreGamesOptions.DROP_OPTION) { + HardcoreGamesOptions.DROP_OPTION = false; + Bukkit.broadcastMessage(StringUtils.DROPS_DESATIVADO); + } else { + commandSender.sendMessage(StringUtils.DROPS_JA_DESATIVADO); + } + } + } else if (args[0].equalsIgnoreCase("break")) { + if (args[1].equalsIgnoreCase("on")) { + if (!HardcoreGamesOptions.BREAK_OPTION) { + HardcoreGamesOptions.BREAK_OPTION = true; + Bukkit.broadcastMessage(StringUtils.BREAK_ATIVADO); + } else { + commandSender.sendMessage(StringUtils.BREAK_JA_ATIVADO); + } + } else if (args[1].equalsIgnoreCase("off")) { + if (HardcoreGamesOptions.BREAK_OPTION) { + HardcoreGamesOptions.BREAK_OPTION = false; + Bukkit.broadcastMessage(StringUtils.BREAK_DESATIVADO); + } else { + commandSender.sendMessage(StringUtils.BREAK_JA_DESATIVADO); + } + } + } else if (args[0].equalsIgnoreCase("place")) { + if (args[1].equalsIgnoreCase("on")) { + if (!HardcoreGamesOptions.PLACE_OPTION) { + HardcoreGamesOptions.PLACE_OPTION = true; + Bukkit.broadcastMessage(StringUtils.PLACE_ATIVADO); + } else { + commandSender.sendMessage(StringUtils.PLACE_JA_ATIVADO); + } + } else if (args[1].equalsIgnoreCase("off")) { + if (HardcoreGamesOptions.PLACE_OPTION) { + HardcoreGamesOptions.PLACE_OPTION = false; + Bukkit.broadcastMessage(StringUtils.PLACE_DESATIVADO); + } else { + commandSender.sendMessage(StringUtils.PLACE_JA_DESATIVADO); + } + } + } else { + commandSender.sendMessage("§cUse /toggle "); + commandSender.sendMessage("§cUse /toggle kit "); + commandSender.sendMessage("§cUse /toggle kit * - para desativar/ativar todos os kits."); + } + } else if (args.length == 3) { + if (args[0].equalsIgnoreCase("kit")) { + String s = args[1].toLowerCase(); + + if (s.equalsIgnoreCase("*")) { + if (args[2].equalsIgnoreCase("off")) { + for (Kit allKits : KitManager.getAllKits()) { + if (!KitManager.getKitsDesativados().contains(allKits.getName().toLowerCase())) { + KitManager.getKitsDesativados().add(allKits.getName().toLowerCase()); + } + } + + for (Player on : Bukkit.getOnlinePlayers()) { + KitManager.removeKits(on, true); + } + + Bukkit.broadcastMessage(StringUtils.TODOS_OS_KITS_FORAM_DESATIVADOS); + } else if (args[2].equalsIgnoreCase("on")) { + KitManager.getKitsDesativados().clear(); + + Bukkit.broadcastMessage(StringUtils.TODOS_OS_KITS_FORAM_ATIVADOS); + } else { + commandSender.sendMessage("§cUse /toggle "); + commandSender.sendMessage("§cUse /toggle kit "); + commandSender.sendMessage("§cUse /toggle kit * - para desativar/ativar todos os kits."); + } + } else if (KitManager.getKits().containsKey(s)) { + s = Objects.requireNonNull(KitManager.getKitInfo(s)).getName(); + + if (args[2].equalsIgnoreCase("on")) { + if (KitManager.getKitsDesativados().contains(s.toLowerCase())) { + KitManager.getKitsDesativados().remove(s.toLowerCase()); + + commandSender.sendMessage(StringUtils.KIT_ATIVADO.replace("%kit%", s)); + } else { + commandSender.sendMessage(StringUtils.KIT_JA_ESTA_ATIVADO.replace("%kit%", s)); + } + } else if (args[2].equalsIgnoreCase("off")) { + if (KitManager.getKitsDesativados().contains(s.toLowerCase())) { + commandSender.sendMessage(StringUtils.KIT_JA_ESTA_DESATIVADO.replace("%kit%", s)); + } else { + KitManager.getKitsDesativados().add(s.toLowerCase()); + commandSender.sendMessage(StringUtils.KIT_DESATIVADO.replace("%kit%", s)); + + for (Player on : Bukkit.getOnlinePlayers()) { + KitManager.removeIfContainsKit(on, s); + } + } + } + } else { + commandSender.sendMessage(StringUtils.COMMAND_KIT_NAO_EXISTE); + } + } + } else { + commandSender.sendMessage("§cUse /toggle "); + commandSender.sendMessage("§cUse /toggle kit "); + commandSender.sendMessage("§cUse /toggle kit * - para desativar/ativar todos os kits."); + } + } + + @Command(name = "fkit", aliases= {"forcekit"}, groupsToUse= {Groups.MOD_PLUS}) + public void fkit1(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length != 2) { + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_USAGE); + return; + } + + String kit = args[0].toLowerCase(), + nick = args[1]; + + if (!KitManager.getKits().containsKey(kit)) { + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_KIT_NAO_EXISTE); + return; + } + + kit = Objects.requireNonNull(Objects.requireNonNull(KitManager.getKitInfo(kit))).getName(); + + if ((nick.equalsIgnoreCase("todos")) || (nick.equals("*"))) { + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + for (Player player : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + if (gamer == null) { + continue; + } + gamer.setKit1(kit); + } + } else { + for (Player player : Bukkit.getOnlinePlayers()) { + KitManager.handleKitSelect(player, true, kit); + } + } + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_SUCESS_ALL_PLAYERS.replace("%kit%", kit)); + } else { + Player target = Bukkit.getPlayer(nick); + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + GamerManager.getGamer(target.getUniqueId()).setKit1(kit); + } else { + KitManager.handleKitSelect(target, true, kit); + } + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_SUCESS_PLAYER.replace("%kit%", kit).replace("%nick%", target.getName())); + } + } + + @Command(name = "fkit2", aliases= {"forcekit2"}, groupsToUse= {Groups.MOD_PLUS}) + public void fkit2(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length != 2) { + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_USAGE); + return; + } + + if (!HardcoreGamesOptions.DOUBLE_KIT) { + commandSender.sendMessage("§cEsta partida está habilitada apenas o primeiro KIT."); + return; + } + + String kit = args[0].toLowerCase(), + nick = args[1]; + + if (!KitManager.getKits().containsKey(kit)) { + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_KIT_NAO_EXISTE); + return; + } + + kit = Objects.requireNonNull(Objects.requireNonNull(KitManager.getKitInfo(kit))).getName(); + + if ((nick.equalsIgnoreCase("todos")) || (nick.equals("*"))) { + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + for (Player player : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + if (gamer == null) { + continue; + } + gamer.setKit2(kit); + } + } else { + for (Player player : Bukkit.getOnlinePlayers()) { + KitManager.handleKitSelect(player, false, kit); + } + } + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_SUCESS_ALL_PLAYERS.replace("%kit%", kit)); + } else { + Player target = Bukkit.getPlayer(nick); + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + GamerManager.getGamer(target.getUniqueId()).setKit2(kit); + } else { + KitManager.handleKitSelect(target, false, kit); + } + commandSender.sendMessage(StringUtils.COMMAND_FORCEKIT_SUCESS_PLAYER.replace("%kit%", kit).replace("%nick%", target.getName())); + } + } + + @SuppressWarnings("deprecation") + @Command(name = "skit", aliases= {"simplekit"}, groupsToUse= {Groups.MOD}) + public void skit(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_USAGE); + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("lista")) { + if (Skits.size() == 0) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_NENHUM_CRIADO); + return; + } + + StringBuilder skits = new StringBuilder(); + for (String kits : Skits.keySet()) { + if (skits.toString().equals("")) { + if (Skits.size() == 1) { + skits = new StringBuilder(kits); + break; + } else { + skits = new StringBuilder(kits); + } + } else { + skits.append(",").append(kits); + } + } + commandSender.sendMessage(StringUtils.COMMAND_SKIT_LISTA + skits); + } else { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_USAGE); + } + } else if (args.length == 2) { + if (!args[0].equalsIgnoreCase("criar")) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_USAGE); + return; + } + String kit = args[1]; + if (Skits.containsKey(kit)) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_JA_EXISTE); + return; + } + Player player = commandSender.getPlayer(); + + Skits.put(kit, new InventoryStore(kit, + player.getInventory().getArmorContents(), + player.getInventory().getContents(), + (List) player.getActivePotionEffects())); + + commandSender.sendMessage(StringUtils.COMMAND_SKIT_CRIADO.replace("%nome%", kit)); + } else if (args.length == 3) { + if (!args[0].equalsIgnoreCase("aplicar")) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_USAGE); + return; + } + String kit = args[1]; + if (!Skits.containsKey(kit)) { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_NAO_EXISTE); + return; + } + + InventoryStore inv = Skits.get(kit); + + if ((args[2].equalsIgnoreCase("todos")) || (args[2].equalsIgnoreCase("*"))) { + for (Player ons : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(ons.getUniqueId()); + + if (gamer.isPlaying()) { + ons.getPlayer().setItemOnCursor(new ItemStack(0)); + ons.getInventory().setArmorContents(inv.getArmor()); + ons.getInventory().setContents(inv.getInv()); + ons.addPotionEffects(inv.getPotions()); + + if (ons.getInventory().contains(Material.WOOL)) { + ons.getInventory().setItem(ons.getInventory().first(Material.WOOL), null); + KitManager.giveItensKit(ons, gamer.getKit1()); + } + + if (!PlayerAPI.isFull(ons.getInventory())) { + ons.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); + } + } + } + commandSender.sendMessage(StringUtils.COMMAND_SKIT_SUCESSO_ALL_PLAYERS.replace("%nome%", kit)); + } else { + Player target = Bukkit.getPlayer(args[2]); + if (target == null) { + commandSender.sendMessage(BukkitMessages.JOGADOR_OFFLINE); + return; + } + + target.getPlayer().setItemOnCursor(new ItemStack(0)); + target.getInventory().setArmorContents(inv.getArmor()); + target.getInventory().setContents(inv.getInv()); + target.addPotionEffects(inv.getPotions()); + + if (target.getInventory().contains(Material.WOOL)) { + target.getInventory().setItem(target.getInventory().first(Material.WOOL), null); + KitManager.giveItensKit(target, GamerManager.getGamer(target.getUniqueId()).getKit1()); + } + + target.updateInventory(); + + if (!PlayerAPI.isFull(target.getInventory())) { + target.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); + target.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); + target.updateInventory(); + } + + commandSender.sendMessage(StringUtils.COMMAND_SKIT_SUCESSO_PLAYER.replace("%nome%", kit).replace("%nick%", target.getName())); + } + } else { + commandSender.sendMessage(StringUtils.COMMAND_SKIT_USAGE); + } + } + + @Command(name = "start", aliases= {"iniciar"}, groupsToUse= {Groups.MOD}) + public void start(BukkitCommandSender commandSender, String label, String[] args) { + if (HardcoreGamesMain.getGameManager().isPreGame()) { + HardcoreGamesMain.getGameManager().getGameType().start(); + } else { + commandSender.sendMessage(StringUtils.COMMAND_START_FAILED); + } + } + + @Command(name = "tempo", aliases= {"t"}, groupsToUse= {Groups.MOD}) + public void tempo(BukkitCommandSender commandSender, String label, String[] args) { + if (args.length != 1) { + commandSender.sendMessage(StringUtils.COMMAND_TEMPO_USAGE); + return; + } + + if (!StringUtility.isInteger(args[0])) { + commandSender.sendMessage(StringUtils.COMMAND_TEMPO_USAGE); + return; + } + + int segundos = Integer.parseInt(args[0]); + + if (segundos <= 0) { + commandSender.sendMessage(StringUtils.COMMAND_TEMPO_USAGE); + return; + } + + HardcoreGamesMain.getTimerManager().updateTime(segundos); + + Bukkit.broadcastMessage(StringUtils.TEMPO_CHANGED.replace("%tempo%", DateUtils.formatTime(segundos))); + } + + @Command(name = "ffeast", aliases= {"forcefeast"}, groupsToUse= {Groups.MOD_PLUS}) + public void ffeast(BukkitCommandSender commandSender, String label, String[] args) { + if(!HardcoreGamesMain.getGameManager().isGaming()) { + commandSender.sendMessage(ChatColor.RED + " * A partida ainda não iniciou ou está no tempo de invencibilidade."); + return; + } + + if(StructuresManager.getFeast().isSpawned()) new PlayerCommand().feast(commandSender, label, args); + else StructuresManager.getFeast().createFeast(StructuresManager.getValidLocation(true)); + } + + @Command(name = "arena", groupsToUse= {Groups.MOD}) + public void arena(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage(StringUtils.COMMAND_ARENA_USAGE); + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("limpar")) { + limparArena(commandSender.getPlayer()); + } else if (args[0].equalsIgnoreCase("final")) { + StructuresManager.getFinalBattle().create(); + } else { + commandSender.sendMessage(StringUtils.COMMAND_ARENA_USAGE); + } + } else if (args.length == 2) { + String largura = args[0], altura = args[1]; + if ((!StringUtility.isInteger(largura)) || (!StringUtility.isInteger(altura))) { + commandSender.sendMessage(StringUtils.COMMAND_ARENA_USAGE); + return; + } + criarArena(commandSender.getPlayer(), commandSender.getPlayer().getLocation(), Integer.parseInt(largura), Integer.parseInt(altura)); + } else { + commandSender.sendMessage(StringUtils.COMMAND_ARENA_USAGE); + } + } + + private static Location ponto_baixo, ponto_alto; + + public static void criarArena(Player p, final Location loc, int largura, int altura) { + if (p != null) { + p.sendMessage(StringUtils.CREATING_ARENA); + } + + List cuboid = new ArrayList<>(); + + for (int bX = -largura; bX <= largura; bX++) { + for (int bZ = -largura; bZ <= largura; bZ++) { + for (int bY = -1; bY <= altura; bY++) { + if ((bY == altura) || (bY == -1)) { + cuboid.add(loc.clone().add(bX, bY, bZ)); + } else if ((bX == -largura) || (bZ == -largura) || (bX == largura) || (bZ == largura)) { + cuboid.add(loc.clone().add(bX, bY, bZ)); + } + } + } + } + + + new BukkitRunnable() { + + boolean ended = false; + int blockAtual = 0; + final int max = cuboid.size() + 10; + final int blocksPerTick = largura >= 30 ? 60 : 100; + final Random random = new Random(); + + @SuppressWarnings("deprecation") + public void run() { + if (ended) { + cancel(); + if (p != null && p.isOnline()) { + p.sendMessage(StringUtils.ARENA_CREATED); + } + cuboid.clear(); + return; + } + + if (blockAtual >= max) { + ended = true; + return; + } + + for (int i = 0; i < blocksPerTick; i++) { + try { + Location location = cuboid.get(blockAtual + i); + + if (location.getBlockY() == altura) { + WorldEditAPI.setAsyncBlock(location.getWorld(), location, random.nextBoolean() ? Material.BEDROCK.getId() : Material.GLOWSTONE.getId()); + } else { + WorldEditAPI.setAsyncBlock(location.getWorld(), location, Material.BEDROCK.getId()); + } + } catch (IndexOutOfBoundsException | NullPointerException e) { + e.printStackTrace(); + } + } + this.blockAtual+=55; + } + }.runTaskTimer(BukkitMain.getInstance(), 1L, 1L); + + ponto_baixo = loc.clone().add(largura - 1, 0, largura - 1); + Location PA = loc.clone().subtract(largura - 1, 0, largura - 1); + PA.add(0, altura - 1, 0); + ponto_alto = PA; + } + + @SuppressWarnings("deprecation") + public void limparArena(Player p) { + if (ponto_alto == null) { + p.sendMessage(StringUtils.ARENA_NOT_CLEANED); + return; + } + + for (Location location : getLocationsFromTwoPoints(ponto_baixo, ponto_alto)) { + WorldEditAPI.setAsyncBlock(location.getWorld(), location, Material.AIR.getId()); + } + + p.sendMessage(StringUtils.ARENA_CLEANED); + } + + public List getLocationsFromTwoPoints(Location location1, Location location2) { + List locations = new ArrayList<>(); + int topBlockX = (Math.max(location1.getBlockX(), location2.getBlockX())); + int bottomBlockX = (Math.min(location1.getBlockX(), location2.getBlockX())); + int topBlockY = (Math.max(location1.getBlockY(), location2.getBlockY())); + int bottomBlockY = (Math.min(location1.getBlockY(), location2.getBlockY())); + int topBlockZ = (Math.max(location1.getBlockZ(), location2.getBlockZ())); + int bottomBlockZ = (Math.min(location1.getBlockZ(), location2.getBlockZ())); + for (int x = bottomBlockX; x <= topBlockX; x++) + for (int z = bottomBlockZ; z <= topBlockZ; z++) + for (int y = bottomBlockY; y <= topBlockY; y++) + locations.add(new Location(location1.getWorld(), x, y, z)); + + return locations; + } + + public List getBlocks(Location location1, Location location2) { + List blocks = new ArrayList<>(); + for (Location loc : getLocationsFromTwoPoints(location1, location2)) { + Block b = loc.getBlock(); + if (!b.getType().equals(Material.AIR)) + blocks.add(b); + } + return blocks; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.java new file mode 100644 index 0000000..b78d2b9 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.java @@ -0,0 +1,16 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.game; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import lombok.Getter; + +public class GameInvincibilityEndEvent extends Event { + + @Getter + public static final HandlerList handlerList = new HandlerList(); + + public HandlerList getHandlers() { + return handlerList; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.java new file mode 100644 index 0000000..5bea9f6 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.java @@ -0,0 +1,33 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.game; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; + +import lombok.Getter; + +public class GameStageChangeEvent extends Event { + + @Getter + public static final HandlerList handlerList = new HandlerList(); + + private GameStages lastStage, newStage; + + public GameStageChangeEvent(GameStages lastStage, GameStages newStage) { + this.lastStage = lastStage; + this.newStage = newStage; + } + + public GameStages getNewStage() { + return newStage; + } + + public GameStages getLastStage() { + return lastStage; + } + + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.java new file mode 100644 index 0000000..a1c5771 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.java @@ -0,0 +1,16 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.game; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import lombok.Getter; + +public class GameStartedEvent extends Event { + + @Getter + public static final HandlerList handlerList = new HandlerList(); + + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.java new file mode 100644 index 0000000..947623f --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.java @@ -0,0 +1,63 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.game; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; + +import lombok.Getter; + +public class GameTimerEvent extends Event { + + @Getter + public static final HandlerList handlerList = new HandlerList(); + + @Getter + private int time; + + @Getter + private boolean changedTime = false; + + public void setTime(int time) { + this.time = time; + changedTime = true; + } + + public GameTimerEvent(final int time) { + this.time = time; + } + + public HandlerList getHandlers() { + return handlerList; + } + + public void checkMessage() { + if (((time >= 10 ? 1 : 0) & (time % 60 == 0 ? 1 : 0)) != 0) { + handleNotify(Sound.NOTE_PLING, getMensagem(time)); + } else if (time == 30 || time == 15 || time == 10 || time <= 5) { + handleNotify(Sound.NOTE_PLING, getMensagem(time)); + } + } + + private String getMensagem(int tempo) { + if (HardcoreGamesMain.getGameManager().isPreGame()) { + return StringUtils.GAME_START_IN.replace("%tempo%", DateUtils.formatSecondsScore(tempo)); + } else if (HardcoreGamesMain.getGameManager().isInvencibilidade()) { + return StringUtils.INVENCIBILITY_END_IN.replace("%tempo%", DateUtils.formatSecondsScore(tempo)); + } + return ""; + } + + private void handleNotify(Sound sound, String message) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.playSound(player.getLocation(), sound, 1.0F, 1.0F); + } + + Bukkit.broadcastMessage(message); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.java new file mode 100644 index 0000000..d4fa7dc --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.java @@ -0,0 +1,23 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.player; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class PlayerCompassEvent extends PlayerEvent { + + private CompassAction action; + private Player target; + + public PlayerCompassEvent(Player player, CompassAction action) { + super(player); + this.action = action; + } + + public enum CompassAction { + LEFT, RIGHT; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.java new file mode 100644 index 0000000..53b81e7 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.java @@ -0,0 +1,25 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.player; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerCancellableEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter +public class PlayerDamagePlayerEvent extends PlayerCancellableEvent { + + private Player damaged; + + @Setter + private double damage; + + @Setter + private boolean cancelled; + + public PlayerDamagePlayerEvent(Player damager, Player damaged, double damage) { + super(damager); + this.damaged = damaged; + this.damage = damage; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.java new file mode 100644 index 0000000..ef7ca38 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.player; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; + +public class PlayerRegisterKitEvent extends PlayerEvent { + + @Getter + private String kitName; + + public PlayerRegisterKitEvent(final Player player, final String kitName) { + super(player); + this.kitName = kitName; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.java new file mode 100644 index 0000000..3c6cab4 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.java @@ -0,0 +1,23 @@ +package com.br.guilhermematthew.nowly.hardcoregames.events.player; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class PlayerSpectateEvent extends PlayerEvent { + + private SpectateAction action; + private Player target; + + public PlayerSpectateEvent(Player player, SpectateAction action) { + super(player); + this.action = action; + } + + public enum SpectateAction { + SAIU, ENTROU; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.java new file mode 100644 index 0000000..a71dcfe --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.hardcoregames.game; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.base.GameType; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class GameManager { + + private GameStages stage; + private GameType gameType; + + public GameManager() { + this.stage = GameStages.LOADING; + } + + public boolean isLoading() { + return stage.equals(GameStages.LOADING); + } + + public boolean isPreGame() { + return stage.equals(GameStages.WAITING); + } + + public boolean isInvencibilidade() { + return stage.equals(GameStages.INVINCIBILITY); + } + + public boolean isGaming() { + return stage.equals(GameStages.PLAYING); + } + + public boolean isEnd() { + return stage.equals(GameStages.END); + } + + public void setGameType(GameType gameType) { + this.gameType = gameType; + } + + public boolean canLogin() { + return !isLoading() && !isEnd(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.java new file mode 100644 index 0000000..4b20ce9 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.java @@ -0,0 +1,240 @@ +package com.br.guilhermematthew.nowly.hardcoregames.game.types; + +import java.util.List; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.base.GameType; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStartedEvent; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.EndListener; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.PluginManager; +import org.bukkit.potion.PotionEffect; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.InvincibilityListener; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.SpectatorListener; + +public class AutomaticEventType extends GameType { + + @Override + public void initialize() { + registerListeners(); + + KitManager.disableKits("Achilles", "Barbarian", "Boxer", "Checkpoint", "Demoman", "Fisherman", "Launcher", + "Monk", "Phantom", "Stomper", "Tank", "Thor", "Urgal", "Viking", "Madman", "Digger", "HotPotato"); + + HardcoreGamesMain.console("GameType (AutomaticEventType) has been loaded."); + + new BukkitRunnable() { + + int seconds = 400; + + @Override + public void run() { + seconds--; + + if (!isPreGame()) { + cancel(); + return; + } + + if (seconds == 0) { + cancel(); + + if (GamerManager.getAliveGamers().size() < 20) { + HardcoreGamesMain.console("AutomaticEventType fechando por conta do Timer (Poucos jogadores)."); + callEnd(); + } + } + } + }.runTaskTimer(HardcoreGamesMain.getInstance(), 20, 20); + } + + @SuppressWarnings("deprecation") + @Override + public void start() { + HardcoreGamesMain.getTimerManager().updateTime(60); + HardcoreGamesMain.getGameManager().setStage(GameStages.INVINCIBILITY); + + PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + + pluginManager.callEvent(new GameStageChangeEvent(GameStages.WAITING, GameStages.INVINCIBILITY)); + pluginManager.registerEvents(new InvincibilityListener(), HardcoreGamesMain.getInstance()); + + List kits = KitManager.getAllKitsAvailables(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + ItemStack capacete = itemBuilder.type(Material.IRON_HELMET).name("§fCapacete de Ferro").build(), + peitoral = itemBuilder.type(Material.IRON_CHESTPLATE).name("§fPeitoral de Ferro").build(), + calça = itemBuilder.type(Material.IRON_LEGGINGS).name("§fCalça de Ferro").build(), + bota = itemBuilder.type(Material.IRON_BOOTS).name("§fBota de Ferro").build(); + + for (Player player : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer == null) + continue; + + player.getPlayer().setItemOnCursor(new ItemStack(0)); + + if (player.getOpenInventory() instanceof PlayerInventory) + player.closeInventory(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + playerInventory.setHelmet(capacete); + playerInventory.setChestplate(peitoral); + playerInventory.setLeggings(calça); + playerInventory.setBoots(bota); + + for (PotionEffect pe : player.getActivePotionEffects()) { + player.removePotionEffect(pe.getType()); + } + + if (player.getGameMode() != GameMode.SURVIVAL) player.setGameMode(GameMode.SURVIVAL); + + player.setAllowFlight(false); + player.setFlying(false); + + playerInventory.setItem(0, itemBuilder.type(Material.DIAMOND_SWORD).enchantment(Enchantment.DAMAGE_ALL).build()); + playerInventory.setItem(3, itemBuilder.type(Material.LAVA_BUCKET).build()); + playerInventory.setItem(4, itemBuilder.type(Material.WOOD).amount(64).build()); + playerInventory.setItem(7, itemBuilder.type(Material.WATER_BUCKET).build()); + playerInventory.setItem(8, itemBuilder.type(Material.COMPASS).name("§6Bússola").build()); + + KitManager.give(player, gamer.getKit1(), true); + KitManager.give(player, gamer.getKit2(), false); + + playerInventory.addItem(itemBuilder.type(Material.LAVA_BUCKET).build()); + playerInventory.addItem(itemBuilder.type(Material.LAVA_BUCKET).build()); + playerInventory.addItem(itemBuilder.type(Material.DIAMOND_SWORD).build()); + + playerInventory.setItem(18, capacete); + playerInventory.setItem(19, peitoral); + playerInventory.setItem(20, calça); + playerInventory.setItem(21, bota); + playerInventory.setItem(22, itemBuilder.type(Material.BOWL).amount(64).build()); + playerInventory.setItem(23, itemBuilder.type(Material.INK_SACK).durability(3).amount(64).build()); + playerInventory.setItem(24, itemBuilder.type(Material.INK_SACK).durability(3).amount(64).build()); + playerInventory.setItem(25, itemBuilder.type(Material.LOG).amount(32).build()); + playerInventory.setItem(26, itemBuilder.type(Material.STONE_AXE).build()); + + playerInventory.setItem(9, capacete); + playerInventory.setItem(10, peitoral); + playerInventory.setItem(11, calça); + playerInventory.setItem(12, bota); + playerInventory.setItem(13, itemBuilder.type(Material.BOWL).amount(64).build()); + playerInventory.setItem(14, itemBuilder.type(Material.INK_SACK).durability(3).amount(64).build()); + playerInventory.setItem(15, itemBuilder.type(Material.INK_SACK).durability(3).amount(64).build()); + playerInventory.setItem(16, itemBuilder.type(Material.INK_SACK).durability(3).amount(64).build()); + playerInventory.setItem(17, itemBuilder.type(Material.STONE_PICKAXE).build()); + + HardcoreGamesScoreboard.createScoreboard(gamer); + } + + Bukkit.broadcastMessage(StringUtils.THE_GAME_HAS_STARTED); + + World world = Bukkit.getWorlds().get(0); + world.setTime(0); + world.setStorm(false); + world.setThundering(false); + + world.playSound(world.getSpawnLocation(), Sound.AMBIENCE_THUNDER, 4.0F, 4.0F); + + pluginManager.registerEvents(new SpectatorListener(), HardcoreGamesMain.getInstance()); + pluginManager.callEvent(new GameStartedEvent()); + + // recyclable + kits.clear(); + } + + @Override + public void checkWin() { + if (isEnd() || isPreGame()) + return; + + if (Bukkit.getOnlinePlayers().size() == 0) { + callEnd(); + return; + } + + List aliveGamers = GamerManager.getAliveGamers(); + + if (aliveGamers.size() == 0) { + callEnd(); + return; + } + + if (aliveGamers.size() != 1) + return; + + Player winner = aliveGamers.get(0); + if (winner == null) { + callEnd(); + return; + } + + EndListener.winner = winner; + + callEnd(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(winner.getUniqueId()); + + final int xp = 250, coins = 500; + + winner.sendMessage(BukkitMessages.KILL_MESSAGE_XP.replace("%quantia%", "250")); + winner.sendMessage(BukkitMessages.KILL_MESSAGE_COINS.replace("%quantia%", "500")); + + bukkitPlayer.addXP(xp); + bukkitPlayer.add(DataType.COINS, coins); + bukkitPlayer.add(DataType.HG_EVENT_WINS); + bukkitPlayer.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + + aliveGamers.clear(); + } + + @Override + public void registerListeners() { + + } + + @Override + public void choiceWinner() { + UUID ganhador = getMVP(); + + for (Player player : GamerManager.getAliveGamers()) { + if (player.getUniqueId() != ganhador) { + setEspectador(player, true); + } + } + + HardcoreGamesMain.runLater(this::checkWin, 20); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.java new file mode 100644 index 0000000..13afc36 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.java @@ -0,0 +1,189 @@ +package com.br.guilhermematthew.nowly.hardcoregames.game.types; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.base.GameType; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStartedEvent; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.EndListener; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.SpectatorListener; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.PluginManager; +import org.bukkit.potion.PotionEffect; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.InvincibilityListener; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ClanType extends GameType { + + private String clanName1 = ""; + private String clanName2 = ""; + + private List participants; + + @Override + public void initialize() { + this.participants = new ArrayList<>(); + + registerListeners(); + + HardcoreGamesMain.console("GameType (ClanType) has been loaded."); + } + + @SuppressWarnings("deprecation") + @Override + public void start() { + PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + + pluginManager.callEvent(new GameStageChangeEvent(GameStages.WAITING, GameStages.INVINCIBILITY)); + + HardcoreGamesMain.getTimerManager().updateTime(120); + HardcoreGamesMain.getGameManager().setStage(GameStages.INVINCIBILITY); + + pluginManager.registerEvents(new InvincibilityListener(), HardcoreGamesMain.getInstance()); + + List kits = KitManager.getAllKitsAvailables(); + + ItemStack compass = new ItemBuilder().type(Material.COMPASS).name("§6Bússola").build(); + + for (Player player : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer == null) + continue; + + player.getPlayer().setItemOnCursor(new ItemStack(0)); + + if (player.getOpenInventory() instanceof PlayerInventory) { + player.closeInventory(); + } + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + for (PotionEffect pe : player.getActivePotionEffects()) { + player.removePotionEffect(pe.getType()); + } + + if (player.getGameMode() != GameMode.SURVIVAL) { + player.setGameMode(GameMode.SURVIVAL); + } + + player.setAllowFlight(false); + player.setFlying(false); + + KitManager.give(player, gamer.getKit1(), true); + KitManager.give(player, gamer.getKit2(), false); + + playerInventory.addItem(compass); + + HardcoreGamesScoreboard.createScoreboard(gamer); + } + + Bukkit.broadcastMessage(StringUtils.THE_GAME_HAS_STARTED); + + World world = Bukkit.getWorlds().get(0); + world.setTime(0); + world.setStorm(false); + world.setThundering(false); + + world.playSound(world.getSpawnLocation(), Sound.AMBIENCE_THUNDER, 4.0F, 4.0F); + + pluginManager.registerEvents(new SpectatorListener(), HardcoreGamesMain.getInstance()); + pluginManager.callEvent(new GameStartedEvent()); + + kits.clear(); + } + + @Override + public void checkWin() { + if (isEnd() || isPreGame()) + return; + + if (Bukkit.getOnlinePlayers().size() == 0) { + callEnd(); + return; + } + + List aliveGamers = GamerManager.getAliveGamers(); + + if (aliveGamers.size() == 0) { + callEnd(); + return; + } + + if (aliveGamers.size() != 1) + return; + + Player winner = aliveGamers.get(0); + if (winner == null) { + callEnd(); + return; + } + + EndListener.winner = winner; + + callEnd(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(winner.getUniqueId()); + + final int xp = 100, coins = 200; + + winner.sendMessage(BukkitMessages.KILL_MESSAGE_XP.replace("%quantia%", "100")); + winner.sendMessage(BukkitMessages.KILL_MESSAGE_COINS.replace("%quantia%", "200")); + + bukkitPlayer.addXP(xp); + bukkitPlayer.add(DataType.COINS, coins); + bukkitPlayer.add(DataType.HG_WINS); + bukkitPlayer.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + + aliveGamers.clear(); + } + + @Override + public void registerListeners() { + + } + + @Override + public void choiceWinner() { + UUID ganhador = getMVP(); + + for (Player player : GamerManager.getAliveGamers()) { + if (player.getUniqueId() != ganhador) { + setEspectador(player, true); + } + } + + HardcoreGamesMain.runLater(this::checkWin, 20); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.java new file mode 100644 index 0000000..f147152 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.java @@ -0,0 +1,174 @@ +package com.br.guilhermematthew.nowly.hardcoregames.game.types; + +import java.util.List; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.base.GameType; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStartedEvent; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.EndListener; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.SpectatorListener; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.PluginManager; +import org.bukkit.potion.PotionEffect; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.listeners.InvincibilityListener; + +public class NormalType extends GameType { + + @Override + public void initialize() { + registerListeners(); + + HardcoreGamesMain.console("GameType (NormalType) has been loaded."); + } + + @SuppressWarnings("deprecation") + @Override + public void start() { + PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + + pluginManager.callEvent(new GameStageChangeEvent(GameStages.WAITING, GameStages.INVINCIBILITY)); + + HardcoreGamesMain.getGameManager().setStage(GameStages.INVINCIBILITY); + HardcoreGamesMain.getTimerManager().updateTime(120); + + pluginManager.registerEvents(new InvincibilityListener(), HardcoreGamesMain.getInstance()); + + List kits = KitManager.getAllKitsAvailables(); + + ItemStack compass = new ItemBuilder().type(Material.COMPASS).name("§6Bússola").build(); + + for (Player player : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer == null) continue; + + player.getPlayer().setItemOnCursor(new ItemStack(0)); + + if (player.getOpenInventory() instanceof PlayerInventory) { + player.closeInventory(); + } + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + for (PotionEffect pe : player.getActivePotionEffects()) { + player.removePotionEffect(pe.getType()); + } + + if (player.getGameMode() != GameMode.SURVIVAL) { + player.setGameMode(GameMode.SURVIVAL); + } + + player.setAllowFlight(false); + player.setFlying(false); + + KitManager.give(player, gamer.getKit1(), true); + KitManager.give(player, gamer.getKit2(), false); + + playerInventory.addItem(compass); + + HardcoreGamesScoreboard.createScoreboard(gamer); + } + + Bukkit.broadcastMessage(StringUtils.THE_GAME_HAS_STARTED); + + World world = Bukkit.getWorlds().get(0); + world.setTime(0); + world.setStorm(false); + world.setThundering(false); + + world.playSound(world.getSpawnLocation(), Sound.AMBIENCE_THUNDER, 4.0F, 4.0F); + + pluginManager.registerEvents(new SpectatorListener(), HardcoreGamesMain.getInstance()); + pluginManager.callEvent(new GameStartedEvent()); + + kits.clear(); + } + + @Override + public void checkWin() { + if (isEnd() || isPreGame()) return; + + if (Bukkit.getOnlinePlayers().size() == 0) { + callEnd(); + return; + } + + List aliveGamers = GamerManager.getAliveGamers(); + + if (aliveGamers.size() == 0) { + callEnd(); + return; + } + + if (aliveGamers.size() != 1) return; + + Player winner = aliveGamers.get(0); + + if (winner == null) { + callEnd(); + return; + } + + EndListener.winner = winner; + + callEnd(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(winner.getUniqueId()); + + final int xp = 100, coins = 200; + + winner.sendMessage(BukkitMessages.KILL_MESSAGE_XP.replace("%quantia%", "100")); + winner.sendMessage(BukkitMessages.KILL_MESSAGE_COINS.replace("%quantia%", "200")); + + bukkitPlayer.addXP(xp); + bukkitPlayer.add(DataType.COINS, coins); + bukkitPlayer.add(DataType.HG_WINS); + bukkitPlayer.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + + aliveGamers.clear(); + } + + @Override + public void registerListeners() { + + } + + @Override + public void choiceWinner() { + UUID ganhador = getMVP(); + + for (Player player : GamerManager.getAliveGamers()) { + if (player.getUniqueId() != ganhador) { + setEspectador(player, true); + } + } + + HardcoreGamesMain.runLater(this::checkWin, 20); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.java new file mode 100644 index 0000000..2ab1495 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.java @@ -0,0 +1,108 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; + +public class BorderListener implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + GameStages stage = HardcoreGamesMain.getGameManager().getStage(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (stage == GameStages.WAITING) { + if (isNotInBoard(onlines.getLocation(), 120)) { + onlines.teleport(HardcoreGamesUtility.getRandomLocation(40)); + } + } else if (stage == GameStages.INVINCIBILITY) { + handleBoardInvincibility(onlines); + } else { + handleBoard(onlines); + } + } + + stage = null; + } + + private void handleBoardInvincibility(Player player) { + if (isNotInBoard(player.getLocation(), 401)) { + + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer != null) { + + if (gamer.isPlaying()) { + player.sendMessage("§aVocê passou da borda e automaticamente foi desclassificado da partida!"); + + player.teleport(HardcoreGamesUtility.getRandomLocation(160)); + + HardcoreGamesMain.getGameManager().getGameType().setEspectador(player); + + if (!HardcoreGamesUtility.availableToSpec(player)) { + BukkitServerAPI.redirectPlayer(player, "LobbyHG", true); + } + } else { + player.teleport(HardcoreGamesUtility.getRandomLocation(160)); + } + + gamer = null; + } else { + player.kickPlayer("WTF? #1"); + } + } + } + + private void handleBoard(Player player) { + if (isNotInBoard(player.getLocation(), 400)) { + if (inLauncher(player)) return; + + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer != null) { + if (gamer.isPlaying()) { + player.setFireTicks(100); + player.damage(3.0D); + player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20, 2)); + } else { + player.teleport(HardcoreGamesUtility.getRandomLocation(160)); + } + + gamer = null; + } else { + player.kickPlayer("WTF? #2"); + } + } + } + + private boolean inLauncher(final Player player) { + if (!player.hasMetadata("nofall")) return false; + + Long time = player.getMetadata("nofall.time").get(0).asLong(); + if (time + 6200 > System.currentTimeMillis()) { + return true; + } + return false; + } + + private boolean isNotInBoard(final Location loc, final int size) { + return ((loc.getBlockX() > size) || (loc.getBlockX() < -size) + || (loc.getBlockZ() > size) || (loc.getBlockY() > 128) || (loc.getBlockZ() < -size)); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.java new file mode 100644 index 0000000..fbace94 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.java @@ -0,0 +1,141 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.weather.WeatherChangeEvent; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.PlayerBukkitQueue; +import com.br.guilhermematthew.nowly.commons.bukkit.queue.QueueType; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; + +public class EndListener implements Listener { + + public static Player winner = null; + + @EventHandler + public void onTimer(GameTimerEvent event) { + if (event.getTime() == 0) { + destroy(); + return; + } + + if (event.getTime() < 0) { + event.setTime(15); + } + + if (winner == null || !winner.isOnline()) { + destroy(); + } else { + Bukkit.broadcastMessage(StringUtils.PLAYER_WIN.replace("%nick%", winner.getName())); + + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(0.0D, 0.0D, CommonsConst.RANDOM.nextInt(5) + 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(CommonsConst.RANDOM.nextInt(5) + 5, 0.0D, 0.0D).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(CommonsConst.RANDOM.nextInt(5) + 5, 0.0D, CommonsConst.RANDOM.nextInt(5) + 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(-CommonsConst.RANDOM.nextInt(5) - 5, 0.0D, 0.0D).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(0.0D, 0.0D, -CommonsConst.RANDOM.nextInt(5) - 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(-CommonsConst.RANDOM.nextInt(5) - 5, 0.0D, -CommonsConst.RANDOM.nextInt(5) - 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(-CommonsConst.RANDOM.nextInt(5) - 5, 0.0D, CommonsConst.RANDOM.nextInt(5) + 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + HardcoreGamesUtility.spawnRandomFirework(Bukkit.getServer().getWorlds().get(0).getHighestBlockAt(winner.getLocation().add(CommonsConst.RANDOM.nextInt(5) + 5, 0.0D, -CommonsConst.RANDOM.nextInt(5) - 5).add(0.0D, 5.0D, 0.0D)).getLocation()); + } + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPickup(PlayerPickupItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBreak(BlockBreakEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onExplosion(ExplosionPrimeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onIgnite(BlockIgniteEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void craftItem(CraftItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + private void destroy() { + HandlerList.unregisterAll(this); + + HardcoreGamesMain.console("Removing Listener from EndListener"); + + PlayerBukkitQueue queue = new PlayerBukkitQueue(10, true, QueueType.CONNECT); + queue.setDestroyOnFinish(true); + queue.setStopOnFinish(true); + + for (Player player : Bukkit.getOnlinePlayers()) { + queue.addToQueue(player, "LobbyHardcoreGames"); + } + + queue.start(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.java new file mode 100644 index 0000000..4d910c2 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.java @@ -0,0 +1,422 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import java.util.Random; + +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.player.PlayerRespawnEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.bossbar.BossBarAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.ability.register.Gladiator; +import com.br.guilhermematthew.nowly.hardcoregames.ability.utility.GladiatorFight; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types.MiniFeast; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; + +public class GameListener implements Listener { + + private final Random random = new Random(); + + @EventHandler + public void onTimer(GameTimerEvent event) { + if (event.getTime() > 5 && event.getTime() % 240 == 0) { + if (HardcoreGamesOptions.MINIFEAST) { + MiniFeast.create(); + } + } + + if (event.getTime() == HardcoreGamesOptions.FEAST_SPAWN) { + if (HardcoreGamesOptions.FEAST) StructuresManager.getFeast().createFeast(StructuresManager.getValidLocation(true)); + } + + if (event.getTime() == 35 * 60 || event.getTime() == 36 * 60 || event.getTime() == 37 * 60 + || event.getTime() == 38 * 60 || event.getTime() == 39 * 60) { + + Bukkit.broadcastMessage(StringUtils.FINAL_ARENA_IN.replace("%tempo%", + DateUtils.formatSeconds(((HardcoreGamesOptions.FINAL_BATTLE_SPAWN) - event.getTime())))); + + } else if (event.getTime() == HardcoreGamesOptions.FINAL_BATTLE_SPAWN) { + HardcoreGamesOptions.MINIFEAST = false; + StructuresManager.getFinalBattle().create(); + } + + if (event.getTime() == 50 * 60 || event.getTime() == 55 * 60 || event.getTime() == 57 * 60 + || event.getTime() == 58 * 60 || event.getTime() == 59 * 60) { + Bukkit.broadcastMessage(StringUtils.GAME_END_IN.replace("%tempo%", + DateUtils.formatSeconds((HardcoreGamesOptions.MAX_TIME - event.getTime())))); + } else if (event.getTime() == HardcoreGamesOptions.MAX_TIME) { + HardcoreGamesMain.getGameManager().getGameType().choiceWinner(); + } + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + + if (GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + player.setSaturation(5f); + } else { + event.setCancelled(true); + } + + player = null; + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + event.getDrops().clear(); + + Player morreu = event.getEntity(), + matou = morreu.getKiller(); + + Location loc = morreu.getLocation(); + + if (Gladiator.inGlad(morreu)) { + GladiatorFight glad = Gladiator.getGladiatorFight(morreu); + + loc = glad.getBackForPlayer(morreu); + + glad.cancelGlad(); + + glad = null; + } + + PlayerAPI.dropItems(morreu, loc); + + Gamer gamerDied = GamerManager.getGamer(morreu.getUniqueId()); + if (!availableToRespawn(morreu)) { + gamerDied.setEliminado(true); + gamerDied.setPlaying(false); + } + + final int jogadoresRestantes = GamerManager.getAliveGamers().size(); + + if (matou != null && matou instanceof Player) { + Gamer gamerKill = GamerManager.getGamer(matou.getUniqueId()); + gamerKill.addKill(); + + Bukkit.broadcastMessage(StringUtils.PLAYER_DEATH_FOR_PLAYER.replace("%matou%", matou.getName()) + .replace("%matouKit%", gamerKill.getKits()).replace("%morreu%", morreu.getName()) + .replace("%morreuKit%", gamerDied.getKits()).replace("%restantes%", "" + jogadoresRestantes) + .replace("%item%", getItemInHand(matou.getItemInHand().getType()))); + + HardcoreGamesScoreboard.getScoreBoardCommon().updateKills(matou, gamerKill.getKills()); + + gamerKill = null; + } else { + Bukkit.broadcastMessage(StringUtils.PLAYER_DEATH.replace("%morreu%", morreu.getName()) + .replace("%kit%", gamerDied.getKit1()).replace("%restantes%", "" + jogadoresRestantes) + .replace("%causa%", getCausa(morreu.getLastDamageCause().getCause()))); + } + + handleStats(matou, morreu); + + gamerDied = null; + morreu = null; + matou = null; + loc = null; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onEntitySpawn(CreatureSpawnEvent event) { + if (event.getEntityType() == EntityType.GHAST || event.getEntityType() == EntityType.PIG_ZOMBIE) { + event.setCancelled(true); + return; + } + + if (event.getSpawnReason() != SpawnReason.NATURAL) + return; + + if (random.nextInt(5) > 2) { + event.setCancelled(true); + } + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + event.setRespawnLocation(HardcoreGamesUtility.getRandomLocation(160)); + } + + @EventHandler + public void onAutoRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + + if (availableToRespawn(player)) { + HardcoreGamesMain.getGameManager().getGameType().setGamer(player); + } else { + HardcoreGamesMain.getGameManager().getGameType().setEspectador(player); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + HardcoreGamesMain.runAsync(() -> { + bukkitPlayer.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + }); + + if (!HardcoreGamesUtility.availableToSpec(player)) { + BukkitServerAPI.redirectPlayer(player, "LobbyHardcoreGames", true); + } + } + + player = null; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) + public void onHit(PlayerDamagePlayerEvent event) { + val gamer = GamerManager.getGamer(event.getDamaged()); + + if(HardcoreGamesOptions.DOUBLE_KIT) { + BossBarAPI.send(event.getPlayer(), + event.getDamaged().getName() + " - " + gamer.getKit1() + " - " + gamer.getKit2(), 3); + } else { + BossBarAPI.send(event.getPlayer(), + event.getDamaged().getName() + " - " + gamer.getKit1(), 3); + } + } + + @EventHandler + public void onEnderPearl(ProjectileLaunchEvent event) { + if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) { + int tempo = HardcoreGamesMain.getTimerManager().getTime().get(); + + if (tempo > (39 * 60) + 35 && tempo < (40 * 60) + 5) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + if (HardcoreGamesMain.getTimerManager().getTime().get() > (39 * 60)) { + event.setCancelled(true); + } + } + + private boolean availableToRespawn(final Player player) { + if (BukkitMain.getServerType() == ServerType.EVENTO || BukkitMain.getServerType() == ServerType.CHAMPIONS) { + return false; + } else { + return player.hasPermission("hardcoregames.respawn") + && HardcoreGamesMain.getTimerManager().getTime().get() <= 300; + } + } + + private static String getItemInHand(final Material material) { + String causa = "o Punho"; + + switch (material) { + case WOOD_SWORD: + causa = "uma Espada de Madeira"; + break; + case STONE_SWORD: + causa = "uma Espada de Pedra"; + break; + case GOLD_SWORD: + causa = "uma Espada de Ouro"; + break; + case IRON_SWORD: + causa = "uma Espada de Ferro"; + break; + case DIAMOND_SWORD: + causa = "uma Espada de Diamante"; + break; + case WOOD_PICKAXE: + causa = "uma Picareta de Madeira"; + break; + case STONE_PICKAXE: + causa = "uma Picareta de Pedra"; + break; + case GOLD_PICKAXE: + causa = "uma Picareta de Ouro"; + break; + case IRON_PICKAXE: + causa = "uma Picareta de Ferro"; + break; + case DIAMOND_PICKAXE: + causa = "uma Picareta de Diamante"; + break; + case WOOD_AXE: + causa = "um Machado de Madeira"; + break; + case STONE_AXE: + causa = "um Machado de Pedra"; + break; + case GOLD_AXE: + causa = "um Machado de Ouro"; + break; + case IRON_AXE: + causa = "um Machado de Ferro"; + break; + case DIAMOND_AXE: + causa = "um Machado de Diamante"; + break; + case COMPASS: + causa = "uma Bussola"; + break; + case MUSHROOM_SOUP: + causa = "uma Sopa"; + break; + case STICK: + causa = "um Graveto"; + break; + default: + break; + } + return causa; + } + + private String getCausa(DamageCause deathCause) { + String cause = "por uma causa desconhecida"; + + switch (deathCause) { + case ENTITY_ATTACK: + cause = "atacado por um monstro"; + break; + case CUSTOM: + cause = "de uma forma não conhecida"; + break; + case BLOCK_EXPLOSION: + cause = "explodido em mil pedaços"; + break; + case ENTITY_EXPLOSION: + cause = "explodido por um monstro"; + break; + case CONTACT: + cause = "espetado por um cacto"; + break; + case FALL: + cause = "de queda"; + break; + case FALLING_BLOCK: + cause = "stompado por um bloco"; + break; + case FIRE_TICK: + cause = "pegando fogo"; + break; + case FIRE: + cause = "pegando fogo"; + break; + case LAVA: + cause = "nadando na lava"; + break; + case LIGHTNING: + cause = "atingido por um raio"; + break; + case MAGIC: + cause = "atingido por uma magia"; + break; + case MELTING: + cause = "atingido por um boneco de neve"; + break; + case POISON: + cause = "envenenado"; + break; + case PROJECTILE: + cause = "atingido por um projétil"; + break; + case STARVATION: + cause = "de fome"; + break; + case SUFFOCATION: + cause = "sufocado"; + break; + case SUICIDE: + cause = "se suicidando"; + break; + case THORNS: + cause = "encostando em alguns espinhos"; + break; + case VOID: + cause = "pelo void"; + break; + case WITHER: + cause = "pelo efeito do whiter"; + break; + case DROWNING: + cause = "afogado"; + break; + default: + break; + } + + return cause; + } + + public static void handleStats(final Player killer, final Player died) { + BukkitPlayer bukkitPlayerDied = BukkitMain.getBukkitPlayer(died.getUniqueId()); + + died.sendMessage(BukkitMessages.DEATH_MESSAGE_XP.replace("%quantia%", "2")); + died.sendMessage(BukkitMessages.DEATH_MESSAGE_COINS.replace("%quantia%", "10")); + + bukkitPlayerDied.add(BukkitMain.getServerType() == ServerType.HARDCORE_GAMES ? DataType.HG_DEATHS + : DataType.HG_EVENT_DEATHS); + bukkitPlayerDied.remove(DataType.COINS, 10); + bukkitPlayerDied.removeXP(2); + + HardcoreGamesMain.runAsync(() -> { + bukkitPlayerDied.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + }); + + if (killer == null) { + return; + } + + BukkitPlayer bukkitPlayerKiller = BukkitMain.getBukkitPlayer(killer.getUniqueId()); + + final int xp = PlayerAPI.getXPKill(killer, bukkitPlayerKiller.getLong(DataType.DOUBLEXP_TIME)), + coins = PlayerAPI.getCoinsKill(killer, bukkitPlayerKiller.getLong(DataType.DOUBLECOINS_TIME)); + + bukkitPlayerKiller.add(DataType.COINS, coins); + bukkitPlayerKiller.addXP(xp); + bukkitPlayerKiller.add( + BukkitMain.getServerType() == ServerType.HARDCORE_GAMES ? DataType.HG_KILLS : DataType.HG_EVENT_KILLS); + HardcoreGamesMain.runAsync(() -> { + bukkitPlayerKiller.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.HARDCORE_GAMES); + }); + } + + @EventHandler + public void onGameEnd(GameStageChangeEvent event) { + if (event.getNewStage() == GameStages.END) { + HardcoreGamesMain.console("Removing listeners from GameListener"); + + HandlerList.unregisterAll(this); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.java new file mode 100644 index 0000000..2237845 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.java @@ -0,0 +1,431 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import java.util.ArrayList; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerCompassEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.combatlog.CombatLogManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.menu.AliveGamers; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerAdminChangeEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerAdminChangeEvent.AdminChangeType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeScoreboardEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeScoreboardEvent.ScoreboardChangeType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStatusUpdateEvent; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; + +public class GeneralListeners implements Listener { + + public static int MEMBERS_SLOTS = 80; + + @EventHandler(priority = EventPriority.MONITOR) + public void onLogin(PlayerLoginEvent event) { + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) return; + + Player player = event.getPlayer(); + + if (!HardcoreGamesMain.getGameManager().canLogin()) { + event.disallow(Result.KICK_OTHER, "§cVocê não pode entrar na sala agora porque ela está " + + (HardcoreGamesMain.getGameManager().isLoading() ? "carregando." : "sendo encerrada.")); + } else { + if (Bukkit.getOnlinePlayers().size() >= MEMBERS_SLOTS) { + if (!event.getPlayer().hasPermission("commons.entrar")) { + event.disallow(Result.KICK_OTHER, BukkitMessages.ACABOU_OS_SLOTS_PARA_MEMBROS); + } else { + event.allow(); + + kickRandomGamer(); + } + } + + if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) { + if (!GamerManager.containsGamer(player.getUniqueId())) { + + if (HardcoreGamesMain.getGameManager().isPreGame()) { + GamerManager.addGamer(player.getUniqueId()); + } else { + if (!player.hasPermission("commons.entrar")) { + event.disallow(Result.KICK_OTHER, StringUtils.GAME_HAS_STARTED); + } else { + GamerManager.addGamer(player.getUniqueId()); + event.allow(); + } + } + } else { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer.isRelogar()) { + event.allow(); + } else { + if (gamer.isEliminado()) { + if (!player.hasPermission("hardcoregames.espectar")) { + event.disallow(Result.KICK_OTHER, StringUtils.YOUR_HAVE_BEEN_ELIMINATED); + } else { + event.allow(); + } + } + } + gamer = null; + } + } + } + + player = null; + } + + private void kickRandomGamer() { + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + return; + } + Gamer randomGamer = GamerManager.getGamers().stream(). + filter(check -> !check.getPlayer().hasPermission("commons.entrar")).findAny().orElse(null); + + if (randomGamer != null) { + randomGamer.getPlayer().sendMessage(BukkitMessages.SEU_SLOT_FOI_DADO_A_UM_JOGADOR_VIP); + + BukkitServerAPI.redirectPlayer(randomGamer.getPlayer(), "LobbyHardcoreGames", true); + + randomGamer = null; + } + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + HardcoreGamesMain.getTimerManager().updateAlive(); + + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + HardcoreGamesScoreboard.createScoreboard(gamer); + + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + gamer.setOnline(true); + + if (gamer.isRelogar()) { + gamer.setRelogar(false); + gamer.setEliminado(true); + + Bukkit.broadcastMessage(StringUtils.PLAYER_RETURNED.replace("%nick%", player.getName())); + + if (gamer.getTaskID() != -1) { + Bukkit.getServer().getScheduler().cancelTask(gamer.getTaskID()); + gamer.setTaskID(-1); + } + + return; + } + + if (gamer.isEliminado()) { + HardcoreGamesMain.getGameManager().getGameType().setEspectador(player); + return; + } + + if ((player.hasPermission("hardcoregames.respawn")) && (HardcoreGamesMain.getTimerManager().getTime().get() <= 300)) { + gamer.setEliminado(true); + HardcoreGamesMain.getGameManager().getGameType().setGamer(player); + + player.teleport(HardcoreGamesUtility.getRandomLocation(160)); + + } else { + HardcoreGamesMain.getGameManager().getGameType().setEspectador(player); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + HardcoreGamesMain.getTimerManager().onSecond(); + } + + @EventHandler + public void onAdminChange(PlayerAdminChangeEvent event) { + if (event.getChangeType() == AdminChangeType.ENTROU) { + HardcoreGamesMain.getGameManager().getGameType().setEspectador(event.getPlayer(), true); + } else { + HardcoreGamesMain.getGameManager().getGameType().setGamer(event.getPlayer()); + } + } + + @EventHandler + public void onCompass(PlayerInteractEvent event) { + if ((event.hasItem()) && (event.getItem().getType() == Material.COMPASS) + && (event.getAction() != Action.PHYSICAL)) { + + Player player = event.getPlayer(); + + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + new AliveGamers().open(player); + return; + } + if (VanishAPI.inAdmin(player)) { + new AliveGamers().open(player); + return; + } + + PlayerCompassEvent compassEvent = new PlayerCompassEvent(player, + event.getAction().name().contains("RIGHT") ? PlayerCompassEvent.CompassAction.RIGHT : PlayerCompassEvent.CompassAction.LEFT); + + Bukkit.getServer().getPluginManager().callEvent(compassEvent); + + Player alvo = compassEvent.getTarget(); + + if (alvo == null) { + player.sendMessage(StringUtils.BUSSOLA_NOT_FINDED); + player.setCompassTarget(player.getWorld().getSpawnLocation()); + } else { + player.sendMessage(StringUtils.BUSSOLA_FINDED.replace("%nick%", alvo.getName())); + player.setCompassTarget(alvo.getLocation()); + + alvo = null; + } + + player = null; + compassEvent = null; + } + } + + @EventHandler + public void onScoreChange(PlayerChangeScoreboardEvent event) { + if (event.getChangeType() == ScoreboardChangeType.ATIVOU) { + HardcoreGamesScoreboard.createScoreboard(event.getPlayer()); + } + } + + @EventHandler + public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { + if (!HardcoreGamesOptions.PLACE_OPTION) { + if (!event.getPlayer().hasPermission("hardcoregames.place")) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlace(BlockPlaceEvent event) { + if (event.getBlock().getLocation().getBlockY() > 128) { + event.setCancelled(true); + event.getPlayer().sendMessage("§cA altura maxima permitida para construção é de 128."); + return; + } + + if (!HardcoreGamesOptions.PLACE_OPTION) { + if (!event.getPlayer().hasPermission("hardcoregames.place")) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onBreak(BlockBreakEvent event) { + if (!HardcoreGamesOptions.BREAK_OPTION) { + if (!event.getPlayer().hasPermission("hardcoregames.break")) { + event.setCancelled(true); + } + } + + if(HardcoreGamesMain.getTimerManager().getTime().get() < 300 && event.getBlock().getType().equals(Material.IRON_ORE)) { + event.getPlayer().sendMessage(ChatColor.RED + "Você só pode minerar após os 5 minutos."); + event.setCancelled(true); + } + } + + @EventHandler + public void onPhysic(BlockPhysicsEvent event) { + if (event.getBlock().getType().equals(Material.BROWN_MUSHROOM)) { + event.setCancelled(true); + } else if (event.getBlock().getType().equals(Material.RED_MUSHROOM)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBreak1(BlockBreakEvent event) { + Player player = event.getPlayer(); + + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (gamer.isPlaying()) { + Material material = event.getBlock().getType(); + + if (material == Material.COBBLESTONE || material == Material.STONE) { + if (!PlayerAPI.isFull(player.getInventory())) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.COBBLESTONE)); + } else { + for (ItemStack itens : player.getInventory().getContents()) { + if ((itens.getType().equals(material)) && (itens.getAmount() != 64)) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.COBBLESTONE)); + break; + } + } + } + } else if (material == Material.BROWN_MUSHROOM) { + if (!PlayerAPI.isFull(player.getInventory())) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.BROWN_MUSHROOM)); + } else { + for (ItemStack itens : player.getInventory().getContents()) { + if ((itens.getType().equals(material)) && (itens.getAmount() != 64)) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.BROWN_MUSHROOM)); + break; + } + } + } + } else if (material == Material.RED_MUSHROOM) { + if (!PlayerAPI.isFull(player.getInventory())) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.RED_MUSHROOM)); + } else { + for (ItemStack itens : player.getInventory().getContents()) { + if ((itens.getType().equals(material)) && (itens.getAmount() != 64)) { + event.getBlock().setType(Material.AIR); + player.getInventory().addItem(new ItemStack(Material.RED_MUSHROOM)); + break; + } + } + } + } else if (material.name().contains("LOG")) { + if (!gamer.containsKit("Lumberjack") && !gamer.containsKit("JackHammer")) { + if (!PlayerAPI.isFull(player.getInventory())) { + ArrayList items = new ArrayList<>(event.getBlock().getDrops()); + for (ItemStack item : items) { + player.getInventory().addItem(item); + } + event.getBlock().setType(Material.AIR); + } else { + for (ItemStack itens : player.getInventory().getContents()) { + if ((itens.getType().equals(material)) && (itens.getAmount() != 64)) { + ArrayList items = new ArrayList<>(event.getBlock().getDrops()); + for (ItemStack item : items) { + player.getInventory().addItem(item); + } + event.getBlock().setType(Material.AIR); + + items.clear(); + items = null; + break; + } + } + } + } + } + + material = null; + } + + player = null; + gamer = null; + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + if (!HardcoreGamesOptions.DROP_OPTION) { + event.setCancelled(true); + } else { + if (BukkitServerAPI.checkItem(event.getItemDrop().getItemStack(), "§bKit")) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onEntityDamage(EntityDamageByEntityEvent event) { + if (event.isCancelled()) return; + if (!(event.getEntity() instanceof Player)) return; + + Player damager = null; + + if (event.getDamager() instanceof Player) { + damager = (Player) event.getDamager(); + } else if (event.getDamager() instanceof Projectile) { + Projectile pr = (Projectile) event.getDamager(); + if (pr.getShooter() != null && pr.getShooter() instanceof Player) { + damager = (Player) pr.getShooter(); + } + pr = null; + } + + if (damager == null) return; + + PlayerDamagePlayerEvent event2 = new PlayerDamagePlayerEvent(damager, (Player) event.getEntity(), + event.getDamage()); + + Bukkit.getPluginManager().callEvent(event2); + + event.setCancelled(event2.isCancelled()); + event.setDamage(event2.getDamage()); + + damager = null; + event2 = null; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + CombatLogManager.newCombatLog(event.getDamaged(), event.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onDeath(PlayerDeathEvent e) { + CombatLogManager.removeCombatLog(e.getEntity()); + } + + @EventHandler + public void onCompass(PlayerCompassEvent event) { + event.setTarget(HardcoreGamesUtility.getRandomPlayer(event.getPlayer())); + } + + @EventHandler + public void onUpdateServer(ServerStatusUpdateEvent event) { + GameStages stage = HardcoreGamesMain.getGameManager().getStage(); + + event.writeMemberSlots(80); + + if (stage == GameStages.END) { + event.writeHungerGames(0, 0, stage.getNome()); + } else { + event.writeHungerGames(GamerManager.getGamersVivos().size(), + HardcoreGamesMain.getTimerManager().getTime().get(), stage.getNome()); + } + + stage = null; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.java new file mode 100644 index 0000000..6ca742d --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.java @@ -0,0 +1,107 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameInvincibilityEndEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.timer.TimerType; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.plugin.PluginManager; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; + +public class InvincibilityListener implements Listener { + + @EventHandler + public void onTimer(GameTimerEvent event) { + if (event.getTime() == 0) { + PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + pluginManager.registerEvents(new GameListener(), HardcoreGamesMain.getInstance()); + + pluginManager.callEvent(new GameInvincibilityEndEvent()); + pluginManager.callEvent(new GameStageChangeEvent(GameStages.INVINCIBILITY, GameStages.PLAYING)); + } else { + event.checkMessage(); + } + } + + @EventHandler + public void onInvincibilityEnd(GameInvincibilityEndEvent event) { + int time = 120; + + if (BukkitMain.getServerType() == ServerType.CHAMPIONS) { + time = 60; + } + + HardcoreGamesMain.getGameManager().setStage(GameStages.PLAYING); + HardcoreGamesMain.getTimerManager().updateTime(time); + HardcoreGamesMain.getTimerManager().setTimerType(TimerType.COUNT_UP); + + for (Gamer gamer : GamerManager.getGamers()) { + if (gamer == null) { + continue; + } + if (!gamer.isOnline()) { + continue; + } + HardcoreGamesScoreboard.createScoreboard(gamer); + gamer.getPlayer().playSound(gamer.getPlayer().getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F); + } + + Bukkit.broadcastMessage(StringUtils.INVENCIBILITY_ENDED); + + HardcoreGamesMain.getGameManager().getGameType().checkWin(); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onEntityDamage(EntityDamageEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onInvencibilityEnd(GameStageChangeEvent event) { + if (event.getLastStage() == GameStages.INVINCIBILITY && + event.getNewStage() == GameStages.PLAYING) { + + HardcoreGamesMain.console("Removing listeners from InvincibilityListener"); + + HandlerList.unregisterAll(this); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.java new file mode 100644 index 0000000..aa859bb --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.java @@ -0,0 +1,198 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.menu.KitSelector; +import com.br.guilhermematthew.nowly.hardcoregames.menu.enums.InventoryMode; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; + +public class PreGameListeners implements Listener { + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (player.getGameMode() != GameMode.ADVENTURE) + player.setGameMode(GameMode.ADVENTURE); + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + playerInventory.setItem(0, itemBuilder.type(Material.CHEST).name("§aEscolher Kit").build()); + + if (HardcoreGamesOptions.DOUBLE_KIT) { + playerInventory.setItem(1, itemBuilder.type(Material.CHEST).amount(2).name("§aEscolher Kit 2").build()); + } + + playerInventory.addItem(itemBuilder.type(Material.EMERALD).name("§6Loja de Kits").build()); + + playerInventory.setItem(8, itemBuilder.type(Material.BED).name("§cVoltar ao Lobby").build()); + + player.teleport(HardcoreGamesUtility.getRandomLocation(40)); + } + + @EventHandler + public void onTimer(GameTimerEvent event) { + World world = Bukkit.getWorlds().get(0); + + world.setTime(0); + world.setStorm(false); + world.setThundering(false); + + if (HardcoreGamesMain.getTimerManager().getLastAlive() < HardcoreGamesOptions.MIN_PLAYERS) { + HardcoreGamesMain.getTimerManager().updateTime(300); + event.setTime(300); + return; + } + + if (event.getTime() == 0) { + HardcoreGamesMain.getGameManager().getGameType().start(); + return; + } + + if (event.getTime() == 15) { + Bukkit.getOnlinePlayers().forEach(onlines -> onlines.teleport(HardcoreGamesUtility.getRandomLocation(20))); + } + + event.checkMessage(); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + event.setCancelled(true); + + ItemStack itemStack = event.getPlayer().getInventory().getItemInHand(); + + if (event.getAction().name().contains("RIGHT")) { + if (BukkitServerAPI.checkItem(itemStack, "§aEscolher Kit 2")) { + new KitSelector(event.getPlayer(), InventoryMode.KIT_SECUNDARIO).open(event.getPlayer()); + } else if (BukkitServerAPI.checkItem(itemStack, "§aEscolher Kit")) { + new KitSelector(event.getPlayer(), InventoryMode.KIT_PRIMARIO).open(event.getPlayer()); + } else if (BukkitServerAPI.checkItem(itemStack, "§6Loja de Kits")) { + new KitSelector(event.getPlayer(), InventoryMode.LOJA).open(event.getPlayer()); + } else if (BukkitServerAPI.checkItem(itemStack, "§cVoltar ao Lobby")) { + BukkitServerAPI.redirectPlayer(event.getPlayer(), "LobbyHardcoreGames"); + } + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + GamerManager.removeGamer(event.getPlayer().getUniqueId()); + + BukkitServerAPI.removePlayerFile(event.getPlayer().getUniqueId()); + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPickup(PlayerPickupItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBreak(BlockBreakEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onExplosion(ExplosionPrimeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onIgnite(BlockIgniteEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void craftItem(CraftItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onStart(GameStageChangeEvent event) { + if (event.getLastStage() == GameStages.WAITING && + event.getNewStage() == GameStages.INVINCIBILITY) { + + HardcoreGamesMain.console("Removing listeners from PreGameListeners"); + + HandlerList.unregisterAll(this); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.java new file mode 100644 index 0000000..6a1cfd3 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.java @@ -0,0 +1,66 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameStageChangeEvent; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStopEvent; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; + +public class ScoreboardListeners implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + update(1); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onQuit(PlayerQuitEvent event) { + update(1); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onTimer(GameTimerEvent event) { + update(2); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onDeath(PlayerDeathEvent event) { + update(1); + } + + public void update(int code) { + HardcoreGamesMain.runLater(() -> { + if (code == 1) { + Bukkit.getOnlinePlayers().stream().filter(check -> check != null).filter(check -> check.isOnline()) + .forEach(onlines -> HardcoreGamesScoreboard.getScoreBoardCommon().updateGaming(onlines)); + } else if (code == 2) { + Bukkit.getOnlinePlayers().stream().filter(check -> check != null).filter(check -> check.isOnline()) + .forEach(onlines -> HardcoreGamesScoreboard.getScoreBoardCommon().updateTime(onlines)); + } + }); + } + + @EventHandler + public void onStop(ServerStopEvent event) { + HandlerList.unregisterAll(this); + } + + @EventHandler + public void onGameEnd(GameStageChangeEvent event) { + if (event.getNewStage() == GameStages.END) { + HardcoreGamesMain.console("Removing listeners from ScoreboardListeners"); + + HandlerList.unregisterAll(this); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.java new file mode 100644 index 0000000..135d3ed --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.java @@ -0,0 +1,162 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.block.Beacon; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.block.Dispenser; +import org.bukkit.block.DoubleChest; +import org.bukkit.block.Furnace; +import org.bukkit.block.Hopper; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; + +public class SpectatorListener implements Listener { + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player)event.getEntity(); + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + event.setCancelled(true); + } + player = null; + } + } + + @EventHandler(priority=EventPriority.LOW) + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + + if (!VanishAPI.inAdmin(player)) { + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + event.setCancelled(true); + } + } + + player = null; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (VanishAPI.inAdmin(event.getPlayer())) { + event.setCancelled(true); + return; + } + + if (!GamerManager.getGamer(event.getPlayer().getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + + if (VanishAPI.inAdmin(event.getDamaged())) { + event.setCancelled(true); + return; + } + if (!GamerManager.getGamer(event.getDamaged().getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + } + + @EventHandler + public void onPickup(PlayerPickupItemEvent event) { + if (!GamerManager.getGamer(event.getPlayer().getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + if (VanishAPI.inAdmin(event.getPlayer())) { + event.setCancelled(true); + return; + } + } + + @EventHandler + public void onTarget(EntityTargetEvent event) { + if (event.getTarget() instanceof Player) { + final Player player = (Player) event.getTarget(); + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + if (VanishAPI.inAdmin(player)) { + event.setCancelled(true); + return; + } + } + } + + @EventHandler + public void onInteractBlock(PlayerInteractEvent event) { + if (!GamerManager.getGamer(event.getPlayer().getUniqueId()).isPlaying()) { + if (event.getAction() == Action.PHYSICAL) { + event.setCancelled(true); + return; + } + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Block b = event.getClickedBlock(); + if (b.getState() instanceof DoubleChest || b.getState() instanceof Chest || b.getState() instanceof Hopper || b.getState() instanceof Dispenser || b.getState() instanceof Furnace || b.getState() instanceof Beacon) { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + if (!GamerManager.getGamer(event.getPlayer().getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + if (VanishAPI.inAdmin(event.getPlayer())) { + event.setCancelled(true); + return; + } + } + + @EventHandler + public void onBreak(BlockBreakEvent event) { + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + final Player player = event.getPlayer(); + if (VanishAPI.inAdmin(player)) { + event.setCancelled(false); + return; + } + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + if (!HardcoreGamesMain.getGameManager().isPreGame()) { + final Player player = event.getPlayer(); + if (VanishAPI.inAdmin(player)) { + event.setCancelled(false); + return; + } + if (!GamerManager.getGamer(player.getUniqueId()).isPlaying()) { + event.setCancelled(true); + return; + } + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.java new file mode 100644 index 0000000..482601c --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.java @@ -0,0 +1,47 @@ +package com.br.guilhermematthew.nowly.hardcoregames.listeners; + +import java.util.Collection; + +public class StringUtils { + + /** + * Junta uma Array em uma {@code String} utilizando um separador. + * + * @param array A array para juntar. + * @param index O ínicio da iteração da array (0 = toda a array). + * @param separator O separador da junção. + * @return Resultado da junção. + */ + public static String join(T[] array, int index, String separator) { + StringBuilder joined = new StringBuilder(); + for (int slot = index; slot < array.length; slot++) { + joined.append(array[slot].toString() + (slot + 1 == array.length ? "" : separator)); + } + + return joined.toString(); + } + + /** + * Junta uma Array em uma {@code String} utilizando um separador. + * + * @param array A array para juntar. + * @param separator O separador da junção. + * @return Resultado da junção. + */ + public static String join(T[] array, String separator) { + return join(array, 0, separator); + } + + /** + * Junta uma Coleção em uma {@code String} utilizando um separador. + * + * @param collection A coleção para juntar. + * @param separator O separador da junção. + * @return Resultado da junção. + */ + public static String join(Collection collection, String separator) { + return join(collection.toArray(new Object[collection.size()]), separator); + } + + +} diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.java new file mode 100644 index 0000000..1902768 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.java @@ -0,0 +1,91 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.combatlog; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +import lombok.Data; +import lombok.RequiredArgsConstructor; + +public class CombatLogManager { + + private final static String COMBATLOG_PLAYER = "combatlog.player"; + private final static String COMBATLOG_EXPIRE = "combatlog.time"; + + private final static long COMBATLOG_TIME = 5000L; // Miliseconds + + public static void newCombatLog(Player damager, Player damaged) { + setCombatLog(damager, damaged); + setCombatLog(damaged, damager); + } + + public static Player getLastHit(Player p) { + Player finded = null; + + CombatLog log = CombatLogManager.getCombatLog(p); + + if (log.isFighting()) { + + Player combatLogger = log.getCombatLogged(); + + if (combatLogger != null) { + if (combatLogger.isOnline()) { + CombatLogManager.removeCombatLog(p); + finded = combatLogger; + } + combatLogger = null; + } + } + + log = null; + + return finded; + } + + public static void removeCombatLog(Player player) { + HardcoreGamesMain plugin = HardcoreGamesMain.getInstance(); + + if (player.hasMetadata(COMBATLOG_PLAYER)) + player.removeMetadata(COMBATLOG_PLAYER, plugin); + + if (player.hasMetadata(COMBATLOG_EXPIRE)) + player.removeMetadata(COMBATLOG_EXPIRE, plugin); + } + + private static void setCombatLog(Player player1, Player player2) { + HardcoreGamesMain plugin = HardcoreGamesMain.getInstance(); + + removeCombatLog(player1); + + player1.setMetadata(COMBATLOG_PLAYER, new FixedMetadataValue(plugin, player2.getName())); + player1.setMetadata(COMBATLOG_EXPIRE, new FixedMetadataValue(plugin, System.currentTimeMillis())); + } + + public static CombatLog getCombatLog(Player player) { + String playerName = ""; + + long time = 0L; + + if (player.hasMetadata(COMBATLOG_PLAYER)) + playerName = player.getMetadata(COMBATLOG_PLAYER).get(0).asString(); + + if (player.hasMetadata(COMBATLOG_EXPIRE)) + time = player.getMetadata(COMBATLOG_EXPIRE).get(0).asLong(); + + Player combatLogged = Bukkit.getPlayer(playerName); + return new CombatLog(combatLogged, time); + } + + @Data + @RequiredArgsConstructor + public static class CombatLog { + + private final Player combatLogged; + private final long time; + + public boolean isFighting() { + return System.currentTimeMillis() < time + COMBATLOG_TIME; + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.java new file mode 100644 index 0000000..f58bfb5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.gamer; + +import java.util.UUID; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class Gamer { + + private UUID uniqueId; + private String kit1, kit2; + + private boolean eliminado, playing, online, relogar; + private int kills, taskID; + + private Player player; + + public Gamer(UUID uniqueId) { + setUniqueId(uniqueId); + + this.kit1 = "Nenhum"; + this.kit2 = "Nenhum"; + + setKills(0); + setTaskID(-1); + setEliminado(false); + setPlaying(true); + setOnline(true); + setRelogar(false); + } + + public boolean containsKit(String name) { + return getKit1().equalsIgnoreCase(name) || (HardcoreGamesOptions.DOUBLE_KIT && getKit2().equalsIgnoreCase(name)); + } + + public void addKill() { + setKills(getKills() + 1); + } + + public Player getPlayer() { + if (this.player == null) { + this.player = Bukkit.getPlayer(uniqueId); + } + + return this.player; + } + + public String getKits() { + if (!getKit2().equalsIgnoreCase("Nenhum")) { + return getKit1() + " e " + getKit2(); + } + return getKit1(); + } + + public void setKit1(String kit) { + this.kit1 = kit; + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit1(getPlayer(), kit); + } + + public void setKit2(String kit) { + this.kit2 = kit; + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit2(getPlayer(), kit); + } + +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.java new file mode 100644 index 0000000..f8bdef3 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.java @@ -0,0 +1,101 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.gamer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class GamerManager { + + private static HashMap gamers = new HashMap<>(); + + public static Gamer getGamer(UUID uniqueId) { + return gamers.get(uniqueId); + } + + public static Gamer getGamer(Player player) { + return gamers.getOrDefault(player.getUniqueId(), null); + } + public static boolean containsGamer(UUID uniqueId) { + return gamers.containsKey(uniqueId); + } + + public static void addGamer(UUID uniqueId) { + gamers.put(uniqueId, new Gamer(uniqueId)); + } + + public static void removeGamer(UUID uniqueId) { + gamers.remove(uniqueId); + } + + public static Collection getGamers() { + return gamers.values(); + } + + public static List getAliveGamers() { + List alives = new ArrayList<>(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + Gamer gamer = getGamer(onlines.getUniqueId()); + if (gamer == null) continue; + + if (gamer.isPlaying()) { + alives.add(onlines); + } + } + + return alives; + } + + public static List getGamersVivos() { + List vivos = new ArrayList<>(); + + for (Gamer gamers : getGamers()) { + if (gamers.isPlaying()) { + vivos.add(gamers); + } + } + + return vivos; + } + + public static List getGamersSpecs() { + List specs = new ArrayList<>(); + + for (Gamer gamers : getGamers()) { + if (!gamers.isPlaying() && gamers.isOnline()) { + specs.add(gamers); + } + } + + return specs; + } + + public static List getGamersEliminateds() { + List list = new ArrayList<>(); + + for (Gamer gamers : getGamers()) { + if (gamers.isEliminado()) { + list.add(gamers); + } + } + + return list; + } + + public static List getGamersToRelog() { + List list = new ArrayList<>(); + + for (Gamer gamers : getGamers()) { + if (gamers.isRelogar()) { + list.add(gamers); + } + } + + return list; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.java new file mode 100644 index 0000000..a19a05b --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.java @@ -0,0 +1,98 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.kit; + +import java.io.File; +import java.util.Arrays; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import org.bukkit.Material; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl.BukkitConfiguration; +import com.br.guilhermematthew.nowly.commons.common.utility.ClassGetter; +import com.br.guilhermematthew.nowly.commons.common.utility.system.Machine; + +import lombok.Getter; + +public class KitLoader { + + @Getter + private static BukkitConfiguration kitsConfig = new BukkitConfiguration("kits-hg", getDirectorty(), false); + + public static void load() { + kitsConfig.load(); + + boolean saveConfig = false; + + for (Class classes : ClassGetter.getClassesForPackage(HardcoreGamesMain.getInstance(), + "com.br.guilhermematthew.nowly.hardcoregames.ability.register")) { + String className = classes.getSimpleName(); + + boolean add = false; + + try { + if (Kit.class.isAssignableFrom(classes) && (classes != Kit.class)) { + add = true; + + if (!kitsConfig.getConfiguration().contains("kits." + className + ".price")) { + kitsConfig.getConfiguration().set("kits." + className + ".price", 1000); + kitsConfig.getConfiguration().set("kits." + className + ".cooldown", 20); + kitsConfig.getConfiguration().set("kits." + className + ".icon.material", "CHEST"); + kitsConfig.getConfiguration().set("kits." + className + ".icon.durability", 0); + kitsConfig.getConfiguration().set("kits." + className + ".icon.amount", 1); + kitsConfig.getConfiguration().set("kits." + className + ".icon.description", + Arrays.asList("&bEdite a desc na", "&cConfig")); + saveConfig = true; + } + } + } catch (Exception ex) { + add = false; + CommonsGeneral.error("Ocorreu um erro ao tentar carregar um kit '"+className+"' > " + ex.getLocalizedMessage()); + } + + + if (add) { + Material material = null; + + try { + material = Material.getMaterial(kitsConfig.getConfiguration().getString("kits." + className + ".icon.material")); + } catch (NullPointerException ex) { + HardcoreGamesMain.console("Material do Kit '" + className + "' está incorreto."); + add = false; + } finally { + if (material == null) { + add = false; + } + } + + if (add) { + try { + KitManager.getKits().put(className.toLowerCase(), (Kit) classes.newInstance()); + } catch (Exception ex) { + HardcoreGamesMain.console("Ocorreu um erro ao tentar adicionar um Kit. ->" + ex.getLocalizedMessage()); + } + } else { + HardcoreGamesMain.console("Não foi possivel adicionar o Kit -> " + className); + } + } + + } + + if (saveConfig) { + kitsConfig.save(); + } + + kitsConfig.unload(); + kitsConfig = null; + } + + private static File getDirectorty() { + File dir = new File(Machine.getDiretorio()); + + if (!dir.exists()) { + dir.mkdir(); + } + + return dir; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.java new file mode 100644 index 0000000..283760d --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.java @@ -0,0 +1,318 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.kit; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.hardcoregames.events.player.PlayerRegisterKitEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class KitManager { + + @Getter + private final static HashMap kits = new HashMap<>(); + + @Getter + private final static ArrayList kitsDesativados = new ArrayList<>(); + + public static List getAllKits() { + return new ArrayList<>(kits.values()); + } + + public static List getAllKitsAvailables() { + List allKits = new ArrayList<>(); + + for (Kit kit : kits.values()) { + if (!getKitsDesativados().contains(kit.getName().toLowerCase())) { + allKits.add(kit); + } + } + + return allKits; + } + + public static void disableKit(final String name) { + if (!getKitsDesativados().contains(name.toLowerCase())) { + getKitsDesativados().add(name.toLowerCase()); + } + } + + public static void disableKits(final String... kits) { + for (String kit : kits) { + disableKit(kit); + } + } + + public static void enableKit(final String name) { + getKitsDesativados().remove(name.toLowerCase()); + } + + public static void enableKits(final String... kits) { + for (String kit : kits) { + enableKit(kit); + } + } + + public static List getPlayerKits(Player player) { + List playerKits = new ArrayList<>(); + + for (Kit kit : getAllKits()) { + if (player.hasPermission("hg.kit." + kit.getName().toLowerCase()) || player.hasPermission("hg.kit.all")) { + playerKits.add(kit); + } else { + if (hasPermissionKit(player, kit.getName(), false)) { + playerKits.add(kit); + } + } + } + return playerKits; + } + + public static Kit getKitInfo(String nome) { + if (nome.equalsIgnoreCase("Nenhum")) return null; //FAST RESULT + + return kits.get(nome.toLowerCase()); + } + + public static boolean hasPermissionKit(Player player, String kit, boolean msg) { + return hasPermissionKit(player, kit, msg, true); + } + + public static boolean hasPermissionKit(Player player, String kit, boolean msg, boolean checkAllFree) { + if (checkAllFree) if (HardcoreGamesOptions.KITS_FREE) return true; + + if (player.hasPermission("hg.kit.all")) return true; + if (player.hasPermission("hg.kit." + kit.toLowerCase())) return true; + + if (msg) { + player.sendMessage(StringUtils.VOCE_NAO_POSSUI_ESTE_KIT); + } + return false; + } + + public static void giveBussola(Player player) { + if (!player.getInventory().contains(Material.COMPASS)) { + player.getInventory().addItem(new ItemBuilder().type(Material.COMPASS).name("§Bússola").build()); + player.updateInventory(); + } + } + + public static void give(Player player, String name, boolean firstKit) { + if (name.equalsIgnoreCase("Nenhum")) return; + + Kit playerKit = KitManager.getKitInfo(name); + + if (playerKit != null) { + playerKit.cleanPlayer(player); + + if (playerKit.getName().equalsIgnoreCase("Surprise")) { + playerKit = getRandomAvailableKit(); + + if(firstKit) GamerManager.getGamer(player.getUniqueId()).setKit1(playerKit.getName()); + else GamerManager.getGamer(player.getUniqueId()).setKit2(playerKit.getName()); + } + + if (playerKit.getItens() != null) { + for (ItemStack item : playerKit.getItens()) { + player.getInventory().addItem(item); + } + } + + playerKit.addUsing(); + + if (!playerKit.isListenerRegistred()) { + playerKit.registerListener(); + } + + if (playerKit.isCallEventRegisterPlayer()) { + Bukkit.getServer().getPluginManager().callEvent(new PlayerRegisterKitEvent(player, playerKit.getName())); + } + } + } + + public static void removeKits(Player player, boolean setInGamer) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + Kit kit1 = getKitInfo(gamer.getKit1()), + kit2 = getKitInfo(gamer.getKit2()); + + if (kit1 != null) kit1.unregisterPlayer(player); + + if (kit2 != null) kit2.unregisterPlayer(player); + + if (setInGamer) { + gamer.setKit1("Nenhum"); + gamer.setKit2("Nenhum"); + } + } + + public static void removeIfContainsKit(Player player, String kitName) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + Kit kit1 = getKitInfo(gamer.getKit1()), + kit2 = getKitInfo(gamer.getKit2()); + + boolean removed = false; + + if (kit1 != null && kit1.getName().equalsIgnoreCase(kitName)) { + kit1.unregisterPlayer(player); + + gamer.setKit1("Nenhum"); + + removed = true; + } + + if (kit2 != null && kit2.getName().equalsIgnoreCase(kitName)) { + kit2.unregisterPlayer(player); + + gamer.setKit2("Nenhum"); + + removed = true; + } + + if (removed) { + player.sendMessage(StringUtils.SEU_KIT_FOI_DESATIVADO.replace("%kit%", kitName)); + } + } + + public static void giveItensKit(Player player, String kitName) { + Kit kit = getKitInfo(kitName); + + if (kit != null) { + if (kit.getItens() != null) { + for (ItemStack item : kit.getItens()) { + player.getInventory().addItem(item); + } + } + } + + player.updateInventory(); + } + + + //PEGAR KIT APOS A PARTIDA TER INICIADO. + public static void handleKitSelect(Player player, boolean primary, String kitToSet) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + Kit olderKit = getKitInfo(primary ? gamer.getKit1() : gamer.getKit2()), + playerKit = getKitInfo(kitToSet); + + if (olderKit != null) { + if (olderKit.getName().equalsIgnoreCase(kitToSet)) return; + olderKit.unregisterPlayer(player); + + if (olderKit.getItens() != null) { + for (ItemStack item : olderKit.getItens()) { + if (player.getInventory().contains(item)) { + player.getInventory().remove(item); + } + } + } + } + + if (playerKit != null) { + if (kitToSet.equalsIgnoreCase("Surprise")) { + playerKit = getRandomAvailableKit(); + kitToSet = playerKit.getName(); + player.sendMessage(StringUtils.O_KIT_SURPRISE_ESCOLHEU_O_KIT.replace("%kit%", playerKit.getName())); + } + + playerKit.registerPlayer(); + + PlayerInventory playerInventory = player.getInventory(); + + if (playerKit.getItens() != null) { + for (ItemStack item : playerKit.getItens()) { + playerInventory.addItem(item); + } + } + + if (!playerInventory.contains(Material.COMPASS)) { + playerInventory.addItem(new ItemBuilder().type(Material.COMPASS).name("§6Bússola").build()); + } + } + + if (primary) { + gamer.setKit1(kitToSet); + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit1(player, kitToSet); + } else { + gamer.setKit2(kitToSet); + HardcoreGamesScoreboard.getScoreBoardCommon().updateKit2(player, kitToSet); + } + } + + private final static String[] combinationsBlockeds = { + "Stomper-Phantom", + "Stomper-Tower", + "Stomper-Jumper", + "Stomper-Launcher", + "Stomper-Grappler", + "Stomper-Flash", + "Stomper-Kangaroo", + "Stomper-Ninja", + "Viking-Urgal", + "Demoman-Tank", + "Kangaroo-Grappler", + "Phantom-Kangaroo", + "Hulk-Phantom", + "Fisherman-Magma", + "Fisherman-Fireman", + "Fisherman-Demoman", + "Phantom-Switcher", + "Gladiator-Ninja", + "Gladiator-Phantom", + "Gladiator-Kangaroo", + "Blink-Stomper", + ""}; + + public static boolean isSameKit(String kit, String otherKit) { + return kit.equalsIgnoreCase(otherKit); + } + + public static boolean hasCombinationOp(String kit, String otherKit) { + boolean isOp = false; + + final String playerCombination1 = kit + "-" + otherKit, + playerCombination2 = otherKit + "-" + kit; + + for (String combinations : combinationsBlockeds) { + if (playerCombination1.equalsIgnoreCase(combinations)) { + isOp = true; + break; + } + if (playerCombination2.equalsIgnoreCase(combinations)) { + isOp = true; + break; + } + } + + return isOp; + } + + private static Kit getRandomAvailableKit() { + val kits = getAllKitsAvailables(); + + val kit = kits.get(CommonsConst.RANDOM.nextInt(kits.size())); + if(kit != null && !kit.getName().equals("Surprise")) return kit; + + return getRandomAvailableKit(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.java new file mode 100644 index 0000000..ed6cb6e --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.java @@ -0,0 +1,54 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types.ChampionsScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types.DoubleKitScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types.SingleKitScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; + +public class HardcoreGamesScoreboard { + + private static ScoreboardCommon scoreBoardCommon = null; + public static String SCOREBOARD_TITLE = ""; + + public static void init() { + if (BukkitMain.getServerType() == ServerType.HARDCORE_GAMES) { + scoreBoardCommon = ( + HardcoreGamesOptions.DOUBLE_KIT ? new DoubleKitScoreboard() : new SingleKitScoreboard()); + } else { + scoreBoardCommon = (new ChampionsScoreboard()); + } + + updateTitle(); + + Bukkit.getOnlinePlayers().forEach(HardcoreGamesScoreboard::createScoreboard); + } + + public static void createScoreboard(Player player) { + createScoreboard(GamerManager.getGamer(player.getUniqueId())); + } + + public static void createScoreboard(Gamer gamer) { + getScoreBoardCommon().create(gamer); + } + + public static void updateTitle() { + if (BukkitMain.getServerType() == ServerType.EVENTO) { + SCOREBOARD_TITLE = "§e§lEVENTO"; + } else if (BukkitMain.getServerType() == ServerType.CHAMPIONS) { + SCOREBOARD_TITLE = "§e§lCHAMPIONS"; + } else { + SCOREBOARD_TITLE = "§e§l" + (HardcoreGamesOptions.DOUBLE_KIT ? "DOUBLE KIT" : "SINGLE KIT"); + } + } + + public static ScoreboardCommon getScoreBoardCommon() { + return scoreBoardCommon; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.java new file mode 100644 index 0000000..5ac1e2e --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.java @@ -0,0 +1,85 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; + +public abstract class ScoreboardCommon { + + public void create(final Gamer gamer) { + int playerMode = getPlayerMode(gamer.getPlayer(), gamer.isPlaying()); + + if (playerMode == 1) { + createGamerScoreboard(gamer.getPlayer(), gamer, SidebarManager.getSidebar(gamer.getUniqueId())); + } else { + createSpecScoreboard(gamer.getPlayer(), gamer, SidebarManager.getSidebar(gamer.getUniqueId()), playerMode); + } + } + + public void updateGaming(final Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + sidebar.updateLine("gaming", "Players: ", "§7" + getGaming() + "§7/" + Bukkit.getMaxPlayers()); + } + + public void updateTime(final Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + sidebar.updateLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + } + + public void updateKit1(final Player player, String kitName) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + Gamer gamerkit = GamerManager.getGamer(player.getUniqueId()); + sidebar.updateLine("kit1", "§fKit 1: ", "§a" + kitName); + + } + + public void updateKit2(final Player player, String kitName) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + Gamer gamerkit = GamerManager.getGamer(player.getUniqueId()); + sidebar.updateLine("kit2", "§fKit 2: ", "§a" + kitName); + + } + + public void updateKills(final Player player, int kills) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + sidebar.updateLine("kills", "§fKills: ", "§a" + kills); + } + + public void updatePlayerMode(Gamer gamer) { + int playerMode = getPlayerMode(gamer.getPlayer(), gamer.isPlaying()); + + Sidebar sidebar = SidebarManager.getSidebar(gamer.getUniqueId()); + sidebar.updateLine("playerMode", "", getPlayerMode(playerMode)); + } + + public abstract void createGamerScoreboard(Player player, Gamer gamer, Sidebar sidebar); + public abstract void createSpecScoreboard(Player player, Gamer gamer, Sidebar sidebar, int playerMode); + + public void createSpecScoreboard(Player player, Gamer gamer, Sidebar sidebar) { + createSpecScoreboard(player, gamer, sidebar, getPlayerMode(player, gamer.isPlaying())); + } + + private int getPlayerMode(final Player player, boolean playing) { + return playing ? 1 : (VanishAPI.inAdmin(player) ? 2 : 0); + } + + public String getMessageTime() { + return (HardcoreGamesMain.getGameManager().isPreGame() ? "Iniciando em: " : + HardcoreGamesMain.getGameManager().isInvencibilidade() ? "Invencível por: " : "Tempo: "); + } + + public String getGaming() { + return "" + HardcoreGamesMain.getTimerManager().getLastAlive(); + } + + public String getPlayerMode(int playerMode) { + return playerMode == 2 ? "§cMODO VANISH" : "§8SPECTATOR"; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.java new file mode 100644 index 0000000..8e5eaa9 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.java @@ -0,0 +1,65 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.ScoreboardCommon; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class ChampionsScoreboard extends ScoreboardCommon { + + @Override + public void createGamerScoreboard(Player player, Gamer gamer, Sidebar sidebar) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + Gamer gamerkit = GamerManager.getGamer(player.getUniqueId()); + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming() + "§7/" + Bukkit.getMaxPlayers()); + sidebar.addBlankLine(); + sidebar.addLine("kit1", "§fKit 1: ", "§a" + gamer.getKit1()); + if (HardcoreGamesMain.getGameManager().isGaming() && gamer.getKills() >= 1) { + sidebar.addLine("kills", "§fKills: ", "§a" + gamer.getKills()); + } + sidebar.addBlankLine(); + sidebar.addLine("mode", "Modo: ", "§aSolo"); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7º)"); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + @Override + public void createSpecScoreboard(Player player, Gamer gamer, Sidebar sidebar, int playerMode) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming()); + sidebar.addBlankLine(); + sidebar.addLine("playerMode", "", getPlayerMode(playerMode)); + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7)"); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.java new file mode 100644 index 0000000..501fcf0 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.java @@ -0,0 +1,78 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.ScoreboardCommon; + +public class DoubleKitScoreboard extends ScoreboardCommon { + + @Override + public void createGamerScoreboard(Player player, Gamer gamer, Sidebar sidebar) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + Gamer gamerkit = GamerManager.getGamer(player.getUniqueId()); + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming() + "§7/" + Bukkit.getMaxPlayers()); + if(!gamer.getKit1().equalsIgnoreCase("Nenhum")) { + sidebar.addBlankLine(); + } else { + sidebar.addBlankLine(); + sidebar.addLine("kit1", "§fKit 1: ", "§a" + gamer.getKit1()); + } + if (!gamer.getKit2().equalsIgnoreCase("Nenhum")) { + //nulo + } else { + sidebar.addLine("kit2", "§fKit 2: ", "§a" + gamer.getKit2()); + } + + if (HardcoreGamesMain.getGameManager().isGaming()) { + sidebar.addLine("kills", "§fKills: ", "§a" + gamer.getKills()); + } + + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7º)"); + sidebar.addLine("room", "Sala: ", "§a#" + BukkitMain.getServerID()); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + @Override + public void createSpecScoreboard(Player player, Gamer gamer, Sidebar sidebar, int playerMode) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming()); + sidebar.addBlankLine(); + sidebar.addLine("playerMode", "", getPlayerMode(playerMode)); + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7)"); + sidebar.addLine("room", "Sala: ", "§a#" + BukkitMain.getServerID()); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.java new file mode 100644 index 0000000..bcb403d --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.ScoreboardCommon; + +public class SingleKitScoreboard extends ScoreboardCommon { + + @Override + public void createGamerScoreboard(Player player, Gamer gamer, Sidebar sidebar) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + Gamer gamerkit = GamerManager.getGamer(player.getUniqueId()); + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming() + "§7/" + Bukkit.getMaxPlayers()); + if(!gamer.getKit1().equalsIgnoreCase("Nenhum")) { + sidebar.addBlankLine(); + } else { + sidebar.addBlankLine(); + sidebar.addLine("kit1", "§fKit 1: ", "§a" + gamer.getKit1()); + } + if (HardcoreGamesMain.getGameManager().isGaming()) { + sidebar.addLine("kills", "§fKills: ", "§a" + gamer.getKills()); + } + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7º)"); + sidebar.addLine("room", "Sala: ", "§a#" + BukkitMain.getServerID()); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + @Override + public void createSpecScoreboard(Player player, Gamer gamer, Sidebar sidebar, int playerMode) { + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle(HardcoreGamesScoreboard.SCOREBOARD_TITLE); + + League league = League.getRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getInt(DataType.XP)); + + sidebar.addBlankLine(); + sidebar.addLine("time", getMessageTime(), "§7" + HardcoreGamesMain.getTimerManager().getLastFormatted()); + sidebar.addLine("gaming", "Players: ", "§7" + getGaming()); + sidebar.addBlankLine(); + sidebar.addLine("playerMode", "", getPlayerMode(playerMode)); + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", "§7" + league.getColor() + league.getSymbol() + "§7(" + MySQLManager.getPlayerPositionRanking(BukkitMain.getBukkitPlayer(player.getUniqueId()).getNick()) + "§7)"); + sidebar.addLine("room", "Sala: ", "§a#" + BukkitMain.getServerID()); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.java new file mode 100644 index 0000000..01ae95f --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.java @@ -0,0 +1,209 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.structures; + +import java.util.ArrayList; +import java.util.Arrays; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types.Feast; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types.FinalBattle; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemChance; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl.BukkitConfiguration; + +import lombok.Getter; + +public class StructuresManager { + + private static FinalBattle finalBattle; + private static Feast feast; + + private static ArrayList itensFeast = new ArrayList<>(); + private static ArrayList itensMinifeast = new ArrayList<>(); + + @Getter + private static BukkitConfiguration chestConfig = new BukkitConfiguration("chests-hg", false); + + public static void loadItens() { + chestConfig.load(); + + boolean save = false; + + ItemBuilder itemBuilder = new ItemBuilder(); + + if (chestConfig.getConfiguration().contains("minifeast.itens")) { + for (String line : chestConfig.getConfiguration().getStringList("minifeast.itens")) { + String separador[] = line.split(","); + String material = separador[0].replace("material:", ""); + int quantidade = Integer.parseInt(separador[1].replace("amount:", "")); + int durabilidade = Integer.parseInt(separador[2].replace("durability:", "")); + int chance = Integer.parseInt(separador[3].replace("chance:", "")); + + Material m = null; + + try { + m = Material.getMaterial(material); + } catch (NullPointerException e) { + HardcoreGamesMain.console("Material invalido no Mini-Feast foi encontrado. -> " + material); + } + + if (m == null) + continue; + + itensMinifeast.add(new ItemChance(itemBuilder.type(m).durability(durabilidade).build(), chance, + (quantidade == 1 ? 0 : quantidade))); + } + } else { + save = true; + + chestConfig.getConfiguration().set("minifeast.itens", Arrays.asList( + "material:IRON_SWORD,amount:1,durability:0,chance:28", + "material:EXP_BOTTLE,amount:15,durability:0,chance:45", + "material:IRON_PICKAXE,amount:1,durability:0,chance:28", + "material:POTION,amount:1,durability:16393,chance:30", + "material:POTION,amount:1,durability:16417,chance:30", + "material:INK_SACK,amount:35,durability:3,chance:39", + "material:COOKED_BEEF,amount:35,durability:0,chance:39", + "material:ENDER_PEARL,amount:10,durability:0,chance:45", + "material:MONSTER_EGG,amount:7,durability:95,chance:34", + "material:BONE,amount:12,durability:0,chance:35", + "material:WEB,amount:10,durability:0,chance:25", + "material:TNT,amount:10,durability:0,chance:25", + "material:LAVA_BUCKET,amount:1,durability:0,chance:10" + )); + } + + if (chestConfig.getConfiguration().contains("feast.itens")) { + for (String line : chestConfig.getConfiguration().getStringList("feast.itens")) { + String separador[] = line.split(","); + String material = separador[0].replace("material:", ""); + int quantidade = Integer.parseInt(separador[1].replace("amount:", "")); + int durabilidade = Integer.parseInt(separador[2].replace("durability:", "")); + int chance = Integer.parseInt(separador[3].replace("chance:", "")); + + Material m = null; + try { + m = Material.getMaterial(material); + } catch (NullPointerException e) { + HardcoreGamesMain.console("Material invalido no Feast foi encontrado. -> " + material); + } + + if (m == null) + continue; + + itensFeast.add(new ItemChance(itemBuilder.type(m).durability(durabilidade).build(), chance, + (quantidade == 1 ? 0 : quantidade))); + } + } else { + save = true; + + chestConfig.getConfiguration().set("feast.itens", Arrays.asList( + "material:DIAMOND_HELMET,amount:1,durability:0,chance:20", + "material:DIAMOND_CHESTPLATE,amount:1,durability:0,chance:19", + "material:DIAMOND_LEGGINGS,amount:1,durability:0,chance:19", + "material:DIAMOND_BOOTS,amount:1,durability:0,chance:20", + "material:DIAMOND_SWORD,amount:1,durability:0,chance:19", + "material:DIAMOND_AXE,amount:1,durability:0,chance:19", + "material:DIAMOND_PICKAXE,amount:1,durability:0,chance:19", + "material:FLINT_AND_STEEL,amount:1,durability:0,chance:26", + "material:WATER_BUCKET,amount:1,durability:0,chance:37", + "material:LAVA_BUCKET,amount:1,durability:0,chance:35", + "material:BOW,amount:1,durability:0,chance:40", + + "material:POTION,amount:1,durability:16418,chance:32", + "material:POTION,amount:1,durability:16424,chance:32", + "material:POTION,amount:1,durability:16420,chance:33", + "material:POTION,amount:1,durability:16428,chance:31", + "material:POTION,amount:1,durability:16426,chance:30", + "material:POTION,amount:1,durability:16417,chance:32", + "material:POTION,amount:1,durability:16419,chance:33", + "material:POTION,amount:1,durability:16421,chance:34", + + "material:COOKED_BEEF,amount:30,durability:0,chance:40", + "material:ENDER_PEARL,amount:12,durability:0,chance:31", + "material:ENDER_PEARL,amount:5,durability:0,chance:21", + "material:GOLDEN_APPLE,amount:15,durability:0,chance:30", + "material:EXP_BOTTLE,amount:32,durability:0,chance:42", + "material:WEB,amount:28,durability:0,chance:13", + "material:TNT,amount:28,durability:0,chance:39", + "material:DIAMOND,amount:12,durability:0,chance:13", + "material:ARROW,amount:31,durability:0,chance:31" + )); + } + + itemBuilder = null; + + if (save) { + chestConfig.save(); + } + + chestConfig.unload(); + chestConfig = null; + } + + public static Location getValidLocation(boolean fixY) { + int x = getCoord(300), z = getCoord(300); + + World world = Bukkit.getWorld("world"); + Location loc = new Location(world, x, fixY ? 90 : world.getHighestBlockYAt(x, z) + 1, z); + + boolean localValido = false; + + while (!localValido) { + if (loc.getBlockY() >= 120 || loc.getBlockY() <= 55 || x + z < 40) { + x = getCoord(300); + z = getCoord(300); + loc = new Location(world, x, fixY ? 90 : world.getHighestBlockYAt(x, z) + 1, z); + } else { + localValido = true; + } + } + + return loc; + } + + public static int getCoord(int range) { + return CommonsConst.RANDOM.nextBoolean() ? CommonsConst.RANDOM.nextInt(range) : -CommonsConst.RANDOM.nextInt(range); + } + + public static FinalBattle getFinalBattle() { + if (finalBattle == null) { + finalBattle = new FinalBattle(); + } + return finalBattle; + } + + public static Feast getFeast() { + if (feast == null) { + feast = new Feast(); + } + return feast; + } + + public static void addItensChestMinifeast(Chest chest) { + for (int i = 0; i < itensMinifeast.size(); i++) + if (CommonsConst.RANDOM.nextInt(100) < itensMinifeast.get(i).getChance()) { + int slot = CommonsConst.RANDOM.nextInt(chest.getBlockInventory().getSize()); + chest.getBlockInventory().setItem(slot, itensMinifeast.get(i).getItem()); + } + chest.update(); + } + + public static void addChestItens(Chest chest) { + for (int i = 0; i < itensFeast.size(); i++) { + if (CommonsConst.RANDOM.nextInt(100) < itensFeast.get(i).getChance()) { + int slot = CommonsConst.RANDOM.nextInt(chest.getBlockInventory().getSize()); + chest.getBlockInventory().setItem(slot, itensFeast.get(i).getItem()); + } + } + chest.update(); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.java new file mode 100644 index 0000000..0046acd --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.java @@ -0,0 +1,139 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types; + +import java.util.ArrayList; +import java.util.List; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.utility.HardcoreGamesUtility; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; +import com.br.guilhermematthew.nowly.hardcoregames.utility.schematic.SchematicUtility; + +import lombok.Getter; + +@Getter +public class Feast { + + private boolean spawned; + private Location location; + + private Location enchantmentTable = null; + private List chests = new ArrayList<>(); + + private Listener listener; + + public void createFeast(final Location location) { + if(isSpawned()) return; + + this.location = location; + + SchematicUtility.spawnarSchematic("feast", location, false); + + final int x = location.getBlockX(), + y = location.getBlockY(), + z = location.getBlockZ(); + + final String coords = "(" + x + ", " + y + ", " + z + ")"; + + registerListener(); + + val totalTime = HardcoreGamesMain.getTimerManager().getTime().get() + 301; + new BukkitRunnable() { + public void run() { + spawned = true; + + val segundos = totalTime - HardcoreGamesMain.getTimerManager().getTime().get(); + if (!HardcoreGamesOptions.FEAST) { + cancel(); + Bukkit.broadcastMessage("§cO feast foi cancelado!"); + destroyListener(); + return; + } + + if (segundos == 300 || segundos == 240 || segundos == 180 || segundos == 120) { + Bukkit.broadcastMessage(StringUtils.FEAST_SPAWN_IN.replace("%coords%", coords).replace("%tempo%", + segundos / 60 + " minutos")); + + } else if (segundos == 60) { + Bukkit.broadcastMessage(StringUtils.FEAST_SPAWN_IN.replace("%coords%", coords).replace("%tempo%", "1 minuto")); + } else if (segundos == 30 || segundos == 15 || segundos == 10 || (segundos > 1 && segundos <= 5)) { + Bukkit.broadcastMessage(StringUtils.FEAST_SPAWN_IN.replace("%coords%", coords).replace("%tempo%", segundos + " segundos")); + } else if (segundos == 1) { + Bukkit.broadcastMessage(StringUtils.FEAST_SPAWN_IN.replace("%coords%", coords).replace("%tempo%", segundos + " segundo")); + } else if (segundos <= 0) { + HardcoreGamesUtility.strikeLightning(location); + + destroyListener(); + + fillChests(); + + Bukkit.broadcastMessage(StringUtils.FEAST_SPAWNED.replace("%coords%", coords)); + cancel(); + } + } + }.runTaskTimer(HardcoreGamesMain.getInstance(), 0, 20); + } + + public void fillChests() { + if (location == null) return; + + for (Block chest : chests) { + chest.setType(Material.CHEST); + + StructuresManager.addChestItens((Chest) chest.getLocation().getBlock().getState()); + } + + if (enchantmentTable != null) { + enchantmentTable.getBlock().setType(Material.ENCHANTMENT_TABLE); + } + + chests.clear(); + chests = null; + } + + public void registerListener() { + listener = new Listener() { + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlace(final BlockBreakEvent event) { + if (enchantmentTable == null) { + return; + } + + if (event.getBlock().getLocation().distance(enchantmentTable) < 15) { + event.setCancelled(true); + } + } + }; + + Bukkit.getServer().getPluginManager().registerEvents(listener, HardcoreGamesMain.getInstance()); + } + + public void destroyListener() { + HandlerList.unregisterAll(listener); + + listener = null; + } + + public void addChest(Block block) { + chests.add(block); + } + + public void setEnchantmentTable(Location location) { + this.enchantmentTable = location; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.java new file mode 100644 index 0000000..9406d18 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.java @@ -0,0 +1,84 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types; + +import java.util.ArrayList; + +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitSettings; + +public class FinalBattle { + + private final int altura = 128; + private final int radius = 30; + + @SuppressWarnings("deprecation") + public void create() { + BukkitSettings.DANO_OPTION = false; + BukkitSettings.PVP_OPTION = false; + + Location location = Bukkit.getWorld("world").getBlockAt(0, 2, 0).getLocation(); + World world = location.getWorld(); + + for (int x = -30; x < 30; x++) { + for (int y = -1; y < 128; y++) { + for (int z = -30; z < 30; z++) { + location.clone().add(x, y, z).getBlock().setType(Material.AIR); + + // WorldEditAPI.setAsyncBlock(world, location.add(x, y, z), Material.AIR.getId()); + } + } + } + + for (int x = -30; x <= 30; x++) + if ((x == -30) || (x == 30)) + for (int z = -30; z <= 30; z++) + for (int y = 0; y <= 150; y++) { + world.getBlockAt(x, y, z).setType(Material.BEDROCK); + } + + for (int z = -30; z <= 30; z++) + if ((z == -30) || (z == 30)) + for (int x = -30; x <= 30; x++) + for (int y = 0; y <= 150; y++) { + world.getBlockAt(x, y, z).setType(Material.BEDROCK); + } + + final Location loc = world.getBlockAt(0, 5, 0).getLocation(); + + final ArrayList players = (ArrayList) world.getPlayers(); + + new BukkitRunnable() { + + int teleporteds = 0; + final int toTeleport = players.size(); + + public void run() { + if (teleporteds > toTeleport) { + cancel(); + BukkitSettings.DANO_OPTION = true; + BukkitSettings.PVP_OPTION = true; + return; + } + + try { + Player target = players.get(teleporteds); + target.setFallDistance(-5); + target.setNoDamageTicks(30); + + target.teleport(loc); + } catch (Exception ex) {} + + teleporteds++; + } + }.runTaskTimer(BukkitMain.getInstance(), 2L, 2L); + + Bukkit.broadcastMessage(StringUtils.ARENA_FINAL_SPAWNED); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.java new file mode 100644 index 0000000..2684be5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.structures.types; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; +import com.br.guilhermematthew.nowly.hardcoregames.utility.schematic.SchematicUtility; + +public class MiniFeast { + + public static void create() { + Location location = StructuresManager.getValidLocation(false); + + SchematicUtility.spawnarSchematic("minifeast", location, false); + + int reduceX = CommonsConst.RANDOM.nextInt(60) + 1; + int reduceZ = CommonsConst.RANDOM.nextInt(40) + 1; + int upX = CommonsConst.RANDOM.nextInt(40) + 1; + int upZ = CommonsConst.RANDOM.nextInt(70) + 1; + + int x = location.getBlockX() + upX, + z = location.getBlockZ() + upZ, + x1 = location.getBlockX() - reduceX, + z1 = location.getBlockZ() - reduceZ; + + Bukkit.broadcastMessage(StringUtils.MINIFEAST_SPAWNED.replace("%x%", "" + x).replace("%z%", "" + z).replace( + "%x1%", "" + x1).replace("%z1%", "" + z1)); + + HardcoreGamesMain.console("MiniFeast spawnou em -> " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ()); + + location = null; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.java new file mode 100644 index 0000000..05160db --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.timer; + +import org.bukkit.Bukkit; + +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.hardcoregames.events.game.GameTimerEvent; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.scoreboard.HardcoreGamesScoreboard; + +import lombok.Getter; +import lombok.Setter; + +import java.util.concurrent.atomic.AtomicInteger; + +@Getter @Setter +public class TimerManager { + + private AtomicInteger time = new AtomicInteger(300); + private String lastFormatted = ""; + private int lastAlive = 0; + + @Setter + private TimerType timerType = TimerType.COUNTDOWN; + + public void onSecond() { + switch (timerType) { + case COUNTDOWN: + time.getAndDecrement(); + break; + case COUNT_UP: + time.getAndIncrement(); + break; + default: + break; + } + + GameTimerEvent event = new GameTimerEvent(getTime().get()); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (event.isChangedTime()) { + this.time.set(event.getTime()); + lastFormatted = DateUtils.formatSecondsScore(getTime().get()); + + Bukkit.getOnlinePlayers().forEach(onlines -> + HardcoreGamesScoreboard.getScoreBoardCommon().updateTime(onlines)); + } + + this.lastFormatted = DateUtils.formatSecondsScore(getTime().get()); + this.lastAlive = GamerManager.getAliveGamers().size(); + } + + public void updateAlive() { + this.lastAlive = GamerManager.getAliveGamers().size(); + } + + public void updateTime(int newTime) { + time.set(newTime); + + this.lastFormatted = DateUtils.formatSecondsScore(getTime().get()); + } + + public String getLastFormatted() { + return lastFormatted; + } + + public int getLastAlive() { + return lastAlive; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.java new file mode 100644 index 0000000..6361f81 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.java @@ -0,0 +1,6 @@ +package com.br.guilhermematthew.nowly.hardcoregames.manager.timer; + +public enum TimerType { + + COUNTDOWN, COUNT_UP, UNKNOWN; +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.java new file mode 100644 index 0000000..10d9390 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.java @@ -0,0 +1,137 @@ +package com.br.guilhermematthew.nowly.hardcoregames.menu; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; + +public class AliveGamers extends MenuInventory { + + private static final int ITEMS_PER_PAGE = 28; + private static final int PREVIOUS_PAGE_SLOT = 27; + private static final int NEXT_PAGE_SLOT = 35; + private static final int CENTER = 31; + private static final int HEADS_PER_ROW = 7; + + public AliveGamers() { + this(1); + } + + public AliveGamers(int page) { + this(page, (3 / ITEMS_PER_PAGE) + 1); + } + + public AliveGamers(int page, int maxPages) { + super("Jogadores Vivos", 6); + + List itens = new ArrayList<>(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(onlines.getUniqueId()); + + if (gamer != null) { + if (gamer.isPlaying()) { + itens.add(new MenuItem(itemBuilder.type(Material.SKULL_ITEM).durability(3).name( + "§a" + onlines.getName()).skin(onlines.getName()).lore( + "§fKills: §7" + gamer.getKills(), "§fKit(s): §6" + gamer.getKits()).build(), new ClickHandler())); + } + gamer = null; + } + } + + int pageStart = 0; + int pageEnd = ITEMS_PER_PAGE; + + if (page > 1) { + pageStart = ((page - 1) * ITEMS_PER_PAGE); + pageEnd = (page * ITEMS_PER_PAGE); + } + + if (pageEnd > itens.size()) { + pageEnd = itens.size(); + } + + if (page == 1) { + setItem(PREVIOUS_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPágina Anterior").build(), + (player, arg1, arg2, arg3, arg4) -> new AliveGamers(page - 1).open(player)), PREVIOUS_PAGE_SLOT); + } + + if ((itens.size() / ITEMS_PER_PAGE) + 1 <= page) { + setItem(NEXT_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPróxima Página").build(), + (player, arg1, arg2, arg3, arg4) -> new AliveGamers(page + 1).open(player)), NEXT_PAGE_SLOT); + } + + int kitSlot = 10; + + for (int i = pageStart; i < pageEnd; i++) { + MenuItem item = itens.get(i); + setItem(item, kitSlot); + + if (kitSlot % 9 == HEADS_PER_ROW) { + kitSlot += 3; + continue; + } + + kitSlot += 1; + } + + if (itens.size() == 0) { + setItem(CENTER, itemBuilder.type(Material.REDSTONE_BLOCK).name("§cNenhum jogador vivo.").build()); + } + + if (StructuresManager.getFeast().getLocation() != null) { + setItem(4, new MenuItem(new ItemBuilder().type(Material.CAKE).name("§aFeast").build(), new ClickHandler())); + } + + itemBuilder = null; + itens.clear(); + itens = null; + } + + private static class ClickHandler implements MenuClickHandler { + + @Override + public void onClick(Player player, Inventory inventory, ClickType clickType, ItemStack item, int slot) { + if (clickType != ClickType.LEFT) return; + + player.closeInventory(); + + if (item.getType() == Material.CAKE) { + player.sendMessage("§aVocê foi para o feast!"); + player.teleport(StructuresManager.getFeast().getLocation().clone().add(0.5, 3, 0.5)); + } else { + String name = item.getItemMeta().getDisplayName().replace("§a", ""); + + Player target = Bukkit.getPlayer(name); + + if (target != null) { + player.teleport(target.getLocation().clone().add(0, 1.2, 0)); + player.sendMessage("§aVocê se teleportou para o §f" + target.getName()); + + target = null; + } else { + player.sendMessage("§cJogador offline!"); + } + } + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.java new file mode 100644 index 0000000..ca5d91e --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.java @@ -0,0 +1,249 @@ +package com.br.guilhermematthew.nowly.hardcoregames.menu; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.ability.Kit; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.hardcoregames.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.hardcoregames.menu.enums.InventoryMode; + +public class KitSelector extends MenuInventory { + + private static final int ITEMS_PER_PAGE = 28; + private static final int PREVIOUS_PAGE_SLOT = 27; + private static final int NEXT_PAGE_SLOT = 35; + private static final int CENTER = 31; + + private static final int KITS_PER_ROW = 7; + + public KitSelector(final Player player) { + this(player, 1, InventoryMode.KIT_PRIMARIO); + } + + public KitSelector(Player player, InventoryMode inventoryMode) { + this(player, 1, inventoryMode); + } + + public KitSelector(Player player, int page, InventoryMode inventoryMode) { + this(player, page, (3 / ITEMS_PER_PAGE) + 1, inventoryMode); + } + + public KitSelector(Player player1, int page, int maxPages, InventoryMode inventoryMode) { + super(inventoryMode.getInventoryName(), 6); + + List kitList = new ArrayList<>(KitManager.getKits().values()); + + kitList.sort(Comparator.comparing(Kit::getName)); + + List itens = new ArrayList<>(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + Gamer gamer = GamerManager.getGamer(player1.getUniqueId()); + + for (Kit kit : kitList) { + List lore = new ArrayList(); + + for (String line : kit.getDescription()) { + lore.add(line.replaceAll("&", "§")); + } + + if (inventoryMode == InventoryMode.LOJA) { + if (continuePlayer(player1, kit.getName(), inventoryMode)) { + lore.add(""); + lore.add("§fCusto: §6" + StringUtility.formatValue(kit.getPrice()) + " coins"); + lore.add(""); + lore.add("§eClique para comprar."); + + itens.add(new MenuItem( + itemBuilder.type(kit.getIcon().getType()).name("§a" + kit.getName()).lore(lore).build(), + new LojaKitsHandler(kit))); + } else { + lore.add(""); + lore.add("§cVocê já possuí este Kit."); + + itens.add(new MenuItem(itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), new LojaKitsHandler(kit))); + } + } else { + if (continuePlayer(player1, kit.getName(), inventoryMode)) { + boolean isOp = KitManager.hasCombinationOp( + inventoryMode == InventoryMode.KIT_PRIMARIO ? gamer.getKit2() : gamer.getKit1(), + kit.getName()); + + if (KitManager.isSameKit( + inventoryMode == InventoryMode.KIT_PRIMARIO ? gamer.getKit2() : gamer.getKit1(), + kit.getName())) { + lore.add(""); + lore.add("§cVocê ja escolheu este Kit."); + itens.add(new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } else { + + if (isOp) { + lore.add(""); + lore.add("§cEsta combinação de Kit está bloqueada."); + itens.add(new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } else { + lore.add(""); + lore.add("§eClique para selecionar."); + itens.add( + new MenuItem( + itemBuilder.type(kit.getIcon().getType()).name("§a" + kit.getName()) + .lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } + } + } else { + lore.add(""); + lore.add("§cVocê não possui este Kit."); + itens.add( + new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } + } + + lore.clear(); + lore = null; + } + + int pageStart = 0; + int pageEnd = ITEMS_PER_PAGE; + + if (page > 1) { + pageStart = ((page - 1) * ITEMS_PER_PAGE); + pageEnd = (page * ITEMS_PER_PAGE); + } + + if (pageEnd > itens.size()) { + pageEnd = itens.size(); + } + + if (page == 1) { + setItem(PREVIOUS_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPágina Anterior").build(), + (player, arg1, arg2, arg3, arg4) -> new KitSelector(player, page - 1, inventoryMode).open(player)), PREVIOUS_PAGE_SLOT); + } + + if ((itens.size() / ITEMS_PER_PAGE) + 1 <= page) { + setItem(NEXT_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPróxima Página").build(), + (player, arg1, arg2, arg3, arg4) -> new KitSelector(player, page + 1, inventoryMode).open(player)), NEXT_PAGE_SLOT); + } + + int kitSlot = 10; + + for (int i = pageStart; i < pageEnd; i++) { + setItem(itens.get(i), kitSlot); + + if (kitSlot % 9 == KITS_PER_ROW) { + kitSlot += 3; + continue; + } + + kitSlot += 1; + } + + if (itens.size() == 0) { + setItem(CENTER, itemBuilder.type(Material.REDSTONE_BLOCK).name("§c" + (inventoryMode == InventoryMode.LOJA ? + "Nenhum Kit para comprar!" : "Nenhum kit para selecionar!")).build()); + } + + itens.clear(); + kitList.clear(); + } + + public static boolean continuePlayer(final Player player, final String kit, final InventoryMode modo) { + if(modo == InventoryMode.KIT_PRIMARIO && HardcoreGamesOptions.DOUBLE_KIT) return true; + if(modo == InventoryMode.LOJA) return !KitManager.hasPermissionKit(player, kit, false); + return KitManager.hasPermissionKit(player, kit, false); + } + + private static class LojaKitsHandler implements MenuClickHandler { + + private Kit kit; + + public LojaKitsHandler(Kit kit) { + this.kit = kit; + } + + @Override + public void onClick(Player player, Inventory arg1, ClickType clickType, ItemStack arg3, int arg4) { + if (clickType != ClickType.LEFT) { + return; + } + + if(!continuePlayer(player, kit.getName(), InventoryMode.LOJA)) return; + player.closeInventory(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer.getInt(DataType.COINS) >= kit.getPrice()) { + bukkitPlayer.getDataHandler().getData(DataType.COINS).remove(kit.getPrice()); + bukkitPlayer.getDataHandler().saveCategory(DataCategory.ACCOUNT); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick(), bukkitPlayer.getUniqueId()).type(PacketType.BUKKIT_SEND_INFO). + field("add-perm").fieldValue("hg.kit." + kit.getName().toLowerCase())); + + player.sendMessage(StringUtils.VOCE_COMPROU_O_KIT.replace("%kit%", kit.getName())); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); + } else { + player.sendMessage(StringUtils.VOCE_NAO_TEM_COINS_O_SUFICIENTE_PARA_COMPRAR_O_KIT.replace("%valor%", + StringUtility.formatValue((kit.getPrice() - bukkitPlayer.getInt(DataType.COINS))))); + } + } + } + + private static class KitSelectHandler implements MenuClickHandler { + + private String kit; + private InventoryMode inventoryMode; + + public KitSelectHandler(String kit, InventoryMode inventoryMode) { + this.kit = kit; + this.inventoryMode = inventoryMode; + } + + @Override + public void onClick(Player player, Inventory arg1, ClickType clickType, ItemStack arg3, int arg4) { + if (clickType != ClickType.LEFT) { + return; + } + + player.closeInventory(); + player.performCommand("kit" + (inventoryMode == InventoryMode.KIT_PRIMARIO ? " " : "2 ") + kit); + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.java new file mode 100644 index 0000000..54979d5 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.hardcoregames.menu.enums; + +import lombok.Getter; + +public enum InventoryMode { + + KIT_PRIMARIO("Selecione um kit primário"), + KIT_SECUNDARIO("Selecione um kit secundário"), + LOJA("Loja de Kits"); + + @Getter + private String inventoryName; + + InventoryMode(String inventoryName) { + this.inventoryName = inventoryName; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.java new file mode 100644 index 0000000..a108bef --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.java @@ -0,0 +1,176 @@ +package com.br.guilhermematthew.nowly.hardcoregames.utility; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import com.br.guilhermematthew.nowly.hardcoregames.StringUtils; +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesOptions; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.hardcoregames.manager.gamer.GamerManager; + +public class HardcoreGamesUtility { + + @SuppressWarnings("deprecation") + public static int handleRelog(Player player, Location loc) { + List drop = new ArrayList<>(); + drop.addAll(Arrays.asList(player.getInventory().getContents())); + drop.addAll(Arrays.asList(player.getInventory().getArmorContents())); + drop.add(player.getItemOnCursor()); + + int taskID = Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(HardcoreGamesMain.getInstance(), + new Runnable() { + public void run() { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if ((!player.isOnline()) && (gamer.isRelogar())) { + gamer.setPlaying(false); + gamer.setEliminado(true); + gamer.setRelogar(false); + + PlayerAPI.dropItems(player, drop, loc); + + Bukkit.broadcastMessage(StringUtils.PLAYER_DEMOROU_PARA_RELOGAR + .replace("%nick%", player.getName()).replace("%kit%", gamer.getKit1()) + .replace("%restantes%", "" + GamerManager.getAliveGamers().size())); + + HardcoreGamesMain.getGameManager().getGameType().checkWin(); + + drop.clear(); + } + } + }, 20 * 45); + + return taskID; + } + + public static boolean availableToSpec(final Player player) { + if (HardcoreGamesOptions.SPEC_FREE_OPTION) return true; + if (!HardcoreGamesOptions.SPEC_OPTION) return false; + + return player.hasPermission("hungergames.espectar"); + } + + public static void strikeLightning(Location coords) { + coords.getWorld().strikeLightningEffect(coords); + + Block block = coords.getBlock(); + block.setType(Material.AIR); + + block = null; + } + + public static Location getRandomLocation(int maximo) { + int x = CommonsConst.RANDOM.nextInt(maximo) + maximo, + z = CommonsConst.RANDOM.nextInt(maximo) + maximo; + + if (CommonsConst.RANDOM.nextBoolean()) { + x = -x; + } + + if (CommonsConst.RANDOM.nextBoolean()) { + z = -z; + } + + final World world = (World) Bukkit.getServer().getWorlds().get(0); + + return new Location(world, x + 0.500, (world.getHighestBlockYAt(x, z) + 1), z + 0.500); + } + + public static Player getRandomPlayer(Player player) { + Player target = null; + + for (Player playerTarget : Bukkit.getOnlinePlayers()) { + Gamer gamer = GamerManager.getGamer(playerTarget.getUniqueId()); + + if (gamer != null) { + if (gamer.isPlaying()) { + if (playerTarget != null) { + if (!playerTarget.equals(player)) { + if (playerTarget.getLocation().distance(player.getLocation()) >= 15.0D) { + if (target == null) { + target = playerTarget; + } else { + double distanciaAtual = target.getLocation().distance(player.getLocation()); + double novaDistancia = playerTarget.getLocation().distance(player.getLocation()); + if (novaDistancia < distanciaAtual) { + target = playerTarget; + if (novaDistancia <= 50) { + break; + } + } + } + } + } + } + } + } + + gamer = null; + } + return target; + } + + public static void spawnRandomFirework(Location loc) { + Firework fireWork = (Firework)loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); + FireworkMeta fireWorkMeta = fireWork.getFireworkMeta(); + + Random r = CommonsConst.RANDOM; + + int rt = r.nextInt(4) + 3; + + FireworkEffect.Type fireWorkType = FireworkEffect.Type.BALL; + + if (rt == 1) { + fireWorkType = FireworkEffect.Type.BALL; + } else if (rt == 2) { + fireWorkType = FireworkEffect.Type.BALL_LARGE; + } else if (rt == 3) { + fireWorkType = FireworkEffect.Type.BURST; + } else if (rt == 4) { + fireWorkType = FireworkEffect.Type.CREEPER; + } else if (rt == 5) { + fireWorkType = FireworkEffect.Type.STAR; + } else if (rt > 5) { + fireWorkType = FireworkEffect.Type.BALL_LARGE; + } + + Color c1 = Color.RED; + Color c2 = Color.LIME; + Color c3 = Color.SILVER; + + FireworkEffect effect = FireworkEffect.builder().flicker( + r.nextBoolean()).withColor(c1).withColor(c2).withFade(c3).with(fireWorkType).trail(r.nextBoolean()).build(); + + fireWorkMeta.addEffect(effect); + + int rp = r.nextInt(2) + 1; + fireWorkMeta.setPower(rp); + fireWork.setFireworkMeta(fireWorkMeta); + + fireWork = null; + r = null; + fireWorkMeta = null; + fireWorkType = null; + c1 = null; + c2 = null; + c3 = null; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.java new file mode 100644 index 0000000..e1bb4e1 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.hardcoregames.utility; + +import java.util.List; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class InventoryStore { + + private String nome; + private ItemStack[] armor, inv; + private List potions; + + public InventoryStore(String nome, ItemStack[] armor, ItemStack[] inv, List potions) { + this.nome = nome; + this.armor = armor; + this.inv = inv; + this.potions = potions; + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.java new file mode 100644 index 0000000..0ac5a35 --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.java @@ -0,0 +1,245 @@ +package com.br.guilhermematthew.nowly.hardcoregames.utility.schematic; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.scheduler.BukkitTask; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.WorldEditAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.object.SchematicBlock; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.object.SchematicLocation; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Region; +import com.br.guilhermematthew.nowly.commons.bukkit.worldedit.schematic.utils.Vector; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.hardcoregames.manager.structures.StructuresManager; + +import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.NBTTagList; + +public class SchematicLoader { + + private final List blockList = new ArrayList<>(); + private final List locationList = new ArrayList<>(); + + private final Region region; + + private BukkitTask task; + + @SuppressWarnings("deprecation") + public SchematicLoader(Region region) { + this.region = region; + + World world = region.getWorld(); + Vector min = region.getMinLocation(); + Vector max = region.getMaxLocation(); + + //blocks ========================================================================================= + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { + for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { + for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { + Block block = world.getBlockAt(x, y, z); + Vector location = new Vector(x, y, z).subtract(min); + SchematicBlock schematicBlock = new SchematicBlock(location, block.getTypeId(), block.getData()); + blockList.add(schematicBlock); + } + } + } + } + + public SchematicLoader(String nome, File file) throws IOException { + FileInputStream stream = new FileInputStream(file); + + NBTTagCompound nbt = NBTCompressedStreamTools.a(stream); + + stream.close(); + + short width = nbt.getShort("Width"); + short height = nbt.getShort("Height"); + short length = nbt.getShort("Length"); + + int offsetX = nbt.getInt("WEOffsetX"); + int offsetY = nbt.getInt("WEOffsetY"); + int offsetZ = nbt.getInt("WEOffsetZ"); + Vector offset = new Vector(offsetX, offsetY, offsetZ); + + int originX = nbt.getInt("WEOriginX"); + int originY = nbt.getInt("WEOriginY"); + int originZ = nbt.getInt("WEOriginZ"); + Vector origin = new Vector(originX, originY, originZ); + + region = new Region(origin, offset, width, height, length); + + //blocks ========================================================================================= + byte[] blockId = nbt.getByteArray("Blocks"); + byte[] blockData = nbt.getByteArray("Data"); + + byte[] addId = new byte[0]; + short[] blocks = new short[blockId.length]; + + if (nbt.hasKey("AddBlocks")) { + addId = nbt.getByteArray("AddBlocks"); + } + + for (int index = 0; index < blockId.length; index++) { + if ((index >> 1) >= addId.length) { + blocks[index] = (short) (blockId[index] & 0xFF); + } else { + if ((index & 1) == 0) { + blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF)); + } else { + blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF)); + } + } + } + + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + for (int z = 0; z < length; ++z) { + int index = y * width * length + z * width + x; + SchematicBlock block = new SchematicBlock(new Vector(x, y, z), blocks[index], blockData[index]); + blockList.add(block); + } + } + } + + //locations ========================================================================================= + NBTTagList locations = nbt.getList("Locations", 8); + for (int i = 0; i < locations.size(); i++) { + SchematicLocation location = new SchematicLocation(locations.getString(i)); + locationList.add(location); + } + } + + public Region getRegion() { + return region; + } + + public void addLocation(SchematicLocation location) { + locationList.add(location); + } + + public List getConvertedLocation(String key, Location pasteLocation) { + List result = new ArrayList<>(); + for (SchematicLocation locations : locationList) { + if (locations.getKey().equals(key)) { + Vector vector = locations.getLocation().clone().add(new Vector(pasteLocation).add(region.getOffset()).subtract(region.getMinLocation())); + result.add(vector.toLocation(pasteLocation.getWorld())); + } + } + return result; + } + + public void paste(String nome, Location location, int bpt) { + Vector finalLocation = new Vector(location).add(region.getOffset()); + World world = location.getWorld(); + + pasteBlocks(nome, world, finalLocation, bpt, false); + } + + public void paste(String nome, Location location, int bpt, boolean force) { + Vector finalLocation = new Vector(location).add(region.getOffset()); + World world = location.getWorld(); + + pasteBlocks(nome, world, finalLocation, bpt, force); + } + + //blocks ========================================================================================= + @SuppressWarnings("deprecation") + private void pasteBlocks(String nome, World world, Vector pasteLocation, int bpt, boolean force) { + HardcoreGamesMain.console("Colando a Schematic '"+nome+"' forçado -> " + (force ? "Sim" : "Nao") + " com " + blockList.size() + " blocos a serem colados."); + + long started = System.currentTimeMillis(); + long startedNano = System.nanoTime(); + + if (force) { + Iterator iterator = blockList.iterator(); + + while (iterator.hasNext()) { + SchematicBlock schemBlock = iterator.next(); + Vector finalLocation = schemBlock.getLocation().clone().add(pasteLocation); + + WorldEditAPI.setAsyncBlock(world, new Location(world, finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()), + schemBlock.getID(), schemBlock.getData()); + + if (nome.equalsIgnoreCase("feast")) { + Block block = world.getBlockAt(finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()); + + if (schemBlock.getID() == 116) { + StructuresManager.getFeast().setEnchantmentTable(block.getLocation()); + block.setType(Material.AIR); + } else if ((block.getTypeId() == 54) || (block.getTypeId() == 146)) { + block.setType(Material.AIR); + StructuresManager.getFeast().addChest(block); + } + } else if (nome.equalsIgnoreCase("minifeast")) { + Block block = world.getBlockAt(finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()); + + if ((block.getTypeId() == 54) || (block.getTypeId() == 146)) { + block.setType(Material.CHEST); + StructuresManager.addItensChestMinifeast(((Chest) block.getLocation().getBlock().getState())); + } + } + + iterator.remove(); + } + return; + } + + task = Bukkit.getScheduler().runTaskTimer(BukkitMain.getInstance(), () -> { + + Iterator iterator = blockList.iterator(); + + for (int i = 0; i < bpt; i++) { + if (!iterator.hasNext()) { + HardcoreGamesMain.console("Schematic '"+nome+"' colada em -> " + DateUtils.getElapsed(started, startedNano)); + task.cancel(); + break; + } + + SchematicBlock schemBlock = iterator.next(); + Vector finalLocation = schemBlock.getLocation().clone().add(pasteLocation); + + WorldEditAPI.setAsyncBlock(world, new Location(world, finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()), + schemBlock.getID(), schemBlock.getData()); + + if (nome.equalsIgnoreCase("feast")) { + Block block = world.getBlockAt(finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()); + + if (schemBlock.getID() == 116) { + StructuresManager.getFeast().setEnchantmentTable(block.getLocation()); + block.setType(Material.AIR); + } else if ((block.getTypeId() == 54) || (block.getTypeId() == 146)) { + block.setType(Material.AIR); + StructuresManager.getFeast().addChest(block); + } + } else if (nome.equalsIgnoreCase("minifeast")) { + Block block = world.getBlockAt(finalLocation.getBlockX(), finalLocation.getBlockY(), finalLocation.getBlockZ()); + + if ((block.getTypeId() == 54) || (block.getTypeId() == 146)) { + block.setType(Material.CHEST); + StructuresManager.addItensChestMinifeast(((Chest) block.getLocation().getBlock().getState())); + } + } + iterator.remove(); + } + }, 0L, 1L); + } + + @SuppressWarnings("deprecation") + public void setBlock(World world, int x, int y, int z, int id, byte data) { + world.getBlockAt(x, y, z).setTypeIdAndData(id, data, false); + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.java b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.java new file mode 100644 index 0000000..b0980af --- /dev/null +++ b/hardcoregames/src/main/java/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.java @@ -0,0 +1,47 @@ +package com.br.guilhermematthew.nowly.hardcoregames.utility.schematic; + +import java.io.File; +import java.io.IOException; + +import com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain; +import org.bukkit.Location; + +import com.br.guilhermematthew.nowly.commons.common.utility.system.Machine; + +public class SchematicUtility { + + public static void spawnarSchematic(String nome, Location loc, boolean force) { + File dir = new File(Machine.getDiretorio() + Machine.getSeparador() + "schematics"); + if (!dir.exists()) { + dir.mkdir(); + } + + File file = new File(Machine.getDiretorio() + Machine.getSeparador() + "schematics", nome + ".schematic"); + + if (file.exists()) { + SchematicLoader schematic; + + HardcoreGamesMain.console("Tentando carregar a schematic '"+nome+"'..."); + + try { + schematic = new SchematicLoader(nome, file); + + schematic.paste(nome, loc, getBlockSpeed(nome), force); + } catch (IOException e) { + HardcoreGamesMain.console("Ocorreu um erro ao tentar carregar a schematic '"+nome+"' -> " + e.getLocalizedMessage()); + } + } else { + HardcoreGamesMain.console("SchematicLoader '"+nome+"' nao existe."); + } + } + + private static int getBlockSpeed(String type) { + if (type.equalsIgnoreCase("feast")) { + return 100; + } else if (type.equalsIgnoreCase("minifeast")) { + return 150; + } else { + return 100; + } + } +} \ No newline at end of file diff --git a/hardcoregames/src/main/resources/config.yml b/hardcoregames/src/main/resources/config.yml new file mode 100644 index 0000000..89f46b0 --- /dev/null +++ b/hardcoregames/src/main/resources/config.yml @@ -0,0 +1,4 @@ +# Por favor, coloque o valor (true ou false) em minusculo. +# Valores: true | false + +DOUBLE_KIT: 'false' diff --git a/hardcoregames/src/main/resources/plugin.yml b/hardcoregames/src/main/resources/plugin.yml new file mode 100644 index 0000000..d1a6d29 --- /dev/null +++ b/hardcoregames/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: HG +main: com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.class new file mode 100644 index 0000000..73d9088 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesMain.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.class new file mode 100644 index 0000000..046858f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/HardcoreGamesOptions.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.class new file mode 100644 index 0000000..829fbe2 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/StringUtils.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.class new file mode 100644 index 0000000..3477d47 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/Kit.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.class new file mode 100644 index 0000000..28597d0 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Achilles.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.class new file mode 100644 index 0000000..962b535 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Anchor.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.class new file mode 100644 index 0000000..7183bd4 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Barbarian.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.class new file mode 100644 index 0000000..eced849 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Berserker.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.class new file mode 100644 index 0000000..6148530 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Blink.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.class new file mode 100644 index 0000000..1a86749 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Boxer.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.class new file mode 100644 index 0000000..abb3730 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cannibal.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.class new file mode 100644 index 0000000..71246cd Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Checkpoint.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.class new file mode 100644 index 0000000..a823e54 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Cultivator.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.class new file mode 100644 index 0000000..b662905 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Demoman.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger$1.class new file mode 100644 index 0000000..11b425f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.class new file mode 100644 index 0000000..f640162 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Digger.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage$1.class new file mode 100644 index 0000000..d7afbbb Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.class new file mode 100644 index 0000000..87fd13a Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Endermage.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.class new file mode 100644 index 0000000..450639a Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fireman.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.class new file mode 100644 index 0000000..9cba8e9 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Fisherman.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.class new file mode 100644 index 0000000..c490565 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Forger.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.class new file mode 100644 index 0000000..8195447 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Gladiator.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.class new file mode 100644 index 0000000..3a73977 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grandpa.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler$Cordinha.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler$Cordinha.class new file mode 100644 index 0000000..716b053 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler$Cordinha.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.class new file mode 100644 index 0000000..becfb0b Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Grappler.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.class new file mode 100644 index 0000000..dfa9c2d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Hulk.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.class new file mode 100644 index 0000000..5622b29 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ironman.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer$1.class new file mode 100644 index 0000000..f9cd661 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.class new file mode 100644 index 0000000..be9dfa6 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/JackHammer.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.class new file mode 100644 index 0000000..aae0783 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Kangaroo.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.class new file mode 100644 index 0000000..df49a44 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Launcher.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.class new file mode 100644 index 0000000..574a7ec Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/LumberJack.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.class new file mode 100644 index 0000000..564e2bd Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Madman.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.class new file mode 100644 index 0000000..4577cac Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Magma.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.class new file mode 100644 index 0000000..02fb82f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Miner.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.class new file mode 100644 index 0000000..ab4dac4 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Monk.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.class new file mode 100644 index 0000000..7b3506e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Neo.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja$NinjaHit.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja$NinjaHit.class new file mode 100644 index 0000000..f5999d1 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja$NinjaHit.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.class new file mode 100644 index 0000000..f8a4509 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Ninja.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.class new file mode 100644 index 0000000..c4a3009 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Noob.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.class new file mode 100644 index 0000000..9fb5c48 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Phantom.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.class new file mode 100644 index 0000000..eb7e80f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Poseidon.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.class new file mode 100644 index 0000000..c60fad5 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Pyro.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.class new file mode 100644 index 0000000..81a078e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Scout.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.class new file mode 100644 index 0000000..0e4c712 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Snail.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.class new file mode 100644 index 0000000..1d038a4 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Specialist.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.class new file mode 100644 index 0000000..ccee50e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Stomper.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.class new file mode 100644 index 0000000..f1e229a Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Surprise.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.class new file mode 100644 index 0000000..9ddce2d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Switcher.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.class new file mode 100644 index 0000000..e8f352b Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Tank.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.class new file mode 100644 index 0000000..a559aba Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Thor.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.class new file mode 100644 index 0000000..9b24a2a Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viking.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.class new file mode 100644 index 0000000..31c5f21 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Viper.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.class new file mode 100644 index 0000000..5c1cb70 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/WeakHand.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.class new file mode 100644 index 0000000..327d155 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/register/Worm.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.class new file mode 100644 index 0000000..3349cc1 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/ability/utility/GladiatorFight.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.class new file mode 100644 index 0000000..40b9855 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/base/GameType.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.class new file mode 100644 index 0000000..75eb028 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/ChampionsCommand.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.class new file mode 100644 index 0000000..141896f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/PlayerCommand.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand$1.class new file mode 100644 index 0000000..7a10a5f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.class new file mode 100644 index 0000000..c327da7 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/commands/StafferCommand.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.class new file mode 100644 index 0000000..d0538b9 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameInvincibilityEndEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.class new file mode 100644 index 0000000..dbbf9f0 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStageChangeEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.class new file mode 100644 index 0000000..5548533 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameStartedEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.class new file mode 100644 index 0000000..1567c07 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/game/GameTimerEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent$CompassAction.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent$CompassAction.class new file mode 100644 index 0000000..38eb374 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent$CompassAction.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.class new file mode 100644 index 0000000..b8b7114 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerCompassEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.class new file mode 100644 index 0000000..b68690e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerDamagePlayerEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.class new file mode 100644 index 0000000..b7d0bb1 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerRegisterKitEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent$SpectateAction.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent$SpectateAction.class new file mode 100644 index 0000000..510b741 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent$SpectateAction.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.class new file mode 100644 index 0000000..629abe4 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/events/player/PlayerSpectateEvent.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.class new file mode 100644 index 0000000..7084702 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/GameManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType$1.class new file mode 100644 index 0000000..a6f27ff Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.class new file mode 100644 index 0000000..3b5c2c3 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/AutomaticEventType.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.class new file mode 100644 index 0000000..c4ba72c Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/ClanType.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.class new file mode 100644 index 0000000..a44088d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/game/types/NormalType.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.class new file mode 100644 index 0000000..df023e3 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/BorderListener.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.class new file mode 100644 index 0000000..a5b7ff2 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/EndListener.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener$1.class new file mode 100644 index 0000000..ad203f4 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.class new file mode 100644 index 0000000..d62ce4c Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GameListener.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.class new file mode 100644 index 0000000..fbecf4e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/GeneralListeners.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.class new file mode 100644 index 0000000..2845444 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/InvincibilityListener.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.class new file mode 100644 index 0000000..dd6ed06 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/PreGameListeners.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.class new file mode 100644 index 0000000..4519adf Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/ScoreboardListeners.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.class new file mode 100644 index 0000000..161ff97 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/SpectatorListener.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.class new file mode 100644 index 0000000..b6a612d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/listeners/StringUtils.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager$CombatLog.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager$CombatLog.class new file mode 100644 index 0000000..a9cd12c Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager$CombatLog.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.class new file mode 100644 index 0000000..c6ce3f5 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/combatlog/CombatLogManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.class new file mode 100644 index 0000000..10abffa Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/Gamer.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.class new file mode 100644 index 0000000..dfe1a74 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/gamer/GamerManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.class new file mode 100644 index 0000000..5d92c27 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitLoader.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.class new file mode 100644 index 0000000..409d8f3 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/kit/KitManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.class new file mode 100644 index 0000000..1634473 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/HardcoreGamesScoreboard.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.class new file mode 100644 index 0000000..3e95419 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/ScoreboardCommon.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.class new file mode 100644 index 0000000..8233692 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/ChampionsScoreboard.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.class new file mode 100644 index 0000000..182ca34 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/DoubleKitScoreboard.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.class new file mode 100644 index 0000000..5c5e7b2 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/scoreboard/types/SingleKitScoreboard.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.class new file mode 100644 index 0000000..3793e5e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/StructuresManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$1.class new file mode 100644 index 0000000..a391a1f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$2.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$2.class new file mode 100644 index 0000000..77612a0 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast$2.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.class new file mode 100644 index 0000000..50c1f12 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/Feast.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle$1.class new file mode 100644 index 0000000..b203206 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.class new file mode 100644 index 0000000..5501eac Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/FinalBattle.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.class new file mode 100644 index 0000000..a04912e Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/structures/types/MiniFeast.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager$1.class new file mode 100644 index 0000000..70f6ba3 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.class new file mode 100644 index 0000000..a33551c Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerManager.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.class new file mode 100644 index 0000000..e66b54f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/manager/timer/TimerType.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$1.class new file mode 100644 index 0000000..a85345d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$ClickHandler.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$ClickHandler.class new file mode 100644 index 0000000..369b18f Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers$ClickHandler.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.class new file mode 100644 index 0000000..f28a443 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/AliveGamers.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$KitSelectHandler.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$KitSelectHandler.class new file mode 100644 index 0000000..925aa32 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$KitSelectHandler.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$LojaKitsHandler.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$LojaKitsHandler.class new file mode 100644 index 0000000..5e5a7ff Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector$LojaKitsHandler.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.class new file mode 100644 index 0000000..216746d Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/KitSelector.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.class new file mode 100644 index 0000000..d9016bd Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/menu/enums/InventoryMode.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility$1.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility$1.class new file mode 100644 index 0000000..a17eea2 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility$1.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.class new file mode 100644 index 0000000..edade22 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/HardcoreGamesUtility.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.class new file mode 100644 index 0000000..8f3b555 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/InventoryStore.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.class new file mode 100644 index 0000000..cf22bf9 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicLoader.class differ diff --git a/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.class b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.class new file mode 100644 index 0000000..6647b37 Binary files /dev/null and b/hardcoregames/target/classes/com/br/guilhermematthew/nowly/hardcoregames/utility/schematic/SchematicUtility.class differ diff --git a/hardcoregames/target/classes/config.yml b/hardcoregames/target/classes/config.yml new file mode 100644 index 0000000..89f46b0 --- /dev/null +++ b/hardcoregames/target/classes/config.yml @@ -0,0 +1,4 @@ +# Por favor, coloque o valor (true ou false) em minusculo. +# Valores: true | false + +DOUBLE_KIT: 'false' diff --git a/hardcoregames/target/classes/plugin.yml b/hardcoregames/target/classes/plugin.yml new file mode 100644 index 0000000..d1a6d29 --- /dev/null +++ b/hardcoregames/target/classes/plugin.yml @@ -0,0 +1,5 @@ +name: HG +main: com.br.guilhermematthew.nowly.hardcoregames.HardcoreGamesMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/hardcoregames/target/hardcoregames-1.0-SNAPSHOT.jar b/hardcoregames/target/hardcoregames-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..3a0a1ce Binary files /dev/null and b/hardcoregames/target/hardcoregames-1.0-SNAPSHOT.jar differ diff --git a/hardcoregames/target/maven-archiver/pom.properties b/hardcoregames/target/maven-archiver/pom.properties new file mode 100644 index 0000000..51536fd --- /dev/null +++ b/hardcoregames/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Sun Feb 26 00:11:11 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=hardcoregames diff --git a/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..9d91880 --- /dev/null +++ b/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,119 @@ +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Viper.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Phantom.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\MiniFeast.class +com\br\guilhermematthew\nowly\hardcoregames\manager\timer\TimerManager$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Tank.class +com\br\guilhermematthew\nowly\hardcoregames\commands\PlayerCommand.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\StringUtils.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerCompassEvent$CompassAction.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Viking.class +com\br\guilhermematthew\nowly\hardcoregames\game\types\AutomaticEventType$1.class +com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\ScoreboardCommon.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Gladiator.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Cannibal.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Digger$1.class +com\br\guilhermematthew\nowly\hardcoregames\manager\combatlog\CombatLogManager$CombatLog.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Miner.class +com\br\guilhermematthew\nowly\hardcoregames\game\types\NormalType.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Kangaroo.class +com\br\guilhermematthew\nowly\hardcoregames\menu\KitSelector$LojaKitsHandler.class +com\br\guilhermematthew\nowly\hardcoregames\manager\timer\TimerManager.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Launcher.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerSpectateEvent$SpectateAction.class +com\br\guilhermematthew\nowly\hardcoregames\menu\AliveGamers$ClickHandler.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Pyro.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Ninja$NinjaHit.class +com\br\guilhermematthew\nowly\hardcoregames\base\GameType.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Cultivator.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Fireman.class +com\br\guilhermematthew\nowly\hardcoregames\commands\ChampionsCommand.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Thor.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Fisherman.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Specialist.class +com\br\guilhermematthew\nowly\hardcoregames\ability\Kit.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Grandpa.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\JackHammer.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Noob.class +com\br\guilhermematthew\nowly\hardcoregames\events\game\GameStartedEvent.class +com\br\guilhermematthew\nowly\hardcoregames\events\game\GameStageChangeEvent.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Digger.class +com\br\guilhermematthew\nowly\hardcoregames\events\game\GameInvincibilityEndEvent.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\InvincibilityListener.class +com\br\guilhermematthew\nowly\hardcoregames\ability\utility\GladiatorFight.class +com\br\guilhermematthew\nowly\hardcoregames\manager\gamer\GamerManager.class +com\br\guilhermematthew\nowly\hardcoregames\commands\StafferCommand$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Grappler.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\FinalBattle.class +com\br\guilhermematthew\nowly\hardcoregames\StringUtils.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Ninja.class +com\br\guilhermematthew\nowly\hardcoregames\manager\kit\KitManager.class +com\br\guilhermematthew\nowly\hardcoregames\events\game\GameTimerEvent.class +com\br\guilhermematthew\nowly\hardcoregames\menu\KitSelector$KitSelectHandler.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Surprise.class +com\br\guilhermematthew\nowly\hardcoregames\HardcoreGamesMain.class +com\br\guilhermematthew\nowly\hardcoregames\utility\HardcoreGamesUtility.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Checkpoint.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Poseidon.class +com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\types\ChampionsScoreboard.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\SpectatorListener.class +com\br\guilhermematthew\nowly\hardcoregames\manager\gamer\Gamer.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\BorderListener.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\GeneralListeners.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Forger.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Anchor.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerSpectateEvent.class +com\br\guilhermematthew\nowly\hardcoregames\menu\AliveGamers$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Blink.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Madman.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Demoman.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Monk.class +com\br\guilhermematthew\nowly\hardcoregames\utility\HardcoreGamesUtility$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Grappler$Cordinha.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\JackHammer$1.class +com\br\guilhermematthew\nowly\hardcoregames\game\GameManager.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\GameListener$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\WeakHand.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\PreGameListeners.class +com\br\guilhermematthew\nowly\hardcoregames\manager\timer\TimerType.class +com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\HardcoreGamesScoreboard.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\Feast.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Endermage$1.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Neo.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\Feast$2.class +com\br\guilhermematthew\nowly\hardcoregames\menu\KitSelector.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\ScoreboardListeners.class +com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\types\SingleKitScoreboard.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Snail.class +com\br\guilhermematthew\nowly\hardcoregames\manager\kit\KitLoader.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\StructuresManager.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\EndListener.class +com\br\guilhermematthew\nowly\hardcoregames\game\types\ClanType.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Achilles.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Stomper.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Boxer.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Scout.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Endermage.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Worm.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\FinalBattle$1.class +com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\Feast$1.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerDamagePlayerEvent.class +com\br\guilhermematthew\nowly\hardcoregames\manager\combatlog\CombatLogManager.class +com\br\guilhermematthew\nowly\hardcoregames\menu\AliveGamers.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Hulk.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Ironman.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Barbarian.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerCompassEvent.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Switcher.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Magma.class +com\br\guilhermematthew\nowly\hardcoregames\utility\schematic\SchematicLoader.class +com\br\guilhermematthew\nowly\hardcoregames\listeners\GameListener.class +com\br\guilhermematthew\nowly\hardcoregames\commands\StafferCommand.class +com\br\guilhermematthew\nowly\hardcoregames\menu\enums\InventoryMode.class +com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\types\DoubleKitScoreboard.class +com\br\guilhermematthew\nowly\hardcoregames\utility\schematic\SchematicUtility.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\LumberJack.class +com\br\guilhermematthew\nowly\hardcoregames\utility\InventoryStore.class +com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerRegisterKitEvent.class +com\br\guilhermematthew\nowly\hardcoregames\HardcoreGamesOptions.class +com\br\guilhermematthew\nowly\hardcoregames\ability\register\Berserker.class +com\br\guilhermematthew\nowly\hardcoregames\game\types\AutomaticEventType.class diff --git a/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..45e006a --- /dev/null +++ b/hardcoregames/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,92 @@ +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Hulk.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Launcher.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Viking.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\commands\StafferCommand.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\Kit.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\WeakHand.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\utility\GladiatorFight.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\game\types\ClanType.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\ScoreboardCommon.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\utility\schematic\SchematicLoader.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\game\GameStartedEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\HardcoreGamesScoreboard.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\StringUtils.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Checkpoint.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Digger.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\InvincibilityListener.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\utility\InventoryStore.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Grappler.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\game\types\NormalType.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerSpectateEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Anchor.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Blink.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Switcher.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\timer\TimerType.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Phantom.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\utility\HardcoreGamesUtility.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Cannibal.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Miner.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\SpectatorListener.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\kit\KitManager.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Thor.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Achilles.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\MiniFeast.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\EndListener.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\game\GameInvincibilityEndEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Cultivator.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\game\GameManager.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Poseidon.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\commands\PlayerCommand.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\game\GameTimerEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Demoman.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Monk.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\ScoreboardListeners.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Fireman.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Worm.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerCompassEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\game\GameStageChangeEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\FinalBattle.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Endermage.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\PreGameListeners.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Gladiator.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Stomper.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\types\SingleKitScoreboard.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Fisherman.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\gamer\GamerManager.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerDamagePlayerEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\structures\StructuresManager.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Forger.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Ninja.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\menu\enums\InventoryMode.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Surprise.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\combatlog\CombatLogManager.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\kit\KitLoader.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Madman.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\HardcoreGamesOptions.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\utility\schematic\SchematicUtility.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Specialist.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\JackHammer.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Tank.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Boxer.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\game\types\AutomaticEventType.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Viper.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\GeneralListeners.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\structures\types\Feast.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Snail.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\gamer\Gamer.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Kangaroo.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Pyro.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Grandpa.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\menu\AliveGamers.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Magma.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\menu\KitSelector.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\scoreboard\types\DoubleKitScoreboard.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\BorderListener.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\events\player\PlayerRegisterKitEvent.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\base\GameType.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\LumberJack.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\HardcoreGamesMain.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\listeners\GameListener.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Barbarian.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\ability\register\Ironman.java +C:\source\dustmc\hardcoregames\src\main\java\com\br\guilhermematthew\nowly\hardcoregames\manager\timer\TimerManager.java diff --git a/hardcoregames/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/hardcoregames/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/lobby/.classpath b/lobby/.classpath new file mode 100644 index 0000000..002ad57 --- /dev/null +++ b/lobby/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lobby/.idea/.gitignore b/lobby/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/lobby/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/lobby/.idea/compiler.xml b/lobby/.idea/compiler.xml new file mode 100644 index 0000000..6121df3 --- /dev/null +++ b/lobby/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lobby/.idea/gradle.xml b/lobby/.idea/gradle.xml new file mode 100644 index 0000000..cabf132 --- /dev/null +++ b/lobby/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/lobby/.idea/jarRepositories.xml b/lobby/.idea/jarRepositories.xml new file mode 100644 index 0000000..e284c41 --- /dev/null +++ b/lobby/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/lobby/.idea/misc.xml b/lobby/.idea/misc.xml new file mode 100644 index 0000000..f6a4583 --- /dev/null +++ b/lobby/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/lobby/.idea/modules/lobby.main.iml b/lobby/.idea/modules/lobby.main.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/lobby/.idea/modules/lobby.main.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/lobby/.project b/lobby/.project new file mode 100644 index 0000000..8dc1556 --- /dev/null +++ b/lobby/.project @@ -0,0 +1,23 @@ + + + lobby + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/lobby/.settings/org.eclipse.jdt.core.prefs b/lobby/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/lobby/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/lobby/.settings/org.eclipse.m2e.core.prefs b/lobby/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/lobby/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/lobby/pom.xml b/lobby/pom.xml new file mode 100644 index 0000000..631e6b3 --- /dev/null +++ b/lobby/pom.xml @@ -0,0 +1,29 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + lobby + + + 8 + 8 + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + system + D:/Users/zFros/Desktop/[SRC]/☕ - Java/Dust/commons/target/commons-1.0-SNAPSHOT.jar + + + + \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/LobbyMain.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/LobbyMain.java new file mode 100644 index 0000000..d550436 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/LobbyMain.java @@ -0,0 +1,135 @@ +package com.br.guilhermematthew.nowly.lobby; + +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardInstance; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.plugin.java.JavaPlugin; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandFramework; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerLoadedEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.loader.BukkitListeners; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.lobby.common.hologram.HologramCommon; +import com.br.guilhermematthew.nowly.lobby.common.hologram.types.LobbyHGHologram; +import com.br.guilhermematthew.nowly.lobby.common.hologram.types.LobbyPvPHologram; +import com.br.guilhermematthew.nowly.lobby.common.npcs.NPCCommon; +import com.br.guilhermematthew.nowly.lobby.common.npcs.types.LobbyHGNPC; +import com.br.guilhermematthew.nowly.lobby.common.npcs.types.LobbyNPC; +import com.br.guilhermematthew.nowly.lobby.common.npcs.types.LobbyPvPNPC; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardCommon; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.types.LobbyHGScoreboard; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.types.LobbyPvPScoreboard; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.types.LobbyScoreboard; + +import lombok.Getter; +import lombok.Setter; + +public class LobbyMain extends JavaPlugin { + + @Getter @Setter + private static LobbyMain instance; + + @Getter @Setter + private static Location spawn; + + @Getter @Setter + private static ScoreboardCommon scoreBoardCommon; + @Getter @Setter + private static LobbyScoreboard lobbyBoardCommon; + + @Getter @Setter + private static NPCCommon npcCommon; + + @Getter @Setter + private static ScoreboardInstance scoreboardInstance; + + @Getter @Setter + private static HologramCommon hologramCommon; + + public void onLoad() { + setInstance(this); + + saveDefaultConfig(); + } + + public void onEnable() { + if (CommonsGeneral.correctlyStarted()) { + BukkitServerAPI.registerServer(); + + Bukkit.setDefaultGameMode(GameMode.ADVENTURE); + setScoreboardInstance(new ScoreboardInstance()); + CommonsGeneral.getServersManager().init(); + + BukkitListeners.loadListeners(getInstance(), "com.br.guilhermematthew.nowly.lobby.listeners"); + BukkitCommandFramework.INSTANCE.loadCommands(getInstance(), "com.br.guilhermematthew.nowly.lobby.commands"); + + BukkitMain.getManager().enablePacketInjector(this); + BukkitMain.getManager().enableHologram(this); + BukkitMain.getManager().enableNPC(this); + + setSpawn(PluginConfiguration.createLocation(getInstance(), "spawn")); + + setScoreBoardCommon( + BukkitMain.getServerType() == ServerType.LOBBY ? new LobbyScoreboard() : + BukkitMain.getServerType() == ServerType.LOBBY_PVP ? new LobbyPvPScoreboard() : + BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES ? new LobbyHGScoreboard() : null); + + if (getScoreBoardCommon() == null) { + console("Nao foi encontrada o padrao da ScoreboardCommon."); + } + + setNpcCommon( + BukkitMain.getServerType() == ServerType.LOBBY ? new LobbyNPC() : + BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES ? new LobbyHGNPC() : + BukkitMain.getServerType() == ServerType.LOBBY_PVP ? new LobbyPvPNPC() : null); + + if (getNpcCommon() == null) { + console("Nao foi encontrado o padrao do NPCCommon."); + } else { + getNpcCommon().create(); + } + + setHologramCommon( + BukkitMain.getServerType() == ServerType.LOBBY ? null : + BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES ? new LobbyHGHologram() : + BukkitMain.getServerType() == ServerType.LOBBY_PVP ? new LobbyPvPHologram() : null); + + if (getHologramCommon() == null) { + console("Nao foi encontrado o padrao do HologramCommon."); + } else { + getHologramCommon().create(); + } + + runLater(() -> { + getServer().getPluginManager().callEvent(new ServerLoadedEvent()); + }, BukkitMain.getServerType().getSecondsToStabilize()); + } else { + Bukkit.shutdown(); + } + } + + public void onDisable() { + + } + + public static void console(String msg) { + Bukkit.getConsoleSender().sendMessage("[Lobby] " + msg); + } + + public static void runAsync(Runnable runnable) { + Bukkit.getScheduler().runTaskAsynchronously(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, 5L); + } + + public static void runLater(Runnable runnable, long ticks) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, ticks); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.java new file mode 100644 index 0000000..4bd379e --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.java @@ -0,0 +1,112 @@ +package com.br.guilhermematthew.nowly.lobby.commands; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; + +public class ServerCommand implements CommandClass { + + public static ArrayList autorizados = new ArrayList<>(); + + private final List bots = Arrays.asList("hg", "evento", "quartel", "pvp", "duels", + "arena", "fps", "lavachallenge"); + + private final List holograms = Arrays.asList("kills", "killstreak", "wins", "killsevent", "winsevent"); + + @Command(name = "setloc", groupsToUse= {Groups.ADMIN}) + public void setloc(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + sendHelp(commandSender); + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 1) { + if (args[0].equalsIgnoreCase("spawn")) { + PluginConfiguration.setLocation(LobbyMain.getInstance(), "spawn", player); + LobbyMain.setSpawn(PluginConfiguration.getLocation(LobbyMain.getInstance(), "spawn")); + commandSender.sendMessage("§aSpawn setado!"); + } else { + sendHelp(commandSender); + } + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("bot")) { + if (isBot(args[1])) { + String botName = args[1].toLowerCase(); + PluginConfiguration.setLocation(LobbyMain.getInstance(), "bots." + botName, player); + player.sendMessage("§aLocal do bot setado."); + } else { + commandSender.sendMessage("§cBot năo encontrado."); + } + } else if (args[0].equalsIgnoreCase("hologramas")) { + if (isHologram(args[1])) { + String name = args[1]; + PluginConfiguration.setLocation(LobbyMain.getInstance(), "hologramas." + name.toLowerCase(), player); + player.sendMessage("§aHolograma setado, é preciso reiniciar o servidor para aplicar o novo local."); + } else { + commandSender.sendMessage("§cHolograma inválido."); + } + } else { + sendHelp(commandSender); + } + } else { + sendHelp(commandSender); + } + + player = null; + } + + private void sendHelp(BukkitCommandSender commandSender) { + commandSender.sendMessage(""); + commandSender.sendMessage("§cUse: /setloc spawn"); + commandSender.sendMessage("§cUse: /setloc bot <" + StringUtility.formatArrayToString(bots, true) + ">"); + commandSender.sendMessage("§cUse: /setloc hologramas <" + StringUtility.formatArrayToString(holograms, true) + ">"); + commandSender.sendMessage(""); + } + + @Command(name = "build", aliases= {"b"}, groupsToUse= {Groups.ADMIN}) + public void build(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (autorizados.contains(player.getUniqueId())) { + autorizados.remove(player.getUniqueId()); + player.sendMessage("§aVocę desativou o modo construçăo."); + player.setGameMode(GameMode.ADVENTURE); + } else { + autorizados.add(player.getUniqueId()); + player.sendMessage("§aVocę ativou o modo construçăo."); + player.setGameMode(GameMode.CREATIVE); + } + + player = null; + } + + public boolean isBot(String name) { + return bots.contains(name.toLowerCase()); + } + + public boolean isHologram(String name) { + return holograms.contains(name.toLowerCase()); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.java new file mode 100644 index 0000000..28a4aa1 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.java @@ -0,0 +1,68 @@ +package com.br.guilhermematthew.nowly.lobby.common; + +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.NetworkServer; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; + +public class LobbyUtility { + + public static void handleInteract(Player player, ServerType serverClicked, ServerType serverConnected) { + if (serverClicked != ServerType.UNKNOWN) { + if (serverConnected != ServerType.LOBBY) { + if (serverClicked == ServerType.HARDCORE_GAMES) { + InventoryCommon.getHardcoreGamesInventory().open(player); + } else if (serverClicked == ServerType.BEDWARS) { + //abrir menu + player.sendMessage("§cEm breve..."); + } else if (serverClicked == ServerType.THEBRIDGE) { + //abrir menu + player.sendMessage("§cEm breve..."); + } else if (serverClicked == ServerType.SKYWARS) { + //abrir menu + player.sendMessage("§cEm breve..."); + } else if (serverClicked == ServerType.EVENTO || serverClicked == ServerType.CHAMPIONS) { + if (CommonsGeneral.getServersManager().getNetworkServer(serverClicked.getName()).isOnline()) { + BukkitServerAPI.redirectPlayer(player, serverClicked.getName()); + } else { + player.sendMessage("§cNenhuma sala disponivel no momento."); + } + } else { + checkAndConnect(player, serverClicked.getName()); + } + } else { + checkAndConnect(player, serverClicked.getName()); + } + } else { + player.sendMessage("§cEm breve."); + } + } + + private static void checkAndConnect(Player player, String serverName) { + NetworkServer server = CommonsGeneral.getServersManager().getNetworkServer(serverName); + + if (server != null) { + if (server.isOnline()) { + boolean connect = true; + + if (server.getOnlines() >= server.getMembersSlots()) { + if (!player.hasPermission("commons.entrar")) { + connect = false; + player.sendMessage("§cOs slots para membros acabaram."); + } + } + + if (connect) { + BukkitServerAPI.redirectPlayer(player, serverName); + } + } else { + player.sendMessage("§cNenhuma sala disponivel no momento."); + } + } else { + + } + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.java new file mode 100644 index 0000000..6f816d2 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.java @@ -0,0 +1,7 @@ +package com.br.guilhermematthew.nowly.lobby.common.hologram; + +public abstract class HologramCommon { + + public abstract void create(); + public abstract void update(); +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.java new file mode 100644 index 0000000..568842f --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.lobby.common.hologram.types; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.types.SimpleHologram; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.hologram.HologramCommon; + +import lombok.Getter; + +public class LobbyHGHologram extends HologramCommon { + + @Getter + private SimpleHologram kills, wins, killsEvent, winsEvent; + + @Override + public void create() { + this.kills = new SimpleHologram("kills", "KILLS HG", DataCategory.HARDCORE_GAMES, DataType.HG_KILLS, LobbyMain.getInstance()); + this.wins = new SimpleHologram("wins", "WINS HG", DataCategory.HARDCORE_GAMES, DataType.HG_WINS, LobbyMain.getInstance()); + + this.killsEvent = new SimpleHologram("killsEvent", "KILLS SET-HG", DataCategory.HARDCORE_GAMES, DataType.HG_EVENT_KILLS, LobbyMain.getInstance()); + this.winsEvent = new SimpleHologram("winsEvent", "WINS SET-HG", DataCategory.HARDCORE_GAMES, DataType.HG_EVENT_WINS, LobbyMain.getInstance()); + + this.kills.create(); + this.wins.create(); + + this.winsEvent.create(); + this.killsEvent.create(); + + update(); + } + + public void update() { + this.kills.updateValues(); + this.wins.updateValues(); + + this.killsEvent.updateValues(); + this.winsEvent.updateValues(); + } + + public void recreate() { + + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.java new file mode 100644 index 0000000..672a342 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.java @@ -0,0 +1,31 @@ +package com.br.guilhermematthew.nowly.lobby.common.hologram.types; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.types.SimpleHologram; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.hologram.HologramCommon; + +import lombok.Getter; + +public class LobbyPvPHologram extends HologramCommon { + + @Getter + private SimpleHologram kills, maxKillStreak; + + @Override + public void create() { + this.kills = new SimpleHologram("kills", "ARENA KILLS", DataCategory.KITPVP, DataType.PVP_KILLS, LobbyMain.getInstance()); + this.maxKillStreak = new SimpleHologram("killstreak", "ARENA MAXSTREAKS", DataCategory.KITPVP, DataType.PVP_MAXKILLSTREAK, LobbyMain.getInstance()); + + this.kills.create(); + this.maxKillStreak.create(); + + update(); + } + + public void update() { + this.kills.updateValues(); + this.maxKillStreak.updateValues(); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.java new file mode 100644 index 0000000..ada0093 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.java @@ -0,0 +1,117 @@ +package com.br.guilhermematthew.nowly.lobby.common.inventory; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.lobby.common.LobbyUtility; +import com.br.guilhermematthew.nowly.lobby.common.inventory.types.GamesInventory; +import com.br.guilhermematthew.nowly.lobby.common.inventory.types.MixInventory; +import com.br.guilhermematthew.nowly.lobby.common.inventory.types.PvPInventory; + +public class InventoryCommon { + + private static GamesInventory gamesInventory = null; + private static MixInventory mixInventory = null; + private static PvPInventory pvpInventory = null; + + private static final MenuClickHandler fastHGClickHandler = new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inv, ClickType type, ItemStack stack, int slot) { + player.closeInventory(); + + String itemName = ChatColor.stripColor(stack.getItemMeta().getDisplayName().trim()); + + ServerType serverClicked = ServerType.getServer(itemName); + + if (BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES) { + if (itemName.equalsIgnoreCase("Partida")) { + serverClicked = ServerType.HARDCORE_GAMES; + } + } + + LobbyUtility.handleInteract(player, serverClicked, BukkitMain.getServerType()); + } + }; + + private static final MenuClickHandler defaultClickHandler = new MenuClickHandler() { + + @Override + public void onClick(Player player, Inventory inv, ClickType type, ItemStack stack, int slot) { + player.closeInventory(); + + String itemName = ChatColor.stripColor(stack.getItemMeta().getDisplayName().trim()); + + ServerType serverClicked = ServerType.getServer(itemName); + + if (BukkitMain.getServerType() == ServerType.LOBBY) { + if (itemName.equalsIgnoreCase("PvP")) { + serverClicked = ServerType.LOBBY_PVP; + } else if (itemName.equalsIgnoreCase("HG")) { + serverClicked = ServerType.LOBBY_HARDCOREGAMES; + } + } + + if (BukkitMain.getServerType() == ServerType.LOBBY_PVP) { + if (itemName.equalsIgnoreCase("PvP")) getPvPInventory().open(player); + else if (itemName.equalsIgnoreCase("HG")) { + serverClicked = ServerType.LOBBY_HARDCOREGAMES; + } + } + + if(BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES) { + if (itemName.equalsIgnoreCase("PvP")) serverClicked = ServerType.LOBBY_PVP; + } + + LobbyUtility.handleInteract(player, serverClicked, BukkitMain.getServerType()); + } + }; + + public static void update() { + if (BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES) { + getHardcoreGamesInventory().update(); + } else if (BukkitMain.getServerType() == ServerType.LOBBY_PVP) { + getGamesInventory().update(); + getPvPInventory().update(); + } else if (BukkitMain.getServerType() == ServerType.LOBBY_DUELS) { + getGamesInventory().update(); + } else { + getGamesInventory().update(); + } + } + + public static MenuClickHandler getDefaultClickHandler() { + return defaultClickHandler; + } + + public static MenuClickHandler getFastHGClickHandler() { + return fastHGClickHandler; + } + + public static GamesInventory getGamesInventory() { + if (gamesInventory == null) { + gamesInventory = new GamesInventory(); + } + return gamesInventory; + } + + public static MixInventory getHardcoreGamesInventory() { + if (mixInventory == null) { + mixInventory = new MixInventory(); + } + return mixInventory; + } + + public static PvPInventory getPvPInventory() { + if (pvpInventory == null) { + pvpInventory = new PvPInventory(); + } + return pvpInventory; + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.java new file mode 100644 index 0000000..bd18cb8 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.java @@ -0,0 +1,38 @@ +package com.br.guilhermematthew.nowly.lobby.common.inventory.types; + +import org.bukkit.Material; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; + +public class GamesInventory extends MenuInventory { + + public GamesInventory() { + super("Selecione um modo", 3); + + update(); + } + + public void update() { + ItemBuilder itemBuilder = new ItemBuilder(); + + ServerType serverType = BukkitMain.getServerType(); + + setItem(10, itemBuilder.type(Material.IRON_CHESTPLATE).name("§aPvP").lore( + "§7" + CommonsGeneral.getServersManager().getAmountOnlinePvP(serverType != ServerType.LOBBY_PVP) + " §7jogando agora!").build(), InventoryCommon.getDefaultClickHandler()); + + setItem(11, itemBuilder.type(Material.MUSHROOM_SOUP).name("§aHG").lore( + "§7" + CommonsGeneral.getServersManager().getAmountOnlineHardcoreGames( + serverType != ServerType.LOBBY_HARDCOREGAMES) + " §7jogando agora!").build(), InventoryCommon.getDefaultClickHandler()); + + setItem(12, itemBuilder.type(Material.DIAMOND_SWORD).name("§aDuels (1v1/Gladiator)").lore( + "§7" + CommonsGeneral.getServersManager().getAmountOnlineDuels(serverType != ServerType.LOBBY_DUELS) + " §7jogando agora!").build(), InventoryCommon.getDefaultClickHandler()); + + setItem(13, itemBuilder.type(Material.CAKE).name("§aParty Games").lore( + "§70 §7jogando agora!").build(), InventoryCommon.getDefaultClickHandler()); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.java new file mode 100644 index 0000000..4966adc --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.java @@ -0,0 +1,119 @@ +package com.br.guilhermematthew.nowly.lobby.common.inventory.types; + +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; +import org.bukkit.Material; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.enums.GameStages; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.types.GameServer; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import org.bukkit.entity.Item; + +public class MixInventory extends MenuInventory { + + private final ItemBuilder itemBuilder; + + public MixInventory() { + super("Salas de HG", 4); + + this.itemBuilder = new ItemBuilder(); + + update(); + onFastRoom(); + } + + public void onFastRoom() { + + ItemBuilder itemBuilder = new ItemBuilder(); + + setItem(31, itemBuilder.type(Material.SLIME_BALL).name("§bPartida Rápida").lore( + "§7Clique para entrar em uma partida", "§7disponivel.").build(), InventoryCommon.getFastHGClickHandler()); + + } + + public void update() { + int slot = 10; + + for (GameServer hardcoreGamesServer : CommonsGeneral.getServersManager().getHardcoreGamesServers()) { + GameStages stage = hardcoreGamesServer.getStage(); + + itemBuilder.name((stage == GameStages.WAITING ? "§a" : "§c") + "HG #" + hardcoreGamesServer.getServerId()); + + if (stage == GameStages.WAITING) { + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(5); + itemBuilder.lore("§aTorneio iniciando em: " + DateUtils.formatTime(hardcoreGamesServer.getTempo()), + "§e" + hardcoreGamesServer.getPlayersGaming() + " aguardando."); + setItem(slot, new MenuItem(itemBuilder.build(), defaultMenuClickHandler)); + } else if (stage == GameStages.INVINCIBILITY) { + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(5); + itemBuilder.lore("§cInvencibilidade acaba em: " + DateUtils.formatTime(hardcoreGamesServer.getTempo()), + "§e" + hardcoreGamesServer.getPlayersGaming() + " jogando."); + setItem(slot, new MenuItem(itemBuilder.build(), defaultMenuClickHandler)); + } else if (stage == GameStages.PLAYING) { + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(7); + itemBuilder.lore("§cO torneio iniciou há: " + DateUtils.formatTime(hardcoreGamesServer.getTempo()), + "§e" + hardcoreGamesServer.getPlayersGaming() + " jogando."); + setItem(slot, new MenuItem(itemBuilder.build(), defaultMenuClickHandler)); + } else { + //evento nulo + } + + slot++; + + /*if (stage == GameStages.LOADING || stage == GameStages.OFFLINE) { + //evento nulo + } else { + //evento nulo + }*/ + + } + + } + + private final MenuClickHandler defaultMenuClickHandler = (player, inventory, clickType, itemStack, slot) -> { + int id = Integer.parseInt(itemStack.getItemMeta().getDisplayName().split("#")[1]); + + + boolean hasPermission = BukkitMain.getBukkitPlayer(player.getUniqueId()).getGroup().getLevel() >= Groups.YOUTUBER.getLevel(), + permissionToJoin = player.hasPermission("commons.entrar"); + + GameServer server = CommonsGeneral.getServersManager().getHardcoreGamesServer(id); + + if (server.isOnline()) { + boolean connect = true; + + if (server.isWhiteList() && !hasPermission) { + connect = false; + player.sendMessage("§cEsta sala está disponível apenas para a nossa equipe."); + } + + if (server.getStage() != GameStages.WAITING && !permissionToJoin) { + connect = false; + player.sendMessage("§cO torneio já iniciou!"); + } + + if (connect) { + if (server.getPlayersGaming() < server.getMembersSlots()) { + BukkitServerAPI.redirectPlayer(player, "HardcoreGames" + id); + } else { + if (permissionToJoin) { + BukkitServerAPI.redirectPlayer(player, "HardcoreGames" + id); + } else { + player.sendMessage("§cOs slots para membros acabaram."); + } + } + } + } else { + player.sendMessage("§cEsta sala năo está online."); + player.closeInventory(); + } + }; +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.java new file mode 100644 index 0000000..716ecc4 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.lobby.common.inventory.types; + +import org.bukkit.Material; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; + +public class PvPInventory extends MenuInventory { + + public PvPInventory() { + super("Escolha um modo", 3); + + update(); + } + + public void update() { + ItemBuilder itemBuilder = new ItemBuilder(); + + setItem(10, new MenuItem(itemBuilder.type(Material.DIAMOND_SWORD).name("§aArena").lore("§e" + CommonsGeneral.getServersManager().getNetworkServer("arena").getOnlines() + " jogando").build(), InventoryCommon.getDefaultClickHandler())); + setItem(11, new MenuItem(itemBuilder.type(Material.GLASS).name("§aFPS").lore("§e" + CommonsGeneral.getServersManager().getNetworkServer("fps").getOnlines() + " jogando").build(), InventoryCommon.getDefaultClickHandler())); + setItem(12, new MenuItem(itemBuilder.type(Material.LAVA_BUCKET).name("§aLavaChallenge").lore("§e" + CommonsGeneral.getServersManager().getNetworkServer("lavachallenge").getOnlines() + " jogando").build(), InventoryCommon.getDefaultClickHandler())); + + itemBuilder = null; + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.java new file mode 100644 index 0000000..75a14d4 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.java @@ -0,0 +1,10 @@ +package com.br.guilhermematthew.nowly.lobby.common.npcs; + +public abstract class NPCCommon { + + public abstract void create(); + public abstract void update(); + public abstract void createLocations(); + public abstract void createHolograms(); + public abstract void registerListeners(); +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.java new file mode 100644 index 0000000..0e1e8a1 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.java @@ -0,0 +1,99 @@ +package com.br.guilhermematthew.nowly.lobby.common.npcs.types; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCLib; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.NPCInteractEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.SkinFetcher; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.LobbyUtility; +import com.br.guilhermematthew.nowly.lobby.common.npcs.NPCCommon; + +import lombok.Getter; + +public class LobbyHGNPC extends NPCCommon { + + @Getter + private static Hologram playingHG, playingChampions, playingEventos; + + @SuppressWarnings("deprecation") + @Override + public void create() { + createLocations(); + + Skin skin = SkinFetcher.fetchSkinByNick("EuFakeON", "7ac29642-e158-4a34-8909-53dbce9efcbd", true); + + NPC npc = NPCLib.createNPC("HG", "§7§a", "47kypxflog", skin, Material.MUSHROOM_SOUP.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.hg")); + + skin = SkinFetcher.fetchSkinByNick("SpectayUS", "49f67001-bf18-4164-b37a-5f3e1ab460d5", true); + npc = NPCLib.createNPC("Evento", "§7§f", "v990g8u6wq", skin, Material.CAKE.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.evento")); + + skin = SkinFetcher.fetchSkinByNick("iHuxNOWLY", "43d75222-0290-48ea-a18a-440d77b16047", true); + npc = NPCLib.createNPC("Champions", "§7§c", "gytixcqcj7", skin, Material.DIAMOND_CHESTPLATE.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.champion")); + + createHolograms(); + registerListeners(); + } + + @Override + public void update() { + playingHG.setText("§e" + CommonsGeneral.getServersManager().getAmountOnlineHardcoreGames(false) + " jogando."); + playingChampions.setText("§e" + CommonsGeneral.getServersManager().getHardcoreGamesServer("Champions", 1).getOnlines() + " jogando."); + playingEventos.setText("§e" + CommonsGeneral.getServersManager().getHardcoreGamesServer("Evento", 1).getOnlines() + " jogando."); + } + + @Override + public void createLocations() { + PluginConfiguration.createLocations(LobbyMain.getInstance(), "bots.hg", "bots.evento", "bots.champion"); + } + + @Override + public void createHolograms() { + playingHG = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("HG").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingHG.spawn(); + playingHG.addLineAbove("bot", "§bHG Mix"); + + playingChampions = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("Champions").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingChampions.spawn(); + playingChampions.addLineAbove("bot", "§bChampions"); + playingChampions.addLineAbove("bot", "§e15h 17h 19h 21h"); + + playingEventos = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("Evento").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingEventos.spawn(); + playingEventos.addLineAbove("bot", "§bEvento"); + } + + @Override + public void registerListeners() { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onInteract(NPCInteractEvent event) { + LobbyUtility.handleInteract(event.getPlayer(), + ServerType.getServer(event.getNpc().getCustomName()), BukkitMain.getServerType()); + } + + }, LobbyMain.getInstance()); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.java new file mode 100644 index 0000000..f3dcfbc --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.java @@ -0,0 +1,107 @@ +package com.br.guilhermematthew.nowly.lobby.common.npcs.types; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import org.apache.commons.lang3.RandomStringUtils; +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCLib; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.NPCInteractEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.SkinFetcher; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.LobbyUtility; +import com.br.guilhermematthew.nowly.lobby.common.npcs.NPCCommon; + +import lombok.Getter; + +public class LobbyNPC extends NPCCommon { + + @Getter + private static Hologram playingHG, playingPvP, playingDuels; + + @SuppressWarnings("deprecation") + @Override + public void create() { + createLocations(); + String npcProvider = "§8[NPC] "; + Skin skin = SkinFetcher.fetchSkinByNick("TheCaioX", "fd9a855c-dfd9-4939-9bac-a0ed3ba0c72e", true); + + NPC npc = NPCLib.createNPC("HG", "§7", "vkxz6shs6d", skin, Material.MUSHROOM_SOUP.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.hg")); + + skin = SkinFetcher.fetchSkinByNick("enbees", "d0140ddd-e7b9-41ed-a9cb-bfd81a8015e8", true); + npc = NPCLib.createNPC("PvP", "§7§5", "0gy1pyow5x", skin, Material.IRON_CHESTPLATE.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.pvp")); + + skin = SkinFetcher.fetchSkinByNick("Agera991", "866e1109-3b9f-4e2d-850a-aae37c01c5ca", true); + npc = NPCLib.createNPC("Duels", "§7§0", "826ejkt171", skin, Material.DIAMOND_SWORD.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.duels")); + + createHolograms(); + registerListeners(); + } + + @Override + public void update() { + playingHG.setText("§e" + CommonsGeneral.getServersManager().getAmountOnlineHardcoreGames(true) + " jogando."); + playingPvP.setText("§e" + CommonsGeneral.getServersManager().getAmountOnlinePvP(true) + " jogando."); + playingDuels.setText("§e0 jogando."); + } + + @Override + public void createLocations() { + PluginConfiguration.createLocations(LobbyMain.getInstance(), "bots.hg", "bots.pvp", "bots.duels"); + } + + @Override + public void createHolograms() { + playingHG = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("HG").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingHG.spawn(); + playingHG.addLineAbove("bot", "§bHG"); + + playingPvP = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("PvP").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingPvP.spawn(); + playingPvP.addLineAbove("bot", "§bPvP"); + + playingDuels = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("Duels").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingDuels.spawn(); + playingDuels.addLineAbove("bot", "§bDuels"); + } + + @Override + public void registerListeners() { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onInteract(NPCInteractEvent event) { + ServerType serverClicked = ServerType.getServer(event.getNpc().getCustomName()); + if (event.getNpc().getCustomName().equalsIgnoreCase("PvP")) { + serverClicked = ServerType.LOBBY_PVP; + } else if (event.getNpc().getCustomName().equalsIgnoreCase("HG")) { + serverClicked = ServerType.LOBBY_HARDCOREGAMES; + } else if (event.getNpc().getCustomName().equalsIgnoreCase("Duels")) { + serverClicked = ServerType.LOBBY_DUELS; + } + + LobbyUtility.handleInteract(event.getPlayer(), serverClicked, BukkitMain.getServerType()); + } + + }, LobbyMain.getInstance()); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.java new file mode 100644 index 0000000..803965b --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.java @@ -0,0 +1,98 @@ +package com.br.guilhermematthew.nowly.lobby.common.npcs.types; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.Hologram; +import com.br.guilhermematthew.nowly.commons.bukkit.api.hologram.HologramAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCLib; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.NPCManager; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.api.NPC; +import com.br.guilhermematthew.nowly.commons.bukkit.api.npc.events.NPCInteractEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.Skin; +import com.br.guilhermematthew.nowly.commons.common.utility.skin.SkinFetcher; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.LobbyUtility; +import com.br.guilhermematthew.nowly.lobby.common.npcs.NPCCommon; + +import lombok.Getter; + +public class LobbyPvPNPC extends NPCCommon { + + @Getter + private static Hologram playingArena, playingFPS, playingLavaChallenge; + + @SuppressWarnings("deprecation") + @Override + public void create() { + createLocations(); + + Skin skin = SkinFetcher.fetchSkinByNick("Kongamitow", "e13fb198-4ecb-41f4-93af-5cb0acd390f7", true); + + NPC npc = NPCLib.createNPC("Arena", "§7", "py3lz629zv", skin, Material.STONE_SWORD.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.arena")); + + skin = SkinFetcher.fetchSkinByNick("iibzNowly", "d212253c-3388-4653-91b7-7379dbd4ca4d", true); + npc = NPCLib.createNPC("FPS", "§7§1", "rh7rgj4q7t", skin, Material.DIAMOND_SWORD.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.fps")); + + skin = SkinFetcher.fetchSkinByNick("Procurador", "ca163766-6db2-4c42-b33a-a574fbaf6cff", true); + npc = NPCLib.createNPC("LavaChallenge", "§7§2", "5hdtvact0p", skin, Material.LAVA_BUCKET.getId()); + npc.create(PluginConfiguration.getLocation(LobbyMain.getInstance(), "bots.lavachallenge")); + + createHolograms(); + registerListeners(); + } + + @Override + public void update() { + playingArena.setText("§e" + CommonsGeneral.getServersManager().getNetworkServer("arena").getOnlines() + " jogando."); + playingFPS.setText("§e" + CommonsGeneral.getServersManager().getNetworkServer("fps").getOnlines() + " jogando."); + playingLavaChallenge.setText("§e" + CommonsGeneral.getServersManager().getNetworkServer("lavachallenge").getOnlines() + " jogando."); + } + + @Override + public void createLocations() { + PluginConfiguration.createLocations(LobbyMain.getInstance(), "bots.arena", "bots.fps", "bots.lavachallenge"); + } + + @Override + public void createHolograms() { + playingArena = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("Arena").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingArena.spawn(); + playingArena.addLineAbove("bot", "§bArena"); + + playingFPS = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("FPS").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingFPS.spawn(); + playingFPS.addLineAbove("bot", "§bFPS"); + + playingLavaChallenge = HologramAPI.createHologram("jogandoAgora", NPCManager.getNPCByName("LavaChallenge").getLocationForHologram().clone().add(0, 0.01, 0), + "§e0 jogando."); + + playingLavaChallenge.spawn(); + playingLavaChallenge.addLineAbove("bot", "§bLava"); + } + + @Override + public void registerListeners() { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onInteract(NPCInteractEvent event) { + LobbyUtility.handleInteract(event.getPlayer(), + ServerType.getServer(event.getNpc().getCustomName()), BukkitMain.getServerType()); + } + + }, LobbyMain.getInstance()); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.java new file mode 100644 index 0000000..ee746b3 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.java @@ -0,0 +1,13 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard; + + +import lombok.Getter; + +@Getter +public abstract class AnimatedCommon { + + public abstract String current(); + public abstract String next(); + public abstract String previous(); + +} diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.java new file mode 100644 index 0000000..a5f5d58 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.java @@ -0,0 +1,16 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard; + +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import static org.bukkit.Bukkit.getServer; + +public abstract class ScoreboardCommon { + + public abstract void createScoreboard(final Player player); + public abstract void updateScoreboard(final Player player); + + +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.java new file mode 100644 index 0000000..6099ec7 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard; + +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.types.LobbyScoreboard; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class ScoreboardInstance { + + private LobbyScoreboard lobbyBoard; + + public ScoreboardInstance() { + setLobbyBoard(new LobbyScoreboard()); + getLobbyBoard().init(); + } + +} diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.java new file mode 100644 index 0000000..7f3584d --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.animating; + +public class ActualAnimation extends FramesAnimation +{ + protected String context, normalFormat, highlightFormat; + + public ActualAnimation(String context, String normalFormat, String highlightFormat) { + this.context = context; + this.normalFormat = normalFormat; + this.highlightFormat = highlightFormat; + generateFrames(); + } + + protected void generateFrames() { + for (int i = 0; i < this.context.length(); i++) { + if (this.context.charAt(i) != ' ') { + String str1 = String.valueOf(this.normalFormat) + this.context.substring(0, i) + + this.highlightFormat + this.context.charAt(i) + this.normalFormat + + this.context.substring(i + 1, this.context.length()); + addFrame(str1); + } else { + addFrame(this.normalFormat + this.context + " "); + } + } + } + + public String getContext() { + return this.context; + } + + public String getNormalColor() { + return this.normalFormat; + } + + public String getHighlightColor() { + return this.highlightFormat; + } +} + diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.java new file mode 100644 index 0000000..e69ec17 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.java @@ -0,0 +1,82 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.animating; + +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.AnimatedCommon; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class FramesAnimation extends AnimatedCommon { + + protected List frames; + protected int currentFrame; + + public FramesAnimation() { + this.frames = new ArrayList<>(); + this.currentFrame = -1; + } + + public FramesAnimation(String... VarArgs) { + this.frames = new ArrayList<>(); + this.currentFrame = -1; + this.frames = Arrays.asList(VarArgs); + } + + public FramesAnimation(List List) { + this.frames = new ArrayList<>(); + this.currentFrame = -1; + this.frames = List; + } + + public void addFrame(String String) { + this.frames.add(String); + } + + public void setFrame(int Int, String String) { + this.frames.set(Int, String); + } + + public void removeFrame(String String) { + this.frames.remove(String); + } + + public int getCurrentFrame() { + return this.currentFrame; + } + + public void setCurrentFrame(int Int) { + this.currentFrame = Int; + } + + public int getTotalLength() { + return this.frames.size(); + } + + public String getString(int Int) { + return (String)this.frames.get(Int); + } + + public String current() { + if (this.currentFrame == -1) { + return null; + } + return (String)this.frames.get(this.currentFrame); + } + + public String next() { + this.currentFrame += 1; + if (this.currentFrame == this.frames.size()) { + this.currentFrame = 0; + } + return (String)this.frames.get(this.currentFrame); + } + + public String previous() { + this.currentFrame -= 1; + if (this.currentFrame == -1) { + this.currentFrame = (this.frames.size() - 1); + } + return (String)this.frames.get(this.currentFrame); + } + +} diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.java new file mode 100644 index 0000000..606cb5a --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.java @@ -0,0 +1,61 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.animating; + +import java.util.ArrayList; +import java.util.List; + +public class StringAnimation { + + private String string; + private List strings; + private int index; + private boolean bools; + + public StringAnimation(String title, String color1, String color2, String color3) { + this(title, color1, color2, color3, 12); + } + + public StringAnimation(String title, String color1, String color2, String color3, int value) { + this.string = title; + this.strings = new ArrayList<>(); + create(color1, color2, color3, value); + } + + public void create(String color1, String color2, String color3, int value) { + if (string != null && !string.isEmpty()) { + for (int i = 0; i < string.length(); i++) + if (string.charAt(i) != ' ') + strings.add(color1 + string.substring(0, i) + color2 + string.charAt(i) + color3 + string.substring(i + 1)); + + for (int i = 0; i < value; i++) + strings.add(color1 + string); + + for (int i = 0; i < string.length(); i++) + if(string.charAt(i) != ' ') + strings.add(color3 + string.substring(0, i) + color2 + string.charAt(i) + color1 + string.substring(i + 1)); + + for (int i = 0; i < value; i++) + strings.add(color3 + string); + } + } + + public String next() { + if (strings.isEmpty()) + return ""; + + if (bools) { + index--; + if (index <= 0) + bools = false; + } + else + { + index++; + if (index >= strings.size()) { + bools = true; + return next(); + } + } + return strings.get(index); + } + +} diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.java new file mode 100644 index 0000000..00efcc9 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.java @@ -0,0 +1,54 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardCommon; +import org.bukkit.entity.Player; + +public class DuelsScoreboard extends ScoreboardCommon { + + + @Override + public void createScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + sidebar.setTitle("§2§lLEAGUE"); + + sidebar.addBlankLine(); + sidebar.addLine("§eUse §6/duel §epara"); + sidebar.addLine("§edesafiar um oponente."); + sidebar.addBlankLine(); + sidebar.addLine("§eGladiator:"); + sidebar.addLine("winsGlad", " Wins: §b" + bukkitPlayer.getData(DataType.GLADIATOR_WINS)); + sidebar.addLine("streakGlad", " Winstreak: §b" + bukkitPlayer.getData(DataType.GLADIATOR_WINSTREAK)); + sidebar.addLine("§eSimulator:"); + sidebar.addLine("winsGlad", " Wins: §b0"); + sidebar.addLine("streakGlad", " Winstreak: §b0"); + sidebar.addBlankLine(); + sidebar.addLine("onlines", "Players: ", "§a" + StringUtility.formatValue(CommonsGeneral.getServersManager().getAmountOnNetwork())); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + sidebar = null; + } + + @Override + public void updateScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + sidebar.updateLine("onlines", "Players: ", "§a" + StringUtility.formatValue( + CommonsGeneral.getServersManager().getAmountOnNetwork())); + sidebar.updateLine("winsGlad", " Wins: §b" + bukkitPlayer.getData(DataType.GLADIATOR_WINS)); + sidebar.updateLine("streakGlad", " Winstreak: §b" + bukkitPlayer.getData(DataType.GLADIATOR_WINSTREAK)); + } + +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.java new file mode 100644 index 0000000..830fdc6 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.java @@ -0,0 +1,59 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.types; + +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import lombok.val; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardCommon; + +public class LobbyHGScoreboard extends ScoreboardCommon { + + + @Override + public void createScoreboard(Player player) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + sidebar.setTitle("§2§lLEAGUE"); + + sidebar.addBlankLine(); + sidebar.addLine("§eHG Mix:"); + sidebar.addLine("hgWins", " Wins: §a" + bukkitPlayer.getIntFormatted(DataType.HG_WINS)); + sidebar.addLine("hgKills", " Kills: §a" + bukkitPlayer.getIntFormatted(DataType.HG_KILLS)); + sidebar.addBlankLine(); + sidebar.addLine("§eChampions:"); + sidebar.addLine("eventWins", " Wins: §a" + bukkitPlayer.getIntFormatted(DataType.HG_EVENT_WINS)); + sidebar.addLine("eventKills", " Kills: §a" + bukkitPlayer.getIntFormatted(DataType.HG_EVENT_KILLS)); + sidebar.addBlankLine(); + sidebar.addLine("coins", "Coins: §6" + bukkitPlayer.getIntFormatted(DataType.COINS)); + sidebar.addLine("onlines", "Players: ", "§a" + StringUtility.formatValue(CommonsGeneral.getServersManager().getAmountOnNetwork())); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + @Override + public void updateScoreboard(Player player) { + val sidebar = SidebarManager.getSidebar(player.getUniqueId()); + if(sidebar == null) return; + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + sidebar.updateLine("hgWins", " Wins: §a" + bukkitPlayer.getIntFormatted(DataType.HG_WINS)); + sidebar.updateLine("hgKills", " Kills: §a" + bukkitPlayer.getIntFormatted(DataType.HG_KILLS)); + sidebar.updateLine("eventWins", " Wins: §a" + bukkitPlayer.getIntFormatted(DataType.HG_EVENT_WINS)); + sidebar.updateLine("eventKills", " Kills: §a" + bukkitPlayer.getIntFormatted(DataType.HG_EVENT_KILLS)); + + sidebar.updateLine("onlines", "Players: ", "§a" + StringUtility.formatValue( + CommonsGeneral.getServersManager().getAmountOnNetwork())); + } + +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.java new file mode 100644 index 0000000..0dbb81e --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.java @@ -0,0 +1,49 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardCommon; + +public class LobbyPvPScoreboard extends ScoreboardCommon { + + + @Override + public void createScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + sidebar.setTitle("§2§lLEAGUE"); + + sidebar.addBlankLine(); + sidebar.addLine("§7Bem-vindo ao PvP"); + sidebar.addLine("§7Selecione um modo!"); + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", group.getColor() + (group.getLevel() == Groups.MEMBRO.getLevel() ? "Membro" : group.getTag().getColor() + group.getTag().getName())); + sidebar.addBlankLine(); + sidebar.addLine("lobbyId", "Lobby: ", "§7#" + BukkitMain.getServerID()); + sidebar.addLine("onlines", "Players: ", "§a" + StringUtility.formatValue(CommonsGeneral.getServersManager().getAmountOnNetwork())); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + sidebar = null; + } + + @Override + public void updateScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + sidebar.updateLine("rank", "Rank: ", group.getColor() + (group.getLevel() == Groups.MEMBRO.getLevel() ? "Membro" : group.getTag().getColor() + group.getTag().getName())); + sidebar.updateLine("onlines", "Players: ", "§a" + StringUtility.formatValue( + CommonsGeneral.getServersManager().getAmountOnNetwork())); + } + +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.java new file mode 100644 index 0000000..9447166 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.java @@ -0,0 +1,114 @@ +package com.br.guilhermematthew.nowly.lobby.common.scoreboard.types; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.animating.StringAnimation; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.ScoreboardCommon; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; + +public class LobbyScoreboard extends ScoreboardCommon { + + private StringAnimation animation; + private String text = ""; + + public void init() { + animation = new StringAnimation(" LEAGUE ", "§f§l", "§2§l", "§a§l", 3); + text = animation.next(); + + registerListener(); + + Bukkit.getScheduler().runTaskTimer(LobbyMain.getInstance(), new Runnable() { + public void run() { + text = animation.next(); + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (onlines == null) { + continue; + } + if (!onlines.isOnline()) { + continue; + } + if (onlines.isDead()) { + continue; + } + Scoreboard score = onlines.getScoreboard(); + if (score == null) { + continue; + } + Objective objective = score.getObjective(DisplaySlot.SIDEBAR); + if (objective == null) { + continue; + } + objective.setDisplayName(text); + } + } + }, 40, 2L); + } + + @Override + public void createScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + sidebar.setTitle("§2§lLEAGUE"); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + sidebar.addBlankLine(); + sidebar.addLine("rank", "Rank: ", group.getColor() + (group.getLevel() == Groups.MEMBRO.getLevel() ? "Membro" : group.getTag().getColor() + group.getTag().getName())); + sidebar.addBlankLine(); + sidebar.addLine("lobbyId", "Lobby: ", "§7#" + BukkitMain.getServerID()); + sidebar.addLine("onlines", "Players: ", "§a" + StringUtility.formatValue(CommonsGeneral.getServersManager().getAmountOnNetwork())); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + + group = null; + bukkitPlayer = null; + + sidebar = null; + } + + @Override + public void updateScoreboard(Player player) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + Groups group = bukkitPlayer.getGroup(); + SidebarManager.getSidebar(player.getUniqueId()).updateLine("rank", "Rank: ", group.getColor() + (group.getLevel() == Groups.MEMBRO.getLevel() ? "Membro" : group.getTag().getColor() + group.getTag().getName())); + SidebarManager.getSidebar(player.getUniqueId()).updateLine("onlines", "Players: ", "§a" + StringUtility.formatValue( + CommonsGeneral.getServersManager().getAmountOnNetwork())); + } + + private void registerListener() { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void update(BukkitUpdateEvent event) { + if (event.getType() != BukkitUpdateEvent.UpdateType.SEGUNDO) { + return; + } + + for (Player onlines : Bukkit.getOnlinePlayers()) { + updateScoreboard(onlines); + } + } + + }, LobbyMain.getInstance()); + } + +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.java new file mode 100644 index 0000000..4cb70d9 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.java @@ -0,0 +1,239 @@ +package com.br.guilhermematthew.nowly.lobby.listeners; + +import java.util.UUID; + +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.metadata.FixedMetadataValue; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack.InteractHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeVisibilityEvent; +import com.br.guilhermematthew.nowly.commons.common.data.DataHandler; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.commands.ServerCommand; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; + +public class AccountListener implements Listener { + + private final String VISIBILITY_DELAY_TAG = "visibility.delay.time"; + + private boolean registred = false; + + private void register() { + if (registred) + return; + registred = true; + ActionItemStack.register("§fJogadores: §aON", visibilityHandler); + ActionItemStack.register("§aSelecionar jogo", gamesModeHandler); + ActionItemStack.register("§aMeu perfil", profileHandler); + } + + @EventHandler + public void onAsyncLogin(AsyncPlayerPreLoginEvent e) { + if(BukkitMain.getServerType() == ServerType.LOBBY) return; + + val category = BukkitMain.getServerType() == ServerType.LOBBY_HARDCOREGAMES ? + DataCategory.HARDCORE_GAMES : DataCategory.KITPVP; + + val bp = BukkitMain.getBukkitPlayer(e.getUniqueId()); + + try { + bp.getDataHandler().load(category); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + register(); + + Player player = event.getPlayer(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + addDelay(player); + + if (player.getGameMode() != GameMode.ADVENTURE) { + player.setGameMode(GameMode.ADVENTURE); + } + + player.setMaxHealth(1.7D); + player.setHealth(1.7); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + boolean playerVisibility = bukkitPlayer.getBoolean(DataType.PLAYERS_VISIBILITY); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.clear(); + playerInventory.setArmorContents(null); + + playerInventory.setItem(0, itemBuilder.type(Material.COMPASS).name("§aSelecionar jogo").build()); + playerInventory.setItem(1, + itemBuilder.type(Material.SKULL_ITEM).skin(bukkitPlayer.getNick()).name("§aMeu perfil").build()); + + playerInventory.setItem(7, itemBuilder.type(Material.INK_SACK).durability(playerVisibility ? 10 : 8) + .name("§fJogadores: §aON").build()); + playerInventory.setItem(8, itemBuilder.type(Material.NETHER_STAR).name("§aSelecionar Lobby").build()); + + player.updateInventory(); + + if (BukkitMain.getServerType() == ServerType.LOBBY) { + TitleAPI.sendTitle(player, "§2§lLEAGUE", "§eSeja bem-vindo(a)", 0, 0, 2); + } + + Groups playerGroup = bukkitPlayer.getGroup(); + + boolean announceJoin = !bukkitPlayer.containsFake() && !VanishAPI.inAdmin(player) && playerGroup.getLevel() > Groups.MEMBRO.getLevel() + && bukkitPlayer.getBoolean(DataType.ANNOUNCEMENT_JOIN); + + val playerTag = bukkitPlayer.getActualTag() != null ? bukkitPlayer.getActualTag() : playerGroup.getTag(); + Groups group = bukkitPlayer.getGroup(); + String joinMessage = group.getColor() + "§l" + group.getTag().getPrefix() + " " + group.getColor() + + player.getName() + " §6entrou neste lobby!"; + + for (Player onlines : Bukkit.getOnlinePlayers()) { + if (announceJoin) { + onlines.sendMessage(joinMessage); + } + if (onlines.getUniqueId() != player.getUniqueId()) { + + if (!playerVisibility) { + player.hidePlayer(onlines); + } + + if (!BukkitMain.getBukkitPlayer(onlines.getUniqueId()).getBoolean(DataType.PLAYERS_VISIBILITY)) { + onlines.hidePlayer(player); + } + } + } + + if (playerGroup.getLevel() > Groups.MEMBRO.getLevel()) { + player.teleport(LobbyMain.getSpawn().clone().add(0, 0.5, 0)); + + player.setAllowFlight(true); + player.setFlying(true); + } else { + player.teleport(LobbyMain.getSpawn()); + } + + LobbyMain.getScoreBoardCommon().createScoreboard(player); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + UUID uniqueId = event.getPlayer().getUniqueId(); + + ServerCommand.autorizados.remove(uniqueId); + } + + @EventHandler + public void onChangeVisibility(PlayerChangeVisibilityEvent event) { + Player player = event.getPlayer(); + + if (event.isVisibility()) { + + for (Player ons : Bukkit.getOnlinePlayers()) { + if (!VanishAPI.isInvisible(ons) && !VanishAPI.inAdmin(ons)) { + player.showPlayer(ons); + } + } + + VanishAPI.updateInvisibles(player); + + player.getInventory().setItem(player.getInventory().first(Material.INK_SACK), new ItemBuilder() + .type(Material.INK_SACK).durability(10).name("§fJogadores: §aON").build()); + } else { + for (Player ons : Bukkit.getOnlinePlayers()) { + player.hidePlayer(ons); + } + + VanishAPI.updateInvisibles(player); + + player.getInventory().setItem(player.getInventory().first(Material.INK_SACK), new ItemBuilder() + .type(Material.INK_SACK).durability(8).name("§fJogadores: §cOFF").build()); + } + } + + private final InteractHandler profileHandler = (player, itemStack, itemAction, clickedBlock) -> { + if (!itemAction.name().contains("RIGHT")) + return true; + player.chat("/acc"); + return true; + }; + + private final InteractHandler gamesModeHandler = (player, itemStack, itemAction, clickedBlock) -> { + if (!itemAction.name().contains("RIGHT")) + return true; + + if (BukkitMain.getServerType() == ServerType.LOBBY_PVP) { + InventoryCommon.getGamesInventory().open(player); + } else { + InventoryCommon.getGamesInventory().open(player); + } + return true; + }; + + private final InteractHandler visibilityHandler = (player, itemStack, itemAction, clickedBlock) -> { + if (!itemAction.name().contains("RIGHT")) return true; + if (hasDelay(player)) return true; + + addDelay(player); + + if (!itemAction.name().contains("RIGHT")) return true; + + DataHandler dataHandler = BukkitMain.getBukkitPlayer(player.getUniqueId()).getDataHandler(); + + if (dataHandler.getBoolean(DataType.PLAYERS_VISIBILITY)) { + dataHandler.getData(DataType.PLAYERS_VISIBILITY).setValue(false); + + LobbyMain.runAsync(() -> dataHandler.saveCategory(DataCategory.PREFERENCES)); + + player.sendMessage(BukkitMessages.VOCE_ATIVOU_A_VISIBILIDADE_DOS_JOGADORES); + + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeVisibilityEvent(player, false)); + } else { + dataHandler.getData(DataType.PLAYERS_VISIBILITY).setValue(true); + LobbyMain.runAsync(() -> dataHandler.saveCategory(DataCategory.PREFERENCES)); + + player.sendMessage(BukkitMessages.VOCE_ATIVOU_A_VISIBILIDADE_DOS_JOGADORES); + player.getInventory().setItem(player.getInventory().first(Material.INK_SACK), new ItemBuilder() + .type(Material.INK_SACK).durability(10).name("§fJogadores: §aON").build()); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeVisibilityEvent(player, true)); + } + return true; + }; + + private void addDelay(Player player) { + player.setMetadata(VISIBILITY_DELAY_TAG, + new FixedMetadataValue(LobbyMain.getInstance(), System.currentTimeMillis() + 4000L)); + } + + private boolean hasDelay(Player player) { + if (!player.hasMetadata(VISIBILITY_DELAY_TAG)) + return false; + return player.getMetadata(VISIBILITY_DELAY_TAG).get(0).asLong() > System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.java b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.java new file mode 100644 index 0000000..0669558 --- /dev/null +++ b/lobby/src/main/java/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.java @@ -0,0 +1,260 @@ +package com.br.guilhermematthew.nowly.lobby.listeners; + +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.lobby.common.scoreboard.animating.StringAnimation; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.weather.WeatherChangeEvent; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerChangeScoreboardEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.lobby.LobbyMain; +import com.br.guilhermematthew.nowly.lobby.commands.ServerCommand; +import com.br.guilhermematthew.nowly.lobby.common.inventory.InventoryCommon; + +public class GeneralListeners implements Listener { + + private StringAnimation animation; + private String text = ""; + public static int MINUTES = 0; + + @EventHandler + public void onRequest(PlayerRequestEvent event) { + if (event.getRequestType().equalsIgnoreCase("update-scoreboard")) { + LobbyMain.getScoreBoardCommon().createScoreboard(event.getPlayer()); + } + } + + @EventHandler + public void onMinute(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.MINUTO) return; + + if (MINUTES++ == 20) { + if (LobbyMain.getHologramCommon() != null) { + LobbyMain.getHologramCommon().update(); + } + MINUTES = 0; + } + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + if(!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + Material material = event.getTo().getBlock().getRelative(BlockFace.DOWN).getType(); + + if (material == Material.SLIME_BLOCK) { + Player player = event.getPlayer(); + + player.setVelocity(player.getLocation().getDirection().multiply(3.1).setY(0.5)); + player.playSound(player.getLocation(), Sound.FIREWORK_LAUNCH, 6.0F, 1.0F); + player.setFallDistance(-30); + } + } + + @EventHandler + public void onSecond(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) { + return; + } + + CommonsGeneral.getServersManager().sendRequireUpdate(); + InventoryCommon.update(); + + if (LobbyMain.getNpcCommon() != null) { + LobbyMain.getNpcCommon().update(); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onUpdateScoreboard(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.TICK) return; + if (event.getCurrentTick() % 40 != 0) return; + + Bukkit.getOnlinePlayers().forEach(player -> LobbyMain.getScoreBoardCommon().updateScoreboard(player)); + } + + @EventHandler + public void onChangeScoreboard(PlayerChangeScoreboardEvent event) { + if (event.getChangeType() == PlayerChangeScoreboardEvent.ScoreboardChangeType.DESATIVOU) { + event.setCancelled(true); + } else { + LobbyMain.getScoreBoardCommon().createScoreboard(event.getPlayer()); + } + } + + @EventHandler + public void onSpread(BlockSpreadEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + event.setCancelled(true); + + if (event.getCause() == DamageCause.VOID) { + event.getEntity().teleport(LobbyMain.getSpawn()); + } + } + + @EventHandler + public void onLeavesDecay(LeavesDecayEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockBurn(BlockBurnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockFade(BlockFadeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPortal(PlayerPortalEvent event) { + event.setCancelled(true); + } + + /* + @EventHandler + public void onBlockForm(BlockFormEvent event) { + event.setCancelled(true); + }*/ + + @EventHandler + public void onBlockFromTo(BlockFromToEvent event) { + event.setCancelled(true); + } + + /* + @EventHandler + public void onBlockGrow(BlockGrowEvent event) { + event.setCancelled(true); + }*/ + + @EventHandler + public void onBlockPhysics(BlockPhysicsEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onCraft(CraftItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onExplosion(ExplosionPrimeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onDamage(EntityDamageByEntityEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockIgnite(BlockIgniteEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onEntitySpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPickup(PlayerPickupItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPhysics(BlockPhysicsEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onBreak(BlockBreakEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.PHYSICAL) { + event.setCancelled(true); + return; + } + + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onRegain(EntityRegainHealthEvent event) { + event.setCancelled(true); + } +} \ No newline at end of file diff --git a/lobby/src/main/resources/config.yml b/lobby/src/main/resources/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/lobby/src/main/resources/plugin.yml b/lobby/src/main/resources/plugin.yml new file mode 100644 index 0000000..bd44322 --- /dev/null +++ b/lobby/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: NowlyLobby +main: com.br.guilhermematthew.nowly.lobby.LobbyMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] +depend: [BukkitCommons] \ No newline at end of file diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/LobbyMain.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/LobbyMain.class new file mode 100644 index 0000000..beecee0 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/LobbyMain.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.class new file mode 100644 index 0000000..0a8175a Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/commands/ServerCommand.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.class new file mode 100644 index 0000000..583c3fc Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/LobbyUtility.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.class new file mode 100644 index 0000000..b006eb8 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/HologramCommon.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.class new file mode 100644 index 0000000..12c9f9b Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyHGHologram.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.class new file mode 100644 index 0000000..88b2902 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/hologram/types/LobbyPvPHologram.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$1.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$1.class new file mode 100644 index 0000000..16c20c9 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$1.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$2.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$2.class new file mode 100644 index 0000000..30e733e Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon$2.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.class new file mode 100644 index 0000000..fbf00c0 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/InventoryCommon.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.class new file mode 100644 index 0000000..718113f Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/GamesInventory.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.class new file mode 100644 index 0000000..fcd4cf6 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/MixInventory.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.class new file mode 100644 index 0000000..5813c55 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/inventory/types/PvPInventory.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.class new file mode 100644 index 0000000..7cb8f35 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/NPCCommon.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC$1.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC$1.class new file mode 100644 index 0000000..87bb6c2 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC$1.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.class new file mode 100644 index 0000000..a426f6c Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyHGNPC.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC$1.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC$1.class new file mode 100644 index 0000000..d986e68 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC$1.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.class new file mode 100644 index 0000000..c5091eb Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyNPC.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC$1.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC$1.class new file mode 100644 index 0000000..89bde9e Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC$1.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.class new file mode 100644 index 0000000..ce2012c Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/npcs/types/LobbyPvPNPC.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.class new file mode 100644 index 0000000..e35e930 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/AnimatedCommon.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.class new file mode 100644 index 0000000..3eb9b8e Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardCommon.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.class new file mode 100644 index 0000000..fcf1e90 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/ScoreboardInstance.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.class new file mode 100644 index 0000000..9b688a6 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/ActualAnimation.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.class new file mode 100644 index 0000000..fbf7307 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/FramesAnimation.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.class new file mode 100644 index 0000000..f131d54 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/animating/StringAnimation.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.class new file mode 100644 index 0000000..aec3cf8 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/DuelsScoreboard.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.class new file mode 100644 index 0000000..150784b Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyHGScoreboard.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.class new file mode 100644 index 0000000..52f082e Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyPvPScoreboard.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$1.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$1.class new file mode 100644 index 0000000..0eec49b Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$1.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$2.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$2.class new file mode 100644 index 0000000..30ad498 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard$2.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.class new file mode 100644 index 0000000..8af6f23 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/common/scoreboard/types/LobbyScoreboard.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.class new file mode 100644 index 0000000..2a585d6 Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/AccountListener.class differ diff --git a/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.class b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.class new file mode 100644 index 0000000..42f58db Binary files /dev/null and b/lobby/target/classes/com/br/guilhermematthew/nowly/lobby/listeners/GeneralListeners.class differ diff --git a/lobby/target/classes/config.yml b/lobby/target/classes/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/lobby/target/classes/plugin.yml b/lobby/target/classes/plugin.yml new file mode 100644 index 0000000..bd44322 --- /dev/null +++ b/lobby/target/classes/plugin.yml @@ -0,0 +1,6 @@ +name: NowlyLobby +main: com.br.guilhermematthew.nowly.lobby.LobbyMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] +depend: [BukkitCommons] \ No newline at end of file diff --git a/lobby/target/lobby-1.0-SNAPSHOT.jar b/lobby/target/lobby-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..a91029a Binary files /dev/null and b/lobby/target/lobby-1.0-SNAPSHOT.jar differ diff --git a/lobby/target/maven-archiver/pom.properties b/lobby/target/maven-archiver/pom.properties new file mode 100644 index 0000000..e619b1b --- /dev/null +++ b/lobby/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Feb 24 01:52:32 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=lobby diff --git a/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..ee84423 --- /dev/null +++ b/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,4 @@ +com\br\guilhermematthew\nowly\lobby\common\inventory\types\MixInventory.class +com\br\guilhermematthew\nowly\lobby\common\inventory\InventoryCommon$2.class +com\br\guilhermematthew\nowly\lobby\common\scoreboard\ScoreboardInstance.class +com\br\guilhermematthew\nowly\lobby\common\scoreboard\types\DuelsScoreboard.class diff --git a/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..6fdd10b --- /dev/null +++ b/lobby/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,26 @@ +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\types\LobbyPvPScoreboard.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\animating\StringAnimation.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\ScoreboardInstance.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\animating\FramesAnimation.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\listeners\GeneralListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\inventory\InventoryCommon.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\hologram\HologramCommon.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\AnimatedCommon.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\inventory\types\GamesInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\ScoreboardCommon.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\hologram\types\LobbyPvPHologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\LobbyMain.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\npcs\NPCCommon.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\animating\ActualAnimation.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\inventory\types\MixInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\types\LobbyScoreboard.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\types\LobbyHGScoreboard.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\npcs\types\LobbyHGNPC.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\npcs\types\LobbyNPC.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\hologram\types\LobbyHGHologram.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\listeners\AccountListener.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\npcs\types\LobbyPvPNPC.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\inventory\types\PvPInventory.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\scoreboard\types\DuelsScoreboard.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\common\LobbyUtility.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\lobby\src\main\java\com\br\guilhermematthew\nowly\lobby\commands\ServerCommand.java diff --git a/lobby/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/lobby/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/login/.classpath b/login/.classpath new file mode 100644 index 0000000..002ad57 --- /dev/null +++ b/login/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/login/.idea/.gitignore b/login/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/login/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/login/.idea/compiler.xml b/login/.idea/compiler.xml new file mode 100644 index 0000000..852a9a8 --- /dev/null +++ b/login/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/login/.idea/gradle.xml b/login/.idea/gradle.xml new file mode 100644 index 0000000..cabf132 --- /dev/null +++ b/login/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/login/.idea/jarRepositories.xml b/login/.idea/jarRepositories.xml new file mode 100644 index 0000000..e284c41 --- /dev/null +++ b/login/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/login/.idea/misc.xml b/login/.idea/misc.xml new file mode 100644 index 0000000..f6a4583 --- /dev/null +++ b/login/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/login/.idea/modules/login.main.iml b/login/.idea/modules/login.main.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/login/.idea/modules/login.main.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/login/.project b/login/.project new file mode 100644 index 0000000..67f034d --- /dev/null +++ b/login/.project @@ -0,0 +1,23 @@ + + + login + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/login/.settings/org.eclipse.jdt.core.prefs b/login/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/login/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/login/.settings/org.eclipse.m2e.core.prefs b/login/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/login/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/login/pom.xml b/login/pom.xml new file mode 100644 index 0000000..a5b3bd0 --- /dev/null +++ b/login/pom.xml @@ -0,0 +1,29 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + login + + + 8 + 8 + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + system + D:/Users/zFros/Desktop/[SRC]/☕ - Java/Dust/commons/target/commons-1.0-SNAPSHOT.jar + + + + \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMain.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMain.java new file mode 100644 index 0000000..a919df6 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMain.java @@ -0,0 +1,70 @@ +package com.br.guilhermematthew.nowly.login; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.plugin.java.JavaPlugin; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandFramework; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerLoadedEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.loader.BukkitListeners; +import com.br.guilhermematthew.nowly.login.manager.LoginManager; + +import lombok.Getter; +import lombok.Setter; + +public class LoginMain extends JavaPlugin { + + @Getter @Setter + private static LoginMain instance; + + @Getter @Setter + public static Location spawn; + + @Getter @Setter + private static LoginManager manager; + + public void onEnable() { + if (CommonsGeneral.correctlyStarted()) { + setInstance(this); + + setManager(new LoginManager()); + + PluginConfiguration.createLocation(getInstance(), "spawn"); + setSpawn(PluginConfiguration.getLocation(getInstance(), "spawn")); + + BukkitListeners.loadListeners(getInstance(), "com.br.guilhermematthew.nowly.login.listener"); + + BukkitCommandFramework.INSTANCE.loadCommands(this, "com.br.guilhermematthew.nowly.login.commands"); + + runLater(() -> { + getServer().getPluginManager().callEvent(new ServerLoadedEvent()); + }, BukkitMain.getServerType().getSecondsToStabilize() + 40); + } else { + Bukkit.shutdown(); + } + } + + public void onDisable() { + getManager().removeGamers(false); + } + + public static void console(String msg) { + Bukkit.getConsoleSender().sendMessage("[Login] " + msg); + } + + public static void runAsync(Runnable runnable) { + Bukkit.getScheduler().runTaskAsynchronously(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, 5L); + } + + public static void runLater(Runnable runnable, long ticks) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, ticks); + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMessages.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMessages.java new file mode 100644 index 0000000..ede9a08 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/LoginMessages.java @@ -0,0 +1,33 @@ +package com.br.guilhermematthew.nowly.login; + +public class LoginMessages { + + public static final String + + LOGIN_COMMAND_USAGE = "§cUse o comando: /login ", + REGISTER_COMMAND_USAGE = "§cUse o comando: /register ", + + VOCE_NAO_POSSUI_UM_REGISTRO = "§cVocê nao possuí um registro.", + VOCE_JA_ESTA_AUTENTICADO = "§aVocê já está autenticado.", + VOCE_JA_POSSUI_UM_REGISTRO = "§cVocê já possui um registro.", + + SENHA_MUITO_PEQUENA = "§cA sua senha é muito curta!", + SENHA_MUITO_GRANDE = "§cA sua senha é muito longa!", + SENHA_NAO_SAO_IGUAIS = "§cAs duas senhas não săo iguais!", + + LOGADO_COM_SUCESSO = "§aLogado com sucesso!", + REGISTRADO_COM_SUCESSO = "§aRegistrado com sucesso!. ", + + MENSAGEM_PARA_LOGAR = "§cUse o comando: /login .", + MENSAGEM_PARA_SE_REGISTRAR = "§cUse o comando: /register ", + + ERROU_A_SENHA_3_VEZES = "§cVocê errou a senha 3 vezes e foi expulso.", + SENHA_INCORRETA = "§cSenha incorreta!", + + VOCE_DEMOROU_MUITO = "§cVocê demorou muito para se autenticar!", + VOCE_DEMOROU_MUITO_PARA_ENTRAR_NO_LOBBY = "§cVocê demorou muito para entrar no lobby!", + CAPTCHA_CONCLUIDO = "§aCaptcha concluído!", + TEMPO_ESGOTADO = "§cTempo esgotado! Você não concluiu o captcha e foi expulso do servidor.", + PARA_USAR_UM_COMANDO_E_NECESSARIO_ESTAR_LOGADO = "§cPara usar um comando é necessário estar autenticado.", + VOCE_NAO_COMPLETOU_O_CAPTCHA = "§cPara se autenticar Você precisa completar o Captcha."; +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/commands/ServerCommand.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/commands/ServerCommand.java new file mode 100644 index 0000000..82c7828 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/commands/ServerCommand.java @@ -0,0 +1,266 @@ +package com.br.guilhermematthew.nowly.login.commands; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.commons.common.utility.system.DateUtils; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.nowly.login.LoginMain; +import com.br.guilhermematthew.nowly.login.LoginMessages; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer.AuthenticationType; +import com.br.guilhermematthew.servercommunication.client.Client; + +public class ServerCommand implements CommandClass { + + public static ArrayList autorizados = new ArrayList<>(); + + @Command(name = "login", aliases= {"logar"}) + public void login(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + if (args.length != 1) { + commandSender.sendMessage(LoginMessages.LOGIN_COMMAND_USAGE); + return; + } + + Player player = commandSender.getPlayer(); + + if (!CommonsGeneral.getProfileManager().containsProfile(player.getUniqueId())) { + player.kickPlayer("§cOcorreu um erro, tente novamente."); + return; + } + + Gamer gamer = LoginMain.getManager().getGamer(player); + + if (!gamer.isCaptchaConcluido()) { + player.sendMessage(LoginMessages.VOCE_NAO_COMPLETOU_O_CAPTCHA); + return; + } + + if (gamer.getAuthenticationType() == AuthenticationType.REGISTRAR) { + player.sendMessage(LoginMessages.VOCE_NAO_POSSUI_UM_REGISTRO); + return; + } + + if (gamer.isLogado()) { + player.sendMessage(LoginMessages.VOCE_JA_ESTA_AUTENTICADO); + return; + } + + String senha = args[0]; + + if (!format(senha).equalsIgnoreCase(BukkitMain.getBukkitPlayer(player.getUniqueId()).getString(DataType.REGISTRO_SENHA))) { + gamer.setTentativasFalhas(gamer.getTentativasFalhas() + 1); + + if (gamer.getTentativasFalhas() == 3) { + player.kickPlayer(LoginMessages.ERROU_A_SENHA_3_VEZES); + } else { + player.sendMessage(LoginMessages.SENHA_INCORRETA); + } + return; + } + + //TitleAPI.sendTitle(player, "§aAutenticado!", "§faguarde...", 0, 0, 6); + + player.sendMessage(LoginMessages.LOGADO_COM_SUCESSO); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F); + + gamer.setLogado(true); + + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(player.getName()).type(PacketType.BUKKIT_SEND_INFO).field("player-authenticated")); + + LoginMain.runLater(() -> { + if (player.isOnline()) { + BukkitServerAPI.redirectPlayer(player, "Lobby"); + //player.getInventory().setItem(0, + // new ItemBuilder().type(Material.COMPASS).name("§aClique para conectar-se ao Lobby").glow().build()); + } + }, 20); + } + + @Command(name = "register", aliases= {"registrar"}) + public void register(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length != 2) { + commandSender.sendMessage(LoginMessages.REGISTER_COMMAND_USAGE); + return; + } + + + Player player = commandSender.getPlayer(); + + if (!CommonsGeneral.getProfileManager().containsProfile(player.getUniqueId())) { + player.kickPlayer("§cOcorreu um erro, tente novamente."); + return; + } + + Gamer gamer = LoginMain.getManager().getGamer(player); + + if (!gamer.isCaptchaConcluido()) { + player.sendMessage(LoginMessages.VOCE_NAO_COMPLETOU_O_CAPTCHA); + return; + } + + if (gamer.getAuthenticationType() == AuthenticationType.LOGAR) { + player.sendMessage(LoginMessages.VOCE_JA_POSSUI_UM_REGISTRO); + return; + } + + if (gamer.isLogado()) { + player.sendMessage(LoginMessages.VOCE_JA_ESTA_AUTENTICADO); + return; + } + + String senha = args[0], + senha1 = args[1]; + + if (senha.length() < 4) { + player.sendMessage(LoginMessages.SENHA_MUITO_PEQUENA); + return; + } + + if (senha.length() > 20) { + player.sendMessage(LoginMessages.SENHA_MUITO_GRANDE); + return; + } + + if (!senha.equals(senha1)) { + player.sendMessage(LoginMessages.SENHA_NAO_SAO_IGUAIS); + return; + } + + String data = DateUtils.getActualDate(false); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + bukkitPlayer.set(DataType.REGISTRO_SENHA, format(senha)); + bukkitPlayer.set(DataType.REGISTRO_DATA, data); + + //TitleAPI.sendTitle(player, "§aRegistrado", "§fcom sucesso!", 0, 0, 6); + + player.sendMessage(LoginMessages.REGISTRADO_COM_SUCESSO); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F); + gamer.setLogado(true); + + registrar(player, format(senha), data); + } + + @Command(name = "setloc", groupsToUse= {Groups.ADMIN}) + public void setloc(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage("§cUse: /setloc spawn"); + return; + } + Player player = commandSender.getPlayer(); + if (args.length == 1) { + if (args[0].equalsIgnoreCase("spawn")) { + PluginConfiguration.setLocation(LoginMain.getInstance(), "spawn", player); + LoginMain.setSpawn(PluginConfiguration.getLocation(LoginMain.getInstance(), "spawn")); + commandSender.sendMessage("§aSpawn setado!"); + } else { + commandSender.sendMessage("§cUse: /setloc spawn"); + } + } else { + commandSender.sendMessage("§cUse: /setloc spawn"); + } + } + + @Command(name = "build", aliases= {"b"}, groupsToUse= {Groups.ADMIN}) + public void build(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (autorizados.contains(player.getUniqueId())) { + autorizados.remove(player.getUniqueId()); + player.sendMessage("§aVocê desativou o modo construçăo."); + player.setGameMode(GameMode.ADVENTURE); + } else { + autorizados.add(player.getUniqueId()); + player.sendMessage("§aVocê ativou o modo construçăo."); + player.setGameMode(GameMode.CREATIVE); + } + } + + private void registrar(Player player, String senha, String dataRegistro) { + Client.getInstance().getClientConnection().sendPacket(new CPacketCustomAction(player.getName()).type(PacketType.BUKKIT_SEND_INFO).field("player-authenticated")); + + LoginMain.runAsync(() -> { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + bukkitPlayer.set(DataType.REGISTRO_SENHA, senha); + bukkitPlayer.set(DataType.REGISTRO_DATA, dataRegistro); + + try (Connection connection = CommonsGeneral.getMySQL().getConnection()) { + PreparedStatement insert = connection.prepareStatement(bukkitPlayer. + getDataHandler().createInsertIntoStringQuery(DataCategory.REGISTER)); + + insert.execute(); + insert.close(); + + bukkitPlayer.getDataHandler().saveCategory(DataCategory.REGISTER); + } catch (SQLException e) { + e.printStackTrace(); + } + }); + + LoginMain.runLater(() -> { + if (player.isOnline()) { + BukkitServerAPI.redirectPlayer(player, "Lobby"); + //player.getInventory().setItem(0, + // new ItemBuilder().type(Material.COMPASS).name("§aClique para conectar-se ao Lobby").glow().build()); + } + }, 20); + } + + public static void kickPlayer(Player player, String mensagem) { + BukkitMain.runLater(() -> {player.kickPlayer(mensagem);}); + } + + public static String format(String string) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] array = md.digest(string.getBytes()); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < array.length; i++) { + sb.append(Integer.toHexString(array[i] & 0xFF | 0x100).substring(1, 3)); + } + return sb.toString(); + } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {} + return null; + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.java new file mode 100644 index 0000000..cab565e --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.java @@ -0,0 +1,93 @@ +package com.br.guilhermematthew.nowly.login.listener; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.login.LoginMain; +import com.br.guilhermematthew.nowly.login.LoginMessages; +import com.br.guilhermematthew.nowly.login.manager.captcha.CaptchaManager; +import org.bukkit.inventory.meta.ItemMeta; + +public class CaptchaListeners implements Listener { + + @EventHandler + public void onClick(InventoryClickEvent event) { + if ((event.getClickedInventory() != null) && (event.getCurrentItem() != null) && (event.getCurrentItem().hasItemMeta())) { + Player player = (Player) event.getWhoClicked(); + if (event.getClickedInventory().getTitle().equalsIgnoreCase("Sistema de captcha")) { + event.setCancelled(true); + + ItemStack item = event.getCurrentItem(); + if (item.getType() == Material.SKULL_ITEM) { + ItemMeta itemMeta = item.getItemMeta(); + if (itemMeta != null) { + if (itemMeta.getDisplayName().equals("§aClique para escolher este")) { + LoginMain.getManager().getGamer(player).setCaptchaConcluido(true); + + player.sendMessage(LoginMessages.CAPTCHA_CONCLUIDO); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F); + + player.closeInventory(); + } else { + player.kickPlayer("§cDetectamos que Você errou em nosso teste CAPTCHA\n§cVocê foi removido por segurança!"); + } + + } + + itemMeta = null; + } + } + } + } + + + + @EventHandler + public void onInventoryClose(InventoryCloseEvent event) { + if (event.getInventory().getName().contains("Sistema")) { + Player player = (Player) event.getPlayer(); + + LoginMain.runLater(() -> { + if (player == null) return; + if (LoginMain.getManager().getGamer(player).isCaptchaConcluido()) return; + + CaptchaManager.createCaptcha(player); + }, 20); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + if (!LoginMain.getManager().getGamer(event.getPlayer()).isLogado()) { + event.getPlayer().teleport(event.getFrom()); + } + } + + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + + if (!LoginMain.getManager().getGamer(player).isLogado()) { + + String msg = event.getMessage().toLowerCase(); + if (msg.startsWith("/logar") + || (msg.startsWith("/registrar") || (msg.startsWith("/login") || (msg.startsWith("/register"))))) { + event.setCancelled(false); + } else { + event.setCancelled(true); + player.sendMessage(LoginMessages.PARA_USAR_UM_COMANDO_E_NECESSARIO_ESTAR_LOGADO); + } + } + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.java new file mode 100644 index 0000000..19ef6e7 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.java @@ -0,0 +1,275 @@ +package com.br.guilhermematthew.nowly.login.listener; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import lombok.SneakyThrows; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.*; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.inventory.Inventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.login.LoginMain; +import com.br.guilhermematthew.nowly.login.LoginMessages; +import com.br.guilhermematthew.nowly.login.commands.ServerCommand; +import com.br.guilhermematthew.nowly.login.manager.captcha.CaptchaManager; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer.AuthenticationType; + +import lombok.Getter; + +public class GeneralListeners implements Listener { + + private static final Inventory inventory = Bukkit.getServer().createInventory(null, 9, "Clique para se conectar"); + + static { + //inventory.setItem(0, new ItemBuilder().type(Material.NETHER_STAR).name("§aConectar a Main Lobby").build()); + } + + private int MINUTES = 0; + + @Getter + private static final List runnableQueue = new ArrayList<>(); + + @EventHandler + public void onMinute(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.MINUTO) { + return; + } + + if (MINUTES == 10) { + LoginMain.getManager().removeGamers(true); + MINUTES=0; + return; + } + MINUTES++; + } + + @EventHandler + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + for (Player onlines : Bukkit.getOnlinePlayers()) { + Gamer gamer = LoginMain.getManager().getGamer(onlines); + + if (gamer == null) + continue; + + if (gamer.isCaptchaConcluido()) { + if (!gamer.isLogado()) { + if (gamer.getSecondsLogin() == 20) { + onlines.kickPlayer(LoginMessages.VOCE_DEMOROU_MUITO); + continue; + } + if (gamer.getSecondsLogin() % 2 == 0) { + if (gamer.getAuthenticationType() == AuthenticationType.LOGAR) { + onlines.sendMessage(LoginMessages.MENSAGEM_PARA_LOGAR); + } else { + onlines.sendMessage(LoginMessages.MENSAGEM_PARA_SE_REGISTRAR); + } + } + gamer.addSecondsLogin(); + } else { + if (gamer.getSecondsConnect() == 25) { + onlines.kickPlayer(LoginMessages.VOCE_DEMOROU_MUITO_PARA_ENTRAR_NO_LOBBY); + continue; + } + gamer.addSecondsConnect(); + } + } else { + if (gamer.getSecondsCaptcha() == 8) { + onlines.kickPlayer(LoginMessages.TEMPO_ESGOTADO); + continue; + } + gamer.addSecondsCaptcha(); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onUpdateHandleQueue(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) + return; + + if (runnableQueue.size() > 0) { + Runnable runnable = runnableQueue.remove(0); + runnable.run(); + } + } + + @EventHandler + public void onInventory(InventoryClickEvent event) { + if (event.getWhoClicked() instanceof Player) { + if (event.getInventory().getTitle().equals(inventory.getTitle())) { + if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) { + event.setCancelled(true); + Player player = (Player)event.getWhoClicked(); + + player.closeInventory(); + + BukkitServerAPI.redirectPlayer(player, "Lobby"); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) @SneakyThrows + public void onLogin(PlayerLoginEvent event) { + if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) { + Player player = event.getPlayer(); + + AuthenticationType authenticationType = AuthenticationType.LOGAR; + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + bukkitPlayer.getDataHandler().load(DataCategory.REGISTER); + String password = bukkitPlayer.getString(DataType.REGISTRO_SENHA); + + System.out.println(password); + + if (password.length() < 4) { + authenticationType = AuthenticationType.REGISTRAR; + bukkitPlayer.set(DataType.LAST_IP, event.getAddress().getHostAddress()); + bukkitPlayer.set(DataType.FIRST_LOGGED_IN, System.currentTimeMillis()); + } + + LoginMain.getManager().addGamer(player, authenticationType); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + player.getInventory().clear(); + player.teleport(LoginMain.getSpawn()); + + if (!player.getGameMode().equals(GameMode.ADVENTURE)) { + player.setGameMode(GameMode.ADVENTURE); + } + + BukkitMain.runLater(() -> { + if (!player.isOnline()) + return; + + CaptchaManager.createCaptcha(player); + }, 30L); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + final UUID uuid = event.getPlayer().getUniqueId(); + + LoginMain.getManager().getGamers().get(uuid).refresh(); + + ServerCommand.autorizados.remove(uuid); + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onAsyncChat(AsyncPlayerChatEvent event) { + if (event.getMessage().startsWith("/")) return; + + event.setCancelled(true); + } + + @EventHandler + public void onSpread(BlockSpreadEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + event.setCancelled(true); + if (event.getCause().equals(DamageCause.VOID)) { + event.getEntity().teleport(LoginMain.getSpawn()); + } + } + + @EventHandler + public void onDamage(EntityDamageByEntityEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void ignite(BlockIgniteEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onEntitySpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onSpawn(ItemSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onBreak(BlockBreakEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if ((event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) && + (ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))) { + event.setCancelled(false); + } else { + event.setCancelled(true); + } + + if (event.getAction() != Action.PHYSICAL) { + if (event.getPlayer().getItemInHand().getType().equals(Material.COMPASS)) { + event.getPlayer().openInventory(inventory); + } + } + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/LoginManager.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/LoginManager.java new file mode 100644 index 0000000..cfb7d77 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/LoginManager.java @@ -0,0 +1,78 @@ +package com.br.guilhermematthew.nowly.login.manager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.common.connections.mysql.MySQLManager; +import com.br.guilhermematthew.nowly.login.LoginMain; +import com.br.guilhermematthew.nowly.login.listener.GeneralListeners; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.login.manager.gamer.Gamer.AuthenticationType; + +import lombok.Getter; + +@Getter +public class LoginManager { + + private final HashMap gamers = new HashMap<>(); + + public Gamer getGamer(Player player) { + return getGamers().get(player.getUniqueId()); + } + + public void addGamer(Player player, AuthenticationType authenticationType) { + if (getGamers().containsKey(player.getUniqueId())) { + getGamers().get(player.getUniqueId()).handleLogin(player); + return; + } + getGamers().put(player.getUniqueId(), new Gamer(player, authenticationType)); + } + + public void removeGamers(boolean addToQueue) { + List toRemove = new ArrayList<>(); + + for (Gamer gamers : getGamers().values()) { + if (System.currentTimeMillis() > gamers.getTimestamp() + TimeUnit.MINUTES.toMillis(10)) { + if (!gamers.getPlayer().isOnline()) { + toRemove.add(gamers.getUniqueId()); + } + } + } + + if (toRemove.size() != 0) { + for (UUID uuid : toRemove) { + String nick = getGamers().get(uuid).getNick(); + + getGamers().remove(uuid); + + if (addToQueue) { + GeneralListeners.getRunnableQueue().add(() -> LoginMain.runAsync(() -> { + if (MySQLManager.contains("premium_map", "nick", nick)) { + + if (!MySQLManager.contains("accounts", "nick", nick)) { + MySQLManager + .executeUpdate("DELETE FROM premium_map WHERE nick='" + nick + "';"); + } + } + })); + } else { + LoginMain.runAsync(() -> { + if (MySQLManager.contains("premium_map", "nick", nick)) { + if (!MySQLManager.contains("accounts", "nick", nick)) { + MySQLManager + .executeUpdate("DELETE FROM premium_map WHERE nick='" + nick + "';"); + } + } + }); + } + } + } + + toRemove.clear(); + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.java new file mode 100644 index 0000000..9f363a4 --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.java @@ -0,0 +1,33 @@ +package com.br.guilhermematthew.nowly.login.manager.captcha; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class CaptchaManager { + + private final static ItemStack olhoDoFim = new ItemBuilder().type(Material.SKULL_ITEM).skinURL("http://textures.minecraft.net/texture/57c57ecc6f34fc34cd3524ce0b7c1dd1c405f1310ea25425e72c8a502e99ad52").durability(3).name("§aClique para escolher este").build(); + private final static ItemStack enderPearl = new ItemBuilder().type(Material.SKULL_ITEM).skinURL("http://textures.minecraft.net/texture/c9f28bf9d149443583f9c1cbc0f17d8f186648336d7d3688ed471cfdf8837002").durability(3).name("§7Ops! Escolha outro está é a errada.").build(); + + public static void createCaptcha(Player player) { + if (!player.isOnline()) return; + + Inventory inventory = player.getServer().createInventory(null, 3 * 9, "Sistema de captcha"); + + int randomSlot = CommonsConst.RANDOM.nextInt(26); + inventory.setItem(randomSlot, olhoDoFim); + + for (int i = 0; i < 27; i++) { + if (i == randomSlot) { + continue; + } + inventory.setItem(i, enderPearl); + } + + player.openInventory(inventory); + } +} \ No newline at end of file diff --git a/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.java b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.java new file mode 100644 index 0000000..d97bcaf --- /dev/null +++ b/login/src/main/java/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.login.manager.gamer; + +import java.util.UUID; + +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class Gamer { + + private Player player; + private String nick; + private UUID uniqueId; + private boolean captchaConcluido, logado; + private int tentativasFalhas, secondsCaptcha, secondsLogin, secondsConnect; + private Long timestamp; + + private AuthenticationType authenticationType; + + public Gamer(Player player, AuthenticationType authenticationType) { + setPlayer(player); + setNick(player.getName()); + + setAuthenticationType(authenticationType); + + setUniqueId(player.getUniqueId()); + + setCaptchaConcluido(false); + setLogado(false); + setTentativasFalhas(0); + + setSecondsCaptcha(-2); + setSecondsLogin(-1); + setSecondsConnect(-1); + + setTimestamp(System.currentTimeMillis()); + } + + public void handleLogin(Player player) { + setPlayer(player); + + refresh(); + } + + public void refresh() { + setCaptchaConcluido(false); + setLogado(false); + setTentativasFalhas(0); + setSecondsCaptcha(-2); + setSecondsLogin(-1); + setSecondsConnect(-1); + } + + public void addSecondsCaptcha() { + setSecondsCaptcha(getSecondsCaptcha() + 1); + } + + public void addSecondsLogin() { + setSecondsLogin(getSecondsLogin() + 1); + } + + public void addSecondsConnect() { + setSecondsConnect(getSecondsConnect() + 1); + } + + public enum AuthenticationType { + REGISTRAR, LOGAR + } +} \ No newline at end of file diff --git a/login/src/main/resources/config.yml b/login/src/main/resources/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/login/src/main/resources/plugin.yml b/login/src/main/resources/plugin.yml new file mode 100644 index 0000000..0208467 --- /dev/null +++ b/login/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: authLib +main: com.br.guilhermematthew.nowly.login.LoginMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMain.class b/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMain.class new file mode 100644 index 0000000..a097fe8 Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMain.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMessages.class b/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMessages.class new file mode 100644 index 0000000..a436006 Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/LoginMessages.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/commands/ServerCommand.class b/login/target/classes/com/br/guilhermematthew/nowly/login/commands/ServerCommand.class new file mode 100644 index 0000000..43d287a Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/commands/ServerCommand.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.class b/login/target/classes/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.class new file mode 100644 index 0000000..311be8b Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/listener/CaptchaListeners.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.class b/login/target/classes/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.class new file mode 100644 index 0000000..d2d18fe Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/listener/GeneralListeners.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/manager/LoginManager.class b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/LoginManager.class new file mode 100644 index 0000000..bf44b18 Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/LoginManager.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.class b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.class new file mode 100644 index 0000000..344863f Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/captcha/CaptchaManager.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer$AuthenticationType.class b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer$AuthenticationType.class new file mode 100644 index 0000000..ebde22b Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer$AuthenticationType.class differ diff --git a/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.class b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.class new file mode 100644 index 0000000..98e5c2e Binary files /dev/null and b/login/target/classes/com/br/guilhermematthew/nowly/login/manager/gamer/Gamer.class differ diff --git a/login/target/classes/config.yml b/login/target/classes/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/login/target/classes/plugin.yml b/login/target/classes/plugin.yml new file mode 100644 index 0000000..0208467 --- /dev/null +++ b/login/target/classes/plugin.yml @@ -0,0 +1,5 @@ +name: authLib +main: com.br.guilhermematthew.nowly.login.LoginMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/login/target/login-1.0-SNAPSHOT.jar b/login/target/login-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..965a6e8 Binary files /dev/null and b/login/target/login-1.0-SNAPSHOT.jar differ diff --git a/login/target/maven-archiver/pom.properties b/login/target/maven-archiver/pom.properties new file mode 100644 index 0000000..aeb44f1 --- /dev/null +++ b/login/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Feb 24 01:53:12 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=login diff --git a/login/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/login/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/login/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/login/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..1a44c00 --- /dev/null +++ b/login/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,8 @@ +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\manager\LoginManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\listener\CaptchaListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\LoginMain.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\listener\GeneralListeners.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\manager\gamer\Gamer.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\LoginMessages.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\manager\captcha\CaptchaManager.java +D:\Users\zFros\Desktop\[SRC]\☕ - Java\Dust\login\src\main\java\com\br\guilhermematthew\nowly\login\commands\ServerCommand.java diff --git a/login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/login/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..298c198 --- /dev/null +++ b/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.br.guilhermematthew.nowly + dustmc + pom + 1.0-SNAPSHOT + + commons + lobby + servercommunication + login + pvp + hardcoregames + anticheat + + + + 8 + 8 + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + nms-repo + https://repo.codemc.org/repository/nms/ + + + + + + org.projectlombok + lombok + 1.16.12 + provided + + + org.github.paperspigot + paperspigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + + \ No newline at end of file diff --git a/pvp/.classpath b/pvp/.classpath new file mode 100644 index 0000000..002ad57 --- /dev/null +++ b/pvp/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pvp/.idea/.gitignore b/pvp/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/pvp/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/pvp/.idea/compiler.xml b/pvp/.idea/compiler.xml new file mode 100644 index 0000000..e203716 --- /dev/null +++ b/pvp/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pvp/.idea/gradle.xml b/pvp/.idea/gradle.xml new file mode 100644 index 0000000..cabf132 --- /dev/null +++ b/pvp/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/pvp/.idea/jarRepositories.xml b/pvp/.idea/jarRepositories.xml new file mode 100644 index 0000000..e284c41 --- /dev/null +++ b/pvp/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pvp/.idea/misc.xml b/pvp/.idea/misc.xml new file mode 100644 index 0000000..c299b59 --- /dev/null +++ b/pvp/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pvp/.idea/modules/pvp.main.iml b/pvp/.idea/modules/pvp.main.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/pvp/.idea/modules/pvp.main.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/pvp/.project b/pvp/.project new file mode 100644 index 0000000..48fb4e5 --- /dev/null +++ b/pvp/.project @@ -0,0 +1,23 @@ + + + pvp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pvp/.settings/org.eclipse.jdt.core.prefs b/pvp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/pvp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/pvp/pom.xml b/pvp/pom.xml new file mode 100644 index 0000000..863b385 --- /dev/null +++ b/pvp/pom.xml @@ -0,0 +1,28 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + pvp + + + 8 + 8 + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + Project + + + + \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/PvPMain.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/PvPMain.java new file mode 100644 index 0000000..24345c5 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/PvPMain.java @@ -0,0 +1,94 @@ +package com.br.guilhermematthew.nowly.pvp; + +import com.br.guilhermematthew.nowly.pvp.mode.arena.ArenaMode; +import com.br.guilhermematthew.nowly.pvp.mode.fps.FPSMode; +import com.br.guilhermematthew.nowly.pvp.mode.lavachallenge.LavaChallengeMode; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandFramework; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerLoadedEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.loader.BukkitListeners; + +import lombok.Getter; +import lombok.Setter; + +public class PvPMain extends JavaPlugin { + + @Getter @Setter + private static PvPMain instance; + + public void onLoad() { + setInstance(this); + + saveDefaultConfig(); + } + + public void onEnable() { + if (CommonsGeneral.correctlyStarted()) { + BukkitServerAPI.registerServer(); + + boolean findedMode = false; + + switch (BukkitMain.getServerType()) { + case PVP_FPS: + FPSMode.init(); + findedMode = true; + break; + case PVP_LAVACHALLENGE: + LavaChallengeMode.init(); + + LavaChallengeMode.updateDifficulty(getConfig().getInt("LavaChallenge.MinHit.Facil"), + getConfig().getInt("LavaChallenge.MinHit.Medio"), + getConfig().getInt("LavaChallenge.MinHit.Dificil"), + getConfig().getInt("LavaChallenge.MinHit.Extremo")); + + findedMode = true; + break; + case PVP_ARENA: + ArenaMode.init(); + findedMode = true; + break; + default: + break; + } + + if (!findedMode) { + Bukkit.shutdown(); + return; + } + + BukkitListeners.loadListeners(getInstance(), "com.br.guilhermematthew.nowly.pvp.listeners"); + BukkitCommandFramework.INSTANCE.loadCommands(this, "com.br.guilhermematthew.nowly.pvp.commands"); + + runLater(() -> { + getServer().getPluginManager().callEvent(new ServerLoadedEvent()); + }, BukkitMain.getServerType().getSecondsToStabilize()); + } else { + Bukkit.shutdown(); + } + } + + public void onDisable() { + + } + + public static void console(String msg) { + Bukkit.getConsoleSender().sendMessage("[PvP] " + msg); + } + + public static void runAsync(Runnable runnable) { + Bukkit.getScheduler().runTaskAsynchronously(getInstance(), runnable); + } + + public static void runLater(Runnable runnable) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, 5L); + } + + public static void runLater(Runnable runnable, long ticks) { + Bukkit.getScheduler().runTaskLater(getInstance(), runnable, ticks); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/StringUtils.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/StringUtils.java new file mode 100644 index 0000000..9fbca6e --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/StringUtils.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.nowly.pvp; + +public class StringUtils { + + public static final String + + + VOCE_NAO_PODE_USAR_ESTA_COMBINAÇĂO_DE_KIT = "§cEsta combinação de Kit está bloqueada!", + VOCE_NAO_PODE_USAR_O_MESMO_KIT = "§cVocê já está utilizando este Kit.", + VOCE_COMPROU_O_KIT = "§aVocê comprou o kit §e%kit%!", + VOCE_NAO_TEM_COINS_O_SUFICIENTE_PARA_COMPRAR_O_KIT = "§cVocê precisa de mais %valor% coins para comprar este kit!", + + VOCE_SELECIONOU_O_KIT_PRIMARIO = "§aVocê selecionou o %kit% como kit primário.", + VOCE_SELECIONOU_O_KIT_SECUNDARIO = "§aVocê selecionou o %kit% como kit secundário", + + BUSSOLA_NOT_FINDED = "§eNenhum jogador por perto, bússola apontando para o spawn.", + BUSSOLA_FINDED = "§eSua bússola está apontando para §b%nick%", + PERDEU_A_PROTEÇĂO = "§cVocê perdeu a proteção do spawn.", + VOCE_MORREU = "§cVocê morreu!", + VOCE_MORREU_PARA = "§cVocê morreu para %nick%!", + VOCE_MATOU = "§cVocê matou %nick%", + + VOCE_NAO_PODE_IR_PARA_O_SPAWN_EM_PVP = "§cVocê não pode ir para o spawn em combate!", + VOCE_NAO_PODE_IR_PARA_O_SPAWN_AGORA = "§cVocê não pode ir para o spawn agora!", + VOCE_JA_ESTA_NO_SPAWN = "§cVocê ja está no spawn!", + VOCE_FOI_PARA_O_SPAWN = "§aVocê foi para o spawn!", + + VOCE_COMPLETOU_LAVA_CHALLENGE = "§aVocê concluiu a dificuldade %dificuldade%", + + KILLSTREAK_WIN = "§e%nick% conseguiu atingir a taxa de killstreak de §b%valor%", + KILLSTREAK_LOSE = "§c%loser% perdeu sua taxa de killstreak de %valor% para %killer%"; +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/Kit.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/Kit.java new file mode 100644 index 0000000..3cca77f --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/Kit.java @@ -0,0 +1,154 @@ +package com.br.guilhermematthew.nowly.pvp.ability; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.CooldownAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.cooldown.types.Cooldown; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.protocol.ProtocolGetter; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.pvp.manager.kit.KitLoader; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public abstract class Kit implements Listener { + + private int amountUsing; + private String name; + private List description; + private ItemStack icon; + private int price, cooldownSeconds; + private ItemStack[] itens; + + private final String itemColor = "§b"; + + public void initialize(String kitName) { + setName(kitName); + + ItemStack icone = new ItemBuilder().type(Material.getMaterial( + getKitsConfig().getString("kits." + getName() + ".icon.material"))). + durability(getKitsConfig().getInt("kits." + getName() + ".icon.durability")). + amount(getKitsConfig().getInt("kits." + getName() + ".icon.amount")) + .build(); + + setIcon(icone); + + setItens(new ItemStack(Material.AIR)); + + setPrice(getKitsConfig().getInt("kits." + getName() + ".price")); + setCooldownSeconds(getKitsConfig().getInt("kits." + getName() + ".cooldown")); + updateDescription(getKitsConfig().getStringList("kits." + getName() + ".icon.description")); + + icone = null; + } + + public void updateDescription(List list) { + this.description = list; + + ItemMeta meta = getIcon().getItemMeta(); + + List lore = new ArrayList(); + + for (String descriptionL : this.description) { + lore.add(descriptionL.replaceAll("&", "§")); + } + + meta.setDisplayName("§a" + getName()); + meta.setLore(lore); + + getIcon().setItemMeta(meta); + setAmountUsing(0); + + lore.clear(); + + meta = null; + lore = null; + } + + //CLEAN PLAYER FROM HASHMAPS, ETC. + protected abstract void clean(Player player); + + public void setItens(ItemStack... itens) { + this.itens = itens; + } + + protected boolean hasAbility(Player player) { + return GamerManager.getGamer(player.getUniqueId()).containsKit(getName()); + } + + public void registerPlayer() { + this.amountUsing++; + + if (this.amountUsing == 1) { + Bukkit.getPluginManager().registerEvents(this, PvPMain.getInstance()); + } + } + + public void unregisterPlayer(Player player) { + if (CooldownAPI.hasCooldown(player, getName())) { + CooldownAPI.removeCooldown(player, getName()); + } + + clean(player); + + this.amountUsing--; + + if (amountUsing == 0) { + HandlerList.unregisterAll(this); + } + } + + protected boolean hasCooldown(Player player, final String cooldownName) { + return CooldownAPI.hasCooldown(player, cooldownName); + } + + protected boolean hasCooldown(Player player) { + return CooldownAPI.hasCooldown(player, getName()); + } + + protected void sendMessageCooldown(Player player) { + CooldownAPI.sendMessage(player, getName()); + } + + protected void addCooldown(Player player, long time) { + if (CooldownAPI.hasCooldown(player, getName())) { + CooldownAPI.removeCooldown(player, getName()); + } + + CooldownAPI.addCooldown(player, new Cooldown(getName(), time, playerOn18(player))); + } + + protected void addCooldown(Player player, String cooldownName, long time) { + if (CooldownAPI.hasCooldown(player, cooldownName)) { + CooldownAPI.removeCooldown(player, cooldownName); + } + + CooldownAPI.addCooldown(player, new Cooldown(cooldownName, time, playerOn18(player))); + } + + public boolean playerOn18(final Player player) { + return ProtocolGetter.getVersion(player) > 5; + } + + public FileConfiguration getKitsConfig() { + return KitLoader.getKitsConfig().getConfiguration(); + } + + public boolean checkItem(ItemStack item, String display) { + return (item != null && item.getType() != Material.AIR && item.hasItemMeta() && item.getItemMeta().hasDisplayName() + && item.getItemMeta().getDisplayName().startsWith(display)); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Anchor.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Anchor.java new file mode 100644 index 0000000..665fcd4 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Anchor.java @@ -0,0 +1,42 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; + +public class Anchor extends Kit { + + public Anchor() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getDamaged())) { + handle(event.getDamaged(), event.getPlayer()); + } else if (hasAbility(event.getPlayer())) { + handle(event.getDamaged(), event.getPlayer()); + } + } + + public void handle(Player player1, Player player2) { + player1.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + player2.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + + player1.playSound(player1.getLocation(), Sound.ANVIL_LAND, 1, 1); + player2.playSound(player2.getLocation(), Sound.ANVIL_LAND, 1, 1); + + PvPMain.runLater(() -> { + player1.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + player2.setVelocity(new Vector(0.0D, 0.0D, 0.0D)); + }, 1L); + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/AntiTower.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/AntiTower.java new file mode 100644 index 0000000..c1d2ae7 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/AntiTower.java @@ -0,0 +1,13 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.entity.Player; + +public class AntiTower extends Kit { + + public AntiTower() { + initialize(getClass().getSimpleName()); + } + + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Berserker.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Berserker.java new file mode 100644 index 0000000..e851b76 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Berserker.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Berserker extends Kit { + + public Berserker() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onKilledPlayer(PlayerDeathEvent event) { + Player player = event.getEntity(); + if (hasAbility(player.getKiller())) { + if (player.isDead()) { + if(player.getKiller() instanceof Player) { + player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 150, 1)); + player.sendMessage("§aVocê recebeu a força de um BERSERKER por um tempo valido de 10 segundos!"); + } + } + } + } + + @Override + protected void clean(Player player) { + } + +} diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Boxer.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Boxer.java new file mode 100644 index 0000000..b4ac81c --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Boxer.java @@ -0,0 +1,24 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; + +public class Boxer extends Kit { + + public Boxer() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getDamaged())) { + event.setDamage(event.getDamage() - 0.9D); + } + } + + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Camel.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Camel.java new file mode 100644 index 0000000..2d2b945 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Camel.java @@ -0,0 +1,39 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import lombok.val; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class Camel extends Kit { + + public Camel() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + if (event.isCancelled()) return; + + val player = event.getPlayer(); + if(!hasAbility(player)) return; + + val blockType = event.getTo().getBlock().getRelative(BlockFace.DOWN).getType(); + if (blockType.equals(Material.SAND) || blockType.equals(Material.SOUL_SAND)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 150, 0)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 150, 0)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 1)); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Fisherman.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Fisherman.java new file mode 100644 index 0000000..74adeb0 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Fisherman.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import lombok.val; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerFishEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.metadata.FixedMetadataValue; + +public class Fisherman extends Kit { + + public Fisherman() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.FISHING_ROD).name( + getItemColor() + "Kit " + getName()).unbreakable().build()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onDamage(EntityDamageByEntityEvent e) { + if(!(e.getEntity() instanceof Player)) return; + + val damager = e.getDamager(); + + if(damager != null && damager.hasMetadata("fisherman")) { + e.setDamage(0); + + damager.getMetadata("fisherman").stream().findFirst().ifPresent(rawMeta -> { + val player = (Player) rawMeta.value(); + + player.sendMessage(ChatColor.GREEN + "Você fisgou " + e.getEntity().getName()); + }); + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerFishListener(PlayerFishEvent event) { + if(event.getState() == PlayerFishEvent.State.FISHING) { + if(hasAbility(event.getPlayer())) event.getHook().setMetadata("fisherman", new FixedMetadataValue(PvPMain.getInstance(), event.getPlayer())); + } + + if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY && event.getCaught() instanceof Player) { + Player player = event.getPlayer(); + + if (hasAbility(player) && !CombatLogListener.isProtected(player)) { + Player caughtPlayer = (Player) event.getCaught(); + + if (caughtPlayer != player) { + if (!CombatLogListener.isProtected(caughtPlayer)) { + caughtPlayer.teleport(player.getLocation()); + } + } else { + event.setCancelled(true); + } + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Flash.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Flash.java new file mode 100644 index 0000000..7bdf7b7 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Flash.java @@ -0,0 +1,71 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.HashSet; + +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.util.BlockIterator; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class Flash extends Kit { + + public Flash() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.REDSTONE_TORCH_ON).name(getItemColor() + "Kit " + getName()).build()); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInteract(PlayerInteractEvent e) { + if(e.getAction() == Action.PHYSICAL) return; + + if (hasAbility(e.getPlayer()) && checkItem(e.getItem(), getItemColor() + "Kit " + getName())) { + if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { + e.setCancelled(true); + e.getPlayer().updateInventory(); + return; + } + + if (e.getAction() != Action.RIGHT_CLICK_AIR) { + return; + } + + e.setCancelled(true); + + Player p = e.getPlayer(); + + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + Block b = e.getPlayer().getTargetBlock((HashSet) null, 25).getLocation().getBlock(); + + if (b.getType() == Material.AIR) { + p.sendMessage("§cEscolha outro bloco para se teleportar."); + return; + } + BlockIterator list = new BlockIterator(p.getEyeLocation(), 0, 100); + while (list.hasNext()) { + p.getWorld().playEffect(list.next().getLocation(), Effect.ENDER_SIGNAL, 100); + } + p.teleport(b.getLocation().clone().add(0, 1.5, 0)); + p.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F); + addCooldown(p, getCooldownSeconds()); + } + } + + @Override + protected void clean(Player player) { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grandpa.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grandpa.java new file mode 100644 index 0000000..279469f --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grandpa.java @@ -0,0 +1,21 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class Grandpa extends Kit { + + public Grandpa() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.STICK).name( + getItemColor() + "Kit " + getName()).enchantment(Enchantment.KNOCKBACK, 3).build()); + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grappler.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grappler.java new file mode 100644 index 0000000..fdd37eb --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Grappler.java @@ -0,0 +1,238 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.HashMap; +import java.util.Map; + +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowball; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Firework; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.PlayerLeashEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; + +import net.minecraft.server.v1_8_R3.EntityFishingHook; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntitySnowball; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; + +public class Grappler extends Kit { + + public Grappler() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.LEASH).name(getItemColor() + "Kit " + getName()).build()); + } + + private final Map hooks = new HashMap<>(); + private final HashMap leftClickGrappler = new HashMap(); + private final HashMap rightClickGrappler = new HashMap(); + + @EventHandler + public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if (hooks.containsKey(event.getPlayer())) { + hooks.get(event.getPlayer()).remove(); + hooks.remove(event.getPlayer()); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) { + if (!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + if ((hooks.containsKey(event.getPlayer())) && (!event.getPlayer().getItemInHand().getType().equals(Material.LEASH))) { + hooks.get(event.getPlayer()).remove(); + hooks.remove(event.getPlayer()); + } + } + + @EventHandler + public void onLeash(PlayerLeashEntityEvent e) { + if (hasAbility(e.getPlayer())) { + e.setCancelled(true); + e.getPlayer().updateInventory(); + } + } + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + if(e.getAction() == Action.PHYSICAL) return; + + Player p = e.getPlayer(); + if ((p.getItemInHand().getType().equals(Material.LEASH)) && + (hasAbility(p))) { + + e.setCancelled(true); + if (hasCooldown(p, "CombatLog")) { + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 5), true); + p.sendMessage("§cVocê levou um hit recentemente, aguarde para usar a habilidade novamente."); + return; + } + + if ((e.getAction() == Action.LEFT_CLICK_AIR) || (e.getAction() == Action.LEFT_CLICK_BLOCK)) { + if (leftClickGrappler.containsKey(p) && leftClickGrappler.get(p) > System.currentTimeMillis()) + return; + + if (hooks.containsKey(p)) + hooks.get(p).remove(); + + Cordinha nmsHook = new Cordinha(p.getWorld(), ((CraftPlayer)p).getHandle()); + nmsHook.spawn(p.getEyeLocation().add(p.getLocation().getDirection().getX(), p.getLocation().getDirection().getY(), p.getLocation().getDirection().getZ())); + + nmsHook.move(p.getLocation().getDirection().getX() * 3.0D, + p.getLocation().getDirection().getY() * 3.0D, + p.getLocation().getDirection().getZ() * 3.0D); + + hooks.put(p, nmsHook); + leftClickGrappler.put(p, System.currentTimeMillis() + 250L); + } else { + if (!hooks.containsKey(p)) + return; + + if (rightClickGrappler.containsKey(p) && rightClickGrappler.get(p) > System.currentTimeMillis()) + return; + + if (!((Cordinha)hooks.get(p)).isHooked()) + return; + + //DamageListener.addBypassVelocity(p); + rightClickGrappler.put(p, System.currentTimeMillis() + 150L); + double d = hooks.get(p).getBukkitEntity().getLocation().distance(p.getLocation()); + double t = d; + double v_x = (1.0D + 0.07000000000000001D * t) * (hooks.get(p).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) / t; + double v_y = (1.0D + 0.03D * t) * (hooks.get(p).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) / t; + double v_z = (1.0D + 0.07000000000000001D * t) * (hooks.get(p).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) / t; + Vector v = p.getVelocity(); + v.setX(v_x); + v.setY(v_y); + v.setZ(v_z); + p.setVelocity(v); + p.playSound(p.getLocation(), Sound.STEP_GRAVEL, 10.0F, 10.0F); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getDamaged())) { + addCooldown(event.getDamaged(), "CombatLog", 3); + } + } + + public class Cordinha extends EntityFishingHook { + + private Snowball sb; + private EntitySnowball controller; + public EntityHuman owner; + public Entity hooked; + public boolean lastControllerDead, isHooked; + + public Cordinha(org.bukkit.World world, EntityHuman entityhuman) { + super(((CraftWorld)world).getHandle(), entityhuman); + this.owner = entityhuman; + } + + protected void c() {} + + public void t_() { + + if ((!this.lastControllerDead) && (this.controller.dead)) + ((Player)this.owner.getBukkitEntity()).sendMessage("§aSua corda prendeu em algo."); + + this.lastControllerDead = this.controller.dead; + for (Entity entity : this.controller.world.getWorld().getEntities()) { + if (!(entity instanceof LivingEntity)) { + continue; + } + if ((!(entity instanceof Firework)) && (entity.getEntityId() != getBukkitEntity().getEntityId()) && + (entity.getEntityId() != this.owner.getBukkitEntity().getEntityId()) && + (entity.getEntityId() != this.controller.getBukkitEntity().getEntityId()) && ( + (entity.getLocation().distance(this.controller.getBukkitEntity().getLocation()) < 2.0D) || (((entity instanceof Player)) && + (((Player)entity).getEyeLocation().distance(this.controller.getBukkitEntity().getLocation()) < 2.0D)))) { + this.controller.die(); + this.hooked = entity; + this.isHooked = true; + this.locX = entity.getLocation().getX(); + this.locY = entity.getLocation().getY(); + this.locZ = entity.getLocation().getZ(); + this.motX = 0.0D; + this.motY = 0.04D; + this.motZ = 0.0D; + } + } + try { + this.locX = this.hooked.getLocation().getX(); + this.locY = this.hooked.getLocation().getY(); + this.locZ = this.hooked.getLocation().getZ(); + this.motX = 0.0D; + this.motY = 0.04D; + this.motZ = 0.0D; + this.isHooked = true; + } catch (Exception e) { + if (this.controller.dead) + this.isHooked = true; + this.locX = this.controller.locX; + this.locY = this.controller.locY; + this.locZ = this.controller.locZ; + } + } + + public void die() {} + + public void remove() { + super.die(); + } + + public void spawn(Location location) { + this.sb = ((Snowball)this.owner.getBukkitEntity().launchProjectile(Snowball.class)); + this.sb.setVelocity(this.sb.getVelocity().multiply(2.25D)); + this.controller = ((CraftSnowball)this.sb).getHandle(); + + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { this.controller.getId() }); + + for (Player p : Bukkit.getOnlinePlayers()) + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); + + ((CraftWorld)location.getWorld()).getHandle().addEntity(this); + } + + public boolean isHooked() { + return this.isHooked; + } + + public void setHookedEntity(Entity damaged) { + this.hooked = damaged; + } + } + + @Override + protected void clean(Player player) { + if (hooks.containsKey(player)) { + hooks.get(player).remove(); + hooks.remove(player); + } + + leftClickGrappler.remove(player); + + rightClickGrappler.remove(player); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Hulk.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Hulk.java new file mode 100644 index 0000000..166c2b4 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Hulk.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; + +public class Hulk extends Kit { + + public Hulk() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent e) { + if (e.getPlayer() != null && e.getRightClicked() instanceof Player) { + Player p = e.getPlayer(); + + if ((p.getInventory().getItemInHand().getType().equals(Material.AIR)) || + (p.getInventory().getItemInHand().getType() == Material.STONE_SWORD)) { + + if (hasAbility(p)) { + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + addCooldown(p, getCooldownSeconds()); + + Player d = (Player) e.getRightClicked(); + p.setPassenger(d); + } + } + } + } + + @EventHandler + public void onDeath(EntityDeathEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + + if (p.isInsideVehicle()) p.leaveVehicle(); + } + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(PlayerDamagePlayerEvent event) { + Player damaged = event.getDamaged(), + damager = event.getPlayer(); + + if ((damaged.isInsideVehicle()) && (hasAbility(damager))) { + event.setCancelled(true); + + damaged.leaveVehicle(); + + PvPMain.runLater(() -> { + damaged.setVelocity(new Vector(damager.getLocation().getDirection().getX() + 0.3, 1.5, damager.getLocation().getDirection().getZ() + 0.3)); + }, 2); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Jumper.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Jumper.java new file mode 100644 index 0000000..5a2d70e --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Jumper.java @@ -0,0 +1,60 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.Material; +import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.metadata.FixedMetadataValue; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class Jumper extends Kit { + + public Jumper() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.EYE_OF_ENDER).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onJumperListener(PlayerInteractEvent event) { + if(event.getAction() == Action.PHYSICAL) return; + + Player p = event.getPlayer(); + + if (hasAbility(p)) { + if (checkItem(p.getItemInHand(), getItemColor() + "Kit " + getName())) { + event.setCancelled(true); + p.updateInventory(); + + if (!hasCooldown(p)) { + addCooldown(p, getCooldownSeconds()); + p.setFallDistance(0); + EnderPearl ender = p.launchProjectile(EnderPearl.class); + ender.setPassenger(p); + ender.setMetadata("Jumper", new FixedMetadataValue(PvPMain.getInstance(), p.getUniqueId())); + ender.setShooter(null); + } else { + sendMessageCooldown(p); + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onJumperHit(ProjectileHitEvent event) { + if (!event.getEntity().hasMetadata("Jumper")) + return; + if (event.getEntity().getPassenger() != null) { + event.getEntity().eject(); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Kangaroo.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Kangaroo.java new file mode 100644 index 0000000..682e7a9 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Kangaroo.java @@ -0,0 +1,116 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; + +public class Kangaroo extends Kit { + + private Set doubleJump; + + public Kangaroo() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.FIREWORK).name( + getItemColor() + "Kit " + getName()).build()); + + this.doubleJump = new HashSet<>(); + } + + public void eject(Player p) { + if (doubleJump.contains(p)) { + doubleJump.remove(p); + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void Habilidade(PlayerInteractEvent e) { + if ((!e.getAction().equals(Action.PHYSICAL)) && + (e.getPlayer().getItemInHand().getType().equals(Material.FIREWORK)) && + (hasAbility(e.getPlayer()))) { + + e.setCancelled(true); + Player p = e.getPlayer(); + + if (hasCooldown(p, "CombatLog")) { + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 5), true); + p.sendMessage("§cVocê levou um hit recentemente, aguarde para usar a habilidade novamente."); + return; + } + + //DamageListener.addBypassVelocity(p); + + if (!doubleJump.contains(p)) { + org.bukkit.util.Vector velocity = p.getEyeLocation().getDirection(); + if (p.isSneaking()) { + velocity = velocity.multiply(2.45F).setY(0.5F); + } else { + velocity = velocity.multiply(0.5F).setY(1.0F); + } + p.setFallDistance(-1.0F); + p.setVelocity(velocity); + doubleJump.add(p); + velocity = null; + + } + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void removeOnMove(PlayerMoveEvent e) { + //if (!e.isRealMovement()) return; + + if (!doubleJump.contains(e.getPlayer())) + return; + if (!e.getPlayer().isOnGround()) + return; + doubleJump.remove(e.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamageEvent(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + final Player player = (Player) event.getEntity(); + if (event.getCause() == EntityDamageEvent.DamageCause.FALL && hasAbility(player)) { + final double damage = event.getDamage(); + if (damage > 7.0D) { + event.setDamage(7.0D); + } else { + event.setCancelled(true); + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getDamaged())) { + addCooldown(event.getDamaged(), "CombatLog", 3); + } + } + + @Override + protected void clean(Player player) { + if (doubleJump.contains(player)) { + doubleJump.remove(player); + } + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Magma.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Magma.java new file mode 100644 index 0000000..c087dbb --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Magma.java @@ -0,0 +1,44 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; + +public class Magma extends Kit { + + public Magma() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerDamagePlayerEvent(PlayerDamagePlayerEvent event) { + if (Math.random() <= 0.35 && hasAbility(event.getPlayer()) + && !CombatLogListener.isProtected(event.getPlayer()) && !CombatLogListener.isProtected(event.getDamaged())) { + event.getDamaged().setFireTicks(100); + } + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if (event.isCancelled()) + return; + + if (event.getEntity() instanceof Player) { + if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.LAVA) { + if (hasAbility((Player) event.getEntity())) { + event.setCancelled(true); + event.getEntity().setFireTicks(0); + } + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Monk.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Monk.java new file mode 100644 index 0000000..cb83db6 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Monk.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class Monk extends Kit { + + public Monk() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.BLAZE_ROD).name( + getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler + public void onInteractEntity(PlayerInteractEntityEvent e) { + if (e.getRightClicked() instanceof Player) { + Player p = e.getPlayer(); + + if ((p.getItemInHand().getType().equals(Material.BLAZE_ROD)) && + (hasAbility(p))) { + + if (hasCooldown(p)) { + sendMessageCooldown(p); + return; + } + + Player d = (Player) e.getRightClicked(); + final ItemStack item = d.getItemInHand(); + final int r = new Random().nextInt(35); + final ItemStack i = d.getInventory().getItem(r); + d.getInventory().setItem(r, item); + d.setItemInHand(i); + addCooldown(p, getCooldownSeconds()); + p.sendMessage("§aMonkado!"); + d.sendMessage("§aVocê foi monkado!"); + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Neo.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Neo.java new file mode 100644 index 0000000..c2c608a --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Neo.java @@ -0,0 +1,35 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class Neo extends Kit { + + public Neo() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onProjectDamage(EntityDamageByEntityEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + Player p = (Player) event.getEntity(); + if (!hasAbility(p)) + return; + if (event.getDamager() instanceof Projectile) { + event.setCancelled(true); + Projectile projectile = (Projectile) event.getDamager(); + if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { + Player projectator = (Player) projectile.getShooter(); + projectator.sendMessage("§cO jogador está utilizando o kit Neo!"); + } + } + } + @Override + protected void clean(Player player) { + } + +} diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Ninja.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Ninja.java new file mode 100644 index 0000000..e054390 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Ninja.java @@ -0,0 +1,105 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerToggleSneakEvent; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.GamerDeathEvent; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; + +import lombok.Getter; + +public class Ninja extends Kit { + + private final Map ninja; + + public Ninja() { + initialize(getClass().getSimpleName()); + this.ninja = new HashMap<>(); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerDamagePlayerEvent(PlayerDamagePlayerEvent event) { + if (!CombatLogListener.isProtected(event.getPlayer()) && !CombatLogListener.isProtected(event.getDamaged()) && + hasAbility(event.getPlayer())) { + + NinjaHit ninjaHit = ninja.get(event.getPlayer()); + if (ninjaHit == null) { + ninjaHit = new NinjaHit(event.getDamaged()); + ninja.put(event.getPlayer(), ninjaHit); + } else { + ninjaHit.setTarget(event.getDamaged()); + } + } + } + + @EventHandler + public void onPlayerToggleSneakEvent(PlayerToggleSneakEvent event) { + final Player player = event.getPlayer(); + + if (event.isSneaking() && this.ninja.containsKey(player) && !CombatLogListener.isProtected(player) && hasAbility(player)) { + + NinjaHit hit = this.ninja.get(player); + if (hit == null) + return; + + if (hit.getTargetExpires() < System.currentTimeMillis()) + return; + + Player target = hit.getTarget(); + if (target.isOnline() && !CombatLogListener.isProtected(target)) { + if (player.getLocation().distance(target.getLocation()) > 40) { + player.sendMessage("§cJogador muito longe!"); + return; + } + + if (!hasCooldown(player)) { + player.teleport(target.getLocation()); + + addCooldown(player, getCooldownSeconds()); + + player.getWorld().playSound(player.getLocation().add(0.0, 0.5, 0.0), Sound + .ENDERMAN_TELEPORT, 0.3F, 1.0F); + } + } + } + } + + @EventHandler + public void onPlayerWarpDeathEvent(GamerDeathEvent event) { + clean(event.getPlayer()); + + if (event.hasKiller()) { + clean(event.getKiller()); + } + } + + protected void clean(Player player) { + this.ninja.remove(player); + } + + @Getter + private static class NinjaHit { + + private Player target; + private long targetExpires; + + public NinjaHit(Player target) { + this.target = target; + this.targetExpires = System.currentTimeMillis() + 15000; + } + + public void setTarget(Player player) { + this.target = player; + this.targetExpires = System.currentTimeMillis() + 15000; + } + + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/NoFall.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/NoFall.java new file mode 100644 index 0000000..f9d79c7 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/NoFall.java @@ -0,0 +1,28 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; + +public class NoFall extends Kit { + + public NoFall() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onEntityDamageEvent(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + final Player player = (Player) event.getEntity(); + if (event.getCause() == EntityDamageEvent.DamageCause.FALL && hasAbility(player)) { + event.setCancelled(true); + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Poseidon.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Poseidon.java new file mode 100644 index 0000000..8636a7b --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Poseidon.java @@ -0,0 +1,36 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import lombok.val; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Poseidon extends Kit { + + public Poseidon() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + //if (!event.isRealMovement()) return; + if (event.isCancelled()) return; + + val player = event.getPlayer(); + if(!hasAbility(player)) return; + + val blockType = event.getTo().getBlock().getType(); + if (blockType.equals(Material.WATER) || blockType.equals(Material.STATIONARY_WATER)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 0)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 0)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 0)); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/PvP.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/PvP.java new file mode 100644 index 0000000..8501178 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/PvP.java @@ -0,0 +1,13 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.entity.Player; + +public class PvP extends Kit { + + public PvP() { + initialize(getClass().getSimpleName()); + } + + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Scout.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Scout.java new file mode 100644 index 0000000..6fb4739 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Scout.java @@ -0,0 +1,48 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.HashSet; +import java.util.Set; + +public class Scout extends Kit { + + public Scout() { + initialize(getClass().getSimpleName()); + + setItens(new ItemBuilder().type(Material.getMaterial(373)).durability(34).name( + getItemColor() + "Kit " + getName()).build()); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.PHYSICAL) return; + Player player = event.getPlayer(); + if ((player.getItemInHand().getType().equals(Material.getMaterial(373))) && + (hasAbility(player))) { + + if (hasCooldown(player)) { + sendMessageCooldown(player); + return; + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 210, 2)); + player.sendMessage("§aVocê recebeu velocidade por um tempo valido de 30 segundos!"); + addCooldown(player, getCooldownSeconds()); + } + } + + @Override + protected void clean(Player player) { + + } +} diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Snail.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Snail.java new file mode 100644 index 0000000..00a8265 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Snail.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Snail extends Kit { + + public Snail() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void playerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getPlayer()) && Math.random() <= 0.33 && + !CombatLogListener.isProtected(event.getPlayer()) && !CombatLogListener.isProtected(event.getDamaged())) { + + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 120, 1)); + event.getDamaged().getLocation().getWorld().playEffect(event.getDamaged().getLocation() + .add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Stomper.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Stomper.java new file mode 100644 index 0000000..d74fb5b --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Stomper.java @@ -0,0 +1,60 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.manager.combatlog.CombatLogManager; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; +import lombok.val; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; + +public class Stomper extends Kit { + + public Stomper() { + initialize(getClass().getSimpleName()); + } + + @EventHandler + public void onFall(EntityDamageEvent event) { + if (event.isCancelled()) return; + + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + + if ((event.getCause() == EntityDamageEvent.DamageCause.FALL) && (hasAbility(p))) { + + if (event.getDamage() <= 4.0) { + return; + } + + p.getNearbyEntities(6.0D, 3.0D, 6.0D) + .stream() + .filter(entity -> (entity instanceof Player) && !GamerManager.getGamer(entity.getUniqueId()).containsKit("AntiTower") && !((Player) entity).isSneaking() && ((Player) entity).getGameMode() != GameMode.CREATIVE) + .forEach(entity -> { + val player = (Player) entity; + + player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 1.0F, 1.0F); + + CombatLogManager.removeCombatLog(player); + CombatLogManager.removeCombatLog(p); + + CombatLogManager.setCombatLog(player, p); + CombatLogManager.setCombatLog(p, player); + + // val health = Math.max(0, player.getHealth() - event.getFinalDamage()); + player.damage(event.getFinalDamage()); + // player.setHealth(health); + }); + + if (event.getDamage() > 4.0D) event.setDamage(4.0D); + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Switcher.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Switcher.java new file mode 100644 index 0000000..0c1e8e0 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Switcher.java @@ -0,0 +1,65 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import lombok.val; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.metadata.FixedMetadataValue; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Switcher extends Kit { + + public Switcher() { + initialize(getClass().getSimpleName()); + setItens(new ItemBuilder().type(Material.SNOW_BALL).name(getItemColor() + "Kit " + getName()).build()); + } + + @EventHandler + public void onProjectileLaunch(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (hasAbility(player) && checkItem(player.getItemInHand(), getItemColor() + "Kit " + getName())) { + event.setCancelled(true); + player.updateInventory(); + + if (hasCooldown(player)) + return; + + val ball = (Snowball) player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.SNOWBALL); + ball.setShooter(player); + ball.setMetadata("switch", new FixedMetadataValue(PvPMain.getInstance(), player)); + ball.setVelocity(player.getLocation().getDirection().multiply(1.5)); + + addCooldown(player, 5); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof Player && event.getDamager().hasMetadata("switch")) { + Player player = (Player) event.getDamager().getMetadata("switch").get(0).value(); + + if (player == null) + return; + + Location loc = event.getEntity().getLocation().clone(); + event.getEntity().teleport(player.getLocation().clone()); + player.teleport(loc); + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Thor.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Thor.java new file mode 100644 index 0000000..2e969f7 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Thor.java @@ -0,0 +1,57 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import java.util.HashSet; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LightningStrike; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; + +public class Thor extends Kit { + + public Thor() { + initialize(getClass().getSimpleName()); + setItens(new ItemBuilder().type(Material.WOOD_AXE).name( + getItemColor() + "Kit " + getName()).build()); + } + + @SuppressWarnings("deprecation") + @EventHandler + public void onInteract(PlayerInteractEvent e) { + if(e.getAction() == Action.PHYSICAL) return; + + if ((e.getPlayer().getItemInHand().getType().equals(Material.WOOD_AXE)) && (e.getAction().name().contains("RIGHT")) && + (hasAbility(e.getPlayer()))) { + + if (hasCooldown(e.getPlayer())) { + sendMessageCooldown(e.getPlayer()); + return; + } + + Location loc = e.getPlayer().getTargetBlock((HashSet) null, 25).getLocation(); + if (!loc.getBlock().getType().equals(Material.AIR)) { + addCooldown(e.getPlayer(), getCooldownSeconds()); + + LightningStrike strike = loc.getWorld().strikeLightning(loc); + + for (Entity nearby : strike.getNearbyEntities(4.0D, 4.0D, 4.0D)) { + if (nearby instanceof Player) { + nearby.setFireTicks(100); + } + } + + e.getPlayer().setFireTicks(0); + } + } + } + + @Override + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Viper.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Viper.java new file mode 100644 index 0000000..d30ed42 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/ability/register/Viper.java @@ -0,0 +1,31 @@ +package com.br.guilhermematthew.nowly.pvp.ability.register; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import org.bukkit.Effect; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Viper extends Kit { + + public Viper() { + initialize(getClass().getSimpleName()); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void playerDamage(PlayerDamagePlayerEvent event) { + if (hasAbility(event.getPlayer()) && Math.random() <= 0.33 && + !CombatLogListener.isProtected(event.getPlayer()) && !CombatLogListener.isProtected(event.getDamaged())) { + + event.getDamaged().addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0)); + event.getDamaged().getLocation().getWorld().playEffect(event.getDamaged().getLocation() + .add(0.0D, 0.4D, 0.0D), Effect.STEP_SOUND, 159, (short) 13); + } + } + + protected void clean(Player player) {} +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/commands/ServerCommand.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/commands/ServerCommand.java new file mode 100644 index 0000000..f772834 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/commands/ServerCommand.java @@ -0,0 +1,118 @@ +package com.br.guilhermematthew.nowly.pvp.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.commands.BukkitCommandSender; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.command.CommandClass; +import com.br.guilhermematthew.nowly.commons.common.command.CommandFramework.Command; +import com.br.guilhermematthew.nowly.commons.common.group.Groups; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.combatlog.CombatLogManager; +import com.br.guilhermematthew.nowly.pvp.mode.arena.ArenaMode; +import com.br.guilhermematthew.nowly.pvp.mode.fps.FPSMode; +import com.br.guilhermematthew.nowly.pvp.mode.lavachallenge.LavaChallengeMode; + +public class ServerCommand implements CommandClass { + + public static ArrayList autorizados = new ArrayList<>(); + + @Command(name = "spawn") + public void spawn(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (CombatLogManager.getCombatLog(player).isFighting()) { + player.sendMessage(StringUtils.VOCE_NAO_PODE_IR_PARA_O_SPAWN_EM_PVP); + return; + } + + Bukkit.getServer().getPluginManager().callEvent(new PlayerRequestEvent(player, "teleport-spawn")); + } + + @Command(name = "setloc", groupsToUse= {Groups.ADMIN}) + public void setloc(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + if (args.length == 0) { + commandSender.sendMessage("§cUse: /setloc spawn"); + return; + } + + Player player = commandSender.getPlayer(); + + if (args.length == 1) { + if (args[0].equalsIgnoreCase("spawn")) { + PluginConfiguration.setLocation(PvPMain.getInstance(), "spawn", player); + + switch (BukkitMain.getServerType()) { + case PVP_FPS: + FPSMode.setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + break; + case PVP_LAVACHALLENGE: + LavaChallengeMode.setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + break; + case PVP_ARENA: + ArenaMode.setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + break; + default: + break; + } + commandSender.sendMessage("§aSpawn setado!"); + } else { + commandSender.sendMessage("§cUse: /setloc spawn"); + } + } else { + commandSender.sendMessage("§cUse: /setloc spawn"); + } + } + + @Command(name = "build", aliases= {"b"}, groupsToUse= {Groups.ADMIN}) + public void build(BukkitCommandSender commandSender, String label, String[] args) { + if (!commandSender.isPlayer()) { + return; + } + + Player player = commandSender.getPlayer(); + + if (autorizados.contains(player.getUniqueId())) { + autorizados.remove(player.getUniqueId()); + player.sendMessage("§aVocê desativou o modo construçăo."); + } else { + autorizados.add(player.getUniqueId()); + player.sendMessage("§aVocê ativou o modo construçăo."); + } + } + + /* + @Command(name = "kit") + public void kit(BukkitCommandSender sender, String label, String[] args) { + if(!sender.isPlayer() || BukkitMain.getServerType() != ServerType.PVP_ARENA) return; + + val player = sender.getPlayer(); + if(args.length == 0) { + val kits = new ArrayList<>(KitManager.getKits().keySet()); + + val text = new TextComponent("Todos os Kits (" + kits.size() + "): "); + text.setColor(ChatColor.GREEN); + + for (int i = 0; i < kits.size(); i++) { + val kit = kits. + } + } + + }*/ + +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/GamerDeathEvent.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/GamerDeathEvent.java new file mode 100644 index 0000000..1682377 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/GamerDeathEvent.java @@ -0,0 +1,21 @@ +package com.br.guilhermematthew.nowly.pvp.events; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; + +@Getter +public class GamerDeathEvent extends PlayerEvent { + + private Player killer; + + public GamerDeathEvent(Player player, Player killer) { + super(player); + this.killer = killer; + } + + public boolean hasKiller() { + return killer != null; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/PlayerDamagePlayerEvent.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/PlayerDamagePlayerEvent.java new file mode 100644 index 0000000..d7865ad --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/events/PlayerDamagePlayerEvent.java @@ -0,0 +1,20 @@ +package com.br.guilhermematthew.nowly.pvp.events; + +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerCancellableEvent; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class PlayerDamagePlayerEvent extends PlayerCancellableEvent { + + private Player damaged; + private double damage; + + public PlayerDamagePlayerEvent(Player damager, Player damaged, double damage) { + super(damager); + this.damaged = damaged; + this.damage = damage; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/AccountListener.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/AccountListener.java new file mode 100644 index 0000000..0819325 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/AccountListener.java @@ -0,0 +1,69 @@ +package com.br.guilhermematthew.nowly.pvp.listeners; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.pvp.commands.ServerCommand; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.server.ServerStatusUpdateEvent; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +import java.sql.SQLException; + +public class AccountListener implements Listener { + + private final int MEMBERS_SLOTS = 80; + + @EventHandler + public void onPre(AsyncPlayerPreLoginEvent e) throws SQLException { + BukkitMain.getBukkitPlayer(e.getUniqueId()).getDataHandler().load(DataCategory.KITPVP); + } + + @EventHandler + public void onLogin(PlayerLoginEvent event) { + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) return; + + if (Bukkit.getOnlinePlayers().size() >= MEMBERS_SLOTS) { + if (!event.getPlayer().hasPermission("commons.entrar")) { + event.disallow(Result.KICK_OTHER, BukkitMessages.ACABOU_OS_SLOTS_PARA_MEMBROS); + } else { + event.allow(); + + Gamer randomGamer = GamerManager.getGamers().values().stream(). + filter(Gamer::isProtection). + filter(check -> !check.getPlayer().hasPermission("commons.entrar")).findAny().orElse(null); + + if (randomGamer != null) { + randomGamer.getPlayer().sendMessage(BukkitMessages.SEU_SLOT_FOI_DADO_A_UM_JOGADOR_VIP); + + BukkitServerAPI.redirectPlayer(randomGamer.getPlayer(), "LobbyPvP", true); + } + } + } + + if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) { + GamerManager.addGamer(event.getPlayer().getUniqueId()); + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + GamerManager.removeGamer(event.getPlayer().getUniqueId()); + + ServerCommand.autorizados.remove(event.getPlayer().getUniqueId()); + } + + @EventHandler + public void onUpdateServer(ServerStatusUpdateEvent event) { + event.writeMemberSlots(MEMBERS_SLOTS); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/CombatLogListener.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/CombatLogListener.java new file mode 100644 index 0000000..b7f7085 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/CombatLogListener.java @@ -0,0 +1,78 @@ +package com.br.guilhermematthew.nowly.pvp.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.br.guilhermematthew.nowly.pvp.events.GamerDeathEvent; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.manager.combatlog.CombatLogManager; +import com.br.guilhermematthew.nowly.pvp.manager.combatlog.CombatLogManager.CombatLog; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +public class CombatLogListener implements Listener { + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + if (GamerManager.getGamer(player).isProtection()) { + event.setCancelled(true); + } + player = null; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + if ((GamerManager.getGamer(event.getDamaged()).isProtection()) || (GamerManager.getGamer(event.getPlayer()).isProtection())) { + event.setCancelled(true); + } + } + + public static boolean isProtected(Player player) { + return GamerManager.getGamer(player.getUniqueId()).isProtection(); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public static void onPlayerDamageCombatLog(PlayerDamagePlayerEvent e) { + CombatLogManager.newCombatLog(e.getDamaged(), e.getPlayer()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onDeath(PlayerDeathEvent e) { + CombatLogManager.removeCombatLog(e.getEntity()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onQuit(PlayerQuitEvent event) { + checkCombatLog(event.getPlayer()); + } + + public static void checkCombatLog(Player player) { + CombatLog log = CombatLogManager.getCombatLog(player); + + if (log.isFighting()) { + + Player combatLogger = log.getCombatLogged(); + + if (combatLogger != null) { + if (combatLogger.isOnline()) { + CombatLogManager.removeCombatLog(combatLogger); + + Bukkit.getServer().getPluginManager().callEvent(new GamerDeathEvent(player, combatLogger)); + } + } + } + + log = null; + + CombatLogManager.removeCombatLog(player); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/GeneralListeners.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/GeneralListeners.java new file mode 100644 index 0000000..6d4f089 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/listeners/GeneralListeners.java @@ -0,0 +1,387 @@ +package com.br.guilhermematthew.nowly.pvp.listeners; + +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Sign; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.BukkitUpdateEvent.UpdateType; +import com.br.guilhermematthew.nowly.pvp.commands.ServerCommand; +import com.br.guilhermematthew.nowly.pvp.events.GamerDeathEvent; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.manager.combatlog.CombatLogManager; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +public class GeneralListeners implements Listener { + + private int MINUTES = 0; + + @EventHandler + public void onInit(PlayerJoinEvent event) { + event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation()); + } + + @EventHandler + public void onMinute(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.MINUTO) return; + + MINUTES++; + + if (MINUTES == 12) { + //HologramManager.updateHolograms(); + + MINUTES = 0; + } + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + event.getDrops().clear(); + + Player morreu = event.getEntity(), + matou = getKiller(morreu); + + morreu.playSound(morreu.getLocation(), Sound.ANVIL_LAND, 1, 1); + + if (matou != null) { + matou.playSound(matou.getLocation(), Sound.LEVEL_UP, 1, 1); + } + + Bukkit.getServer().getPluginManager().callEvent(new GamerDeathEvent(morreu, matou)); + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) { + ItemStack item = event.getItemDrop().getItemStack(); + + if (item.hasItemMeta()) { + event.setCancelled(true); + } else if (item.toString().contains("SWORD") || item.toString().equalsIgnoreCase("COMPASS") + || item.toString().contains("AXE")) { + event.setCancelled(true); + } + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onItemPickUp(PlayerPickupItemEvent event) { + if (VanishAPI.inAdmin(event.getPlayer())) { + event.setCancelled(true); + return; + } + + if (GamerManager.getGamer(event.getPlayer()).isProtection()) { + event.setCancelled(true); + return; + } + + final ItemStack item = event.getItem().getItemStack(); + + if (item.getItemMeta().hasDisplayName()) { + event.setCancelled(true); + return; + } + if (item.getType().toString().contains("SWORD") || item.getType().toString().contains("AXE")) { + event.setCancelled(true); + return; + } + if (item.getType().toString().contains("HELMET") || item.getType().toString().contains("CHESTPLATE") + || item.getType().toString().contains("LEGGING") || item.getType().toString().contains("BOOTS")) { + event.setCancelled(true); + } + } + + @EventHandler + public void onUpdate(BukkitUpdateEvent event) { + if (event.getType() != UpdateType.SEGUNDO) return; + + World world = Bukkit.getServer().getWorld("world"); + + if (world != null) { + for (Entity itens : world.getEntitiesByClass(Item.class)) { + if (!(itens instanceof Item)) { + continue; + } + + if (itens.getTicksLived() >= 200) { + itens.remove(); + } + } + } + } + + @EventHandler + public void onExplosion(ExplosionPrimeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onPlayerRegainHealth(EntityRegainHealthEvent event) { + if ((event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) + || (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.REGEN)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onLeavesDecay(LeavesDecayEvent event) { + event.setCancelled(true); + } + + + @EventHandler + public void onBlockBurn(BlockBurnEvent event) { + event.setCancelled(true); + } + + + @EventHandler + public void onBlockForm(BlockFormEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockFromTo(BlockFromToEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onBlockGrow(BlockGrowEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onProjectileHit(ProjectileHitEvent event) { + if (event.getEntity() instanceof Arrow) { + Arrow arrow = (Arrow) event.getEntity(); + arrow.remove(); + } + } + + + @EventHandler + public void onSpread(BlockSpreadEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onFood(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event) { + event.setCancelled(event.toWeatherState()); + } + + @EventHandler + public void onBlockIgnite(BlockIgniteEvent event) { + // event.setCancelled(true); + } + + @EventHandler + public void onEntitySpawn(CreatureSpawnEvent event) { + event.setCancelled(true); + } + + @EventHandler(ignoreCancelled = true) + public void onEntityDamage(EntityDamageByEntityEvent event) { + if (!(event.getEntity() instanceof Player)) return; + + Player damager = null; + + if (event.getDamager() instanceof Player) { + damager = (Player) event.getDamager(); + } else if (event.getDamager() instanceof Projectile) { + Projectile pr = (Projectile) event.getDamager(); + if (pr.getShooter() != null && pr.getShooter() instanceof Player) { + damager = (Player) pr.getShooter(); + } + } + + if (damager == null) return; + + if (event.isCancelled()) return; + + PlayerDamagePlayerEvent event2 = new PlayerDamagePlayerEvent(damager, (Player) event.getEntity(), + event.getDamage()); + + Bukkit.getPluginManager().callEvent(event2); + event.setCancelled(event2.isCancelled()); + event.setDamage(event2.getDamage()); + } + + @EventHandler + public void onPlayerInteractListener(PlayerInteractEvent event) { + if(event.getAction() == Action.PHYSICAL) return; + + if ((event.getPlayer().getGameMode() != GameMode.CREATIVE) + && (event.getAction() == Action.PHYSICAL && event.getClickedBlock() != null + && event.getClickedBlock().getType() != Material.STONE_PLATE + && event.getClickedBlock().getType() != Material.WOOD_PLATE) + + || (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null + && (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE + || event.getClickedBlock().getType() == Material.CHEST + || event.getClickedBlock().getType() == Material.ENDER_CHEST))) { + event.setCancelled(true); + } + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onBreak(BlockBreakEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } + + @EventHandler + public void onSignChange(SignChangeEvent e) { + if (e.getLine(0).equalsIgnoreCase("[sopa]")) { + e.setLine(0, ""); + e.setLine(1, "§2§lLEAGUE"); + e.setLine(2, "§fSopas"); + e.setLine(3, ""); + e.getPlayer().sendMessage("§aPlaca criada com sucesso."); + } else if (e.getLine(0).equalsIgnoreCase("[recraft]")) { + e.setLine(0, ""); + e.setLine(1, "§2§lLEAGUE"); + e.setLine(2, "§fRecraft"); + e.setLine(3, ""); + e.getPlayer().sendMessage("§aPlaca criada com sucesso."); + } else if (e.getLine(0).equalsIgnoreCase("[lavachallenge]")) { + boolean created = false; + + if (e.getLine(1).equalsIgnoreCase("[facil]")) { + e.setLine(2, "§aFácil"); + created = true; + } else if (e.getLine(1).equalsIgnoreCase("[medio]")) { + e.setLine(2, "§eMédio"); + created = true; + } else if (e.getLine(1).equalsIgnoreCase("[dificil]")) { + e.setLine(2, "§cDifícil"); + created = true; + } else if (e.getLine(1).equalsIgnoreCase("[extreme]")) { + e.setLine(2, "§4Extreme"); + created = true; + } else { + e.getPlayer().sendMessage("§cPlaca inválida."); + } + + if (created) { + e.setLine(0, ""); + e.setLine(1, "§6§lLAVACHALLENGE"); + e.getPlayer().sendMessage("§aPlaca criada com sucesso."); + e.setLine(3, ""); + } + } + } + + @EventHandler + public void onClickInSign(PlayerInteractEvent event) { + if(event.getAction() == Action.PHYSICAL) return; + + if ((event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getClickedBlock() != null) + && ((event.getClickedBlock().getType().equals(Material.WALL_SIGN)) + || (event.getClickedBlock().getType().equals(Material.SIGN_POST)))) { + + Sign sign = (Sign) event.getClickedBlock().getState(); + String[] lines = sign.getLines(); + + if (lines[2].contains("Recraft")) { + Inventory inv = event.getPlayer().getServer().createInventory(null, 9 * 3, "Recraft"); + + ItemBuilder itemBuilder = new ItemBuilder(); + ItemStack bowl = itemBuilder.type(Material.BOWL).amount(64).build(), + redMushroom = itemBuilder.type(Material.RED_MUSHROOM).amount(64).build(), + brownMushroom = itemBuilder.type(Material.BROWN_MUSHROOM).amount(64).build(); + + for (int slot = 0; slot < 27; slot++) { + + if (slot <= 8) { + inv.setItem(slot, bowl); + } else if (slot <= 17) { + inv.setItem(slot, redMushroom); + } else { + inv.setItem(slot, brownMushroom); + } + } + + event.getPlayer().openInventory(inv); + } else if (lines[2].contains("Sopa")) { + Inventory inv = event.getPlayer().getServer().createInventory(null, 9 * 4, "Sopas"); + for (ItemStack i : inv.getContents()) { + if (i == null) + inv.setItem(inv.firstEmpty(), new ItemStack(Material.MUSHROOM_SOUP)); + } + event.getPlayer().openInventory(inv); + } + } + } + + public Player getKiller(Player morreu) { + val log = CombatLogManager.getCombatLog(morreu); + + if(log.isFighting()) { + val killer = log.getCombatLogged(); + + CombatLogManager.removeCombatLog(morreu); + CombatLogManager.removeCombatLog(killer); + + if(killer.isOnline()) return killer; + } + + return morreu.getKiller(); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/combatlog/CombatLogManager.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/combatlog/CombatLogManager.java new file mode 100644 index 0000000..f772a61 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/combatlog/CombatLogManager.java @@ -0,0 +1,92 @@ +package com.br.guilhermematthew.nowly.pvp.manager.combatlog; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +import lombok.Data; +import lombok.RequiredArgsConstructor; + +public class CombatLogManager { + + private final static String COMBATLOG_PLAYER = "combatlog.player"; + private final static String COMBATLOG_EXPIRE = "combatlog.time"; + + private final static long COMBATLOG_TIME = 5000L; + + public static void newCombatLog(Player damager, Player damaged) { + setCombatLog(damager, damaged); + setCombatLog(damaged, damager); + } + + public static Player getLastHit(Player player) { + Player finded = null; + + CombatLog log = getCombatLog(player); + + if (log.isFighting()) { + Player combatLogger = log.getCombatLogged(); + + if (combatLogger != null) { + if (combatLogger.isOnline()) { + finded = combatLogger; + } + } + } + + return finded; + } + + public static void removeCombatLog(Player player) { + PvPMain plugin = PvPMain.getInstance(); + + if (player.hasMetadata(COMBATLOG_PLAYER)) { + player.removeMetadata(COMBATLOG_PLAYER, plugin); + } + + if (player.hasMetadata(COMBATLOG_EXPIRE)) { + player.removeMetadata(COMBATLOG_EXPIRE, plugin); + } + } + + public static void setCombatLog(Player player1, Player player2) { + PvPMain plugin = PvPMain.getInstance(); + + removeCombatLog(player1); + + player1.removeMetadata(COMBATLOG_PLAYER, plugin); + player1.removeMetadata(COMBATLOG_EXPIRE, plugin); + + player1.setMetadata(COMBATLOG_PLAYER, new FixedMetadataValue(plugin, player2.getName())); + player1.setMetadata(COMBATLOG_EXPIRE, new FixedMetadataValue(plugin, System.currentTimeMillis())); + } + + public static CombatLog getCombatLog(Player player) { + String playerName = ""; + + long time = 0L; + + if (player.hasMetadata(COMBATLOG_PLAYER)) { + playerName = player.getMetadata(COMBATLOG_PLAYER).get(0).asString(); + } + + if (player.hasMetadata(COMBATLOG_EXPIRE)) { + time = player.getMetadata(COMBATLOG_EXPIRE).get(0).asLong(); + } + + return new CombatLog(Bukkit.getPlayer(playerName), time); + } + + @Data + @RequiredArgsConstructor + public static class CombatLog { + + private final Player combatLogged; + private final long time; + + public boolean isFighting() { + return System.currentTimeMillis() < time + COMBATLOG_TIME; + } + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/Gamer.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/Gamer.java new file mode 100644 index 0000000..b5675b8 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/Gamer.java @@ -0,0 +1,66 @@ +package com.br.guilhermematthew.nowly.pvp.manager.gamer; + +import java.util.UUID; + +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Gamer { + + private UUID uniqueId; + private boolean protection; + private Player player; + private String kit1, kit2; + + public Gamer(UUID uniqueId) { + setUniqueId(uniqueId); + setProtection(true); + setKit1("Nenhum"); + setKit2("Nenhum"); + } + + public Player getPlayer() { + if (player == null) + player = Bukkit.getPlayer(getUniqueId()); + + return player; + } + + public void removeProtection(Player player, boolean message) { + if (!isProtection()) { + return; + } + + setProtection(false); + player.closeInventory(); + + if (message) { + player.sendMessage(StringUtils.PERDEU_A_PROTEÇĂO); + } + } + + public boolean containsKit(String name) { + return getKit1().equalsIgnoreCase(name) || getKit2().equalsIgnoreCase(name); + } + + public void joinArena() { + if (getKit1().equalsIgnoreCase("Nenhum")) { + setKit1("PvP"); + } + if (getKit2().equalsIgnoreCase("Nenhum")) { + setKit2("PvP"); + } + + removeProtection(getPlayer(), true); + } + + public String getKits() { + return getKit1() + " e " + getKit2(); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/GamerManager.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/GamerManager.java new file mode 100644 index 0000000..aa11146 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/gamer/GamerManager.java @@ -0,0 +1,30 @@ +package com.br.guilhermematthew.nowly.pvp.manager.gamer; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.entity.Player; + +import lombok.Getter; + +public class GamerManager { + + @Getter + private static HashMap gamers = new HashMap<>(); + + public static Gamer getGamer(UUID uniqueId) { + return gamers.get(uniqueId); + } + + public static Gamer getGamer(Player player) { + return gamers.get(player.getUniqueId()); + } + + public static void addGamer(UUID uniqueId) { + gamers.put(uniqueId, new Gamer(uniqueId)); + } + + public static void removeGamer(UUID uniqueId) { + gamers.remove(uniqueId); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitLoader.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitLoader.java new file mode 100644 index 0000000..05375d3 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitLoader.java @@ -0,0 +1,92 @@ +package com.br.guilhermematthew.nowly.pvp.manager.kit; + +import java.util.Arrays; + +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.Material; + +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.impl.BukkitConfiguration; +import com.br.guilhermematthew.nowly.commons.common.utility.ClassGetter; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; + +import lombok.Getter; + +public class KitLoader { + + @Getter + private static BukkitConfiguration kitsConfig = new BukkitConfiguration("kits", PvPMain.getInstance().getDataFolder(), false); + + @SuppressWarnings("deprecation") + public static void load() { + kitsConfig.load(); + + boolean saveConfig = false; + + for (Class classes : ClassGetter.getClassesForPackage(PvPMain + .getInstance(), "com.br.guilhermematthew.nowly.pvp.ability.register")) { + String className = classes.getSimpleName(); + + boolean add = false; + + try { + if (Kit.class.isAssignableFrom(classes) && (classes != Kit.class)) { + add = true; + + if (!kitsConfig.getConfiguration().contains("kits." + className + ".price")) { + kitsConfig.getConfiguration().set("kits." + className + ".price", 1000); + kitsConfig.getConfiguration().set("kits." + className + ".cooldown", 20); + kitsConfig.getConfiguration().set("kits." + className + ".icon.material", "CHEST"); + kitsConfig.getConfiguration().set("kits." + className + ".icon.durability", 0); + kitsConfig.getConfiguration().set("kits." + className + ".icon.amount", 1); + kitsConfig.getConfiguration().set("kits." + className + ".icon.description", + Arrays.asList("&7Edite a desc na", "&7Config")); + saveConfig = true; + } + } + } catch (Exception ex) { + add = false; + PvPMain.console("Ocorreu um erro ao tentar carregar um kit '"+className+"' > " + ex.getLocalizedMessage()); + } + + + if (add) { + Material material = null; + + try { + if (StringUtility.isInteger(kitsConfig.getConfiguration().getString("kits." + className + ".icon.material"))) { + material = Material.getMaterial(Integer.valueOf( + kitsConfig.getConfiguration().getString("kits." + className + ".icon.material"))); + } else { + material = Material.getMaterial(kitsConfig.getConfiguration().getString("kits." + className + ".icon.material")); + } + } catch (NullPointerException ex) { + PvPMain.console("Material do Kit '" + className + "' está incorreto."); + add = false; + } finally { + if (material == null) { + add = false; + } + } + + if (add) { + try { + KitManager.getKits().put(className.toLowerCase(), (Kit) classes.newInstance()); + } catch (Exception ex) { + PvPMain.console("Ocorreu um erro ao tentar adicionar um Kit. ->" + ex.getLocalizedMessage()); + } + } else { + PvPMain.console("não foi possivel adicionar o Kit -> " + className); + } + } + + } + + if (saveConfig) { + kitsConfig.save(); + } + + kitsConfig.unload(); + kitsConfig = null; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitManager.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitManager.java new file mode 100644 index 0000000..396171f --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/manager/kit/KitManager.java @@ -0,0 +1,95 @@ +package com.br.guilhermematthew.nowly.pvp.manager.kit; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class KitManager { + + @Getter + private static final HashMap kits = new HashMap<>(); + + public static void giveKitToPlayer(Player player, String kitName) { + Kit kit = getKitInfo(kitName); + + if (kit != null) { + kit.registerPlayer(); + + if (kit.getItens() != null) { + for (ItemStack item : kit.getItens()) { + player.getInventory().addItem(item); + } + } + } + } + + public List getAllKits() { + return new ArrayList<>(kits.values()); + } + + public static List getPlayerKits(Player player) { + List playerKits = new ArrayList<>(); + + for (Kit kit : kits.values()) { + if (player.hasPermission("pvp.kit." + kit.getName().toLowerCase()) || player.hasPermission("pvp.kit.all")) { + playerKits.add(kit); + } + } + + return playerKits; + } + + public static Kit getKitInfo(String nome) { + return kits.getOrDefault(nome.toLowerCase(), null); + } + + public static boolean hasPermissionKit(final Player player, String kit, boolean msg) { + if (kit.equalsIgnoreCase("PvP")) return true; + + if (player.hasPermission("pvp.kit.all")) return true; + + if (player.hasPermission("pvp.kit." + kit.toLowerCase())) return true; + + if (msg) player.sendMessage("§cVocê não possuí este Kit."); + return false; + } + + private final static String[] combinationsBlockeds = { + "kangaroo-nofall", "nofall-kangaroo", + "stomper-switcher", "switcher-stomper", + "stomper-hulk", "hulk-stomper", + "grappler-kangaroo", "kangaroo-grappler", + "ajnin-ninja", "ninja-ajnin"}; + + public static boolean isSameKit(String kit, String otherKit) { + return kit.equalsIgnoreCase(otherKit); + } + + public static boolean hasCombinationOp(String kit, String otherKit) { + boolean isOp = false; + + final String playerCombination1 = kit + "-" + otherKit, + playerCombination2 = otherKit + "-" + kit; + + for (String combinations : combinationsBlockeds) { + if (playerCombination1.equalsIgnoreCase(combinations)) { + isOp = true; + break; + } + if (playerCombination2.equalsIgnoreCase(combinations)) { + isOp = true; + break; + } + } + + return isOp; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/KitSelector.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/KitSelector.java new file mode 100644 index 0000000..15e4015 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/KitSelector.java @@ -0,0 +1,316 @@ +package com.br.guilhermematthew.nowly.pvp.menu; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.mode.arena.ArenaScoreboard; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.ClickType; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuClickHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuInventory; +import com.br.guilhermematthew.nowly.commons.bukkit.api.menu.MenuItem; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.utility.string.StringUtility; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketType; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketCustomAction; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.pvp.manager.kit.KitManager; +import com.br.guilhermematthew.nowly.pvp.menu.enums.InventoryMode; + +public class KitSelector extends MenuInventory { + + private static final int ITEMS_PER_PAGE = 21; + private static final int PREVIOUS_PAGE_SLOT = 45; + private static final int NEXT_PAGE_SLOT = 53; + private static final int CENTER = 31; + + private static final int KITS_PER_ROW = 7; + + public KitSelector(final Player player) { + this(player, 1, InventoryMode.KIT_PRIMARIO); + } + + public KitSelector(Player player, InventoryMode inventoryMode) { + this(player, 1, inventoryMode); + } + + public KitSelector(Player player, int page, InventoryMode inventoryMode) { + this(player, page, (3 / ITEMS_PER_PAGE) + 1, inventoryMode); + } + + public KitSelector(Player player1, int page, int maxPages, InventoryMode inventoryMode) { + super(inventoryMode.getInventoryName(), 6); + + Gamer gamer = GamerManager.getGamer(player1.getUniqueId()); + + List kitList = new ArrayList<>(KitManager.getKits().values()); + + kitList.sort(Comparator.comparing(Kit::getName)); + + List itens = new ArrayList<>(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + for (Kit kit : kitList) { + List lore = new ArrayList<>(); + + for (String line : kit.getDescription()) { + lore.add(line.replaceAll("&", "§")); + } + + if (inventoryMode == InventoryMode.LOJA) { + if (continuePlayer(player1, kit.getName(), inventoryMode)) { + lore.add(""); + lore.add("§fCusto: §6" + StringUtility.formatValue(kit.getPrice()) + " coins"); + lore.add(""); + lore.add("§eClique para comprar."); + + itens.add(new MenuItem( + itemBuilder.type(kit.getIcon().getType()).name("§a" + kit.getName()).lore(lore).build(), + new LojaKitsHandler(kit))); + } else { + lore.add(""); + lore.add("§cVocê já possuí este Kit."); + + itens.add(new MenuItem(itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), new LojaKitsHandler(kit))); + } + } else { + if (continuePlayer(player1, kit.getName(), inventoryMode)) { + boolean isOp = KitManager.hasCombinationOp( + inventoryMode == InventoryMode.KIT_PRIMARIO ? gamer.getKit2() : gamer.getKit1(), + kit.getName()); + + if (KitManager.isSameKit( + inventoryMode == InventoryMode.KIT_PRIMARIO ? gamer.getKit2() : gamer.getKit1(), + kit.getName())) { + lore.add(""); + lore.add("§cVocê ja escolheu este Kit."); + itens.add(new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } else { + + lore.add(""); + if (isOp) { + lore.add("§cEsta combinaçăo de Kit está bloqueada."); + itens.add(new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } else { + lore.add("§eClique para selecionar."); + itens.add( + new MenuItem( + itemBuilder.type(kit.getIcon().getType()).name("§a" + kit.getName()) + .lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } + } + } else { + lore.add(""); + lore.add("§cVocê não possui este Kit."); + itens.add( + new MenuItem( + itemBuilder.type(Material.STAINED_GLASS_PANE).durability(14) + .name("§c" + kit.getName()).lore(lore).build(), + new KitSelectHandler(kit.getName(), inventoryMode))); + } + } + + lore.clear(); + } + + int pageStart = 0; + int pageEnd = ITEMS_PER_PAGE; + + if (page > 1) { + pageStart = ((page - 1) * ITEMS_PER_PAGE); + pageEnd = (page * ITEMS_PER_PAGE); + } + + if (pageEnd > itens.size()) { + pageEnd = itens.size(); + } + + if (page == 1) { + setItem(PREVIOUS_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPágina Anterior").build(), + (player, arg1, arg2, arg3, arg4) -> new KitSelector(player, page - 1, inventoryMode).open(player)), + PREVIOUS_PAGE_SLOT); + } + + if ((itens.size() / ITEMS_PER_PAGE) + 1 <= page) { + setItem(NEXT_PAGE_SLOT, itemBuilder.type(Material.AIR).build()); + } else { + setItem(new MenuItem(itemBuilder.type(Material.ARROW).name("§aPróxima Página").build(), + (player, arg1, arg2, arg3, arg4) -> new KitSelector(player, page + 1, inventoryMode).open(player)), + NEXT_PAGE_SLOT); + } + + int kitSlot = 10; + + for (int i = pageStart; i < pageEnd; i++) { + setItem(itens.get(i), kitSlot); + + if (kitSlot % 9 == KITS_PER_ROW) { + kitSlot += 3; + continue; + } + + kitSlot += 1; + } + + if (itens.size() == 0) { + setItem(CENTER, + itemBuilder.type(Material.REDSTONE_BLOCK) + .name("§c" + (inventoryMode == InventoryMode.LOJA ? "Nenhum Kit para comprar!" + : "Nenhum kit para selecionar!")) + .build()); + } + + if (inventoryMode != InventoryMode.LOJA) { + Kit kitSelected = null; + + if (inventoryMode == InventoryMode.KIT_PRIMARIO) { + if (!gamer.getKit1().equalsIgnoreCase("Nenhum")) { + kitSelected = KitManager.getKitInfo(gamer.getKit1()); + } + } else { + if (!gamer.getKit2().equalsIgnoreCase("Nenhum")) { + kitSelected = KitManager.getKitInfo(gamer.getKit2()); + } + } + + setItem(49, + kitSelected == null + ? itemBuilder.type(Material.SLIME_BALL).name("§cNenhum Kit Selecionado").build() + : itemBuilder.type(kitSelected.getIcon().getType()) + .name("§aKit Atual: " + kitSelected.getName()).build()); + + } + + itens.clear(); + kitList.clear(); + } + + public static boolean continuePlayer(final Player player, final String kit, final InventoryMode modo) { + if(modo == InventoryMode.KIT_PRIMARIO) return true; + if(modo == InventoryMode.LOJA) return !KitManager.hasPermissionKit(player, kit, false); + + return KitManager.hasPermissionKit(player, kit, false); + } + + private static class LojaKitsHandler implements MenuClickHandler { + + private final Kit kit; + + public LojaKitsHandler(Kit kit) { + this.kit = kit; + } + + @Override + public void onClick(Player player, Inventory arg1, ClickType clickType, ItemStack arg3, int arg4) { + if (clickType != ClickType.LEFT) { + return; + } + + if(!continuePlayer(player, kit.getName(), InventoryMode.LOJA)) return; + + player.closeInventory(); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + if (bukkitPlayer.getInt(DataType.COINS) >= kit.getPrice()) { + bukkitPlayer.getDataHandler().getData(DataType.COINS).remove(kit.getPrice()); + + bukkitPlayer.sendPacket(new CPacketCustomAction(bukkitPlayer.getNick(), bukkitPlayer.getUniqueId()).type(PacketType.BUKKIT_SEND_INFO). + field("add-perm").fieldValue("pvp.kit." + kit.getName().toLowerCase())); + + player.sendMessage(StringUtils.VOCE_COMPROU_O_KIT.replace("%kit%", kit.getName())); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); + } else { + player.sendMessage(StringUtils.VOCE_NAO_TEM_COINS_O_SUFICIENTE_PARA_COMPRAR_O_KIT.replace("%valor%", + StringUtility.formatValue((kit.getPrice() - bukkitPlayer.getInt(DataType.COINS))))); + } + } + } + + private static class KitSelectHandler implements MenuClickHandler { + + private final String kit; + private final InventoryMode inventoryMode; + + public KitSelectHandler(String kit, InventoryMode inventoryMode) { + this.kit = kit; + this.inventoryMode = inventoryMode; + } + + @Override + public void onClick(Player player, Inventory arg1, ClickType clickType, ItemStack arg3, int arg4) { + if (clickType != ClickType.LEFT) { + return; + } + + player.closeInventory(); + + if (inventoryMode == InventoryMode.KIT_SECUNDARIO && !KitManager.hasPermissionKit(player, kit, true)) { + return; + } + + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + + if (inventoryMode == InventoryMode.KIT_PRIMARIO) { + if (!gamer.getKit1().equalsIgnoreCase(kit)) { + if (!KitManager.isSameKit(kit, gamer.getKit2())) { + if (!KitManager.hasCombinationOp(kit, gamer.getKit2())) { + gamer.setKit1(kit); + + ArenaScoreboard.updateScoreboard(player); + + player.sendMessage(StringUtils.VOCE_SELECIONOU_O_KIT_PRIMARIO.replace("%kit%", kit)); + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_ESTA_COMBINAÇĂO_DE_KIT); + } + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_O_MESMO_KIT); + } + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_O_MESMO_KIT); + } + } else { + if (!gamer.getKit2().equalsIgnoreCase(kit)) { + if (!KitManager.isSameKit(kit, gamer.getKit1())) { + if (!KitManager.hasCombinationOp(kit, gamer.getKit1())) { + gamer.setKit2(kit); + + ArenaScoreboard.updateScoreboard(player); + + player.sendMessage(StringUtils.VOCE_SELECIONOU_O_KIT_SECUNDARIO.replace("%kit%", kit)); + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_ESTA_COMBINAÇĂO_DE_KIT); + } + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_O_MESMO_KIT); + } + } else { + player.sendMessage(StringUtils.VOCE_NAO_PODE_USAR_O_MESMO_KIT); + } + } + } + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/enums/InventoryMode.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/enums/InventoryMode.java new file mode 100644 index 0000000..4d3531a --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/menu/enums/InventoryMode.java @@ -0,0 +1,17 @@ +package com.br.guilhermematthew.nowly.pvp.menu.enums; + +import lombok.Getter; + +public enum InventoryMode { + + KIT_PRIMARIO("Selecione o kit Primário"), + KIT_SECUNDARIO("Selecione o kit Secundario"), + LOJA("Loja de Kits"); + + @Getter + private String inventoryName; + + InventoryMode(String inventoryName) { + this.inventoryName = inventoryName; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaListeners.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaListeners.java new file mode 100644 index 0000000..b6b6526 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaListeners.java @@ -0,0 +1,275 @@ +package com.br.guilhermematthew.nowly.pvp.mode.arena; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.utility.LocationUtil; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.pvp.ability.Kit; +import com.br.guilhermematthew.nowly.pvp.events.GamerDeathEvent; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import com.br.guilhermematthew.nowly.pvp.utility.PvPUtility; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.bossbar.BossBarAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.pvp.manager.kit.KitManager; + +public class ArenaListeners implements Listener { + + private static final String NOFALL_TAG = "nofall", + NOFALL_TAG_TIME = "nofall.time"; + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + player.teleport(ArenaMode.getSpawn()); + + ArenaScoreboard.createScoreboard(player); + ArenaMode.refreshPlayer(player); + + if (BukkitMain.getServerType() == ServerType.PVP_ARENA) { + TitleAPI.sendTitle(player, "§f", "§b§lARENA", 0, 0, 2); + } + + player = null; + } + + @EventHandler + public void onWarpDeath(GamerDeathEvent event) { + Player died = event.getPlayer(); + + PvPUtility.dropItens(died, died.getLocation()); + + Gamer gamer = GamerManager.getGamer(died.getUniqueId()); + + Kit kit1 = KitManager.getKitInfo(gamer.getKit1()), kit2 = KitManager.getKitInfo(gamer.getKit2()); + + if (kit1 != null) { + kit1.unregisterPlayer(died); + + kit1 = null; + } + + if (kit2 != null) { + kit2.unregisterPlayer(died); + + kit2 = null; + } + + PvPUtility.handleStats(event.getKiller(), died); + + if (event.hasKiller()) { + ArenaScoreboard.updateScoreboard(event.getKiller()); + } + + died = null; + gamer = null; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerDamage(PlayerDamagePlayerEvent event) { + Player player = event.getPlayer(), damaged = event.getDamaged(); + + BossBarAPI.send(player, + damaged.getName() + " - " + GamerManager.getGamer(damaged.getUniqueId()).getKits(), 3); + + player = null; + damaged = null; + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + event.setRespawnLocation(ArenaMode.getSpawn()); + } + + @EventHandler + public void onAutoRespawn(PlayerRespawnEvent event) { + ArenaMode.refreshPlayer(event.getPlayer()); + } + + @EventHandler + public void onRequest(PlayerRequestEvent event) { + if (event.getRequestType().equalsIgnoreCase("update-scoreboard")) { + ArenaScoreboard.updateScoreboard(event.getPlayer()); + } else if (event.getRequestType().equalsIgnoreCase("teleport-spawn")) { + if (CombatLogListener.isProtected(event.getPlayer())) { + event.getPlayer().sendMessage(StringUtils.VOCE_JA_ESTA_NO_SPAWN); + return; + } + + ArenaMode.refreshPlayer(event.getPlayer()); + event.getPlayer().teleport(ArenaMode.getSpawn()); + event.getPlayer().sendMessage(StringUtils.VOCE_FOI_PARA_O_SPAWN); + } + } + + @EventHandler + public void onVoidDamage(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + + if (event.getCause() != EntityDamageEvent.DamageCause.VOID) + return; + + Player player = (Player) event.getEntity(); + + if (GamerManager.getGamer(player).isProtection()) { + player.teleport(ArenaMode.getSpawn()); + } else { + CombatLogListener.checkCombatLog(player); + + ArenaMode.refreshPlayer(player); + player.teleport(ArenaMode.getSpawn()); + } + + player = null; + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.getCause() != DamageCause.FALL) + return; + + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + + if (player.hasMetadata(NOFALL_TAG)) { + player.removeMetadata(NOFALL_TAG, PvPMain.getInstance()); + + if (!player.hasMetadata(NOFALL_TAG_TIME)) { + event.setCancelled(true); + return; + } + + Long time = player.getMetadata(NOFALL_TAG_TIME).get(0).asLong(); + if (time + 6000 > System.currentTimeMillis()) + event.setCancelled(true); + + player.removeMetadata(NOFALL_TAG_TIME, PvPMain.getInstance()); + } + + player = null; + } + + @EventHandler + public void onRealMove(PlayerMoveEvent event) { + if(!LocationUtil.isRealMovement(event.getFrom(), event.getTo())) return; + + if (event.isCancelled()) + return; + + Material material = event.getTo().getBlock().getRelative(BlockFace.DOWN).getType(); + + + Player player = event.getPlayer(); + + if (material.equals(Material.SPONGE)) { + double xvel = 0.0D; + double yvel = 3.7D; + double zvel = 0.0D; + + player.setVelocity(new Vector(xvel, yvel, zvel)); + + material = null; + } else if (material.equals(Material.SLIME_BLOCK)) { + player.setVelocity(player.getLocation().getDirection().multiply(1.3).setY(0.6)); + + material = null; + } + + if (material == null) { + + player.playSound(player.getLocation(), Sound.FIREWORK_LAUNCH, 6.0F, 1.0F); + + player.setMetadata(NOFALL_TAG, new FixedMetadataValue(PvPMain.getInstance(), true)); + + if (player.hasMetadata(NOFALL_TAG_TIME)) { + player.removeMetadata(NOFALL_TAG_TIME, PvPMain.getInstance()); + } + + player.setMetadata(NOFALL_TAG_TIME, + new FixedMetadataValue(PvPMain.getInstance(), System.currentTimeMillis())); + + player = null; + return; + } + + material = null; + + Gamer gamer = GamerManager.getGamer(player); + + if (gamer.isProtection()) { + if (player.getLocation().getBlockY() < 95) { + gamer.joinArena(); + + player.setMetadata(NOFALL_TAG, new FixedMetadataValue(PvPMain.getInstance(), true)); + player.setFallDistance(-100); + player.setNoDamageTicks(20); + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + playerInventory.clear(); + + playerInventory.setHeldItemSlot(0); + + if (gamer.containsKit("PvP")) { + playerInventory.setItem(0, itemBuilder.type(Material.STONE_SWORD).name("§7Espada de Pedra") + .unbreakable().enchantment(Enchantment.DAMAGE_ALL).build()); + } else { + playerInventory.setItem(0, + itemBuilder.type(Material.STONE_SWORD).name("§7Espada de Pedra").unbreakable().build()); + } + + KitManager.giveKitToPlayer(player, gamer.getKit1()); + KitManager.giveKitToPlayer(player, gamer.getKit2()); + + playerInventory.setItem(8, itemBuilder.type(Material.COMPASS).name("§aBússola").build()); + playerInventory.setItem(13, itemBuilder.type(Material.BOWL).amount(27).build()); + playerInventory.setItem(14, itemBuilder.type(Material.RED_MUSHROOM).amount(27).build()); + playerInventory.setItem(15, itemBuilder.type(Material.BROWN_MUSHROOM).amount(27).build()); + + ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); + + for (ItemStack is : playerInventory.getContents()) { + if (is == null) { + playerInventory.addItem(soup); + } + } + + player.updateInventory(); + playerInventory = null; + soup = null; + itemBuilder = null; + } + } + + player = null; + gamer = null; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaMode.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaMode.java new file mode 100644 index 0000000..f18eb89 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaMode.java @@ -0,0 +1,174 @@ +package com.br.guilhermematthew.nowly.pvp.mode.arena; + +import com.br.guilhermematthew.nowly.pvp.menu.KitSelector; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack.InteractHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.vanish.VanishAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; +import com.br.guilhermematthew.nowly.pvp.manager.kit.KitLoader; +import com.br.guilhermematthew.nowly.pvp.menu.enums.InventoryMode; + +import lombok.Getter; +import lombok.Setter; + +public class ArenaMode { + + @Getter @Setter + private static Location spawn; + + public static void init() { + PluginConfiguration.createLocation(PvPMain.getInstance(), "spawn"); + + setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + + KitLoader.load(); + + ActionItemStack.register("§cRetornar ao Lobby", lobbyAction); + ActionItemStack.register("§aSelecionar kit 1", kitPrimaryAction); + ActionItemStack.register("§aSelecionar kit 2", kitSecundaryAction); + ActionItemStack.register("§aLoja de Kits", kitShopAction); + ActionItemStack.register("§aBússola", compassAction); + + setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + + Bukkit.getServer().getPluginManager().registerEvents(new ArenaListeners(), PvPMain.getInstance()); + } + + public static void refreshPlayer(Player player) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + gamer.setProtection(true); + + if (player.getPassenger() != null) { + player.getPassenger().leaveVehicle(); + } + + if (player.isInsideVehicle()) { + player.leaveVehicle(); + } + + player.setNoDamageTicks(20); + player.setFallDistance(-5); + + player.getInventory().clear(); + player.getInventory().setArmorContents(null); + player.updateInventory(); + + player.setFireTicks(0); + player.setLevel(0); + player.setExp((float)0); + player.setHealth(20.0D); + + PlayerAPI.clearEffects(player); + + if (player.getGameMode() != GameMode.SURVIVAL) { + player.setGameMode(GameMode.SURVIVAL); + } + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.setHeldItemSlot(0); + + playerInventory.setItem(0, itemBuilder.type(Material.CHEST).name("§aSelecionar kit 1").build()); + playerInventory.setItem(1, itemBuilder.type(Material.CHEST).amount(2).name("§aSelecionar kit 2").build()); + playerInventory.setItem(2, itemBuilder.type(Material.EMERALD).name("§aLoja de Kits").build()); + + playerInventory.setItem(8, itemBuilder.type(Material.BED).name("§cRetornar ao Lobby").build()); + + player.updateInventory(); + + ArenaScoreboard.updateScoreboard(player); + playerInventory = null; + itemBuilder = null; + gamer = null; + player = null; + } + + private final static InteractHandler lobbyAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction.name().contains("LEFT")) return true; + + BukkitServerAPI.redirectPlayer(player, "LobbyPvP"); + return true; + }; + + private final static InteractHandler kitPrimaryAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction.name().contains("LEFT")) return true; + + new KitSelector(player, InventoryMode.KIT_PRIMARIO).open(player); + return true; + }; + + private final static InteractHandler kitSecundaryAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction.name().contains("LEFT")) return true; + + new KitSelector(player, InventoryMode.KIT_SECUNDARIO).open(player); + return true; + }; + + private final static InteractHandler kitShopAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction.name().contains("LEFT")) return true; + + new KitSelector(player, InventoryMode.LOJA).open(player); + return true; + }; + + private final static InteractHandler compassAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction == Action.PHYSICAL) return true; + + final Player alvo = getRandomPlayer(player); + + if (alvo == null) { + player.sendMessage(StringUtils.BUSSOLA_NOT_FINDED); + player.setCompassTarget(player.getWorld().getSpawnLocation()); + } else { + player.sendMessage(StringUtils.BUSSOLA_FINDED.replace("%nick%", alvo.getName())); + player.setCompassTarget(alvo.getLocation()); + } + return true; + }; + + private static Player getRandomPlayer(final Player player) { + Player target = null; + + for (Player inWarp : Bukkit.getOnlinePlayers()) { + if (inWarp == player) { + continue; + } + if (VanishAPI.isInvisible(inWarp)) { + continue; + } + + if (inWarp.getLocation().distance(player.getLocation()) >= 15.0D) { + if (target == null) { + target = inWarp; + } else { + double distanciaAtual = target.getLocation().distance(player.getLocation()); + double novaDistancia = inWarp.getLocation().distance(player.getLocation()); + if (novaDistancia < distanciaAtual) { + target = inWarp; + if (novaDistancia <= 30) { + break; + } + } + } + } + } + return target; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaScoreboard.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaScoreboard.java new file mode 100644 index 0000000..9eca790 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/arena/ArenaScoreboard.java @@ -0,0 +1,46 @@ +package com.br.guilhermematthew.nowly.pvp.mode.arena; + +import lombok.val; +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +public class ArenaScoreboard { + + public static void createScoreboard(Player player) { + val sidebar = SidebarManager.getSidebar(player.getUniqueId()); + sidebar.setTitle("§b§lARENA: PVP"); + + val bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + sidebar.addBlankLine(); + sidebar.addLine("kills", "Kills: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLS)); + sidebar.addLine("deaths", "Deaths: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_DEATHS)); + sidebar.addLine("killstreak", "Killstreak: ", "§a" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLSTREAK)); + sidebar.addBlankLine(); + + sidebar.addLine("kit1", "Kit 1: ", "§aNenhum"); + sidebar.addLine("kit2", "Kit 2: ", "§aNenhum"); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + public static void updateScoreboard(Player player) { + val sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + val bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + val gamer = GamerManager.getGamer(player.getUniqueId()); + + sidebar.updateLine("killstreak", "Killstreak: ", "§a" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLSTREAK)); + sidebar.updateLine("kills", "Kills: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLS)); + sidebar.updateLine("deaths", "Deaths: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_DEATHS)); + + sidebar.updateLine("kit1", "Kit 1: ", "§a" + gamer.getKit1()); + sidebar.updateLine("kit2", "Kit 2: ", "§a" + gamer.getKit2()); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSListeners.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSListeners.java new file mode 100644 index 0000000..b8f83e4 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSListeners.java @@ -0,0 +1,192 @@ +package com.br.guilhermematthew.nowly.pvp.mode.fps; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.commands.ServerCommand; +import com.br.guilhermematthew.nowly.pvp.events.GamerDeathEvent; +import com.br.guilhermematthew.nowly.pvp.listeners.CombatLogListener; +import com.br.guilhermematthew.nowly.pvp.utility.PvPUtility; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +public class FPSListeners implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + player.teleport(FPSMode.getSpawn()); + + FPSScoreboard.createScoreboard(player); + FPSMode.refreshPlayer(player); + + if (BukkitMain.getServerType() == ServerType.PVP_FPS) { + TitleAPI.sendTitle(player, "§f", "§b§lFPS", 0, 0, 3); + } + + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + event.setRespawnLocation(FPSMode.getSpawn()); + } + + @EventHandler + public void onAutoRespawn(PlayerRespawnEvent event) { + FPSMode.refreshPlayer(event.getPlayer()); + } + + @EventHandler + public void onRequest(PlayerRequestEvent event) { + if (event.getRequestType().equalsIgnoreCase("update-scoreboard")) { + FPSScoreboard.updateScoreboard(event.getPlayer()); + } else if (event.getRequestType().equalsIgnoreCase("teleport-spawn")) { + if (CombatLogListener.isProtected(event.getPlayer())) { + event.getPlayer().sendMessage(StringUtils.VOCE_JA_ESTA_NO_SPAWN); + return; + } + + FPSMode.refreshPlayer(event.getPlayer()); + event.getPlayer().teleport(FPSMode.getSpawn()); + event.getPlayer().sendMessage(StringUtils.VOCE_FOI_PARA_O_SPAWN); + } + } + + @EventHandler + public void onWarpDeath(GamerDeathEvent event) { + PvPUtility.dropItens(event.getPlayer(), event.getPlayer().getLocation()); + + PvPUtility.handleStats(event.getKiller(), event.getPlayer()); + + FPSScoreboard.updateScoreboard(event.getKiller()); + + if (event.hasKiller()) { + PvPUtility.repairArmor(event.getKiller()); + } + } + + @EventHandler( + priority = EventPriority.LOW + ) + public void onSpawnMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + Gamer gamer = GamerManager.getGamer(player); + + if(gamer.isProtection() && player.getLocation().distance(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")) > 8.5D) { + gamer.setProtection(false); + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + playerInventory.clear(); + + playerInventory.setHeldItemSlot(0); + + playerInventory.setHelmet(new ItemStack(Material.IRON_HELMET)); + playerInventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); + playerInventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS)); + playerInventory.setBoots(new ItemStack(Material.IRON_BOOTS)); + + playerInventory.setItem(0, itemBuilder.type(Material.DIAMOND_SWORD).name("§7Espada de Diamante") + .unbreakable().enchantment(Enchantment.DAMAGE_ALL).build()); + + playerInventory.setItem(13, itemBuilder.type(Material.BOWL).amount(64).build()); + playerInventory.setItem(14, itemBuilder.type(Material.RED_MUSHROOM).amount(64).build()); + playerInventory.setItem(15, itemBuilder.type(Material.BROWN_MUSHROOM).amount(64).build()); + + ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); + + for (ItemStack is : playerInventory.getContents()) { + if (is == null) { + playerInventory.addItem(soup); + } + } + + player.updateInventory(); + } + + } + /*@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntytyDamageEvent(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { + Gamer gamer = GamerManager.getGamer(player); + + + if (gamer.isProtection()) { + event.setCancelled(true); + + player.setFallDistance(5); + player.setNoDamageTicks(20); + gamer.setProtection(false); + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + playerInventory.clear(); + + playerInventory.setHeldItemSlot(0); + + playerInventory.setHelmet(new ItemStack(Material.IRON_HELMET)); + playerInventory.setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); + playerInventory.setLeggings(new ItemStack(Material.IRON_LEGGINGS)); + playerInventory.setBoots(new ItemStack(Material.IRON_BOOTS)); + + playerInventory.setItem(0, itemBuilder.type(Material.DIAMOND_SWORD).name("§7Espada de Diamante") + .unbreakable().enchantment(Enchantment.DAMAGE_ALL).build()); + + playerInventory.setItem(13, itemBuilder.type(Material.BOWL).amount(64).build()); + playerInventory.setItem(14, itemBuilder.type(Material.RED_MUSHROOM).amount(64).build()); + playerInventory.setItem(15, itemBuilder.type(Material.BROWN_MUSHROOM).amount(64).build()); + + ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); + + for (ItemStack is : playerInventory.getContents()) { + if (is == null) { + playerInventory.addItem(soup); + } + } + + player.updateInventory(); + } + } else if (event.getCause() == EntityDamageEvent.DamageCause.VOID) { + event.setCancelled(true); + + if (!GamerManager.getGamer(player).isProtection()) CombatLogListener.checkCombatLog(player); + FPSMode.refreshPlayer(player); + player.teleport(FPSMode.getSpawn()); + } + }*/ + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + event.setCancelled((!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) || + (!ServerCommand.autorizados.contains(event.getPlayer().getUniqueId()))); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSMode.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSMode.java new file mode 100644 index 0000000..0edb7db --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSMode.java @@ -0,0 +1,91 @@ +package com.br.guilhermematthew.nowly.pvp.mode.fps; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ActionItemStack.InteractHandler; +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.Gamer; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +import lombok.Getter; +import lombok.Setter; + +public class FPSMode { + + @Getter @Setter + private static Location spawn; + + public static void init() { + PluginConfiguration.createLocation(PvPMain.getInstance(), "spawn"); + + ActionItemStack.register("§cRetornar ao Lobby", lobbyAction); + + setSpawn(PluginConfiguration.getLocation(PvPMain.getInstance(), "spawn")); + + Bukkit.getServer().getPluginManager().registerEvents(new FPSListeners(), PvPMain.getInstance()); + } + + public static void refreshPlayer(Player player) { + Gamer gamer = GamerManager.getGamer(player.getUniqueId()); + gamer.setProtection(true); + + if (player.getPassenger() != null) { + player.getPassenger().leaveVehicle(); + } + + if (player.isInsideVehicle()) { + player.leaveVehicle(); + } + + player.setFallDistance(-10); + player.setNoDamageTicks(20); + + player.getInventory().clear(); + player.getInventory().setArmorContents(null); + player.updateInventory(); + + player.setFireTicks(0); + player.setLevel(0); + player.setExp((float)0); + player.setHealth(20.0D); + + PlayerAPI.clearEffects(player); + + if (player.getGameMode() != GameMode.SURVIVAL) { + player.setGameMode(GameMode.SURVIVAL); + } + + ItemBuilder itemBuilder = new ItemBuilder(); + + PlayerInventory playerInventory = player.getInventory(); + + playerInventory.setHeldItemSlot(0); + + playerInventory.setItem(8, itemBuilder.type(Material.BED).name("§cRetornar ao Lobby").build()); + + player.updateInventory(); + + FPSScoreboard.updateScoreboard(player); + playerInventory = null; + itemBuilder = null; + gamer = null; + player = null; + } + + private final static InteractHandler lobbyAction = (player, itemStack, itemAction, clickedBlock) -> { + if (itemAction.name().contains("LEFT")) return true; + + BukkitServerAPI.redirectPlayer(player, "LobbyPvP"); + return true; + }; +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSScoreboard.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSScoreboard.java new file mode 100644 index 0000000..b6a0419 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/fps/FPSScoreboard.java @@ -0,0 +1,51 @@ +package com.br.guilhermematthew.nowly.pvp.mode.fps; + +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; + +public class FPSScoreboard { + + public static void createScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + sidebar.setTitle("§b§lARENA: FPS"); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + League league = League.getRanking(bukkitPlayer.getInt(DataType.XP)); + + sidebar.addBlankLine(); + sidebar.addLine("kills", "Kills: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLS)); + sidebar.addLine("deaths", "Deaths: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_DEATHS)); + sidebar.addLine("killstreak", "Killstreak: ", "§a" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLSTREAK)); + sidebar.addBlankLine(); + sidebar.addLine("coins", "Coins: ", "§6" + bukkitPlayer.getIntFormatted(DataType.COINS)); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + + bukkitPlayer = null; + league = null; + sidebar = null; + } + + public static void updateScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + League league = League.getRanking(bukkitPlayer.getInt(DataType.XP)); + + sidebar.updateLine("killstreak", "Killstreak: ", "§a" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLSTREAK)); + sidebar.updateLine("kills", "Kills: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_KILLS)); + sidebar.updateLine("deaths", "Deaths: ", "§7" + bukkitPlayer.getIntFormatted(DataType.PVP_DEATHS)); + sidebar.updateLine("coins", "Coins: ", "§6" + bukkitPlayer.getIntFormatted(DataType.COINS)); + + bukkitPlayer = null; + sidebar = null; + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeListeners.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeListeners.java new file mode 100644 index 0000000..836c412 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeListeners.java @@ -0,0 +1,193 @@ +package com.br.guilhermematthew.nowly.pvp.mode.lavachallenge; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.title.TitleAPI; +import com.br.guilhermematthew.nowly.commons.common.serverinfo.ServerType; +import com.br.guilhermematthew.nowly.pvp.events.PlayerDamagePlayerEvent; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerVelocityEvent; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.custom.events.player.PlayerRequestEvent; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.StringUtils; +import com.br.guilhermematthew.nowly.pvp.manager.gamer.GamerManager; + +public class LavaChallengeListeners implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + player.teleport(LavaChallengeMode.getSpawn()); + + GamerManager.getGamer(player.getUniqueId()).setProtection(false); + + LavaChallengeScoreboard.createScoreboard(player); + LavaChallengeMode.refreshPlayer(player); + + if (BukkitMain.getServerType() == ServerType.PVP_LAVACHALLENGE) { + TitleAPI.sendTitle(player, "§f", "§b§lLAVA", 0, 0, 3); + } + + player = null; + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) { + LavaChallengeMode.cleanPlayer(event.getPlayer()); + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + event.setRespawnLocation(LavaChallengeMode.getSpawn()); + } + + @EventHandler + public void onAutoRespawn(PlayerRespawnEvent event) { + LavaChallengeMode.refreshPlayer(event.getPlayer()); + } + + @EventHandler + public void onRequest(PlayerRequestEvent event) { + if (event.getRequestType().equalsIgnoreCase("update-scoreboard")) { + LavaChallengeScoreboard.updateScoreboard(event.getPlayer()); + } else if (event.getRequestType().equalsIgnoreCase("teleport-spawn")) { + LavaChallengeMode.refreshPlayer(event.getPlayer()); + event.getPlayer().teleport(LavaChallengeMode.getSpawn()); + event.getPlayer().sendMessage(StringUtils.VOCE_FOI_PARA_O_SPAWN); + } + } + + @EventHandler + public void onDamage(PlayerDamagePlayerEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onVelocity(PlayerVelocityEvent event) { + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDamage(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) return; + + if (event.getCause() != DamageCause.LAVA) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void addDamage(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + + Player player = (Player) event.getEntity(); + + if (event.getCause() != DamageCause.LAVA) { + return; + } + + if (!event.isCancelled()) { + addLavaDamage(player); + } + } + + private void addLavaDamage(Player player) { + int amount = LavaChallengeMode.lavaDamages.getOrDefault(player.getUniqueId(), 0); + + LavaChallengeMode.lavaDamages.put(player.getUniqueId(), amount + 1); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) { + if ((event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getClickedBlock() != null) + && ((event.getClickedBlock().getType().equals(Material.WALL_SIGN)) + || (event.getClickedBlock().getType().equals(Material.SIGN_POST)))) { + + Sign sign = (Sign) event.getClickedBlock().getState(); + String[] lines = sign.getLines(); + + Player player = event.getPlayer(); + + int lavaDmg = LavaChallengeMode.lavaDamages.get(player.getUniqueId()); + + if (lines[1].contains("LAVACHALLENGE")) { + LavaChallengeMode.LavaDifficulty difficulty = LavaChallengeMode.LavaDifficulty.FACIL; + + if (lines[2].contains("Médio")) { + difficulty = LavaChallengeMode.LavaDifficulty.MEDIO; + } else if (lines[2].contains("Difícil")) { + difficulty = LavaChallengeMode.LavaDifficulty.DIFICIL; + } else if (lines[2].contains("Extreme")) { + difficulty = LavaChallengeMode.LavaDifficulty.EXTREMO; + } + + if (lavaDmg < difficulty.getMinHits()) { + Bukkit.broadcastMessage("o desgraçado do " + player.getName() + " completou o lava muito rapido!"); + } else { + handleCompleteLava(player, difficulty); + } + + player.teleport(LavaChallengeMode.getSpawn()); + LavaChallengeMode.refreshPlayer(player); + } + } + } + + public void handleCompleteLava(Player player, LavaChallengeMode.LavaDifficulty difficulty) { + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + + switch (difficulty) { + case FACIL: + bukkitPlayer.getDataHandler().getData(DataType.PVP_LAVACHALLENGE_FACIL).add(); + bukkitPlayer.getDataHandler().getData(DataType.COINS).add(200); + bukkitPlayer.addXP(50); + + player.sendMessage(StringUtils.VOCE_COMPLETOU_LAVA_CHALLENGE.replace("%dificuldade%", "Fácil")); + + break; + case MEDIO: + bukkitPlayer.getDataHandler().getData(DataType.PVP_LAVACHALLENGE_MEDIO).add(); + bukkitPlayer.getDataHandler().getData(DataType.COINS).add(300); + bukkitPlayer.addXP(150); + + player.sendMessage(StringUtils.VOCE_COMPLETOU_LAVA_CHALLENGE.replace("%dificuldade%", "Médio")); + break; + case DIFICIL: + bukkitPlayer.getDataHandler().getData(DataType.PVP_LAVACHALLENGE_DIFICIL).add(); + bukkitPlayer.getDataHandler().getData(DataType.COINS).add(400); + bukkitPlayer.addXP(250); + + player.sendMessage(StringUtils.VOCE_COMPLETOU_LAVA_CHALLENGE.replace("%dificuldade%", "Dificil")); + break; + case EXTREMO: + bukkitPlayer.getDataHandler().getData(DataType.PVP_LAVACHALLENGE_EXTREMO).add(); + bukkitPlayer.getDataHandler().getData(DataType.COINS).add(500); + bukkitPlayer.addXP(300); + + player.sendMessage(StringUtils.VOCE_COMPLETOU_LAVA_CHALLENGE.replace("%dificuldade%", "Extremo")); + break; + default: + break; + } + + PvPMain.runAsync(() -> bukkitPlayer.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.KITPVP)); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeMode.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeMode.java new file mode 100644 index 0000000..c779c59 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeMode.java @@ -0,0 +1,113 @@ +package com.br.guilhermematthew.nowly.pvp.mode.lavachallenge; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import com.br.guilhermematthew.nowly.commons.bukkit.api.item.ItemBuilder; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.bukkit.manager.configuration.PluginConfiguration; +import com.br.guilhermematthew.nowly.pvp.PvPMain; + +import lombok.Getter; +import lombok.Setter; + +public class LavaChallengeMode { + + @Getter @Setter + private static Location spawn; + + public static HashMap lavaDamages; + + public static void init() { + lavaDamages = new HashMap<>(); + + setSpawn(PluginConfiguration.createLocation(PvPMain.getInstance(), "spawn")); + + Bukkit.getServer().getPluginManager().registerEvents(new LavaChallengeListeners(), PvPMain.getInstance()); + } + + public static void refreshPlayer(Player player) { + if (player.getPassenger() != null) { + player.getPassenger().leaveVehicle(); + } + + if (player.isInsideVehicle()) { + player.leaveVehicle(); + } + + player.setNoDamageTicks(20); + player.setFallDistance(-5); + + player.getInventory().clear(); + player.getInventory().setArmorContents(null); + player.updateInventory(); + + player.setFireTicks(0); + player.setLevel(0); + player.setExp((float)0); + player.setHealth(20.0D); + + PlayerAPI.clearEffects(player); + + if (player.getGameMode() != GameMode.SURVIVAL) { + player.setGameMode(GameMode.SURVIVAL); + } + + PlayerInventory playerInventory = player.getInventory(); + + ItemBuilder itemBuilder = new ItemBuilder(); + + playerInventory.setItem(13, itemBuilder.type(Material.BOWL).amount(64).build()); + playerInventory.setItem(14, itemBuilder.type(Material.RED_MUSHROOM).amount(64).build()); + playerInventory.setItem(15, itemBuilder.type(Material.BROWN_MUSHROOM).amount(64).build()); + + ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); + + for (ItemStack is : playerInventory.getContents()) { + if (is == null) { + playerInventory.addItem(soup); + } + } + + player.updateInventory(); + + lavaDamages.put(player.getUniqueId(), 0); + + LavaChallengeScoreboard.updateScoreboard(player); + } + + public static void updateDifficulty(int minDamageFacil, int minDamageMedio, int minDamageDificil, int minDamageExtremo) { + LavaDifficulty.FACIL.setMinHits(minDamageFacil); + LavaDifficulty.MEDIO.setMinHits(minDamageMedio); + LavaDifficulty.DIFICIL.setMinHits(minDamageDificil); + LavaDifficulty.EXTREMO.setMinHits(minDamageExtremo); + } + + public enum LavaDifficulty { + FACIL(20), + MEDIO(20), + DIFICIL(20), + EXTREMO(20); + + @Getter @Setter + int minHits; + + LavaDifficulty(int minHits) { + this.minHits = minHits; + } + } + + public static void cleanPlayer(Player player) { + if (lavaDamages.containsKey(player.getUniqueId())) { + lavaDamages.remove(player.getUniqueId()); + } + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeScoreboard.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeScoreboard.java new file mode 100644 index 0000000..cf52523 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/mode/lavachallenge/LavaChallengeScoreboard.java @@ -0,0 +1,40 @@ +package com.br.guilhermematthew.nowly.pvp.mode.lavachallenge; + +import org.bukkit.entity.Player; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.Sidebar; +import com.br.guilhermematthew.nowly.commons.bukkit.scoreboard.sidebar.SidebarManager; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.commons.common.profile.addons.League; + +public class LavaChallengeScoreboard { + + public static void createScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + sidebar.hide(); + sidebar.show(); + + sidebar.setTitle("§b§lARENA: LAVA"); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + League league = League.getRanking(bukkitPlayer.getInt(DataType.XP)); + + sidebar.addBlankLine(); + sidebar.addLine("coins", "Coins: ", "§6" + bukkitPlayer.getIntFormatted(DataType.COINS)); + sidebar.addBlankLine(); + sidebar.addLine("§aleaguemc.com.br"); + + sidebar.update(); + } + + public static void updateScoreboard(Player player) { + Sidebar sidebar = SidebarManager.getSidebar(player.getUniqueId()); + + BukkitPlayer bukkitPlayer = BukkitMain.getBukkitPlayer(player.getUniqueId()); + League league = League.getRanking(bukkitPlayer.getInt(DataType.XP)); + + sidebar.addLine("coins", "Coins: ", "§6" + bukkitPlayer.getIntFormatted(DataType.COINS)); + } +} \ No newline at end of file diff --git a/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/utility/PvPUtility.java b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/utility/PvPUtility.java new file mode 100644 index 0000000..2c57771 --- /dev/null +++ b/pvp/src/main/java/com/br/guilhermematthew/nowly/pvp/utility/PvPUtility.java @@ -0,0 +1,108 @@ +package com.br.guilhermematthew.nowly.pvp.utility; + +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMain; +import com.br.guilhermematthew.nowly.commons.bukkit.BukkitMessages; +import com.br.guilhermematthew.nowly.commons.bukkit.account.BukkitPlayer; +import com.br.guilhermematthew.nowly.commons.bukkit.api.player.PlayerAPI; +import com.br.guilhermematthew.nowly.commons.common.data.category.DataCategory; +import com.br.guilhermematthew.nowly.commons.common.data.type.DataType; +import com.br.guilhermematthew.nowly.pvp.PvPMain; +import com.br.guilhermematthew.nowly.pvp.StringUtils; + +public class PvPUtility { + + public static void dropItens(Player player, Location loc) { + ArrayList itens = new ArrayList<>(); + + for (ItemStack item : player.getPlayer().getInventory().getContents()) { + if ((item != null) && (item.getType() != Material.AIR)) { + if (item.getType() == Material.BROWN_MUSHROOM || item.getType() == Material.RED_MUSHROOM || item.getType() == Material.BOWL || + item.getType() == Material.MUSHROOM_SOUP) { + itens.add(item); + } + } + } + + PlayerAPI.dropItems(player, itens, loc); + + itens.clear(); + } + + public static void handleStats(final Player killer, final Player died) { + BukkitPlayer bukkitPlayerDied = BukkitMain.getBukkitPlayer(died.getUniqueId()); + + if (killer != null) { + died.sendMessage(StringUtils.VOCE_MORREU_PARA.replace("%nick%", killer.getName())); + + checkStreakLose(killer.getName(), died.getName(), + StringUtils.KILLSTREAK_LOSE, bukkitPlayerDied.getInt(DataType.PVP_KILLSTREAK)); + } else { + died.sendMessage(StringUtils.VOCE_MORREU); + } + + died.sendMessage(BukkitMessages.DEATH_MESSAGE_XP.replace("%quantia%", "2")); + died.sendMessage(BukkitMessages.DEATH_MESSAGE_COINS.replace("%quantia%", "10")); + + bukkitPlayerDied.add(DataType.PVP_DEATHS); + bukkitPlayerDied.remove(DataType.COINS, 10); + bukkitPlayerDied.removeXP(2); + bukkitPlayerDied.set(DataType.PVP_KILLSTREAK, 0); + + if (killer == null) { + PvPMain.runAsync(() -> bukkitPlayerDied.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.KITPVP)); + return; + } + + BukkitPlayer bukkitPlayerKiller = BukkitMain.getBukkitPlayer(killer.getUniqueId()); + + killer.sendMessage(StringUtils.VOCE_MATOU.replace("%nick%", died.getName())); + + final int xp = PlayerAPI.getXPKill(killer, bukkitPlayerKiller.getLong(DataType.DOUBLEXP_TIME)), + coins = PlayerAPI.getCoinsKill(killer, bukkitPlayerKiller.getLong(DataType.DOUBLECOINS_TIME)); + + bukkitPlayerKiller.add(DataType.COINS, coins); + bukkitPlayerKiller.addXP(xp); + bukkitPlayerKiller.add(DataType.PVP_KILLS); + + int atualKillStreak = bukkitPlayerKiller.getInt(DataType.PVP_KILLSTREAK) + 1; + bukkitPlayerKiller.set(DataType.PVP_KILLSTREAK, atualKillStreak); + + if (atualKillStreak > bukkitPlayerKiller.getInt(DataType.PVP_MAXKILLSTREAK)) { + bukkitPlayerKiller.set(DataType.PVP_MAXKILLSTREAK, atualKillStreak); + } + + checkStreakWin(killer.getName(), atualKillStreak, StringUtils.KILLSTREAK_WIN); + + PvPMain.runAsync(() -> { + bukkitPlayerKiller.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.KITPVP); + bukkitPlayerDied.getDataHandler().saveCategorys(DataCategory.ACCOUNT, DataCategory.KITPVP); + }); + } + + public static void checkStreakWin(String nick, int value, String message) { + if (value >= 10 && value % 10 == 0) { + Bukkit.broadcastMessage(message.replace("%nick%", nick).replace("%valor%", "" + value)); + } + } + + public static void checkStreakLose(String killer, String loser, String message, int winstreak) { + if (winstreak >= 10) { + Bukkit.broadcastMessage(message.replace("%loser%", loser).replace("%killer%", killer).replace("%valor%", "" + winstreak)); + } + } + + public static void repairArmor(Player killer) { + killer.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET)); + killer.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); + killer.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); + killer.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS)); + } +} \ No newline at end of file diff --git a/pvp/src/main/resources/config.yml b/pvp/src/main/resources/config.yml new file mode 100644 index 0000000..6b459e8 --- /dev/null +++ b/pvp/src/main/resources/config.yml @@ -0,0 +1,6 @@ +LavaChallenge: + MinHit: + Facil: 20 + Medio: 30 + Dificil: 50 + Extremo: 80 \ No newline at end of file diff --git a/pvp/src/main/resources/plugin.yml b/pvp/src/main/resources/plugin.yml new file mode 100644 index 0000000..a7405d2 --- /dev/null +++ b/pvp/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: PvP +main: com.br.guilhermematthew.nowly.pvp.PvPMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/pvp/target/classes/config.yml b/pvp/target/classes/config.yml new file mode 100644 index 0000000..6b459e8 --- /dev/null +++ b/pvp/target/classes/config.yml @@ -0,0 +1,6 @@ +LavaChallenge: + MinHit: + Facil: 20 + Medio: 30 + Dificil: 50 + Extremo: 80 \ No newline at end of file diff --git a/pvp/target/classes/plugin.yml b/pvp/target/classes/plugin.yml new file mode 100644 index 0000000..a7405d2 --- /dev/null +++ b/pvp/target/classes/plugin.yml @@ -0,0 +1,5 @@ +name: PvP +main: com.br.guilhermematthew.nowly.pvp.PvPMain +authors: [Guilherme Matthew, theo] +version: 0.0.1 +softdepend: [BukkitCommons] \ No newline at end of file diff --git a/pvp/target/maven-archiver/pom.properties b/pvp/target/maven-archiver/pom.properties new file mode 100644 index 0000000..eda5cc8 --- /dev/null +++ b/pvp/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Sat Feb 25 15:25:35 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=pvp diff --git a/pvp/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/pvp/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/pvp/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/pvp/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..afae0ea --- /dev/null +++ b/pvp/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,48 @@ +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Switcher.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\events\GamerDeathEvent.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\listeners\AccountListener.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\manager\combatlog\CombatLogManager.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\fps\FPSListeners.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Magma.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\arena\ArenaScoreboard.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\Kit.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\menu\enums\InventoryMode.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Jumper.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Monk.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Snail.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\listeners\CombatLogListener.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\arena\ArenaMode.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\lavachallenge\LavaChallengeMode.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Grappler.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Fisherman.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Thor.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\manager\kit\KitManager.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\StringUtils.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\PvPMain.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\manager\gamer\GamerManager.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Camel.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\fps\FPSScoreboard.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\arena\ArenaListeners.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\PvP.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\fps\FPSMode.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\listeners\GeneralListeners.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\utility\PvPUtility.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Ninja.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\manager\gamer\Gamer.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Anchor.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Flash.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\menu\KitSelector.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Grandpa.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\AntiTower.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Hulk.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Viper.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\lavachallenge\LavaChallengeScoreboard.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Stomper.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\mode\lavachallenge\LavaChallengeListeners.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Poseidon.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\manager\kit\KitLoader.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Kangaroo.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\events\PlayerDamagePlayerEvent.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\commands\ServerCommand.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\Boxer.java +C:\source\dustmc\pvp\src\main\java\com\br\guilhermematthew\nowly\pvp\ability\register\NoFall.java diff --git a/pvp/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/pvp/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/pvp/target/pvp-1.0-SNAPSHOT.jar b/pvp/target/pvp-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..dc36f50 Binary files /dev/null and b/pvp/target/pvp-1.0-SNAPSHOT.jar differ diff --git a/servercommunication/.classpath b/servercommunication/.classpath new file mode 100644 index 0000000..a5d9509 --- /dev/null +++ b/servercommunication/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/servercommunication/.project b/servercommunication/.project new file mode 100644 index 0000000..ee5643f --- /dev/null +++ b/servercommunication/.project @@ -0,0 +1,23 @@ + + + servercommunication + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/servercommunication/.settings/org.eclipse.jdt.core.prefs b/servercommunication/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/servercommunication/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/servercommunication/.settings/org.eclipse.m2e.core.prefs b/servercommunication/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/servercommunication/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/servercommunication/dependency-reduced-pom.xml b/servercommunication/dependency-reduced-pom.xml new file mode 100644 index 0000000..1e005b4 --- /dev/null +++ b/servercommunication/dependency-reduced-pom.xml @@ -0,0 +1,122 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + servercommunication + + clean install + + + maven-shade-plugin + 2.4 + + + package + + shade + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + maven-jar-plugin + + + + true + com.br.guilhermematthew.servercommunication.ServerCommunication + + + + + + + + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + viaversion-repo + https://repo.viaversion.com + + + + + org.projectlombok + lombok + 1.16.12 + provided + + + org.github.paperspigot + paperspigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + json-simple + com.googlecode.json-simple + + + guava + com.google.guava + + + ebean + org.avaje + + + snakeyaml + org.yaml + + + bungeecord-chat + net.md-5 + + + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + system + C:/source/dustmc/commons/target/commons-1.0-SNAPSHOT.jar + + + + 8 + 8 + + + diff --git a/servercommunication/pom.xml b/servercommunication/pom.xml new file mode 100644 index 0000000..c111aac --- /dev/null +++ b/servercommunication/pom.xml @@ -0,0 +1,101 @@ + + + + dustmc + com.br.guilhermematthew.nowly + 1.0-SNAPSHOT + + 4.0.0 + + common-core + + + 8 + 8 + + + + clean install + + + org.apache.maven.plugins + maven-shade-plugin + 2.4 + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + package + + shade + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + com.br.guilhermematthew.servercommunication.ServerCommunication + + + + + + + + + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + viaversion-repo + https://repo.viaversion.com + + + + + + com.br.guilhermematthew.nowly + commons + 1.0-SNAPSHOT + Project + + + org.apache.commons + commons-lang3 + 3.12.0 + + + com.google.code.gson + gson + 2.10 + + + org.apache.commons + commons-pool2 + 2.11.1 + + + + \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java new file mode 100644 index 0000000..d6bfb8f --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunication.java @@ -0,0 +1,81 @@ +package com.br.guilhermematthew.servercommunication; + +import com.br.guilhermematthew.nowly.commons.custompackets.CommonPacketHandler; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.common.packet.PacketListenerManager; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener; +import com.br.guilhermematthew.servercommunication.server.Server; +import lombok.Getter; +import lombok.Setter; + +import java.io.IOException; + +public class ServerCommunication { + + public static final int TIMEOUT_TIME = 10; //TIMEOUT CLIENTS + + public static final int PORT = 30001; //SERVER PORT + + @Getter + private static final PacketListenerManager packetListener = new PacketListenerManager(); + public static ServerCommunicationInstance INSTANCE = ServerCommunicationInstance.UNKNOWN; + // START DEBUGS + public static final boolean DEBUG_CLIENT_CONNECTED = false; + public static final boolean DEBUG_CLIENT_DROPED = false; + public static final boolean DEBUG_CLIENT_AUTHENTICATED = false; + public static final boolean DEBUG_PACKET_RECEIVED = false; + public static boolean DEBUG_PACKET_SEND = false; + @Getter + @Setter + private static CommonPacketHandler packetHandler = null; + @Getter + private static UpdateListener updateListener; + //END DEBUGS + + static { + new Thread(updateListener = new UpdateListener()).start(); + } + + public static void startClient(final String clientName, final int clientID, final String hostName) { + Client client = new Client(hostName, clientName, clientID); + + debug("CLIENT", "Connecting on: " + hostName); + + try { + client.getClientConnection().connect(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public static void startServer(final String hostName) { + new Server(hostName); + } + + public static void main(final String[] args) { + if (args.length > 1) { + new Thread(updateListener = new UpdateListener()).start(); + + if (args[1].equalsIgnoreCase("server")) { + startServer(args[0]); + } else { + startClient("KitPvP", 1, args[0]); + } + } else { + debug("ERROR", "Correct usage: ServerCommunication.jar HostName"); + } + } + + + public static void debug(final String message) { + debug(null, message); + } + + public static void debug(final String prefix, final String message) { + if (prefix == null) { + System.out.println("[Debug] " + message); + } else { + System.out.println("[" + prefix + "] " + message); + } + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java new file mode 100644 index 0000000..7439930 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/ServerCommunicationInstance.java @@ -0,0 +1,7 @@ +package com.br.guilhermematthew.servercommunication; + +public enum ServerCommunicationInstance { + + UNKNOWN, CLIENT, SERVER + +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java new file mode 100644 index 0000000..ef26ef3 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/Client.java @@ -0,0 +1,34 @@ +package com.br.guilhermematthew.servercommunication.client; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.ServerCommunicationInstance; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Client { + + @Getter + private static Client instance; + + private String clientName; + private int clientID; + + private ClientConnection clientConnection; + + public Client(final String hostName, final String clientName, final int clientID) { + instance = this; + + ServerCommunication.INSTANCE = ServerCommunicationInstance.CLIENT; + + setClientName(clientName); + setClientID(clientID); + + setClientConnection(new ClientConnection(hostName)); + } + + public static boolean isInstanced() { + return instance != null; + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java new file mode 100644 index 0000000..6a10b2b --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/client/ClientConnection.java @@ -0,0 +1,124 @@ +package com.br.guilhermematthew.servercommunication.client; + +import com.br.guilhermematthew.nowly.commons.CommonsGeneral; +import com.br.guilhermematthew.nowly.commons.bukkit.api.BukkitServerAPI; +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.CommonClient; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.listener.PacketListener; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener.UpdateEvent; +import com.br.guilhermematthew.servercommunication.common.update.UpdateListener.UpdateType; +import lombok.Getter; +import lombok.Setter; + +import java.io.IOException; +import java.net.Socket; + +@Getter +@Setter +public class ClientConnection implements IConnection { + + private String hostName; + private int port; + + private Socket socket; + private CommonClient connectionListen; + + public ClientConnection(final String hostName) { + setHostName(hostName); + setPort(ServerCommunication.PORT); + } + + public void connect() throws IOException { + socket = new Socket(getHostName(), ServerCommunication.PORT); + + setConnectionListen(new CommonClient(socket)); + ServerCommunication.getPacketListener().register(new PacketListener()); + debug("Connected to " + hostName + ":" + port + "!"); + + sendPacket(new CPacketAction(Client.getInstance().getClientName(), Client.getInstance().getClientID()). + writeType("HandShake").writeField(Client.getInstance().getClientName()).writeFieldValue("" + Client.getInstance().getClientID())); + + if (CommonsGeneral.getPluginInstance().isBukkit() && BukkitServerAPI.isRegisteredServer()) + BukkitServerAPI.registerServer(); + + ServerCommunication.getUpdateListener().register(new UpdateEvent() { + + int seconds = 0; + + @Override + public void onUpdate(UpdateType updateType) { + if (updateType != UpdateType.SECOND) return; + + seconds++; + + if (seconds % 10 == 0) { + sendPacket(new CPacketAction(Client.getInstance().getClientName(), Client.getInstance().getClientID()). + writeType("KeepAlive")); + } + } + }); + } + + public void sendPacket(final CommonPacket packet) { + connectionListen.sendPacket(packet); + } + + public void debug(String string) { + ServerCommunication.debug("CLIENT - " + Client.getInstance().getClientName() + ":" + Client.getInstance().getClientID(), string); + } + + public boolean isConnected() { + return socket != null && socket.isConnected(); + } + + @Override + public String getAddress() { + return hostName + ":" + port; + } + + @Override + public void disconnect() { + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + socket = null; + } + } + + @Override + public Socket getSocket() { + return socket; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return null; + } + + public void reconnect(Runnable callback) { + if (socket != null) disconnect(); + if (connectionListen != null) connectionListen.disconnect(); + + try { + connect(); + } catch (Exception ex) { + debug("Failed to reconnect, retrying... (" + ex.getLocalizedMessage() + ")."); + + try { + Thread.sleep(1000 * 5); + } catch (Exception ignored) { + } + + reconnect(callback); + return; + } + + if (callback != null) callback.run(); + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java new file mode 100644 index 0000000..0ec03ca --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/CommonClient.java @@ -0,0 +1,74 @@ +package com.br.guilhermematthew.servercommunication.common.connection; + +import com.br.guilhermematthew.servercommunication.common.connection.handle.InputHandler; +import com.br.guilhermematthew.servercommunication.common.connection.handle.OutputHandler; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import lombok.Getter; +import lombok.Setter; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; + +@Getter +@Setter +public class CommonClient implements IConnection { + + private Socket socket; + + private InputHandler inputHandler; + private OutputHandler outputHandler; + + private String clientName; + private int clientID; + + //NEWS + private int time; + + public CommonClient(final Socket socket) throws IOException { + setSocket(socket); + + setInputHandler(new InputHandler(this, new DataInputStream(socket.getInputStream()))); + setOutputHandler(new OutputHandler(new DataOutputStream(socket.getOutputStream()))); + + getInputHandler().start(); + getOutputHandler().start(); + } + + public void sendPacket(final CommonPacket packet) { + getOutputHandler().sendPacket(packet); + } + + public void disconnect() { + if (!socket.isClosed()) { + try { + inputHandler.close(); + outputHandler.close(); + socket.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + inputHandler.stopThread(); + outputHandler.stopThread(); + } + + public String getAddress() { + return socket.getInetAddress().getHostName() + ":" + socket.getPort(); + } + + public boolean isAuthenticated() { + return getClientName() != null; + } + + public void incrementTimeout() { + time++; + } + + @Override + public String getServerName() { + return clientName + "-" + clientID; + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java new file mode 100644 index 0000000..ba060df --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/IConnection.java @@ -0,0 +1,15 @@ +package com.br.guilhermematthew.servercommunication.common.connection; + +import java.io.IOException; +import java.net.Socket; + +public interface IConnection { + + String getAddress(); + + void disconnect() throws IOException; + + Socket getSocket(); + + String getServerName(); +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java new file mode 100644 index 0000000..4cbab45 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/InputHandler.java @@ -0,0 +1,62 @@ +package com.br.guilhermematthew.servercommunication.common.connection.handle; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import lombok.Getter; +import lombok.Setter; + +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.net.SocketException; + +@Getter +@Setter +public class InputHandler extends Thread { + + private IConnection connection; + private DataInputStream data; + + private boolean running; + + public InputHandler(final IConnection connection, DataInputStream data) { + setConnection(connection); + setData(data); + } + + @Override + public void run() { + running = true; + + while (isRunning()) { + try { + String message = data.readUTF(); + + if (message != null) { + ServerCommunication.getPacketListener().call(message, connection.getSocket()); + message = null; + } + } catch (EOFException ex) { + running = false; + } catch (SocketException ex) { + //TODO nothing to do + } catch (IOException ex) { + ex.printStackTrace(); + try { + connection.disconnect(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + public void stopThread() { + running = false; + } + + public void close() throws IOException { + data.close(); + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java new file mode 100644 index 0000000..cab7434 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/connection/handle/OutputHandler.java @@ -0,0 +1,93 @@ +package com.br.guilhermematthew.servercommunication.common.connection.handle; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.client.Client; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.List; + +public class OutputHandler extends Thread { + + private final Object LOCK = new Object(); + private final List packetQueue = new ArrayList<>(); + private final DataOutputStream data; + private boolean running; + private int serverOutOfReach; + + public OutputHandler(DataOutputStream data) { + this.data = data; + } + + @Override + public void run() { + running = true; + + while (running) { + try { + synchronized (packetQueue) { + while (packetQueue.size() > 0) { + CommonPacket packet = packetQueue.get(0); + + if (packet != null) { + try { + data.writeUTF(packet.getJSONString()); + } catch (SocketException ex) { + serverOutOfReach++; + + if (serverOutOfReach == 1) { + ServerCommunication.debug("PACKET SEND", "Server is offline!"); + } + + if (serverOutOfReach % 5 == 0) { + Client.getInstance().getClientConnection().reconnect(null); + } + + if (serverOutOfReach >= 30) { + stopThread(); + close(); + serverOutOfReach = 0; + } + } + + packet = null; + } + + packetQueue.remove(0); + } + } + synchronized (LOCK) { + LOCK.wait(3250); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (Exception e) { + packetQueue.remove(0); + e.printStackTrace(); + } + } + } + + public void sendPacket(final CommonPacket packet) { + synchronized (packetQueue) { + packet.write(); + + packetQueue.add(packet); + } + + synchronized (LOCK) { + LOCK.notifyAll(); + } + } + + public void stopThread() { + running = false; + } + + public void close() throws IOException { + data.close(); + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java new file mode 100644 index 0000000..cc16422 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/CommonPacket.java @@ -0,0 +1,30 @@ +package com.br.guilhermematthew.servercommunication.common.packet; + +import com.google.gson.JsonObject; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; + +@Getter +@Setter +public abstract class CommonPacket { + + private JsonObject json; + + private String serverName; + private int serverID; + private Long timestamp; + + public abstract void read(final JsonObject json); + + public abstract void write(); + + public abstract void handle(final Socket socket); + + public abstract String getJSONString(); + + public abstract String getPacketName(); + + public abstract String getDebugReceived(); +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java new file mode 100644 index 0000000..f0b337d --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/PacketListenerManager.java @@ -0,0 +1,32 @@ +package com.br.guilhermematthew.servercommunication.common.packet; + +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +public class PacketListenerManager { + + private final List packetMap; + + public PacketListenerManager() { + packetMap = new ArrayList<>(); + } + + public void register(PacketEvent packetEvent) { + this.packetMap.add(packetEvent); + } + + public void unregister(PacketEvent packetEvent) { + this.packetMap.remove(packetEvent); + } + + public void call(final String packetString, final Socket socket) { + this.packetMap.forEach(packetEvent -> packetEvent.onPacketReceive(packetString, socket)); + } + + public interface PacketEvent { + + void onPacketReceive(final String packetString, final Socket socket); + + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java new file mode 100644 index 0000000..17e1c0d --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/packet/listener/PacketListener.java @@ -0,0 +1,53 @@ +package com.br.guilhermematthew.servercommunication.common.packet.listener; + +import com.br.guilhermematthew.nowly.commons.CommonsConst; +import com.br.guilhermematthew.nowly.commons.custompackets.PacketsManager; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.PacketListenerManager.PacketEvent; +import com.google.gson.JsonObject; + +import java.net.Socket; + +public class PacketListener implements PacketEvent { + + @Override + public void onPacketReceive(final String packetString, final Socket socket) { + JsonObject json = null; + + try { + json = CommonsConst.PARSER.parse(packetString).getAsJsonObject(); + } catch (Exception ex) { + ServerCommunication.debug("PACKET PARSER", "An error ocurred while trying to parse packet! (" + ex.getLocalizedMessage() + ")"); + } finally { + if (json != null) { + if (json.has("packetName")) { + String packetName = json.get("packetName").getAsString(); + + CommonPacket packet = PacketsManager.getPacket(packetName); + + if (packet != null) { + packet.read(json); + + if (ServerCommunication.DEBUG_PACKET_RECEIVED) { + ServerCommunication.debug("PACKET RECEIVE", packet.getDebugReceived()); + } + + try { + packet.handle(socket); + } catch (Exception ex) { + ServerCommunication.debug("PACKET HANDLER", "An error ocurred while trying to handle packet! (" + ex.getLocalizedMessage() + ")"); + ex.printStackTrace(); + } + + packet = null; + } + packetName = null; + } else { + ServerCommunication.debug("I received a Invalid Packet! (#1)"); + } + json = null; + } + } + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java new file mode 100644 index 0000000..2e7a02a --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/common/update/UpdateListener.java @@ -0,0 +1,57 @@ +package com.br.guilhermematthew.servercommunication.common.update; + +import java.util.concurrent.ConcurrentLinkedQueue; + +public class UpdateListener implements Runnable { + + private long seconds; + + private final ConcurrentLinkedQueue list; + + private boolean running; + + public UpdateListener() { + list = new ConcurrentLinkedQueue<>(); + } + + public void register(UpdateEvent updateEvent) { + list.add(updateEvent); + } + + public void unregister(UpdateEvent updateEvent) { + list.remove(updateEvent); + } + + @Override + public void run() { + running = true; + + while (running) { + try { + Thread.sleep(1000); + } catch (Exception ex) { + } + + seconds++; + + call(UpdateType.SECOND); + + if (seconds % 60 == 0) + call(UpdateType.MINUTE); + } + } + + private void call(UpdateType updateEvent) { + list.forEach(update -> update.onUpdate(updateEvent)); + } + + public enum UpdateType { + SECOND, MINUTE + } + + public interface UpdateEvent { + + void onUpdate(UpdateType updateType); + + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java new file mode 100644 index 0000000..e719832 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ConnectionInfo.java @@ -0,0 +1,23 @@ +package com.br.guilhermematthew.servercommunication.server; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ConnectionInfo { + + private String address; + private int connectionsPerSecond; + + public ConnectionInfo(String address) { + this.address = address; + } + + public void addConnection() { + this.connectionsPerSecond++; + if (this.connectionsPerSecond >= 6) { + //Server.getInstance().getServerGeneral().adToBlackList(address); + } + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java new file mode 100644 index 0000000..dcbde15 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/Server.java @@ -0,0 +1,50 @@ +package com.br.guilhermematthew.servercommunication.server; + +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.ServerCommunicationInstance; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import com.br.guilhermematthew.servercommunication.common.packet.listener.PacketListener; +import lombok.Getter; +import lombok.Setter; + +import java.net.Socket; + +public class Server { + + @Getter + @Setter + private static Server instance; + + @Getter + private ServerGeneral serverGeneral; + + public Server(final String hostName) { + setInstance(this); + + ServerCommunication.debug("[ServerCommunication] The server has started on: " + hostName); + + ServerCommunication.INSTANCE = ServerCommunicationInstance.SERVER; + + ServerCommunication.getPacketListener().register(new PacketListener()); + + try { + serverGeneral = new ServerGeneral(hostName); + serverGeneral.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(0); + } + } + + public void sendPacket(final String text, final CommonPacket packet) { + getServerGeneral().sendPacket(text, packet); + } + + public void sendPacket(final String name, final int id, final CommonPacket packet) { + getServerGeneral().sendPacket(name, id, packet); + } + + public void sendPacket(final Socket socket, final CommonPacket packet) { + getServerGeneral().sendPacket(socket, packet); + } +} \ No newline at end of file diff --git a/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java new file mode 100644 index 0000000..78d31f8 --- /dev/null +++ b/servercommunication/src/main/java/com/br/guilhermematthew/servercommunication/server/ServerGeneral.java @@ -0,0 +1,259 @@ +package com.br.guilhermematthew.servercommunication.server; + +import com.br.guilhermematthew.nowly.commons.custompackets.registry.CPacketAction; +import com.br.guilhermematthew.servercommunication.ServerCommunication; +import com.br.guilhermematthew.servercommunication.common.connection.CommonClient; +import com.br.guilhermematthew.servercommunication.common.connection.IConnection; +import com.br.guilhermematthew.servercommunication.common.packet.CommonPacket; +import lombok.Getter; +import lombok.Setter; +import lombok.val; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Getter +@Setter +public class ServerGeneral extends Thread implements IConnection { + + private String hostName; + private int port; + + private ServerSocket serverSocket; + + private ConcurrentHashMap socketToRegister; + private Map clientMap; + + private boolean RUNNING; + + public ServerGeneral(final String hostName) throws Exception { + setHostName(hostName); + setPort(ServerCommunication.PORT); + + setServerSocket(new ServerSocket()); + getServerSocket().bind(new InetSocketAddress(hostName, getPort())); + + setSocketToRegister(new ConcurrentHashMap<>()); + setClientMap(new HashMap<>()); + + debug("Connection to " + hostName + ":" + port + " established!"); + + ServerCommunication.getUpdateListener().register(updateType -> { + for (CommonClient connections : getSocketToRegister().values()) { + if (!connections.isAuthenticated()) { + connections.incrementTimeout(); + + if (connections.getTime() == ServerCommunication.TIMEOUT_TIME + 3) { + connections.disconnect(); + + socketToRegister.remove(connections.getSocket()); + + if (ServerCommunication.DEBUG_CLIENT_DROPED) { + debug("Connection " + connections.getAddress() + " dropped!"); + } + } + + if (connections.getTime() == ServerCommunication.TIMEOUT_TIME) { + connections.sendPacket(new CPacketAction("Server", 0).writeType("TimedOut")); + + if (ServerCommunication.DEBUG_CLIENT_DROPED) { + debug("Connection " + connections.getAddress() + " timeout!"); + } + } + } + } + }); + } + + @Override + public void run() { + RUNNING = true; + + while (RUNNING) { + if (serverSocket == null) { + RUNNING = false; + return; + } + + if (getServerSocket().isClosed()) { + try { + getServerSocket().bind(new InetSocketAddress(getHostName(), getPort())); + } catch (IOException e1) { + e1.printStackTrace(); + break; + } + } + + try { + Socket socket = serverSocket.accept(); + String clientHost = socket.getInetAddress().getHostName(); + int clientPort = socket.getPort(); + + socketToRegister.put(socket, new CommonClient(socket)); + + if (ServerCommunication.DEBUG_CLIENT_CONNECTED) { + debug("Connection from " + clientHost + ":" + clientPort + " accepted!"); + } + + } catch (SocketException ex) { + if (!ex.getLocalizedMessage().equals("Socket closed")) ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + try { + disconnect(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void sendPacket(final Socket socket, final CommonPacket packet) { + CommonClient connection = getConnectionByPort(socket.getPort()); + + if (connection != null) { + connection.sendPacket(packet); + } + } + + public void sendPacket(final String text, final CommonPacket packet) { + val name = text.replaceAll("\\d", ""); + val id = name.length() != text.length() ? Integer.parseInt(text.replaceAll("\\D+","")) : 1; + + sendPacket(name, id, packet); + } + + public void sendPacket(final String name, final int id, final CommonPacket packet) { + CommonClient connection = getConnectionListen(name, id); + if (connection != null) { + connection.sendPacket(packet); + } + } + + public CommonClient getConnectionListen(final String name, final int id) { + CommonClient connection = getClientMap().getOrDefault(name.toLowerCase() + "," + id, null); + + if (connection != null) return connection; + + for (CommonClient connections : getClientMap().values()) { + if ((connections.getClientName().equalsIgnoreCase(name)) && (connections.getClientID() == id)) { + connection = connections; + break; + } + } + + return connection; + } + + public CommonClient getConnectionListenByPort(int port) { + CommonClient connection = null; + + for (CommonClient connectionListen : socketToRegister.values()) { + if (connectionListen.getSocket().getPort() == port) { + connection = connectionListen; + break; + } + } + + return connection; + } + + public CommonClient getConnectionByPort(int port) { + CommonClient connection = null; + + for (CommonClient connectionListen : getClientMap().values()) { + if (connectionListen.getSocket().getPort() == port) { + connection = connectionListen; + break; + } + } + + return connection; + } + + public Socket getSocketByPort(int port) { + Socket socket = null; + + for (Socket sockets : socketToRegister.keySet()) { + if (sockets.getPort() == port) { + socket = sockets; + break; + } + } + + return socket; + } + + public void registerClient(final String clientName, final Integer clientID, final Socket socket) { + CommonClient connection = getConnectionListenByPort(socket.getPort()); + + if (connection != null) { + connection.setClientName(clientName); + connection.setClientID(clientID); + + clientMap.put(clientName + "," + clientID, connection); + + if (ServerCommunication.DEBUG_CLIENT_AUTHENTICATED) { + debug(clientName + " (" + clientID + ") authenticated!"); + } + } + + socketToRegister.remove(socket); + } + + public void unregisterClient(Socket socket) { + CommonClient connection = getConnectionListenByPort(socket.getPort()); + + if (connection != null) { + String clientName = connection.getClientName(); + + int clientId = connection.getClientID(); + + clientMap.remove(clientName.toLowerCase() + "," + clientId); + + if (ServerCommunication.DEBUG_CLIENT_AUTHENTICATED) { + debug(clientName + " (" + clientId + ") loggout!"); + } + + } + } + + public void debug(final String string) { + ServerCommunication.debug("SERVER", string); + } + + @Override + public String getAddress() { + return hostName + ":" + port; + } + + @Override + public void disconnect() throws IOException { + RUNNING = false; + + if (getServerSocket() != null) { + getServerSocket().close(); + } + + serverSocket = null; + } + + @Override + public Socket getSocket() { + return null; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return "SERVER"; + } +} \ No newline at end of file diff --git a/servercommunication/target/maven-archiver/pom.properties b/servercommunication/target/maven-archiver/pom.properties new file mode 100644 index 0000000..0e6d080 --- /dev/null +++ b/servercommunication/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Feb 24 02:02:33 UTC 2023 +version=1.0-SNAPSHOT +groupId=com.br.guilhermematthew.nowly +artifactId=servercommunication diff --git a/servercommunication/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/servercommunication/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/servercommunication/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/servercommunication/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..6668727 --- /dev/null +++ b/servercommunication/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,15 @@ +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\listener\PacketListener.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\handle\InputHandler.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\server\ServerGeneral.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\client\ClientConnection.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\CommonClient.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\client\Client.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\CommonPacket.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\ServerCommunicationInstance.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\packet\PacketListenerManager.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\server\ConnectionInfo.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\handle\OutputHandler.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\server\Server.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\ServerCommunication.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\connection\IConnection.java +C:\source\dustmc\servercommunication\src\main\java\com\br\guilhermematthew\servercommunication\common\update\UpdateListener.java diff --git a/servercommunication/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/servercommunication/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/servercommunication/target/original-servercommunication-1.0-SNAPSHOT.jar b/servercommunication/target/original-servercommunication-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..f774fcc Binary files /dev/null and b/servercommunication/target/original-servercommunication-1.0-SNAPSHOT.jar differ diff --git a/servercommunication/target/servercommunication-1.0-SNAPSHOT-shaded.jar b/servercommunication/target/servercommunication-1.0-SNAPSHOT-shaded.jar new file mode 100644 index 0000000..e5433a1 Binary files /dev/null and b/servercommunication/target/servercommunication-1.0-SNAPSHOT-shaded.jar differ diff --git a/servercommunication/target/servercommunication-1.0-SNAPSHOT.jar b/servercommunication/target/servercommunication-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..e5433a1 Binary files /dev/null and b/servercommunication/target/servercommunication-1.0-SNAPSHOT.jar differ