upload v4

This commit is contained in:
Matheus 2024-06-13 23:30:14 -04:00
parent f1bd3ab48f
commit 304d6f4460
8 changed files with 158 additions and 40 deletions

View File

@ -29,9 +29,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -70,6 +68,31 @@ public class MatchListener implements Listener {
this.plugin.getPartyManager().leaveParty(player); this.plugin.getPartyManager().leaveParty(player);
} }
@EventHandler
public void damage1(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player)) return;
final Player player = (Player) event.getEntity();
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
if (playerData.getPlayerState() == PlayerState.FIGHTING) {
Match match = plugin.getMatchManager().getMatch(playerData);
if (match.isPartyMatch()) {
if (plugin.getMatchManager().getMatch(plugin.getMatchManager().getSpectators().get(player.getUniqueId())) == match) event.setCancelled(true);
}
}
}
@EventHandler
public void damage0(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) return;
final Player player = (Player) event.getEntity();
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
if (playerData.getPlayerState() == PlayerState.FIGHTING) {
Match match = plugin.getMatchManager().getMatch(playerData);
if (match.isPartyMatch()) {
if (plugin.getMatchManager().getMatch(plugin.getMatchManager().getSpectators().get(player.getUniqueId())) == match) event.setCancelled(true);
}
}
}
@EventHandler @EventHandler
public void onEntitySpawn(EntitySpawnEvent event) { public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType().equals(EntityType.ARMOR_STAND)) { if (event.getEntityType().equals(EntityType.ARMOR_STAND)) {

View File

@ -27,6 +27,7 @@ import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState; import land.battle.practice.player.PlayerState;
import land.battle.practice.queue.QueueType; import land.battle.practice.queue.QueueType;
import land.battle.practice.util.CC; import land.battle.practice.util.CC;
import land.battle.practice.util.DeathUtils;
import land.battle.practice.util.PlayerUtil; import land.battle.practice.util.PlayerUtil;
import com.solexgames.shop.menu.ShopCategoryMenu; import com.solexgames.shop.menu.ShopCategoryMenu;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
@ -47,6 +48,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -272,10 +274,10 @@ public class PlayerListener implements Listener {
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId()); final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
if (event.getClickedBlock() != null && playerData.getPlayerState() == PlayerState.SPAWN) { /*if (event.getClickedBlock() != null && playerData.getPlayerState() == PlayerState.SPAWN) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }*/
if (playerData.getPlayerState() == PlayerState.SPECTATING) { if (playerData.getPlayerState() == PlayerState.SPECTATING) {
event.setCancelled(true); event.setCancelled(true);
@ -756,7 +758,8 @@ public class PlayerListener implements Listener {
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
final Player player = event.getEntity(); final Player player = event.getEntity();
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId()); final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
PlayerUtil.animateDeath(player); //player.setVelocity(new Vector());
PlayerUtil.animateDeath(player, false);
switch (playerData.getPlayerState()) { switch (playerData.getPlayerState()) {
case FIGHTING: case FIGHTING:
this.plugin.getMatchManager().removeFighter(player, playerData, true); this.plugin.getMatchManager().removeFighter(player, playerData, true);

View File

@ -51,6 +51,7 @@ public class MatchManager {
private final Map<UUID, Set<MatchRequest>> matchRequests = new TtlHashMap<>(TimeUnit.SECONDS, 30); private final Map<UUID, Set<MatchRequest>> matchRequests = new TtlHashMap<>(TimeUnit.SECONDS, 30);
private final Map<UUID, UUID> rematchUUIDs = new TtlHashMap<>(TimeUnit.SECONDS, 30); private final Map<UUID, UUID> rematchUUIDs = new TtlHashMap<>(TimeUnit.SECONDS, 30);
private final Map<UUID, UUID> rematchInventories = new TtlHashMap<>(TimeUnit.SECONDS, 30); private final Map<UUID, UUID> rematchInventories = new TtlHashMap<>(TimeUnit.SECONDS, 30);
@Getter
private final Map<UUID, UUID> spectators = new ConcurrentHashMap<>(); private final Map<UUID, UUID> spectators = new ConcurrentHashMap<>();
@Getter @Getter
@ -276,6 +277,7 @@ public class MatchManager {
final EntityPlayer playerEp = playerCp.getHandle(); final EntityPlayer playerEp = playerCp.getHandle();
playerEp.getDataWatcher().watch(6, 0.0F); playerEp.getDataWatcher().watch(6, 0.0F);
player.setFireTicks(0);
match.addRunnable(this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> { match.addRunnable(this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
match.getTeams().forEach(team -> team.streamAlivePlayers().forEach(member -> Practice.getInstance().getEntityHider().hideEntity(member, player))); match.getTeams().forEach(team -> team.streamAlivePlayers().forEach(member -> Practice.getInstance().getEntityHider().hideEntity(member, player)));
@ -302,8 +304,8 @@ public class MatchManager {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, -5)); player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, -5));
if (match.isParty() || match.isFFA()) { if (match.isParty() || match.isFFA()) {
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> player.getInventory().setContents(this.plugin.getItemManager().getPartySpecItems()), 1L);
player.getInventory().setContents(this.plugin.getItemManager().getPartySpecItems()), 1L); this.plugin.getServer().getOnlinePlayers().forEach(online -> Practice.getInstance().getEntityHider().hideEntity(online, player));
} }
player.updateInventory(); player.updateInventory();
@ -372,7 +374,6 @@ public class MatchManager {
public void removeSpectator(Player player, boolean silent) { public void removeSpectator(Player player, boolean silent) {
final Match match = this.matches.get(this.spectators.get(player.getUniqueId())); final Match match = this.matches.get(this.spectators.get(player.getUniqueId()));
match.removeSpectator(player.getUniqueId()); match.removeSpectator(player.getUniqueId());
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId()); final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
@ -385,16 +386,11 @@ public class MatchManager {
} }
} }
if (match.getMatchState() != MatchState.ENDING) {
if (!match.haveSpectated(player.getUniqueId())) {
match.addHaveSpectated(player.getUniqueId());
}
}
if (!player.hasPermission("practice.staff") && !silent) { if (!player.hasPermission("practice.staff") && !silent) {
match.broadcast(player.getDisplayName() + Color.SECONDARY_COLOR + " is no longer spectating your match."); match.broadcast(player.getDisplayName() + Color.SECONDARY_COLOR + " is no longer spectating your match.");
} }
match.getTeamByPlayer(player.getUniqueId()).getPlayers().remove(player.getUniqueId());
this.spectators.remove(player.getUniqueId()); this.spectators.remove(player.getUniqueId());
this.plugin.getPlayerManager().sendToSpawnAndReset(player); this.plugin.getPlayerManager().sendToSpawnAndReset(player);
} }

View File

@ -276,8 +276,8 @@ public class PlayerManager {
} }
Schedulers.sync().runLater(() -> this.plugin.getServer().getOnlinePlayers().forEach(other -> { Schedulers.sync().runLater(() -> this.plugin.getServer().getOnlinePlayers().forEach(other -> {
Practice.getInstance().getEntityHider().hideEntity(player, other); Practice.getInstance().getEntityHider().showEntity(player, other);
Practice.getInstance().getEntityHider().hideEntity(other, player); Practice.getInstance().getEntityHider().showEntity(other, player);
}), 1L); }), 1L);
} }

View File

@ -7,6 +7,7 @@ import com.solexgames.core.util.external.Button;
import com.solexgames.core.util.external.Menu; import com.solexgames.core.util.external.Menu;
import land.battle.practice.Practice; import land.battle.practice.Practice;
import land.battle.practice.kit.Kit; import land.battle.practice.kit.Kit;
import land.battle.practice.match.Match;
import land.battle.practice.party.Party; import land.battle.practice.party.Party;
import land.battle.practice.player.PlayerData; import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState; import land.battle.practice.player.PlayerState;
@ -85,7 +86,7 @@ public class JoinQueueMenu extends Menu {
@Override @Override
public ItemStack getButtonItem(final Player player) { public ItemStack getButtonItem(final Player player) {
final List<String> lore = new ArrayList<>(); final List<String> lore = new ArrayList<>();
final int playing = StatusCache.getInstance().getFightingKits().get(this.queue); final int playing = getFighting(queue);
lore.add("&7In Queue: &f" + getQueued(queue)); lore.add("&7In Queue: &f" + getQueued(queue));
lore.add("&7In Fights: &f" + getFighting(queue)); lore.add("&7In Fights: &f" + getFighting(queue));
@ -124,10 +125,15 @@ public class JoinQueueMenu extends Menu {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
PlayerData data = Practice.getInstance().getPlayerManager().getPlayerData(player.getUniqueId()); PlayerData data = Practice.getInstance().getPlayerManager().getPlayerData(player.getUniqueId());
if (data.getPlayerState() == PlayerState.FIGHTING) { if (data.getPlayerState() == PlayerState.FIGHTING) {
if (Objects.equals(Practice.getInstance().getMatchManager().getMatch(data.getCurrentMatchID()).getKit().getName(), kit.getName()) && Practice.getInstance().getMatchManager().getMatch(data.getCurrentMatchID()).getType() == queueType) { for (Match match : Practice.getInstance().getMatchManager().getMatches().values()) {
i++; if (match.getTeamByPlayer(player.getUniqueId()) != null) {
continue; if (match.getType() == queueType && match.getKit() == kit) {
} i++;
} else {
continue;
}
}
}
} else { } else {
continue; continue;
} }

View File

@ -116,19 +116,6 @@ public class PracticeSettingsImpl implements ISettings {
.toUpdatingButton((player1, clickType) -> data.getOptions().setSpectators(!data.getOptions().isSpectators())) .toUpdatingButton((player1, clickType) -> data.getOptions().setSpectators(!data.getOptions().isSpectators()))
); );
buttonList.add(new ItemBuilder(Material.SKULL_ITEM)
.setDisplayName(Color.MAIN_COLOR + CC.BOLD + "Death Animation")
.addLore(
"",
CC.GRAY + "Would you like a different",
CC.GRAY + "death animation?",
" ",
(data.getOptions().isNoneAnimation() ? CC.GREEN + CC.BOLD + "" : CC.DARK_GRAY + CC.BOLD + "") + "&fAnimated",
(!data.getOptions().isNoneAnimation() ? CC.GREEN + CC.BOLD + "" : CC.DARK_GRAY + CC.BOLD + "") + "&fStatic"
)
.toUpdatingButton((player1, clickType) -> data.getOptions().setNoneAnimation(!data.getOptions().isNoneAnimation()))
);
buttonList.add(new ItemBuilder(Material.BLAZE_ROD) buttonList.add(new ItemBuilder(Material.BLAZE_ROD)
.setDisplayName(Color.MAIN_COLOR + CC.BOLD + "Kill Effects") .setDisplayName(Color.MAIN_COLOR + CC.BOLD + "Kill Effects")
.addLore( .addLore(

View File

@ -0,0 +1,102 @@
package land.battle.practice.util;
import land.battle.practice.Practice;
import lombok.experimental.UtilityClass;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityStatus;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class DeathUtils {
private static Field STATUS_PACKET_ID_FIELD;
private static Field STATUS_PACKET_STATUS_FIELD;
private static Field SPAWN_PACKET_ID_FIELD;
static {
try {
STATUS_PACKET_ID_FIELD = PacketPlayOutEntityStatus.class.getDeclaredField("a");
STATUS_PACKET_ID_FIELD.setAccessible(true);
STATUS_PACKET_STATUS_FIELD = PacketPlayOutEntityStatus.class.getDeclaredField("b");
STATUS_PACKET_STATUS_FIELD.setAccessible(true);
SPAWN_PACKET_ID_FIELD = PacketPlayOutNamedEntitySpawn.class.getDeclaredField("a");
SPAWN_PACKET_ID_FIELD.setAccessible(true);
} catch (NoSuchFieldException ex) {
ex.printStackTrace();
}
}
public static void animateDeath(Player player) {
final int entityId = EntityUtils.getFakeEntityId();
final PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle());
final PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus();
try {
SPAWN_PACKET_ID_FIELD.set(spawnPacket, entityId);
STATUS_PACKET_ID_FIELD.set(statusPacket, entityId);
STATUS_PACKET_STATUS_FIELD.set(statusPacket, (byte) 3);
final int radius = MinecraftServer.getServer().getPlayerList().d();
final Set<Player> sentTo = new HashSet<>();
for (Entity entity : player.getNearbyEntities(radius, radius, radius)) {
if (!(entity instanceof Player)) {
continue;
}
final Player watcher = (Player) entity;
if (watcher.getUniqueId().equals(player.getUniqueId())) {
continue;
}
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(spawnPacket);
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(statusPacket);
sentTo.add(watcher);
}
Practice.getInstance().getServer().getScheduler().runTaskLater(Practice.getInstance(), () -> {
for (Player watcher : sentTo) {
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(entityId));
}
}, 40L);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void animateDeath(Player player, Player watcher) {
final int entityId = EntityUtils.getFakeEntityId();
final PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle());
final PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus();
try {
SPAWN_PACKET_ID_FIELD.set(spawnPacket, entityId);
STATUS_PACKET_ID_FIELD.set(statusPacket, entityId);
STATUS_PACKET_STATUS_FIELD.set(statusPacket, (byte) 3);
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(spawnPacket);
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(statusPacket);
Practice.getInstance().getServer().getScheduler().runTaskLater(Practice.getInstance(), () -> ((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[]{entityId})), 40L);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -141,11 +141,8 @@ public final class PlayerUtil {
} }
public static void animateDeath(Player player) { public static void animateDeath(Player player, boolean showPlayer) {
try { try {
for (Player player1 : Bukkit.getOnlinePlayers()) {
player1.hidePlayer(player);
}
int entityId = EntityUtils.getFakeEntityId(); int entityId = EntityUtils.getFakeEntityId();
PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle()); PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle());
@ -188,6 +185,10 @@ public final class PlayerUtil {
sentTo.add(watcher); sentTo.add(watcher);
} }
if (showPlayer) for (Player player1 : Bukkit.getOnlinePlayers()) {
player1.hidePlayer(player);
}
// Schedule task to update the position of the fake entity // Schedule task to update the position of the fake entity
Bukkit.getScheduler().runTaskTimer(Practice.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(Practice.getInstance(), () -> {
for (Player watcher : sentTo) { for (Player watcher : sentTo) {
@ -234,7 +235,7 @@ public final class PlayerUtil {
((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(entityId)); ((CraftPlayer) watcher).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(entityId));
} }
}, 40L); }, 40L);
Bukkit.getScheduler().runTaskLater(Practice.getInstance(), () -> { if (showPlayer) Bukkit.getScheduler().runTaskLater(Practice.getInstance(), () -> {
for (Player player1 : Bukkit.getOnlinePlayers()) { for (Player player1 : Bukkit.getOnlinePlayers()) {
player1.showPlayer(player); player1.showPlayer(player);
} }