1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Fixed formatting, import and small optimization

This commit is contained in:
TheBusyBiscuit 2021-01-15 11:52:56 +01:00
parent 3663a7d43b
commit d678977a03
3 changed files with 27 additions and 9 deletions

View File

@ -32,7 +32,7 @@ public interface HologramOwner extends ItemAttribute {
* The nametag for the hologram * The nametag for the hologram
*/ */
default void updateHologram(@Nonnull Block b, @Nonnull String text) { default void updateHologram(@Nonnull Block b, @Nonnull String text) {
Location loc = b.getLocation().add(getHologramOffset()); Location loc = b.getLocation().add(getHologramOffset(b));
SlimefunPlugin.getHologramsService().setHologramLabel(loc, ChatColors.color(text)); SlimefunPlugin.getHologramsService().setHologramLabel(loc, ChatColors.color(text));
} }
@ -43,7 +43,7 @@ public interface HologramOwner extends ItemAttribute {
* The {@link Block} to which the hologram blocks * The {@link Block} to which the hologram blocks
*/ */
default void removeHologram(@Nonnull Block b) { default void removeHologram(@Nonnull Block b) {
Location loc = b.getLocation().add(getHologramOffset()); Location loc = b.getLocation().add(getHologramOffset(b));
SlimefunPlugin.getHologramsService().removeHologram(loc); SlimefunPlugin.getHologramsService().removeHologram(loc);
} }
@ -52,11 +52,14 @@ public interface HologramOwner extends ItemAttribute {
* This offset is applied to {@link Block#getLocation()} when spawning * This offset is applied to {@link Block#getLocation()} when spawning
* the hologram. * the hologram.
* *
* @param block
* The {@link Block} which serves as the origin point
*
* @return The hologram offset * @return The hologram offset
*/ */
@Nonnull @Nonnull
default Vector getHologramOffset() { default Vector getHologramOffset(@Nonnull Block block) {
return new Vector(0.5, 0.75, 0.5); return SlimefunPlugin.getHologramsService().getDefaultOffset();
} }
} }

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.services.holograms; package io.github.thebusybiscuit.slimefun4.core.services.holograms;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -10,7 +11,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import com.google.common.base.Objects;
/** /**
* This represents an {@link ArmorStand} that can expire and be renamed. * This represents an {@link ArmorStand} that can expire and be renamed.
@ -99,7 +99,7 @@ class Hologram {
* The label to set * The label to set
*/ */
void setLabel(@Nullable String label) { void setLabel(@Nullable String label) {
if (Objects.equal(this.label, label)) { if (Objects.equals(this.label, label)) {
/* /*
* Label is already set, no need to cause an entity * Label is already set, no need to cause an entity
* update. But we can update the lastAccess flag. * update. But we can update the lastAccess flag.

View File

@ -21,6 +21,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition; import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.core.attributes.HologramOwner; import io.github.thebusybiscuit.slimefun4.core.attributes.HologramOwner;
@ -51,6 +52,11 @@ public class HologramsService {
*/ */
private final Plugin plugin; private final Plugin plugin;
/**
* The default hologram offset
*/
private final Vector defaultOffset = new Vector(0.5, 0.75, 0.5);
/** /**
* The {@link NamespacedKey} used to store data on a hologram * The {@link NamespacedKey} used to store data on a hologram
*/ */
@ -82,6 +88,16 @@ public class HologramsService {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this::purge, PURGE_RATE, PURGE_RATE); plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this::purge, PURGE_RATE, PURGE_RATE);
} }
/**
* This returns the default {@link Hologram} offset.
*
* @return The default offset
*/
@Nonnull
public Vector getDefaultOffset() {
return defaultOffset;
}
/** /**
* This purges any expired {@link Hologram}. * This purges any expired {@link Hologram}.
*/ */
@ -252,9 +268,8 @@ public class HologramsService {
* @param loc * @param loc
* The {@link Location} * The {@link Location}
* *
* @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not exist or was * @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not
* already * exist or was already removed
* removed
*/ */
public boolean removeHologram(@Nonnull Location loc) { public boolean removeHologram(@Nonnull Location loc) {
Validate.notNull(loc, "Location cannot be null"); Validate.notNull(loc, "Location cannot be null");