SteamWar/FightSystem
Archiviert
13
1

Add Multi Personal Kits

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-09 17:35:32 +01:00
Ursprung 5035cde575
Commit 42b4109698
4 geänderte Dateien mit 126 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -97,7 +97,7 @@ public class GUI {
return;
if(Config.PersonalKits){
PersonalKitCreator.openKitCreator(p);
PersonalKitCreator.openKitSelector(p, "");
return;
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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;

Datei anzeigen

@ -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,117 @@ 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) -> showKit(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, "§eKit namen eingeben");
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
anvilInv.setCallback(s -> {
Kit prototype = KitManager.getKits(Fight.getFightPlayer(player).isLeader()).get(0);
PersonalKit.create(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
List<PersonalKit> kitList = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), s);
if(kitList.size() > 1) {
List<SWListInv.SWListEntry<PersonalKit>> kitsSelect = new ArrayList<>(kitList.size());
kitList.forEach(kit -> kitsSelect.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName()), kit)));
SWListInv<PersonalKit> inv1 = new SWListInv<>(player, "§eWelches Kit bearbeiten", kitsSelect, (clickType1, kit) -> openKitCreator(player, kit));
inv1.open();
} else {
openKitCreator(player, kitList.get(0));
}
});
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();
}
private static void showKit(Player player, PersonalKit kit) {
SWInventory inv = new SWInventory(player, 9, "§e" + kit.getName());
inv.setItem(0, Material.LEATHER_CHESTPLATE, "§aKit benutzen", clickType -> useKit(player, kit));
inv.setItem(1, Material.GLASS, "§bPreview", clickType -> preview(player, kit));
inv.setItem(4, SWItem.getMaterial("WOOD_AXE"), "§6Kit bearbeiten", clickType -> openKitCreator(player, kit));
inv.setItem(5, Material.NAME_TAG, "§6Kit Umbenennen", clickType -> renameKit(player, kit));
inv.setItem(8, Material.BARRIER, "§cKit Löschen", clickType -> {
player.closeInventory();
SWInventory conf = new SWInventory(player, 0, "§cKit " + kit.getName() + " 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()) {
PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
}
kit.delete();
});
conf.open();
});
inv.open();
}
public static void renameKit(Player player, PersonalKit kit) {
SWAnvilInv inv = new SWAnvilInv(player, "§6Kit " + kit.getName() + " umbenennen");
inv.setItem(Material.NAME_TAG);
inv.setCallback(kit::setName);
inv.open();
}
public static void preview(Player player, PersonalKit kit){
SWInventory inv = new SWInventory(player, 54, "§e" + kit.getName());
//36 = Inventargröße
for(int i = 0; i < 36; i++){
if(kit.getInventory()[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(kit.getInventory()[i]);
inv.setItem(i, item);
}
if(kit.getArmor() != null){
for(int i = 0; i < 4; i++){
if(kit.getArmor()[i] == null)
continue;
SWItem item = new SWItem();
item.setItemStack(kit.getArmor()[i]);
inv.setItem(36 + i, item);
}
}
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
player.closeInventory();
useKit(player, kit);
});
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> showKit(player, kit));
inv.open();
}
private static void useKit(Player player, PersonalKit kit) {
PersonalKit kitUse = PersonalKit.getKitInUse(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
if(kitUse != null) kitUse.setInUse(false);
kit.setInUse(true);
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 +295,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 +314,11 @@ 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.setInventory(removeBadItems(player.getInventory().getContents()));
kit.setArmor(removeBadItems(player.getInventory().getArmorContents()));
loadBackup();
player.setGameMode(GameMode.SURVIVAL);
useKit(player, kit);
}
private ItemStack[] removeBadItems(ItemStack[] inventory){