Skip to content

Commit

Permalink
Fixed a lot of bugs and added Titles for matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 5, 2024
1 parent e7e2c1f commit fdc608d
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public enum Locale {
OPTIONS_SHOW_PLAYERS_ENABLED("OPTIONS.SHOWPLAYERS_ENABLED"),
OPTIONS_SHOW_PLAYERS_DISABLED("OPTIONS.SHOWPLAYERS_DISABLED"),
SILENT_ENABLED("OPTIONS.SILENT_ENABLED"),
STAFF_MODE_ENABLE("OPTIONS.STAFF_MODE_ENABLE"),
STAFF_MODE_DISABLE("OPTIONS.STAFF_MODE_DISABLE"),
FOLLOW_START("FOLLOW.FOLLOW_START"),
FOLLOW_END("FOLLOW.FOLLOW_END"),
FOLLOWED_LEFT("FOLLOW.FOLLOWED_LEFT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public void pingOthers(Player player, String otherPlayer) {
return;
}
if (Bukkit.getPlayer(otherPlayer).equals(player)) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't follow yourself!"));
player.sendMessage(CC.translate("&4ERROR - &cYou cannot follow yourself!"));
return;
}
Player otherP = Bukkit.getPlayer(otherPlayer);

Profile playerProfile = Profile.getProfiles().get(player.getUniqueId());
if (!playerProfile.getFollowing().isEmpty() && !playerProfile.getFollowing().contains(otherP.getUniqueId())) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't follow multiple players!"));
player.sendMessage(CC.translate("&4ERROR - &cYou cannot follow multiple players!"));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public void create(Player player) {
return;
}


Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getParty() != null) {
player.sendMessage(CC.RED + "You already have a party.");
return;
}


if (profile.getState() != ProfileState.LOBBY) {
player.sendMessage(CC.RED + "You must be in the lobby to create a party.");
return;
Expand Down Expand Up @@ -174,6 +176,7 @@ public void join(Player player, String playerName) {
return;
}


if (player.hasMetadata("frozen")) {
player.sendMessage(CC.RED + "You cannot join a party while frozen.");
return;
Expand All @@ -186,6 +189,7 @@ public void join(Player player, String playerName) {
return;
}


Profile targetProfile = Profile.getByUuid(target.getUniqueId());
Party party = targetProfile.getParty();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/kit/command/KitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void setinv(Player player, String kitName) {
}

if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't set inv in create!"));
player.sendMessage(CC.translate("&4ERROR - &cYou cannot set inv in creative mode!"));
return;
}
Kit kit = Kit.getByName(kitName);
Expand Down
53 changes: 22 additions & 31 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
Expand Down Expand Up @@ -159,11 +157,6 @@ public void setupPlayer(Player player) {
// Reset the player's inventory
PlayerUtil.reset(player);

if (kit.getGameRules().isShowHealth()) {


}


// Set the player's max damage ticks
player.setMaximumNoDamageTicks(getKit().getGameRules().getHitDelay());
Expand Down Expand Up @@ -269,7 +262,7 @@ public void end() {
PlayerUtil.teleportToSpawn(player);
PlayerUtil.allowMovement(gamePlayer.getPlayer());
Objective objective = player.getScoreboard().getObjective(DisplaySlot.BELOW_NAME);

profile.setMatch(null);
if (objective != null) {
objective.unregister();
}
Expand Down Expand Up @@ -358,19 +351,11 @@ public void onRoundEnd() {
// Send ending messages to spectators
for (Player player : getSpectatorsAsPlayers()) {
for (BaseComponent[] components : endingMessages) {
player.spigot().sendMessage(components);
player.sendMessage(components);
}

removeSpectator(player);
}
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
Profile profile = Profile.getByUuid(gamePlayer.getPlayer().getUniqueId());
profile.setMatch(null);
}
}
}
}

public void respawn(UUID playerUUID) {
Expand All @@ -388,9 +373,6 @@ public void respawn(UUID playerUUID) {

sendDeathMessage(player, PlayerUtil.getLastAttacker(player), false);

player.addPotionEffect(
new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 0));

player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.updateInventory();
Expand All @@ -406,6 +388,7 @@ public void respawn(UUID playerUUID) {
public void run() {
if (countdown > 0) {
player.sendMessage(Locale.MATCH_RESPAWN_TIMER.format(player, countdown));
PlayerUtil.sendTitle(player, CC.translate("&c" + countdown), "", 20);
if (!gamePlayer.isRespawned()) {
gamePlayer.setRespawned(false);
this.cancel();
Expand All @@ -422,11 +405,11 @@ public void run() {
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(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);
gamePlayer.setRespawned(false);
PlayerUtil.setImmune(player, 40);
PlayerUtil.sendTitle(player, CC.translate("&aRespawned!"), "", 20);
this.cancel();
}
}
Expand Down Expand Up @@ -499,7 +482,9 @@ public void onDeath(Player dead) {

MatchGamePlayer deadGamePlayer = getGamePlayer(dead);
Player killer = PlayerUtil.getLastAttacker(dead);

if (killer != null) {
PlayerUtil.sendTitle(dead, CC.translate("&cLOST!"), "&c" + killer.getName() + " &fwon the match!", 60);
}

// Don't continue if the player is already dead
if (deadGamePlayer.isDead()) {
Expand All @@ -511,11 +496,10 @@ public void onDeath(Player dead) {

// Get killer
if (killer != null) {

Profile killerProfile = Profile.getByUuid(killer.getUniqueId());
Location location = dead.getLocation();
killerProfile.getOptions().killEffect().execute(killer, location);
killerProfile.getOptions().killEffect().execute(killer, dead.getLocation());
PlayerUtil.setLastAttacker(killer, null);
PlayerUtil.sendTitle(killer, CC.translate("&aVICTORY!"), "&a" + killer.getName() + " &fwon the match!", 60);
killer.playSound(killer.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
}

Expand All @@ -532,10 +516,11 @@ public void onDeath(Player dead) {
// Add snapshot to list
snapshots.add(snapshot);

PlayerUtil.setLastAttacker(dead, null);

PlayerUtil.doVelocityChange(dead);
PlayerUtil.reset(dead);

PlayerUtil.setLastAttacker(dead, null);
PlayerUtil.doVelocityChange(dead);

// Handle visibility for match players
// Send death message
Expand Down Expand Up @@ -582,8 +567,6 @@ public void onDeath(Player dead) {
} else {
Practice.getInstance().getHotbar().giveHotbarItems(dead);
}
// Reset inventory
PlayerUtil.reset(dead);
}

public abstract boolean isOnSameTeam(Player first, Player second);
Expand Down Expand Up @@ -710,6 +693,14 @@ public void sendMessage(String message) {
}
}

public void sendTitle(String header, String footer, int duration) {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
PlayerUtil.sendTitle(gamePlayer.getPlayer(), header, footer, duration);
}
}
}

public void sendSound(Sound sound, float volume, float pitch) {
for (GameParticipant gameParticipant : getParticipants()) {
gameParticipant.sendSound(sound, volume, pitch);
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ public class MatchListener implements Listener {
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());
Match match = profile.getMatch();


if (profile.getMatch() != null) {
if (profile.getMatch().getKit().getGameRules().isSumo() ||
profile.getMatch().getKit().getGameRules().isSpleef()) {
Match match = profile.getMatch();
Location playerLocation = event.getPlayer().getLocation();
Block block = playerLocation.getBlock();

if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
match.onDeath(event.getPlayer());
}
}
if (profile.getMatch().getKit().getGameRules().isBedwars()) {
if (match.getKit().getGameRules().isBedwars()) {
Player player = event.getPlayer();
Match match = profile.getMatch();

boolean bedGone = match.getParticipantA().containsPlayer(player.getUniqueId()) ? match.bedBBroken : match.bedABroken;

Expand Down Expand Up @@ -344,7 +343,6 @@ public void onPlayerPickUpEvent(PlayerPickupItemEvent event) {
public void onPlayerDeathEvent(PlayerDeathEvent event) {
Player player = event.getEntity();
event.setDeathMessage(null);
player.getInventory().setContents(new ItemStack[36]);

Profile profile = Profile.getByUuid(event.getEntity().getUniqueId());

Expand Down Expand Up @@ -421,8 +419,8 @@ public void onPotionSplashEvent(PotionSplashEvent event) {
Player shooter = (Player) event.getPotion().getShooter();
Profile shooterData = Profile.getByUuid(shooter.getUniqueId());

if (shooterData.getState() == ProfileState.FIGHTING &&
shooterData.getMatch().getState() == MatchState.PLAYING_ROUND) {
if (shooterData.getMatch() != null &&
shooterData.getMatch().getState().equals(MatchState.PLAYING_ROUND)) {
if (event.getIntensity(shooter) <= 0.5D) {
shooterData.getMatch().getGamePlayer(shooter).incrementPotionsMissed();
}
Expand Down Expand Up @@ -581,7 +579,7 @@ public void onEntityDamageByEntityLow(EntityDamageByEntityEvent event) {
StringEscapeUtils.unescapeJava("❤")
));
}
if (match.getGamePlayer(attacker).isRespawned()) {
if (match.getGamePlayer(attacker).isRespawned() && match.getState().equals(MatchState.ENDING_MATCH)) {
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -610,6 +608,17 @@ public void onEntityDamageByEntityMonitor(EntityDamageByEntityEvent event) {
}
}

@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
Player attacker = (Player) event.getDamager();
Match match = Profile.getByUuid(attacker.getUniqueId()).getMatch();
if (match != null && match.getGamePlayer(attacker).isRespawned()) {
event.setCancelled(true);
}
}
}

@EventHandler
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event) {
if (event.getItem().getType() == Material.GOLDEN_APPLE) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/lrxh/practice/match/task/MatchLogicTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.lrxh.practice.match.participant.MatchGamePlayer;
import me.lrxh.practice.participant.GameParticipant;
import me.lrxh.practice.participant.GamePlayer;
import me.lrxh.practice.util.CC;
import me.lrxh.practice.util.PlayerUtil;
import org.bukkit.scheduler.BukkitRunnable;

Expand Down Expand Up @@ -58,6 +59,7 @@ public void run() {
}
} else {
match.sendMessage(Locale.MATCH_START_TIMER.format(nextAction, nextAction == 1 ? "" : "s"));
match.sendTitle(CC.translate("&e" + nextAction), "", 20);
if (match.getKit().getGameRules().isBoxing()) {
for (GameParticipant<MatchGamePlayer> players : match.getParticipants()) {
players.addSpeed();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/lrxh/practice/profile/ProfileListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.match.Match;
import me.lrxh.practice.match.MatchState;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.profile.meta.option.button.AllowSpectatorsOptionButton;
Expand Down Expand Up @@ -92,6 +93,11 @@ public void onEntityDamageEvent(EntityDamageEvent event) {
if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
PlayerUtil.teleportToSpawn((Player) event.getEntity());
}

Match match = profile.getMatch();
if (match != null && match.getState().equals(MatchState.ENDING_MATCH)) {
event.setCancelled(true);
}
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/me/lrxh/practice/profile/hotbar/Hotbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void init() {
hotbarItem.setSlot(config.getInt(path + "SLOT"));
if (section.equals("PARTY")) {
hotbarItem.setParty(true);
hotbarItem.setStaffmode(false);
} else {
hotbarItem.setState(ProfileState.valueOf(section));
}
Expand Down Expand Up @@ -70,17 +71,15 @@ public void giveHotbarItems(Player player) {

switch (profile.getState()) {
case LOBBY:
if (profile.getParty() == null) {
for (HotbarItem item : items.keySet()) {

for (HotbarItem item : items.keySet()) {
if (profile.getParty() == null) {
if (item.getState() != null && item.getState().equals(ProfileState.LOBBY) || item.equals(HotbarItem.KIT_EDITOR)) {
player.getInventory().setItem(item.getSlot(), items.get(item));
}
}
} else {
for (HotbarItem item : items.keySet()) {
if (item.isParty()) {
player.getInventory().setItem(item.getSlot(), items.get(item));
}
} else if (item.isParty()) {

player.getInventory().setItem(item.getSlot(), items.get(item));
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/lrxh/practice/profile/hotbar/HotbarItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public enum HotbarItem {
private int slot;
@Setter
private boolean party;
@Setter
private boolean staffmode;

HotbarItem(String command) {
this.command = command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ private String replaceLeaderboardPlaceholders(String line, Queue queue) {
public void clicked(Player player, ClickType clickType) {
Profile profile = Profile.getByUuid(player.getUniqueId());
if (!profile.getFollowing().isEmpty()) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't queue while following someone!"));
player.sendMessage(CC.translate("&4ERROR - &cYou cannot queue while following someone!"));
player.closeInventory();
return;
}

if (player.hasMetadata("frozen")) {
player.sendMessage(CC.RED + "You cannot queue while frozen.");
return;
Expand Down
Loading

0 comments on commit fdc608d

Please sign in to comment.