From eabb4e24c9e6e51993ce072f642dba348edb8fc4 Mon Sep 17 00:00:00 2001 From: lluiscab Date: Mon, 13 Aug 2018 15:00:26 +0200 Subject: [PATCH 1/4] More BedWars development --- .../com/biel/lobby/mapes/jocs/BedWars.java | 242 ++++++++++++++++-- 1 file changed, 214 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java index 83818c3..3b22236 100644 --- a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java +++ b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java @@ -4,15 +4,19 @@ import com.biel.BielAPI.Utils.Regions.Cuboid; import com.biel.lobby.mapes.JocEquipsLastStanding; import com.biel.lobby.mapes.JocObjectius; +import com.biel.lobby.utilities.ScoreBoardUpdater; import com.biel.lobby.utilities.Utils; -import org.bukkit.DyeColor; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; +import com.connorlinfoot.bountifulapi.BountifulAPI; +import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -20,6 +24,11 @@ import java.util.Optional; public class BedWars extends JocEquipsLastStanding { + + /* + General + */ + @Override protected void customJocIniciat() { super.customJocIniciat(); @@ -32,10 +41,14 @@ protected void customJocIniciat() { @Override protected ArrayList getDesiredTeams() { + ArrayList equips = new ArrayList<>(); - equips.add(new EquipBedWars(DyeColor.RED, "vermell")); - equips.add(new EquipBedWars(DyeColor.BLUE, "blau")); + + equips.add(new EquipBedWars(DyeColor.RED, "vermell")); + equips.add(new EquipBedWars(DyeColor.BLUE, "blau")); + return equips; + } @Override @@ -47,53 +60,226 @@ protected void setCustomGameRules() { public String getGameName() { return "BedWars"; } + @Override protected ArrayList getStartingItems(Player ply) { + ArrayList items = new ArrayList<>(); + Equip e = obtenirEquip(ply); - items.add(new ItemStack(Material.WOOD_SWORD, 1)); - items.add(Utils.createColoredTeamArmor(Material.LEATHER_CHESTPLATE, e)); - items.add(Utils.createColoredTeamArmor(Material.LEATHER_HELMET, e)); - items.add(Utils.createColoredTeamArmor(Material.LEATHER_BOOTS, e)); - items.add(new ItemStack(Material.ARROW, 1)); + + // Armor + items.add(Utils.createColoredTeamArmor(Material.LEATHER_CHESTPLATE, e)); + items.add(Utils.createColoredTeamArmor(Material.LEATHER_HELMET, e)); + items.add(Utils.createColoredTeamArmor(Material.LEATHER_BOOTS, e)); + items.add(Utils.createColoredTeamArmor(Material.LEATHER_LEGGINGS, e)); + + // Sword + ItemStack sword = new ItemStack(Material.IRON_SWORD, 1); + sword.addUnsafeEnchantment(Enchantment.SWEEPING_EDGE, 5); + items.add(sword); + + // Bow + ItemStack bow = new ItemStack(Material.BOW, 1); + bow.addUnsafeEnchantment(Enchantment.DURABILITY, 10); + items.add(bow); + + // Balancing multiplier + double balancingMultiplier = getBalancingMultiplier(e); + + // Pickaxe + ItemStack pickaxe = new ItemStack(Material.DIAMOND_PICKAXE, 1); + if (balancingMultiplier > 1) pickaxe.addUnsafeEnchantment(Enchantment.DIG_SPEED, (balancingMultiplier > 1.20 ? 2 : 1)); + items.add(pickaxe); + + // Blocks + int block_amount = (int) (45 * balancingMultiplier); + if (block_amount > 64) block_amount = 64; + + if (obtenirEquip(ply).getId() == 0) items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 14)); + else items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 10)); + + // Arrows + int arrows = (int) (50 * balancingMultiplier); + if (arrows > 64) arrows = 64; + items.add(new ItemStack(Material.ARROW, arrows)); return items; + } + /* + Game specific functions + */ + @Override public EquipBedWars obtenirEquip(Player ply) { return obtenirEquip(ply, EquipBedWars.class); } - public class EquipBedWars extends Equip{ - private org.bukkit.Location bedLocation; - public EquipBedWars(DyeColor color, String adj) { + + + @Override + protected void updateScoreBoard(Player ply) { + + super.updateScoreBoard(ply); + + if(!JocIniciat) return; + + ArrayList list = new ArrayList<>(); + + list.add(ChatColor.RED + ""); + + for(Equip equip : Equips) { + + EquipBedWars equipBedWars = (EquipBedWars) equip; + + String teamSidebar = equipBedWars.getChatColor() + "" + ChatColor.BOLD + "" + equipBedWars.getAdjectiu().toUpperCase().charAt(0) + "" + ChatColor.RESET + "" + ChatColor.GRAY + " Equip " + equipBedWars.getAdjectiu() + ": "; + + if(equipBedWars.isBedAlive()) list.add(teamSidebar + ChatColor.BOLD + "" + ChatColor.GREEN + "✓"); + else if (equipBedWars.getPlayers().size() > 0) list.add(teamSidebar + ChatColor.YELLOW + equipBedWars.getPlayers().size()); + else list.add(teamSidebar + ChatColor.BOLD + "" + ChatColor.RED + "✗"); + + } + + list.add(ChatColor.GREEN + ""); + + ScoreBoardUpdater.setScoreBoard(ply, ChatColor.BOLD + "" + ChatColor.RED + "Bed Wars", list, null); + + } + + @Override + protected void onPlayerMove(PlayerMoveEvent evt, Player p) { + super.onPlayerMove(evt, p); + + Player ply = evt.getPlayer(); + + if (isSpectator(ply)) return; + if (!JocIniciat) return; + + if (ply.getLocation().getY() < 80) ply.damage(10000); + + } + + @Override + protected void onBlockHitByProjectile(ProjectileHitEvent evt, Block b, Projectile proj) { + + super.onBlockHitByProjectile(evt, b, proj); + + Material t = b.getType(); + if ( + t == Material.GLASS || + t == Material.STAINED_GLASS || + t == Material.STAINED_GLASS_PANE || + t == Material.THIN_GLASS + ) { + + b.setType(Material.AIR); + getWorld().playSound(b.getLocation(), Sound.BLOCK_GLASS_BREAK, 15F, 1.2F); + proj.remove(); + + for (BlockFace f : BlockFace.values()) { + + if (GUtils.Possibilitat(58)) continue; + Block relative = b.getRelative(f); + t = relative.getType(); + + if ( + t == Material.GLASS || + t == Material.STAINED_GLASS || + t == Material.STAINED_GLASS_PANE || + t == Material.THIN_GLASS + ) { + relative.setType(Material.AIR); + } + + } + } + } + + @Override + protected void onPlayerDeath(PlayerDeathEvent evt, Player killed) { + + super.onPlayerDeath(evt, killed); + Bukkit.broadcastMessage("isBedAlive: " + obtenirEquip(killed).isBedAlive()); + if(!obtenirEquip(killed).isBedAlive()) removeAlive(killed); + } + + @Override + protected void onBlockBreak(BlockBreakEvent evt, Block blk) { + + super.onBlockBreak(evt, blk); + + // Check for bed + if(evt.getBlock().getType() == Material.BED || evt.getBlock().getType() == Material.BED_BLOCK) { + + evt.setDropItems(false); + Player ply = evt.getPlayer(); + + // S'han de tenir en compte que un llit es un bloc doble i per tant s'han de comprovar els blocs alrededor + if( + obtenirEquip(ply).getBedLocation().equals(evt.getBlock().getLocation().add(1, 0, 0)) || + obtenirEquip(ply).getBedLocation().equals(evt.getBlock().getLocation().add(-1, 0, 0)) || + obtenirEquip(ply).getBedLocation().equals(evt.getBlock().getLocation().add(0, 0, 1)) || + obtenirEquip(ply).getBedLocation().equals(evt.getBlock().getLocation().add(0, 0, -1)) || + obtenirEquip(ply).getBedLocation().equals(evt.getBlock().getLocation()) + ) { + + evt.setCancelled(true); + ply.playSound(ply.getLocation(), Sound.ENTITY_VILLAGER_NO, 100, 1); + String msg = ChatColor.RED + "" + ChatColor.ITALIC + "No pots destruir el teu propi llit"; + BountifulAPI.sendActionBar(ply, msg, 150); + + } else { + + sendGlobalSound(Sound.ENTITY_ENDERDRAGON_GROWL, 100, 1); + String text = obtenirEquip(ply).getChatColor() == ChatColor.RED + ? ChatColor.GREEN + "S'ha destruit el llit " + ChatColor.BLUE + "blau" + : ChatColor.GREEN + "S'ha destruit el llit " + ChatColor.RED + "vermell"; + + for (Player p : getPlayers()) { + BountifulAPI.sendTitle(p, 10, 20, 10, "", text); + } + + } + + updateScoreBoards(); + + } + + // Check if block has been placed by a player or was on the map by default + + } + + public class EquipBedWars extends Equip { + + private Location bedLocation; + EquipBedWars(DyeColor color, String adj) { super(color, adj); } - public void detectBed(){ + + void detectBed() { + int radiusFromSpawn = 8; Cuboid cuboid = GUtils.getCuboidAround(this.getTeamSpawnLocation(), radiusFromSpawn); Optional optionalBed = cuboid.getBlocks().stream() .filter(block -> block.getType().equals(Material.BED_BLOCK)) .findAny(); - if(optionalBed.isPresent()){ + + if(optionalBed.isPresent()) { + bedLocation = optionalBed.get().getLocation(); getWorld().playEffect(bedLocation, Effect.MOBSPAWNER_FLAMES, 0); - }else{ - sendMessage("[Error] No s'ha pogut trobar el llit per a l'equip " + this.getAdjectiuColored()); + + } else { + Bukkit.broadcastMessage("[Error] No s'ha pogut trobar el llit per a l'equip " + this.getAdjectiuColored()); } } - public Location getBedLocation() { + + Location getBedLocation() { return bedLocation; } - public boolean isBedAlive(){ - return bedLocation.getBlock().getType() == Material.BED; - } - } - @Override - protected void onPlayerDeath(PlayerDeathEvent evt, Player killed) { - super.onPlayerDeath(evt, killed); - if(!obtenirEquip(killed).isBedAlive()) - removeAlive(killed); + boolean isBedAlive() { return bedLocation != null && (bedLocation.getBlock().getType() == Material.BED_BLOCK); } + } } From 168b521bc674af4178ef274236349c8fdc75519e Mon Sep 17 00:00:00 2001 From: lluiscab Date: Mon, 13 Aug 2018 15:09:11 +0200 Subject: [PATCH 2/4] Added isGlassBlock utils --- .../com/biel/lobby/mapes/jocs/BedWars.java | 20 ++++--------------- .../java/com/biel/lobby/utilities/BUtils.java | 12 +++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java index 3b22236..a02b091 100644 --- a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java +++ b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java @@ -4,6 +4,7 @@ import com.biel.BielAPI.Utils.Regions.Cuboid; import com.biel.lobby.mapes.JocEquipsLastStanding; import com.biel.lobby.mapes.JocObjectius; +import com.biel.lobby.utilities.BUtils; import com.biel.lobby.utilities.ScoreBoardUpdater; import com.biel.lobby.utilities.Utils; import com.connorlinfoot.bountifulapi.BountifulAPI; @@ -164,14 +165,7 @@ protected void onPlayerMove(PlayerMoveEvent evt, Player p) { protected void onBlockHitByProjectile(ProjectileHitEvent evt, Block b, Projectile proj) { super.onBlockHitByProjectile(evt, b, proj); - - Material t = b.getType(); - if ( - t == Material.GLASS || - t == Material.STAINED_GLASS || - t == Material.STAINED_GLASS_PANE || - t == Material.THIN_GLASS - ) { + if (BUtils.isGlassBlock(b)) { b.setType(Material.AIR); getWorld().playSound(b.getLocation(), Sound.BLOCK_GLASS_BREAK, 15F, 1.2F); @@ -181,14 +175,8 @@ protected void onBlockHitByProjectile(ProjectileHitEvent evt, Block b, Projectil if (GUtils.Possibilitat(58)) continue; Block relative = b.getRelative(f); - t = relative.getType(); - - if ( - t == Material.GLASS || - t == Material.STAINED_GLASS || - t == Material.STAINED_GLASS_PANE || - t == Material.THIN_GLASS - ) { + + if (BUtils.isGlassBlock(b)) { relative.setType(Material.AIR); } diff --git a/src/main/java/com/biel/lobby/utilities/BUtils.java b/src/main/java/com/biel/lobby/utilities/BUtils.java index cf72fde..308dbb0 100644 --- a/src/main/java/com/biel/lobby/utilities/BUtils.java +++ b/src/main/java/com/biel/lobby/utilities/BUtils.java @@ -54,4 +54,16 @@ public static ArrayList locListToBlock(List locs) { return blks; } + public static boolean isGlassBlock(Block blk) { + + Material t = blk.getType(); + return ( + t == Material.GLASS || + t == Material.STAINED_GLASS || + t == Material.STAINED_GLASS_PANE || + t == Material.THIN_GLASS + ); + + } + } From c507c5096222d8fe47ecef9207c39a309f1715a0 Mon Sep 17 00:00:00 2001 From: lluiscab Date: Mon, 13 Aug 2018 17:51:39 +0200 Subject: [PATCH 3/4] More BedWars --- src/main/java/com/biel/lobby/GestorMapes.java | 2 +- .../lobby/mapes/JocEquipsLastStanding.java | 2 + .../com/biel/lobby/mapes/jocs/BedWars.java | 48 +++++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/biel/lobby/GestorMapes.java b/src/main/java/com/biel/lobby/GestorMapes.java index 3ac1950..e3a59c0 100644 --- a/src/main/java/com/biel/lobby/GestorMapes.java +++ b/src/main/java/com/biel/lobby/GestorMapes.java @@ -65,7 +65,7 @@ public GestorMapes() { Mapes.add(new ContenidorJoc(PilotaSplash.class, "Pilota Splash", Material.SLIME_BALL, DevelopmentState.Alpha)); //Mapes.add(new ContenidorJoc(TempleQuest.class, "Temple Quest", Material.QUARTZ_BLOCK, DevelopmentState.InDevelopment)); Mapes.add(new ContenidorJoc(OneInTheChamber.class, "OneInTheChamber", Material.BOW, DevelopmentState.Alpha)); - Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.BED, DevelopmentState.InDevelopment)); + Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.BED, DevelopmentState.Beta)); } public void queryAutoRatings() { auto_ratings = Com.getDataAPI().getAutoRating(); diff --git a/src/main/java/com/biel/lobby/mapes/JocEquipsLastStanding.java b/src/main/java/com/biel/lobby/mapes/JocEquipsLastStanding.java index d1cc9c6..2ce2b61 100644 --- a/src/main/java/com/biel/lobby/mapes/JocEquipsLastStanding.java +++ b/src/main/java/com/biel/lobby/mapes/JocEquipsLastStanding.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import org.bukkit.ChatColor; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import com.biel.lobby.utilities.ScoreBoardUpdater; @@ -73,6 +74,7 @@ public void comprovarGuanyador(){ winnerTeam = getWinner(); sendGlobalMessage(ChatColor.GRAY + "L'equip " + winnerTeam.getChatColor() + winnerTeam.getAdjectiu() + ChatColor.GRAY + " ha guanyat la partida!"); winGame(winnerTeam); + getPlayers().forEach(player -> player.setGameMode(GameMode.SPECTATOR)); } if (AliveTeamIDs.size() == 0){ sendGlobalMessage(ChatColor.YELLOW + "No hi ha guanyadors!"); diff --git a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java index a02b091..24531b4 100644 --- a/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java +++ b/src/main/java/com/biel/lobby/mapes/jocs/BedWars.java @@ -3,7 +3,6 @@ import com.biel.BielAPI.Utils.GUtils; import com.biel.BielAPI.Utils.Regions.Cuboid; import com.biel.lobby.mapes.JocEquipsLastStanding; -import com.biel.lobby.mapes.JocObjectius; import com.biel.lobby.utilities.BUtils; import com.biel.lobby.utilities.ScoreBoardUpdater; import com.biel.lobby.utilities.Utils; @@ -15,13 +14,13 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.List; import java.util.Optional; public class BedWars extends JocEquipsLastStanding { @@ -32,12 +31,14 @@ public class BedWars extends JocEquipsLastStanding { @Override protected void customJocIniciat() { + super.customJocIniciat(); - Equips.stream() - .map(e -> (EquipBedWars)e) - .forEach(EquipBedWars::detectBed); + + Equips.stream().map(e -> (EquipBedWars)e).forEach(EquipBedWars::detectBed); setBlockBreakPlace(true); setGiveStartingItemsRespawn(true); + updateScoreBoards(); + } @Override @@ -45,8 +46,8 @@ protected ArrayList getDesiredTeams() { ArrayList equips = new ArrayList<>(); - equips.add(new EquipBedWars(DyeColor.RED, "vermell")); - equips.add(new EquipBedWars(DyeColor.BLUE, "blau")); + equips.add(new EquipBedWars(DyeColor.ORANGE, "taronja")); + equips.add(new EquipBedWars(DyeColor.GREEN, "verd")); return equips; @@ -72,8 +73,8 @@ protected ArrayList getStartingItems(Player ply) { // Armor items.add(Utils.createColoredTeamArmor(Material.LEATHER_CHESTPLATE, e)); items.add(Utils.createColoredTeamArmor(Material.LEATHER_HELMET, e)); + items.add(new ItemStack(Material.IRON_LEGGINGS, 1)); items.add(Utils.createColoredTeamArmor(Material.LEATHER_BOOTS, e)); - items.add(Utils.createColoredTeamArmor(Material.LEATHER_LEGGINGS, e)); // Sword ItemStack sword = new ItemStack(Material.IRON_SWORD, 1); @@ -97,8 +98,8 @@ protected ArrayList getStartingItems(Player ply) { int block_amount = (int) (45 * balancingMultiplier); if (block_amount > 64) block_amount = 64; - if (obtenirEquip(ply).getId() == 0) items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 14)); - else items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 10)); + if (obtenirEquip(ply).getId() == 0) items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 1)); + else items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 5)); // Arrows int arrows = (int) (50 * balancingMultiplier); @@ -118,13 +119,19 @@ public EquipBedWars obtenirEquip(Player ply) { return obtenirEquip(ply, EquipBedWars.class); } + @Override + protected void updateScoreBoards() { + getPlayers().forEach(this::updateScoreBoard); + } @Override protected void updateScoreBoard(Player ply) { - super.updateScoreBoard(ply); - - if(!JocIniciat) return; + if(!JocIniciat) { + ArrayList list = new ArrayList<>(); + ScoreBoardUpdater.setScoreBoard(ply, ChatColor.BOLD + "" + ChatColor.RED + "Bed Wars", list, null); + return; + } ArrayList list = new ArrayList<>(); @@ -188,7 +195,7 @@ protected void onBlockHitByProjectile(ProjectileHitEvent evt, Block b, Projectil protected void onPlayerDeath(PlayerDeathEvent evt, Player killed) { super.onPlayerDeath(evt, killed); - Bukkit.broadcastMessage("isBedAlive: " + obtenirEquip(killed).isBedAlive()); + updateScoreBoards(); if(!obtenirEquip(killed).isBedAlive()) removeAlive(killed); } @@ -219,23 +226,22 @@ protected void onBlockBreak(BlockBreakEvent evt, Block blk) { } else { + blk.setType(Material.AIR); sendGlobalSound(Sound.ENTITY_ENDERDRAGON_GROWL, 100, 1); - String text = obtenirEquip(ply).getChatColor() == ChatColor.RED - ? ChatColor.GREEN + "S'ha destruit el llit " + ChatColor.BLUE + "blau" - : ChatColor.GREEN + "S'ha destruit el llit " + ChatColor.RED + "vermell"; + String text = obtenirEquip(ply).getId() == 0 + ? ChatColor.RED + "S'ha destruit el llit " + ChatColor.GREEN + "verd" + : ChatColor.RED + "S'ha destruit el llit " + ChatColor.GOLD + "taronja"; for (Player p : getPlayers()) { BountifulAPI.sendTitle(p, 10, 20, 10, "", text); } - } + updateScoreBoards(); - updateScoreBoards(); + } } - // Check if block has been placed by a player or was on the map by default - } public class EquipBedWars extends Equip { From ee8e6b624c2ec75975d27d9b359a38afd2b5de15 Mon Sep 17 00:00:00 2001 From: Biel Simon Rojas Date: Tue, 14 Aug 2018 19:23:08 +0200 Subject: [PATCH 4/4] Set DevelopmentState to Alpha --- src/main/java/com/biel/lobby/GestorMapes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/biel/lobby/GestorMapes.java b/src/main/java/com/biel/lobby/GestorMapes.java index e3a59c0..de22201 100644 --- a/src/main/java/com/biel/lobby/GestorMapes.java +++ b/src/main/java/com/biel/lobby/GestorMapes.java @@ -65,7 +65,7 @@ public GestorMapes() { Mapes.add(new ContenidorJoc(PilotaSplash.class, "Pilota Splash", Material.SLIME_BALL, DevelopmentState.Alpha)); //Mapes.add(new ContenidorJoc(TempleQuest.class, "Temple Quest", Material.QUARTZ_BLOCK, DevelopmentState.InDevelopment)); Mapes.add(new ContenidorJoc(OneInTheChamber.class, "OneInTheChamber", Material.BOW, DevelopmentState.Alpha)); - Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.BED, DevelopmentState.Beta)); + Mapes.add(new ContenidorJoc(BedWars.class, "Bed Wars", Material.BED, DevelopmentState.Alpha)); } public void queryAutoRatings() { auto_ratings = Com.getDataAPI().getAutoRating();