Skip to content

Commit

Permalink
[enhancement] Fix Invisibility Potions on 1.8 and some cosmetic chang…
Browse files Browse the repository at this point in the history
…es (andrei1058#408)

* Make titles smoothly fade out

* What was the point for such long cooldown?

* Fix english grammar error

* Fix Invisibility Potion not working on 1_8_R3

* Revert "What was the point for such long cooldown?"

This reverts commit f66e035.

Co-authored-by: MarcelDutko <[email protected]>
  • Loading branch information
2 people authored and Cubixmeister committed Apr 6, 2022
1 parent 5d1129c commit b2eb7df
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class SpectatorFirstPersonEnterEvent extends Event implements Cancellable
private Function<Player, String> title;
private Function<Player, String> subTitle;
private int fadeIn = 0;
private int stay = 30;
private int fadeOut = 0;
private int stay = 40;
private int fadeOut = 10;

// A list of all players spectating in first person
private static List<UUID> spectatingInFirstPerson = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class SpectatorFirstPersonLeaveEvent extends Event {
private Function<Player, String> title;
private Function<Player, String> subTitle;
private int fadeIn = 0;
private int stay = 30;
private int fadeOut = 0;
private int stay = 40;
private int fadeOut = 10;

public SpectatorFirstPersonLeaveEvent(Player spectator, IArena arena, Function<Player, String> title, Function<Player, String> subtitle) {
this.spectator = spectator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ protected void loadDefaultEffects() {
*/
public abstract boolean isProjectile(ItemStack itemStack);

/**
* Check if itemstack is Invisibility Potion
*/
public abstract boolean isInvisibilityPotion(ItemStack itemStack);

/**
* Register custom entities
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ public void setStatus(GameState status) {
if (this.status == GameState.starting && status == GameState.waiting) {
for (Player player : getPlayers()) {
Language playerLang = Language.getPlayerLanguage(player);
nms.sendTitle(player, playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_TITLE), playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_SUB_TITLE), 0, 40, 0);
nms.sendTitle(player, playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_TITLE), playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_SUB_TITLE), 0, 40, 10);
}
}
this.status = status;
Expand Down Expand Up @@ -1848,7 +1848,7 @@ public void checkWinner() {
//noinspection deprecation
for (Player p : winner.getMembersCache()) {
if (p.getWorld().equals(getWorld())) {
nms.sendTitle(p, getMsg(p, Messages.GAME_END_VICTORY_PLAYER_TITLE), null, 0, 70, 0);
nms.sendTitle(p, getMsg(p, Messages.GAME_END_VICTORY_PLAYER_TITLE), null, 0, 70, 20);
}
if (!winners.toString().contains(p.getDisplayName())) {
winners.append(p.getDisplayName()).append(" ");
Expand Down Expand Up @@ -1901,7 +1901,7 @@ public void checkWinner() {
p.sendMessage(getMsg(p, Messages.GAME_END_TEAM_WON_CHAT).replace("{TeamColor}", winner.getColor().chat().toString())
.replace("{TeamName}", winner.getDisplayName(Language.getPlayerLanguage(p))));
if (!winner.getMembers().contains(p)) {
nms.sendTitle(p, getMsg(p, Messages.GAME_END_GAME_OVER_PLAYER_TITLE), null, 0, 70, 0);
nms.sendTitle(p, getMsg(p, Messages.GAME_END_GAME_OVER_PLAYER_TITLE), null, 0, 70, 20);
}
for (String s : getList(p, Messages.GAME_END_TOP_PLAYER_CHAT)) {
String message = s.replace("{firstName}", firstName.isEmpty() ? getMsg(p, Messages.MEANING_NOBODY) : firstName).replace("{firstKills}", String.valueOf(first))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public void run() {
beds_destroy_countdown--;
if (getBedsDestroyCountdown() == 0) {
for (Player p : getArena().getPlayers()) {
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_BEDS_DESTROYED), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_BEDS_DESTROYED), 0, 30, 0);
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_BEDS_DESTROYED), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_BEDS_DESTROYED), 0, 40, 10);
p.sendMessage(getMsg(p, Messages.NEXT_EVENT_CHAT_ANNOUNCE_BEDS_DESTROYED));
}
for (Player p : getArena().getSpectators()) {
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_BEDS_DESTROYED), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_BEDS_DESTROYED), 0, 30, 0);
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_BEDS_DESTROYED), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_BEDS_DESTROYED), 0, 40, 10);
p.sendMessage(getMsg(p, Messages.NEXT_EVENT_CHAT_ANNOUNCE_BEDS_DESTROYED));
}
for (ITeam t : getArena().getTeams()) {
Expand All @@ -126,15 +126,15 @@ public void run() {
dragon_spawn_countdown--;
if (getDragonSpawnCountdown() == 0) {
for (Player p : getArena().getPlayers()) {
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_SUDDEN_DEATH), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_SUDDEN_DEATH), 0, 30, 0);
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_SUDDEN_DEATH), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_SUDDEN_DEATH), 0, 40, 10);
for (ITeam t : getArena().getTeams()) {
if (t.getMembers().isEmpty()) continue;
p.sendMessage(getMsg(p, Messages.NEXT_EVENT_CHAT_ANNOUNCE_SUDDEN_DEATH).replace("{TeamDragons}", String.valueOf(t.getDragons()))
.replace("{TeamColor}", t.getColor().chat().toString()).replace("{TeamName}", t.getDisplayName(Language.getPlayerLanguage(p))));
}
}
for (Player p : getArena().getSpectators()) {
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_SUDDEN_DEATH), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_SUDDEN_DEATH), 0, 30, 0);
nms.sendTitle(p, getMsg(p, Messages.NEXT_EVENT_TITLE_ANNOUNCE_SUDDEN_DEATH), getMsg(p, Messages.NEXT_EVENT_SUBTITLE_ANNOUNCE_SUDDEN_DEATH), 0, 40, 10);
for (ITeam t : getArena().getTeams()) {
if (t.getMembers().isEmpty()) continue;
p.sendMessage(getMsg(p, Messages.NEXT_EVENT_CHAT_ANNOUNCE_SUDDEN_DEATH).replace("{TeamDragons}", String.valueOf(t.getDragons()))
Expand Down Expand Up @@ -230,7 +230,7 @@ public void run() {
} else {
nms.sendTitle(e.getKey(), getMsg(e.getKey(), Messages.PLAYER_DIE_RESPAWN_TITLE).replace("{time}",
String.valueOf(e.getValue())), getMsg(e.getKey(), Messages.PLAYER_DIE_RESPAWN_SUBTITLE).replace("{time}",
String.valueOf(e.getValue())), 0, 30, 0);
String.valueOf(e.getValue())), 0, 30, 10);
e.getKey().sendMessage(getMsg(e.getKey(), Messages.PLAYER_DIE_RESPAWN_CHAT).replace("{time}", String.valueOf(e.getValue())));
getArena().getRespawnSessions().replace(e.getKey(), e.getValue() - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void run() {
for (Player player : getArena().getPlayers()) {
Language playerLang = Language.getPlayerLanguage(player);
String[] titleSubtitle = Language.getCountDownTitle(playerLang, getCountdown());
nms.sendTitle(player, titleSubtitle[0], titleSubtitle[1], 4, 22, 4);
nms.sendTitle(player, titleSubtitle[0], titleSubtitle[1], 0, 20, 10);
player.sendMessage(getMsg(player, Messages.ARENA_STATUS_START_COUNTDOWN_CHAT).replace("{time}", String.valueOf(getCountdown())));
}
}
Expand All @@ -171,7 +171,7 @@ private void spawnPlayers() {
BedWarsTeam.reSpawnInvulnerability.put(p.getUniqueId(), System.currentTimeMillis() + 2000L);
bwt.firstSpawn(p);
Sounds.playSound(ConfigPath.SOUND_GAME_START, p);
nms.sendTitle(p, getMsg(p, Messages.ARENA_STATUS_START_PLAYER_TITLE), null, 0, 20, 0);
nms.sendTitle(p, getMsg(p, Messages.ARENA_STATUS_START_PLAYER_TITLE), null, 0, 30, 10);
for (String tut : getList(p, Messages.ARENA_STATUS_START_PLAYER_TUTORIAL)) {
p.sendMessage(SupportPAPI.getSupportPAPI().replace(p, tut));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void respawnMember(@NotNull Player p) {
}
}, 8L);

nms.sendTitle(p, getMsg(p, Messages.PLAYER_DIE_RESPAWNED_TITLE), "", 0, 20, 0);
nms.sendTitle(p, getMsg(p, Messages.PLAYER_DIE_RESPAWNED_TITLE), "", 0, 20, 10);

sendDefaultInventory(p, false);
ShopCache sc = ShopCache.getShopCache(p.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean execute(String[] args, CommandSender s) {
p.spigot().sendMessage(Misc.msgHoverClick(ss.getPrefix() + "Make sure you set the team's spawn first!", ChatColor.WHITE + "Set a team spawn.", "/" + getParent().getName() + " " + getSubCommandName() + " ", ClickEvent.Action.SUGGEST_COMMAND));
p.spigot().sendMessage(Misc.msgHoverClick(ss.getPrefix() + "Or if you set the spawn and it wasn't found automatically try using: /bw " + getSubCommandName() + " <team>", "Set a team shop.", "/" + getParent().getName() + " " + getSubCommandName() + " ", ClickEvent.Action.SUGGEST_COMMAND));
p.spigot().sendMessage(Misc.msgHoverClick(ss.getPrefix() + "Other use: /bw setShop <teamName>", "Set a team shop.", "/" + getParent().getName() + " " + getSubCommandName() + " ", ClickEvent.Action.SUGGEST_COMMAND));
com.andrei1058.bedwars.BedWars.nms.sendTitle(p, " ", ChatColor.RED + "Could not find any nearby team.", 5, 60, 5);
com.andrei1058.bedwars.BedWars.nms.sendTitle(p, " ", ChatColor.RED + "Could not find any nearby team.", 0, 60, 10);
Sounds.playSound(ConfigPath.SOUNDS_INSUFF_MONEY, p);
} else {
Bukkit.dispatchCommand(s, getParent().getName() + " " + getSubCommandName() + " " + foundTeam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean execute(String[] args, CommandSender s) {
p.sendMessage(ss.getPrefix() + ChatColor.RED + "Could not find any nearby team.");
p.spigot().sendMessage(Misc.msgHoverClick(ss.getPrefix() + "Make sure you set the team's spawn first!", ChatColor.WHITE + "Set a team spawn.", "/" + getParent().getName() + " " + getSubCommandName() + " ", ClickEvent.Action.SUGGEST_COMMAND));
p.spigot().sendMessage(Misc.msgHoverClick(ss.getPrefix() + "Or if you set the spawn and it wasn't found automatically try using: /bw " + getSubCommandName() + " <team>", "Set team upgrades NPC for a team.", "/" + getParent().getName() + " " + getSubCommandName() + " ", ClickEvent.Action.SUGGEST_COMMAND));
com.andrei1058.bedwars.BedWars.nms.sendTitle(p, " ", ChatColor.RED + "Could not find any nearby team.", 5, 60, 5);
com.andrei1058.bedwars.BedWars.nms.sendTitle(p, " ", ChatColor.RED + "Could not find any nearby team.", 0, 60, 10);
Sounds.playSound(ConfigPath.SOUNDS_INSUFF_MONEY, p);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public English() {
yml.addDefault(Messages.COMMAND_PARTY_INVITE_SENT_TARGET_RECEIVE_MSG, "{prefix}&b{player} &ehas invited you to a party! &o&7(Click to accept)");
yml.addDefault(Messages.COMMAND_PARTY_INVITE_DENIED_CANNOT_INVITE_YOURSELF, "{prefix}&cYou cannot invite yourself!");
yml.addDefault(Messages.COMMAND_PARTY_INVITE_DENIED_PLAYER_OFFLINE, "{prefix}&7{player} &eis offline!");
yml.addDefault(Messages.COMMAND_PARTY_ACCEPT_DENIED_NO_INVITE, "{prefix}&cThere's no party requests to accept");
yml.addDefault(Messages.COMMAND_PARTY_ACCEPT_DENIED_NO_INVITE, "{prefix}&cThere are no party requests to accept!");
yml.addDefault(Messages.COMMAND_PARTY_ACCEPT_DENIED_ALREADY_IN_PARTY, "{prefix}&eYou're already in a party!");
yml.addDefault(Messages.COMMAND_PARTY_INSUFFICIENT_PERMISSIONS, "{prefix}&cOnly the party owner can do this!");
yml.addDefault(Messages.COMMAND_PARTY_ACCEPT_USAGE, "{prefix}&eUsage: &7/party accept <player>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void onBlockBreak(BlockBreakEvent e) {
.replace("{PlayerName}", p.getDisplayName()));
}
if (breakEvent.getTitle() != null && breakEvent.getSubTitle() != null) {
nms.sendTitle(on, breakEvent.getTitle().apply(on), breakEvent.getSubTitle().apply(on), 0, 25, 0);
nms.sendTitle(on, breakEvent.getTitle().apply(on), breakEvent.getSubTitle().apply(on), 0, 40, 10);
}
if (t.isMember(on)) Sounds.playSound(ConfigPath.SOUNDS_BED_DESTROY_OWN, on);
else Sounds.playSound(ConfigPath.SOUNDS_BED_DESTROY, on);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,43 @@ public void onDrink(PlayerItemConsumeEvent e) {
nms.minusAmount(e.getPlayer(), new ItemStack(Material.GLASS_BOTTLE), 1),
5L);
//
PotionMeta pm = (PotionMeta) e.getItem().getItemMeta();
if (pm.hasCustomEffects()) {
if (pm.hasCustomEffect(PotionEffectType.INVISIBILITY)) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
for (PotionEffect pe : e.getPlayer().getActivePotionEffects()) {
if (pe.getType().toString().contains("INVISIBILITY")) {
// if is already invisible
if (a.getShowTime().containsKey(e.getPlayer())) {
ITeam t = a.getTeam(e.getPlayer());
// increase invisibility timer
// keep trace of invisible players to send hide armor packet when required
// because potions do not hide armors
a.getShowTime().replace(e.getPlayer(), pe.getDuration() / 20);
// call custom event
Bukkit.getPluginManager().callEvent(new PlayerInvisibilityPotionEvent(PlayerInvisibilityPotionEvent.Type.ADDED, t, e.getPlayer(), t.getArena()));
} else {
// if not already invisible
ITeam t = a.getTeam(e.getPlayer());
// keep trace of invisible players to send hide armor packet when required
// because potions do not hide armors
a.getShowTime().put(e.getPlayer(), pe.getDuration() / 20);
//
for (Player p1 : e.getPlayer().getWorld().getPlayers()) {
if (a.isSpectator(p1)) {
// hide player armor to spectators
nms.hideArmor(e.getPlayer(), p1);
} else if (t != a.getTeam(p1)) {
// hide player armor to other teams
nms.hideArmor(e.getPlayer(), p1);
}

if (nms.isInvisibilityPotion(e.getItem())) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
for (PotionEffect pe : e.getPlayer().getActivePotionEffects()) {
if (pe.getType().toString().contains("INVISIBILITY")) {
// if is already invisible
if (a.getShowTime().containsKey(e.getPlayer())) {
ITeam t = a.getTeam(e.getPlayer());
// increase invisibility timer
// keep trace of invisible players to send hide armor packet when required
// because potions do not hide armors
a.getShowTime().replace(e.getPlayer(), pe.getDuration() / 20);
// call custom event
Bukkit.getPluginManager().callEvent(new PlayerInvisibilityPotionEvent(PlayerInvisibilityPotionEvent.Type.ADDED, t, e.getPlayer(), t.getArena()));
} else {
// if not already invisible
ITeam t = a.getTeam(e.getPlayer());
// keep trace of invisible players to send hide armor packet when required
// because potions do not hide armors
a.getShowTime().put(e.getPlayer(), pe.getDuration() / 20);
//
for (Player p1 : e.getPlayer().getWorld().getPlayers()) {
if (a.isSpectator(p1)) {
// hide player armor to spectators
nms.hideArmor(e.getPlayer(), p1);
} else if (t != a.getTeam(p1)) {
// hide player armor to other teams
nms.hideArmor(e.getPlayer(), p1);
}
// call custom event
Bukkit.getPluginManager().callEvent(new PlayerInvisibilityPotionEvent(PlayerInvisibilityPotionEvent.Type.ADDED, t, e.getPlayer(), t.getArena()));
}
break;
// call custom event
Bukkit.getPluginManager().callEvent(new PlayerInvisibilityPotionEvent(PlayerInvisibilityPotionEvent.Type.ADDED, t, e.getPlayer(), t.getArena()));
}
break;
}
}, 5L);
}
}
}, 5L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public boolean isProjectile(org.bukkit.inventory.ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack).getItem() instanceof IProjectile;
}

@Override
public boolean isInvisibilityPotion(org.bukkit.inventory.ItemStack itemStack) {
if (!itemStack.getType().equals(org.bukkit.Material.POTION)) return false;

org.bukkit.inventory.meta.PotionMeta pm = (org.bukkit.inventory.meta.PotionMeta) itemStack.getItemMeta();

return pm.hasCustomEffects() && pm.hasCustomEffect(org.bukkit.potion.PotionEffectType.INVISIBILITY);
}

@Override
public void registerEntities() {
registerEntity("Silverfish2", 60, Silverfish.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ public boolean isProjectile(org.bukkit.inventory.ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack).getItem() instanceof IProjectile;
}

@Override
public boolean isInvisibilityPotion(org.bukkit.inventory.ItemStack itemStack) {
if (!itemStack.getType().equals(org.bukkit.Material.POTION)) return false;

org.bukkit.inventory.meta.PotionMeta pm = (org.bukkit.inventory.meta.PotionMeta) itemStack.getItemMeta();

return pm.hasCustomEffects() && pm.hasCustomEffect(org.bukkit.potion.PotionEffectType.INVISIBILITY);
}

@Override
public void registerEntities() {

Expand Down
Loading

0 comments on commit b2eb7df

Please sign in to comment.