mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-26 04:05:26 +01:00
Merge branch 'development'
This commit is contained in:
commit
2fd0bd4578
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateKits</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.6.14</version>
|
||||
<version>2.6.15</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateKits-${project.version}</finalName>
|
||||
|
@ -46,6 +46,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -75,8 +76,6 @@ public class UltimateKits extends SongodaPlugin {
|
||||
private CrateManager crateManager;
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
private ItemSerializer itemSerializer;
|
||||
|
||||
private DatabaseConnector databaseConnector;
|
||||
private DataMigrationManager dataMigrationManager;
|
||||
private DataManager dataManager;
|
||||
@ -95,12 +94,6 @@ public class UltimateKits extends SongodaPlugin {
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
try {
|
||||
this.itemSerializer = new ItemSerializer();
|
||||
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
||||
console.sendMessage(ChatColor.RED + "Could not load the serialization class! Please report this error.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -227,13 +220,22 @@ public class UltimateKits extends SongodaPlugin {
|
||||
ConfigurationSection section = kitConfig.getConfigurationSection("Kits." + kitName);
|
||||
if (section == null) continue;
|
||||
|
||||
String itemString = section.getString("displayItem");
|
||||
|
||||
ItemStack item = null;
|
||||
|
||||
if (itemString != null) {
|
||||
if (itemString.contains("{"))
|
||||
item = ItemSerializer.deserializeItemStackFromJson(itemString);
|
||||
else
|
||||
item = CompatibleMaterial.getMaterial(itemString).getItem();
|
||||
}
|
||||
|
||||
kitManager.addKit(new Kit(kitName)
|
||||
.setTitle(section.getString("title"))
|
||||
.setDelay(section.getLong("delay"))
|
||||
.setLink(section.getString("link"))
|
||||
.setDisplayItem(section.contains("displayItem")
|
||||
? CompatibleMaterial.getMaterial(section.getString("displayItem"), CompatibleMaterial.DIAMOND_HELMET)
|
||||
: null)
|
||||
.setDisplayItem(item)
|
||||
.setCategory(categoryManager.getCategory(section.getString("category")))
|
||||
.setHidden(section.getBoolean("hidden"))
|
||||
.setPrice(section.getDouble("price"))
|
||||
@ -314,7 +316,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
public void onPluginDisable() {
|
||||
saveKits(false);
|
||||
dataFile.save();
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
kitManager.clearKits();
|
||||
HologramManager.removeAllHolograms();
|
||||
}
|
||||
@ -326,9 +328,9 @@ public class UltimateKits extends SongodaPlugin {
|
||||
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
kitConfig.load();
|
||||
categoryConfig.load();
|
||||
keyFile.load();
|
||||
@ -488,7 +490,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
if (kit.getCategory() != null)
|
||||
kitConfig.set("Kits." + kit.getKey() + ".category", kit.getCategory().getKey());
|
||||
if (kit.getDisplayItem() != null)
|
||||
kitConfig.set("Kits." + kit.getKey() + ".displayItem", kit.getDisplayItem().toString());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".displayItem", ItemSerializer.serializeItemStackToJson(kit.getDisplayItem()));
|
||||
else
|
||||
kitConfig.set("Kits." + kit.getKey() + ".displayItem", null);
|
||||
|
||||
@ -587,15 +589,6 @@ public class UltimateKits extends SongodaPlugin {
|
||||
return guiManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of the item serializer
|
||||
*
|
||||
* @return instance of ItemSerializer
|
||||
*/
|
||||
public ItemSerializer getItemSerializer() {
|
||||
return this.itemSerializer;
|
||||
}
|
||||
|
||||
public DisplayItemHandler getDisplayItemHandler() {
|
||||
return displayItemHandler;
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ public class CommandCreatekit extends AbstractCommand {
|
||||
if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
String kitStr = args[0].toLowerCase();
|
||||
String kitStr = args[0].toLowerCase().trim();
|
||||
if (plugin.getKitManager().getKit(kitStr) != null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
|
||||
Kit kit = new Kit(kitStr.trim());
|
||||
Kit kit = new Kit(kitStr);
|
||||
plugin.getKitManager().addKit(kit);
|
||||
guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, null));
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.ultimatekits.conversion.hooks;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.conversion.Hook;
|
||||
import com.songoda.ultimatekits.utils.ItemSerializer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -16,7 +17,7 @@ public class DefaultHook implements Hook {
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) continue;
|
||||
for (String string : kit.items) {
|
||||
items.add(UltimateKits.getInstance().getItemSerializer().deserializeItemStackFromJson(string));
|
||||
items.add(ItemSerializer.deserializeItemStackFromJson(string));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ public class CategoryEditorGui extends Gui {
|
||||
plugin.getLocale().newMessage("&aCategory added successfully!").sendPrefixedMessage(player);
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
||||
plugin.saveKits(false);
|
||||
}).setOnClose(() -> {
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
|
||||
});
|
||||
|
@ -29,7 +29,7 @@ public class ConfirmBuyGui extends Gui {
|
||||
Methods.fillGlass(this);
|
||||
|
||||
// Kit information
|
||||
setItem(0, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.DIAMOND_HELMET,
|
||||
setItem(0, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.DIAMOND_HELMET.getItem(),
|
||||
ChatColor.RED + TextUtils.formatText(kit.getKey().toLowerCase(), true),
|
||||
ChatColor.GREEN + Settings.CURRENCY_SYMBOL.getString() + Methods.formatEconomy(cost)));
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class KitDecorOptionsGui extends Gui {
|
||||
});
|
||||
|
||||
// Item Display Override
|
||||
setButton(1, 7, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON,
|
||||
setButton(1, 7, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON.getItem(),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayone").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayonelore")
|
||||
.processPlaceholder("enabled", kitBlockData.isItemOverride() ? enableLore : disableLore)
|
||||
|
@ -32,6 +32,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
private final UltimateKits plugin;
|
||||
private final Kit kit;
|
||||
private final Player player;
|
||||
private final Gui back;
|
||||
|
||||
private boolean isInFunction = false;
|
||||
private boolean isInInventory = false;
|
||||
@ -39,20 +40,20 @@ public class KitEditorGui extends DoubleGui {
|
||||
private ItemStack[] stash;
|
||||
|
||||
public KitEditorGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(back);
|
||||
super(6);
|
||||
this.plugin = plugin;
|
||||
this.kit = kit;
|
||||
this.player = player;
|
||||
this.back = back;
|
||||
|
||||
setDefaultItem(null);
|
||||
setRows(6);
|
||||
setTitle(plugin.getLocale().getMessage("interface.kiteditor.title")
|
||||
.processPlaceholder("name", kit.getName())
|
||||
.getMessage());
|
||||
|
||||
setOnClose((event) -> {
|
||||
restoreItemsInstance();
|
||||
this.saveKit(player, inventory, false);
|
||||
saveKit(player, inventory, false);
|
||||
CompatibleSound.ENTITY_VILLAGER_YES.play(player);
|
||||
});
|
||||
|
||||
@ -77,7 +78,10 @@ public class KitEditorGui extends DoubleGui {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
event -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, back);
|
||||
});
|
||||
|
||||
// info icon
|
||||
setItem(0, 4, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
|
||||
@ -212,7 +216,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
plugin.getLocale().getMessage("interface.kiteditor.generaloptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitGeneralOptionsGui(plugin, player, kit, this));
|
||||
guiManager.showGUI(player, new KitGeneralOptionsGui(plugin, player, kit, back));
|
||||
});
|
||||
|
||||
setPlayerButton(1, GuiUtils.createButtonItem(CompatibleMaterial.EMERALD,
|
||||
@ -220,7 +224,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
plugin.getLocale().getMessage("interface.kiteditor.sellingoptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitSellingOptionsGui(plugin, player, kit, this));
|
||||
guiManager.showGUI(player, new KitSellingOptionsGui(plugin, player, kit, back));
|
||||
});
|
||||
|
||||
setPlayerButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
|
||||
@ -228,7 +232,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
plugin.getLocale().getMessage("interface.kiteditor.guioptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitGuiOptionsGui(plugin, player, kit, this));
|
||||
guiManager.showGUI(player, new KitGuiOptionsGui(plugin, player, kit, back));
|
||||
});
|
||||
|
||||
setPlayerButton(4, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
||||
@ -257,7 +261,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
.processPlaceholder("command", msg).getMessage())
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
this.inventory.addItem(parseStack);
|
||||
inventory.addItem(parseStack);
|
||||
Bukkit.getScheduler().runTask(plugin, event.player::closeInventory);
|
||||
}).setOnClose(() -> {
|
||||
event.manager.showGUI(event.player, this);
|
||||
@ -301,6 +305,30 @@ public class KitEditorGui extends DoubleGui {
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
setPlayerButton(7, GuiUtils.createButtonItem(CompatibleMaterial.SHEEP_SPAWN_EGG,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.clonelore")
|
||||
.getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
gui.setTitle("Enter a new kit name");
|
||||
gui.setAction(evnt -> {
|
||||
String kitStr = gui.getInputText().toLowerCase().trim();
|
||||
|
||||
if (plugin.getKitManager().getKit(kitStr) != null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
player.closeInventory();
|
||||
} else {
|
||||
Kit newKit = kit.clone(kitStr);
|
||||
plugin.getKitManager().addKit(newKit);
|
||||
player.closeInventory();
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
guiManager.showGUI(player, new KitEditorGui(plugin, player, newKit, null)), 2L);
|
||||
}
|
||||
});
|
||||
guiManager.showGUI(player, gui);
|
||||
});
|
||||
|
||||
setPlayerButton(8, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.animationlore")
|
||||
@ -314,6 +342,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
}
|
||||
setInvItems();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,8 +16,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
public class KitGeneralOptionsGui extends Gui {
|
||||
|
||||
public KitGeneralOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(back);
|
||||
setRows(3);
|
||||
super(3);
|
||||
setTitle(plugin.getLocale().getMessage("interface.kitoptions.title")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.getMessage());
|
||||
@ -35,7 +34,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
|
||||
// edit delay
|
||||
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK,
|
||||
@ -56,6 +55,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delaynonumber").processPlaceholder("input", msg).sendPrefixedMessage(player);
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
@ -80,6 +80,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
return;
|
||||
}
|
||||
plugin.getLocale().getMessage("interface.kitoptions.notacategory").processPlaceholder("input", msg).sendPrefixedMessage(player);
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
} else if (event.clickType == ClickType.RIGHT) {
|
||||
@ -106,6 +107,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
plugin.getLocale().getMessage("interface.kitoptions.destroycancel").sendPrefixedMessage(player);
|
||||
}
|
||||
aevent.player.closeInventory();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
@ -21,11 +21,10 @@ public class KitGuiOptionsGui extends Gui {
|
||||
private final Player player;
|
||||
|
||||
public KitGuiOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(back);
|
||||
super(3);
|
||||
this.plugin = plugin;
|
||||
this.kit = kit;
|
||||
this.player = player;
|
||||
setRows(3);
|
||||
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.getMessage());
|
||||
@ -44,7 +43,7 @@ public class KitGuiOptionsGui extends Gui {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
paint();
|
||||
}
|
||||
|
||||
@ -61,7 +60,7 @@ public class KitGuiOptionsGui extends Gui {
|
||||
event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitguioptions.holoprompt").getMessage());
|
||||
gui.setAction(aevent -> {
|
||||
gui.setAction(evnt -> {
|
||||
final String msg = gui.getInputText().trim();
|
||||
kit.setTitle(msg);
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.holoset")
|
||||
@ -70,8 +69,9 @@ public class KitGuiOptionsGui extends Gui {
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
plugin.updateHologram(kit);
|
||||
aevent.player.closeInventory();
|
||||
evnt.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
@ -79,13 +79,15 @@ public class KitGuiOptionsGui extends Gui {
|
||||
kit.setTitle(null);
|
||||
plugin.updateHologram(kit);
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
|
||||
setButton(1, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON,
|
||||
setButton(1, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.BEACON.getItem(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.item").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemlore")
|
||||
.processPlaceholder("onoff",
|
||||
kit.getDisplayItem() != null ? plugin.getLocale().getMessage("interface.kitguioptions.itemon").processPlaceholder("item", kit.getDisplayItem().toString()).getMessage()
|
||||
kit.getDisplayItem() != null ? plugin.getLocale().getMessage("interface.kitguioptions.itemon")
|
||||
.processPlaceholder("item", kit.getDisplayItem().toString()).getMessage()
|
||||
: plugin.getLocale().getMessage("interface.kitguioptions.itemoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
@ -98,6 +100,7 @@ public class KitGuiOptionsGui extends Gui {
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemset").processPlaceholder("item", kit.getName()).sendPrefixedMessage(player);
|
||||
paint();
|
||||
}
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
setAction(1, 4, ClickType.RIGHT, event -> {
|
||||
kit.setDisplayItem((ItemStack) null);
|
||||
@ -115,6 +118,7 @@ public class KitGuiOptionsGui extends Gui {
|
||||
event -> {
|
||||
kit.setHidden(!kit.isHidden());
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class KitSelectorGui extends Gui {
|
||||
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
|
||||
|
||||
setButton(row, col, GuiUtils.createButtonItem(
|
||||
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK, kitTitle,
|
||||
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK.getItem(), kitTitle,
|
||||
getKitLore(kit)),
|
||||
event -> {
|
||||
if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {
|
||||
@ -157,6 +157,7 @@ public class KitSelectorGui extends Gui {
|
||||
plugin.getKitManager().moveKit(kit, false);
|
||||
}
|
||||
loadKits();
|
||||
plugin.saveKits(false);
|
||||
showPage();
|
||||
} else if (event.clickType == ClickType.LEFT) {
|
||||
kit.display(player, guiManager, this);
|
||||
|
@ -20,11 +20,10 @@ public class KitSellingOptionsGui extends Gui {
|
||||
private final Kit kit;
|
||||
|
||||
public KitSellingOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(back);
|
||||
super(3);
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.kit = kit;
|
||||
setRows(3);
|
||||
setTitle(plugin.getLocale().getMessage("interface.kitblock.title")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.getMessage());
|
||||
@ -42,7 +41,7 @@ public class KitSellingOptionsGui extends Gui {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
paint();
|
||||
}
|
||||
|
||||
@ -81,6 +80,7 @@ public class KitSellingOptionsGui extends Gui {
|
||||
plugin.updateHologram(kit);
|
||||
aevent.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
@ -119,6 +119,7 @@ public class KitSellingOptionsGui extends Gui {
|
||||
plugin.updateHologram(kit);
|
||||
aevent.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
}
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
|
@ -74,7 +74,7 @@ public class DisplayItemHandler {
|
||||
ItemStack is = list.get(inum - 1);
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
if (kit.getDisplayItem() != null)
|
||||
is = kit.getDisplayItem().getItem();
|
||||
is = kit.getDisplayItem();
|
||||
}
|
||||
is.setAmount(1);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
|
@ -39,10 +39,10 @@ import java.util.Objects;
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class Kit {
|
||||
public class Kit implements Cloneable {
|
||||
|
||||
private final String key;
|
||||
private final String name;
|
||||
private String key;
|
||||
private String name;
|
||||
private Category category = null;
|
||||
|
||||
private static UltimateKits plugin;
|
||||
@ -50,7 +50,7 @@ public class Kit {
|
||||
private String link, title = null;
|
||||
private long delay = 0L;
|
||||
private boolean hidden = false;
|
||||
private CompatibleMaterial displayItem = null;
|
||||
private ItemStack displayItem = null;
|
||||
private List<KitItem> contents = new ArrayList<>();
|
||||
private KitAnimation kitAnimation = KitAnimation.NONE;
|
||||
|
||||
@ -281,7 +281,7 @@ public class Kit {
|
||||
}
|
||||
|
||||
public boolean giveKit(Player player) {
|
||||
return giveKit(player, getContents().size(), -1);
|
||||
return giveKit(player, contents.size(), -1);
|
||||
}
|
||||
|
||||
private boolean giveKit(Player player, Key key) {
|
||||
@ -294,13 +294,13 @@ public class Kit {
|
||||
|
||||
private boolean giveKit(Player player, int itemAmount, int kitAmount) {
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
int kitSize = innerContents.size();
|
||||
|
||||
// Amount of items from the kit to give to the player.
|
||||
if (kitAnimation == KitAnimation.ROULETTE)
|
||||
itemAmount = 1; //TODO how about kitAmount > 1? generateRandomItem() will only give 1 random item instead of kitAmount
|
||||
int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize;
|
||||
if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount;
|
||||
System.out.println("itemAmount" + ": " + itemAmount);
|
||||
int itemGiveAmount = kitAmount > 0 ? itemAmount * kitAmount : kitAmount;
|
||||
System.out.println(itemGiveAmount + " : " + kitAmount + " : " + itemAmount);
|
||||
|
||||
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemGiveAmount)) {
|
||||
plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player);
|
||||
@ -310,20 +310,21 @@ public class Kit {
|
||||
if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE)
|
||||
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
||||
|
||||
return generateRandomItem(innerContents, itemGiveAmount, player);
|
||||
return generateRandomItem(innerContents, itemGiveAmount, 0, player);
|
||||
}
|
||||
|
||||
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, Player player) {
|
||||
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, int itemGivenAmount, Player player) {
|
||||
if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE)
|
||||
Collections.shuffle(innerContents);
|
||||
|
||||
for (KitItem item : new ArrayList<>(innerContents)) {
|
||||
if (itemGiveAmount == 0) break;
|
||||
if (itemGiveAmount <= 0 && itemGivenAmount != 0) break;
|
||||
double ch = item.getChance() == 0 ? 100 : item.getChance();
|
||||
double rand = Math.random() * 100;
|
||||
System.out.println("We tryin here [" + ch + ":" + rand + "]");
|
||||
itemGiveAmount--;
|
||||
if (rand < ch || ch == 100) {
|
||||
|
||||
itemGivenAmount++;
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
// TODO: this is a very bad way to solve this problem.
|
||||
// Giving the player kit rewards really should be done outside of the Kit class.
|
||||
@ -347,9 +348,8 @@ public class Kit {
|
||||
}
|
||||
}
|
||||
|
||||
if (itemGiveAmount > 0 && !innerContents.isEmpty()) {
|
||||
return generateRandomItem(innerContents, itemGiveAmount, player);
|
||||
}
|
||||
if ((itemGiveAmount > 0 || itemGivenAmount == 0) && !innerContents.isEmpty())
|
||||
return generateRandomItem(innerContents, itemGiveAmount, itemGivenAmount, player);
|
||||
|
||||
player.updateInventory();
|
||||
return true;
|
||||
@ -447,16 +447,12 @@ public class Kit {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CompatibleMaterial getDisplayItem() {
|
||||
public ItemStack getDisplayItem() {
|
||||
return displayItem;
|
||||
}
|
||||
|
||||
public void setDisplayItem(ItemStack item) {
|
||||
this.displayItem = item != null ? CompatibleMaterial.getMaterial(item) : null;
|
||||
}
|
||||
|
||||
public Kit setDisplayItem(CompatibleMaterial material) {
|
||||
this.displayItem = material;
|
||||
public Kit setDisplayItem(ItemStack item) {
|
||||
this.displayItem = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -478,6 +474,26 @@ public class Kit {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kit clone(String key) {
|
||||
try {
|
||||
Kit newKit = (Kit) super.clone();
|
||||
|
||||
List<KitItem> contents = new ArrayList<>();
|
||||
|
||||
for (KitItem item : newKit.contents)
|
||||
contents.add(item.clone());
|
||||
|
||||
newKit.setContents(contents);
|
||||
|
||||
newKit.key = key;
|
||||
newKit.name = TextUtils.formatText(key, true);
|
||||
|
||||
return newKit;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (key != null ? key.hashCode() : 0);
|
||||
|
@ -9,6 +9,7 @@ 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.settings.Settings;
|
||||
import com.songoda.ultimatekits.utils.ItemSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -19,7 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class KitItem {
|
||||
public class KitItem implements Cloneable {
|
||||
|
||||
private KitContent content;
|
||||
private KitItemType type;
|
||||
@ -52,7 +53,7 @@ public class KitItem {
|
||||
this.content = new KitContentCommand(line.substring(1));
|
||||
this.type = KitItemType.COMMAND;
|
||||
} else {
|
||||
ItemStack itemStack = item == null ? UltimateKits.getInstance().getItemSerializer().deserializeItemStackFromJson(line) : item;
|
||||
ItemStack itemStack = item == null ? ItemSerializer.deserializeItemStackFromJson(line) : item;
|
||||
this.content = itemStack != null ? new KitContentItem(itemStack) : null;
|
||||
this.type = KitItemType.ITEM;
|
||||
}
|
||||
@ -222,6 +223,10 @@ public class KitItem {
|
||||
return type;
|
||||
}
|
||||
|
||||
public KitItem clone() throws CloneNotSupportedException {
|
||||
return (KitItem)super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KitItem:{"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.ItemSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -25,7 +26,7 @@ public class KitContentItem implements KitContent {
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
if (serialized != null) return serialized;
|
||||
serialized = UltimateKits.getInstance().getItemSerializer().serializeItemStackToJson(itemStack);
|
||||
serialized = ItemSerializer.serializeItemStackToJson(itemStack);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
@ -11,23 +11,23 @@ public class ItemSerializer {
|
||||
|
||||
// classes needed for reflections
|
||||
|
||||
private Class<?> classMojangsonParser = Class.forName(formatNMS("net.minecraft.server.NMS.MojangsonParser"));
|
||||
private Class<?> classItemStack = Class.forName(formatNMS("net.minecraft.server.NMS.ItemStack"));
|
||||
private Class<?> classCraftItemStack = Class.forName(formatNMS("org.bukkit.craftbukkit.NMS.inventory.CraftItemStack"));
|
||||
private Class<?> classNBTTagCompound = Class.forName(formatNMS("net.minecraft.server.NMS.NBTTagCompound"));
|
||||
private Class<?> classBukkitItemStack = Class.forName("org.bukkit.inventory.ItemStack");
|
||||
private static Class<?> classMojangsonParser;
|
||||
private static Class<?> classItemStack;
|
||||
private static Class<?> classCraftItemStack;
|
||||
private static Class<?> classNBTTagCompound;
|
||||
private static Class<?> classBukkitItemStack;
|
||||
|
||||
private Constructor<?> constructorItemStack;
|
||||
private static Constructor<?> constructorItemStack;
|
||||
|
||||
// reflected methods
|
||||
|
||||
private Method methodParseString;
|
||||
private Method methodCreateStack;
|
||||
private Method methodToItemStack;
|
||||
private Method methodTobItemStack;
|
||||
private Method methodTocItemStack;
|
||||
private Method methodSaveTagToStack;
|
||||
private Method methodToString;
|
||||
private static Method methodParseString;
|
||||
private static Method methodCreateStack;
|
||||
private static Method methodToItemStack;
|
||||
private static Method methodTobItemStack;
|
||||
private static Method methodTocItemStack;
|
||||
private static Method methodSaveTagToStack;
|
||||
private static Method methodToString;
|
||||
|
||||
/**
|
||||
* Initializes all reflection methods
|
||||
@ -36,19 +36,29 @@ public class ItemSerializer {
|
||||
* @throws SecurityException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public ItemSerializer() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
methodParseString = classMojangsonParser.getMethod("parse", String.class);
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
methodToItemStack = classItemStack.getMethod("a", classNBTTagCompound);
|
||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
constructorItemStack = classItemStack.getConstructor(classNBTTagCompound);
|
||||
else
|
||||
methodCreateStack = classItemStack.getMethod("createStack", classNBTTagCompound);
|
||||
methodTobItemStack = classCraftItemStack.getMethod("asBukkitCopy", classItemStack);
|
||||
static {
|
||||
try {
|
||||
classMojangsonParser = Class.forName(formatNMS("net.minecraft.server.NMS.MojangsonParser"));
|
||||
classItemStack = Class.forName(formatNMS("net.minecraft.server.NMS.ItemStack"));
|
||||
classCraftItemStack = Class.forName(formatNMS("org.bukkit.craftbukkit.NMS.inventory.CraftItemStack"));
|
||||
classNBTTagCompound = Class.forName(formatNMS("net.minecraft.server.NMS.NBTTagCompound"));
|
||||
classBukkitItemStack = Class.forName("org.bukkit.inventory.ItemStack");
|
||||
methodParseString = classMojangsonParser.getMethod("parse", String.class);
|
||||
|
||||
methodTocItemStack = classCraftItemStack.getDeclaredMethod("asNMSCopy", classBukkitItemStack);
|
||||
methodSaveTagToStack = classItemStack.getMethod("save", classNBTTagCompound);
|
||||
methodToString = classNBTTagCompound.getMethod("toString");
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
methodToItemStack = classItemStack.getMethod("a", classNBTTagCompound);
|
||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
constructorItemStack = classItemStack.getConstructor(classNBTTagCompound);
|
||||
else
|
||||
methodCreateStack = classItemStack.getMethod("createStack", classNBTTagCompound);
|
||||
methodTobItemStack = classCraftItemStack.getMethod("asBukkitCopy", classItemStack);
|
||||
|
||||
methodTocItemStack = classCraftItemStack.getDeclaredMethod("asNMSCopy", classBukkitItemStack);
|
||||
methodSaveTagToStack = classItemStack.getMethod("save", classNBTTagCompound);
|
||||
methodToString = classNBTTagCompound.getMethod("toString");
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.getStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,7 +67,7 @@ public class ItemSerializer {
|
||||
* @param s the string to format, must contain NMS.
|
||||
* @return formatted string
|
||||
*/
|
||||
private String formatNMS(String s) {
|
||||
private static String formatNMS(String s) {
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String nmsVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
return s.replace("NMS", nmsVersion);
|
||||
@ -69,7 +79,7 @@ public class ItemSerializer {
|
||||
* @param jsonString the JSON String to parse
|
||||
* @return the deserialized ItemStack
|
||||
*/
|
||||
public ItemStack deserializeItemStackFromJson(String jsonString) {
|
||||
public static ItemStack deserializeItemStackFromJson(String jsonString) {
|
||||
try {
|
||||
Object nbtTagCompound = methodParseString.invoke(null, jsonString);
|
||||
Object citemStack;
|
||||
@ -94,7 +104,7 @@ public class ItemSerializer {
|
||||
* @param itemStack the ItemStack to parse
|
||||
* @return condensed JSON String
|
||||
*/
|
||||
public String serializeItemStackToJson(ItemStack itemStack) {
|
||||
public static String serializeItemStackToJson(ItemStack itemStack) {
|
||||
try {
|
||||
Object citemStack = methodTocItemStack.invoke(null, itemStack);
|
||||
Object nbtTagCompoundObject = classNBTTagCompound.newInstance();
|
||||
|
@ -153,6 +153,8 @@ interface:
|
||||
addeconomyok: '&8Money &5$%amount%&8 has been added to your kit.'
|
||||
animation: '&6Kit Animation'
|
||||
animationlore: '&7Currently: &6%animation%'
|
||||
clone: '&aClone Kit'
|
||||
clonelore: '&7Use this to create an identical|&7kit with a different name.'
|
||||
itemediting: '&6Switch To Item Editing'
|
||||
itemeditinglore: '&7Click to enable|&7item editing.'
|
||||
itemmoving: '&6Switch To Item Moving'
|
||||
|
Loading…
Reference in New Issue
Block a user