Skip to content

Commit

Permalink
🔥 Remove debug, API is now working and probably finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Sep 11, 2024
1 parent 98bb44c commit 9d0cbd1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mattmx/nametags/EventsListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mattmx.nametags;

import com.mattmx.nametags.entity.NameTagEntity;
import com.mattmx.nametags.entity.trait.RefreshTrait;
import com.mattmx.nametags.event.NameTagEntityCreateEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/mattmx/nametags/NameTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.util.Vector3f;
import com.mattmx.nametags.entity.NameTagEntityManager;
import com.mattmx.nametags.entity.TestImplTrait;
import me.tofaa.entitylib.APIConfig;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.meta.display.AbstractDisplayMeta;
import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -54,9 +52,6 @@ public void onEnable() {
.registerListener(packetListener);

Bukkit.getPluginManager().registerEvents(eventsListener, this);

// DEBUG
Bukkit.getPluginManager().registerEvents(new TestImplTrait(), this);
}

public @NotNull NameTagEntityManager getEntityManager() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mattmx/nametags/entity/NameTagEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.tofaa.entitylib.wrapper.WrapperEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void modify(Consumer<TextDisplayMeta> consumer) {
this.passenger.consumeEntityMeta(TextDisplayMeta.class, consumer);
}

public @NotNull TextDisplayMeta getMeta() {
return this.passenger.getEntityMeta(TextDisplayMeta.class);
}

public void sendPassengerPacket(Player target) {
PacketEvents.getAPI()
.getPlayerManager()
Expand Down
44 changes: 0 additions & 44 deletions src/main/java/com/mattmx/nametags/entity/TestImplTrait.java

This file was deleted.

52 changes: 52 additions & 0 deletions src/main/java/com/mattmx/nametags/entity/trait/RefreshTrait.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mattmx.nametags.entity.trait;

import com.mattmx.nametags.entity.NameTagEntity;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

public class RefreshTrait extends Trait {
private final @NotNull ScheduledTask task;
private boolean paused = false;

public RefreshTrait(@NotNull JavaPlugin plugin, long period, TimeUnit unit, Consumer<NameTagEntity> update) {
this.task = Bukkit.getAsyncScheduler()
.runAtFixedRate(plugin, (task) -> {

if (!this.isPaused()) {
update.accept(getTag());
}

}, 0L, period, unit);
}

public void setPaused(boolean paused) {
this.paused = paused;
}

public boolean isPaused() {
return this.paused;
}

@Override
public void onDestroy() {
task.cancel();
}

public static @NotNull RefreshTrait ofMinutes(@NotNull JavaPlugin plugin, long minutes, Consumer<NameTagEntity> update) {
return new RefreshTrait(plugin, minutes, TimeUnit.MINUTES, update);
}

public static @NotNull RefreshTrait ofSeconds(@NotNull JavaPlugin plugin, long seconds, Consumer<NameTagEntity> update) {
return new RefreshTrait(plugin, seconds, TimeUnit.SECONDS, update);
}

public static @NotNull RefreshTrait ofTicks(@NotNull JavaPlugin plugin, long ticks, Consumer<NameTagEntity> update) {
return new RefreshTrait(plugin, ticks * 50, TimeUnit.MILLISECONDS, update);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public TraitHolder(@NotNull NameTagEntity owner) {
return null;
}

public <T extends Trait> boolean hasTrait(@NotNull Class<T> traitClazz) {
return map.containsKey(traitClazz);
}

public void destroy() {
for (Trait trait : map.values()) {
trait.onDestroy();
Expand Down

0 comments on commit 9d0cbd1

Please sign in to comment.