forked from rlf/uSkyBlock
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wither spawning with disabled spawn-limits (#66)
* Fix wither spawning with disabled spawn-limits Resolves #60 Decouples wither-origin tracking and spawn limit listeners. The issue was that withers were tagged with their origin island in the creature spawn listeners for of SpawnEvents, which is not registered if spawn limits are disabled. I solved this by moving the wither tagging logic into a separate listener that is always active. Untagged Withers are despawned by the GriefEvents listener. I also migrated the tagging to PDC to make the tagging consistent without relying on name tagging that is prone to errors. * Cleanup SpawnEvents
- Loading branch information
Showing
4 changed files
with
67 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/event/WitherTagListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package us.talabrek.ultimateskyblock.event; | ||
|
||
import dk.lockfuglsang.minecraft.po.I18nUtil; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.entity.Wither; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.CreatureSpawnEvent; | ||
import org.bukkit.persistence.PersistentDataType; | ||
import us.talabrek.ultimateskyblock.api.IslandInfo; | ||
import us.talabrek.ultimateskyblock.uSkyBlock; | ||
|
||
public class WitherTagListener implements Listener { | ||
|
||
static final String ENTITY_ORIGIN_METADATA = "from-island"; | ||
private final uSkyBlock plugin; | ||
|
||
public WitherTagListener(uSkyBlock plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler(ignoreCancelled = true) | ||
public void onCreatureSpawn(CreatureSpawnEvent event) { | ||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BUILD_WITHER | ||
&& event.getEntity() instanceof Wither wither) { | ||
IslandInfo islandInfo = plugin.getIslandInfo(event.getLocation()); | ||
if (islandInfo != null && islandInfo.getLeader() != null) { | ||
wither.setCustomName(I18nUtil.tr("{0}''s Wither", islandInfo.getLeader())); | ||
NamespacedKey key = new NamespacedKey(plugin, ENTITY_ORIGIN_METADATA); | ||
wither.getPersistentDataContainer().set(key, PersistentDataType.STRING, islandInfo.getName()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters