Skip to content

Commit

Permalink
More bedwars bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 4, 2024
1 parent acbee4e commit e771c95
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,12 @@ public void run() {
if (countdown > 0) {
player.sendMessage(Locale.MATCH_RESPAWN_TIMER.format(player, countdown));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 10, 1);
if(!gamePlayer.isRespawned()){
gamePlayer.setRespawned(false);
this.cancel();
}
countdown--;
} else {
showPlayer(playerUUID);
player.sendMessage(Locale.MATCH_RESPAWNED.format(player));
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1);
player.setAllowFlight(false);
Expand All @@ -429,9 +432,13 @@ public void run() {
Location spawn = aTeam ? getArena().getSpawnA() : getArena().getSpawnB();
player.teleport(spawn);
player.getInventory().setArmorContents(InventoryUtil.color(gamePlayer.getKitLoadout().getArmor(), aTeam ? Color.RED : Color.BLUE).toArray(new ItemStack[0]));
player.getInventory().setContents(gamePlayer.getKitLoadout().getContents());
//player.getInventory().setContents(gamePlayer.getKitLoadout().getContents());
player.getInventory().setContents(InventoryUtil.color(gamePlayer.getKitLoadout().getContents(), aTeam ? Color.RED : Color.BLUE).toArray(new ItemStack[0]));

player.setGameMode(GameMode.SURVIVAL);
gamePlayer.setRespawned(false);
PlayerUtil.setImmune(player, 30);
showPlayer(playerUUID);
this.cancel();
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,21 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {
}

Arena arena = match.getArena();
Location blockLocation = event.getBlockPlaced().getLocation();
int x = (int) event.getBlockPlaced().getLocation().getX();
int y = (int) event.getBlockPlaced().getLocation().getY();
int z = (int) event.getBlockPlaced().getLocation().getZ();
Location newBlockLocation = new Location(arena.getWorld(), x, y, z);
event.getPlayer().sendMessage(newBlockLocation.toString());
if (newBlockLocation.equals(new Location(arena.getSpawnA().getWorld(), (int) arena.getSpawnA().getX(), (int) arena.getSpawnA().getY(), (int) arena.getSpawnA().getZ()))
|| newBlockLocation.equals(new Location(arena.getSpawnB().getWorld(), (int) arena.getSpawnB().getX(), (int) arena.getSpawnB().getY(), (int) arena.getSpawnB().getZ()))
|| newBlockLocation.equals(new Location(arena.getSpawnA().getWorld(), (int) arena.getSpawnA().getX(), (int) arena.getSpawnA().getY() + 1, (int) arena.getSpawnA().getZ()))
|| newBlockLocation.equals(new Location(arena.getSpawnB().getWorld(), (int) arena.getSpawnB().getX(), (int) arena.getSpawnB().getY() + 1, (int) arena.getSpawnB().getZ()))){

event.getPlayer().sendMessage(CC.translate("&cYou cannot place block blocks here!"));
event.setCancelled(true);
return;
}

if (y > arena.getMaxBuildHeight()) {
event.getPlayer().sendMessage(CC.RED + "You have reached the maximum build height.");
Expand All @@ -100,7 +112,7 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {

if (x >= arena.getX1() && x <= arena.getX2() && y >= arena.getY1() && y <= arena.getY2() &&
z >= arena.getZ1() && z <= arena.getZ2()) {
match.getPlacedBlocks().add(event.getBlock().getLocation());
match.getPlacedBlocks().add(blockLocation);
} else {
event.getPlayer().sendMessage(CC.RED + "You cannot build outside of the arena!");
event.setCancelled(true);
Expand Down Expand Up @@ -704,7 +716,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
profile.getMatch().getGamePlayer(player).setKitLoadout(kitLoadout);
GameParticipant<MatchGamePlayer> participantA = match.getParticipantA();
player.getInventory().setArmorContents(InventoryUtil.color(kitLoadout.getArmor(), participantA.containsPlayer(player.getUniqueId()) ? Color.RED : Color.BLUE).toArray(new ItemStack[0]));
player.getInventory().setContents(kitLoadout.getContents());
player.getInventory().setContents(InventoryUtil.color(kitLoadout.getContents(), participantA.containsPlayer(player.getUniqueId()) ? Color.RED : Color.BLUE).toArray(new ItemStack[0]));
player.updateInventory();
event.setCancelled(true);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/lrxh/practice/util/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -256,6 +257,12 @@ public static List<ItemStack> color(ItemStack[] itemStackList, Color color) {
LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta();
meta.setColor(color);
itemStack.setItemMeta(meta);
} else if (itemStack.getType() == Material.WOOL) {
if (color.equals(Color.BLUE)){
itemStack.setDurability((short) 11);
}else{
itemStack.setDurability((short) 14);
}
}
items.add(itemStack);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/lrxh/practice/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void setLastAttacker(Player victim, Player attacker) {
victim.setMetadata("lastAttacker", new FixedMetadataValue(Practice.getInstance(), attacker.getUniqueId()));
}

public static void setImmune(Player player, int ticks) {
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, ticks, 250));
}

public Player getLastAttacker(Player victim) {
if (victim.hasMetadata("lastAttacker")) {
return Bukkit.getPlayer((UUID) victim.getMetadata("lastAttacker").get(0).value());
Expand Down

0 comments on commit e771c95

Please sign in to comment.