Skip to content

Commit

Permalink
Removed #respawn (causes lag) now using NMS
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Feb 15, 2024
1 parent 17e03ce commit 72f32f4
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ public void clicked(Player player, ClickType clickType) {
}

}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.funky.praxi.leaderboards;

import me.funky.praxi.Praxi;
import me.funky.praxi.profile.Profile;
import me.funky.praxi.util.CC;
import me.funky.praxi.util.Console;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -36,6 +38,10 @@ public void run() {

if (Leaderboard.getRefreshTime() <= 0) {
rested = false;
for (Profile profile : Profile.getProfiles().values()) {
profile.save();
}
Console.sendMessage(CC.translate("&aSaved Player Data!"));
Leaderboard.getEloLeaderboards().clear();
Leaderboard.setEloLeaderboards(Leaderboard.init());
for (Player player : Bukkit.getOnlinePlayers()) {
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/me/funky/praxi/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public void onDisconnect(Player dead) {
}

public void onDeath(Player dead) {
PlayerUtil.animateDeath(dead);
// Don't continue if the match is already ending
if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) {
return;
Expand Down Expand Up @@ -453,12 +454,6 @@ public void onDeath(Player dead) {
break;
}
}

// Respawn player if needed
if (dead.isDead()) {
dead.spigot().respawn();
}

// Prevent further movement
dead.setVelocity(new Vector());

Expand Down
14 changes: 5 additions & 9 deletions src/main/java/me/funky/praxi/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ public void onPlayerDropItemEvent(PlayerDropItemEvent event) {

@EventHandler
public void onPlayerDeathEvent(PlayerDeathEvent event) {
event.getEntity().spigot().respawn();
event.setDeathMessage(null);
event.getDrops().clear();

Expand All @@ -241,8 +240,6 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {
}
});

event.getDrops().clear();

profile.getMatch().getDroppedItems().addAll(entities);
profile.getMatch().onDeath(event.getEntity());
}
Expand Down Expand Up @@ -526,8 +523,8 @@ public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
@EventHandler(priority = EventPriority.MONITOR)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
Projectile projectile = event.getEntity();
ProjectileSource source = projectile.getShooter();

Expand All @@ -542,17 +539,16 @@ public void onProjectileLaunch(final ProjectileLaunchEvent event) {
return;
}

if (profile.isEnderpearlOnCooldown()) {
if (!profile.isEnderpearlOnCooldown()) {
profile.setEnderpearlCooldown(new Cooldown(16_000));
} else {
event.setCancelled(true);
String time = TimeUtil.millisToSeconds(profile.getEnderpearlCooldown().getRemaining());
shooter.sendMessage(Locale.MATCH_ENDERPEARL_COOLDOWN.format(shooter, time,
(time.equalsIgnoreCase("1.0") ? "" : "s")));
shooter.updateInventory();
return;
}

profile.setEnderpearlCooldown(new Cooldown(16_000));

}
}

Expand Down
56 changes: 31 additions & 25 deletions src/main/java/me/funky/praxi/match/menu/MatchDetailsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.funky.praxi.util.menu.Button;
import me.funky.praxi.util.menu.Menu;
import me.funky.praxi.util.menu.button.DisplayButton;
import me.funky.praxi.util.menu.filters.Filters;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand All @@ -26,9 +27,19 @@ public class MatchDetailsMenu extends Menu {

@Override
public String getTitle(Player player) {
return "&6Inventory of " + snapshot.getUsername();
return "&7Inventory of " + snapshot.getUsername();
}

@Override
public Filters getFilter() {
return Filters.FILL;
}

public boolean getFixedPositions() {
return false;
}


@Override
public Map<Integer, Button> getButtons(Player player) {
Map<Integer, Button> buttons = new HashMap<>();
Expand All @@ -42,15 +53,8 @@ public Map<Integer, Button> getButtons(Player player) {
}
}

for (int i = 0; i < snapshot.getArmor().length; i++) {
ItemStack itemStack = snapshot.getArmor()[i];

if (itemStack != null && itemStack.getType() != Material.AIR) {
buttons.put(39 - i, new DisplayButton(itemStack, true));
}
}

int pos = 45;
int pos = 46;

buttons.put(pos++, new HealthButton(snapshot.getHealth()));
buttons.put(pos++, new HungerButton(snapshot.getHunger()));
Expand All @@ -66,6 +70,8 @@ public Map<Integer, Button> getButtons(Player player) {
buttons.put(53, new SwitchInventoryButton(this.snapshot.getOpponent()));
}

buttons.put(46, new SwitchInventoryButton(this.snapshot.getUuid()));

return buttons;
}

Expand All @@ -82,7 +88,7 @@ private static class HealthButton extends Button {
@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.MELON)
.name("&dHealth: &e" + health + "/10 &4" + StringEscapeUtils.unescapeJava("❤"))
.name("&bHealth: &f" + health + "/10 &4" + StringEscapeUtils.unescapeJava("❤"))
.amount((int) (health == 0 ? 1 : health))
.clearFlags()
.build();
Expand All @@ -97,17 +103,17 @@ private static class EffectsButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
ItemBuilder builder = new ItemBuilder(Material.POTION).name("&aPotion Effects");
ItemBuilder builder = new ItemBuilder(Material.POTION).name("&bPotion Effects");

if (effects.isEmpty()) {
builder.lore("&dNo potion effects");
builder.lore("&bNo potion effects");
} else {
List<String> lore = new ArrayList<>();

effects.forEach(effect -> {
String name = PotionUtil.getName(effect.getType()) + " " + (effect.getAmplifier() + 1);
String duration = " (" + TimeUtil.millisToTimer((effect.getDuration() / 20) * 1000L) + ")";
lore.add("&d" + name + "&e" + duration);
lore.add("&b" + name + "&f" + duration);
});

builder.lore(lore);
Expand All @@ -129,8 +135,8 @@ public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.POTION)
.durability(16421)
.amount(potions == 0 ? 1 : potions)
.name("&aPotions")
.lore("&d" + name + " &ehad &a" + potions + " &epotion" + (potions == 1 ? "" : "s") + " left.")
.name("&bPotions")
.lore("&b" + name + " &fhad &b" + potions + " &fpotion" + (potions == 1 ? "" : "s") + " left.")
.clearFlags()
.build();
}
Expand All @@ -145,13 +151,13 @@ private static class StatisticsButton extends Button {
@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.PAPER)
.name("&aMatch Stats")
.name("&bMatch Stats")
.lore(Arrays.asList(
"&dHits: &e" + snapshot.getTotalHits(),
"&dLongest Combo: &e" + snapshot.getLongestCombo(),
"&dPotions Thrown: &e" + snapshot.getPotionsThrown(),
"&dPotions Missed: &e" + snapshot.getPotionsMissed(),
"&dPotion Accuracy: &e" + snapshot.getPotionAccuracy()
"&bHits: &f" + snapshot.getTotalHits(),
"&bLongest Combo: &f" + snapshot.getLongestCombo(),
"&bPotions Thrown: &f" + snapshot.getPotionsThrown(),
"&bPotions Missed: &f" + snapshot.getPotionsMissed(),
"&bPotion Accuracy: &f" + snapshot.getPotionAccuracy()
))
.clearFlags()
.build();
Expand All @@ -169,9 +175,9 @@ public ItemStack getButtonItem(Player player) {
MatchSnapshot snapshot = MatchSnapshot.getByUuid(opponent);

if (snapshot != null) {
return new ItemBuilder(Material.LEVER)
.name("&6Opponent's Inventory")
.lore("&eSwitch to &a" + snapshot.getUsername() + "&e's inventory")
return new ItemBuilder(Material.ARROW)
.name("&7Opponent's Inventory")
.lore("&fSwitch to &b" + snapshot.getUsername() + "&f's inventory")
.clearFlags()
.build();
} else {
Expand All @@ -193,7 +199,7 @@ private class HungerButton extends Button {
@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.COOKED_BEEF)
.name("&dHunger: &e" + hunger + "/20")
.name("&bHunger: &f" + hunger + "/20")
.amount(hunger == 0 ? 1 : hunger)
.clearFlags()
.build();
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/me/funky/praxi/match/task/MatchLogicTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.funky.praxi.match.task;

import lombok.Getter;
import lombok.Setter;
import me.funky.praxi.Locale;
import me.funky.praxi.match.Match;
Expand All @@ -15,8 +14,6 @@
public class MatchLogicTask extends BukkitRunnable {

private final Match match;
private int totalTicked;
@Getter
@Setter
private int nextAction;

Expand All @@ -32,7 +29,6 @@ public MatchLogicTask(Match match) {

@Override
public void run() {
totalTicked++;
nextAction--;
if (match.getState() == MatchState.STARTING_ROUND) {
if (match.getKit().getGameRules().isSumo()) {
Expand All @@ -46,6 +42,7 @@ public void run() {
match.onRoundStart();
match.setState(MatchState.PLAYING_ROUND);
match.sendMessage(Locale.MATCH_STARTED.format());
match.sendMessage(" ");
match.sendMessage(Locale.MATCH_WARNING.format());
match.sendSound(Sound.ORB_PICKUP, 1.0F, 1.0F);
if (match.getKit().getGameRules().isSumo()) {
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/me/funky/praxi/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import me.funky.praxi.queue.QueueProfile;
import me.funky.praxi.setting.Colors;
import me.funky.praxi.util.CC;
import me.funky.praxi.util.Console;
import me.funky.praxi.util.Cooldown;
import me.funky.praxi.util.InventoryUtil;
import org.bson.Document;
Expand Down Expand Up @@ -107,16 +106,6 @@ public void run() {
}
}.runTaskTimerAsynchronously(Praxi.getInstance(), 60L, 60L);

// Save every 5 minutes to prevent data loss
new BukkitRunnable() {
@Override
public void run() {
for (Profile profile : Profile.getProfiles().values()) {
profile.save();
Console.sendMessage(CC.translate("&aSaved Player Data!"));
}
}
}.runTaskTimerAsynchronously(Praxi.getInstance(), 6000L, 6000L);
}

public static Profile getByUuid(UUID uuid) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/me/funky/praxi/profile/hotbar/Hotbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class Hotbar {

Expand Down Expand Up @@ -49,10 +50,18 @@ public static void init() {
HotbarItem hotbarItem = HotbarItem.KIT_SELECTION;
ItemBuilder builder = new ItemBuilder(Material.ENCHANTED_BOOK);
builder.durability(0);
builder.name("&7» &6&l%KIT% &7«");
builder.name("&7» &a&l%KIT% &7«");
builder.lore("");
builder.clearFlags();
items.put(hotbarItem, builder.build());
for (HotbarItem kitEditorItem : items.keySet()) {
if (kitEditorItem.equals(HotbarItem.KIT_SELECTION)) {
String voteName = Hotbar.getItems().get(HotbarItem.KIT_SELECTION).getItemMeta().getDisplayName();
String[] nameSplit = voteName.split("%KIT%");
kitEditorItem.setPattern(
Pattern.compile("(" + nameSplit[0] + ")(.*)(" + (nameSplit.length > 1 ? nameSplit[1] : "") + ")"));
}
}
}

public static void giveHotbarItems(Player player) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/funky/praxi/queue/QueueThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public void run() {
}


if (firstProfile.getOptions().eu() != secondProfile.getOptions().eu()) {
break;
}
//if (firstProfile.getOptions().eu() != secondProfile.getOptions().eu()) {
// break;
//}

// Find arena
final Arena arena = Arena.getRandomArena(queueProfile.getQueue().getKit());
Expand Down
Loading

0 comments on commit 72f32f4

Please sign in to comment.