Implement personal kits (untested)
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
00967a2d3e
Commit
c5c6e8c32b
@ -98,6 +98,7 @@ public class Config {
|
|||||||
public static final String MemberDefault;
|
public static final String MemberDefault;
|
||||||
public static final String LeaderDefault;
|
public static final String LeaderDefault;
|
||||||
public static final boolean PersonalKits;
|
public static final boolean PersonalKits;
|
||||||
|
public static final List<String> ForbiddenItems;
|
||||||
|
|
||||||
//tech hider parameter
|
//tech hider parameter
|
||||||
public static final Set<Integer> HiddenBlocks;
|
public static final Set<Integer> HiddenBlocks;
|
||||||
@ -179,6 +180,7 @@ public class Config {
|
|||||||
MemberDefault = config.getString("Kits.MemberDefault");
|
MemberDefault = config.getString("Kits.MemberDefault");
|
||||||
LeaderDefault = config.getString("Kits.LeaderDefault");
|
LeaderDefault = config.getString("Kits.LeaderDefault");
|
||||||
PersonalKits = config.getBoolean("Kits.PersonalKits");
|
PersonalKits = config.getBoolean("Kits.PersonalKits");
|
||||||
|
ForbiddenItems = config.getStringList("Kits.ForbiddenItems");
|
||||||
|
|
||||||
ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks");
|
ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks");
|
||||||
Set<Integer> blocks = new HashSet<>();
|
Set<Integer> blocks = new HashSet<>();
|
||||||
|
@ -41,6 +41,8 @@ WinConditionParams:
|
|||||||
Kits:
|
Kits:
|
||||||
MemberDefault: default
|
MemberDefault: default
|
||||||
LeaderDefault: default
|
LeaderDefault: default
|
||||||
|
PersonalKits: false
|
||||||
|
ForbiddenItems: []
|
||||||
Techhider:
|
Techhider:
|
||||||
ObfuscateWith: 121
|
ObfuscateWith: 121
|
||||||
ObfuscateWithTag: ENDER_STONE
|
ObfuscateWithTag: ENDER_STONE
|
||||||
|
@ -10,6 +10,7 @@ import de.steamwar.fightsystem.listener.*;
|
|||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
import de.steamwar.fightsystem.utils.FightScoreboard;
|
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||||
|
import de.steamwar.fightsystem.utils.PersonalKitCreator;
|
||||||
import de.steamwar.fightsystem.utils.TechHider;
|
import de.steamwar.fightsystem.utils.TechHider;
|
||||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
import de.steamwar.fightsystem.utils.WaterRemover;
|
||||||
import de.steamwar.fightsystem.winconditions.*;
|
import de.steamwar.fightsystem.winconditions.*;
|
||||||
@ -136,6 +137,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
throw new SecurityException(fightState.name());
|
throw new SecurityException(fightState.name());
|
||||||
setFightState(FightState.PRE_RUNNING);
|
setFightState(FightState.PRE_RUNNING);
|
||||||
|
|
||||||
|
PersonalKitCreator.closeAll();
|
||||||
loadKits(Fight.getBlueTeam());
|
loadKits(Fight.getBlueTeam());
|
||||||
loadKits(Fight.getRedTeam());
|
loadKits(Fight.getRedTeam());
|
||||||
setAllPlayersGM(GameMode.SURVIVAL);
|
setAllPlayersGM(GameMode.SURVIVAL);
|
||||||
|
@ -8,6 +8,7 @@ import de.steamwar.fightsystem.kit.Kit;
|
|||||||
import de.steamwar.fightsystem.kit.KitManager;
|
import de.steamwar.fightsystem.kit.KitManager;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.utils.PersonalKitCreator;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
@ -77,6 +78,11 @@ public class GUI {
|
|||||||
if(fightPlayer == null)
|
if(fightPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(Config.PersonalKits){
|
||||||
|
new PersonalKitCreator(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Pair<SWItem, Kit>> iconList = new ArrayList<>();
|
List<Pair<SWItem, Kit>> iconList = new ArrayList<>();
|
||||||
|
|
||||||
List<Kit> kitList = KitManager.getKits(fightPlayer.isLeader());
|
List<Kit> kitList = KitManager.getKits(fightPlayer.isLeader());
|
||||||
|
@ -149,7 +149,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
|
|
||||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||||
player.teleport(spawn);
|
player.teleport(spawn);
|
||||||
if(KitManager.getKits(false).size() > 1)
|
if(KitManager.getKits(false).size() > 1 || Config.PersonalKits)
|
||||||
player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
|
player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
|
||||||
player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build());
|
player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build());
|
||||||
TechHider.reloadChunks(player, chunksToReload);
|
TechHider.reloadChunks(player, chunksToReload);
|
||||||
|
@ -1,18 +1,30 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class PersonalKitCreator implements Listener {
|
public class PersonalKitCreator implements Listener {
|
||||||
|
|
||||||
|
private static final Set<PersonalKitCreator> openKitCreators = new HashSet<>();
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
private final SteamwarUser user;
|
||||||
private final ItemStack[] contents;
|
private final ItemStack[] contents;
|
||||||
private final ItemStack[] armor;
|
private final ItemStack[] armor;
|
||||||
|
|
||||||
@ -20,15 +32,33 @@ public class PersonalKitCreator implements Listener {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
contents = player.getInventory().getContents();
|
contents = player.getInventory().getContents();
|
||||||
armor = player.getInventory().getArmorContents();
|
armor = player.getInventory().getArmorContents();
|
||||||
|
user = SteamwarUser.get(player.getUniqueId());
|
||||||
|
|
||||||
//TODO Get Current Kit inventory
|
PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB());
|
||||||
//TODO Prevent unwanted items
|
if(kit == null){
|
||||||
player.getInventory().setContents();
|
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||||
player.getInventory().setArmorContents();
|
assert fightPlayer != null;
|
||||||
|
fightPlayer.getKit().loadToPlayer(player);
|
||||||
|
}else{
|
||||||
|
player.getInventory().setContents(kit.getInventory());
|
||||||
|
player.getInventory().setArmorContents(kit.getArmor());
|
||||||
|
}
|
||||||
|
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
player.openInventory(this.inventory);
|
player.openInventory(player.getInventory());
|
||||||
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
|
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
|
||||||
|
openKitCreators.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void closeAll(){
|
||||||
|
for(PersonalKitCreator creator : openKitCreators)
|
||||||
|
creator.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent e){
|
||||||
|
if(e.getCursor() != null && Config.ForbiddenItems.contains(e.getCursor().getType().name()))
|
||||||
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -36,11 +66,16 @@ public class PersonalKitCreator implements Listener {
|
|||||||
if(!player.equals(e.getPlayer()))
|
if(!player.equals(e.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//TODO Autoclose inventory on PreFightStart
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(){
|
||||||
|
PersonalKit.save(user.getId(), Config.SchematicType.toDB(), player.getInventory().getContents(), player.getInventory().getArmorContents());
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.getInventory().setContents(contents);
|
player.getInventory().setContents(contents);
|
||||||
player.getInventory().setArmorContents(contents);
|
player.getInventory().setArmorContents(armor);
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
|
openKitCreators.remove(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren