use of org.bukkit.inventory.meta.SpawnEggMeta in project Skills by StarTux.
the class BukkitSkillSacrifice method rewardsForItem.
List<Reward> rewardsForItem(ItemStack item) {
List<Reward> result = new ArrayList<>();
if (item == null)
return result;
addReward(result, rewardForItem(item));
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
}
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta instanceof EnchantmentStorageMeta) {
for (Map.Entry<Enchantment, Integer> entry : ((EnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) {
addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
}
}
if (meta instanceof SpawnEggMeta) {
SpawnEggMeta spawnEggMeta = (SpawnEggMeta) meta;
if (spawnEggMeta.getSpawnedType() != null) {
addReward(result, rewardForEntityType(spawnEggMeta.getSpawnedType()));
}
}
}
return result;
}
use of org.bukkit.inventory.meta.SpawnEggMeta in project LandLord by SpatiumPrinceps.
the class AbstractManage method create.
@Override
protected void create() {
List<String> regenerateDesc = lm.getStringList("Commands.Manage.Regenerate.description");
List<String> greetDesc = lm.getStringList("Commands.Manage.SetGreet.description");
List<String> farewellDesc = lm.getStringList("Commands.Manage.SetFarewell.description");
int position = 0;
if (regions.size() < 1)
return;
OwnedLand land = regions.get(0);
for (LLFlag iFlag : land.getFlags()) {
// For every IFlag of the land we wanna display an icon in the gui IF the flag is enabled for change
String flagName = iFlag.getWGFlag().getName();
String title = lm.getRawString("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".title");
List<String> description = lm.getStringList("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".description");
if (plugin.getConfig().getBoolean("Manage." + flagName + ".enable")) {
int finalPosition = position;
this.setIcon(position, new Icon(createItem(iFlag.getMaterial(), 1, title, formatList(description, iFlag.getStatus()))).addClickAction((p, icon) -> {
for (OwnedLand region : regions) {
for (LLFlag llFlag : region.getFlags()) {
if (llFlag.getWGFlag().equals(iFlag.getWGFlag())) {
llFlag.toggle();
}
}
}
updateLore(finalPosition, formatList(description, iFlag.getStatus()));
}));
position++;
}
}
// Reminder: Regenerate is not implemented in Manageall, cos it might cos some trouble. Calculating costs might be a bit tedious
if (plugin.getConfig().getBoolean("Manage.regenerate.enable") && regions.size() == 1) {
double cost = plugin.getConfig().getDouble("ResetCost");
this.setIcon(position, new Icon(createItem(Material.BARRIER, 1, lm.getRawString("Commands.Manage.Regenerate.title"), formatList(regenerateDesc, (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")))).addClickAction((p, ic) -> {
if (land.isOwner(player.getUniqueId())) {
ConfirmationGUI confi = new ConfirmationGUI(p, lm.getRawString("Commands.Manage.Regenerate.confirmation").replace("%cost%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")), (p1, ic1) -> {
boolean flag = false;
if (Options.isVaultEnabled())
if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
plugin.getVaultHandler().take(player.getUniqueId(), cost);
flag = true;
} else
player.sendMessage(lm.getString("Commands.Manage.Regenerate.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)).replace("%name%", land.getName()));
else
flag = true;
if (flag) {
if (land.isOwner(player.getUniqueId())) {
player.getWorld().regenerateChunk(land.getChunk().getX(), land.getChunk().getZ());
player.sendMessage(lm.getString("Commands.Manage.Regenerate.success").replace("%land%", land.getName()));
display();
}
}
}, (p2, ic2) -> {
player.sendMessage(lm.getString("Commands.Manage.Regenerate.abort").replace("%land%", land.getName()));
display();
}, this);
confi.setConfirm(lm.getRawString("Confirmation.accept"));
confi.setDecline(lm.getRawString("Confirmation.decline"));
confi.display();
}
}));
position++;
}
// Set greet icon
if (plugin.getConfig().getBoolean("Manage.setgreet.enable")) {
String currentGreet = land.getWGLand().getFlag(DefaultFlag.GREET_MESSAGE);
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setgreet.item")), 1, lm.getRawString("Commands.Manage.SetGreet.title"), formatList(greetDesc, currentGreet))).addClickAction(((p, ic) -> {
p.closeInventory();
ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetGreet.clickMsg"));
if (regions.size() > 1)
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreetall "));
else
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreet "));
p.spigot().sendMessage(builder.create());
})));
position++;
}
// TODO add functionality for manageall
if (plugin.getConfig().getBoolean("Manage.mob-spawning.enable")) {
String title = lm.getRawString("Commands.Manage.AllowMob-spawning.title");
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.mob-spawning.item")), 1, title, lm.getStringList("Commands.Manage.AllowMob-spawning.description"))).addClickAction((p, icon) -> {
// Open a new gui with spawneggs where you can manage the spawns by clicking on them
List<Icon> icons = new ArrayList<>();
EntityType[] types = EntityType.values();
List<String> lore = lm.getStringList("Commands.Manage.AllowMob-spawning.toggleItem.description");
MultiPagedGUI gui = new MultiPagedGUI(p, 4, title, icons, this) {
};
for (EntityType t : types) {
if (t.isAlive() && t.isSpawnable()) {
if (!toggleMobs.contains(t.name()))
continue;
ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
SpawnEggMeta meta = (SpawnEggMeta) spawnEgg.getItemMeta();
meta.setSpawnedType(t);
meta.setDisplayName(lm.getRawString("Commands.Manage.AllowMob-spawning.toggleItem.title").replace("%mob%", t.name()));
Set<EntityType> flag = land.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
String state;
if (flag != null)
state = (flag.contains(t) ? "DENY" : "ALLOW");
else
state = "ALLOW";
List<String> formattedLore = new ArrayList<>();
for (String s : lore) {
formattedLore.add(s.replace("%mob%", t.name()).replace("%value%", state));
}
meta.setLore(formattedLore);
spawnEgg.setItemMeta(meta);
Icon ic = new Icon(spawnEgg).addClickAction((clickingPlayer, ic3) -> {
for (OwnedLand region : regions) {
Set<EntityType> localFlag = region.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
// Toggle spawning of specific mob
if (localFlag != null) {
if (localFlag.contains(t))
localFlag.remove(t);
else
localFlag.add(t);
} else {
Set<EntityType> set = new HashSet<>();
set.add(t);
region.getWGLand().setFlag(DefaultFlag.DENY_SPAWN, set);
}
}
// update icon text
String iconState;
if (flag != null)
iconState = (flag.contains(t) ? "DENY" : "ALLOW");
else
iconState = "ALLOW";
List<String> newLore = new ArrayList<>();
for (String s : lore) {
newLore.add(s.replace("%mob%", t.name()).replace("%value%", iconState));
}
// System.out.println(newLore + " :" + finalIconPos);
ic3.setLore(newLore);
gui.refresh();
});
icons.add(ic);
}
}
gui.display();
}));
position++;
}
// set farewell icon
if (plugin.getConfig().getBoolean("Manage.setfarewell.enable")) {
String currentFarewell = land.getWGLand().getFlag(DefaultFlag.FAREWELL_MESSAGE);
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setfarewell.item")), 1, lm.getRawString("Commands.Manage.SetFarewell.title"), formatList(farewellDesc, currentFarewell))).addClickAction(((p, icon) -> {
p.closeInventory();
ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetFarewell.clickMsg"));
if (regions.size() > 1)
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewellall "));
else
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewell "));
p.spigot().sendMessage(builder.create());
})));
position++;
}
// set friends icon
if (plugin.getConfig().getBoolean("Manage.friends.enable")) {
ItemStack skull = createSkull(player.getName(), lm.getRawString("Commands.Manage.ManageFriends.title"), lm.getStringList("Commands.Manage.ManageFriends.description"));
Set<UUID> friends = land.getWGLand().getMembers().getUniqueIds();
MultiPagedGUI friendsGui = new MultiPagedGUI(player, (int) Math.ceil((double) friends.size() / 9.0), lm.getRawString("Commands.Manage.ManageFriends.title"), new ArrayList<>(), this) {
};
friends.forEach(id -> friendsGui.addIcon(new Icon(createSkull(Bukkit.getOfflinePlayer(id).getName(), Bukkit.getOfflinePlayer(id).getName(), formatFriendsSegment(id))).addClickAction((player, icon) -> {
ConfirmationGUI confirmationGUI = new ConfirmationGUI(player, lm.getRawString("Commands.Manage.ManageFriends.unfriend").replace("%player%", Bukkit.getOfflinePlayer(id).getName()), (p, ic1) -> {
friendsGui.removeIcon(friendsGui.filter(Bukkit.getOfflinePlayer(id).getName()).get(0));
if (regions.size() > 1)
Bukkit.dispatchCommand(player, "land unfriendall " + Bukkit.getOfflinePlayer(id).getName());
else
Bukkit.dispatchCommand(player, "land unfriend " + Bukkit.getOfflinePlayer(id).getName());
player.closeInventory();
friendsGui.display();
}, (p, ic2) -> {
player.closeInventory();
friendsGui.display();
}, friendsGui);
confirmationGUI.setConfirm(lm.getRawString("Confirmation.accept"));
confirmationGUI.setDecline(lm.getRawString("Confirmation.decline"));
confirmationGUI.display();
})));
this.setIcon(position, new Icon(skull).setName(lm.getRawString("Commands.Manage.ManageFriends.title")).addClickAction((p, ic) -> friendsGui.display()));
position++;
}
if (plugin.getConfig().getBoolean("Manage.unclaim.enable")) {
this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.unclaim.item")), 1, lm.getRawString("Commands.Manage.Unclaim.title"), lm.getStringList("Commands.Manage.Unclaim.description"))).addClickAction(((player1, icon) -> {
ConfirmationGUI gui = new ConfirmationGUI(player1, lm.getRawString("Commands.Manage.Unclaim.confirmationTitle").replace("%land%", land.getName()), (p, ic2) -> {
if (regions.size() > 1)
Bukkit.dispatchCommand(p, "ll unclaimall");
else
Bukkit.dispatchCommand(p, "ll unclaim " + land.getName());
p.closeInventory();
}, (p, ic) -> {
p.closeInventory();
display();
}, this);
gui.setConfirm(lm.getRawString("Confirmation.accept"));
gui.setDecline(lm.getRawString("Confirmation.decline"));
gui.display();
})));
position++;
}
}
Aggregations