generated from Slimefun/Addon-Template
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/EndermanAdapter.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,59 @@ | ||
package io.github.thebusybiscuit.mobcapturer.adapters.mobs; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
import io.github.thebusybiscuit.mobcapturer.adapters.MobAdapter; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.block.data.BlockData; | ||
import org.bukkit.entity.Enderman; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import java.util.List; | ||
|
||
public class EndermanAdapter implements MobAdapter<Enderman> { | ||
|
||
@Nonnull | ||
@Override | ||
public List<String> getLore(@Nonnull JsonObject json) { | ||
List<String> lore = MobAdapter.super.getLore(json); | ||
|
||
lore.add(ChatColor.GRAY + "Carrying block: " + ChatColor.WHITE + json.has("carriedBlock")); | ||
|
||
return lore; | ||
} | ||
|
||
@Override | ||
@ParametersAreNonnullByDefault | ||
public void apply(Enderman entity, JsonObject json) { | ||
MobAdapter.super.apply(entity, json); | ||
|
||
if (json.has("carriedBlock")) { | ||
BlockData blockData = Bukkit.getServer().createBlockData(json.get("carriedBlock").getAsString()); | ||
entity.setCarriedBlock(blockData); | ||
} | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public JsonObject saveData(@Nonnull Enderman entity) { | ||
JsonObject json = MobAdapter.super.saveData(entity); | ||
|
||
BlockData blockData = entity.getCarriedBlock(); | ||
if (blockData != null) { | ||
json.addProperty("carriedBlock", blockData.getAsString()); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Class<Enderman> getEntityClass() { | ||
return Enderman.class; | ||
} | ||
|
||
} |
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