Merge pull request 'Add Multi Personal Kits' (#228) from multi-kits into master
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
10eeedb878
@ -97,7 +97,7 @@ public class GUI {
|
||||
return;
|
||||
|
||||
if(Config.PersonalKits){
|
||||
PersonalKitCreator.openKitCreator(p);
|
||||
PersonalKitCreator.openKitSelector(p, "");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ public class FightTeam implements IFightTeam{
|
||||
|
||||
PersonalKit personalKit = null;
|
||||
if(Config.PersonalKits)
|
||||
personalKit = PersonalKit.get(SteamwarUser.get(fightPlayer.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
personalKit = PersonalKit.getKitInUse(SteamwarUser.get(fightPlayer.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
|
||||
if(personalKit != null){
|
||||
PlayerInventory inventory = fightPlayer.getPlayer().getInventory();
|
||||
|
@ -82,6 +82,14 @@ public class Kit {
|
||||
return memberAllowed;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
/* Is this kit allowed to set/handle tnt? */
|
||||
public boolean isTnt(){
|
||||
return tnt;
|
||||
@ -154,6 +162,18 @@ public class Kit {
|
||||
public void preview(Player player){
|
||||
SWInventory inv = new SWInventory(player, 54, name);
|
||||
|
||||
preview(inv, inventory, armor, effects);
|
||||
|
||||
inv.setCallback(-999, (click) -> player.closeInventory());
|
||||
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
|
||||
Commands.kit(player, name);
|
||||
player.closeInventory();
|
||||
});
|
||||
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> GUI.kitSelection(player));
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void preview(SWInventory inv, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects) {
|
||||
//36 = Inventargröße
|
||||
for(int i = 0; i < 36; i++){
|
||||
if(inventory[i] == null)
|
||||
@ -183,13 +203,5 @@ public class Kit {
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
|
||||
inv.setCallback(-999, (click) -> player.closeInventory());
|
||||
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
|
||||
Commands.kit(player, name);
|
||||
player.closeInventory();
|
||||
});
|
||||
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> GUI.kitSelection(player));
|
||||
inv.open();
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,16 @@ import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.kit.Kit;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -46,9 +51,7 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PersonalKitCreator extends BasicListener {
|
||||
@ -60,16 +63,77 @@ public class PersonalKitCreator extends BasicListener {
|
||||
super(enabled);
|
||||
}
|
||||
|
||||
public static void openKitCreator(Player player){
|
||||
public static void openKitSelector(Player player, String qry) {
|
||||
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
kits.removeIf(kit -> !kit.getName().toLowerCase().contains(qry.toLowerCase()));
|
||||
List<SWListInv.SWListEntry<PersonalKit>> entries = new ArrayList<>(kits.size());
|
||||
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), kit)));
|
||||
SWListInv<PersonalKit> inv = new SWListInv<>(player, "§eKit wählen", false, entries, (clickType, kit) -> preview(player, kit));
|
||||
if(entries.isEmpty())
|
||||
inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden"));
|
||||
inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Kitname eingeben");
|
||||
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
|
||||
anvilInv.setCallback(s -> {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) {
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!");
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
Kit prototype = KitManager.getKits(Fight.getFightPlayer(player).isLeader()).get(0);
|
||||
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
|
||||
openKitCreator(player, kit);
|
||||
});
|
||||
anvilInv.open();
|
||||
});
|
||||
inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "§eNach Kit suchen");
|
||||
anvilInv.setItem(Material.PAPER);
|
||||
anvilInv.setCallback(s -> openKitSelector(player, s));
|
||||
anvilInv.open();
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void preview(Player player, PersonalKit kit){
|
||||
SWInventory inv = new SWInventory(player, 54, kit.getName());
|
||||
|
||||
Kit.preview(inv, kit.getInventory(), kit.getArmor(), null);
|
||||
|
||||
inv.setItem(45, Material.LEATHER_CHESTPLATE, "§aKit benutzen", clickType -> useKit(player, kit));
|
||||
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> openKitCreator(player, kit));
|
||||
inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> {
|
||||
player.closeInventory();
|
||||
SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?");
|
||||
conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory());
|
||||
conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> {
|
||||
player.closeInventory();
|
||||
if(kit.isInUse()) {
|
||||
useKit(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()).get(0));
|
||||
}
|
||||
kit.delete();
|
||||
});
|
||||
conf.open();
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private static void useKit(Player player, PersonalKit kit) {
|
||||
kit.setInUse();
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
public static void openKitCreator(Player player, PersonalKit kit){
|
||||
if(!enabled.contains(FightSystem.getFightState()))
|
||||
return;
|
||||
|
||||
new InventoryBackup(player);
|
||||
player.closeInventory();
|
||||
new InventoryBackup(player, kit);
|
||||
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||
assert fightPlayer != null;
|
||||
|
||||
PersonalKit kit = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
if(kit == null){
|
||||
fightPlayer.getKit().loadToPlayer(player);
|
||||
}else{
|
||||
@ -191,12 +255,14 @@ public class PersonalKitCreator extends BasicListener {
|
||||
private final Player player;
|
||||
private final ItemStack[] contents;
|
||||
private final ItemStack[] armor;
|
||||
private final PersonalKit kit;
|
||||
|
||||
private InventoryBackup(Player player){
|
||||
private InventoryBackup(Player player, PersonalKit kit){
|
||||
openKitCreators.put(player, this);
|
||||
this.player = player;
|
||||
this.contents = player.getInventory().getContents();
|
||||
this.armor = player.getInventory().getArmorContents();
|
||||
this.kit = kit;
|
||||
}
|
||||
|
||||
private void loadBackup(){
|
||||
@ -208,9 +274,10 @@ public class PersonalKitCreator extends BasicListener {
|
||||
|
||||
private void close(){
|
||||
openKitCreators.remove(player);
|
||||
PersonalKit.save(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
|
||||
kit.setContainer(removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
|
||||
loadBackup();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
useKit(player, kit);
|
||||
}
|
||||
|
||||
private ItemStack[] removeBadItems(ItemStack[] inventory){
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren