Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/biel/lobby/GestorMapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.Alpha));
}
public void queryAutoRatings() {
auto_ratings = Com.getDataAPI().getAutoRating();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/biel/lobby/mapes/JocEquipsLastStanding.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Això aniria a customJocFinalitzat(), a BedWars.java

}
if (AliveTeamIDs.size() == 0){
sendGlobalMessage(ChatColor.YELLOW + "No hi ha guanyadors!");
Expand Down
246 changes: 213 additions & 33 deletions src/main/java/com/biel/lobby/mapes/jocs/BedWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,54 @@
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;
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.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 {

/*
General
*/

@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
protected ArrayList<Equip> getDesiredTeams() {

ArrayList<Equip> 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;

}

@Override
Expand All @@ -47,53 +62,218 @@ protected void setCustomGameRules() {
public String getGameName() {
return "BedWars";
}

@Override
protected ArrayList<ItemStack> getStartingItems(Player ply) {

ArrayList<ItemStack> 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(new ItemStack(Material.IRON_LEGGINGS, 1));
items.add(Utils.createColoredTeamArmor(Material.LEATHER_BOOTS, 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) 1));
else items.add(new ItemStack(Material.STAINED_CLAY, block_amount, (short) 5));

// 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 updateScoreBoards() {
getPlayers().forEach(this::updateScoreBoard);
}

@Override
protected void updateScoreBoard(Player ply) {

if(!JocIniciat) {
ArrayList<String> list = new ArrayList<>();
ScoreBoardUpdater.setScoreBoard(ply, ChatColor.BOLD + "" + ChatColor.RED + "Bed Wars", list, null);
return;
}

ArrayList<String> 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);
if (BUtils.isGlassBlock(b)) {

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);

if (BUtils.isGlassBlock(b)) {
relative.setType(Material.AIR);
}

}
}
}

@Override
protected void onPlayerDeath(PlayerDeathEvent evt, Player killed) {

super.onPlayerDeath(evt, killed);
updateScoreBoards();
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 {

blk.setType(Material.AIR);
sendGlobalSound(Sound.ENTITY_ENDERDRAGON_GROWL, 100, 1);
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();

}

}

}

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<Block> 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); }

}
}
12 changes: 12 additions & 0 deletions src/main/java/com/biel/lobby/utilities/BUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ public static ArrayList<Block> locListToBlock(List<Location> 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
);

}

}