SteamWar/FightSystem
Archiviert
13
1

personalKit #106

Zusammengeführt
Lixfel hat 5 Commits von personalKit nach master 2020-01-27 06:33:09 +01:00 zusammengeführt
3 geänderte Dateien mit 28 neuen und 12 gelöschten Zeilen
Nur Änderungen aus Commit 0ebc7e5616 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -8,20 +8,22 @@ 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.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
public class PersonalKitCreator implements Listener {
private static final Set<PersonalKitCreator> openKitCreators = new HashSet<>();
private static final Map<Player, PersonalKitCreator> openKitCreators = new HashMap<>();
private final Player player;
private final SteamwarUser user;
@ -45,14 +47,18 @@ public class PersonalKitCreator implements Listener {
}
player.setGameMode(GameMode.CREATIVE);
player.openInventory(player.getInventory());
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
openKitCreators.add(this);
openKitCreators.put(player, this);
}
public static void closeAll(){
for(PersonalKitCreator creator : openKitCreators)
creator.close();
for(PersonalKitCreator creator : openKitCreators.values()){
creator.player.closeInventory();
}
}
public static boolean inKitCreator(HumanEntity player){
return openKitCreators.containsKey(player);
}
@EventHandler
@ -61,6 +67,14 @@ public class PersonalKitCreator implements Listener {
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()))
@ -71,11 +85,10 @@ public class PersonalKitCreator implements Listener {
private void close(){
PersonalKit.save(user.getId(), Config.SchematicType.toDB(), player.getInventory().getContents(), player.getInventory().getArmorContents());
player.closeInventory();
player.getInventory().setContents(contents);
player.getInventory().setArmorContents(armor);
player.setGameMode(GameMode.SURVIVAL);
HandlerList.unregisterAll(this);
openKitCreators.remove(this);
openKitCreators.remove(player);
}
}