forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Egg {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final String message;
|
||||
private final EggDifficulty difficulty;
|
||||
|
||||
private Optional<PlayerProfile> playerProfile = null;
|
||||
|
||||
public Egg(Map<String, ?> config) {
|
||||
this.x = (int) config.get("x");
|
||||
this.y = (int) config.get("y");
|
||||
this.z = (int) config.get("z");
|
||||
this.message = (String) config.get("name");
|
||||
this.difficulty = EggDifficulty.valueOf(((String) config.get("difficulty")).toUpperCase());
|
||||
}
|
||||
|
||||
public Vector getVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public EggDifficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (block.getType() != Material.PLAYER_HEAD && block.getType() != Material.PLAYER_WALL_HEAD) {
|
||||
System.out.println("Block is not a skull: " + block.getType() + " " + x + "," + y + "," + z);
|
||||
return null;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
public SWItem getItem(Player player, boolean found) {
|
||||
if (playerProfile == null) {
|
||||
Block block = getBlock();
|
||||
if (block == null) {
|
||||
playerProfile = Optional.empty();
|
||||
return null;
|
||||
}
|
||||
|
||||
Skull skull = (Skull) block.getState();
|
||||
PlayerProfile playerProfile = skull.getOwnerProfile();
|
||||
if (playerProfile == null) {
|
||||
this.playerProfile = Optional.empty();
|
||||
return null;
|
||||
}
|
||||
this.playerProfile = Optional.of(playerProfile);
|
||||
}
|
||||
|
||||
if (!playerProfile.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SWItem swItem;
|
||||
if (found) {
|
||||
swItem = new SWItem();
|
||||
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
|
||||
skullMeta.setOwnerProfile(playerProfile.get());
|
||||
itemStack.setItemMeta(skullMeta);
|
||||
swItem.setItemStack(itemStack);
|
||||
} else {
|
||||
swItem = SWItem.getPlayerSkull("MHF_Question");
|
||||
}
|
||||
|
||||
swItem.setLore(Arrays.asList(LobbySystem.getMessage().parse(difficulty.getMessage(), player)));
|
||||
try {
|
||||
swItem.setName("§f" + LobbySystem.getMessage().parse(message, player));
|
||||
} catch (Exception e) {
|
||||
swItem.setName("§f" + message);
|
||||
}
|
||||
return swItem;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user