Skip to content
Merged

Dev #604

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
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
SpectatorManager.getInstance().getSpectators().get(player).removeSpectator(player);
}

// Update sender reference to the current online Player instance
// in case the original sender disconnected and rejoined since the request was sent.
request.setSender(target);
request.acceptRequest();
} else
Common.sendMMMessage(player, LanguageManager.getString("command.accept.player-not-available").replace("%target%", target.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import dev.nandi0813.practice.util.Cuboid;
import dev.nandi0813.practice.util.NumberUtil;
import dev.nandi0813.practice.util.fightmapchange.FightChangeOptimized;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.damage.DamageSource;
Expand Down Expand Up @@ -198,8 +197,6 @@ protected static void arrowDisplayHearth(Player shooter, Player target, double f
.replace("%health%", String.valueOf(health)));
}

private static final String FFA_DEATH_ANIMATION_ENABLED_PATH = "FFA.DEATH-ANIMATION.ENABLED";

private static final boolean ALLOW_DESTROYABLE_BLOCK = ConfigManager.getBoolean("FFA.ALLOW-DESTROYABLE-BLOCK");

/**
Expand Down Expand Up @@ -379,10 +376,7 @@ public void onPlayerDeath(PlayerDeathEvent e) {
e.setDroppedExp(0);
e.setKeepInventory(true);
e.setKeepLevel(true);
e.setDeathMessage(null);

boolean playVanillaDeathAnimation = ConfigManager.getConfig().getBoolean(FFA_DEATH_ANIMATION_ENABLED_PATH, true);
e.setCancelled(!playVanillaDeathAnimation);
e.setCancelled(true);

DamageSource damageSource = e.getDamageSource();

Expand All @@ -398,43 +392,17 @@ public void onPlayerDeath(PlayerDeathEvent e) {
if (cause == DeathCause.EXPLOSION && killer != null && !killer.equals(player)) {
cause = DeathCause.EXPLOSION_BY_PLAYER;
}
ffa.killPlayer(player, killer, cause.getMessage().replace("%killer%", killer != null ? killer.getName() : "Unknown"));

Player finalKiller = killer;
DeathCause finalCause = cause;

Runnable deathTask = () -> {
if (playVanillaDeathAnimation && player.isOnline() && player.isDead()) {
player.spigot().respawn();
}
ffa.killPlayer(player, finalKiller, finalCause.getMessage().replace("%killer%", finalKiller != null ? finalKiller.getName() : "Unknown"));

if (finalKiller != null && !finalKiller.equals(player)) {
Statistic statistic = ffa.getStatistics().computeIfAbsent(
finalKiller,
p -> new Statistic(ProfileManager.getInstance().getUuids().get(p))
);
statistic.setKills(statistic.getKills() + 1);
}
};

if (playVanillaDeathAnimation) {
long delayTicks = 15L;
Bukkit.getScheduler().runTaskLater(ZonePractice.getInstance(), deathTask, delayTicks);
} else {
deathTask.run();
if (killer != null && !killer.equals(player)) {
Statistic statistic = ffa.getStatistics().computeIfAbsent(
killer,
p -> new Statistic(ProfileManager.getInstance().getUuids().get(p))
);
statistic.setKills(statistic.getKills() + 1);
}
}

@EventHandler
public void onFFARespawn(PlayerRespawnEvent e) {
Player player = e.getPlayer();

FFA ffa = FFAManager.getInstance().getFFAByPlayer(player);
if (ffa == null) return;

e.setRespawnLocation(player.getLocation());
}

private Player resolveKiller(Player victim, FFA ffa, DamageSource damageSource) {
Player killer = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import dev.nandi0813.practice.manager.fight.match.runnable.game.BridgeArrowRunnable;
import dev.nandi0813.practice.manager.fight.match.util.KnockbackUtil;
import dev.nandi0813.practice.manager.fight.match.util.MatchFightPlayer;

import dev.nandi0813.practice.manager.fight.match.util.TeamUtil;
import dev.nandi0813.practice.manager.fight.util.*;
import dev.nandi0813.practice.manager.fight.util.Stats.Statistic;
Expand Down Expand Up @@ -51,6 +50,7 @@

import static dev.nandi0813.practice.manager.arena.util.ArenaUtil.containsDestroyableBlock;
import static dev.nandi0813.practice.util.PermanentConfig.FIGHT_ENTITY;
import static dev.nandi0813.practice.util.PermanentConfig.PLACED_IN_FIGHT;

public class LadderTypeListener implements Listener {

Expand All @@ -59,7 +59,6 @@ public class LadderTypeListener implements Listener {
private static final String SHIELD_STUN_DURATION_PATH = AXE_LADDER_SETTINGS_PATH + ".SHIELD-STUN.DURATION-TICKS";
private static final String SHIELD_STUN_REQUIRE_AXE_PATH = AXE_LADDER_SETTINGS_PATH + ".SHIELD-STUN.REQUIRE-AXE";
private static final String SHIELD_SKIP_VANILLA_TICK_PATH = AXE_LADDER_SETTINGS_PATH + ".SKIP-VANILLA-DAMAGE-TICK-WHEN-SHIELD-BLOCKED";
private static final String DEATH_ANIMATION_ENABLED_PATH = "MATCH-SETTINGS.DEATH-ANIMATION.ENABLED";
private static final int SKYWARS_KILLER_EXP_LEVEL_REWARD = 5;
private static final int SKYWARS_ENCHANT_LAPIS_AMOUNT = 3;

Expand Down Expand Up @@ -196,6 +195,7 @@ private static void enforceShieldDamageTickBypass(Player target) {
// Run one tick later so vanilla cannot restore the damage immunity window.
Bukkit.getScheduler().runTask(ZonePractice.getInstance(), () -> {
if (!target.isOnline() || target.isDead()) {
return;
}
});
}
Expand Down Expand Up @@ -680,10 +680,7 @@ public void onPlayerDeath(PlayerDeathEvent e) {
e.setDroppedExp(0);
e.setKeepInventory(true);
e.setKeepLevel(true);
e.deathMessage(null);

boolean playVanillaDeathAnimation = ConfigManager.getConfig().getBoolean(DEATH_ANIMATION_ENABLED_PATH, true);
e.setCancelled(!playVanillaDeathAnimation);
e.setCancelled(true);

DamageSource damageSource = e.getDamageSource();
Player killer;
Expand All @@ -694,18 +691,8 @@ public void onPlayerDeath(PlayerDeathEvent e) {
}

DeathCause cause = FightUtil.convert(damageSource.getDamageType());
if (cause == DeathCause.EXPLOSION && killer != null && !killer.equals(player)) {
cause = DeathCause.EXPLOSION_BY_PLAYER;
}
DeathCause finalCause = cause;

long delayTicks = playVanillaDeathAnimation ? 15L : 1L;
Bukkit.getScheduler().runTaskLater(ZonePractice.getInstance(), () -> {
if (playVanillaDeathAnimation && player.isOnline() && player.isDead()) {
player.spigot().respawn();
}
match.killPlayer(player, killer, finalCause.getMessage().replace("%killer%", killer != null ? killer.getName() : "Unknown"));
}, delayTicks);
Bukkit.getScheduler().runTaskLater(ZonePractice.getInstance(), () ->
match.killPlayer(player, killer, cause.getMessage().replace("%killer%", killer != null ? killer.getName() : "Unknown")), 1L);

if (killer != null) {
Statistic statistic = match.getCurrentStat(killer);
Expand All @@ -719,16 +706,6 @@ public void onPlayerDeath(PlayerDeathEvent e) {
}
}

@EventHandler
public void onMatchRespawn(PlayerRespawnEvent e) {
Player player = e.getPlayer();

Match match = MatchManager.getInstance().getLiveMatchByPlayer(player);
if (match == null) return;

e.setRespawnLocation(player.getLocation());
}

private static void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
if (!(e.getEntity() instanceof Player target)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.nandi0813.practice.manager.fight.match.Match;
import dev.nandi0813.practice.manager.fight.match.MatchManager;
import dev.nandi0813.practice.manager.fight.match.enums.MatchStatus;
import dev.nandi0813.practice.manager.fight.match.enums.TeamEnum;
import dev.nandi0813.practice.manager.fight.match.interfaces.Team;
import dev.nandi0813.practice.manager.fight.match.util.MatchFightPlayer;
Expand Down Expand Up @@ -59,6 +60,9 @@ public void onPlayerTeleport(PlayerTeleportEvent e) {
Match match = MatchManager.getInstance().getLiveMatchByPlayer(e.getPlayer());
if (match == null) return;

if (match.getStatus().equals(MatchStatus.END) || match.getStatus().equals(MatchStatus.OVER))
return;

if (!match.getArena().getCuboid().contains(e.getTo()))
e.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ private void placeQuickMatchItem(Inventory inventory, ItemStack filler, int actu
private void placeCategorySelectors(Inventory inventory, CategoryConfig currentCategory,
List<CategoryConfig> allCategories, int actualSize, String guiPath) {
for (CategoryConfig category : allCategories) {
if (category.iconDisabled()) {
continue;
}

int selectorSlot = category.selectorSlot();
if (selectorSlot < 0 || selectorSlot >= actualSize) {
continue;
Expand Down Expand Up @@ -690,6 +694,7 @@ private List<CategoryConfig> loadCategories(String queuePath) {

String iconMaterial = ConfigManager.getString(categoryPath + ".ICON-MATERIAL");
String selectedIconMaterial = ConfigManager.getString(categoryPath + ".SELECTED-ICON-MATERIAL");
boolean iconDisabled = ConfigManager.getBoolean(categoryPath + ".ICON-DISABLED");

categories.add(new CategoryConfig(
categoryKey,
Expand All @@ -698,7 +703,8 @@ private List<CategoryConfig> loadCategories(String queuePath) {
iconMaterial,
selectedIconMaterial,
ladders,
new ArrayList<>(ladderSlots)
new ArrayList<>(ladderSlots),
iconDisabled
));
}

Expand Down Expand Up @@ -769,7 +775,8 @@ private NormalLadder getRandomQuickMatchLadder(Map<Integer, NormalLadder> ladder

private record CategoryConfig(String key, String displayName, int selectorSlot,
String iconMaterial, String selectedIconMaterial,
List<String> ladderNames, List<Integer> ladderSlots) {
List<String> ladderNames, List<Integer> ladderSlots,
boolean iconDisabled) {
}
/**
* Replaces %in_queue% and %in_fight% in a Component using Adventure's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ protected Hologram(String name, HologramType hologramType) {
}
}

// ABSTRACT METHODS

public abstract void getAbstractData(YamlConfiguration config);
public abstract void setAbstractData(YamlConfiguration config);
public abstract boolean isReadyToEnable();
public abstract Leaderboard getNextLeaderboard();

// DATA PERSISTENCE

public void getData() {
enabled = config.getBoolean("holograms." + name + ".enabled", false);

Expand Down Expand Up @@ -143,8 +139,6 @@ public void moveTo(@NotNull Location location) {
this.baseLocation = location.clone().subtract(0, 2, 0);
}

// CORE MANAGEMENT

/**
* Despawns all hologram lines and clears state.
*/
Expand Down Expand Up @@ -236,8 +230,6 @@ else if (textLines.size() < lines.size()) {
}
}

// UPDATE LOGIC

/**
* Main update method - handles leaderboard changes and content updates.
*/
Expand Down Expand Up @@ -291,8 +283,6 @@ private void handleEmptyLeaderboard() {
}
}

// TEXT BUILDING

private List<String> buildTextLines(@NotNull Leaderboard leaderboard) {
List<String> configLines = getConfigLines(leaderboard);

Expand Down Expand Up @@ -385,8 +375,6 @@ private String formatPlayerEntry(OfflinePlayer player, Map<OfflinePlayer, Intege
.replace("%group%", group != null ? group.getDisplayName() : ""));
}

// SETUP HOLOGRAMS

/**
* Shows a setup/placeholder hologram.
*/
Expand Down Expand Up @@ -420,8 +408,6 @@ public synchronized void setSetupHologram(@NotNull SetupHologramType type) {
updateSmartly(setupLines, spacings);
}

// DELETION

/**
* Deletes the hologram completely.
*/
Expand All @@ -437,8 +423,6 @@ public synchronized void deleteHologram(boolean removeFromManager) {
}
}

// ENABLE/DISABLE

public void setEnabled(boolean enabled) {
if (enabled && isReadyToEnable()) {
this.enabled = true;
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION: 64
VERSION: 66

# Mysql database setup.
MYSQL-DATABASE:
Expand Down Expand Up @@ -91,6 +91,7 @@ QUEUE:
DISPLAY-NAME: "PVP"
ICON-MATERIAL: "DIAMOND_SWORD"
SELECTED-ICON-MATERIAL: "NETHERITE_SWORD"
ICON-DISABLED: false
LADDERS:
- "SPEARMACE"
- "MACE"
Expand All @@ -111,6 +112,7 @@ QUEUE:
DISPLAY-NAME: "MINIGAMES"
ICON-MATERIAL: "SLIME_BALL"
SELECTED-ICON-MATERIAL: "TNT"
ICON-DISABLED: false
LADDERS:
- "SUMO"
- "TNTSUMO"
Expand Down Expand Up @@ -162,6 +164,7 @@ QUEUE:
DISPLAY-NAME: "PVP"
ICON-MATERIAL: "DIAMOND_SWORD"
SELECTED-ICON-MATERIAL: "NETHERITE_SWORD"
ICON-DISABLED: false
LADDERS:
- "SPEARMACE"
- "MACE"
Expand All @@ -182,6 +185,7 @@ QUEUE:
DISPLAY-NAME: "MINIGAMES"
ICON-MATERIAL: "SLIME_BALL"
SELECTED-ICON-MATERIAL: "TNT"
ICON-DISABLED: false
LADDERS:
- "SUMO"
- "TNTSUMO"
Expand Down Expand Up @@ -386,8 +390,6 @@ MATCH-SETTINGS:
ENABLED: true
DURATION-TICKS: 100
REQUIRE-AXE: true
DEATH-ANIMATION:
ENABLED: false # If true, plays the vanilla death animation before respawning the player.
DISPLAY-ARROW-HIT-HEALTH: true # If true, the player will see the health of the player they hit.
#
# FFA settings
Expand All @@ -399,8 +401,6 @@ FFA:
DISPLAY-ARROW-HIT-HEALTH: true # If true, the player will see the health of the player they hit.
ALLOW-DESTROYABLE-BLOCK: true # If true, player can destroy the fixed blocks in the arena that their ladder has.
ENABLE_TNT: true # If true, players can use TNT in the arena (ONLY IN BUILD MODE).
DEATH-ANIMATION:
ENABLED: false # If true, plays the vanilla death animation before respawning in FFA.
#
# Spectator settings
SPECTATOR-SETTINGS:
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/resources/guis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION: 37
VERSION: 38

GENERAL-FILLER-ITEM:
NAME: " "
Expand Down Expand Up @@ -1061,6 +1061,8 @@ GUIS:
NAME: "<dark_purple>Ladder Effects"
MATERIAL: POTION
DAMAGE: 8233
FLAGS:
- HIDE_POTION_EFFECTS
LORE:
- "<dark_gray><st>------------------------"
- "<gray>This ladder has no effects."
Expand All @@ -1071,6 +1073,8 @@ GUIS:
NAME: "<dark_purple>Ladder Effects"
MATERIAL: POTION
DAMAGE: 8233
FLAGS:
- HIDE_POTION_EFFECTS
LORE:
- "<dark_gray><st>------------------------"
- "<yellow>You will get these effects,"
Expand Down