mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-01-20 06:41:20 +01:00
Rename API classes
This commit is contained in:
parent
b8860a9d60
commit
4e028efb27
@ -9,19 +9,19 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Interface to handle touch holograms.
|
||||
* Interface to handle clickable hologram lines.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TouchHandler {
|
||||
public interface ClickListener {
|
||||
|
||||
/**
|
||||
* Called when a player interacts with the hologram (right click).
|
||||
* Called when a player clicks on a hologram line.
|
||||
*
|
||||
* @param player the player who interacts
|
||||
* @param player the player who clicked
|
||||
* @since 1
|
||||
*/
|
||||
void onTouch(@NotNull Player player);
|
||||
void onClick(@NotNull Player player);
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.hologram;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A hologram line that can be clicked (left or right click).
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface ClickableLine extends HologramLine {
|
||||
|
||||
/**
|
||||
* Sets the click listener.
|
||||
*
|
||||
* @param clickListener the new click listener
|
||||
* @since 1
|
||||
*/
|
||||
void setClickListener(@Nullable ClickListener clickListener);
|
||||
|
||||
/**
|
||||
* Returns the current click listener.
|
||||
*
|
||||
* @return the current click listener
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable ClickListener getClickListener();
|
||||
|
||||
}
|
@ -8,26 +8,26 @@ package me.filoghost.holographicdisplays.api.hologram;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A line of a Hologram that can be picked up.
|
||||
* A hologram line that can be "picked up" by a nearby player.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface CollectableLine extends HologramLine {
|
||||
|
||||
/**
|
||||
* Sets the PickupHandler for this line.
|
||||
* Sets the pickup listener.
|
||||
*
|
||||
* @param pickupHandler the new PickupHandler, can be null.
|
||||
* @param pickupListener the new pickup listener
|
||||
* @since 1
|
||||
*/
|
||||
void setPickupHandler(@Nullable PickupHandler pickupHandler);
|
||||
void setPickupListener(@Nullable PickupListener pickupListener);
|
||||
|
||||
/**
|
||||
* Returns the current PickupHandler of this line.
|
||||
* Returns the current pickup listener.
|
||||
*
|
||||
* @return the current PickupHandler, can be null.
|
||||
* @return the current pickup listener
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable PickupHandler getPickupHandler();
|
||||
@Nullable PickupListener getPickupListener();
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface ItemLine extends CollectableLine, TouchableLine {
|
||||
public interface ItemLine extends CollectableLine, ClickableLine {
|
||||
|
||||
/**
|
||||
* Returns the ItemStack of this ItemLine.
|
||||
|
@ -9,12 +9,12 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Interface to handle items being picked up by players.
|
||||
* Interface to handle hologram lines being picked up by players.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PickupHandler {
|
||||
public interface PickupListener {
|
||||
|
||||
/**
|
||||
* Called when a player picks up the item.
|
@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface TextLine extends TouchableLine {
|
||||
public interface TextLine extends ClickableLine {
|
||||
|
||||
/**
|
||||
* Returns the current text of this TextLine.
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.hologram;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A line of a Hologram that can be touched (right click).
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface TouchableLine extends HologramLine {
|
||||
|
||||
/**
|
||||
* Sets the TouchHandler for this line.
|
||||
*
|
||||
* @param touchHandler the new TouchHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
void setTouchHandler(@Nullable TouchHandler touchHandler);
|
||||
|
||||
/**
|
||||
* Returns the current TouchHandler of this line.
|
||||
*
|
||||
* @return the current TouchHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
@Nullable TouchHandler getTouchHandler();
|
||||
|
||||
}
|
@ -52,7 +52,7 @@ public class PowerUps extends JavaPlugin implements Listener {
|
||||
hologram.appendTextLine(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp");
|
||||
ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
|
||||
|
||||
icon.setPickupHandler((Player player) -> {
|
||||
icon.setPickupListener((Player player) -> {
|
||||
// Play an effect
|
||||
player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null);
|
||||
|
||||
|
@ -11,20 +11,20 @@ import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramLine;
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class V2HologramLineAdapter implements HologramLine {
|
||||
|
||||
private final APIHologramLine v3HologramLine;
|
||||
private final APIHologramLine v3Line;
|
||||
|
||||
public V2HologramLineAdapter(APIHologramLine v3HologramLine) {
|
||||
this.v3HologramLine = v3HologramLine;
|
||||
public V2HologramLineAdapter(APIHologramLine v3Line) {
|
||||
this.v3Line = v3Line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V2HologramAdapter getParent() {
|
||||
return v3HologramLine.getParent().getV2Adapter();
|
||||
return v3Line.getParent().getV2Adapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine() {
|
||||
v3HologramLine.removeLine();
|
||||
v3Line.removeLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,17 +37,17 @@ public abstract class V2HologramLineAdapter implements HologramLine {
|
||||
}
|
||||
|
||||
V2HologramLineAdapter other = (V2HologramLineAdapter) obj;
|
||||
return this.v3HologramLine.equals(other.v3HologramLine);
|
||||
return this.v3Line.equals(other.v3Line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return v3HologramLine.hashCode();
|
||||
return v3Line.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return v3HologramLine.toString();
|
||||
return v3Line.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,23 +7,22 @@ package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIItemLine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class V2ItemLineAdapter extends V2TouchableLineAdapter implements ItemLine {
|
||||
|
||||
private final APIItemLine v3ItemLine;
|
||||
private final APIItemLine v3Line;
|
||||
private PickupHandler v2PickupHandler;
|
||||
|
||||
public V2ItemLineAdapter(APIItemLine v3ItemLine) {
|
||||
super(v3ItemLine);
|
||||
this.v3ItemLine = v3ItemLine;
|
||||
public V2ItemLineAdapter(APIItemLine v3Line) {
|
||||
super(v3Line);
|
||||
this.v3Line = v3Line;
|
||||
}
|
||||
|
||||
public void onV3PickupHandlerChange(
|
||||
me.filoghost.holographicdisplays.api.hologram.PickupHandler previous,
|
||||
me.filoghost.holographicdisplays.api.hologram.PickupHandler current) {
|
||||
public void onV3PickupListenerChange(PickupListener previous, PickupListener current) {
|
||||
if (previous != current) {
|
||||
v2PickupHandler = null; // Clear the field to force a new lazy initialization
|
||||
}
|
||||
@ -32,17 +31,17 @@ public class V2ItemLineAdapter extends V2TouchableLineAdapter implements ItemLin
|
||||
@Override
|
||||
public void setPickupHandler(PickupHandler v2PickupHandler) {
|
||||
if (v2PickupHandler == null) {
|
||||
v3ItemLine.setPickupHandler(null);
|
||||
v3Line.setPickupListener(null);
|
||||
} else if (v2PickupHandler instanceof V2PickupHandlerAdapter) {
|
||||
// Adapter created from the getter method, simply unwrap it
|
||||
v3ItemLine.setPickupHandler(((V2PickupHandlerAdapter) v2PickupHandler).getV3PickupHandler());
|
||||
v3Line.setPickupListener(((V2PickupHandlerAdapter) v2PickupHandler).getV3PickupListener());
|
||||
} else {
|
||||
me.filoghost.holographicdisplays.api.hologram.PickupHandler v3PickupHandler = v3ItemLine.getPickupHandler();
|
||||
PickupListener v3PickupListener = v3Line.getPickupListener();
|
||||
|
||||
// Adapt the old v2 handler to the new API, creating a new instance only if the wrapped handler changed
|
||||
if (!(v3PickupHandler instanceof V3PickupHandlerAdapter)
|
||||
|| ((V3PickupHandlerAdapter) v3PickupHandler).getV2PickupHandler() != v2PickupHandler) {
|
||||
v3ItemLine.setPickupHandler(new V3PickupHandlerAdapter(v2PickupHandler));
|
||||
if (!(v3PickupListener instanceof V3PickupListenerAdapter)
|
||||
|| ((V3PickupListenerAdapter) v3PickupListener).getV2PickupHandler() != v2PickupHandler) {
|
||||
v3Line.setPickupListener(new V3PickupListenerAdapter(v2PickupHandler));
|
||||
}
|
||||
}
|
||||
this.v2PickupHandler = v2PickupHandler;
|
||||
@ -52,16 +51,16 @@ public class V2ItemLineAdapter extends V2TouchableLineAdapter implements ItemLin
|
||||
public PickupHandler getPickupHandler() {
|
||||
// Lazy initialization
|
||||
if (v2PickupHandler == null) {
|
||||
me.filoghost.holographicdisplays.api.hologram.PickupHandler v3PickupHandler = v3ItemLine.getPickupHandler();
|
||||
PickupListener v3PickupListener = v3Line.getPickupListener();
|
||||
|
||||
if (v3PickupHandler == null) {
|
||||
if (v3PickupListener == null) {
|
||||
// Keep it null
|
||||
} else if (v3PickupHandler instanceof V3PickupHandlerAdapter) {
|
||||
} else if (v3PickupListener instanceof V3PickupListenerAdapter) {
|
||||
// Adapter created from the setter method, simply unwrap it
|
||||
v2PickupHandler = ((V3PickupHandlerAdapter) v3PickupHandler).getV2PickupHandler();
|
||||
v2PickupHandler = ((V3PickupListenerAdapter) v3PickupListener).getV2PickupHandler();
|
||||
} else {
|
||||
// Adapt the new handler to the old v2 API
|
||||
v2PickupHandler = new V2PickupHandlerAdapter(v3PickupHandler);
|
||||
v2PickupHandler = new V2PickupHandlerAdapter(v3PickupListener);
|
||||
}
|
||||
}
|
||||
return v2PickupHandler;
|
||||
@ -69,12 +68,12 @@ public class V2ItemLineAdapter extends V2TouchableLineAdapter implements ItemLin
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return v3ItemLine.getItemStack();
|
||||
return v3Line.getItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemStack(ItemStack itemStack) {
|
||||
v3ItemLine.setItemStack(itemStack);
|
||||
v3Line.setItemStack(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,25 +5,26 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class V2PickupHandlerAdapter implements com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler {
|
||||
class V2PickupHandlerAdapter implements PickupHandler {
|
||||
|
||||
private final PickupHandler v3PickupHandler;
|
||||
private final PickupListener v3PickupListener;
|
||||
|
||||
V2PickupHandlerAdapter(PickupHandler v3PickupHandler) {
|
||||
this.v3PickupHandler = v3PickupHandler;
|
||||
V2PickupHandlerAdapter(PickupListener v3PickupListener) {
|
||||
this.v3PickupListener = v3PickupListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickup(Player player) {
|
||||
v3PickupHandler.onPickup(player);
|
||||
v3PickupListener.onPickup(player);
|
||||
}
|
||||
|
||||
public PickupHandler getV3PickupHandler() {
|
||||
return v3PickupHandler;
|
||||
public PickupListener getV3PickupListener() {
|
||||
return v3PickupListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,17 +37,17 @@ class V2PickupHandlerAdapter implements com.gmail.filoghost.holographicdisplays.
|
||||
}
|
||||
|
||||
V2PickupHandlerAdapter other = (V2PickupHandlerAdapter) obj;
|
||||
return this.v3PickupHandler.equals(other.v3PickupHandler);
|
||||
return this.v3PickupListener.equals(other.v3PickupListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return v3PickupHandler.hashCode();
|
||||
return v3PickupListener.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return v3PickupHandler.toString();
|
||||
return v3PickupListener.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine;
|
||||
@SuppressWarnings("deprecation")
|
||||
public class V2TextLineAdapter extends V2TouchableLineAdapter implements TextLine {
|
||||
|
||||
private final APITextLine v3TextLine;
|
||||
private final APITextLine v3Line;
|
||||
|
||||
public V2TextLineAdapter(APITextLine v3TextLine) {
|
||||
super(v3TextLine);
|
||||
this.v3TextLine = v3TextLine;
|
||||
public V2TextLineAdapter(APITextLine v3Line) {
|
||||
super(v3Line);
|
||||
this.v3Line = v3Line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return v3TextLine.getText();
|
||||
return v3Line.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
v3TextLine.setText(text);
|
||||
v3Line.setText(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,25 +5,26 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class V2TouchHandlerAdapter implements com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler {
|
||||
class V2TouchHandlerAdapter implements TouchHandler {
|
||||
|
||||
private final TouchHandler v3TouchHandler;
|
||||
private final ClickListener v3ClickListener;
|
||||
|
||||
V2TouchHandlerAdapter(TouchHandler v3TouchHandler) {
|
||||
this.v3TouchHandler = v3TouchHandler;
|
||||
V2TouchHandlerAdapter(ClickListener v3ClickListener) {
|
||||
this.v3ClickListener = v3ClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouch(Player player) {
|
||||
v3TouchHandler.onTouch(player);
|
||||
v3ClickListener.onClick(player);
|
||||
}
|
||||
|
||||
public TouchHandler getV3TouchHandler() {
|
||||
return v3TouchHandler;
|
||||
public ClickListener getV3ClickListener() {
|
||||
return v3ClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,17 +37,17 @@ class V2TouchHandlerAdapter implements com.gmail.filoghost.holographicdisplays.a
|
||||
}
|
||||
|
||||
V2TouchHandlerAdapter other = (V2TouchHandlerAdapter) obj;
|
||||
return this.v3TouchHandler.equals(other.v3TouchHandler);
|
||||
return this.v3ClickListener.equals(other.v3ClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return v3TouchHandler.hashCode();
|
||||
return v3ClickListener.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return v3TouchHandler.toString();
|
||||
return v3ClickListener.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,22 +7,21 @@ package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.TouchableLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APITouchableLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIClickableLine;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
abstract class V2TouchableLineAdapter extends V2HologramLineAdapter implements TouchableLine {
|
||||
|
||||
private final APITouchableLine v3TouchableLine;
|
||||
private final APIClickableLine v3Line;
|
||||
private TouchHandler v2TouchHandler;
|
||||
|
||||
V2TouchableLineAdapter(APITouchableLine v3TouchableLine) {
|
||||
super(v3TouchableLine);
|
||||
this.v3TouchableLine = v3TouchableLine;
|
||||
V2TouchableLineAdapter(APIClickableLine v3Line) {
|
||||
super(v3Line);
|
||||
this.v3Line = v3Line;
|
||||
}
|
||||
|
||||
public void onV3TouchHandlerChange(
|
||||
me.filoghost.holographicdisplays.api.hologram.TouchHandler previous,
|
||||
me.filoghost.holographicdisplays.api.hologram.TouchHandler current) {
|
||||
public void onV3ClickListenerChange(ClickListener previous, ClickListener current) {
|
||||
if (previous != current) {
|
||||
v2TouchHandler = null; // Clear the field to force a new lazy initialization
|
||||
}
|
||||
@ -31,17 +30,17 @@ abstract class V2TouchableLineAdapter extends V2HologramLineAdapter implements T
|
||||
@Override
|
||||
public void setTouchHandler(TouchHandler v2TouchHandler) {
|
||||
if (v2TouchHandler == null) {
|
||||
v3TouchableLine.setTouchHandler(null);
|
||||
v3Line.setClickListener(null);
|
||||
} else if (v2TouchHandler instanceof V2TouchHandlerAdapter) {
|
||||
// Adapter created from the getter method, simply unwrap it
|
||||
v3TouchableLine.setTouchHandler(((V2TouchHandlerAdapter) v2TouchHandler).getV3TouchHandler());
|
||||
v3Line.setClickListener(((V2TouchHandlerAdapter) v2TouchHandler).getV3ClickListener());
|
||||
} else {
|
||||
me.filoghost.holographicdisplays.api.hologram.TouchHandler v3TouchHandler = v3TouchableLine.getTouchHandler();
|
||||
ClickListener v3ClickListener = v3Line.getClickListener();
|
||||
|
||||
// Adapt the old v2 handler to the new API, creating a new instance only if the wrapped handler changed
|
||||
if (!(v3TouchHandler instanceof V3TouchHandlerAdapter)
|
||||
|| ((V3TouchHandlerAdapter) v3TouchHandler).getV2TouchHandler() != v2TouchHandler) {
|
||||
v3TouchableLine.setTouchHandler(new V3TouchHandlerAdapter(v2TouchHandler));
|
||||
if (!(v3ClickListener instanceof V3ClickListenerAdapter)
|
||||
|| ((V3ClickListenerAdapter) v3ClickListener).getV2TouchHandler() != v2TouchHandler) {
|
||||
v3Line.setClickListener(new V3ClickListenerAdapter(v2TouchHandler));
|
||||
}
|
||||
}
|
||||
this.v2TouchHandler = v2TouchHandler;
|
||||
@ -51,16 +50,16 @@ abstract class V2TouchableLineAdapter extends V2HologramLineAdapter implements T
|
||||
public TouchHandler getTouchHandler() {
|
||||
// Lazy initialization
|
||||
if (v2TouchHandler == null) {
|
||||
me.filoghost.holographicdisplays.api.hologram.TouchHandler v3TouchHandler = v3TouchableLine.getTouchHandler();
|
||||
ClickListener v3ClickListener = v3Line.getClickListener();
|
||||
|
||||
if (v3TouchHandler == null) {
|
||||
if (v3ClickListener == null) {
|
||||
// Keep it null
|
||||
} else if (v3TouchHandler instanceof V3TouchHandlerAdapter) {
|
||||
} else if (v3ClickListener instanceof V3ClickListenerAdapter) {
|
||||
// Adapter created from the setter method, simply unwrap it
|
||||
v2TouchHandler = ((V3TouchHandlerAdapter) v3TouchHandler).getV2TouchHandler();
|
||||
v2TouchHandler = ((V3ClickListenerAdapter) v3ClickListener).getV2TouchHandler();
|
||||
} else {
|
||||
// Adapt the new handler to the old v2 API
|
||||
v2TouchHandler = new V2TouchHandlerAdapter(v3TouchHandler);
|
||||
v2TouchHandler = new V2TouchHandlerAdapter(v3ClickListener);
|
||||
}
|
||||
}
|
||||
return v2TouchHandler;
|
||||
|
@ -6,20 +6,21 @@
|
||||
package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class V3TouchHandlerAdapter implements me.filoghost.holographicdisplays.api.hologram.TouchHandler {
|
||||
public class V3ClickListenerAdapter implements ClickListener {
|
||||
|
||||
private final TouchHandler v2TouchHandler;
|
||||
|
||||
public V3TouchHandlerAdapter(TouchHandler v2TouchHandler) {
|
||||
public V3ClickListenerAdapter(TouchHandler v2TouchHandler) {
|
||||
this.v2TouchHandler = v2TouchHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouch(@NotNull Player player) {
|
||||
public void onClick(@NotNull Player player) {
|
||||
v2TouchHandler.onTouch(player);
|
||||
}
|
||||
|
||||
@ -32,11 +33,11 @@ public class V3TouchHandlerAdapter implements me.filoghost.holographicdisplays.a
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof V3TouchHandlerAdapter)) {
|
||||
if (!(obj instanceof V3ClickListenerAdapter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
V3TouchHandlerAdapter other = (V3TouchHandlerAdapter) obj;
|
||||
V3ClickListenerAdapter other = (V3ClickListenerAdapter) obj;
|
||||
return this.v2TouchHandler.equals(other.v2TouchHandler);
|
||||
}
|
||||
|
@ -6,15 +6,16 @@
|
||||
package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class V3PickupHandlerAdapter implements me.filoghost.holographicdisplays.api.hologram.PickupHandler {
|
||||
public class V3PickupListenerAdapter implements PickupListener {
|
||||
|
||||
private final PickupHandler v2PickupHandler;
|
||||
|
||||
public V3PickupHandlerAdapter(PickupHandler v2PickupHandler) {
|
||||
public V3PickupListenerAdapter(PickupHandler v2PickupHandler) {
|
||||
this.v2PickupHandler = v2PickupHandler;
|
||||
}
|
||||
|
||||
@ -32,11 +33,11 @@ public class V3PickupHandlerAdapter implements me.filoghost.holographicdisplays.
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof V3PickupHandlerAdapter)) {
|
||||
if (!(obj instanceof V3PickupListenerAdapter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
V3PickupHandlerAdapter other = (V3PickupHandlerAdapter) obj;
|
||||
V3PickupListenerAdapter other = (V3PickupListenerAdapter) obj;
|
||||
return this.v2PickupHandler.equals(other.v2PickupHandler);
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.hologram.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchableLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickableLine;
|
||||
|
||||
public interface APITouchableLine extends TouchableLine, APIHologramLine {
|
||||
public interface APIClickableLine extends ClickableLine, APIHologramLine {
|
||||
|
||||
}
|
@ -6,15 +6,15 @@
|
||||
package me.filoghost.holographicdisplays.plugin.hologram.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.ItemLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.api.v2.V2ItemLineAdapter;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseItemLine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class APIItemLine extends BaseItemLine implements ItemLine, APITouchableLine {
|
||||
public class APIItemLine extends BaseItemLine implements ItemLine, APIClickableLine {
|
||||
|
||||
private final APIHologram parent;
|
||||
private final V2ItemLineAdapter v2Adapter;
|
||||
@ -31,17 +31,17 @@ public class APIItemLine extends BaseItemLine implements ItemLine, APITouchableL
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchHandler(@Nullable TouchHandler touchHandler) {
|
||||
TouchHandler oldTouchHandler = getTouchHandler();
|
||||
super.setTouchHandler(touchHandler);
|
||||
v2Adapter.onV3TouchHandlerChange(oldTouchHandler, touchHandler);
|
||||
public void setClickListener(@Nullable ClickListener clickListener) {
|
||||
ClickListener oldClickListener = getClickListener();
|
||||
super.setClickListener(clickListener);
|
||||
v2Adapter.onV3ClickListenerChange(oldClickListener, clickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupHandler(@Nullable PickupHandler pickupHandler) {
|
||||
PickupHandler oldPickupHandler = getPickupHandler();
|
||||
super.setPickupHandler(pickupHandler);
|
||||
v2Adapter.onV3PickupHandlerChange(oldPickupHandler, pickupHandler);
|
||||
public void setPickupListener(@Nullable PickupListener pickupListener) {
|
||||
PickupListener oldPickupListener = getPickupListener();
|
||||
super.setPickupListener(pickupListener);
|
||||
v2Adapter.onV3PickupListenerChange(oldPickupListener, pickupListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,14 +5,14 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.hologram.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import me.filoghost.holographicdisplays.api.hologram.TextLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.plugin.api.v2.V2TextLineAdapter;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTextLine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class APITextLine extends BaseTextLine implements TextLine, APITouchableLine {
|
||||
public class APITextLine extends BaseTextLine implements TextLine, APIClickableLine {
|
||||
|
||||
private final APIHologram parent;
|
||||
private final V2TextLineAdapter v2Adapter;
|
||||
@ -34,10 +34,10 @@ public class APITextLine extends BaseTextLine implements TextLine, APITouchableL
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTouchHandler(@Nullable TouchHandler touchHandler) {
|
||||
TouchHandler oldTouchHandler = getTouchHandler();
|
||||
super.setTouchHandler(touchHandler);
|
||||
v2Adapter.onV3TouchHandlerChange(oldTouchHandler, touchHandler);
|
||||
public void setClickListener(@Nullable ClickListener clickListener) {
|
||||
ClickListener oldClickListener = getClickListener();
|
||||
super.setClickListener(clickListener);
|
||||
v2Adapter.onV3ClickListenerChange(oldClickListener, clickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.base;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.ItemLineTracker;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class BaseItemLine extends BaseTouchableLine {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private PickupHandler pickupHandler;
|
||||
private PickupListener pickupListener;
|
||||
|
||||
public BaseItemLine(BaseHologram<?> hologram, ItemStack itemStack) {
|
||||
super(hologram);
|
||||
@ -31,27 +31,27 @@ public abstract class BaseItemLine extends BaseTouchableLine {
|
||||
}
|
||||
|
||||
public void onPickup(Player player) {
|
||||
if (pickupHandler == null || !canInteract(player)) {
|
||||
if (pickupListener == null || !canInteract(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
pickupHandler.onPickup(player);
|
||||
pickupListener.onPickup(player);
|
||||
} catch (Throwable t) {
|
||||
Log.warning("The plugin " + getCreatorPlugin().getName() + " generated an exception"
|
||||
+ " when the player " + player.getName() + " picked up an item from a hologram.", t);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable PickupHandler getPickupHandler() {
|
||||
return pickupHandler;
|
||||
public @Nullable PickupListener getPickupListener() {
|
||||
return pickupListener;
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
public void setPickupHandler(@Nullable PickupHandler pickupHandler) {
|
||||
public void setPickupListener(@Nullable PickupListener pickupListener) {
|
||||
checkNotDeleted();
|
||||
|
||||
this.pickupHandler = pickupHandler;
|
||||
this.pickupListener = pickupListener;
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItemStack() {
|
||||
|
@ -6,7 +6,7 @@
|
||||
package me.filoghost.holographicdisplays.plugin.hologram.base;
|
||||
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -18,14 +18,14 @@ public abstract class BaseTouchableLine extends BaseHologramLine {
|
||||
|
||||
private static final Map<Player, Long> lastClickByPlayer = new WeakHashMap<>();
|
||||
|
||||
private TouchHandler touchHandler;
|
||||
private ClickListener clickListener;
|
||||
|
||||
protected BaseTouchableLine(BaseHologram<?> hologram) {
|
||||
super(hologram);
|
||||
}
|
||||
|
||||
public void onTouch(Player player) {
|
||||
if (touchHandler == null || !canInteract(player)) {
|
||||
if (clickListener == null || !canInteract(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -38,22 +38,22 @@ public abstract class BaseTouchableLine extends BaseHologramLine {
|
||||
lastClickByPlayer.put(player, now);
|
||||
|
||||
try {
|
||||
touchHandler.onTouch(player);
|
||||
clickListener.onClick(player);
|
||||
} catch (Throwable t) {
|
||||
Log.warning("The plugin " + getCreatorPlugin().getName() + " generated an exception"
|
||||
+ " when the player " + player.getName() + " touched a hologram.", t);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable TouchHandler getTouchHandler() {
|
||||
return touchHandler;
|
||||
public @Nullable ClickListener getClickListener() {
|
||||
return clickListener;
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
public void setTouchHandler(@Nullable TouchHandler touchHandler) {
|
||||
public void setClickListener(@Nullable ClickListener clickListener) {
|
||||
checkNotDeleted();
|
||||
|
||||
this.touchHandler = touchHandler;
|
||||
this.clickListener = clickListener;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public abstract class TouchableLineTracker<T extends BaseTouchableLine> extends
|
||||
protected void detectChanges() {
|
||||
super.detectChanges();
|
||||
|
||||
boolean spawnSlimeEntities = line.getTouchHandler() != null;
|
||||
boolean spawnSlimeEntities = line.getClickListener() != null;
|
||||
if (this.spawnSlimeEntities != spawnSlimeEntities) {
|
||||
this.spawnSlimeEntities = spawnSlimeEntities;
|
||||
this.spawnSlimeEntitiesChanged = true;
|
||||
|
@ -5,8 +5,9 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.api.v2;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
|
||||
import me.filoghost.holographicdisplays.api.hologram.TouchHandler;
|
||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine;
|
||||
@ -33,30 +34,30 @@ class V2TouchableLineAdapterTest {
|
||||
void setNullV2TouchHandler() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV3TouchHandler v3TouchHandler = new ExampleV3TouchHandler();
|
||||
ExampleV3ClickListener v3ClickListener = new ExampleV3ClickListener();
|
||||
|
||||
v3Line.setTouchHandler(v3TouchHandler);
|
||||
v3Line.setClickListener(v3ClickListener);
|
||||
v2Line.setTouchHandler(null);
|
||||
|
||||
assertThat(v2Line.getTouchHandler()).isNull();
|
||||
assertThat(v3Line.getTouchHandler()).isNull();
|
||||
assertThat(v3Line.getClickListener()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setNullV3TouchHandler() {
|
||||
void setNullV3ClickListener() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||
|
||||
v2Line.setTouchHandler(v2TouchHandler);
|
||||
v3Line.setTouchHandler(null);
|
||||
v3Line.setClickListener(null);
|
||||
|
||||
assertThat(v2Line.getTouchHandler()).isNull();
|
||||
assertThat(v3Line.getTouchHandler()).isNull();
|
||||
assertThat(v3Line.getClickListener()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setV2GetV2TouchHandler() {
|
||||
void setThenGetV2TouchHandler() {
|
||||
TextLine v2Line = new APITextLine(hologram, "").getV2Adapter();
|
||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||
|
||||
@ -66,25 +67,25 @@ class V2TouchableLineAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setV3GetV2TouchHandler() {
|
||||
void setV3ClickListenerThenGetV2TouchHandler() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV3TouchHandler v3TouchHandler = new ExampleV3TouchHandler();
|
||||
ExampleV3ClickListener v3ClickListener = new ExampleV3ClickListener();
|
||||
|
||||
v3Line.setTouchHandler(v3TouchHandler);
|
||||
v3Line.setClickListener(v3ClickListener);
|
||||
|
||||
assertThat(v2Line.getTouchHandler()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setV2GetV3TouchHandler() {
|
||||
void setV2TouchHandlerThenGetV3ClickListener() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||
|
||||
v2Line.setTouchHandler(v2TouchHandler);
|
||||
|
||||
assertThat(v3Line.getTouchHandler()).isNotNull();
|
||||
assertThat(v3Line.getClickListener()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,7 +93,7 @@ class V2TouchableLineAdapterTest {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
|
||||
v3Line.setTouchHandler(new ExampleV3TouchHandler());
|
||||
v3Line.setClickListener(new ExampleV3ClickListener());
|
||||
assertThat(v2Line.getTouchHandler()).isSameAs(v2Line.getTouchHandler());
|
||||
|
||||
v2Line.setTouchHandler(new ExampleV2TouchHandler());
|
||||
@ -100,103 +101,103 @@ class V2TouchableLineAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedSetV2TouchHandlerShouldNotChangeV3TouchHandlerInstance() {
|
||||
void repeatedSetV2TouchHandlerShouldNotChangeV3ClickListenerInstance() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||
|
||||
v2Line.setTouchHandler(v2TouchHandler);
|
||||
TouchHandler v3TouchHandlerA = v3Line.getTouchHandler();
|
||||
ClickListener v3ClickListenerA = v3Line.getClickListener();
|
||||
v2Line.setTouchHandler(v2TouchHandler);
|
||||
TouchHandler v3TouchHandlerB = v3Line.getTouchHandler();
|
||||
ClickListener v3ClickListenerB = v3Line.getClickListener();
|
||||
|
||||
assertThat(v3TouchHandlerA).isSameAs(v3TouchHandlerB);
|
||||
assertThat(v3ClickListenerA).isSameAs(v3ClickListenerB);
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedSetV3TouchHandlerShouldNotChangeV2TouchHandlerInstance() {
|
||||
void repeatedSetV3ClickListenerShouldNotChangeV2TouchHandlerInstance() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV3TouchHandler v2TouchHandler = new ExampleV3TouchHandler();
|
||||
ExampleV3ClickListener v2TouchHandler = new ExampleV3ClickListener();
|
||||
|
||||
v3Line.setTouchHandler(v2TouchHandler);
|
||||
com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler v2TouchHandlerA = v2Line.getTouchHandler();
|
||||
v3Line.setTouchHandler(v2TouchHandler);
|
||||
com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler v2TouchHandlerB = v2Line.getTouchHandler();
|
||||
v3Line.setClickListener(v2TouchHandler);
|
||||
TouchHandler v2TouchHandlerA = v2Line.getTouchHandler();
|
||||
v3Line.setClickListener(v2TouchHandler);
|
||||
TouchHandler v2TouchHandlerB = v2Line.getTouchHandler();
|
||||
|
||||
assertThat(v2TouchHandlerA).isSameAs(v2TouchHandlerB);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2TouchHandlerChangesWhenV3TouchHandlerChanges() {
|
||||
void v2TouchHandlerChangesWhenV3ClickListenerChanges() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
|
||||
v3Line.setTouchHandler(new ExampleV3TouchHandler());
|
||||
com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler v2TouchHandlerA = v2Line.getTouchHandler();
|
||||
v3Line.setTouchHandler(new ExampleV3TouchHandler());
|
||||
com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler v2TouchHandlerB = v2Line.getTouchHandler();
|
||||
v3Line.setClickListener(new ExampleV3ClickListener());
|
||||
TouchHandler v2TouchHandlerA = v2Line.getTouchHandler();
|
||||
v3Line.setClickListener(new ExampleV3ClickListener());
|
||||
TouchHandler v2TouchHandlerB = v2Line.getTouchHandler();
|
||||
|
||||
assertThat(v2TouchHandlerA).isNotSameAs(v2TouchHandlerB);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v3TouchHandlerChangesWhenV2TouchHandlerChanges() {
|
||||
void v3ClickListenerChangesWhenV2TouchHandlerChanges() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
|
||||
v2Line.setTouchHandler(new ExampleV2TouchHandler());
|
||||
TouchHandler v3TouchHandlerA = v3Line.getTouchHandler();
|
||||
ClickListener v3ClickListenerA = v3Line.getClickListener();
|
||||
v2Line.setTouchHandler(new ExampleV2TouchHandler());
|
||||
TouchHandler v3TouchHandlerB = v3Line.getTouchHandler();
|
||||
ClickListener v3ClickListenerB = v3Line.getClickListener();
|
||||
|
||||
assertThat(v3TouchHandlerA).isNotSameAs(v3TouchHandlerB);
|
||||
assertThat(v3ClickListenerA).isNotSameAs(v3ClickListenerB);
|
||||
}
|
||||
|
||||
@Test
|
||||
void preserveTouchHandlerInstancesWhenUsingV3API() {
|
||||
void preserveInstancesWhenUsingV3API() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV2TouchHandler v2TouchHandler = new ExampleV2TouchHandler();
|
||||
|
||||
v2Line.setTouchHandler(v2TouchHandler);
|
||||
|
||||
TouchHandler v3TouchHandler = v3Line.getTouchHandler();
|
||||
ClickListener v3ClickListener = v3Line.getClickListener();
|
||||
v2Line.setTouchHandler(null); // This also clears the adapter
|
||||
v3Line.setTouchHandler(v3TouchHandler); // Return to the initial value
|
||||
v3Line.setClickListener(v3ClickListener); // Return to the initial value
|
||||
|
||||
// Instances should be the same
|
||||
assertThat(v2Line.getTouchHandler()).isSameAs(v2TouchHandler);
|
||||
assertThat(v3Line.getTouchHandler()).isSameAs(v3TouchHandler);
|
||||
assertThat(v3Line.getClickListener()).isSameAs(v3ClickListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
void preserveTouchHandlerInstancesWhenUsingV2API() {
|
||||
void preserveInstancesWhenUsingV2API() {
|
||||
APITextLine v3Line = hologram.appendTextLine("");
|
||||
TextLine v2Line = v3Line.getV2Adapter();
|
||||
ExampleV3TouchHandler v3TouchHandler = new ExampleV3TouchHandler();
|
||||
ExampleV3ClickListener v3ClickListener = new ExampleV3ClickListener();
|
||||
|
||||
v3Line.setTouchHandler(v3TouchHandler);
|
||||
v3Line.setClickListener(v3ClickListener);
|
||||
|
||||
com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler v2TouchHandler = v2Line.getTouchHandler();
|
||||
TouchHandler v2TouchHandler = v2Line.getTouchHandler();
|
||||
v2Line.setTouchHandler(null); // This also clears the adapter
|
||||
v2Line.setTouchHandler(v2TouchHandler); // Return to the initial value
|
||||
|
||||
// Instances should be the same
|
||||
assertThat(v2Line.getTouchHandler()).isSameAs(v2TouchHandler);
|
||||
assertThat(v3Line.getTouchHandler()).isSameAs(v3TouchHandler);
|
||||
assertThat(v3Line.getClickListener()).isSameAs(v3ClickListener);
|
||||
}
|
||||
|
||||
|
||||
private static class ExampleV3TouchHandler implements TouchHandler {
|
||||
private static class ExampleV3ClickListener implements ClickListener {
|
||||
|
||||
@Override
|
||||
public void onTouch(@NotNull Player player) {}
|
||||
public void onClick(@NotNull Player player) {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class ExampleV2TouchHandler implements com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler {
|
||||
private static class ExampleV2TouchHandler implements TouchHandler {
|
||||
|
||||
@Override
|
||||
public void onTouch(Player player) {}
|
||||
|
Loading…
Reference in New Issue
Block a user