Skip to content

Commit

Permalink
Final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Jun 22, 2024
1 parent 088e64f commit 1f3da53
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'com.maximde'
version = '1.2.2'
version = '1.2.4'

repositories {
mavenCentral()
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/maximde/hologramapi/HologramAPI.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.maximde.hologramapi;

import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.player.PlayerManager;
import com.maximde.hologramapi.bstats.Metrics;
import com.maximde.hologramapi.hologram.HologramManager;
import com.maximde.hologramapi.utils.ItemsAdderHolder;
import com.maximde.hologramapi.utils.ReplaceText;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import lombok.Getter;
import me.tofaa.entitylib.APIConfig;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform;
import org.bukkit.plugin.java.JavaPlugin;

public final class HologramAPI extends JavaPlugin {
Expand All @@ -22,8 +27,28 @@ public final class HologramAPI extends JavaPlugin {
@Getter
private static HologramAPI instance;

@Override
public void onLoad() {
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().reEncodeByDefault(false)
.checkForUpdates(false)
.bStats(true);
PacketEvents.getAPI().load();
}

@Override
public void onEnable() {
instance = this;
PacketEvents.getAPI().init();

SpigotEntityLibPlatform platform = new SpigotEntityLibPlatform(this);
APIConfig settings = new APIConfig(PacketEvents.getAPI())
.usePlatformLogger();

EntityLib.init(platform, settings);

playerManager = PacketEvents.getAPI().getPlayerManager();

hologram = new HologramManager(this);
new Metrics(this, 19375);

Expand All @@ -34,4 +59,8 @@ public void onEnable() {
}
}

@Override
public void onDisable() {
PacketEvents.getAPI().terminate();
}
}
63 changes: 36 additions & 27 deletions src/main/java/com/maximde/hologramapi/hologram/TextHologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public TextHologram(String id) {

private void startRunnable() {
if(task != null) return;
task = Bukkit.getServer().getScheduler().runTaskTimer(HologramAPI.getInstance(), this::updateAffectedPlayers, 20L, 20L * 2);
task = Bukkit.getServer().getScheduler().runTaskTimer(HologramAPI.getInstance(), this::updateAffectedPlayers, 20L, 20L * 3);
}

public TextHologram spawn(Location location) {
Expand All @@ -108,33 +108,39 @@ public TextHologram spawn(Location location) {
WrapperPlayServerSpawnEntity packet = new WrapperPlayServerSpawnEntity(entityID, Optional.of(UUID.randomUUID()),
EntityTypes.TEXT_DISPLAY,
new Vector3d(this.location.getX(), this.location.getY() + 1, this.location.getZ()), 0f, 0f, 0f, 0, Optional.empty());
updateAffectedPlayers();
sendPacket(packet);
this.dead = false;
HologramAPI.getInstance().getServer().getScheduler().runTask(HologramAPI.getInstance(), t -> {
updateAffectedPlayers();
sendPacket(packet);
this.dead = false;
});

update();
return this;
}

public TextHologram update() {
updateAffectedPlayers();
TextDisplayMeta meta = (TextDisplayMeta) EntityMeta.createMeta(this.entityID, EntityTypes.TEXT_DISPLAY);
meta.setText(getTextAsComponent());
meta.setInterpolationDelay(-1);
meta.setTransformationInterpolationDuration(this.getInterpolationDurationTicks());
meta.setPositionRotationInterpolationDuration(this.getInterpolationDurationTicks());
meta.setTranslation(new com.github.retrooper.packetevents.util.Vector3f(this.getTranslation().getX(), this.getTranslation().getY() ,this.getTranslation().getZ()));
meta.setScale(new com.github.retrooper.packetevents.util.Vector3f(this.getScale().getX(), this.getScale().getY() ,this.getScale().getZ()));
meta.setBillboardConstraints(AbstractDisplayMeta.BillboardConstraints.valueOf(this.getBillboard().name()));
meta.setLineWidth(this.getMaxLineWidth());
meta.setViewRange((float) this.getViewRange());
meta.setBackgroundColor(this.getBackgroundColor());
meta.setTextOpacity(this.getTextOpacity());
meta.setShadow(this.isShadow());
meta.setSeeThrough(this.isSeeThroughBlocks());
switch (this.getAlignment()) {
case LEFT -> meta.setAlignLeft(true);
case RIGHT -> meta.setAlignRight(true);
}
sendPacket(meta.createPacket());
HologramAPI.getInstance().getServer().getScheduler().runTask(HologramAPI.getInstance(), t -> {
updateAffectedPlayers();
TextDisplayMeta meta = (TextDisplayMeta) EntityMeta.createMeta(this.entityID, EntityTypes.TEXT_DISPLAY);
meta.setText(getTextAsComponent());
meta.setInterpolationDelay(-1);
meta.setTransformationInterpolationDuration(this.getInterpolationDurationTicks());
meta.setPositionRotationInterpolationDuration(this.getInterpolationDurationTicks());
meta.setTranslation(new com.github.retrooper.packetevents.util.Vector3f(this.getTranslation().getX(), this.getTranslation().getY() ,this.getTranslation().getZ()));
meta.setScale(new com.github.retrooper.packetevents.util.Vector3f(this.getScale().getX(), this.getScale().getY() ,this.getScale().getZ()));
meta.setBillboardConstraints(AbstractDisplayMeta.BillboardConstraints.valueOf(this.getBillboard().name()));
meta.setLineWidth(this.getMaxLineWidth());
meta.setViewRange((float) this.getViewRange());
meta.setBackgroundColor(this.getBackgroundColor());
meta.setTextOpacity(this.getTextOpacity());
meta.setShadow(this.isShadow());
meta.setSeeThrough(this.isSeeThroughBlocks());
switch (this.getAlignment()) {
case LEFT -> meta.setAlignLeft(true);
case RIGHT -> meta.setAlignRight(true);
}
sendPacket(meta.createPacket());
});
return this;
}

Expand Down Expand Up @@ -240,11 +246,14 @@ private void updateAffectedPlayers() {

if(this.getRenderMode() == RenderMode.VIEWER_LIST) return;
if(this.getRenderMode() == RenderMode.ALL) this.addAllViewers(new ArrayList<>(Bukkit.getOnlinePlayers()));
if(this.getRenderMode() == RenderMode.NEARBY) this.location.getWorld().getNearbyEntities(this.location, 40, 40, 40).forEach(entity -> {
if(entity instanceof Player pl) this.getViewers().add(pl);
});
if(this.getRenderMode() == RenderMode.NEARBY) {
this.location.getWorld().getNearbyEntities(this.location, 40, 40, 40).forEach(entity -> {
if(entity instanceof Player pl) this.getViewers().add(pl);
});
}
}


private void sendPacket(PacketWrapper<?> packet) {
if(this.renderMode == RenderMode.NONE) return;
this.getViewers().forEach(player -> {
Expand Down

0 comments on commit 1f3da53

Please sign in to comment.