Skip to content

Commit

Permalink
SittingTrait: multiple retries, also clean up the last PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 8, 2022
1 parent f0e2c3f commit 7a1643f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Expand Up @@ -126,7 +126,7 @@ public void sitInternal(Location location) {
safetyCleanup(location.clone());
new NPCTag(npc).action("sit", null);
npc.getEntity().teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
forceEntitySit(npc.getEntity(), location.clone(), false);
forceEntitySit(npc.getEntity(), location.clone(), 0);
sitting = true;
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public void forceUnsit(Entity entity) {

public NPC sitStandNPC = null;

public void forceEntitySit(Entity entity, Location location, boolean isRetry) {
public void forceEntitySit(Entity entity, Location location, int retryCount) {
if (sitStandNPC != null) {
sitStandNPC.destroy();
}
Expand All @@ -252,15 +252,15 @@ public void forceEntitySit(Entity entity, Location location, boolean isRetry) {
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
boolean spawned = holder.spawn(location);
if (!spawned || !holder.isSpawned()) {
if (isRetry) {
if (retryCount >= 4) {
Debug.echoError("NPC " + (npc == null ? "null" : npc.getId()) + " sit failed (" + spawned + "," + holder.isSpawned() + "): cannot spawn chair id "
+ holder.getId() + " at " + new LocationTag(location).identifySimple() + " ChunkIsLoaded=" + new ChunkTag(location).isLoaded());
holder.destroy();
sitStandNPC = null;
}
else {
Messaging.debug("(Denizen/SittingTrait) retrying failed sit for", npc.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> { if (npc.isSpawned()) { forceEntitySit(entity, location, true); } }, 5);
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> { if (npc.isSpawned()) { forceEntitySit(entity, location, retryCount + 1); } }, 5);
}
return;
}
Expand Down
Expand Up @@ -176,9 +176,7 @@ public void adjust(Mechanism mechanism) {
CustomNBT.removeCustomNBT(dentity.getBukkitEntity(), CustomNBT.KEY_DISABLED_SLOTS);
return;
}

Map<EquipmentSlot, Set<Action>> map = new HashMap<>();

if (mechanism.value.canBeType(MapTag.class)) {
MapTag input = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> entry : input.map.entrySet()) {
Expand All @@ -188,10 +186,8 @@ public void adjust(Mechanism mechanism) {
mechanism.echoError("Invalid equipment slot specified: " + entry.getKey().str);
continue;
}

ListTag actionsInput = entry.getValue().asType(ListTag.class, mechanism.context);
Set<Action> actions = new HashSet<>();

for (String actionStr : actionsInput) {
Action action = new ElementTag(actionStr).asEnum(Action.class);
if (action == null) {
Expand All @@ -208,15 +204,12 @@ public void adjust(Mechanism mechanism) {
ListTag input = mechanism.valueAsType(ListTag.class);
for (String string : input) {
String[] split = string.split("/", 2);

EquipmentSlot slot = new ElementTag(split[0]).asEnum(EquipmentSlot.class);
Action action = Action.ALL;

if (slot == null) {
mechanism.echoError("Invalid equipment slot specified: " + split[0]);
continue;
}

if (split.length == 2) {
action = new ElementTag(split[1]).asEnum(Action.class);
if (action == null) {
Expand All @@ -228,7 +221,6 @@ public void adjust(Mechanism mechanism) {
set.add(action);
}
}

CustomNBT.setDisabledSlots(dentity.getBukkitEntity(), map);
}
}
Expand Down
Expand Up @@ -166,6 +166,8 @@ public class BukkitImplDeprecations {

// Added 2021/05/05.
public static Warning locationDistanceTag = new SlowWarning("locationDistanceTag", "locationtag.tree_distance is deprecated in favor of location.material.distance");

// Added 2022/05/07.
public static Warning armorStandRawSlot = new SlowWarning("armorStandRawSlot", "The EntityTag.disabled_slots.raw tag and EntityTag.disabled_slots_raw mechanism are deprecated, use the EntityTag.disabled_slots_data tag and EntityTag.disabled_slots mechanism instead.");

// ==================== VERY SLOW deprecations ====================
Expand Down Expand Up @@ -250,8 +252,8 @@ public class BukkitImplDeprecations {
// Added 2022/02/21, deprecate officially by 2024.
public static Warning oldPotionEffects = new FutureWarning("oldPotionEffects", "The comma-separated-list potion effect tags like 'list_effects' are deprecated in favor of MapTag based tags - 'effects_data'. Refer to meta documentation for details.");

// Added 2022/5/7, deprecate officially by 2024.
public static Warning armorStandDisabledSlotsOldFormat = new FutureWarning("armorStandDisabledSlotsList", "The EntityTag.disabled_slots tag and the SLOT/ACTION format in the EntityTag.disabled_slots mechanism are deprecated in favour of the EntityTag.disabled_slots_data tag and the MapTag format.");
// Added 2022/05/07, deprecate officially by 2024.
public static Warning armorStandDisabledSlotsOldFormat = new FutureWarning("armorStandDisabledSlotsOldFormat", "The EntityTag.disabled_slots tag and the SLOT/ACTION format in the EntityTag.disabled_slots mechanism are deprecated in favour of the EntityTag.disabled_slots_data tag and the MapTag format.");


// ==================== PAST deprecations of things that are already gone but still have a warning left behind ====================
Expand Down

0 comments on commit 7a1643f

Please sign in to comment.