Skip to content

Commit 617e38e

Browse files
committed
Fix class cast error for holo manager & added new methods to text holo
1 parent 1f3da53 commit 617e38e

File tree

3 files changed

+134
-102
lines changed

3 files changed

+134
-102
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'com.maximde'
7-
version = '1.2.4'
7+
version = '1.2.5'
88

99
repositories {
1010
mavenCentral()

src/main/java/com/maximde/hologramapi/hologram/HologramManager.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
import org.bukkit.plugin.Plugin;
77
import org.bukkit.scheduler.BukkitRunnable;
88

9-
import java.util.HashMap;
10-
import java.util.List;
9+
import java.util.*;
10+
import java.util.concurrent.ConcurrentHashMap;
1111

1212
@AllArgsConstructor
1313
public class HologramManager {
1414

1515
private final Plugin plugin;
1616

1717
@Getter
18-
private final HashMap<TextHologram, BukkitRunnable> hologramAnimations = new HashMap<>();
18+
private final Map<TextHologram, BukkitRunnable> hologramAnimations = new ConcurrentHashMap<>();
1919

2020
@Getter
21-
private final HashMap<String, TextHologram> hologramsMap = new HashMap<>();
21+
private final Map<String, TextHologram> hologramsMap = new ConcurrentHashMap<>();
2222

2323
public List<TextHologram> getHolograms() {
24-
return (List<TextHologram>) this.hologramsMap.values();
24+
return new ArrayList<>(this.hologramsMap.values());
2525
}
2626

2727
public void spawn(TextHologram textHologram, Location location) {
@@ -38,9 +38,7 @@ public void remove(TextHologram textHologram) {
3838
}
3939

4040
public void remove(String id) {
41-
if(!hologramsMap.containsKey(id)) return;
42-
this.hologramsMap.get(id).kill();
43-
this.hologramsMap.remove(id);
41+
Optional.ofNullable(this.hologramsMap.remove(id)).ifPresent(TextHologram::kill);
4442
}
4543

4644
public void removeAll() {
@@ -54,21 +52,17 @@ public void applyAnimation(TextHologram hologram, TextAnimation textAnimation) {
5452
}
5553

5654
public void cancelAnimation(TextHologram hologram) {
57-
if(hologramAnimations.containsKey(hologram)) {
58-
hologramAnimations.get(hologram).cancel();
59-
hologramAnimations.remove(hologram);
60-
}
55+
Optional.ofNullable(hologramAnimations.remove(hologram)).ifPresent(BukkitRunnable::cancel);
6156
}
6257

6358
private BukkitRunnable animateHologram(TextHologram hologram, TextAnimation textAnimation) {
6459
final BukkitRunnable animation = new BukkitRunnable() {
6560
int currentFrame = 0;
6661
public void run() {
67-
if(textAnimation.getTextFrames().isEmpty()) return;
62+
if (textAnimation.getTextFrames().isEmpty()) return;
6863
hologram.setMiniMessageText(textAnimation.getTextFrames().get(currentFrame));
6964
hologram.update();
70-
currentFrame++;
71-
if(currentFrame >= textAnimation.getTextFrames().size()) currentFrame = 0;
65+
currentFrame = (currentFrame + 1) % textAnimation.getTextFrames().size();
7266
}
7367
};
7468

0 commit comments

Comments
 (0)