Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Fix floating chatbubbles after player quit
Browse files Browse the repository at this point in the history
  • Loading branch information
fxdsu committed Jul 16, 2023
1 parent f3dca60 commit 1ed187d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/net/flectone/custom/FPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.scoreboard.Team;
Expand All @@ -16,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class FPlayer {

Expand Down Expand Up @@ -395,14 +398,23 @@ public String getChat() {
return chat;
}

private List<String> listChatBubbles = new ArrayList<>();
private final List<String> listChatBubbles = new ArrayList<>();

public void addChatBubble(String message){
listChatBubbles.add(message);
}

public void removeChatBubble(int number){
listChatBubbles.remove(number);
if (listChatBubbles.size() > number) listChatBubbles.remove(number);
}

public List<Entity> getChatBubbleEntities() {
return player.getPassengers().stream().filter(entity -> entity instanceof AreaEffectCloud).collect(Collectors.toList());
}

public void clearChatBubbles() {
getChatBubbleEntities().forEach(Entity::remove);
listChatBubbles.clear();
}

public List<String> getListChatBubbles() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/flectone/listeners/EntityDismountListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.flectone.listeners;

import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.spigotmc.event.entity.EntityDismountEvent;

public class EntityDismountListener implements Listener {
@EventHandler
public void checkAreaEffectCloudDismount(EntityDismountEvent event){
Entity entity = event.getEntity();
if (entity.getType().equals(EntityType.AREA_EFFECT_CLOUD)) entity.remove();
}
}

0 comments on commit 1ed187d

Please sign in to comment.