mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-23 02:35:28 +01:00
Added the ability to change the currency symbol.
Corrected the sound default config value. Added a chance option for all kit items. Kit storage system redone. Kit animations added. Cleaned up code. Fixed issues with "Any" kit keys
This commit is contained in:
parent
cf35947043
commit
49d2c70ece
@ -133,7 +133,9 @@ public enum Lang {
|
||||
LAST("Last", "&7Last Page"),
|
||||
ECO_SENT("Eco_Sent", "&7You received &a{AMT}&7."),
|
||||
|
||||
INVENTORY_FULL("Inventory-full", "&cYour inventory is too full to claim this kit!");
|
||||
INVENTORY_FULL("Inventory-full", "&cYour inventory is too full to claim this kit!"),
|
||||
|
||||
CRATE_WON("Crate-won", "&7You got a &6{ITEM}&7.");
|
||||
|
||||
|
||||
private static FileConfiguration LANG;
|
||||
@ -166,6 +168,7 @@ public enum Lang {
|
||||
value = value.replace("{AMT}", ob.toString());
|
||||
value = value.replace("{COST}", ob.toString());
|
||||
value = value.replace("{PRICE}", ob.toString());
|
||||
value = value.replace("{ITEM}", ob.toString());
|
||||
value = value.replace("{TIME}", ob.toString());
|
||||
}
|
||||
return value;
|
||||
|
@ -10,12 +10,9 @@ import com.songoda.ultimatekits.handlers.HologramHandler;
|
||||
import com.songoda.ultimatekits.handlers.ParticleHandler;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.key.KeyManager;
|
||||
import com.songoda.ultimatekits.kit.BlockEditor;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitManager;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.editor.BlockEditor;
|
||||
import com.songoda.ultimatekits.editor.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.*;
|
||||
import com.songoda.ultimatekits.player.PlayerData;
|
||||
import com.songoda.ultimatekits.player.PlayerDataManager;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
@ -160,9 +157,16 @@ public class UltimateKits extends JavaPlugin {
|
||||
Material material = kitFile.getConfig().contains("Kits." + kitName + ".displayItem") ? Material.valueOf(kitFile.getConfig().getString("Kits." + kitName + ".displayItem")) : null;
|
||||
boolean hidden = kitFile.getConfig().getBoolean("Kits." + kitName + ".hidden");
|
||||
double price = kitFile.getConfig().getDouble("Kits." + kitName + ".price");
|
||||
List<String> contents = kitFile.getConfig().getStringList("Kits." + kitName + ".items");
|
||||
List<String> strContents = kitFile.getConfig().getStringList("Kits." + kitName + ".items");
|
||||
String kitAnimation = kitFile.getConfig().getString("Kits." + kitName + ".animation", KitAnimation.NONE.name());
|
||||
|
||||
Kit kit = new Kit(kitName, title, link, price, material, delay, hidden, contents);
|
||||
List<KitItem> contents = new ArrayList<>();
|
||||
|
||||
for (String string : strContents) {
|
||||
contents.add(new KitItem(string));
|
||||
}
|
||||
|
||||
Kit kit = new Kit(kitName, title, link, price, material, delay, hidden, contents, KitAnimation.valueOf(kitAnimation));
|
||||
kitManager.addKit(kit);
|
||||
} catch (Exception ex) {
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&cYour kit &4" + kitName + " &cis setup incorrectly."));
|
||||
@ -225,9 +229,16 @@ public class UltimateKits extends JavaPlugin {
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".link", kit.getLink());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".price", kit.getPrice());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".hidden", kit.isHidden());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".animation", kit.getKitAnimation().name());
|
||||
if (kit.getDisplayItem() != null)
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".displayItem", kit.getDisplayItem().toString());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".items", kit.getContents());
|
||||
|
||||
List<KitItem> contents = kit.getContents();
|
||||
List<String> strContents = new ArrayList<>();
|
||||
|
||||
for (KitItem item : contents) strContents.add(item.getSerialized());
|
||||
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".items", strContents);
|
||||
}
|
||||
|
||||
// Wipe old block information.
|
||||
|
@ -4,8 +4,7 @@ import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -28,7 +27,7 @@ public class CommandCreatekit extends AbstractCommand {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText("&aThat kit doesn't exist. Creating it now."));
|
||||
Kit kit = new Kit(kitStr.trim());
|
||||
UltimateKits.getInstance().getKitManager().addKit(kit);
|
||||
instance.getKitEditor().openOverview(kit, p, false, null);
|
||||
instance.getKitEditor().openOverview(kit, p, false, null, 0);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class CommandEdit extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
instance.getKitEditor().openOverview(instance.getKitManager().getKit(kitStr), player, false, null);
|
||||
instance.getKitEditor().openOverview(instance.getKitManager().getKit(kitStr), player, false, null, 0);
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -53,12 +53,12 @@ public class CommandKey extends AbstractCommand {
|
||||
if (!args[3].trim().equals("all")) {
|
||||
Player p = Bukkit.getPlayer(args[3]);
|
||||
p.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue(kit.getShowableName()));
|
||||
p.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue((kit == null ? "Any" : kit.getShowableName())));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
for (Player pl : instance.getServer().getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
pl.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue(kit.getShowableName()));
|
||||
pl.sendMessage(instance.references.getPrefix() + Lang.KEY_GIVEN.getConfigValue((kit == null ? "Any" : kit.getShowableName())));
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.KitsGUI;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
public class CommandKits extends AbstractCommand {
|
||||
|
||||
public CommandKits() {
|
||||
super("Kits", null, false, false);
|
||||
super("Kits", null, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,7 @@ package com.songoda.ultimatekits.command.commands;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -4,7 +4,7 @@ import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
package com.songoda.ultimatekits.editor;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.editor;
|
||||
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
package com.songoda.ultimatekits.editor;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitAnimation;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -30,7 +32,7 @@ public class KitEditor {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void openOverview(Kit kit, Player player, boolean backb, ItemStack command) {
|
||||
public void openOverview(Kit kit, Player player, boolean backb, ItemStack command, int slot) {
|
||||
try {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
@ -47,7 +49,7 @@ public class KitEditor {
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
ItemStack head2 = new ItemStack(Material.PLAYER_HEAD, 1, (byte) 3);
|
||||
ItemStack back = head2;
|
||||
ItemStack back;
|
||||
back = Arconix.pl().getApi().getGUI().addTexture(head2, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
@ -60,7 +62,7 @@ public class KitEditor {
|
||||
itmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&5&l" + playerData.getKit().getName()));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&fPermissions:"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7essentials.kit." + playerData.getKit().getName().toLowerCase()));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7ultimatekits.kit." + playerData.getKit().getName().toLowerCase()));
|
||||
itmeta.setLore(lore);
|
||||
it.setItemMeta(itmeta);
|
||||
|
||||
@ -75,9 +77,16 @@ public class KitEditor {
|
||||
i.setItem(8, exit);
|
||||
|
||||
int num = 10;
|
||||
List<ItemStack> list = kit.getReadableContents(player, true);
|
||||
for (ItemStack is : list) {
|
||||
/*
|
||||
List<ItemStack> list = kit.getReadableContents(player, true, true);
|
||||
for (ItemStack iss : list) {
|
||||
if (num == 17 || num == 36)
|
||||
num++;
|
||||
|
||||
KitItem item = new KitItem(iss);
|
||||
|
||||
if (slot != 0 && slot == num) item.setChance(item.getChance() == 100 ? 5 : (item.getChance() + 5));
|
||||
ItemStack is = item.getMoveableItem();
|
||||
|
||||
ItemMeta meta;
|
||||
|
||||
if (is.hasItemMeta()) meta = is.getItemMeta();
|
||||
@ -87,19 +96,20 @@ public class KitEditor {
|
||||
|
||||
if (meta.hasLore()) itemLore = meta.getLore();
|
||||
else itemLore = new ArrayList<>();
|
||||
|
||||
itemLore.add(TextComponent.convertToInvisibleString("----"));
|
||||
itemLore.add(TextComponent.formatText("&7Chance: &6" + item.getChance() + "%"));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&7Left-Click: &6To set a display item."));
|
||||
itemLore.add(TextComponent.formatText("&7Middle-Click: &6To set a display name."));
|
||||
itemLore.add(TextComponent.formatText("&7Right-Click: &6To set display lore."));
|
||||
itemLore.add(TextComponent.formatText("&7Shift-Click: &6To set crate percentage."));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&6Leave function mode to move items."));
|
||||
if (playerData.isInFuction()) {
|
||||
itemLore.add(TextComponent.formatText("&7Left-Click: &6To set a display item."));
|
||||
itemLore.add(TextComponent.formatText("&7Middle-Click: &6To set a display name."));
|
||||
itemLore.add(TextComponent.formatText("&7Right-Click: &6To set display lore."));
|
||||
itemLore.add(TextComponent.formatText("&7Shift-Click: &6To set chance."));
|
||||
itemLore.add("");
|
||||
itemLore.add(TextComponent.formatText("&6Leave function mode to move items."));
|
||||
}
|
||||
meta.setLore(itemLore);
|
||||
is.setItemMeta(meta);
|
||||
*/
|
||||
if (num == 17 || num == 36)
|
||||
num++;
|
||||
|
||||
if (is.getAmount() > 64) {
|
||||
int overflow = is.getAmount() % 64;
|
||||
int stackamt = (int) ((long) (is.getAmount() / 64));
|
||||
@ -162,23 +172,41 @@ public class KitEditor {
|
||||
}
|
||||
|
||||
public void updateInvButton(Inventory i, KitEditorPlayerData playerData) {
|
||||
ItemStack alli = new ItemStack(Material.ITEM_FRAME, 1);
|
||||
ItemStack alli = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta allmeta = alli.getItemMeta();
|
||||
if (!playerData.isInFuction()) {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Item Editing"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to enable"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7item editing."));
|
||||
allmeta.setLore(lore);
|
||||
} else {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Item Moving"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to switch back"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to item moving."));
|
||||
allmeta.setLore(lore);
|
||||
}
|
||||
alli.setItemMeta(allmeta);
|
||||
i.setItem(48, alli);
|
||||
|
||||
alli = new ItemStack(Material.ITEM_FRAME, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
if (!playerData.isInInventory()) {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Your Inventory"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking to switch to"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to switch to"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7your inventory."));
|
||||
allmeta.setLore(lore);
|
||||
} else {
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Switch To Kit Functions"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking to switch back"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Click to switch back"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7to the kit functions."));
|
||||
allmeta.setLore(lore);
|
||||
}
|
||||
alli.setItemMeta(allmeta);
|
||||
i.setItem(49, alli);
|
||||
i.setItem(50, alli);
|
||||
}
|
||||
|
||||
public void getInvItems(Player player, KitEditorPlayerData playerData) {
|
||||
@ -241,6 +269,16 @@ public class KitEditor {
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(14, alli);
|
||||
|
||||
alli = new ItemStack(Material.CHEST, 1);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&6Kit Animation"));
|
||||
lore = new ArrayList<>();
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &6" + playerData.getKit().getKitAnimation().name()));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
player.getInventory().setItem(17, alli);
|
||||
}
|
||||
|
||||
public void selling(Player player) {
|
||||
@ -322,6 +360,25 @@ public class KitEditor {
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&a&lSet kit link"));
|
||||
lore = new ArrayList<>();
|
||||
if (kit.getLink() != null)
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &a" + kit.getLink() + "&7."));
|
||||
else
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Currently: &cNot set&7."));
|
||||
lore.add(Arconix.pl().getApi().format().formatText(""));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7Clicking this option will"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7allow you to set a link"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7that players will receive"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7when attempting to purchase"));
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&7this kit."));
|
||||
allmeta.setLore(lore);
|
||||
alli.setItemMeta(allmeta);
|
||||
|
||||
i.setItem(13, alli);
|
||||
|
||||
alli = new ItemStack(Material.DIAMOND_HELMET);
|
||||
allmeta = alli.getItemMeta();
|
||||
allmeta.setDisplayName(Arconix.pl().getApi().format().formatText("&a&lSet kit price"));
|
||||
@ -602,6 +659,20 @@ public class KitEditor {
|
||||
}
|
||||
}
|
||||
|
||||
public void changeAnimation(Player player) {
|
||||
KitEditorPlayerData playerData = getDataFor(player);
|
||||
|
||||
Kit kit = playerData.getKit();
|
||||
if (kit.getKitAnimation() == KitAnimation.NONE) {
|
||||
kit.setKitAnimation(KitAnimation.CSGO);
|
||||
} else {
|
||||
kit.setKitAnimation(KitAnimation.NONE);
|
||||
}
|
||||
|
||||
getInvItems(player, playerData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void createMoney(Player player) {
|
||||
try {
|
||||
@ -643,7 +714,10 @@ public class KitEditor {
|
||||
items = Arrays.copyOf(items, items.length - 10);
|
||||
|
||||
kit.saveKit(Arrays.asList(items));
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Changes to &a" + kit.getShowableName() + " &8saved successfully."));
|
||||
if (!playerData.isMuteSave())
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Changes to &a" + kit.getShowableName() + " &8saved successfully."));
|
||||
|
||||
playerData.setMuteSave(false);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.editor;
|
||||
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -10,6 +11,8 @@ public class KitEditorPlayerData {
|
||||
private EditorType editorType = EditorType.NOTIN;
|
||||
private ItemStack[] inventory = new ItemStack[0];
|
||||
private boolean showInventory = false;
|
||||
private boolean showFuctions = false;
|
||||
private boolean muteSave = false;
|
||||
|
||||
public Kit getKit() {
|
||||
return kit;
|
||||
@ -27,9 +30,24 @@ public class KitEditorPlayerData {
|
||||
this.editorType = editorType;
|
||||
}
|
||||
|
||||
public boolean isMuteSave() {
|
||||
return muteSave;
|
||||
}
|
||||
|
||||
public void setMuteSave(boolean muteSave) {
|
||||
this.muteSave = muteSave;
|
||||
}
|
||||
|
||||
public boolean isInInventory() {
|
||||
return showInventory;
|
||||
}
|
||||
public boolean isInFuction() {
|
||||
return showFuctions;
|
||||
}
|
||||
|
||||
public void setInFunction(boolean showFuctions) {
|
||||
this.showFuctions = showFuctions;
|
||||
}
|
||||
|
||||
public void setInInventory(boolean showInventory) {
|
||||
this.showInventory = showInventory;
|
@ -2,8 +2,8 @@ package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -3,9 +3,9 @@ package com.songoda.ultimatekits.events;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.editor.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.editor.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -106,7 +106,7 @@ public class ChatListeners implements Listener {
|
||||
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Command &5" + msg + "&8 has been added to your kit."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.openOverview(kit, player, false, parseStack);
|
||||
edit.openOverview(kit, player, false, parseStack, 0);
|
||||
break;
|
||||
case MONEY:
|
||||
ItemStack parseStack2 = new ItemStack(Material.PAPER, 1);
|
||||
@ -125,7 +125,7 @@ public class ChatListeners implements Listener {
|
||||
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Money &5$" + msg + "&8 has been added to your kit."));
|
||||
playerData.setEditorType(KitEditorPlayerData.EditorType.NOTIN);
|
||||
edit.openOverview(kit, player, false, parseStack2);
|
||||
edit.openOverview(kit, player, false, parseStack2, 0);
|
||||
break;
|
||||
default:
|
||||
e.setCancelled(false);
|
||||
|
@ -3,9 +3,9 @@ package com.songoda.ultimatekits.events;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -3,12 +3,12 @@ package com.songoda.ultimatekits.events;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.BlockEditor;
|
||||
import com.songoda.ultimatekits.kit.KitEditor;
|
||||
import com.songoda.ultimatekits.editor.BlockEditor;
|
||||
import com.songoda.ultimatekits.editor.KitEditor;
|
||||
import com.songoda.ultimatekits.kit.KitsGUI;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.editor.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.editor.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.player.PlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -32,8 +32,10 @@ public class InventoryListeners implements Listener {
|
||||
try {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
PlayerData playerData = instance.getPlayerDataManager().getPlayerAction(player);
|
||||
|
||||
if (playerData.getGuiLocation() == PlayerData.GUILocation.BUY_FINAL) {
|
||||
|
||||
if (playerData.isInCrate()) {
|
||||
event.setCancelled(true);
|
||||
} else if (playerData.getGuiLocation() == PlayerData.GUILocation.BUY_FINAL) {
|
||||
if (event.getSlot() == 11) {
|
||||
Kit kit = playerData.getInKit();
|
||||
kit.buyWithEconomy(player);
|
||||
@ -64,7 +66,6 @@ public class InventoryListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(clicked.getItemMeta().getDisplayName());
|
||||
String kitName = clicked.getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":")[0];
|
||||
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
@ -144,7 +145,7 @@ public class InventoryListeners implements Listener {
|
||||
edit.decor(player);
|
||||
break;
|
||||
case 15:
|
||||
instance.getKitEditor().openOverview(instance.getBlockEditor().getDataFor(player).getKit(), player, true, null);
|
||||
instance.getKitEditor().openOverview(instance.getBlockEditor().getDataFor(player).getKit(), player, true, null, 0);
|
||||
break;
|
||||
}
|
||||
} else if (instance.getBlockEditor().getDataFor(player).getEditorType() == BlockEditorPlayerData.EditorType.DECOR) {
|
||||
@ -178,6 +179,19 @@ public class InventoryListeners implements Listener {
|
||||
KitEditor edit = instance.getKitEditor();
|
||||
if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.OVERVIEW) {
|
||||
KitEditorPlayerData editorData = edit.getDataFor(player);
|
||||
if ((event.getSlot() > 9 && event.getSlot() < 44) && event.getSlot() != 17 && event.getSlot() != 36) {
|
||||
if (event.getCurrentItem().getType() != Material.AIR) {
|
||||
if (editorData.isInFuction()) {
|
||||
if (event.isShiftClick()) {
|
||||
editorData.setMuteSave(true);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, event.getSlot());
|
||||
editorData.setMuteSave(true);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, event.getSlot());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((event.getSlot() < 10 || event.getSlot() > 43) || event.getSlot() == 17 || event.getSlot() == 36) {
|
||||
if (event.getInventory() != null && event.getInventory().getType() == InventoryType.CHEST) {
|
||||
event.setCancelled(true);
|
||||
@ -203,11 +217,14 @@ public class InventoryListeners implements Listener {
|
||||
case 14:
|
||||
edit.createMoney(player);
|
||||
break;
|
||||
case 17:
|
||||
edit.changeAnimation(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getSlot() == 49) {
|
||||
if (event.getSlot() == 50) {
|
||||
if (!editorData.isInInventory()) {
|
||||
player.getInventory().setContents(editorData.getInventory());
|
||||
editorData.setInInventory(true);
|
||||
@ -215,6 +232,11 @@ public class InventoryListeners implements Listener {
|
||||
} else edit.getInvItems(player, editorData);
|
||||
edit.updateInvButton(event.getInventory(), editorData);
|
||||
}
|
||||
if (event.getSlot() == 48) {
|
||||
editorData.setInFunction(!editorData.isInFuction());
|
||||
editorData.setMuteSave(true);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, 0);
|
||||
}
|
||||
} else if (instance.getKitEditor().getDataFor(player).getEditorType() == KitEditorPlayerData.EditorType.SELLING) {
|
||||
event.setCancelled(true);
|
||||
switch (event.getSlot()) {
|
||||
@ -270,7 +292,7 @@ public class InventoryListeners implements Listener {
|
||||
if (event.getInventory().getTitle().contains("You are editing kit")) {
|
||||
instance.getBlockEditor().openOverview(player, instance.getBlockEditor().getDataFor(player).getLocation());
|
||||
} else {
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null);
|
||||
edit.openOverview(edit.getDataFor(player).getKit(), player, false, null, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.ultimatekits.events;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.kit.object.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.editor.BlockEditorPlayerData;
|
||||
import com.songoda.ultimatekits.editor.KitEditorPlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -45,7 +45,7 @@ public class DisplayItemHandler {
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
List<ItemStack> list = kit.getReadableContents(null, false);
|
||||
List<ItemStack> list = kit.getReadableContents(null, false, false);
|
||||
for (Entity e : location.getChunk().getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM
|
||||
|| e.getLocation().getX() != location.getX()
|
||||
|
@ -3,9 +3,9 @@ package com.songoda.ultimatekits.handlers;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.object.KitType;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
@ -2,7 +2,7 @@ package com.songoda.ultimatekits.key;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
@ -1,12 +1,18 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentItem;
|
||||
import com.songoda.ultimatekits.player.PlayerData;
|
||||
import com.songoda.ultimatekits.tasks.CrateAnimateTask;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -21,11 +27,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
@ -43,13 +45,16 @@ public class Kit {
|
||||
|
||||
private Material displayItem;
|
||||
|
||||
private List<String> contents;
|
||||
private List<KitItem> contents;
|
||||
|
||||
public Kit(String name, String title, String link, double price, Material displayItem, int delay, boolean hidden, List<String> contents) {
|
||||
private KitAnimation kitAnimation;
|
||||
|
||||
public Kit(String name, String title, String link, double price, Material displayItem, int delay, boolean hidden, List<KitItem> contents, KitAnimation kitAnimation) {
|
||||
this.name = name;
|
||||
this.showableName = Arconix.pl().getApi().format().formatText(name, true);
|
||||
this.price = price;
|
||||
this.link = link;
|
||||
this.kitAnimation = kitAnimation;
|
||||
this.title = title;
|
||||
this.delay = delay;
|
||||
this.hidden = hidden;
|
||||
@ -58,7 +63,7 @@ public class Kit {
|
||||
}
|
||||
|
||||
public Kit(String name) {
|
||||
this(name, null, null, 0, null, 0, false, new ArrayList<>());
|
||||
this(name, null, null, 0, null, 0, false, new ArrayList<>(), KitAnimation.NONE);
|
||||
}
|
||||
|
||||
public void buy(Player p) {
|
||||
@ -90,9 +95,9 @@ public class Kit {
|
||||
|
||||
private List<ItemStack> getItemContents() {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
for (String str : this.getContents()) {
|
||||
if ((!str.startsWith("/") && !str.startsWith("$")))
|
||||
items.add(Methods.deserializeItemStack(str));
|
||||
for (KitItem item : this.getContents()) {
|
||||
if (item.getContent() instanceof KitContentItem)
|
||||
items.add(((KitContentItem) item.getContent()).getItemStack());
|
||||
}
|
||||
return items;
|
||||
}
|
||||
@ -118,51 +123,53 @@ public class Kit {
|
||||
return space >= spaceNeeded;
|
||||
}
|
||||
|
||||
public void give(Player p, boolean useKey, boolean economy, boolean console) {
|
||||
public void give(Player player, boolean useKey, boolean economy, boolean console) {
|
||||
try {
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Prevent The Redeeming of a Kit When Inventory Is Full") && !hasRoom(p, useKey)) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.INVENTORY_FULL.getConfigValue()));
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Prevent The Redeeming of a Kit When Inventory Is Full") && !hasRoom(player, useKey)) {
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.INVENTORY_FULL.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Sounds Enabled") && kitAnimation == KitAnimation.NONE) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
}
|
||||
if (useKey) {
|
||||
if (p.getItemInHand().getType() != Material.TRIPWIRE_HOOK || !p.getItemInHand().hasItemMeta()) {
|
||||
if (player.getItemInHand().getType() != Material.TRIPWIRE_HOOK || !player.getItemInHand().hasItemMeta()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Key key = UltimateKits.getInstance().getKeyManager().getKey(ChatColor.stripColor(p.getItemInHand().getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
Key key = UltimateKits.getInstance().getKeyManager().getKey(ChatColor.stripColor(player.getItemInHand().getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
|
||||
if (!p.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue(showableName)) && !p.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue("All"))) {
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(UltimateKits.getInstance().references.getPrefix() + Lang.WRONG_KEY.getConfigValue()));
|
||||
if (!player.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue(showableName)) && !player.getItemInHand().getItemMeta().getDisplayName().equals(Lang.KEY_TITLE.getConfigValue("Any"))) {
|
||||
player.sendMessage(Arconix.pl().getApi().format().formatText(UltimateKits.getInstance().references.getPrefix() + Lang.WRONG_KEY.getConfigValue()));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < key.getKitAmount(); i++)
|
||||
givePartKit(p, key);
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.KEY_SUCCESS.getConfigValue(showableName)));
|
||||
if (p.getInventory().getItemInHand().getAmount() != 1) {
|
||||
ItemStack is = p.getItemInHand();
|
||||
givePartKit(player, key);
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.KEY_SUCCESS.getConfigValue(showableName)));
|
||||
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
||||
ItemStack is = player.getItemInHand();
|
||||
is.setAmount(is.getAmount() - 1);
|
||||
p.setItemInHand(is);
|
||||
player.setItemInHand(is);
|
||||
} else {
|
||||
p.setItemInHand(null);
|
||||
player.setItemInHand(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (getNextUse(p) == -1 && !economy && !console) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.NOT_TWICE.getConfigValue(showableName)));
|
||||
} else if (getNextUse(p) <= 0 || economy || console) {
|
||||
giveKit(p);
|
||||
if (getNextUse(player) == -1 && !economy && !console) {
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.NOT_TWICE.getConfigValue(showableName)));
|
||||
} else if (getNextUse(player) <= 0 || economy || console) {
|
||||
giveKit(player);
|
||||
if (economy) {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.PURCHASE_SUCCESS.getConfigValue(showableName)));
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.PURCHASE_SUCCESS.getConfigValue(showableName)));
|
||||
} else {
|
||||
updateDelay(p);
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.GIVE_SUCCESS.getConfigValue(showableName)));
|
||||
updateDelay(player);
|
||||
if (kitAnimation == KitAnimation.NONE) {
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.GIVE_SUCCESS.getConfigValue(showableName)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.DELAY.getConfigValue(Arconix.pl().getApi().format().readableTime(getNextUse(p)))));
|
||||
player.sendMessage(UltimateKits.getInstance().references.getPrefix() + Arconix.pl().getApi().format().formatText(Lang.DELAY.getConfigValue(Arconix.pl().getApi().format().readableTime(getNextUse(player)))));
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
@ -195,7 +202,7 @@ public class Kit {
|
||||
|
||||
guititle = Arconix.pl().getApi().format().formatText(guititle);
|
||||
|
||||
List<ItemStack> list = getReadableContents(p, true);
|
||||
List<ItemStack> list = getReadableContents(p, true, false);
|
||||
|
||||
int amt = 0;
|
||||
for (ItemStack is : list) {
|
||||
@ -368,21 +375,32 @@ public class Kit {
|
||||
|
||||
public void saveKit(List<ItemStack> items) {
|
||||
try {
|
||||
List<String> list = new ArrayList<>();
|
||||
List<KitItem> list = new ArrayList<>();
|
||||
for (ItemStack is : items) {
|
||||
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
|
||||
if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).equals("Command")) {
|
||||
|
||||
if (is.getItemMeta().hasLore()) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.equals(TextComponent.convertToInvisibleString("----"))) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
|
||||
if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).endsWith("Command")) {
|
||||
StringBuilder command = new StringBuilder();
|
||||
for (String line : is.getItemMeta().getLore()) {
|
||||
command.append(line);
|
||||
}
|
||||
list.add(ChatColor.stripColor(command.toString()));
|
||||
} else if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).equals("Money")) {
|
||||
list.add(new KitItem(ChatColor.stripColor(command.toString())));
|
||||
} else if (is.getType() == Material.PAPER && ChatColor.stripColor(is.getItemMeta().getDisplayName()).endsWith("Money")) {
|
||||
String money = is.getItemMeta().getLore().get(0);
|
||||
list.add(ChatColor.stripColor(money));
|
||||
list.add(new KitItem(ChatColor.stripColor(money)));
|
||||
} else {
|
||||
String serialized = Methods.serializeItemStack(is);
|
||||
list.add(serialized);
|
||||
list.add(new KitItem(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,43 +411,19 @@ public class Kit {
|
||||
}
|
||||
|
||||
|
||||
public List<ItemStack> getReadableContents(Player player, boolean commands) {
|
||||
public List<ItemStack> getReadableContents(Player player, boolean commands, boolean moveable) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
try {
|
||||
for (String str : getContents()) {
|
||||
if ((!str.startsWith("/") && !str.startsWith("$")) || commands) {
|
||||
ItemStack parseStack;
|
||||
if (str.startsWith("$")) {
|
||||
parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("§a" + str.trim());
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.MONEY.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
} else if (str.startsWith("/")) {
|
||||
parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
for (KitItem item : getContents()) {
|
||||
if ((!item.getSerialized().startsWith("/") && !item.getSerialized().startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) || commands) { //ToDO: I doubt this is correct.
|
||||
ItemStack stack = moveable ? item.getMoveableItem() : item.getItem();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < str.length()) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText("&a" + str.substring(index, Math.min(index + 30, str.length()))));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.COMMAND.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
} else {
|
||||
parseStack = Methods.deserializeItemStack(str);
|
||||
}
|
||||
ItemStack fin = parseStack;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && parseStack.getItemMeta().getLore() != null) {
|
||||
ItemStack fin = stack;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && stack.getItemMeta().getLore() != null) {
|
||||
ArrayList<String> lore2 = new ArrayList<>();
|
||||
ItemMeta meta2 = parseStack.getItemMeta();
|
||||
for (String lor : parseStack.getItemMeta().getLore()) {
|
||||
lor = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, lor.replace(" ", "_")).replace("_", " ");
|
||||
ItemMeta meta2 = stack.getItemMeta();
|
||||
for (String lor : stack.getItemMeta().getLore()) {
|
||||
lor = PlaceholderAPI.setPlaceholders(player, lor.replace(" ", "_")).replace("_", " ");
|
||||
lore2.add(lor);
|
||||
}
|
||||
meta2.setLore(lore2);
|
||||
@ -454,45 +448,59 @@ public class Kit {
|
||||
|
||||
public void givePartKit(Player player, Key key) {
|
||||
try {
|
||||
|
||||
List<String> innerContents = new ArrayList<>(getContents());
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
Collections.shuffle(innerContents);
|
||||
int amt = innerContents.size();
|
||||
int amtToGive = key == null ? amt : key.getAmt();
|
||||
|
||||
if (key != null && key.getAmt() != -1 && key.getAmt() < innerContents.size()) {
|
||||
amt = innerContents.size() - key.getAmt();
|
||||
}
|
||||
|
||||
while (key != null && amt != 0 && key.getAmt() != -1) {
|
||||
int num = ThreadLocalRandom.current().nextInt(0, innerContents.size());
|
||||
innerContents.remove(num);
|
||||
amt--;
|
||||
}
|
||||
for (String line : innerContents) {
|
||||
if (line.startsWith("$")) {
|
||||
try {
|
||||
Methods.pay(player, Double.parseDouble(line.substring("$".length()).trim()));
|
||||
player.sendMessage(Lang.ECO_SENT.getConfigValue(Arconix.pl().getApi().format().formatEconomy(Double.parseDouble(line.substring("$".length()).trim()))));
|
||||
} catch (NumberFormatException ex) {
|
||||
Debugger.runReport(ex);
|
||||
int num = 0;
|
||||
for (KitItem item : innerContents) {
|
||||
if (amtToGive == 0) continue;
|
||||
int ch = item.getChance() == 0 ? 100 : item.getChance();
|
||||
double rand = Math.random() * 100;
|
||||
if (rand - ch < 0 || ch == 100) {
|
||||
if (item.getContent() instanceof KitContentEconomy) {
|
||||
try {
|
||||
Methods.pay(player, ((KitContentEconomy) item.getContent()).getAmount());
|
||||
player.sendMessage(Lang.ECO_SENT.getConfigValue(Arconix.pl().getApi().format().formatEconomy(((KitContentEconomy) item.getContent()).getAmount())));
|
||||
} catch (NumberFormatException ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
amtToGive --;
|
||||
continue;
|
||||
} else if (item.getContent() instanceof KitContentCommand) {
|
||||
String parsed = ((KitContentCommand) item.getContent()).getCommand();
|
||||
parsed = parsed.replace("{player}", player.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
|
||||
amtToGive --;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
} else if (line.startsWith("/")) {
|
||||
String parsed = line.substring(1);
|
||||
parsed = parsed.replace("{player}", player.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed); // Not proud of this.
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack parseStack = Methods.deserializeItemStack(line);
|
||||
if (parseStack.getType() == Material.AIR) continue;
|
||||
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(parseStack);
|
||||
|
||||
|
||||
for (ItemStack item : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
||||
|
||||
ItemStack parseStack = ((KitContentItem)item.getContent()).getItemStack();
|
||||
if (parseStack.getType() == Material.AIR) continue;
|
||||
|
||||
|
||||
amtToGive --;
|
||||
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(),
|
||||
() -> new CrateAnimateTask(UltimateKits.getInstance(), player, this, item.getItem()), 210 * num);
|
||||
} else {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item2);
|
||||
}
|
||||
}
|
||||
num ++;
|
||||
}
|
||||
}
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(),
|
||||
() -> {
|
||||
UltimateKits.getInstance().getPlayerDataManager().getPlayerAction(player).setInCrate(false);
|
||||
player.closeInventory();
|
||||
}, (210 * num) + 20);
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
} catch (Exception e) {
|
||||
@ -660,11 +668,11 @@ public class Kit {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public List<String> getContents() {
|
||||
public List<KitItem> getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
public void setContents(List<String> contents) {
|
||||
public void setContents(List<KitItem> contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@ -692,6 +700,14 @@ public class Kit {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public KitAnimation getKitAnimation() {
|
||||
return kitAnimation;
|
||||
}
|
||||
|
||||
public void setKitAnimation(KitAnimation kitAnimation) {
|
||||
this.kitAnimation = kitAnimation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (name != null ? name.hashCode() : 0);
|
@ -0,0 +1,5 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
public enum KitAnimation {
|
||||
NONE, CSGO
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Location;
|
95
src/main/java/com/songoda/ultimatekits/kit/KitItem.java
Normal file
95
src/main/java/com/songoda/ultimatekits/kit/KitItem.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.math.AMath;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.type.KitContent;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentItem;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class KitItem {
|
||||
|
||||
private final KitContent content;
|
||||
private int chance = 0;
|
||||
|
||||
public KitItem(String item) {
|
||||
String item2 = item.replace(String.valueOf(ChatColor.COLOR_CHAR), "");
|
||||
if (item2.substring(0, Math.min(item2.length(), 5)).contains(":")) {
|
||||
this.chance = Integer.parseInt(item2.split(":", 2)[0]);
|
||||
item = item.split(":", 2)[1].trim();
|
||||
}
|
||||
if (item.startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) {
|
||||
this.content = new KitContentEconomy(Double.parseDouble(item.substring(1).trim()));
|
||||
} else if (item.startsWith("/")) {
|
||||
this.content = new KitContentCommand(item.substring(1));
|
||||
} else {
|
||||
this.content = new KitContentItem(Methods.deserializeItemStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
public KitItem(ItemStack item) {
|
||||
ItemStack itemStack = item.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta.getDisplayName().contains(":")) {
|
||||
String[] split = meta.getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":", 2);
|
||||
if (AMath.isInt(split[0])) {
|
||||
this.chance = Integer.parseInt(split[0]);
|
||||
meta.setDisplayName(split[1].contains("aqf") ? null : meta.getDisplayName().split(":", 2)[1]);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
String name = meta.hasDisplayName() ? meta.getDisplayName() : "";
|
||||
|
||||
if (name.startsWith(UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol"))) {
|
||||
this.content = new KitContentEconomy(Double.parseDouble(name.substring(1).trim()));
|
||||
} else if (name.startsWith("/")) {
|
||||
this.content = new KitContentCommand(name.substring(1));
|
||||
} else {
|
||||
this.content = new KitContentItem(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
public KitContent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getSerialized() {
|
||||
if (chance == 0) return this.content.getSerialized();
|
||||
return chance + ":" + this.content.getSerialized();
|
||||
}
|
||||
|
||||
public int getChance() {
|
||||
return chance == 0 ? 100 : chance;
|
||||
}
|
||||
|
||||
public void setChance(int chance) {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return content.getItemForDisplay();
|
||||
}
|
||||
|
||||
public ItemStack getMoveableItem() {
|
||||
ItemStack item = content.getItemForDisplay();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (chance != 0) meta.setDisplayName(meta.hasDisplayName() ? TextComponent.convertToInvisibleString(chance + ":") + meta.getDisplayName() : TextComponent.convertToInvisibleString(chance + ":aqf") + item.getType().name().replace("_", " "));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KitItem:{"
|
||||
+ "Item:\"" + content.getSerialized() + "\","
|
||||
+ "Chance:" + chance
|
||||
+ "}";
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
@ -1,3 +1,3 @@
|
||||
package com.songoda.ultimatekits.kit.object;
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
public enum KitType {PREVIEW, CRATE, CLAIM}
|
@ -4,7 +4,6 @@ import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.player.PlayerData;
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface KitContent {
|
||||
|
||||
String getSerialized();
|
||||
|
||||
ItemStack getItemForDisplay();
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KitContentCommand implements KitContent {
|
||||
|
||||
private String command; // Stored like "eco give <player> 100"
|
||||
|
||||
public KitContentCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
return "/" + command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemForDisplay() {
|
||||
ItemStack stack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (index < command.length()) {
|
||||
lore.add(TextComponent.formatText("&a" + (index == 0 ? "/" : "") + "&a" + command.substring(index, Math.min(index + 30, command.length()))));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.COMMAND.getConfigValue());
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KitContentEconomy implements KitContent {
|
||||
|
||||
private double amount;
|
||||
|
||||
public KitContentEconomy(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
return UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") + amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemForDisplay() {
|
||||
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < String.valueOf(amount).length()) {
|
||||
lore.add(TextComponent.formatText("&a" + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + "&a" + String.valueOf(amount).substring(index, Math.min(index + 30, String.valueOf(amount).length()))));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(Lang.MONEY.getConfigValue());
|
||||
parseStack.setItemMeta(meta);
|
||||
return parseStack;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class KitContentItem implements KitContent {
|
||||
|
||||
private ItemStack itemStack;
|
||||
|
||||
public KitContentItem(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
return Methods.serializeItemStack(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemForDisplay() {
|
||||
return itemStack.clone();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.ultimatekits.player;
|
||||
|
||||
import com.songoda.ultimatekits.kit.object.Kit;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -10,6 +10,8 @@ public class PlayerData {
|
||||
|
||||
public enum GUILocation { NOT_IN, BUY_FINAL, KITS, DISPLAY }
|
||||
|
||||
private boolean isInCrate = false;
|
||||
|
||||
private final UUID playerUUID;
|
||||
private boolean kitMode;
|
||||
private Kit inKit = null;
|
||||
@ -55,4 +57,12 @@ public class PlayerData {
|
||||
public void setGuiLocation(GUILocation guiLocation) {
|
||||
this.guiLocation = guiLocation;
|
||||
}
|
||||
|
||||
public boolean isInCrate() {
|
||||
return isInCrate;
|
||||
}
|
||||
|
||||
public void setInCrate(boolean inCrate) {
|
||||
isInCrate = inCrate;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,122 @@
|
||||
package com.songoda.ultimatekits.tasks;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.methods.inventory.AInventory;
|
||||
import com.songoda.ultimatekits.Lang;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CrateAnimateTask extends BukkitRunnable {
|
||||
|
||||
private CrateAnimateTask instance;
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
private final Player player;
|
||||
|
||||
private final Inventory inventory;
|
||||
|
||||
private final ArrayDeque<KitItem> items;
|
||||
|
||||
private final ItemStack give;
|
||||
|
||||
private boolean slow = false;
|
||||
private boolean finish = false;
|
||||
private boolean done = false;
|
||||
|
||||
public CrateAnimateTask(UltimateKits plugin, Player player, Kit kit, ItemStack give) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.give = give;
|
||||
this.inventory = Bukkit.createInventory(null, 27, TextComponent.formatText(kit.getShowableName()));
|
||||
|
||||
plugin.getPlayerDataManager().getPlayerAction(player).setInCrate(true);
|
||||
List<KitItem> items = kit.getContents();
|
||||
Collections.shuffle(items);
|
||||
this.items = new ArrayDeque<>(items);
|
||||
while (this.items.size() < 10) {
|
||||
for (KitItem item : items) {
|
||||
if (this.items.size() < 10)
|
||||
this.items.addLast(item);
|
||||
}
|
||||
}
|
||||
|
||||
instance = this;
|
||||
instance.runTaskTimer(plugin, 0, 3);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
slow = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> finish = true, 20);
|
||||
}, 130);
|
||||
}
|
||||
|
||||
private int num = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (slow && num == 1) {
|
||||
num = 0;
|
||||
return;
|
||||
}
|
||||
num = slow ? 1 : 0;
|
||||
|
||||
for (int i = 0; i < 27; i ++) {
|
||||
inventory.setItem(i, AInventory.toGlass(true, 0));
|
||||
}
|
||||
|
||||
for (int i = 9; i < 18; i ++) {
|
||||
inventory.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
|
||||
inventory.setItem(4, new ItemStack(Material.TRIPWIRE_HOOK));
|
||||
inventory.setItem(22, new ItemStack(Material.TRIPWIRE_HOOK));
|
||||
|
||||
if (!done) {
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 5f, 5f);
|
||||
this.items.addFirst(this.items.getLast());
|
||||
this.items.removeLast();
|
||||
}
|
||||
|
||||
List<KitItem> items = new ArrayList<>(this.items);
|
||||
for (int i = 0; i < 9; i ++) {
|
||||
inventory.setItem(9 + i, items.get(i).getItem());
|
||||
}
|
||||
|
||||
if (finish) {
|
||||
if (inventory.getItem(13).isSimilar(give)) {
|
||||
if (!done) {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item2);
|
||||
}
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10f, 10f);
|
||||
player.sendMessage(plugin.references.getPrefix() + TextComponent.formatText(Lang.CRATE_WON.getConfigValue(WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> finish(), 50);
|
||||
}
|
||||
done = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
|
||||
}
|
||||
|
||||
private void finish() {
|
||||
instance.cancel();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -220,8 +220,9 @@ public class SettingsManager implements Listener {
|
||||
o5("Dont-Preview-Commands", "Main.Dont Preview Commands In Kits", false),
|
||||
o6("Hologram-Layout", "Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}")),
|
||||
o7("EnableSound", "Main.Sounds Enabled", true),
|
||||
o8("Sound", "Main.Sound Played While Clicking In Inventories", "ENTITY_ENDERMEN_TELEPORT"),
|
||||
o85("Sound", "Main.Prevent The Redeeming of a Kit When Inventory Is Full", true),
|
||||
o8("Sound", "Main.Sound Played While Clicking In Inventories", "ENTITY_ENDERMAN_TELEPORT"),
|
||||
o85("-", "Main.Prevent The Redeeming of a Kit When Inventory Is Full", true),
|
||||
CURRENCY_SYMBOL("-", "Main.Currency Symbol", "$"),
|
||||
|
||||
o9("Exit-Icon", "Interfaces.Exit Icon", "OAK_DOOR"),
|
||||
o10("Buy-Icon", "Interfaces.Buy Icon", "EMERALD"),
|
||||
|
Loading…
Reference in New Issue
Block a user