mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
force tick task to dispatch on create
This commit is contained in:
@@ -55,6 +55,7 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
|
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
|
||||||
.createCosmeticUser(uuid)
|
.createCosmeticUser(uuid)
|
||||||
.initialize(userData);
|
.initialize(userData);
|
||||||
|
cosmeticUser.startTicking();
|
||||||
|
|
||||||
CosmeticUsers.addUser(cosmeticUser);
|
CosmeticUsers.addUser(cosmeticUser);
|
||||||
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
|
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
|
||||||
|
|||||||
@@ -45,10 +45,9 @@ import java.util.*;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CosmeticUser {
|
public class CosmeticUser {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final UUID uniqueId;
|
private final UUID uniqueId;
|
||||||
private int taskId;
|
private int taskId = -1;
|
||||||
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||||
private UserWardrobeManager userWardrobeManager;
|
private UserWardrobeManager userWardrobeManager;
|
||||||
private UserBalloonManager userBalloonManager;
|
private UserBalloonManager userBalloonManager;
|
||||||
@@ -105,7 +104,6 @@ public class CosmeticUser {
|
|||||||
this.applyHiddenState(userData.getHiddenReasons());
|
this.applyHiddenState(userData.getHiddenReasons());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startTickTask();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,25 +161,48 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTickTask() {
|
/**
|
||||||
// Occasionally updates the entity cosmetics
|
* Start ticking against the {@link CosmeticUser}.
|
||||||
Runnable run = () -> {
|
* @implNote The tick-rate is determined by the {@link Settings#getTickPeriod()}, if it is less-than or equal to 0
|
||||||
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
|
* there will be no {@link BukkitTask} created, and the {@link CosmeticUser#taskId} will be -1
|
||||||
if (Hooks.isInvisible(uniqueId)) hideCosmetics(HiddenReason.VANISH);
|
*/
|
||||||
else showCosmetics(HiddenReason.VANISH);
|
public final void startTicking() {
|
||||||
updateCosmetic();
|
|
||||||
if (isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
|
||||||
};
|
|
||||||
|
|
||||||
int tickPeriod = Settings.getTickPeriod();
|
int tickPeriod = Settings.getTickPeriod();
|
||||||
if (tickPeriod > 0) {
|
if(tickPeriod <= 0) {
|
||||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), run, 0, tickPeriod);
|
MessagesUtil.sendDebugMessages("CosmeticUser tick is disabled.");
|
||||||
taskId = task.getTaskId();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), this::tick, 0, tickPeriod);
|
||||||
|
this.taskId = task.getTaskId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch an operation to happen against this {@link CosmeticUser}
|
||||||
|
* at a pre-determined tick-rate.
|
||||||
|
* The tick-rate is determined by the {@link Settings#getTickPeriod()}.
|
||||||
|
*/
|
||||||
|
protected void tick() {
|
||||||
|
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
|
||||||
|
|
||||||
|
if (Hooks.isInvisible(uniqueId)) {
|
||||||
|
this.hideCosmetics(HiddenReason.VANISH);
|
||||||
|
} else {
|
||||||
|
this.showCosmetics(HiddenReason.VANISH);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateCosmetic();
|
||||||
|
|
||||||
|
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) {
|
||||||
|
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
Bukkit.getScheduler().cancelTask(taskId);
|
if(this.taskId != -1) { // ensure we're actually ticking this user.
|
||||||
|
Bukkit.getScheduler().cancelTask(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
despawnBackpack();
|
despawnBackpack();
|
||||||
despawnBalloon();
|
despawnBalloon();
|
||||||
}
|
}
|
||||||
@@ -237,7 +258,6 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeCosmeticSlot(CosmeticSlot slot) {
|
public void removeCosmeticSlot(CosmeticSlot slot) {
|
||||||
// API
|
// API
|
||||||
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
|
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
|
||||||
@@ -260,7 +280,6 @@ public class CosmeticUser {
|
|||||||
removeArmor(slot);
|
removeArmor(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeCosmeticSlot(Cosmetic cosmetic) {
|
public void removeCosmeticSlot(Cosmetic cosmetic) {
|
||||||
removeCosmeticSlot(cosmetic.getSlot());
|
removeCosmeticSlot(cosmetic.getSlot());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user