mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-02-01 04:31:21 +01:00
Make names more consistent
This commit is contained in:
parent
4e028efb27
commit
b9d55363c6
@ -23,7 +23,7 @@ import me.filoghost.holographicdisplays.plugin.disk.Settings;
|
||||
import me.filoghost.holographicdisplays.plugin.disk.upgrade.LegacySymbolsUpgrade;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.internal.InternalHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTouchListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
import me.filoghost.holographicdisplays.plugin.listener.ChunkListener;
|
||||
import me.filoghost.holographicdisplays.plugin.listener.PlayerListener;
|
||||
@ -101,8 +101,8 @@ public class HolographicDisplays extends FCommonsPlugin {
|
||||
placeholderRegistry = new PlaceholderRegistry();
|
||||
TickClock tickClock = new TickClock();
|
||||
PlaceholderTracker placeholderTracker = new PlaceholderTracker(placeholderRegistry, tickClock);
|
||||
LineTouchListener lineTouchListener = new LineTouchListener();
|
||||
lineTrackerManager = new LineTrackerManager(nmsManager, placeholderTracker, lineTouchListener);
|
||||
LineClickListener lineClickListener = new LineClickListener();
|
||||
lineTrackerManager = new LineTrackerManager(nmsManager, placeholderTracker, lineClickListener);
|
||||
internalHologramManager = new InternalHologramManager(lineTrackerManager);
|
||||
APIHologramManager apiHologramManager = new APIHologramManager(lineTrackerManager);
|
||||
|
||||
@ -118,16 +118,16 @@ public class HolographicDisplays extends FCommonsPlugin {
|
||||
PlaceholderAPIHook.setup();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
nmsManager.injectPacketListener(player, lineTouchListener);
|
||||
nmsManager.injectPacketListener(player, lineClickListener);
|
||||
}
|
||||
|
||||
TickingTask tickingTask = new TickingTask(tickClock, lineTrackerManager, lineTouchListener);
|
||||
TickingTask tickingTask = new TickingTask(tickClock, lineTrackerManager, lineClickListener);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, tickingTask, 0, 1);
|
||||
|
||||
HologramCommandManager commandManager = new HologramCommandManager(this, internalHologramManager, configManager);
|
||||
commandManager.register(this);
|
||||
|
||||
registerListener(new PlayerListener(nmsManager, lineTrackerManager, lineTouchListener));
|
||||
registerListener(new PlayerListener(nmsManager, lineTrackerManager, lineClickListener));
|
||||
registerListener(new ChunkListener(this, lineTrackerManager));
|
||||
UpdateNotificationListener updateNotificationListener = new UpdateNotificationListener();
|
||||
registerListener(updateNotificationListener);
|
||||
|
@ -14,17 +14,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public abstract class BaseTouchableLine extends BaseHologramLine {
|
||||
public abstract class BaseClickableLine extends BaseHologramLine {
|
||||
|
||||
private static final Map<Player, Long> lastClickByPlayer = new WeakHashMap<>();
|
||||
|
||||
private ClickListener clickListener;
|
||||
|
||||
protected BaseTouchableLine(BaseHologram<?> hologram) {
|
||||
protected BaseClickableLine(BaseHologram<?> hologram) {
|
||||
super(hologram);
|
||||
}
|
||||
|
||||
public void onTouch(Player player) {
|
||||
public void onClick(Player player) {
|
||||
if (clickListener == null || !canInteract(player)) {
|
||||
return;
|
||||
}
|
||||
@ -41,7 +41,7 @@ public abstract class BaseTouchableLine extends BaseHologramLine {
|
||||
clickListener.onClick(player);
|
||||
} catch (Throwable t) {
|
||||
Log.warning("The plugin " + getCreatorPlugin().getName() + " generated an exception"
|
||||
+ " when the player " + player.getName() + " touched a hologram.", t);
|
||||
+ " when the player " + player.getName() + " clicked a hologram.", t);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseItemLine extends BaseTouchableLine {
|
||||
public abstract class BaseItemLine extends BaseClickableLine {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private PickupListener pickupListener;
|
||||
|
@ -9,7 +9,7 @@ import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerMana
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.TextLineTracker;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseTextLine extends BaseTouchableLine {
|
||||
public abstract class BaseTextLine extends BaseClickableLine {
|
||||
|
||||
private String text;
|
||||
|
||||
|
@ -8,32 +8,32 @@ package me.filoghost.holographicdisplays.plugin.hologram.tracking;
|
||||
import me.filoghost.holographicdisplays.common.nms.EntityID;
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSPacketList;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTouchableLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseClickableLine;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
public abstract class TouchableLineTracker<T extends BaseTouchableLine> extends LocationBasedLineTracker<T> {
|
||||
public abstract class ClickableLineTracker<T extends BaseClickableLine> extends LocationBasedLineTracker<T> {
|
||||
|
||||
private static final double SLIME_HEIGHT = 0.5;
|
||||
|
||||
private final LineTouchListener lineTouchListener;
|
||||
private final LineClickListener lineClickListener;
|
||||
private final EntityID vehicleEntityID;
|
||||
private final EntityID slimeEntityID;
|
||||
|
||||
private boolean spawnSlimeEntities;
|
||||
private boolean spawnSlimeEntitiesChanged;
|
||||
|
||||
public TouchableLineTracker(T line, NMSManager nmsManager, LineTouchListener lineTouchListener) {
|
||||
public ClickableLineTracker(T line, NMSManager nmsManager, LineClickListener lineClickListener) {
|
||||
super(line, nmsManager);
|
||||
this.vehicleEntityID = nmsManager.newEntityID();
|
||||
this.slimeEntityID = nmsManager.newEntityID();
|
||||
this.lineTouchListener = lineTouchListener;
|
||||
this.lineClickListener = lineClickListener;
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@Override
|
||||
public void onRemoval() {
|
||||
super.onRemoval();
|
||||
lineTouchListener.unregisterLine(slimeEntityID);
|
||||
lineClickListener.unregisterLine(slimeEntityID);
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@ -46,9 +46,9 @@ public abstract class TouchableLineTracker<T extends BaseTouchableLine> extends
|
||||
this.spawnSlimeEntities = spawnSlimeEntities;
|
||||
this.spawnSlimeEntitiesChanged = true;
|
||||
if (spawnSlimeEntities) {
|
||||
lineTouchListener.registerLine(slimeEntityID, line);
|
||||
lineClickListener.registerLine(slimeEntityID, line);
|
||||
} else {
|
||||
lineTouchListener.unregisterLine(slimeEntityID);
|
||||
lineClickListener.unregisterLine(slimeEntityID);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemLineTracker extends TouchableLineTracker<BaseItemLine> {
|
||||
public class ItemLineTracker extends ClickableLineTracker<BaseItemLine> {
|
||||
|
||||
private final EntityID vehicleEntityID;
|
||||
private final EntityID itemEntityID;
|
||||
@ -25,8 +25,8 @@ public class ItemLineTracker extends TouchableLineTracker<BaseItemLine> {
|
||||
private boolean spawnItemEntities;
|
||||
private boolean spawnItemEntitiesChanged;
|
||||
|
||||
public ItemLineTracker(BaseItemLine line, NMSManager nmsManager, LineTouchListener lineTouchListener) {
|
||||
super(line, nmsManager, lineTouchListener);
|
||||
public ItemLineTracker(BaseItemLine line, NMSManager nmsManager, LineClickListener lineClickListener) {
|
||||
super(line, nmsManager, lineClickListener);
|
||||
this.vehicleEntityID = nmsManager.newEntityID();
|
||||
this.itemEntityID = nmsManager.newEntityID();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.tracking;
|
||||
|
||||
import me.filoghost.holographicdisplays.common.nms.EntityID;
|
||||
import me.filoghost.holographicdisplays.common.nms.PacketListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTouchableLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseClickableLine;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -15,54 +15,55 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class LineTouchListener implements PacketListener {
|
||||
public class LineClickListener implements PacketListener {
|
||||
|
||||
private final ConcurrentMap<Integer, BaseTouchableLine> linesByEntityID;
|
||||
private final ConcurrentMap<Integer, BaseClickableLine> linesByEntityID;
|
||||
|
||||
// It is necessary to queue async touch events to process them from the main thread.
|
||||
// Use a set to avoid duplicate touch events to the same line.
|
||||
private final Set<TouchEvent> queuedTouchEvents;
|
||||
// It is necessary to queue async click events to process them from the main thread.
|
||||
// Use a set to avoid duplicate click events to the same line.
|
||||
private final Set<ClickEvent> queuedClickEvents;
|
||||
|
||||
public LineTouchListener() {
|
||||
public LineClickListener() {
|
||||
linesByEntityID = new ConcurrentHashMap<>();
|
||||
queuedTouchEvents = new HashSet<>();
|
||||
queuedClickEvents = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAsyncEntityInteract(Player player, int entityID) {
|
||||
BaseTouchableLine line = linesByEntityID.get(entityID);
|
||||
BaseClickableLine line = linesByEntityID.get(entityID);
|
||||
if (line != null) {
|
||||
queuedTouchEvents.add(new TouchEvent(player, line));
|
||||
queuedClickEvents.add(new ClickEvent(player, line));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void processQueuedTouchEvents() {
|
||||
for (TouchEvent touchEvent : queuedTouchEvents) {
|
||||
touchEvent.line.onTouch(touchEvent.player);
|
||||
// This method is called from the main thread
|
||||
public void processQueuedClickEvents() {
|
||||
for (ClickEvent clickEvent : queuedClickEvents) {
|
||||
clickEvent.line.onClick(clickEvent.player);
|
||||
}
|
||||
queuedTouchEvents.clear();
|
||||
queuedClickEvents.clear();
|
||||
}
|
||||
|
||||
public void registerLine(EntityID touchableEntityID, BaseTouchableLine line) {
|
||||
linesByEntityID.put(touchableEntityID.getNumericID(), line);
|
||||
public void registerLine(EntityID clickableEntityID, BaseClickableLine line) {
|
||||
linesByEntityID.put(clickableEntityID.getNumericID(), line);
|
||||
}
|
||||
|
||||
public void unregisterLine(EntityID touchableEntityID) {
|
||||
if (touchableEntityID.hasInitializedNumericID()) {
|
||||
linesByEntityID.remove(touchableEntityID.getNumericID());
|
||||
public void unregisterLine(EntityID clickableEntityID) {
|
||||
if (clickableEntityID.hasInitializedNumericID()) {
|
||||
linesByEntityID.remove(clickableEntityID.getNumericID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TouchEvent {
|
||||
private static class ClickEvent {
|
||||
|
||||
private final Player player;
|
||||
private final BaseTouchableLine line;
|
||||
private final BaseClickableLine line;
|
||||
|
||||
TouchEvent(Player player, BaseTouchableLine line) {
|
||||
ClickEvent(Player player, BaseClickableLine line) {
|
||||
this.player = player;
|
||||
this.line = line;
|
||||
}
|
||||
@ -76,8 +77,7 @@ public class LineTouchListener implements PacketListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
TouchEvent other = (TouchEvent) obj;
|
||||
|
||||
ClickEvent other = (ClickEvent) obj;
|
||||
return this.player.equals(other.player) && this.line.equals(other.line);
|
||||
}
|
||||
|
@ -21,24 +21,24 @@ public class LineTrackerManager {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
private final PlaceholderTracker placeholderTracker;
|
||||
private final LineTouchListener lineTouchListener;
|
||||
private final LineClickListener lineClickListener;
|
||||
private final Collection<LineTracker<?>> lineTrackers;
|
||||
|
||||
public LineTrackerManager(NMSManager nmsManager, PlaceholderTracker placeholderTracker, LineTouchListener lineTouchListener) {
|
||||
public LineTrackerManager(NMSManager nmsManager, PlaceholderTracker placeholderTracker, LineClickListener lineClickListener) {
|
||||
this.nmsManager = nmsManager;
|
||||
this.placeholderTracker = placeholderTracker;
|
||||
this.lineTouchListener = lineTouchListener;
|
||||
this.lineClickListener = lineClickListener;
|
||||
this.lineTrackers = new LinkedList<>();
|
||||
}
|
||||
|
||||
public TextLineTracker startTracking(BaseTextLine line) {
|
||||
TextLineTracker tracker = new TextLineTracker(line, nmsManager, lineTouchListener, placeholderTracker);
|
||||
TextLineTracker tracker = new TextLineTracker(line, nmsManager, lineClickListener, placeholderTracker);
|
||||
lineTrackers.add(tracker);
|
||||
return tracker;
|
||||
}
|
||||
|
||||
public ItemLineTracker startTracking(BaseItemLine line) {
|
||||
ItemLineTracker tracker = new ItemLineTracker(line, nmsManager, lineTouchListener);
|
||||
ItemLineTracker tracker = new ItemLineTracker(line, nmsManager, lineClickListener);
|
||||
lineTrackers.add(tracker);
|
||||
return tracker;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TextLineTracker extends TouchableLineTracker<BaseTextLine> {
|
||||
public class TextLineTracker extends ClickableLineTracker<BaseTextLine> {
|
||||
|
||||
private final EntityID armorStandEntityID;
|
||||
|
||||
@ -25,9 +25,9 @@ public class TextLineTracker extends TouchableLineTracker<BaseTextLine> {
|
||||
public TextLineTracker(
|
||||
BaseTextLine line,
|
||||
NMSManager nmsManager,
|
||||
LineTouchListener lineTouchListener,
|
||||
LineClickListener lineClickListener,
|
||||
PlaceholderTracker placeholderTracker) {
|
||||
super(line, nmsManager, lineTouchListener);
|
||||
super(line, nmsManager, lineClickListener);
|
||||
this.armorStandEntityID = nmsManager.newEntityID();
|
||||
this.displayText = new DisplayText(placeholderTracker);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
package me.filoghost.holographicdisplays.plugin.listener;
|
||||
|
||||
import me.filoghost.holographicdisplays.common.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTouchListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -18,18 +18,18 @@ public class PlayerListener implements Listener {
|
||||
|
||||
private final NMSManager nmsManager;
|
||||
private final LineTrackerManager lineTrackerManager;
|
||||
private final LineTouchListener lineTouchListener;
|
||||
private final LineClickListener lineClickListener;
|
||||
|
||||
public PlayerListener(NMSManager nmsManager, LineTrackerManager lineTrackerManager, LineTouchListener lineTouchListener) {
|
||||
public PlayerListener(NMSManager nmsManager, LineTrackerManager lineTrackerManager, LineClickListener lineClickListener) {
|
||||
this.nmsManager = nmsManager;
|
||||
this.lineTrackerManager = lineTrackerManager;
|
||||
this.lineTouchListener = lineTouchListener;
|
||||
this.lineClickListener = lineClickListener;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
nmsManager.injectPacketListener(player, lineTouchListener);
|
||||
nmsManager.injectPacketListener(player, lineClickListener);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -6,21 +6,21 @@
|
||||
package me.filoghost.holographicdisplays.plugin.placeholder;
|
||||
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTouchListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
|
||||
public class TickingTask implements Runnable {
|
||||
|
||||
private final TickClock tickClock;
|
||||
private final LineTrackerManager lineTrackerManager;
|
||||
private final LineTouchListener lineTouchListener;
|
||||
private final LineClickListener lineClickListener;
|
||||
|
||||
private long lastErrorLogTick;
|
||||
|
||||
public TickingTask(TickClock tickClock, LineTrackerManager lineTrackerManager, LineTouchListener lineTouchListener) {
|
||||
public TickingTask(TickClock tickClock, LineTrackerManager lineTrackerManager, LineClickListener lineClickListener) {
|
||||
this.tickClock = tickClock;
|
||||
this.lineTrackerManager = lineTrackerManager;
|
||||
this.lineTouchListener = lineTouchListener;
|
||||
this.lineClickListener = lineClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,7 +38,7 @@ public class TickingTask implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
lineTouchListener.processQueuedTouchEvents();
|
||||
lineClickListener.processQueuedClickEvents();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
package me.filoghost.holographicdisplays.plugin.test;
|
||||
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTouchListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker;
|
||||
|
||||
@ -15,7 +15,7 @@ import static org.mockito.Mockito.*;
|
||||
public class TestAPIHologramManager extends APIHologramManager {
|
||||
|
||||
public TestAPIHologramManager() {
|
||||
super(new LineTrackerManager(new TestNMSManager(), mock(PlaceholderTracker.class), new LineTouchListener()));
|
||||
super(new LineTrackerManager(new TestNMSManager(), mock(PlaceholderTracker.class), new LineClickListener()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user