Skip to content

Commit

Permalink
Quality of live improvements to bedwars
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 4, 2024
1 parent 5e45820 commit 7182ab8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum Locale {
MATCH_PLAYER_KILLED("MATCH.PLAYER_KILLED"),
MATCH_PLAYER_FINAL_KILL("MATCH.PLAYER_FINAL_KILL"),
MATCH_PLAYER_DIED("MATCH.PLAYER_DIED"),
MATCH_PLAYER_DIED_FINAL("MATCH.PLAYER_DIED_FINAL"),
REMATCH_SENT_REQUEST("REMATCH.SENT_REQUEST"),
REMATCH_RECEIVED_REQUEST("REMATCH.RECEIVED_REQUEST"),
REMATCH_RECEIVED_REQUEST_HOVER("REMATCH.RECEIVED_REQUEST_HOVER"),
Expand Down
32 changes: 8 additions & 24 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,19 @@ public void end() {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (!gamePlayer.isDisconnected()) {
if (player != null) {
player.setFireTicks(0);
player.updateInventory();

Profile profile = Profile.getByUuid(player.getUniqueId());
profile.setState(ProfileState.LOBBY);
profile.setMatch(null);
profile.setEnderpearlCooldown(new Cooldown(0));
PlayerUtil.allowMovement(gamePlayer.getPlayer());
player.sendMessage(CC.translate("&cEnemy &7committed suicide."));
VisibilityLogic.handle(player);
Practice.getInstance().getHotbar().giveHotbarItems(player);
PlayerUtil.teleportToSpawn(player);
PlayerUtil.allowMovement(gamePlayer.getPlayer());
}
}
}
}

Expand Down Expand Up @@ -373,6 +369,7 @@ public void respawn(UUID playerUUID) {
gamePlayer.setRespawned(true);

sendDeathMessage(player, PlayerUtil.getLastAttacker(player), false);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1);
player.addPotionEffect(
new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 0));

Expand All @@ -382,28 +379,23 @@ public void respawn(UUID playerUUID) {
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);

player.setVelocity(player.getVelocity().add(new Vector(0, 0.25, 0)));
player.setAllowFlight(true);
player.setFlying(true);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.15, 0)));
player.setAllowFlight(true);
player.setFlying(true);
PlayerUtil.doVelocityChange(player);

new BukkitRunnable() {
int countdown = 3;

@Override
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 {
player.sendMessage(Locale.MATCH_RESPAWNED.format(player));
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1);
player.playSound(player.getLocation(), Sound.FALL_BIG, 1.0f, 1.0f);
player.setAllowFlight(false);
player.setFlying(false);
boolean aTeam = getParticipantA().containsPlayer(player.getUniqueId());
Expand Down Expand Up @@ -464,7 +456,6 @@ public void showPlayer(UUID playerUUID) {
public abstract boolean canEndRound();

public void onDisconnect(Player dead) {
// Don't continue if the match is already ending
if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) {
return;
}
Expand All @@ -479,7 +470,6 @@ public void onDisconnect(Player dead) {
}
}
end();
sendDeathMessage(dead, null, false);
}

public void onDeath(Player dead) {
Expand Down Expand Up @@ -530,14 +520,6 @@ public void onDeath(Player dead) {
break;
}
}
dead.setHealth(dead.getMaxHealth());
dead.setFoodLevel(20);
dead.setVelocity(dead.getVelocity().add(new Vector(0, 0.25, 0)));
dead.setAllowFlight(true);
dead.setFlying(true);
dead.setVelocity(dead.getVelocity().add(new Vector(0, 0.15, 0)));
dead.setAllowFlight(true);
dead.setFlying(true);

// Store snapshot of player inventory and stats
MatchSnapshot snapshot = new MatchSnapshot(dead, true);
Expand All @@ -555,6 +537,8 @@ public void onDeath(Player dead) {
// Reset inventory
PlayerUtil.reset(dead);

PlayerUtil.doVelocityChange(dead);

// Handle visibility for match players
// Send death message
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
Expand Down Expand Up @@ -776,7 +760,7 @@ public void sendDeathMessage(Player dead, Player killer, boolean finalKill) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
Player player = gamePlayer.getPlayer();
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player,
deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
Expand All @@ -791,7 +775,7 @@ public void sendDeathMessage(Player dead, Player killer, boolean finalKill) {

for (Player player : getSpectatorsAsPlayers()) {
if (killer == null) {
deathMessage = Locale.MATCH_PLAYER_FINAL_KILL.format(player,
deathMessage = Locale.MATCH_PLAYER_DIED_FINAL.format(player,
getRelationColor(player, dead) + dead.getName()
);
} else {
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.util.*;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -62,6 +59,11 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) {
if (profile.getMatch().kit.getGameRules().isBedwars()) {
if (!(player.getLocation().getY() >= match.getArena().getDeathZone()) && !match.getGamePlayer(player).isRespawned()) {
if (!bedGone) {

if(PlayerUtil.getLastAttacker(player) != null){
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}

match.respawn(player.getUniqueId());
} else {
profile.getMatch().onDeath(player);
Expand Down Expand Up @@ -191,8 +193,12 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
return;
}

match.sendSound(Sound.ORB_PICKUP, 1.0F, 1.0F);
match.sendSound(Sound.WITHER_DEATH, 1.0F, 1.0F);
match.broadcast(" ");
match.broadcast(Locale.MATCH_BED_BROKEN.format(player, aTeam ? CC.translate("&9Blue") : CC.translate("&cRed"),
aTeam ? CC.translate("&c" + player.getName()) : CC.translate("&9" + player.getName())));
match.broadcast(" ");
}

if (match.getKit().getGameRules().isBuild() && match.getState() == MatchState.PLAYING_ROUND) {
Expand Down Expand Up @@ -276,7 +282,7 @@ public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) {
event.setCancelled(true);
return;
}
if (event.getItem().getItemStack().getType().equals(Material.ENDER_STONE) || (event.getItem().getItemStack().getType().equals(Material.WOOD))) {
if (event.getItem().getItemStack().getType().equals(Material.ENDER_STONE) || (event.getItem().getItemStack().getType().equals(Material.WOOD) || event.getItem().getItemStack().getType().equals(Material.WOOL))) {

event.setCancelled(false);
return;
Expand Down Expand Up @@ -341,7 +347,6 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {

if (profile.getState() == ProfileState.FIGHTING) {


Match match = profile.getMatch();
event.getDrops().clear();

Expand All @@ -352,6 +357,11 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {
if (profile.getMatch().getKit().getGameRules().isBedwars()) {
event.getDrops().clear();
if (!bedGone) {

if(PlayerUtil.getLastAttacker(player) != null){
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}

match.respawn(player.getUniqueId());
} else {
profile.getMatch().onDeath(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) {
}

if (profile.getMatch() != null) {
profile.getMatch().sendDeathMessage(event.getPlayer(), null, false);
profile.getMatch().end();

}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/me/lrxh/practice/util/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ public static void removeCrafting(Material material) {
public static List<ItemStack> color(ItemStack[] itemStackList, Color color) {
List<ItemStack> items = new ArrayList<>();
for (ItemStack itemStack : itemStackList) {
if(itemStack.getType()==null){
continue;
}
if (itemStack.getType() == Material.LEATHER_BOOTS || itemStack.getType() == Material.LEATHER_CHESTPLATE || itemStack.getType() == Material.LEATHER_HELMET
|| itemStack.getType() == Material.LEATHER_LEGGINGS) {
LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta();
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,27 @@ public static List<String> format(List<String> lines, Player player) {
line = line.replaceAll("<leader>", profile.getParty().getLeader().getName());
line = line.replaceAll("<party-size>", String.valueOf(profile.getParty().getListOfPlayers().size()));
}
Match match = profile.getMatch();
if(match != null) {
if (match.getOpponent(player.getUniqueId()) != null) {
line = line.replaceAll("<opponent>", match.getOpponent(player.getUniqueId()).getName());
line = line.replaceAll("<duration>", match.getDuration());
line = line.replaceAll("<opponent-ping>", String.valueOf(BukkitReflection.getPing(match.getOpponent(player.getUniqueId()))));
line = line.replaceAll("<your-hits>", String.valueOf(match.getGamePlayer(player).getHits()));
line = line.replaceAll("<their-hits>", String.valueOf(match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()));
line = line.replaceAll("<diffrence>", getDifference(player));

if (profile.getMatch() != null) {
Match match = profile.getMatch();
line = line.replaceAll("<opponent>", match.getOpponent(player.getUniqueId()).getName());
line = line.replaceAll("<duration>", match.getDuration());
line = line.replaceAll("<opponent-ping>", String.valueOf(BukkitReflection.getPing(match.getOpponent(player.getUniqueId()))));
line = line.replaceAll("<your-hits>", String.valueOf(match.getGamePlayer(player).getHits()));
line = line.replaceAll("<their-hits>", String.valueOf(match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()));
line = line.replaceAll("<diffrence>", getDifference(player));

if (match.getKit().getGameRules().isBedwars()) {
line = line.replaceAll("<bedA>", match.isBedABroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);
line = line.replaceAll("<bedB>", match.isBedBBroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);
if (match.getKit().getGameRules().isBedwars()) {
line = line.replaceAll("<bedA>", match.isBedABroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);
line = line.replaceAll("<bedB>", match.isBedBBroken() ? CC.RED + CC.X : CC.GREEN + CC.CHECKMARK);
}
}
}

if (profile.getState() == ProfileState.SPECTATING) {
Match match = profile.getMatch();
line = line.replaceAll("<duration>", match.getDuration());
if (profile.getState() == ProfileState.SPECTATING) {
line = line.replaceAll("<duration>", match.getDuration());
}
}


if (Practice.getInstance().isPlaceholder()) {
formattedLines.add(PlaceholderAPI.setPlaceholders(player, line));
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/me/lrxh/practice/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void reset(Player player) {
player.getInventory().setContents(new ItemStack[36]);
player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));
player.getInventory().setHeldItemSlot(0);

player.updateInventory();
}

Expand All @@ -112,6 +111,15 @@ public void applyFireballKnockback(Location location, List<Player> entities) {
}
}

public void doVelocityChange(Player player){
player.setVelocity(player.getVelocity().add(new Vector(0, 0.25, 0)));
player.setAllowFlight(true);
player.setFlying(true);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.15, 0)));
player.setAllowFlight(true);
player.setFlying(true);
}

public void denyMovement(Player player) {
if (player == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public void run() {
private void tick() {
for (Player player : this.assemble.getPlugin().getServer().getOnlinePlayers()) {
Profile profile = Profile.getByUuid(player.getUniqueId());
if (player != null) {
try {
try {
if (!profile.getOptions().showScoreboard()) {
return;
}
Expand Down Expand Up @@ -128,9 +127,8 @@ private void tick() {
} catch (Exception e) {
//Bukkit.getServer().getScheduler().runTask(assemble.getPlugin(), () -> player.kickPlayer(CC.translate("&cPlease rejoin.")));
Bukkit.getLogger().warning("Error updating scoreboard for player " + player.getName() + ": " + e.getMessage());
}

}
}
}

}
1 change: 1 addition & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ MATCH:
PLAYER_KILLED: '&a{1} &7killed &c{0}&7.'
PLAYER_DIED: '{0} &7committed suicide.'
PLAYER_FINAL_KILL: '&a{1} &7killed &c{0}&7. &b&lFINAL KILL'
PLAYER_DIED_FINAL: '{0} &7committed suicide. &b&lFINAL KILL'
ROUNDS_TO_WIN: ''
REMATCH:
SENT_REQUEST:
Expand Down

0 comments on commit 7182ab8

Please sign in to comment.