Merge branch 'personalKit' of SteamWar/FightSystem into master
Dieser Commit ist enthalten in:
Commit
86c3855cd5
@ -98,6 +98,8 @@ public class Config {
|
||||
//default kits
|
||||
public static final String MemberDefault;
|
||||
public static final String LeaderDefault;
|
||||
public static final boolean PersonalKits;
|
||||
public static final List<String> ForbiddenItems;
|
||||
|
||||
//tech hider parameter
|
||||
public static final Set<Integer> HiddenBlocks;
|
||||
@ -179,6 +181,8 @@ public class Config {
|
||||
|
||||
MemberDefault = config.getString("Kits.MemberDefault");
|
||||
LeaderDefault = config.getString("Kits.LeaderDefault");
|
||||
PersonalKits = config.getBoolean("Kits.PersonalKits");
|
||||
ForbiddenItems = config.getStringList("Kits.ForbiddenItems");
|
||||
|
||||
ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks");
|
||||
Set<Integer> blocks = new HashSet<>();
|
||||
|
@ -41,6 +41,8 @@ WinConditionParams:
|
||||
Kits:
|
||||
MemberDefault: default
|
||||
LeaderDefault: default
|
||||
PersonalKits: false
|
||||
ForbiddenItems: []
|
||||
Techhider:
|
||||
ObfuscateWith: 121
|
||||
ObfuscateWithTag: ENDER_STONE
|
||||
|
@ -133,12 +133,14 @@ public class FightSystem extends JavaPlugin {
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.PRE_RUNNING);
|
||||
|
||||
loadKits(Fight.getBlueTeam());
|
||||
loadKits(Fight.getRedTeam());
|
||||
PersonalKitCreator.closeAll();
|
||||
Fight.getBlueTeam().loadKits();
|
||||
Fight.getRedTeam().loadKits();
|
||||
setAllPlayersGM(GameMode.SURVIVAL);
|
||||
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
||||
|
||||
mainCountdown = new PreRunningCountdown();
|
||||
|
||||
Fight.replaceSync();
|
||||
|
||||
if(Config.event())
|
||||
@ -253,17 +255,6 @@ public class FightSystem extends JavaPlugin {
|
||||
stateDependent.enable();
|
||||
}
|
||||
|
||||
private static void loadKits(FightTeam team){
|
||||
for(FightPlayer allFightPlayers : team.getPlayers()) {
|
||||
if(allFightPlayers.getPlayer() == null)
|
||||
continue;
|
||||
allFightPlayers.getPlayer().getInventory().clear();
|
||||
if(allFightPlayers.getKit() == null)
|
||||
continue;
|
||||
allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAllPlayersGM(GameMode gm) {
|
||||
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
|
||||
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
||||
|
@ -8,6 +8,7 @@ import de.steamwar.fightsystem.kit.Kit;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.PersonalKitCreator;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
@ -76,6 +77,11 @@ public class GUI {
|
||||
if(fightPlayer == null)
|
||||
return;
|
||||
|
||||
if(Config.PersonalKits){
|
||||
new PersonalKitCreator(p);
|
||||
return;
|
||||
}
|
||||
|
||||
List<SWListInv.SWListEntry<Kit>> iconList = new ArrayList<>();
|
||||
|
||||
List<Kit> kitList = KitManager.getKits(fightPlayer.isLeader());
|
||||
|
@ -10,7 +10,9 @@ import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -20,6 +22,7 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.scoreboard.NameTagVisibility;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
@ -145,7 +148,7 @@ public class FightTeam implements IFightTeam{
|
||||
|
||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||
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(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build());
|
||||
TechHider.reloadChunks(player, chunksToReload);
|
||||
@ -195,7 +198,7 @@ public class FightTeam implements IFightTeam{
|
||||
|
||||
leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
|
||||
Inventory inventory = leader.getPlayer().getInventory();
|
||||
if (KitManager.getKits(true).size() > 1)
|
||||
if (KitManager.getKits(true).size() > 1 || Config.PersonalKits)
|
||||
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
|
||||
else
|
||||
inventory.setItem(1, new ItemBuilder(Material.AIR).build());
|
||||
@ -349,6 +352,25 @@ public class FightTeam implements IFightTeam{
|
||||
return currentHearts / maximumHearts;
|
||||
}
|
||||
|
||||
public void loadKits(){
|
||||
for(FightPlayer fightPlayer : players) {
|
||||
if(fightPlayer.getPlayer() == null)
|
||||
continue;
|
||||
fightPlayer.getPlayer().getInventory().clear();
|
||||
|
||||
PersonalKit personalKit = null;
|
||||
if(Config.PersonalKits)
|
||||
personalKit = PersonalKit.get(SteamwarUser.get(fightPlayer.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
|
||||
if(personalKit != null){
|
||||
PlayerInventory inventory = fightPlayer.getPlayer().getInventory();
|
||||
inventory.setContents(personalKit.getInventory());
|
||||
inventory.setArmorContents(personalKit.getArmor());
|
||||
}else if(fightPlayer.getKit() != null)
|
||||
fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
void replaceSync(boolean replace, Material target, Material replacement) {
|
||||
if(!replace)
|
||||
return;
|
||||
|
@ -2,6 +2,7 @@ package de.steamwar.fightsystem.listener;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.PersonalKitCreator;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -42,12 +43,14 @@ public class FreezeWorldStateListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
event.setCancelled(true);
|
||||
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -0,0 +1,94 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
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.GameMode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PersonalKitCreator implements Listener {
|
||||
|
||||
private static final Map<Player, PersonalKitCreator> openKitCreators = new HashMap<>();
|
||||
|
||||
private final Player player;
|
||||
private final SteamwarUser user;
|
||||
private final ItemStack[] contents;
|
||||
private final ItemStack[] armor;
|
||||
|
||||
public PersonalKitCreator(Player player){
|
||||
this.player = player;
|
||||
contents = player.getInventory().getContents();
|
||||
armor = player.getInventory().getArmorContents();
|
||||
user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB());
|
||||
if(kit == null){
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||
assert fightPlayer != null;
|
||||
fightPlayer.getKit().loadToPlayer(player);
|
||||
}else{
|
||||
player.getInventory().setContents(kit.getInventory());
|
||||
player.getInventory().setArmorContents(kit.getArmor());
|
||||
}
|
||||
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
|
||||
openKitCreators.put(player, this);
|
||||
}
|
||||
|
||||
public static void closeAll(){
|
||||
for(PersonalKitCreator creator : openKitCreators.values()){
|
||||
creator.player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inKitCreator(HumanEntity player){
|
||||
return openKitCreators.containsKey(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e){
|
||||
if(e.getCursor() != null && Config.ForbiddenItems.contains(e.getCursor().getType().name()))
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMoveEvent(PlayerMoveEvent e){
|
||||
if(!player.equals(e.getPlayer()))
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if(!player.equals(e.getPlayer()))
|
||||
return;
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
private void close(){
|
||||
PersonalKit.save(user.getId(), Config.SchematicType.toDB(), player.getInventory().getContents(), player.getInventory().getArmorContents());
|
||||
player.getInventory().setContents(contents);
|
||||
player.getInventory().setArmorContents(armor);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
HandlerList.unregisterAll(this);
|
||||
openKitCreators.remove(player);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren