Dateien nach "src/main/java/pb/ajneb97/managers" hochladen
This commit is contained in:
31
src/main/java/pb/ajneb97/managers/Actualizacion.java
Normal file
31
src/main/java/pb/ajneb97/managers/Actualizacion.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
|
||||
public class Actualizacion implements Listener{
|
||||
|
||||
private PaintballBattle plugin;
|
||||
public Actualizacion(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void Join(PlayerJoinEvent event){
|
||||
Player jugador = event.getPlayer();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(jugador.isOp() && !(plugin.version.equals(plugin.latestversion))){
|
||||
if(config.getString("new_version_reminder").equals("true")){
|
||||
jugador.sendMessage(PaintballBattle.prefix + ChatColor.RED +" There is a new version available. "+ChatColor.YELLOW+
|
||||
"("+ChatColor.GRAY+plugin.latestversion+ChatColor.YELLOW+")");
|
||||
jugador.sendMessage(ChatColor.RED+"You can download it at: "+ChatColor.GREEN+"https://www.spigotmc.org/resources/76676/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
src/main/java/pb/ajneb97/managers/CartelesAdmin.java
Normal file
95
src/main/java/pb/ajneb97/managers/CartelesAdmin.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
|
||||
public class CartelesAdmin {
|
||||
|
||||
private int taskID;
|
||||
private PaintballBattle plugin;
|
||||
public CartelesAdmin(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public int getTaskID() {
|
||||
return this.taskID;
|
||||
}
|
||||
|
||||
public void actualizarCarteles() {
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
ejecutarActualizarCarteles();
|
||||
}
|
||||
},0, 30L);
|
||||
}
|
||||
|
||||
protected void ejecutarActualizarCarteles() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
if(config.contains("Signs")) {
|
||||
for(String arena : config.getConfigurationSection("Signs").getKeys(false)) {
|
||||
Partida partida = plugin.getPartida(arena);
|
||||
if(partida != null) {
|
||||
List<String> listaCarteles = new ArrayList<String>();
|
||||
if(config.contains("Signs."+arena)) {
|
||||
listaCarteles = config.getStringList("Signs."+arena);
|
||||
}
|
||||
for(int i=0;i<listaCarteles.size();i++) {
|
||||
String[] separados = listaCarteles.get(i).split(";");
|
||||
int x = Integer.valueOf(separados[0]);
|
||||
int y = Integer.valueOf(separados[1]);
|
||||
int z = Integer.valueOf(separados[2]);
|
||||
World world = Bukkit.getWorld(separados[3]);
|
||||
if(world != null) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
if(!world.isChunkLoaded(chunkX, chunkZ)) {
|
||||
continue;
|
||||
}
|
||||
Block block = world.getBlockAt(x,y,z);
|
||||
|
||||
if(block.getType().name().contains("SIGN")) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
String estado = "";
|
||||
if(partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
estado = messages.getString("signStatusIngame");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.COMENZANDO)) {
|
||||
estado = messages.getString("signStatusStarting");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.ESPERANDO)) {
|
||||
estado = messages.getString("signStatusWaiting");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.DESACTIVADA)) {
|
||||
estado = messages.getString("signStatusDisabled");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
estado = messages.getString("signStatusFinishing");
|
||||
}
|
||||
|
||||
List<String> lista = messages.getStringList("signFormat");
|
||||
for(int c=0;c<lista.size();c++) {
|
||||
sign.setLine(c, ChatColor.translateAlternateColorCodes('&', lista.get(c).replace("%arena%", arena).replace("%current_players%", partida.getCantidadActualJugadores()+"")
|
||||
.replace("%max_players%", partida.getCantidadMaximaJugadores()+"").replace("%status%", estado)));
|
||||
}
|
||||
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
172
src/main/java/pb/ajneb97/managers/CartelesListener.java
Normal file
172
src/main/java/pb/ajneb97/managers/CartelesListener.java
Normal file
@@ -0,0 +1,172 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
|
||||
public class CartelesListener implements Listener{
|
||||
|
||||
private PaintballBattle plugin;
|
||||
public CartelesListener(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//Al poner Cartel
|
||||
@EventHandler
|
||||
public void crearCartel(SignChangeEvent event ) {
|
||||
Player jugador = event.getPlayer();
|
||||
if(jugador.isOp() || jugador.hasPermission("paintball.admin")) {
|
||||
if(event.getLine(0).equals("[Paintball]")) {
|
||||
String arena = event.getLine(1);
|
||||
if(arena != null && plugin.getPartida(arena) != null) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
Partida partida = plugin.getPartida(arena);
|
||||
String estado = "";
|
||||
if(partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
estado = messages.getString("signStatusIngame");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.COMENZANDO)) {
|
||||
estado = messages.getString("signStatusStarting");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.ESPERANDO)) {
|
||||
estado = messages.getString("signStatusWaiting");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.DESACTIVADA)) {
|
||||
estado = messages.getString("signStatusDisabled");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
estado = messages.getString("signStatusFinishing");
|
||||
}
|
||||
|
||||
List<String> lista = messages.getStringList("signFormat");
|
||||
for(int c=0;c<lista.size();c++) {
|
||||
event.setLine(c, ChatColor.translateAlternateColorCodes('&', lista.get(c).replace("%arena%", arena).replace("%current_players%", partida.getCantidadActualJugadores()+"")
|
||||
.replace("%max_players%", partida.getCantidadMaximaJugadores()+"").replace("%status%", estado)));
|
||||
}
|
||||
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
List<String> listaCarteles = new ArrayList<String>();
|
||||
if(config.contains("Signs."+arena)) {
|
||||
listaCarteles = config.getStringList("Signs."+arena);
|
||||
}
|
||||
listaCarteles.add(event.getBlock().getX()+";"+event.getBlock().getY()+";"+event.getBlock().getZ()+";"+event.getBlock().getWorld().getName());
|
||||
config.set("Signs."+arena, listaCarteles);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void eliminarCartel(BlockBreakEvent event ) {
|
||||
Player jugador = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if(jugador.isOp() || jugador.hasPermission("paintball.admin")) {
|
||||
if(block.getType().name().contains("SIGN")) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(config.contains("Signs")) {
|
||||
for(String arena : config.getConfigurationSection("Signs").getKeys(false)) {
|
||||
List<String> listaCarteles = new ArrayList<String>();
|
||||
if(config.contains("Signs."+arena)) {
|
||||
listaCarteles = config.getStringList("Signs."+arena);
|
||||
}
|
||||
for(int i=0;i<listaCarteles.size();i++) {
|
||||
String[] separados = listaCarteles.get(i).split(";");
|
||||
int x = Integer.valueOf(separados[0]);
|
||||
int y = Integer.valueOf(separados[1]);
|
||||
int z = Integer.valueOf(separados[2]);
|
||||
World world = Bukkit.getWorld(separados[3]);
|
||||
if(world != null) {
|
||||
if(block.getX() == x && block.getY() == y && block.getZ() == z && world.getName().equals(block.getWorld().getName())) {
|
||||
listaCarteles.remove(i);
|
||||
config.set("Signs."+arena, listaCarteles);
|
||||
plugin.saveConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entrarPartida(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Block block = event.getClickedBlock();
|
||||
if(block != null && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(block.getType().name().contains("SIGN")) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(config.contains("Signs")) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
for(String arena : config.getConfigurationSection("Signs").getKeys(false)) {
|
||||
Partida partida = plugin.getPartida(arena);
|
||||
if(partida != null) {
|
||||
List<String> listaCarteles = new ArrayList<String>();
|
||||
if(config.contains("Signs."+arena)) {
|
||||
listaCarteles = config.getStringList("Signs."+arena);
|
||||
}
|
||||
for(int i=0;i<listaCarteles.size();i++) {
|
||||
String[] separados = listaCarteles.get(i).split(";");
|
||||
int x = Integer.valueOf(separados[0]);
|
||||
int y = Integer.valueOf(separados[1]);
|
||||
int z = Integer.valueOf(separados[2]);
|
||||
World world = Bukkit.getWorld(separados[3]);
|
||||
if(world != null) {
|
||||
if(block.getX() == x && block.getY() == y && block.getZ() == z && world.getName().equals(block.getWorld().getName())) {
|
||||
if(partida != null) {
|
||||
if(!Checks.checkTodo(plugin, jugador)) {
|
||||
return;
|
||||
}
|
||||
if(partida.estaActivada()) {
|
||||
if(plugin.getPartidaJugador(jugador.getName()) == null) {
|
||||
if(!partida.estaIniciada()) {
|
||||
if(!partida.estaLlena()) {
|
||||
if(!UtilidadesOtros.pasaConfigInventario(jugador, config)) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("errorClearInventory")));
|
||||
return;
|
||||
}
|
||||
PartidaManager.jugadorEntra(partida, jugador,plugin);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("arenaIsFull")));
|
||||
}
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("arenaAlreadyStarted")));
|
||||
}
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("alreadyInArena")));
|
||||
}
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("arenaDisabledError")));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
136
src/main/java/pb/ajneb97/managers/Checks.java
Normal file
136
src/main/java/pb/ajneb97/managers/Checks.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
|
||||
public class Checks {
|
||||
|
||||
public static boolean checkTodo(PaintballBattle plugin,CommandSender jugador){
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
String nombre = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+ " ";
|
||||
String mensaje = nombre+messages.getString("materialNameError");
|
||||
|
||||
//Check config.yml
|
||||
if(!comprobarMaterial(config.getString("leave_item.item"),jugador,mensaje) &&
|
||||
!comprobarMaterial(config.getString("killstreaks_item.item"),jugador,mensaje)
|
||||
&& !comprobarMaterial(config.getString("play_again_item.item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
for(String key : config.getConfigurationSection("teams").getKeys(false)) {
|
||||
if(!comprobarMaterial(config.getString("teams."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for(String key : config.getConfigurationSection("killstreaks_items").getKeys(false)) {
|
||||
if(!comprobarMaterial(config.getString("killstreaks_items."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(String key : config.getConfigurationSection("hats_items").getKeys(false)) {
|
||||
if(!comprobarMaterial(config.getString("hats_items."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
for(String key : shop.getConfigurationSection("shop_items").getKeys(false)) {
|
||||
if(!comprobarMaterial(shop.getString("shop_items."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(String key : shop.getConfigurationSection("perks_items").getKeys(false)) {
|
||||
if(!comprobarMaterial(shop.getString("perks_items."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for(String key : shop.getConfigurationSection("hats_items").getKeys(false)) {
|
||||
if(!comprobarMaterial(shop.getString("hats_items."+key+".item"),jugador,mensaje)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public static boolean comprobarMaterial(String key,CommandSender jugador,String mensaje){
|
||||
try{
|
||||
if(key.contains(":")){
|
||||
String[] idsplit = key.split(":");
|
||||
String stringDataValue = idsplit[1];
|
||||
short DataValue = Short.valueOf(stringDataValue);
|
||||
Material mat = Material.getMaterial(idsplit[0].toUpperCase());
|
||||
ItemStack item = new ItemStack(mat,1,(short)DataValue);
|
||||
}else {
|
||||
ItemStack item = new ItemStack(Material.getMaterial(key),1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', mensaje.replace("%material%", key)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Al iniciar el server, revisa TODOS LOS PATHS ORIGINALES (IDs numericas) y los modifica si no es 1.13+
|
||||
public static void checkearYModificar(PaintballBattle plugin, boolean primeraVez) {
|
||||
if(UtilidadesOtros.isLegacy()) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
if(primeraVez) {
|
||||
modificarPath(config,"teams.blue.item","WOOL:11");
|
||||
modificarPath(config,"teams.red.item","WOOL:14");
|
||||
modificarPath(config,"teams.yellow.item","WOOL:4");
|
||||
modificarPath(config,"teams.green.item","WOOL:13");
|
||||
modificarPath(config,"teams.orange.item","WOOL:1");
|
||||
modificarPath(config,"teams.purple.item","WOOL:10");
|
||||
modificarPath(config,"teams.black.item","WOOL:15");
|
||||
modificarPath(config,"teams.white.item","WOOL");
|
||||
modificarPath(config,"play_again_item.item","INK_SACK:12");
|
||||
modificarPath(config,"killedBySound","NOTE_PLING;10;0.1");
|
||||
modificarPath(config,"killSound","FIREWORK_BLAST;10;2");
|
||||
modificarPath(config,"expireKillstreakSound","NOTE_SNARE_DRUM;10;2");
|
||||
modificarPath(config,"snowballShootSound","SHOOT_ARROW;10;0.5");
|
||||
modificarPath(config,"shopUnlockSound","FIREWORK_BLAST;10;2");
|
||||
modificarPath(config,"hatAbilityActivatedSound","CHEST_OPEN;10;1.5");
|
||||
modificarPath(config,"explosiveHatSound","EXPLODE;10;1");
|
||||
modificarPath(config,"killstreaks_items.more_snowballs.item","SNOW_BALL");
|
||||
modificarPath(config,"killstreaks_items.lightning.item","GOLD_AXE");
|
||||
modificarPath(config,"hats_items.present_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(config,"hats_items.assassin_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(config,"hats_items.chicken_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(config,"hats_items.time_hat.item","GOLD_HELMET");
|
||||
modificarPath(config,"killstreaks_items.more_snowballs.activateSound","VILLAGER_YES;10;1");
|
||||
modificarPath(config,"killstreaks_items.strong_arm.activateSound","ANVIL_USE;10;2");
|
||||
modificarPath(config,"killstreaks_items.triple_shoot.activateSound","ANVIL_USE;10;2");
|
||||
modificarPath(config,"killstreaks_items.3_lives.activateSound","BAT_TAKEOFF;10;1.5;global");
|
||||
modificarPath(config,"killstreaks_items.teleport.activateSound","ENDERMAN_TELEPORT;10;1");
|
||||
modificarPath(config,"killstreaks_items.lightning.activateSound","AMBIENCE_THUNDER;10;1");
|
||||
modificarPath(config,"killstreaks_items.nuke.activateSound","WOLF_HOWL;10;2;global");
|
||||
modificarPath(config,"killstreaks_items.nuke.finalSound","EXPLODE;10;1;global");
|
||||
modificarPath(config,"killstreaks_items.fury.activateSound","PISTON_EXTEND;10;1.5;global");
|
||||
plugin.saveConfig();
|
||||
|
||||
modificarPath(shop,"perks_items.decorative_item.item","STAINED_GLASS_PANE:10");
|
||||
modificarPath(shop,"hats_items.present_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(shop,"hats_items.assassin_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(shop,"hats_items.chicken_hat.item","SKULL_ITEM:3");
|
||||
modificarPath(shop,"hats_items.time_hat.item","GOLD_HELMET");
|
||||
plugin.saveShop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void modificarPath(FileConfiguration config,String path,String idNueva) {
|
||||
if(config.contains(path)) {
|
||||
config.set(path, idNueva);
|
||||
}
|
||||
}
|
||||
}
|
90
src/main/java/pb/ajneb97/managers/CooldownHats.java
Normal file
90
src/main/java/pb/ajneb97/managers/CooldownHats.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
|
||||
public class CooldownHats {
|
||||
|
||||
int taskID;
|
||||
int tiempo;
|
||||
private JugadorPaintball jugador;
|
||||
private Partida partida;
|
||||
private PaintballBattle plugin;
|
||||
public CooldownHats(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void cooldownHat(final JugadorPaintball jugador, final Partida partida,int tiempo){
|
||||
this.jugador = jugador;
|
||||
this.tiempo = tiempo;
|
||||
this.partida = partida;
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarCooldownHat()){
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
if(!partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
jugador.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("hatCooldownFinished")));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarCooldownHat() {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
if(tiempo <= 0) {
|
||||
jugador.setEfectoHatEnCooldown(false);
|
||||
return false;
|
||||
}else {
|
||||
tiempo--;
|
||||
jugador.setTiempoEfectoHat(tiempo);
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
jugador.setEfectoHatEnCooldown(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void durationHat(final JugadorPaintball jugador, final Partida partida,int tiempo){
|
||||
this.jugador = jugador;
|
||||
this.tiempo = tiempo;
|
||||
this.partida = partida;
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarDurationHat()){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarDurationHat() {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
if(tiempo <= 0) {
|
||||
jugador.setEfectoHatActivado(false);
|
||||
return false;
|
||||
}else {
|
||||
tiempo--;
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
jugador.setEfectoHatActivado(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
198
src/main/java/pb/ajneb97/managers/CooldownKillstreaks.java
Normal file
198
src/main/java/pb/ajneb97/managers/CooldownKillstreaks.java
Normal file
@@ -0,0 +1,198 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Killstreak;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.utils.ValueOfPatch;
|
||||
|
||||
public class CooldownKillstreaks {
|
||||
|
||||
int taskID;
|
||||
int tiempo;
|
||||
private JugadorPaintball jugador;
|
||||
private Partida partida;
|
||||
private PaintballBattle plugin;
|
||||
public CooldownKillstreaks(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void cooldownKillstreak(final JugadorPaintball jugador, final Partida partida, final String nombre,int tiempo){
|
||||
this.jugador = jugador;
|
||||
this.partida = partida;
|
||||
this.tiempo = tiempo;
|
||||
if(nombre.equalsIgnoreCase("fury")) {
|
||||
CooldownKillstreaks c = new CooldownKillstreaks(plugin);
|
||||
c.cooldownParticulasFury(jugador, partida);
|
||||
}
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarCooldownKillstreak(nombre)){
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(!partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
String name = ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_items."+nombre+".name"));
|
||||
jugador.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakExpired").replace("%killstreak%", name)));
|
||||
String[] separados = config.getString("expireKillstreakSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugador.getJugador().playSound(jugador.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarCooldownKillstreak(String nombre) {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
if(tiempo <= 0) {
|
||||
jugador.removerKillstreak(nombre);
|
||||
return false;
|
||||
}else {
|
||||
Killstreak k = jugador.getKillstreak(nombre);
|
||||
if(k != null) {
|
||||
tiempo--;
|
||||
k.setTiempo(tiempo);
|
||||
return true;
|
||||
}else {
|
||||
jugador.removerKillstreak(nombre);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
jugador.removerKillstreak(nombre);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void cooldownParticulasFury(final JugadorPaintball jugador, final Partida partida){
|
||||
this.jugador = jugador;
|
||||
this.partida = partida;
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarParticulasFury()){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 5L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarParticulasFury() {
|
||||
if (partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
if (jugador != null) {
|
||||
if (jugador.getKillstreak("fury") != null) {
|
||||
Location l = jugador.getJugador().getLocation().clone();
|
||||
l.setY(l.getY() + 1.5);
|
||||
if (Bukkit.getVersion().contains("1.8")) {
|
||||
l.getWorld().playEffect(l, org.bukkit.Effect.valueOf("VILLAGER_THUNDERCLOUD"), 1);
|
||||
} else {
|
||||
// KORREKT für Paper 1.13+ (einschließlich 1.21.5): VILLAGER_ANGRY
|
||||
l.getWorld().spawnParticle(Particle.ANGRY_VILLAGER, l, 1);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void cooldownNuke(final JugadorPaintball jugador, final Partida partida, final String[] separados1, final String[] separados2){
|
||||
this.jugador = jugador;
|
||||
this.partida = partida;
|
||||
this.tiempo = 5;
|
||||
final FileConfiguration messages = plugin.getMessages();
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
player.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("nukeImpact").replace("%time%", tiempo+"")));
|
||||
}
|
||||
tiempo--;
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarNuke(separados1,separados2,messages)){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 20L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarNuke(String[] separados1,String[] separados2,FileConfiguration messages) {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
if(jugador != null) {
|
||||
if(tiempo <= 0) {
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados2[0]);
|
||||
if(separados2.length >= 4) {
|
||||
if(separados2[3].equalsIgnoreCase("global")) {
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
player.getJugador().playSound(player.getJugador().getLocation(), sound, Float.valueOf(separados2[1]), Float.valueOf(separados2[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.getJugador().playSound(jugador.getJugador().getLocation(), sound, Float.valueOf(separados2[1]), Float.valueOf(separados2[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.getJugador().playSound(jugador.getJugador().getLocation(), sound, Float.valueOf(separados2[1]), Float.valueOf(separados2[2]));
|
||||
}
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados2[0]+" &7is not valid."));
|
||||
}
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
PartidaManager.muereJugador(partida, jugador, player, plugin, false, true);
|
||||
}
|
||||
partida.setEnNuke(false);
|
||||
return false;
|
||||
}else {
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados1[0]);
|
||||
if(separados1.length >= 4) {
|
||||
if(separados1[3].equalsIgnoreCase("global")) {
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
player.getJugador().playSound(player.getJugador().getLocation(), sound, Float.valueOf(separados1[1]), Float.valueOf(separados1[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.getJugador().playSound(jugador.getJugador().getLocation(), sound, Float.valueOf(separados1[1]), Float.valueOf(separados1[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.getJugador().playSound(jugador.getJugador().getLocation(), sound, Float.valueOf(separados1[1]), Float.valueOf(separados1[2]));
|
||||
}
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados1[0]+" &7is not valid."));
|
||||
}
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
player.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("nukeImpact").replace("%time%", tiempo+"")));
|
||||
}
|
||||
tiempo--;
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Killstreak;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.lib.actionbarapi.ActionBarAPI;
|
||||
|
||||
public class CooldownKillstreaksActionbar {
|
||||
|
||||
int taskID;
|
||||
private PaintballBattle plugin;
|
||||
public CooldownKillstreaksActionbar(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void crearActionbars() {
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
final FileConfiguration messages = plugin.getMessages();
|
||||
final FileConfiguration config = plugin.getConfig();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
actualizarActionbars(player,messages,config);
|
||||
}
|
||||
}
|
||||
},0, 20L);
|
||||
}
|
||||
|
||||
protected void actualizarActionbars(final Player player,final FileConfiguration messages,final FileConfiguration config) {
|
||||
Partida partida = plugin.getPartidaJugador(player.getName());
|
||||
if(partida != null) {
|
||||
JugadorPaintball jugador = partida.getJugador(player.getName());
|
||||
Killstreak ultima = jugador.getUltimaKillstreak();
|
||||
if(ultima != null) {
|
||||
String name = config.getString("killstreaks_items."+ultima.getTipo()+".name");
|
||||
int tiempo = ultima.getTiempo();
|
||||
ActionBarAPI.sendActionBar(jugador.getJugador(), ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakActionbar")
|
||||
.replace("%killstreak%", name).replace("%time%", tiempo+"")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
147
src/main/java/pb/ajneb97/managers/CooldownManager.java
Normal file
147
src/main/java/pb/ajneb97/managers/CooldownManager.java
Normal file
@@ -0,0 +1,147 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.Equipo;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import pb.ajneb97.utils.ValueOfPatch;
|
||||
|
||||
|
||||
public class CooldownManager {
|
||||
|
||||
int taskID;
|
||||
int tiempo;
|
||||
private Partida partida;
|
||||
private PaintballBattle plugin;
|
||||
public CooldownManager(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void cooldownComenzarJuego(Partida partida,int cooldown){
|
||||
this.partida = partida;
|
||||
this.tiempo = cooldown;
|
||||
partida.setTiempo(tiempo);
|
||||
final FileConfiguration messages = plugin.getMessages();
|
||||
final FileConfiguration config = plugin.getConfig();
|
||||
final String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("arenaStartingMessage").replace("%time%", tiempo+"")));
|
||||
}
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarComenzarJuego(messages,config,prefix)){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarComenzarJuego(FileConfiguration messages,FileConfiguration config,String prefix) {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.COMENZANDO)) {
|
||||
if(tiempo <= 5 && tiempo > 0) {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("arenaStartingMessage").replace("%time%", tiempo+"")));
|
||||
String[] separados = config.getString("startCooldownSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugadores.get(i).getJugador().playSound(jugadores.get(i).getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
}
|
||||
partida.disminuirTiempo();
|
||||
tiempo--;
|
||||
return true;
|
||||
}else if(tiempo <= 0) {
|
||||
PartidaManager.iniciarPartida(partida,plugin);
|
||||
return false;
|
||||
}else {
|
||||
partida.disminuirTiempo();
|
||||
tiempo--;
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("gameStartingCancelled")));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void cooldownJuego(Partida partida){
|
||||
this.partida = partida;
|
||||
this.tiempo = partida.getTiempoMaximo();
|
||||
partida.setTiempo(tiempo);
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarJuego()){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarJuego() {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
partida.disminuirTiempo();
|
||||
if(tiempo == 0) {
|
||||
PartidaManager.iniciarFaseFinalizacion(partida, plugin);
|
||||
return false;
|
||||
}else {
|
||||
tiempo--;
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void cooldownFaseFinalizacion(Partida partida,int cooldown,final Equipo ganador){
|
||||
this.partida = partida;
|
||||
this.tiempo = cooldown;
|
||||
partida.setTiempo(tiempo);
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutarComenzarFaseFinalizacion(ganador)){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean ejecutarComenzarFaseFinalizacion(Equipo ganador) {
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
partida.disminuirTiempo();
|
||||
if(tiempo == 0) {
|
||||
PartidaManager.finalizarPartida(partida,plugin,false,ganador);
|
||||
return false;
|
||||
}else {
|
||||
tiempo--;
|
||||
if(ganador != null) {
|
||||
PartidaManager.lanzarFuegos(ganador.getJugadores());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
|
||||
public class CooldownSnowballParticle {
|
||||
|
||||
int taskID;
|
||||
private PaintballBattle plugin;
|
||||
private Projectile snowball;
|
||||
private String particula;
|
||||
public CooldownSnowballParticle(PaintballBattle plugin,Projectile snowball,String particula){
|
||||
this.plugin = plugin;
|
||||
this.snowball = snowball;
|
||||
this.particula = particula;
|
||||
}
|
||||
|
||||
public void cooldown(){
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run(){
|
||||
if(!ejecutar()){
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 3L);
|
||||
}
|
||||
|
||||
protected boolean ejecutar() {
|
||||
if(snowball != null && !snowball.isDead()) {
|
||||
Location l = snowball.getLocation();
|
||||
UtilidadesOtros.generarParticula(particula, l, 0.01F, 0.01F, 0.01F, 0.01F, 1);
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
430
src/main/java/pb/ajneb97/managers/InventarioAdmin.java
Normal file
430
src/main/java/pb/ajneb97/managers/InventarioAdmin.java
Normal file
@@ -0,0 +1,430 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.juego.PartidaEditando;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
|
||||
public class InventarioAdmin implements Listener{
|
||||
|
||||
private PaintballBattle plugin;
|
||||
public InventarioAdmin(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static void crearInventario(Player jugador,Partida partida,PaintballBattle plugin) {
|
||||
Inventory inv = Bukkit.createInventory(null, 36, ChatColor.translateAlternateColorCodes('&', "&2Editing Arena: &7"+partida.getNombre()));
|
||||
ItemStack item = new ItemStack(Material.BEACON,1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Lobby"));
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena Lobby in your"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7current position."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
Location lobby = partida.getLobby();
|
||||
if(lobby == null) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position: &7NONE"));
|
||||
}else {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position:"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eX: &7"+lobby.getX()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eY: &7"+lobby.getY()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eZ: &7"+lobby.getZ()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eWorld: &7"+lobby.getWorld().getName()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eYaw: &7"+lobby.getYaw()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&ePitch: &7"+lobby.getPitch()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(10, item);
|
||||
|
||||
item = new ItemStack(Material.QUARTZ_BLOCK,1);
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Team 1 Spawn"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena team 1 Spawn"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7in your current position."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
Location spawn = partida.getTeam1().getSpawn();
|
||||
if(spawn == null) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position: &7NONE"));
|
||||
}else {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position:"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eX: &7"+spawn.getX()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eY: &7"+spawn.getY()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eZ: &7"+spawn.getZ()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eWorld: &7"+spawn.getWorld().getName()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eYaw: &7"+spawn.getYaw()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&ePitch: &7"+spawn.getPitch()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(11, item);
|
||||
|
||||
item = new ItemStack(Material.QUARTZ_BLOCK,1);
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Team 2 Spawn"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena team 2 Spawn"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7in your current position."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
spawn = partida.getTeam2().getSpawn();
|
||||
if(spawn == null) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position: &7NONE"));
|
||||
}else {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Position:"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eX: &7"+spawn.getX()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eY: &7"+spawn.getY()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eZ: &7"+spawn.getZ()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eWorld: &7"+spawn.getWorld().getName()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&eYaw: &7"+spawn.getYaw()));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&ePitch: &7"+spawn.getPitch()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(12, item);
|
||||
|
||||
item = new ItemStack(Material.GHAST_TEAR,partida.getCantidadMinimaJugadores());
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Min Players"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena minimum number"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7of players."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getCantidadMinimaJugadores()));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(13, item);
|
||||
|
||||
item = new ItemStack(Material.GHAST_TEAR,partida.getCantidadMaximaJugadores());
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Max Players"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena maximum number"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7of players."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getCantidadMaximaJugadores()));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(14, item);
|
||||
|
||||
item = new ItemStack(Material.NAME_TAG,1);
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Team 1 Color"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena team 1 Color."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
if(partida.getTeam1().esRandom()) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7random"));
|
||||
}else {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getTeam1().getTipo()));
|
||||
}
|
||||
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(15, item);
|
||||
|
||||
item = new ItemStack(Material.NAME_TAG,1);
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Team 2 Color"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena team 2 Color."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
if(partida.getTeam2().esRandom()) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7random"));
|
||||
}else {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getTeam2().getTipo()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(16, item);
|
||||
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
item = new ItemStack(Material.CLOCK,1);
|
||||
}else {
|
||||
item = new ItemStack(Material.valueOf("WATCH"),1);
|
||||
}
|
||||
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Time"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the arena time in seconds."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getTiempoMaximo()));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(21, item);
|
||||
|
||||
item = new ItemStack(Material.REDSTONE_BLOCK,1);
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lSet Starting Lives"));
|
||||
lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Click to define the starting amount of lives"));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7for both teams."));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', ""));
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&9Current Value: &7"+partida.getVidasIniciales()));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(23, item);
|
||||
|
||||
jugador.openInventory(inv);
|
||||
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida);
|
||||
plugin.setPartidaEditando(p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alCerrarInventario(InventoryCloseEvent event) {
|
||||
Player jugador = (Player) event.getPlayer();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', "&2Editing Arena:");
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
PartidaEditando partida = plugin.getPartidaEditando();
|
||||
if(partida != null && partida.getJugador().getName().equals(jugador.getName())) {
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).contains(pathInventoryM)){
|
||||
plugin.removerPartidaEditando();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alSalir(PlayerQuitEvent event) {
|
||||
PartidaEditando partida = plugin.getPartidaEditando();
|
||||
Player jugador = event.getPlayer();
|
||||
if(partida != null && partida.getJugador().getName().equals(jugador.getName())) {
|
||||
plugin.removerPartidaEditando();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventario(InventoryClickEvent event){
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', "&2Editing Arena:");
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).contains(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
PartidaEditando partida = plugin.getPartidaEditando();
|
||||
if(partida != null && partida.getJugador().getName().equals(jugador.getName())) {
|
||||
int slot = event.getSlot();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(slot == 10) {
|
||||
partida.getPartida().setLobby(jugador.getLocation().clone());
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("lobbyDefined").replace("%name%", partida.getPartida().getNombre())));
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(),plugin);
|
||||
}else if(slot == 11) {
|
||||
partida.getPartida().getTeam1().setSpawn(jugador.getLocation().clone());
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("spawnTeamDefined").replace("%number%", "1").replace("%name%", partida.getPartida().getNombre())));
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(),plugin);
|
||||
}else if(slot == 12) {
|
||||
partida.getPartida().getTeam2().setSpawn(jugador.getLocation().clone());
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("spawnTeamDefined").replace("%number%", "2").replace("%name%", partida.getPartida().getNombre())));
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(),plugin);
|
||||
}else if(slot == 13) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("min");
|
||||
plugin.setPartidaEditando(p);
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite an even number."));
|
||||
}else if(slot == 14) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("max");
|
||||
plugin.setPartidaEditando(p);
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite an even number."));
|
||||
}else if(slot == 15) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("team1name");
|
||||
plugin.setPartidaEditando(p);
|
||||
String lista = "";
|
||||
for(String key : config.getConfigurationSection("teams").getKeys(false)) {
|
||||
lista=lista+key+" ";
|
||||
}
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite one of these team names: &7random "+lista));
|
||||
}else if(slot == 16) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("team2name");
|
||||
plugin.setPartidaEditando(p);
|
||||
String lista = "";
|
||||
for(String key : config.getConfigurationSection("teams").getKeys(false)) {
|
||||
lista=lista+key+" ";
|
||||
}
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite one of these team names: &7random "+lista));
|
||||
}else if(slot == 21) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("time");
|
||||
plugin.setPartidaEditando(p);
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite a number. This will be the arena time in seconds."));
|
||||
}else if(slot == 23) {
|
||||
jugador.closeInventory();
|
||||
PartidaEditando p = new PartidaEditando(jugador,partida.getPartida());
|
||||
p.setPaso("lives");
|
||||
plugin.setPartidaEditando(p);
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aWrite a number. This will be the amount of starting lives for each team."));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void capturarChat(AsyncPlayerChatEvent event) {
|
||||
final PartidaEditando partida = plugin.getPartidaEditando();
|
||||
final Player jugador = event.getPlayer();
|
||||
String message = ChatColor.stripColor(event.getMessage());
|
||||
if(partida != null && partida.getJugador().getName().equals(jugador.getName())) {
|
||||
event.setCancelled(true);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
String paso = partida.getPaso();
|
||||
if(paso.equals("min")) {
|
||||
try {
|
||||
int num = Integer.valueOf(message);
|
||||
if(num >= 2 && num % 2 == 0) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("minPlayersDefined").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().setCantidadMinimaJugadores(num);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}catch(NumberFormatException e) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}else if(paso.equals("max")) {
|
||||
try {
|
||||
int num = Integer.valueOf(message);
|
||||
if(num >= 2 && num % 2 == 0) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("maxPlayersDefined").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().setCantidadMaximaJugadores(num);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}catch(NumberFormatException e) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}else if(paso.equals("team1name")) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
if(config.contains("teams."+message) || message.equalsIgnoreCase("random")) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("typeDefined").replace("%number%", "1").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().getTeam1().setTipo(message);
|
||||
if(message.equalsIgnoreCase("random")) {
|
||||
partida.getPartida().getTeam1().setRandom(true);
|
||||
}else {
|
||||
partida.getPartida().getTeam1().setRandom(false);
|
||||
}
|
||||
partida.getPartida().modificarTeams(config);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', "&cThat team name doesn't exists."));
|
||||
}
|
||||
}else if(paso.equals("team2name")) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
if(config.contains("teams."+message) || message.equalsIgnoreCase("random")) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("typeDefined").replace("%number%", "2").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().getTeam2().setTipo(message);
|
||||
if(message.equalsIgnoreCase("random")) {
|
||||
partida.getPartida().getTeam2().setRandom(true);
|
||||
}else {
|
||||
partida.getPartida().getTeam2().setRandom(false);
|
||||
}
|
||||
partida.getPartida().modificarTeams(config);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', "&cThat team name doesn't exists."));
|
||||
}
|
||||
}else if(paso.equals("time")) {
|
||||
try {
|
||||
int num = Integer.valueOf(message);
|
||||
if(num > 0) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("timeDefined").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().setTiempoMaximo(num);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}catch(NumberFormatException e) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}else if(paso.equals("lives")) {
|
||||
try {
|
||||
int num = Integer.valueOf(message);
|
||||
if(num > 0) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("livesDefined").replace("%name%", partida.getPartida().getNombre())));
|
||||
partida.getPartida().setVidasIniciales(num);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InventarioAdmin.crearInventario(jugador, partida.getPartida(), plugin);
|
||||
}
|
||||
}, 3L);
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}catch(NumberFormatException e) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("validNumberError")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
143
src/main/java/pb/ajneb97/managers/InventarioHats.java
Normal file
143
src/main/java/pb/ajneb97/managers/InventarioHats.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.api.Hat;
|
||||
import pb.ajneb97.api.PaintballAPI;
|
||||
import pb.ajneb97.database.JugadorDatos;
|
||||
import pb.ajneb97.database.MySQL;
|
||||
import pb.ajneb97.utils.UtilidadesItems;
|
||||
|
||||
public class InventarioHats implements Listener{
|
||||
|
||||
PaintballBattle plugin;
|
||||
public InventarioHats(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static void crearInventario(Player jugador,PaintballBattle plugin) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
Inventory inv = Bukkit.createInventory(null, 27, ChatColor.translateAlternateColorCodes('&', config.getString("hats_inventory_title")));
|
||||
ArrayList<Hat> hats = PaintballAPI.getHats(jugador);
|
||||
int slot = 0;
|
||||
if(hats.isEmpty()) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_items.no_hats");
|
||||
inv.setItem(13, item);
|
||||
}else {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
for(Hat h : hats) {
|
||||
String name = h.getName();
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_items."+name);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
String status = "";
|
||||
if(h.isSelected()) {
|
||||
status = messages.getString("hatStatusSelected");
|
||||
}else {
|
||||
status = messages.getString("hatStatusNotSelected");
|
||||
}
|
||||
for(int i=0;i<lore.size();i++) {
|
||||
lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i).replace("%status%", status)));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
if(config.contains("hats_items."+name+".skull_id")) {
|
||||
String id = config.getString("hats_items."+name+".skull_id");
|
||||
String textura = config.getString("hats_items."+name+".skull_texture");
|
||||
item = UtilidadesItems.getCabeza(item, id, textura);
|
||||
}
|
||||
|
||||
inv.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_items.remove_hat");
|
||||
inv.setItem(26, item);
|
||||
}
|
||||
|
||||
jugador.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventario(InventoryClickEvent event){
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', config.getString("hats_inventory_title"));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).equals(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
final Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
ArrayList<Hat> hats = PaintballAPI.getHats(jugador);
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if(item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
|
||||
if(event.getSlot() == 26) {
|
||||
if(MySQL.isEnabled(config)) {
|
||||
MySQL.deseleccionarHats(plugin, jugador.getName());
|
||||
}else {
|
||||
JugadorDatos jDatos = plugin.getJugador(jugador.getName());
|
||||
jDatos.deseleccionarHats();
|
||||
}
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("hatRemoved")));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
InventarioHats.crearInventario(jugador, plugin);
|
||||
}
|
||||
}, 5L);
|
||||
return;
|
||||
}
|
||||
for(Hat h : hats) {
|
||||
ItemStack itemConfig = UtilidadesItems.crearItem(config, "hats_items."+h.getName());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
ItemMeta metaConfig = itemConfig.getItemMeta();
|
||||
if(item.getType().equals(itemConfig.getType()) && meta.getDisplayName().equals(metaConfig.getDisplayName())) {
|
||||
//Seleccionar hat
|
||||
if(PaintballAPI.hasHatSelected(jugador, h.getName())) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("hatAlreadySelected")));
|
||||
return;
|
||||
}
|
||||
if(MySQL.isEnabled(config)) {
|
||||
MySQL.seleccionarHatAsync(plugin, jugador.getName(), h.getName());
|
||||
}else {
|
||||
JugadorDatos jDatos = plugin.getJugador(jugador.getName());
|
||||
jDatos.seleccionarHat(h.getName());
|
||||
}
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("hatSelected").replace("%name%", config.getString("hats_items."+h.getName()+".name"))));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
InventarioHats.crearInventario(jugador, plugin);
|
||||
}
|
||||
}, 5L);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
src/main/java/pb/ajneb97/managers/InventarioKillstreaks.java
Normal file
77
src/main/java/pb/ajneb97/managers/InventarioKillstreaks.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Killstreak;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.utils.UtilidadesItems;
|
||||
|
||||
public class InventarioKillstreaks{
|
||||
|
||||
int taskID;
|
||||
private PaintballBattle plugin;
|
||||
public InventarioKillstreaks(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void actualizarInventario(final Player jugador,final Partida partida) {
|
||||
BukkitScheduler sh = Bukkit.getServer().getScheduler();
|
||||
final FileConfiguration config = plugin.getConfig();
|
||||
final FileConfiguration messages = plugin.getMessages();
|
||||
taskID = sh.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
if(!update(jugador,config,messages,partida)) {
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
protected boolean update(Player jugador,FileConfiguration config,FileConfiguration messages,Partida partida) {
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_inventory_title")));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
Inventory inv = jugador.getOpenInventory().getTopInventory();
|
||||
if(partida == null) {
|
||||
return false;
|
||||
}
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
if(j == null) {
|
||||
return false;
|
||||
}
|
||||
if(inv != null && ChatColor.stripColor(jugador.getOpenInventory().getTitle()).equals(pathInventoryM)) {
|
||||
for(String key : config.getConfigurationSection("killstreaks_items").getKeys(false)) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "killstreaks_items."+key);
|
||||
|
||||
Killstreak k = j.getKillstreak(key);
|
||||
if(k != null) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakCurrentlyActive").replace("%time%", k.getTiempo()+"")));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
int slot = Integer.valueOf(config.getString("killstreaks_items."+key+".slot"));
|
||||
if(slot != - 1) {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
462
src/main/java/pb/ajneb97/managers/InventarioShop.java
Normal file
462
src/main/java/pb/ajneb97/managers/InventarioShop.java
Normal file
@@ -0,0 +1,462 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import me.realized.tokenmanager.api.TokenManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.api.Hat;
|
||||
import pb.ajneb97.api.PaintballAPI;
|
||||
import pb.ajneb97.api.Perk;
|
||||
import pb.ajneb97.database.JugadorDatos;
|
||||
import pb.ajneb97.database.MySQL;
|
||||
import pb.ajneb97.utils.UtilidadesItems;
|
||||
import pb.ajneb97.utils.ValueOfPatch;
|
||||
|
||||
|
||||
public class InventarioShop implements Listener{
|
||||
|
||||
private PaintballBattle plugin;
|
||||
public InventarioShop(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static void crearInventarioPrincipal(Player jugador,PaintballBattle plugin) {
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
Inventory inv = Bukkit.createInventory(null, 27, ChatColor.translateAlternateColorCodes('&', shop.getString("shopInventoryTitle")));
|
||||
for(String key : shop.getConfigurationSection("shop_items").getKeys(false)) {
|
||||
ItemStack item = UtilidadesItems.crearItem(shop, "shop_items."+key);
|
||||
int slot = Integer.valueOf(shop.getString("shop_items."+key+".slot"));
|
||||
if(slot != - 1) {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
jugador.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventarioPrincipal(InventoryClickEvent event){
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', shop.getString("shopInventoryTitle"));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
//FileConfiguration messages = plugin.getMessages();
|
||||
//String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).equals(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
int slot = event.getSlot();
|
||||
for(String key : shop.getConfigurationSection("shop_items").getKeys(false)) {
|
||||
if(slot == Integer.valueOf(shop.getString("shop_items."+key+".slot"))) {
|
||||
if(key.equals("perks_items")) {
|
||||
crearInventarioPerks(jugador,plugin);
|
||||
}else if(key.equals("hats_items")) {
|
||||
crearInventarioHats(jugador,plugin);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void crearInventarioPerks(Player jugador,PaintballBattle plugin) {
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
Inventory inv = Bukkit.createInventory(null, 54, ChatColor.translateAlternateColorCodes('&', shop.getString("shopPerksInventoryTitle")));
|
||||
for(String key : shop.getConfigurationSection("perks_items").getKeys(false)) {
|
||||
ItemStack item = UtilidadesItems.crearItem(shop, "perks_items."+key);
|
||||
if(key.equals("coins_info")) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(config.getString("economy_used").equals("vault")) {
|
||||
Economy econ = plugin.getEconomy();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", econ.getBalance(jugador)+"")));
|
||||
}else if(config.getString("economy_used").equals("token_manager")) {
|
||||
TokenManager tokenManager = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", tokenManager.getTokens(jugador).orElse(0)+"")));
|
||||
}
|
||||
else {
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", PaintballAPI.getCoins(jugador)+"")));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
if(shop.contains("perks_items."+key+".slot")) {
|
||||
int slot = Integer.valueOf(shop.getString("perks_items."+key+".slot"));
|
||||
if(slot != - 1) {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ItemStack item = UtilidadesItems.crearItem(shop, "perks_items.decorative_item");
|
||||
for(int i=0;i<=8;i++) {
|
||||
inv.setItem(i, item);
|
||||
}
|
||||
for(int i=36;i<=44;i++) {
|
||||
inv.setItem(i, item);
|
||||
}
|
||||
|
||||
int levelExtraLives = PaintballAPI.getPerkLevel(jugador, "extra_lives");
|
||||
List<String> lista = shop.getStringList("perks_upgrades.extra_lives");
|
||||
for(int i=0;i<lista.size();i++) {
|
||||
if(i > levelExtraLives-1) {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.extra_lives_perk_item");
|
||||
}else {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.extra_lives_bought_perk_item");
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String[] separados = lista.get(i).split(";");
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%name%", separados[2])));
|
||||
List<String> lore = meta.getLore();
|
||||
for(int c=0;c<lore.size();c++) {
|
||||
lore.set(c, lore.get(c).replace("%amount%", separados[0]).replace("%cost%", separados[1]));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(9+i, item);
|
||||
|
||||
if(i==8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int levelInitialKillcoins = PaintballAPI.getPerkLevel(jugador, "initial_killcoins");
|
||||
lista = shop.getStringList("perks_upgrades.initial_killcoins");
|
||||
for(int i=0;i<lista.size();i++) {
|
||||
if(i > levelInitialKillcoins-1) {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.initial_killcoins_perk_item");
|
||||
}else {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.initial_killcoins_bought_perk_item");
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String[] separados = lista.get(i).split(";");
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%name%", separados[2])));
|
||||
List<String> lore = meta.getLore();
|
||||
for(int c=0;c<lore.size();c++) {
|
||||
lore.set(c, lore.get(c).replace("%amount%", separados[0]).replace("%cost%", separados[1]));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(18+i, item);
|
||||
|
||||
if(i==8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int levelExtraKillcoins = PaintballAPI.getPerkLevel(jugador, "extra_killcoins");
|
||||
lista = shop.getStringList("perks_upgrades.extra_killcoins");
|
||||
for(int i=0;i<lista.size();i++) {
|
||||
if(i > levelExtraKillcoins-1) {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.extra_killcoins_perk_item");
|
||||
}else {
|
||||
item = UtilidadesItems.crearItem(shop, "perks_items.extra_killcoins_bought_perk_item");
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String[] separados = lista.get(i).split(";");
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%name%", separados[2])));
|
||||
List<String> lore = meta.getLore();
|
||||
for(int c=0;c<lore.size();c++) {
|
||||
lore.set(c, lore.get(c).replace("%amount%", separados[0]).replace("%cost%", separados[1]));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(27+i, item);
|
||||
|
||||
if(i==8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jugador.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventarioPerks(InventoryClickEvent event){
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', shop.getString("shopPerksInventoryTitle"));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).equals(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
final Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(!event.getCurrentItem().getType().equals(Material.AIR)) {
|
||||
int slot = event.getSlot();
|
||||
if(slot >= 9 && slot <= 17 || slot >= 18 && slot <= 26 || slot >= 27 && slot <= 35) {
|
||||
int slotSum = 0;
|
||||
String perk = "";
|
||||
if(slot >= 9 && slot <= 17) {
|
||||
//ExtraLives
|
||||
slotSum = 9;
|
||||
perk = "extra_lives";
|
||||
}else if(slot >= 18 && slot <= 26) {
|
||||
//Initial KillCoins
|
||||
slotSum = 18;
|
||||
perk = "initial_killcoins";
|
||||
}else {
|
||||
//Extra KillCoins
|
||||
slotSum = 27;
|
||||
perk = "extra_killcoins";
|
||||
}
|
||||
|
||||
List<String> lista = shop.getStringList("perks_upgrades."+perk);
|
||||
for(int i=0;i<lista.size();i++) {
|
||||
String[] separados = lista.get(i).split(";");
|
||||
if(slot == slotSum+i) {
|
||||
//Si es nivel 1 significa que el proximo nivel a desbloquear es el slot 10
|
||||
int nivel = PaintballAPI.getPerkLevel(jugador, perk);
|
||||
int slotADesbloquear = nivel+slotSum;
|
||||
if(slot == slotADesbloquear) {
|
||||
int cost = Integer.valueOf(separados[1]);
|
||||
double dinero = 0;
|
||||
if(config.getString("economy_used").equals("vault")) {
|
||||
Economy econ = plugin.getEconomy();
|
||||
dinero = econ.getBalance(jugador);
|
||||
if(dinero < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
econ.withdrawPlayer(jugador, cost);
|
||||
}else if(config.getString("economy_used").equals("token_manager")) {
|
||||
TokenManager tokenManager = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
|
||||
float dineroF = tokenManager.getTokens(jugador).orElse(0);
|
||||
if(dineroF < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
tokenManager.removeTokens(jugador, cost);
|
||||
}
|
||||
else {
|
||||
dinero = PaintballAPI.getCoins(jugador);
|
||||
if(dinero < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
PaintballAPI.removeCoins(jugador, cost);
|
||||
}
|
||||
if(MySQL.isEnabled(config)) {
|
||||
MySQL.setPerkJugadorAsync(plugin, jugador.getUniqueId().toString(), jugador.getName(), perk, nivel+1);
|
||||
}else {
|
||||
plugin.registerPlayer(jugador.getUniqueId().toString()+".yml");
|
||||
if(plugin.getJugador(jugador.getName()) == null) {
|
||||
plugin.agregarJugadorDatos(new JugadorDatos(jugador.getName(),jugador.getUniqueId().toString(),0,0,0,0,0,new ArrayList<Perk>(),new ArrayList<Hat>()));
|
||||
}
|
||||
JugadorDatos jDatos = plugin.getJugador(jugador.getName());
|
||||
jDatos.setPerk(perk, nivel+1);
|
||||
}
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("perkUnlocked").replace("%name%", separados[2])));
|
||||
String[] separadosSound = config.getString("shopUnlockSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separadosSound[0]);
|
||||
jugador.playSound(jugador.getLocation(), sound, Float.valueOf(separadosSound[1]), Float.valueOf(separadosSound[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separadosSound[0]+" &7is not valid."));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
InventarioShop.crearInventarioPerks(jugador, plugin);
|
||||
}
|
||||
}, 5L);
|
||||
}else if(slot > slotADesbloquear) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("perkErrorPrevious")));
|
||||
return;
|
||||
}else {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("perkErrorUnlocked")));
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}else if(slot == Integer.valueOf(shop.getString("perks_items.go_to_menu.slot"))) {
|
||||
InventarioShop.crearInventarioPrincipal(jugador, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void crearInventarioHats(Player jugador,PaintballBattle plugin) {
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
Inventory inv = Bukkit.createInventory(null, 54, ChatColor.translateAlternateColorCodes('&', shop.getString("shopHatsInventoryTitle")));
|
||||
for(String key : shop.getConfigurationSection("hats_items").getKeys(false)) {
|
||||
ItemStack item = UtilidadesItems.crearItem(shop, "hats_items."+key);
|
||||
if(key.equals("coins_info")) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(config.getString("economy_used").equals("vault")) {
|
||||
Economy econ = plugin.getEconomy();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", econ.getBalance(jugador)+"")));
|
||||
}else if(config.getString("economy_used").equals("token_manager")) {
|
||||
TokenManager tokenManager = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", tokenManager.getTokens(jugador).orElse(0)+"")));
|
||||
}
|
||||
else {
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', meta.getDisplayName().replace("%coins%", PaintballAPI.getCoins(jugador)+"")));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}else {
|
||||
if(!key.equals("go_to_menu")) {
|
||||
if(PaintballAPI.hasHat(jugador, key)) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = shop.getStringList("hats_items."+key+".bought_lore");
|
||||
for(int i=0;i<lore.size();i++) {
|
||||
lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i)));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(shop.contains("hats_items."+key+".skull_id")) {
|
||||
String id = shop.getString("hats_items."+key+".skull_id");
|
||||
String textura = shop.getString("hats_items."+key+".skull_texture");
|
||||
item = UtilidadesItems.getCabeza(item, id, textura);
|
||||
}
|
||||
|
||||
if(shop.contains("hats_items."+key+".slot")) {
|
||||
int slot = Integer.valueOf(shop.getString("hats_items."+key+".slot"));
|
||||
if(slot != - 1) {
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
jugador.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventarioHats(InventoryClickEvent event){
|
||||
FileConfiguration shop = plugin.getShop();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', shop.getString("shopHatsInventoryTitle"));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).equals(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
final Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(!event.getCurrentItem().getType().equals(Material.AIR)) {
|
||||
int slot = event.getSlot();
|
||||
for(String key : shop.getConfigurationSection("hats_items").getKeys(false)) {
|
||||
if(key.equals("go_to_menu")) {
|
||||
if(slot == Integer.valueOf(shop.getString("hats_items."+key+".slot"))) {
|
||||
InventarioShop.crearInventarioPrincipal(jugador, plugin);
|
||||
return;
|
||||
}
|
||||
}else if(!key.equals("coins_info")) {
|
||||
if(slot == Integer.valueOf(shop.getString("hats_items."+key+".slot"))) {
|
||||
if(PaintballAPI.hasHat(jugador, key)) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("hatErrorBought")));
|
||||
return;
|
||||
}
|
||||
int cost = Integer.valueOf(shop.getString("hats_items."+key+".cost"));
|
||||
double dinero = 0;
|
||||
if(config.getString("economy_used").equals("vault")) {
|
||||
Economy econ = plugin.getEconomy();
|
||||
dinero = econ.getBalance(jugador);
|
||||
if(dinero < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
econ.withdrawPlayer(jugador, cost);
|
||||
}else if(config.getString("economy_used").equals("token_manager")) {
|
||||
TokenManager tokenManager = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
|
||||
float dineroF = tokenManager.getTokens(jugador).orElse(0);
|
||||
if(dineroF < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
tokenManager.removeTokens(jugador, cost);
|
||||
}
|
||||
else {
|
||||
dinero = PaintballAPI.getCoins(jugador);
|
||||
if(dinero < cost) {
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("buyNoSufficientCoins")));
|
||||
return;
|
||||
}
|
||||
PaintballAPI.removeCoins(jugador, cost);
|
||||
}
|
||||
|
||||
if(MySQL.isEnabled(config)) {
|
||||
MySQL.agregarJugadorHatAsync(plugin, jugador.getUniqueId().toString(), jugador.getName(), key);
|
||||
}else {
|
||||
plugin.registerPlayer(jugador.getUniqueId().toString()+".yml");
|
||||
if(plugin.getJugador(jugador.getName()) == null) {
|
||||
plugin.agregarJugadorDatos(new JugadorDatos(jugador.getName(),jugador.getUniqueId().toString(),0,0,0,0,0,new ArrayList<Perk>(),new ArrayList<Hat>()));
|
||||
}
|
||||
JugadorDatos jDatos = plugin.getJugador(jugador.getName());
|
||||
jDatos.agregarHat(key);
|
||||
}
|
||||
jugador.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("hatBought").replace("%name%", shop.getString("hats_items."+key+".name"))));
|
||||
String[] separadosSound = config.getString("shopUnlockSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separadosSound[0]);
|
||||
jugador.playSound(jugador.getLocation(), sound, Float.valueOf(separadosSound[1]), Float.valueOf(separadosSound[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separadosSound[0]+" &7is not valid."));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
InventarioShop.crearInventarioHats(jugador, plugin);
|
||||
}
|
||||
}, 5L);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
693
src/main/java/pb/ajneb97/managers/PartidaListener.java
Normal file
693
src/main/java/pb/ajneb97/managers/PartidaListener.java
Normal file
@@ -0,0 +1,693 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Egg;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.event.EventHandler;
|
||||
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.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.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.Equipo;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Killstreak;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.utils.UtilidadesItems;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
import pb.ajneb97.utils.ValueOfPatch;
|
||||
|
||||
public class PartidaListener implements Listener{
|
||||
|
||||
PaintballBattle plugin;
|
||||
public PartidaListener(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alSalir(PlayerQuitEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
PartidaManager.jugadorSale(partida, jugador,false,plugin,false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickearItemSalir(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(event.getItem() != null) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "leave_item");
|
||||
if(event.getItem().isSimilar(item)) {
|
||||
event.setCancelled(true);
|
||||
PartidaManager.jugadorSale(partida, jugador,false,plugin,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickearItemHats(PlayerInteractEvent event) {
|
||||
final Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(event.getItem() != null) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_item");
|
||||
if(event.getItem().isSimilar(item)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
jugador.updateInventory();
|
||||
jugador.getEquipment().setHelmet(null);
|
||||
InventarioHats.crearInventario(jugador, plugin);
|
||||
}
|
||||
},2L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickearItemPlayAgain(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(event.getItem() != null) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "play_again_item");
|
||||
if(event.getItem().isSimilar(item)) {
|
||||
event.setCancelled(true);
|
||||
Partida partidaNueva = PartidaManager.getPartidaDisponible(plugin);
|
||||
if(partidaNueva == null) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("noArenasAvailable")));
|
||||
}else {
|
||||
PartidaManager.jugadorSale(partida, jugador, true, plugin, false);
|
||||
PartidaManager.jugadorEntra(partidaNueva, jugador, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickearItemSelectorEquipo(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(event.getItem() != null) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
if(config.getString("choose_team_system").equals("true")) {
|
||||
ItemStack team1 = UtilidadesItems.crearItem(config, "teams."+partida.getTeam1().getTipo());
|
||||
ItemMeta meta = team1.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.getString("teamChoose").replace("%team%", config.getString("teams."+partida.getTeam1().getTipo()+".name"))));
|
||||
team1.setItemMeta(meta);
|
||||
ItemStack team2 = UtilidadesItems.crearItem(config, "teams."+partida.getTeam2().getTipo());
|
||||
meta = team2.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.getString("teamChoose").replace("%team%", config.getString("teams."+partida.getTeam2().getTipo()+".name"))));
|
||||
team2.setItemMeta(meta);
|
||||
//String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(event.getItem().isSimilar(team1)) {
|
||||
event.setCancelled(true);
|
||||
jugador.updateInventory();
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
if(j.getPreferenciaTeam() != null && j.getPreferenciaTeam().equals(partida.getTeam1().getTipo())) {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("errorTeamAlreadySelected")));
|
||||
return;
|
||||
}
|
||||
if(partida.puedeSeleccionarEquipo(partida.getTeam1().getTipo())) {
|
||||
j.setPreferenciaTeam(partida.getTeam1().getTipo());
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("teamSelected").replace("%team%", config.getString("teams."+partida.getTeam1().getTipo()+".name"))));
|
||||
}else {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("errorTeamSelected")));
|
||||
}
|
||||
|
||||
}else if(event.getItem().isSimilar(team2)) {
|
||||
event.setCancelled(true);
|
||||
jugador.updateInventory();
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
if(j.getPreferenciaTeam() != null && j.getPreferenciaTeam().equals(partida.getTeam2().getTipo())) {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("errorTeamAlreadySelected")));
|
||||
return;
|
||||
}
|
||||
if(partida.puedeSeleccionarEquipo(partida.getTeam2().getTipo())) {
|
||||
j.setPreferenciaTeam(partida.getTeam2().getTipo());
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("teamSelected").replace("%team%", config.getString("teams."+partida.getTeam2().getTipo()+".name"))));
|
||||
}else {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("errorTeamSelected")));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickearItemKillstreak(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if(event.getItem() != null && event.getItem().hasItemMeta()) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(jugador.getInventory().getHeldItemSlot() == 8 && (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
|
||||
if(config.getString("killstreaks_item_enabled").equals("true")) {
|
||||
if(partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
event.setCancelled(true);
|
||||
Inventory inv = Bukkit.createInventory(null, 18, ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_inventory_title")));
|
||||
jugador.openInventory(inv);
|
||||
InventarioKillstreaks i = new InventarioKillstreaks(plugin);
|
||||
i.actualizarInventario(jugador, partida);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alShiftear(PlayerToggleSneakEvent event) {
|
||||
if(event.isSneaking()) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
String hat = j.getSelectedHat();
|
||||
if(hat.equals("guardian_hat") || hat.equals("jump_hat")) {
|
||||
if(!j.isEfectoHatEnCooldown()) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
int duration = Integer.valueOf(config.getString("hats_items."+hat+".duration"));
|
||||
int cooldown = Integer.valueOf(config.getString("hats_items."+hat+".cooldown"));
|
||||
if(hat.equals("jump_hat")) {
|
||||
jugador.addPotionEffect(new PotionEffect(PotionEffectType.JUMP_BOOST,20*duration,1,false,false));
|
||||
}else if(hat.equals("guardian_hat")) {
|
||||
jugador.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS,20*duration,2,false,false));
|
||||
CooldownHats c = new CooldownHats(plugin);
|
||||
c.durationHat(j, partida, duration);
|
||||
}
|
||||
j.setEfectoHatActivado(true);
|
||||
j.setEfectoHatEnCooldown(true);
|
||||
j.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("hatAbilityActivated")));
|
||||
String[] separados = config.getString("hatAbilityActivatedSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
j.getJugador().playSound(j.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
CooldownHats c = new CooldownHats(plugin);
|
||||
c.cooldownHat(j, partida, cooldown);
|
||||
}else {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("hatCooldownError").replace("%time%", j.getTiempoEfectoHat()+"")));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alUsarComando(PlayerCommandPreprocessEvent event) {
|
||||
String comando = event.getMessage().toLowerCase();
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null && !jugador.isOp() && !jugador.hasPermission("paintball.admin")) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
List<String> comandos = config.getStringList("commands_whitelist");
|
||||
for(int i=0;i<comandos.size();i++) {
|
||||
if(comando.toLowerCase().startsWith(comandos.get(i))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void romperBloques(BlockBreakEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void dropearItem(PlayerDropItemEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void interactuarInventario(InventoryClickEvent event){
|
||||
Player jugador = (Player) event.getWhoClicked();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if((event.getInventory().getType().equals(InventoryType.PLAYER) ||
|
||||
event.getInventory().getType().equals(InventoryType.CRAFTING))
|
||||
&& event.getSlotType() != null && event.getCurrentItem() != null){
|
||||
if(!event.getCurrentItem().getType().equals(Material.AIR) &&
|
||||
!event.getCurrentItem().getType().name().contains("SNOW")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ponerBloques(BlockPlaceEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void caerVacio(EntityDamageEvent event) {
|
||||
Entity entidad = event.getEntity();
|
||||
if(entidad instanceof Player) {
|
||||
Player jugador = (Player) entidad;
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null && partida.estaIniciada()) {
|
||||
if(event.getCause().equals(DamageCause.VOID)) {
|
||||
Equipo equipo = partida.getEquipoJugador(jugador.getName());
|
||||
if(equipo != null) {
|
||||
jugador.teleport(equipo.getSpawn());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void craftear(InventoryClickEvent event) {
|
||||
Player jugador = (Player) event.getWhoClicked();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getClickedInventory() != null) {
|
||||
if(event.getClickedInventory().getType().equals(InventoryType.CRAFTING)
|
||||
&& event.getSlot() == 0 && event.getSlotType() != null && event.getSlotType().equals(SlotType.RESULT)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void romperGranjas(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
if(event.getClickedBlock() != null) {
|
||||
String name = event.getClickedBlock().getType().name();
|
||||
if(event.getAction() == Action.PHYSICAL && (name.equals("SOIL") || name.equals("FARMLAND"))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alDañar(EntityDamageEvent event) {
|
||||
Entity entidad = event.getEntity();
|
||||
if(entidad instanceof Player) {
|
||||
Player jugador = (Player) entidad;
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void nivelDeComida(FoodLevelChangeEvent event) {
|
||||
Player jugador = (Player) event.getEntity();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alChatear(AsyncPlayerChatEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
if(!event.isCancelled()) {
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(config.getString("arena_chat_enabled").equals("false")) {
|
||||
return;
|
||||
}
|
||||
if(partida != null) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
String message = event.getMessage();
|
||||
event.setCancelled(true);
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
if(partida.estaIniciada()) {
|
||||
String teamName = config.getString("teams."+partida.getEquipoJugador(jugador.getName()).getTipo()+".name");
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
String msg = ChatColor.translateAlternateColorCodes('&', config.getString("arena_chat_format").replace("%player%", jugador.getName()).replace("%team%", teamName));
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
msg = PlaceholderAPI.setPlaceholders(j.getJugador(), msg.replace("%message%", message));
|
||||
}else {
|
||||
msg = msg.replace("%message%", message);
|
||||
}
|
||||
j.getJugador().sendMessage(msg);
|
||||
}
|
||||
}else {
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
String msg = ChatColor.translateAlternateColorCodes('&', config.getString("arena_chat_format").replace("%player%", jugador.getName()).replace("%team%", messages.getString("teamInformationNone")));
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
msg = PlaceholderAPI.setPlaceholders(j.getJugador(), msg.replace("%message%", message));
|
||||
}else {
|
||||
msg = msg.replace("%message%", message);
|
||||
}
|
||||
j.getJugador().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
||||
if(plugin.getPartidaJugador(p.getName()) != null) {
|
||||
event.getRecipients().remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void impactoBolaDeNieve(EntityDamageByEntityEvent event) {
|
||||
Entity e = event.getDamager();
|
||||
if(e instanceof Projectile && (e.getType().equals(EntityType.SNOWBALL) || e.getType().equals(EntityType.EGG))) {
|
||||
Projectile proyectil = (Projectile) e;
|
||||
ProjectileSource shooter = proyectil.getShooter();
|
||||
Entity dañado = event.getEntity();
|
||||
if(dañado instanceof Player && shooter instanceof Player) {
|
||||
Player jugadorDañado = (Player) dañado;
|
||||
Player jugadorAtacante = (Player) shooter;
|
||||
Partida partida = plugin.getPartidaJugador(jugadorAtacante.getName());
|
||||
if(partida != null) {
|
||||
if(partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
JugadorPaintball j = partida.getJugador(jugadorAtacante.getName());
|
||||
JugadorPaintball j2 = partida.getJugador(jugadorDañado.getName());
|
||||
|
||||
if(j2 == null || j2.getKillstreak("fury") != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PartidaManager.muereJugador(partida, j, j2, plugin, false, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickInventarioKillstreak(InventoryClickEvent event){
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
String pathInventory = ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_inventory_title"));
|
||||
String pathInventoryM = ChatColor.stripColor(pathInventory);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
//String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
if(ChatColor.stripColor(event.getView().getTitle()).contains(pathInventoryM)){
|
||||
if(event.getCurrentItem() == null){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if((event.getSlotType() == null)){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}else{
|
||||
Player jugador = (Player) event.getWhoClicked();
|
||||
event.setCancelled(true);
|
||||
if(event.getClickedInventory().equals(jugador.getOpenInventory().getTopInventory())) {
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
int slot = event.getSlot();
|
||||
for(String key : config.getConfigurationSection("killstreaks_items").getKeys(false)) {
|
||||
if(slot == Integer.valueOf(config.getString("killstreaks_items."+key+".slot"))) {
|
||||
if(j.getKillstreak(key) != null) {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakAlreadyActivated")));
|
||||
return;
|
||||
}
|
||||
if(config.contains("killstreaks_items."+key+".permission")) {
|
||||
if(!jugador.hasPermission(config.getString("killstreaks_items."+key+".permission"))) {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_items."+key+".permissionError")));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int cost = Integer.valueOf(config.getString("killstreaks_items."+key+".cost"));
|
||||
if(j.getCoins() >= cost) {
|
||||
if(key.equalsIgnoreCase("nuke") && partida.isEnNuke()) {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("nukeError")));
|
||||
return;
|
||||
}
|
||||
|
||||
j.disminuirCoins(cost);
|
||||
String name = ChatColor.translateAlternateColorCodes('&', config.getString("killstreaks_items."+key+".name"));
|
||||
String teamName = config.getString("teams."+partida.getEquipoJugador(jugador.getName()).getTipo()+".name");
|
||||
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
if(!player.getJugador().getName().equals(jugador.getName())) {
|
||||
String msg = ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakActivatedPlayer").replace("%player%", jugador.getName()).replace("%team%", teamName)
|
||||
.replace("%killstreak%", name));
|
||||
player.getJugador().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("killstreakActivated").replace("%killstreak%", name)));
|
||||
|
||||
|
||||
if(key.equalsIgnoreCase("strong_arm") || key.equalsIgnoreCase("triple_shoot") || key.equalsIgnoreCase("fury")) {
|
||||
int duration = Integer.valueOf(config.getString("killstreaks_items."+key+".duration"));
|
||||
if(j.getSelectedHat().equals("time_hat")) {
|
||||
duration = duration+5;
|
||||
}
|
||||
Killstreak k = new Killstreak(key,duration);
|
||||
j.agregarKillstreak(k);
|
||||
CooldownKillstreaks cooldown = new CooldownKillstreaks(plugin);
|
||||
cooldown.cooldownKillstreak(j, partida, key, duration);
|
||||
}else {
|
||||
PartidaManager.killstreakInstantanea(key, jugador, partida, plugin);
|
||||
}
|
||||
|
||||
String[] separados = config.getString("killstreaks_items."+key+".activateSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
if(separados.length >= 4) {
|
||||
if(separados[3].equalsIgnoreCase("global")) {
|
||||
for(JugadorPaintball player : partida.getJugadores()) {
|
||||
player.getJugador().playSound(player.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.playSound(jugador.getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}
|
||||
}else {
|
||||
jugador.playSound(jugador.getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}
|
||||
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
|
||||
UtilidadesItems.crearItemKillstreaks(j, config);
|
||||
}else {
|
||||
jugador.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("noSufficientCoins")));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preLanzarSnowball(PlayerInteractEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
ItemStack item = event.getItem();
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
|
||||
if(item != null && (item.getType().name().contains("SNOW") || item.getType().name().contains("EGG"))) {
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
JugadorPaintball player = partida.getJugador(jugador.getName());
|
||||
|
||||
if(player.getKillstreak("fury") == null) {
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
if(player.getSelectedHat().equals("chicken_hat")) {
|
||||
jugador.getInventory().removeItem(new ItemStack(Material.EGG,1));
|
||||
}else {
|
||||
jugador.getInventory().removeItem(new ItemStack(Material.SNOWBALL,1));
|
||||
}
|
||||
}else {
|
||||
if(player.getSelectedHat().equals("chicken_hat")) {
|
||||
jugador.getInventory().removeItem(new ItemStack(Material.EGG,1));
|
||||
}else {
|
||||
jugador.getInventory().removeItem(new ItemStack(Material.valueOf("SNOW_BALL"),1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
String[] separados = config.getString("snowballShootSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugador.playSound(jugador.getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
|
||||
if(player.getSelectedHat().equals("chicken_hat")) {
|
||||
jugador.launchProjectile(Egg.class, jugador.getLocation().getDirection());
|
||||
}else {
|
||||
jugador.launchProjectile(Snowball.class, jugador.getLocation().getDirection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Killstreak k = player.getKillstreak("triple_shoot");
|
||||
if(k != null) {
|
||||
Vector direccion = jugador.getLocation().getDirection().clone();
|
||||
double anguloEntre = Math.toRadians(10);
|
||||
|
||||
double xFinal = direccion.getX()*Math.cos(anguloEntre)-direccion.getZ()*Math.sin(anguloEntre);
|
||||
double zFinal = direccion.getX()*Math.sin(anguloEntre)+direccion.getZ()*Math.cos(anguloEntre);
|
||||
|
||||
|
||||
direccion = new Vector(xFinal,direccion.getY(),zFinal);
|
||||
|
||||
if(player.getSelectedHat().equals("chicken_hat")) {
|
||||
jugador.launchProjectile(Egg.class, direccion);
|
||||
}else {
|
||||
jugador.launchProjectile(Snowball.class, direccion);
|
||||
}
|
||||
|
||||
direccion = jugador.getLocation().getDirection().clone();
|
||||
|
||||
anguloEntre = Math.toRadians(-10);
|
||||
|
||||
xFinal = direccion.getX()*Math.cos(anguloEntre)-direccion.getZ()*Math.sin(anguloEntre);
|
||||
zFinal = direccion.getX()*Math.sin(anguloEntre)+direccion.getZ()*Math.cos(anguloEntre);
|
||||
|
||||
|
||||
direccion = new Vector(xFinal,direccion.getY(),zFinal);
|
||||
|
||||
if(player.getSelectedHat().equals("chicken_hat")) {
|
||||
jugador.launchProjectile(Egg.class, direccion);
|
||||
}else {
|
||||
jugador.launchProjectile(Snowball.class, direccion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void lanzarSnowball(ProjectileLaunchEvent event) {
|
||||
Projectile p = event.getEntity();
|
||||
ProjectileSource source = p.getShooter();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if((p.getType().equals(EntityType.SNOWBALL) || p.getType().equals(EntityType.EGG)) && source instanceof Player) {
|
||||
Player jugador = (Player) source;
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
p.setMetadata("PaintballBattle", new FixedMetadataValue(plugin,"proyectil"));
|
||||
p.setVelocity(p.getVelocity().multiply(1.25));
|
||||
JugadorPaintball player = partida.getJugador(jugador.getName());
|
||||
Killstreak k = player.getKillstreak("strong_arm");
|
||||
if(k != null) {
|
||||
p.setVelocity(p.getVelocity().multiply(2));
|
||||
}
|
||||
String particle = config.getString("snowball_particle");
|
||||
if(!particle.equals("none")) {
|
||||
if(!player.getSelectedHat().equals("chicken_hat")) {
|
||||
CooldownSnowballParticle c = new CooldownSnowballParticle(plugin,p,particle);
|
||||
c.cooldown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void tirarHuevo(PlayerEggThrowEvent event) {
|
||||
Egg egg = event.getEgg();
|
||||
if(egg.hasMetadata("PaintballBattle")) {
|
||||
event.setHatching(false);
|
||||
}
|
||||
}
|
||||
}
|
26
src/main/java/pb/ajneb97/managers/PartidaListenerNew.java
Normal file
26
src/main/java/pb/ajneb97/managers/PartidaListenerNew.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
|
||||
public class PartidaListenerNew implements Listener{
|
||||
|
||||
PaintballBattle plugin;
|
||||
public PartidaListenerNew(PaintballBattle plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void alCambiarDeMano(PlayerSwapHandItemsEvent event) {
|
||||
Player jugador = event.getPlayer();
|
||||
Partida partida = plugin.getPartidaJugador(jugador.getName());
|
||||
if(partida != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
923
src/main/java/pb/ajneb97/managers/PartidaManager.java
Normal file
923
src/main/java/pb/ajneb97/managers/PartidaManager.java
Normal file
@@ -0,0 +1,923 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
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 org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.api.Hat;
|
||||
import pb.ajneb97.api.PaintballAPI;
|
||||
import pb.ajneb97.api.Perk;
|
||||
import pb.ajneb97.database.JugadorDatos;
|
||||
import pb.ajneb97.database.MySQL;
|
||||
import pb.ajneb97.juego.Equipo;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.lib.titleapi.TitleAPI;
|
||||
import pb.ajneb97.utils.UtilidadesItems;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
import pb.ajneb97.utils.ValueOfPatch;
|
||||
|
||||
public class PartidaManager {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void jugadorEntra(Partida partida,Player jugador,PaintballBattle plugin) {
|
||||
JugadorPaintball jugadorPaintball = new JugadorPaintball(jugador);
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
partida.agregarJugador(jugadorPaintball);
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("playerJoin").replace("%player%", jugador.getName())
|
||||
.replace("%current_players%", partida.getCantidadActualJugadores()+"").replace("%max_players%", partida.getCantidadMaximaJugadores()+"")));
|
||||
}
|
||||
|
||||
jugador.getInventory().clear();
|
||||
jugador.getEquipment().clear();
|
||||
jugador.getEquipment().setArmorContents(null);
|
||||
jugador.updateInventory();
|
||||
|
||||
jugador.setGameMode(GameMode.SURVIVAL);
|
||||
jugador.setExp(0);
|
||||
jugador.setLevel(0);
|
||||
jugador.setFoodLevel(20);
|
||||
jugador.setMaxHealth(20);
|
||||
jugador.setHealth(20);
|
||||
jugador.setFlying(false);
|
||||
jugador.setAllowFlight(false);
|
||||
for(PotionEffect p : jugador.getActivePotionEffects()) {
|
||||
jugador.removePotionEffect(p.getType());
|
||||
}
|
||||
|
||||
jugador.teleport(partida.getLobby());
|
||||
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(config.getString("leave_item_enabled").equals("true")) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "leave_item");
|
||||
jugador.getInventory().setItem(8, item);
|
||||
}
|
||||
if(config.getString("hats_item_enabled").equals("true")) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_item");
|
||||
jugador.getInventory().setItem(7, item);
|
||||
}
|
||||
if(config.getString("choose_team_system").equals("true")) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "teams."+partida.getTeam1().getTipo());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.getString("teamChoose").replace("%team%", config.getString("teams."+partida.getTeam1().getTipo()+".name"))));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setItem(0, item);
|
||||
item = UtilidadesItems.crearItem(config, "teams."+partida.getTeam2().getTipo());
|
||||
meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.getString("teamChoose").replace("%team%", config.getString("teams."+partida.getTeam2().getTipo()+".name"))));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setItem(1, item);
|
||||
}
|
||||
|
||||
if(partida.getCantidadActualJugadores() >= partida.getCantidadMinimaJugadores()
|
||||
&& partida.getEstado().equals(EstadoPartida.ESPERANDO)) {
|
||||
cooldownIniciarPartida(partida,plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void jugadorSale(Partida partida,Player jugador,boolean finalizaPartida,
|
||||
PaintballBattle plugin,boolean cerrandoServer) {
|
||||
JugadorPaintball jugadorPaintball = partida.getJugador(jugador.getName());
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
ItemStack[] inventarioGuardado = jugadorPaintball.getGuardados().getInventarioGuardado();
|
||||
ItemStack[] equipamientoGuardado = jugadorPaintball.getGuardados().getEquipamientoGuardado();
|
||||
GameMode gamemodeGuardado = jugadorPaintball.getGuardados().getGamemodeGuardado();
|
||||
float xpGuardada = jugadorPaintball.getGuardados().getXPGuardada();
|
||||
int levelGuardado = jugadorPaintball.getGuardados().getLevelGuardado();
|
||||
int hambreGuardada = jugadorPaintball.getGuardados().getHambreGuardada();
|
||||
double vidaGuardada = jugadorPaintball.getGuardados().getVidaGuardada();
|
||||
double maxVidaGuardada = jugadorPaintball.getGuardados().getMaxVidaGuardada();
|
||||
boolean allowFligth = jugadorPaintball.getGuardados().isAllowFlight();
|
||||
boolean isFlying = jugadorPaintball.getGuardados().isFlying();
|
||||
|
||||
partida.removerJugador(jugador.getName());
|
||||
|
||||
if(!finalizaPartida) {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("playerLeave").replace("%player%", jugador.getName())
|
||||
.replace("%current_players%", partida.getCantidadActualJugadores()+"").replace("%max_players%", partida.getCantidadMaximaJugadores()+"")));
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
double x = Double.valueOf(config.getString("MainLobby.x"));
|
||||
double y = Double.valueOf(config.getString("MainLobby.y"));
|
||||
double z = Double.valueOf(config.getString("MainLobby.z"));
|
||||
String world = config.getString("MainLobby.world");
|
||||
float yaw = Float.valueOf(config.getString("MainLobby.yaw"));
|
||||
float pitch = Float.valueOf(config.getString("MainLobby.pitch"));
|
||||
Location mainLobby = new Location(Bukkit.getWorld(world),x,y,z,yaw,pitch);
|
||||
jugador.teleport(mainLobby);
|
||||
|
||||
jugador.getInventory().setContents(inventarioGuardado);
|
||||
jugador.getEquipment().setArmorContents(equipamientoGuardado);
|
||||
jugador.setGameMode(gamemodeGuardado);
|
||||
jugador.setLevel(levelGuardado);
|
||||
jugador.setExp(xpGuardada);
|
||||
jugador.setFoodLevel(hambreGuardada);
|
||||
jugador.setMaxHealth(maxVidaGuardada);
|
||||
jugador.setHealth(vidaGuardada);
|
||||
for(PotionEffect p : jugador.getActivePotionEffects()) {
|
||||
jugador.removePotionEffect(p.getType());
|
||||
}
|
||||
jugador.updateInventory();
|
||||
|
||||
jugador.setAllowFlight(allowFligth);
|
||||
jugador.setFlying(isFlying);
|
||||
|
||||
if(!cerrandoServer) {
|
||||
if(partida.getCantidadActualJugadores() < partida.getCantidadMinimaJugadores()
|
||||
&& partida.getEstado().equals(EstadoPartida.COMENZANDO)){
|
||||
partida.setEstado(EstadoPartida.ESPERANDO);
|
||||
}else if(partida.getCantidadActualJugadores() <= 1 && (partida.getEstado().equals(EstadoPartida.JUGANDO))) {
|
||||
//fase finalizacion
|
||||
PartidaManager.iniciarFaseFinalizacion(partida, plugin);
|
||||
}else if((partida.getTeam1().getCantidadJugadores() == 0 || partida.getTeam2().getCantidadJugadores() == 0) && partida.getEstado().equals(EstadoPartida.JUGANDO)) {
|
||||
//fase finalizacion
|
||||
PartidaManager.iniciarFaseFinalizacion(partida, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cooldownIniciarPartida(Partida partida,PaintballBattle plugin) {
|
||||
partida.setEstado(EstadoPartida.COMENZANDO);
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
int time = Integer.valueOf(config.getString("arena_starting_cooldown"));
|
||||
|
||||
CooldownManager cooldown = new CooldownManager(plugin);
|
||||
cooldown.cooldownComenzarJuego(partida,time);
|
||||
|
||||
String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
|
||||
if(config.getString("broadcast_starting_arena.enabled").equals("true")) {
|
||||
List<String> worlds = config.getStringList("broadcast_starting_arena.worlds");
|
||||
for(String world : worlds) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(player.getWorld().getName().equals(world)) {
|
||||
player.sendMessage(prefix+ChatColor.translateAlternateColorCodes('&', messages.getString("arenaStartingBroadcast")
|
||||
.replace("%arena%", partida.getNombre())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void iniciarPartida(Partida partida,PaintballBattle plugin) {
|
||||
|
||||
partida.setEstado(EstadoPartida.JUGANDO);
|
||||
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
//String prefix = ChatColor.translateAlternateColorCodes('&', messages.getString("prefix"))+" ";
|
||||
// Scoreboards für alle Spieler anzeigen
|
||||
|
||||
|
||||
if(plugin.getConfig().getString("choose_team_system").equals("true")) {
|
||||
setTeams(partida);
|
||||
}else {
|
||||
setTeamsAleatorios(partida);
|
||||
}
|
||||
|
||||
darItems(partida,plugin.getConfig(),plugin.getShop(),plugin.getMessages());
|
||||
teletransportarJugadores(partida);
|
||||
setVidas(partida,plugin.getShop());
|
||||
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
String[] separados = config.getString("startGameSound").split(";");
|
||||
Sound sound = null;
|
||||
float volume = 0;
|
||||
float pitch = 0;
|
||||
try {
|
||||
sound = ValueOfPatch.valueOf(separados[0]);
|
||||
volume = Float.valueOf(separados[1]);
|
||||
pitch = Float.valueOf(separados[2]);
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
sound = null;
|
||||
}
|
||||
for(int i=0;i<jugadores.size();i++) {
|
||||
String nombreTeam = partida.getEquipoJugador(jugadores.get(i).getJugador().getName()).getTipo();
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("gameStarted")));
|
||||
jugadores.get(i).getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("teamInformation").replace("%team%", plugin.getConfig().getString("teams."+nombreTeam+".name"))));
|
||||
jugadores.get(i).getJugador().closeInventory();
|
||||
if(sound != null) {
|
||||
jugadores.get(i).getJugador().playSound(jugadores.get(i).getJugador().getLocation(), sound, volume, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
CooldownManager cooldown = new CooldownManager(plugin);
|
||||
cooldown.cooldownJuego(partida);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void setVidas(Partida partida,FileConfiguration shop) {
|
||||
partida.getTeam1().setVidas(partida.getVidasIniciales());
|
||||
partida.getTeam2().setVidas(partida.getVidasIniciales());
|
||||
|
||||
ArrayList<JugadorPaintball> jugadoresTeam1 = partida.getTeam1().getJugadores();
|
||||
for(JugadorPaintball j : jugadoresTeam1) {
|
||||
//comprobar perk extralives
|
||||
int nivelExtraLives = PaintballAPI.getPerkLevel(j.getJugador(), "extra_lives");
|
||||
if(nivelExtraLives != 0) {
|
||||
String linea = shop.getStringList("perks_upgrades.extra_lives").get(nivelExtraLives-1);
|
||||
String[] sep = linea.split(";");
|
||||
int cantidad = Integer.valueOf(sep[0]);
|
||||
partida.getTeam1().aumentarVidas(cantidad);
|
||||
}
|
||||
}
|
||||
ArrayList<JugadorPaintball> jugadoresTeam2 = partida.getTeam2().getJugadores();
|
||||
for(JugadorPaintball j : jugadoresTeam2) {
|
||||
//comprobar perk extralives
|
||||
int nivelExtraLives = PaintballAPI.getPerkLevel(j.getJugador(), "extra_lives");
|
||||
if(nivelExtraLives != 0) {
|
||||
String linea = shop.getStringList("perks_upgrades.extra_lives").get(nivelExtraLives-1);
|
||||
String[] sep = linea.split(";");
|
||||
int cantidad = Integer.valueOf(sep[0]);
|
||||
partida.getTeam2().aumentarVidas(cantidad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void killstreakInstantanea(String key,Player jugador,Partida partida,PaintballBattle plugin) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if(key.equalsIgnoreCase("3_lives")) {
|
||||
Equipo equipo = partida.getEquipoJugador(jugador.getName());
|
||||
equipo.aumentarVidas(3);
|
||||
}else if(key.equalsIgnoreCase("teleport")) {
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
if(j.getDeathLocation() != null) {
|
||||
j.getJugador().teleport(j.getDeathLocation());
|
||||
}else {
|
||||
Equipo equipo = partida.getEquipoJugador(jugador.getName());
|
||||
j.getJugador().teleport(equipo.getSpawn());
|
||||
}
|
||||
}else if(key.equalsIgnoreCase("more_snowballs")) {
|
||||
JugadorPaintball j = partida.getJugador(jugador.getName());
|
||||
int snowballs = Integer.valueOf(config.getString("killstreaks_items."+key+".snowballs"));
|
||||
ItemStack item = null;
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
if(j.getSelectedHat().equals("chicken_hat")) {
|
||||
item = new ItemStack(Material.EGG,1);
|
||||
}else {
|
||||
item = new ItemStack(Material.SNOWBALL,1);
|
||||
}
|
||||
|
||||
}else {
|
||||
if(j.getSelectedHat().equals("chicken_hat")) {
|
||||
item = new ItemStack(Material.EGG,1);
|
||||
}else {
|
||||
item = new ItemStack(Material.valueOf("SNOW_BALL"),1);
|
||||
}
|
||||
|
||||
}
|
||||
for(int i=0;i<snowballs;i++) {
|
||||
jugador.getInventory().addItem(item);
|
||||
}
|
||||
}else if(key.equalsIgnoreCase("lightning")) {
|
||||
JugadorPaintball jugadorAtacante = partida.getJugador(jugador.getName());
|
||||
int radio = Integer.valueOf(config.getString("killstreaks_items."+key+".radius"));
|
||||
Collection<Entity> entidades = jugador.getWorld().getNearbyEntities(jugador.getLocation(), radio, radio, radio);
|
||||
for(Entity e : entidades) {
|
||||
if(e != null && e.getType().equals(EntityType.PLAYER)) {
|
||||
Player player = (Player) e;
|
||||
JugadorPaintball jugadorDañado = partida.getJugador(player.getName());
|
||||
if(jugadorDañado != null) {
|
||||
PartidaManager.muereJugador(partida, jugadorAtacante, jugadorDañado, plugin, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(key.equalsIgnoreCase("nuke")) {
|
||||
partida.setEnNuke(true);
|
||||
JugadorPaintball jugadorAtacante = partida.getJugador(jugador.getName());
|
||||
CooldownKillstreaks c = new CooldownKillstreaks(plugin);
|
||||
String[] separados1 = config.getString("killstreaks_items."+key+".activateSound").split(";");
|
||||
String[] separados2 = config.getString("killstreaks_items."+key+".finalSound").split(";");
|
||||
c.cooldownNuke(jugadorAtacante, partida, separados1, separados2);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void setTeamsAleatorios(Partida partida) {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
ArrayList<JugadorPaintball> jugadoresCopia = (ArrayList<JugadorPaintball>) partida.getJugadores().clone();
|
||||
//Si son 4 se seleccionan 2, Si son 5 tambien 2, Si son 6, 3, Si son 7, tambien 3
|
||||
Random r = new Random();
|
||||
int num = jugadores.size()/2;
|
||||
for(int i=0;i<num;i++) {
|
||||
int pos = r.nextInt(jugadoresCopia.size());
|
||||
JugadorPaintball jugadorSelect = jugadoresCopia.get(pos);
|
||||
jugadoresCopia.remove(pos);
|
||||
|
||||
partida.repartirJugadorTeam2(jugadorSelect);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setTeams(Partida partida) {
|
||||
//Falta comprobar lo siguiente:
|
||||
//Si 2 usuarios seleccionan team y uno se va, los 2 usuarios estaran en el mismo team al
|
||||
//iniciar la partida y seran solo ellos 2.
|
||||
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
partida.getEquipoJugador(j.getJugador().getName()).removerJugador(j.getJugador().getName());
|
||||
String preferenciaTeam = j.getPreferenciaTeam();
|
||||
if(preferenciaTeam == null) {
|
||||
if(partida.puedeSeleccionarEquipo(partida.getTeam1().getTipo())) {
|
||||
j.setPreferenciaTeam(partida.getTeam1().getTipo());
|
||||
}else {
|
||||
j.setPreferenciaTeam(partida.getTeam2().getTipo());
|
||||
}
|
||||
}
|
||||
preferenciaTeam = j.getPreferenciaTeam();
|
||||
if(preferenciaTeam.equals(partida.getTeam2().getTipo())) {
|
||||
partida.getTeam2().agregarJugador(j);
|
||||
}else {
|
||||
partida.getTeam1().agregarJugador(j);
|
||||
}
|
||||
}
|
||||
|
||||
//Balanceo final
|
||||
Equipo equipo1 = partida.getTeam1();
|
||||
Equipo equipo2 = partida.getTeam2();
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
Equipo equipo = partida.getEquipoJugador(j.getJugador().getName());
|
||||
if(equipo1.getCantidadJugadores() > equipo2.getCantidadJugadores()+1) {
|
||||
if(equipo.getTipo().equals(equipo1.getTipo())) {
|
||||
//Mover al jugador del equipo1 al equipo2
|
||||
equipo1.removerJugador(j.getJugador().getName());
|
||||
equipo2.agregarJugador(j);
|
||||
}
|
||||
}else if(equipo2.getCantidadJugadores() > equipo1.getCantidadJugadores()+1) {
|
||||
if(equipo.getTipo().equals(equipo2.getTipo())) {
|
||||
//Mover al jugador del equipo2 al equipo1
|
||||
equipo2.removerJugador(j.getJugador().getName());
|
||||
equipo1.agregarJugador(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void darItems(Partida partida,FileConfiguration config,FileConfiguration shop,FileConfiguration messages) {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
Player p = j.getJugador();
|
||||
p.getInventory().setItem(8, null);
|
||||
|
||||
Equipo equipo = partida.getEquipoJugador(p.getName());
|
||||
if(config.contains("teams."+equipo.getTipo())) {
|
||||
darEquipamientoJugador(p,Integer.valueOf(config.getString("teams."+equipo.getTipo()+".color")));
|
||||
}else {
|
||||
darEquipamientoJugador(p,0);
|
||||
}
|
||||
//comprobar perk initial killcoins
|
||||
int nivelInitialKillcoins = PaintballAPI.getPerkLevel(j.getJugador(), "initial_killcoins");
|
||||
if(nivelInitialKillcoins != 0) {
|
||||
String linea = shop.getStringList("perks_upgrades.initial_killcoins").get(nivelInitialKillcoins-1);
|
||||
String[] sep = linea.split(";");
|
||||
int cantidad = Integer.valueOf(sep[0]);
|
||||
j.agregarCoins(cantidad);
|
||||
}
|
||||
UtilidadesItems.crearItemKillstreaks(j,config);
|
||||
ponerHat(partida,j,config,messages);
|
||||
setBolasDeNieve(j,config);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void ponerHat(Partida partida,JugadorPaintball jugador,FileConfiguration config,FileConfiguration messages) {
|
||||
ArrayList<Hat> hats = PaintballAPI.getHats(jugador.getJugador());
|
||||
for(Hat h : hats) {
|
||||
if(h.isSelected()) {
|
||||
jugador.setSelectedHat(h.getName());
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "hats_items."+h.getName());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(null);
|
||||
item.setItemMeta(meta);
|
||||
if(config.contains("hats_items."+h.getName()+".skull_id")) {
|
||||
String id = config.getString("hats_items."+h.getName()+".skull_id");
|
||||
String textura = config.getString("hats_items."+h.getName()+".skull_texture");
|
||||
item = UtilidadesItems.getCabeza(item, id, textura);
|
||||
}
|
||||
jugador.getJugador().getEquipment().setHelmet(item);
|
||||
|
||||
if(h.getName().equals("speed_hat")) {
|
||||
jugador.getJugador().addPotionEffect(new PotionEffect(PotionEffectType.SPEED,9999999,0,false,false));
|
||||
}else if(h.getName().equals("present_hat")) {
|
||||
Equipo equipo = partida.getEquipoJugador(jugador.getJugador().getName());
|
||||
ArrayList<JugadorPaintball> jugadoresCopy = (ArrayList<JugadorPaintball>) equipo.getJugadores().clone();
|
||||
jugadoresCopy.remove(jugador);
|
||||
if(!jugadoresCopy.isEmpty()) {
|
||||
Random r = new Random();
|
||||
int pos = r.nextInt(jugadoresCopy.size());
|
||||
String jName = jugadoresCopy.get(pos).getJugador().getName();
|
||||
JugadorPaintball j = partida.getJugador(jName);
|
||||
j.agregarCoins(3);
|
||||
jugador.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("presentHatGive").replace("%player%", j.getJugador().getName())));
|
||||
j.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("presentHatReceive").replace("%player%", jugador.getJugador().getName())));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void darEquipamientoJugador(Player jugador,int color) {
|
||||
ItemStack item = new ItemStack(Material.LEATHER_HELMET,1);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(color));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setHelmet(item);
|
||||
|
||||
item = new ItemStack(Material.LEATHER_CHESTPLATE,1);
|
||||
meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(color));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setChestplate(item);
|
||||
|
||||
item = new ItemStack(Material.LEATHER_LEGGINGS,1);
|
||||
meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(color));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setLeggings(item);
|
||||
|
||||
item = new ItemStack(Material.LEATHER_BOOTS,1);
|
||||
meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
meta.setColor(Color.fromRGB(color));
|
||||
item.setItemMeta(meta);
|
||||
jugador.getInventory().setBoots(item);
|
||||
}
|
||||
|
||||
public static void setBolasDeNieve(JugadorPaintball j,FileConfiguration config) {
|
||||
for(int i=0;i<=7;i++) {
|
||||
j.getJugador().getInventory().setItem(i, null);
|
||||
}
|
||||
for(int i=9;i<=35;i++) {
|
||||
j.getJugador().getInventory().setItem(i, null);
|
||||
}
|
||||
int amount = Integer.valueOf(config.getString("initial_snowballs"));
|
||||
ItemStack item = null;
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
if(j.getSelectedHat().equals("chicken_hat")) {
|
||||
item = new ItemStack(Material.EGG,1);
|
||||
}else {
|
||||
item = new ItemStack(Material.SNOWBALL,1);
|
||||
}
|
||||
}else {
|
||||
if(j.getSelectedHat().equals("chicken_hat")) {
|
||||
item = new ItemStack(Material.EGG,1);
|
||||
}else {
|
||||
item = new ItemStack(Material.valueOf("SNOW_BALL"),1);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<amount;i++) {
|
||||
j.getJugador().getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void lanzarFuegos(ArrayList<JugadorPaintball> jugadores) {
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
Firework fw = (Firework) j.getJugador().getWorld().spawnEntity(j.getJugador().getLocation(), EntityType.FIREWORK_ROCKET);
|
||||
FireworkMeta fwm = fw.getFireworkMeta();
|
||||
Type type = Type.BALL;
|
||||
Color c1 = Color.RED;
|
||||
Color c2 = Color.AQUA;
|
||||
FireworkEffect efecto = FireworkEffect.builder().withColor(c1).withFade(c2).with(type).build();
|
||||
fwm.addEffect(efecto);
|
||||
fwm.setPower(2);
|
||||
fw.setFireworkMeta(fwm);
|
||||
}
|
||||
}
|
||||
|
||||
public static void teletransportarJugadores(Partida partida) {
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
Player p = j.getJugador();
|
||||
Equipo equipo = partida.getEquipoJugador(p.getName());
|
||||
p.teleport(equipo.getSpawn());
|
||||
}
|
||||
}
|
||||
|
||||
public static void iniciarFaseFinalizacion(Partida partida,PaintballBattle plugin) {
|
||||
partida.setEstado(EstadoPartida.TERMINANDO);
|
||||
Equipo ganador = partida.getGanador();
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
String nameTeam1 = config.getString("teams."+partida.getTeam1().getTipo()+".name");
|
||||
String nameTeam2 = config.getString("teams."+partida.getTeam2().getTipo()+".name");
|
||||
|
||||
String status = "";
|
||||
if(ganador == null) {
|
||||
//empate
|
||||
status = messages.getString("gameFinishedTieStatus");
|
||||
}else {
|
||||
String ganadorTexto = plugin.getConfig().getString("teams."+ganador.getTipo()+".name");
|
||||
status = messages.getString("gameFinishedWinnerStatus").replace("%winner_team%", ganadorTexto);
|
||||
}
|
||||
|
||||
ArrayList<JugadorPaintball> jugadoresKillsOrd = partida.getJugadoresKills();
|
||||
String top1 = "";
|
||||
String top2 = "";
|
||||
String top3 = "";
|
||||
int top1Kills = 0;
|
||||
int top2Kills = 0;
|
||||
int top3Kills = 0;
|
||||
|
||||
if(jugadoresKillsOrd.size() == 2) {
|
||||
top1 = jugadoresKillsOrd.get(0).getJugador().getName();
|
||||
top1Kills = jugadoresKillsOrd.get(0).getAsesinatos();
|
||||
top2 = jugadoresKillsOrd.get(1).getJugador().getName();
|
||||
top2Kills = jugadoresKillsOrd.get(1).getAsesinatos();
|
||||
top3 = messages.getString("topKillsNone");
|
||||
}else if(jugadoresKillsOrd.size() == 1) {
|
||||
top1 = jugadoresKillsOrd.get(0).getJugador().getName();
|
||||
top1Kills = jugadoresKillsOrd.get(0).getAsesinatos();
|
||||
top3 = messages.getString("topKillsNone");
|
||||
top2 = messages.getString("topKillsNone");
|
||||
}else {
|
||||
top1 = jugadoresKillsOrd.get(0).getJugador().getName();
|
||||
top1Kills = jugadoresKillsOrd.get(0).getAsesinatos();
|
||||
top2 = jugadoresKillsOrd.get(1).getJugador().getName();
|
||||
top3 = jugadoresKillsOrd.get(2).getJugador().getName();
|
||||
top2Kills = jugadoresKillsOrd.get(1).getAsesinatos();
|
||||
top3Kills = jugadoresKillsOrd.get(2).getAsesinatos();
|
||||
}
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
List<String> msg = messages.getStringList("gameFinished");
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
for(int i=0;i<msg.size();i++) {
|
||||
j.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', msg.get(i).replace("%status_message%", status).replace("%team1%", nameTeam1)
|
||||
.replace("%team2%", nameTeam2).replace("%kills_team1%", partida.getTeam1().getAsesinatosTotales()+"")
|
||||
.replace("%kills_team2%", partida.getTeam2().getAsesinatosTotales()+"").replace("%player1%", top1).replace("%player2%", top2)
|
||||
.replace("%player3%", top3).replace("%kills_player1%", top1Kills+"").replace("%kills_player2%", top2Kills+"")
|
||||
.replace("%kills_player3%", top3Kills+"").replace("%kills_player%", j.getAsesinatos()+"")));
|
||||
}
|
||||
Equipo equipoJugador = partida.getEquipoJugador(j.getJugador().getName());
|
||||
if(MySQL.isEnabled(plugin.getConfig())) {
|
||||
int win = 0;
|
||||
int lose = 0;
|
||||
int tie = 0;
|
||||
if(equipoJugador.equals(ganador)) {
|
||||
win = 1;
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("winnerTitleMessage"), "");
|
||||
}else if(ganador == null) {
|
||||
tie = 1;
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("tieTitleMessage"), "");
|
||||
}else {
|
||||
lose = 1;
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("loserTitleMessage"), "");
|
||||
}
|
||||
//Aqui se crea/modifica el registro global del jugador
|
||||
if(!MySQL.jugadorExiste(plugin, j.getJugador().getName())) {
|
||||
MySQL.crearJugadorPartidaAsync(plugin, j.getJugador().getUniqueId().toString(), j.getJugador().getName(), "", win, tie, lose, j.getAsesinatos(),0, 1);
|
||||
}else {
|
||||
JugadorDatos player = MySQL.getJugador(plugin, j.getJugador().getName());
|
||||
int kills = j.getAsesinatos()+player.getKills();
|
||||
int wins = player.getWins()+win;
|
||||
int loses = player.getLoses()+lose;
|
||||
int ties = player.getTies()+tie;
|
||||
MySQL.actualizarJugadorPartidaAsync(plugin, j.getJugador().getUniqueId().toString(), j.getJugador().getName(), wins, loses, ties, kills);
|
||||
}
|
||||
//Este registro es el que se crea para datos mensuales y semanales
|
||||
MySQL.crearJugadorPartidaAsync(plugin, j.getJugador().getUniqueId().toString(), j.getJugador().getName(), partida.getNombre(), win, tie, lose, j.getAsesinatos(),0,0);
|
||||
}else {
|
||||
plugin.registerPlayer(j.getJugador().getUniqueId().toString()+".yml");
|
||||
if(plugin.getJugador(j.getJugador().getName()) == null) {
|
||||
plugin.agregarJugadorDatos(new JugadorDatos(j.getJugador().getName(),j.getJugador().getUniqueId().toString(),0,0,0,0,0,new ArrayList<Perk>(),new ArrayList<Hat>()));
|
||||
}
|
||||
JugadorDatos jugador = plugin.getJugador(j.getJugador().getName());
|
||||
if(partida.getEquipoJugador(j.getJugador().getName()).equals(ganador)) {
|
||||
jugador.aumentarWins();
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("winnerTitleMessage"), "");
|
||||
}else if(ganador == null) {
|
||||
jugador.aumentarTies();
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("tieTitleMessage"), "");
|
||||
}else {
|
||||
jugador.aumentarLoses();
|
||||
TitleAPI.sendTitle(j.getJugador(), 10, 40, 10, messages.getString("loserTitleMessage"), "");
|
||||
}
|
||||
|
||||
jugador.aumentarKills(j.getAsesinatos());
|
||||
}
|
||||
j.getJugador().closeInventory();
|
||||
j.getJugador().getInventory().clear();
|
||||
|
||||
|
||||
if(config.getString("leave_item_enabled").equals("true")) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "leave_item");
|
||||
j.getJugador().getInventory().setItem(8, item);
|
||||
}
|
||||
if(config.getString("play_again_item_enabled").equals("true")) {
|
||||
ItemStack item = UtilidadesItems.crearItem(config, "play_again_item");
|
||||
j.getJugador().getInventory().setItem(7, item);
|
||||
}
|
||||
|
||||
if(config.getString("rewards_executed_after_teleport").equals("false")) {
|
||||
if(ganador != null) {
|
||||
if(ganador.getTipo().equals(equipoJugador.getTipo())) {
|
||||
List<String> commands = config.getStringList("winners_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}else {
|
||||
List<String> commands = config.getStringList("losers_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}
|
||||
}else {
|
||||
List<String> commands = config.getStringList("tie_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int time = Integer.valueOf(config.getString("arena_ending_phase_cooldown"));
|
||||
CooldownManager c = new CooldownManager(plugin);
|
||||
c.cooldownFaseFinalizacion(partida,time,ganador);
|
||||
}
|
||||
|
||||
public static void ejecutarComandosRewards(List<String> commands,JugadorPaintball j) {
|
||||
CommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
for(int i=0;i<commands.size();i++){
|
||||
if(commands.get(i).startsWith("msg %player%")) {
|
||||
String mensaje = commands.get(i).replace("msg %player% ", "");
|
||||
j.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', mensaje));
|
||||
}else {
|
||||
String comandoAEnviar = commands.get(i).replaceAll("%player%", j.getJugador().getName());
|
||||
if(comandoAEnviar.contains("%random")) {
|
||||
int pos = comandoAEnviar.indexOf("%random");
|
||||
int nextPos = comandoAEnviar.indexOf("%", pos+1);
|
||||
String variableCompleta = comandoAEnviar.substring(pos,nextPos+1);
|
||||
String variable = variableCompleta.replace("%random_", "").replace("%", "");
|
||||
String[] sep = variable.split("-");
|
||||
int cantidadMinima = 0;
|
||||
int cantidadMaxima = 0;
|
||||
|
||||
try {
|
||||
cantidadMinima = (int) UtilidadesOtros.eval(sep[0].replace("kills", j.getAsesinatos()+""));
|
||||
cantidadMaxima = (int) UtilidadesOtros.eval(sep[1].replace("kills", j.getAsesinatos()+""));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
int num = UtilidadesOtros.getNumeroAleatorio(cantidadMinima, cantidadMaxima);
|
||||
comandoAEnviar = comandoAEnviar.replace(variableCompleta, num+"");
|
||||
}
|
||||
Bukkit.dispatchCommand(console, comandoAEnviar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void finalizarPartida(Partida partida,PaintballBattle plugin,boolean cerrandoServer,Equipo ganadorEquipo) {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
ArrayList<JugadorPaintball> jugadores = partida.getJugadores();
|
||||
// Scoreboards für alle Spieler entfernen
|
||||
for(JugadorPaintball j : jugadores) {
|
||||
String tipoFin = "";
|
||||
if(ganadorEquipo != null) {
|
||||
Equipo equipoJugador = partida.getEquipoJugador(j.getJugador().getName());
|
||||
if(ganadorEquipo.getTipo().equals(equipoJugador.getTipo())) {
|
||||
tipoFin = "ganador";
|
||||
}else {
|
||||
tipoFin = "perdedor";
|
||||
}
|
||||
}else {
|
||||
tipoFin = "empate";
|
||||
}
|
||||
jugadorSale(partida, j.getJugador(),true,plugin,cerrandoServer);
|
||||
if(config.getString("rewards_executed_after_teleport").equals("true") && !cerrandoServer) {
|
||||
if(tipoFin.equals("ganador")) {
|
||||
List<String> commands = config.getStringList("winners_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}else if(tipoFin.equals("perdedor")) {
|
||||
List<String> commands = config.getStringList("losers_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}else {
|
||||
List<String> commands = config.getStringList("tie_command_rewards");
|
||||
ejecutarComandosRewards(commands,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
partida.getTeam1().setVidas(0);
|
||||
partida.getTeam2().setVidas(0);
|
||||
partida.setEnNuke(false);
|
||||
partida.modificarTeams(config);
|
||||
|
||||
partida.setEstado(EstadoPartida.ESPERANDO);
|
||||
}
|
||||
|
||||
public static void muereJugador(Partida partida,JugadorPaintball jugadorAtacante,final JugadorPaintball jugadorDañado,PaintballBattle plugin,boolean lightning,boolean nuke) {
|
||||
if(jugadorDañado.haSidoAsesinadoRecientemente()) {
|
||||
return;
|
||||
}
|
||||
if(jugadorDañado.getSelectedHat().equals("guardian_hat") && jugadorDañado.isEfectoHatActivado()) {
|
||||
return;
|
||||
}
|
||||
if(jugadorDañado.getSelectedHat().equals("protector_hat")) {
|
||||
Random r = new Random();
|
||||
int num = r.nextInt(100);
|
||||
if(num >= 80) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Equipo equipoDañado = partida.getEquipoJugador(jugadorDañado.getJugador().getName());
|
||||
Equipo equipoAtacante = partida.getEquipoJugador(jugadorAtacante.getJugador().getName());
|
||||
if(equipoDañado.equals(equipoAtacante)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(lightning) {
|
||||
jugadorDañado.getJugador().getWorld().strikeLightningEffect(jugadorDañado.getJugador().getLocation());
|
||||
}
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
jugadorDañado.aumentarMuertes();
|
||||
jugadorDañado.setDeathLocation(jugadorDañado.getJugador().getLocation().clone());
|
||||
jugadorDañado.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("killedBy").replace("%player%", jugadorAtacante.getJugador().getName())));
|
||||
String[] separados = config.getString("killedBySound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugadorDañado.getJugador().playSound(jugadorDañado.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
jugadorDañado.setAsesinadoRecientemente(true);
|
||||
jugadorDañado.setLastKilledBy(jugadorAtacante.getJugador().getName());
|
||||
equipoDañado.disminuirVidas(1);
|
||||
|
||||
Equipo equipo = partida.getEquipoJugador(jugadorDañado.getJugador().getName());
|
||||
if(jugadorDañado.getSelectedHat().equals("explosive_hat")) {
|
||||
Random r = new Random();
|
||||
int num = r.nextInt(100);
|
||||
if(num >= 80) {
|
||||
if(Bukkit.getVersion().contains("1.8")) {
|
||||
jugadorDañado.getJugador().getWorld().playEffect(jugadorDañado.getJugador().getLocation(), Effect.valueOf("EXPLOSION_LARGE"), 2);
|
||||
}else {
|
||||
jugadorDañado.getJugador().getWorld().spawnParticle(Particle.EXPLOSION,jugadorDañado.getJugador().getLocation(),2);
|
||||
}
|
||||
separados = config.getString("explosiveHatSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugadorDañado.getJugador().getWorld().playSound(jugadorDañado.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
Collection<Entity> entidades = jugadorDañado.getJugador().getWorld().getNearbyEntities(jugadorDañado.getJugador().getLocation(), 5, 5, 5);
|
||||
for(Entity e : entidades) {
|
||||
if(e != null && e.getType().equals(EntityType.PLAYER)) {
|
||||
Player player = (Player) e;
|
||||
JugadorPaintball jugadorDañado2 = partida.getJugador(player.getName());
|
||||
if(jugadorDañado2 != null) {
|
||||
PartidaManager.muereJugador(partida, jugadorDañado, jugadorDañado2, plugin, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
jugadorDañado.getJugador().teleport(equipo.getSpawn());
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
if(jugadorDañado.getSelectedHat().equals("chicken_hat")) {
|
||||
jugadorDañado.getJugador().getInventory().removeItem(new ItemStack(Material.EGG));
|
||||
}else {
|
||||
jugadorDañado.getJugador().getInventory().removeItem(new ItemStack(Material.SNOWBALL));
|
||||
}
|
||||
}else {
|
||||
if(jugadorDañado.getSelectedHat().equals("chicken_hat")) {
|
||||
jugadorDañado.getJugador().getInventory().removeItem(new ItemStack(Material.EGG));
|
||||
}else {
|
||||
jugadorDañado.getJugador().getInventory().removeItem(new ItemStack(Material.valueOf("SNOW_BALL")));
|
||||
}
|
||||
}
|
||||
PartidaManager.setBolasDeNieve(jugadorDañado,config);
|
||||
|
||||
jugadorAtacante.aumentarAsesinatos();
|
||||
int cantidadCoinsGanados = UtilidadesOtros.coinsGanados(jugadorAtacante.getJugador(), config);
|
||||
int nivelExtraKillCoins = PaintballAPI.getPerkLevel(jugadorAtacante.getJugador(), "extra_killcoins");
|
||||
if(nivelExtraKillCoins != 0) {
|
||||
String linea = plugin.getShop().getStringList("perks_upgrades.extra_killcoins").get(nivelExtraKillCoins-1);
|
||||
String[] sep = linea.split(";");
|
||||
int cantidad = Integer.valueOf(sep[0]);
|
||||
cantidadCoinsGanados = cantidadCoinsGanados+cantidad;
|
||||
}
|
||||
String lastKilledBy = jugadorAtacante.getLastKilledBy();
|
||||
if(lastKilledBy != null && lastKilledBy.equals(jugadorDañado.getJugador().getName())) {
|
||||
cantidadCoinsGanados = cantidadCoinsGanados+1;
|
||||
}
|
||||
jugadorAtacante.agregarCoins(cantidadCoinsGanados);
|
||||
UtilidadesItems.crearItemKillstreaks(jugadorAtacante,config);
|
||||
|
||||
if(nuke) {
|
||||
String equipoAtacanteName = config.getString("teams."+equipoAtacante.getTipo()+".name");
|
||||
String equipoDañadoName = config.getString("teams."+equipoDañado.getTipo()+".name");
|
||||
for(JugadorPaintball j : partida.getJugadores()) {
|
||||
if(!j.getJugador().getName().equals(jugadorAtacante.getJugador().getName())) {
|
||||
j.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("nukeKillMessage").replace("%team_player1%", equipoDañadoName)
|
||||
.replace("%player1%", jugadorDañado.getJugador().getName()).replace("%team_player2%", equipoAtacanteName)
|
||||
.replace("%player2%", jugadorAtacante.getJugador().getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
jugadorAtacante.getJugador().sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("kill").replace("%player%", jugadorDañado.getJugador().getName())));
|
||||
if(!nuke) {
|
||||
separados = config.getString("killSound").split(";");
|
||||
try {
|
||||
Sound sound = ValueOfPatch.valueOf(separados[0]);
|
||||
jugadorAtacante.getJugador().playSound(jugadorAtacante.getJugador().getLocation(), sound, Float.valueOf(separados[1]), Float.valueOf(separados[2]));
|
||||
}catch(Exception ex) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', PaintballBattle.prefix+"&7Sound Name: &c"+separados[0]+" &7is not valid."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int snowballs = Integer.valueOf(config.getString("snowballs_per_kill"));
|
||||
if(!UtilidadesOtros.isLegacy()) {
|
||||
if(jugadorAtacante.getSelectedHat().equals("chicken_hat")) {
|
||||
jugadorAtacante.getJugador().getInventory().addItem(new ItemStack(Material.EGG,snowballs));
|
||||
}else {
|
||||
jugadorAtacante.getJugador().getInventory().addItem(new ItemStack(Material.SNOWBALL,snowballs));
|
||||
}
|
||||
|
||||
}else {
|
||||
if(jugadorAtacante.getSelectedHat().equals("chicken_hat")) {
|
||||
jugadorAtacante.getJugador().getInventory().addItem(new ItemStack(Material.EGG,snowballs));
|
||||
}else {
|
||||
jugadorAtacante.getJugador().getInventory().addItem(new ItemStack(Material.valueOf("SNOW_BALL"),snowballs));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(equipoDañado.getVidas() <= 0) {
|
||||
//terminar partida
|
||||
PartidaManager.iniciarFaseFinalizacion(partida, plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
int invulnerability = Integer.valueOf(config.getString("respawn_invulnerability"));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
jugadorDañado.setAsesinadoRecientemente(false);
|
||||
}
|
||||
}, invulnerability*20L);
|
||||
}
|
||||
|
||||
public static Partida getPartidaDisponible(PaintballBattle plugin) {
|
||||
ArrayList<Partida> partidas = plugin.getPartidas();
|
||||
ArrayList<Partida> disponibles = new ArrayList<Partida>();
|
||||
for(int i=0;i<partidas.size();i++) {
|
||||
if(partidas.get(i).getEstado().equals(EstadoPartida.ESPERANDO) ||
|
||||
partidas.get(i).getEstado().equals(EstadoPartida.COMENZANDO)) {
|
||||
if(!partidas.get(i).estaLlena()) {
|
||||
disponibles.add(partidas.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(disponibles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Ordenar
|
||||
for(int i=0;i<disponibles.size();i++) {
|
||||
for(int c=i+1;c<disponibles.size();c++) {
|
||||
if(disponibles.get(i).getCantidadActualJugadores() < disponibles.get(c).getCantidadActualJugadores()) {
|
||||
Partida p = disponibles.get(i);
|
||||
disponibles.set(i, disponibles.get(c));
|
||||
disponibles.set(c, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return disponibles.get(0);
|
||||
}
|
||||
}
|
102
src/main/java/pb/ajneb97/managers/ScoreboardAdmin.java
Normal file
102
src/main/java/pb/ajneb97/managers/ScoreboardAdmin.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.juego.Equipo;
|
||||
import pb.ajneb97.juego.EstadoPartida;
|
||||
import pb.ajneb97.juego.JugadorPaintball;
|
||||
import pb.ajneb97.juego.Partida;
|
||||
import pb.ajneb97.lib.fastboard.FastBoard;
|
||||
import pb.ajneb97.utils.UtilidadesOtros;
|
||||
|
||||
public class ScoreboardAdmin {
|
||||
|
||||
private int taskID;
|
||||
private PaintballBattle plugin;
|
||||
private final Map<UUID, FastBoard> boards = new HashMap<>();
|
||||
public ScoreboardAdmin(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public int getTaskID() {
|
||||
return this.taskID;
|
||||
}
|
||||
|
||||
public void crearScoreboards() {
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
final FileConfiguration messages = plugin.getMessages();
|
||||
final FileConfiguration config = plugin.getConfig();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
actualizarScoreboard(player,messages,config);
|
||||
}
|
||||
}
|
||||
},0, 20L);
|
||||
}
|
||||
|
||||
protected void actualizarScoreboard(final Player player,final FileConfiguration messages,final FileConfiguration config) {
|
||||
Partida partida = plugin.getPartidaJugador(player.getName());
|
||||
FastBoard board = boards.get(player.getUniqueId());
|
||||
if(partida != null) {
|
||||
JugadorPaintball jugador = partida.getJugador(player.getName());
|
||||
if(board == null) {
|
||||
board = new FastBoard(player);
|
||||
board.updateTitle(ChatColor.translateAlternateColorCodes('&',messages.getString("gameScoreboardTitle")));
|
||||
boards.put(player.getUniqueId(), board);
|
||||
}
|
||||
|
||||
List<String> lista = messages.getStringList("gameScoreboardBody");
|
||||
Equipo equipo1 = partida.getTeam1();
|
||||
Equipo equipo2 = partida.getTeam2();
|
||||
String equipo1Nombre = config.getString("teams."+equipo1.getTipo()+".name");
|
||||
String equipo2Nombre = config.getString("teams."+equipo2.getTipo()+".name");
|
||||
|
||||
for(int i=0;i<lista.size();i++) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', lista.get(i).replace("%status%", getEstado(partida,messages)).replace("%team_1%", equipo1Nombre)
|
||||
.replace("%team_2%", equipo2Nombre).replace("%team_1_lives%", equipo1.getVidas()+"").replace("%team_2_lives%", equipo2.getVidas()+"")
|
||||
.replace("%kills%", jugador.getAsesinatos()+"").replace("%arena%", partida.getNombre()).replace("%current_players%", partida.getCantidadActualJugadores()+"")
|
||||
.replace("%max_players%", partida.getCantidadMaximaJugadores()+""));
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI")!= null){
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
board.updateLine(i, message);
|
||||
}
|
||||
}else {
|
||||
if(board != null) {
|
||||
boards.remove(player.getUniqueId());
|
||||
board.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getEstado(Partida partida,FileConfiguration messages) {
|
||||
//Remplazar variables del %time%
|
||||
if(partida.getEstado().equals(EstadoPartida.ESPERANDO)) {
|
||||
return messages.getString("statusWaiting");
|
||||
}else if(partida.getEstado().equals(EstadoPartida.COMENZANDO)) {
|
||||
int tiempo = partida.getTiempo();
|
||||
return messages.getString("statusStarting").replace("%time%", UtilidadesOtros.getTiempo(tiempo));
|
||||
}else if(partida.getEstado().equals(EstadoPartida.TERMINANDO)) {
|
||||
int tiempo = partida.getTiempo();
|
||||
return messages.getString("statusFinishing").replace("%time%", UtilidadesOtros.getTiempo(tiempo));
|
||||
}else {
|
||||
int tiempo = partida.getTiempo();
|
||||
return messages.getString("statusIngame").replace("%time%", UtilidadesOtros.getTiempo(tiempo));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
144
src/main/java/pb/ajneb97/managers/TopHologram.java
Normal file
144
src/main/java/pb/ajneb97/managers/TopHologram.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import eu.decentsoftware.holograms.api.DHAPI;
|
||||
import eu.decentsoftware.holograms.api.holograms.Hologram;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
import pb.ajneb97.database.MySQL;
|
||||
import pb.ajneb97.database.MySQLCallback;
|
||||
import pb.ajneb97.utils.UtilidadesHologramas;
|
||||
|
||||
public class TopHologram {
|
||||
|
||||
private String name;
|
||||
private String type;
|
||||
private Hologram hologram;
|
||||
private double yOriginal;
|
||||
private String period;
|
||||
|
||||
public TopHologram(String name, String type, Location location, PaintballBattle plugin, String period) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.period = period;
|
||||
this.yOriginal = location.getY();
|
||||
Location nuevaLoc = location.clone();
|
||||
nuevaLoc.setY(nuevaLoc.getY() + UtilidadesHologramas.determinarY(nuevaLoc, UtilidadesHologramas.getCantidadLineasHolograma(plugin)) + 1.4);
|
||||
this.hologram = DHAPI.createHologram(name, nuevaLoc, true);
|
||||
}
|
||||
|
||||
public String getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public double getyOriginal() {
|
||||
return yOriginal;
|
||||
}
|
||||
|
||||
public void removeHologram() {
|
||||
this.hologram.delete();
|
||||
}
|
||||
|
||||
public void spawnHologram(PaintballBattle plugin) {
|
||||
FileConfiguration messages = plugin.getMessages();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
final int topPlayersMax = Integer.valueOf(config.getString("top_hologram_number_of_players"));
|
||||
List<String> lineas = messages.getStringList("topHologramFormat");
|
||||
|
||||
hologram.setDefaultVisibleState(true);
|
||||
//this.hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.VISIBLE);
|
||||
|
||||
String typeName = "";
|
||||
String periodName = "";
|
||||
if (type.equals("kills")) {
|
||||
typeName = messages.getString("topHologramTypeKills");
|
||||
} else {
|
||||
typeName = messages.getString("topHologramTypeWins");
|
||||
}
|
||||
if (period.equals("monthly")) {
|
||||
periodName = messages.getString("topHologramPeriodMonthly");
|
||||
} else if (period.equals("weekly")) {
|
||||
periodName = messages.getString("topHologramPeriodWeekly");
|
||||
} else {
|
||||
periodName = messages.getString("topHologramPeriodGlobal");
|
||||
}
|
||||
|
||||
final String lineaMessage = messages.getString("topHologramScoreboardLine");
|
||||
for (int i = 0; i < lineas.size(); i++) {
|
||||
String linea = lineas.get(i).replace("%type%", typeName).replace("%period%", periodName);
|
||||
if (linea.contains("%scoreboard_lines%")) {
|
||||
if (MySQL.isEnabled(config) && !period.equals("global")) {
|
||||
UtilidadesHologramas.getTopPlayersSQL(plugin, type, period, new MySQLCallback() {
|
||||
@Override
|
||||
public void alTerminar(ArrayList<String> playersList) {
|
||||
for (int c = 0; c < topPlayersMax; c++) {
|
||||
int num = c + 1;
|
||||
try {
|
||||
String[] separados = playersList.get(c).split(";");
|
||||
DHAPI.addHologramLine(hologram,ChatColor.translateAlternateColorCodes('&', lineaMessage
|
||||
.replace("%position%", String.valueOf(num))
|
||||
.replace("%name%", separados[0])
|
||||
.replace("%points%", separados[1])));
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
UtilidadesHologramas.getTopPlayers(plugin, plugin.getJugadores(), type, new MySQLCallback() {
|
||||
@Override
|
||||
public void alTerminar(ArrayList<String> playersList) {
|
||||
for (int c = 0; c < topPlayersMax; c++) {
|
||||
int num = c + 1;
|
||||
try {
|
||||
String[] separados = playersList.get(c).split(";");
|
||||
DHAPI.addHologramLine(hologram,(ChatColor.translateAlternateColorCodes('&', lineaMessage
|
||||
.replace("%position%", String.valueOf(num))
|
||||
.replace("%name%", separados[0])
|
||||
.replace("%points%", separados[1]))));
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
DHAPI.addHologramLine(hologram, ChatColor.translateAlternateColorCodes('&', linea));
|
||||
//hologram.getLines().appendText(ChatColor.translateAlternateColorCodes('&', linea));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void actualizar(PaintballBattle plugin) {
|
||||
//Location loc = this.hologram.getPosition().toLocation();
|
||||
Location loc = this.hologram.getLocation();
|
||||
removeHologram();
|
||||
loc.setY(yOriginal);
|
||||
Location nuevaLoc = loc.clone();
|
||||
nuevaLoc.setY(nuevaLoc.getY() + UtilidadesHologramas.determinarY(nuevaLoc, UtilidadesHologramas.getCantidadLineasHolograma(plugin)) + 1.4);
|
||||
//this.hologram = HolographicDisplaysAPI.get(plugin).createHologram(nuevaLoc);
|
||||
this.hologram = DHAPI.createHologram(name,nuevaLoc);
|
||||
spawnHologram(plugin);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Hologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
}
|
40
src/main/java/pb/ajneb97/managers/TopHologramAdmin.java
Normal file
40
src/main/java/pb/ajneb97/managers/TopHologramAdmin.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package pb.ajneb97.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import pb.ajneb97.PaintballBattle;
|
||||
|
||||
public class TopHologramAdmin {
|
||||
|
||||
int taskID;
|
||||
private PaintballBattle plugin;
|
||||
public TopHologramAdmin(PaintballBattle plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public int getTaskID() {
|
||||
return this.taskID;
|
||||
}
|
||||
|
||||
public void actualizarHologramas() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
long ticks = Long.valueOf(config.getString("top_hologram_update_time"))*20;
|
||||
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||
taskID = scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
ejecutarActualizarHologramas();
|
||||
}
|
||||
},ticks, ticks);
|
||||
}
|
||||
|
||||
protected void ejecutarActualizarHologramas() {
|
||||
ArrayList<TopHologram> hologramas = plugin.getTopHologramas();
|
||||
for(int i=0;i<hologramas.size();i++) {
|
||||
hologramas.get(i).actualizar(plugin);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user