SteamWar/FightSystem
Archiviert
13
1

Fixing bugs occured with testing

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-01-23 19:57:21 +01:00
Ursprung 0c21251720
Commit 0ebc7e5616
3 geänderte Dateien mit 28 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -202,7 +202,7 @@ public class FightTeam implements IFightTeam{
leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
Inventory inventory = leader.getPlayer().getInventory(); 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()); inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());
else else
inventory.setItem(1, new ItemBuilder(Material.AIR).build()); 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.Config;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.PersonalKitCreator;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -42,11 +43,13 @@ public class FreezeWorldStateListener extends BasicListener {
@EventHandler @EventHandler
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler @EventHandler
public void onInventoryDrag(InventoryDragEvent event) { public void onInventoryDrag(InventoryDragEvent event) {
if(!PersonalKitCreator.inKitCreator(event.getWhoClicked()))
event.setCancelled(true); event.setCancelled(true);
} }

Datei anzeigen

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