Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eba6a1d
commit 62a5058
Showing
3 changed files
with
105 additions
and
1 deletion.
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
103 changes: 103 additions & 0 deletions
103
...main/java/com/denizenscript/denizen/objects/properties/entity/EntityConversionPlayer.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,103 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.PlayerTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.ZombieVillager; | ||
|
||
public class EntityConversionPlayer implements Property { | ||
|
||
public static boolean describes(ObjectTag object) { | ||
if (!(object instanceof EntityTag)) { | ||
return false; | ||
} | ||
Entity entity = ((EntityTag) object).getBukkitEntity(); | ||
return entity instanceof ZombieVillager; | ||
} | ||
|
||
public static EntityConversionPlayer getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityConversionPlayer((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"conversion_player" | ||
}; | ||
|
||
private EntityConversionPlayer(EntityTag ent) { | ||
entity = ent; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
OfflinePlayer player = getZombieVillager().getConversionPlayer(); | ||
if (player != null && player.hasPlayedBefore()) { | ||
return new PlayerTag(player).identify(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "conversion_player"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.conversion_player> | ||
// @returns PlayerTag | ||
// @mechanism EntityTag.conversion_player | ||
// @group properties | ||
// @description | ||
// Returns the player that caused a zombie villager to start converting back to a villager, if any. | ||
// --> | ||
PropertyParser.<EntityConversionPlayer, PlayerTag>registerTag(PlayerTag.class, "conversion_player", (attribute, object) -> { | ||
OfflinePlayer player = object.getZombieVillager().getConversionPlayer(); | ||
if (player != null && player.hasPlayedBefore()) { | ||
return new PlayerTag(player); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
public ZombieVillager getZombieVillager() { | ||
return (ZombieVillager) entity.getBukkitEntity(); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name conversion_player | ||
// @input PlayerTag | ||
// @description | ||
// Sets the player that caused a zombie villager to start converting back to a villager. | ||
// Give no input to remove the player ID from the zombie-villager. | ||
// @tags | ||
// <EntityTag.conversion_player> | ||
// --> | ||
if (mechanism.matches("conversion_player")) { | ||
if (mechanism.hasValue()) { | ||
if (mechanism.requireObject(PlayerTag.class)) { | ||
getZombieVillager().setConversionPlayer(mechanism.valueAsType(PlayerTag.class).getOfflinePlayer()); | ||
} | ||
} | ||
else { | ||
getZombieVillager().setConversionPlayer(null); | ||
} | ||
} | ||
} | ||
} |
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