SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Add Multi Personal Kits' (#228) from multi-kits into master

Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-01-30 16:41:53 +01:00
Commit 10eeedb878
4 geänderte Dateien mit 97 neuen und 18 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -405,7 +405,7 @@ public class FightTeam implements IFightTeam{
PersonalKit personalKit = null; PersonalKit personalKit = null;
if(Config.PersonalKits) 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){ if(personalKit != null){
PlayerInventory inventory = fightPlayer.getPlayer().getInventory(); PlayerInventory inventory = fightPlayer.getPlayer().getInventory();

Datei anzeigen

@ -82,6 +82,14 @@ public class Kit {
return memberAllowed; return memberAllowed;
} }
public ItemStack[] getInventory() {
return inventory;
}
public ItemStack[] getArmor() {
return armor;
}
/* Is this kit allowed to set/handle tnt? */ /* Is this kit allowed to set/handle tnt? */
public boolean isTnt(){ public boolean isTnt(){
return tnt; return tnt;
@ -154,6 +162,18 @@ public class Kit {
public void preview(Player player){ public void preview(Player player){
SWInventory inv = new SWInventory(player, 54, name); 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 //36 = Inventargröße
for(int i = 0; i < 36; i++){ for(int i = 0; i < 36; i++){
if(inventory[i] == null) if(inventory[i] == null)
@ -183,13 +203,5 @@ public class Kit {
pos--; 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();
} }
} }

Datei anzeigen

@ -28,11 +28,16 @@ import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.kit.Kit; import de.steamwar.fightsystem.kit.Kit;
import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.states.FightState; 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.PersonalKit;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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.BlockDataMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.EnumSet; import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
public class PersonalKitCreator extends BasicListener { public class PersonalKitCreator extends BasicListener {
@ -60,16 +63,77 @@ public class PersonalKitCreator extends BasicListener {
super(enabled); 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())) if(!enabled.contains(FightSystem.getFightState()))
return; return;
new InventoryBackup(player); player.closeInventory();
new InventoryBackup(player, kit);
FightPlayer fightPlayer = Fight.getFightPlayer(player); FightPlayer fightPlayer = Fight.getFightPlayer(player);
assert fightPlayer != null; assert fightPlayer != null;
PersonalKit kit = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
if(kit == null){ if(kit == null){
fightPlayer.getKit().loadToPlayer(player); fightPlayer.getKit().loadToPlayer(player);
}else{ }else{
@ -191,12 +255,14 @@ public class PersonalKitCreator extends BasicListener {
private final Player player; private final Player player;
private final ItemStack[] contents; private final ItemStack[] contents;
private final ItemStack[] armor; private final ItemStack[] armor;
private final PersonalKit kit;
private InventoryBackup(Player player){ private InventoryBackup(Player player, PersonalKit kit){
openKitCreators.put(player, this); openKitCreators.put(player, this);
this.player = player; this.player = player;
this.contents = player.getInventory().getContents(); this.contents = player.getInventory().getContents();
this.armor = player.getInventory().getArmorContents(); this.armor = player.getInventory().getArmorContents();
this.kit = kit;
} }
private void loadBackup(){ private void loadBackup(){
@ -208,9 +274,10 @@ public class PersonalKitCreator extends BasicListener {
private void close(){ private void close(){
openKitCreators.remove(player); 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(); loadBackup();
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
useKit(player, kit);
} }
private ItemStack[] removeBadItems(ItemStack[] inventory){ private ItemStack[] removeBadItems(ItemStack[] inventory){