Merge branch 'master' into recordSystem
Dieser Commit ist enthalten in:
Commit
b24a8636da
@ -76,6 +76,8 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new TestListener();
|
new TestListener();
|
||||||
new NormalJoinListener();
|
new NormalJoinListener();
|
||||||
new RankedJoinListener();
|
new RankedJoinListener();
|
||||||
|
new SleepListener();
|
||||||
|
new PersonalKitCreator();
|
||||||
if(Core.getVersion() > 8)
|
if(Core.getVersion() > 8)
|
||||||
new ExtendedInventoryListener();
|
new ExtendedInventoryListener();
|
||||||
|
|
||||||
@ -157,7 +159,6 @@ 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();
|
|
||||||
Fight.getBlueTeam().loadKits();
|
Fight.getBlueTeam().loadKits();
|
||||||
Fight.getRedTeam().loadKits();
|
Fight.getRedTeam().loadKits();
|
||||||
setAllPlayersGM(GameMode.SURVIVAL);
|
setAllPlayersGM(GameMode.SURVIVAL);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
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.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
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.Config;
|
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||||
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;
|
||||||
@ -78,7 +78,7 @@ public class GUI {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(Config.PersonalKits){
|
if(Config.PersonalKits){
|
||||||
new PersonalKitCreator(p);
|
PersonalKitCreator.openKitCreator(p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,13 +101,19 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SWInventory inv = new SWInventory(p, 9, Config.GameName + "-Auswahl");
|
SWInventory inv = new SWInventory(p, 9, Config.GameName + "-Auswahl");
|
||||||
inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> schemDialog(p, true));
|
inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> {
|
||||||
|
p.closeInventory();
|
||||||
|
schemDialog(p, true);
|
||||||
|
});
|
||||||
if(Fight.getMaxRank() == 0){
|
if(Fight.getMaxRank() == 0){
|
||||||
inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{});
|
inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{});
|
||||||
}else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){
|
}else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){
|
||||||
inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{});
|
inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{});
|
||||||
}else{
|
}else{
|
||||||
inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false));
|
inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> {
|
||||||
|
p.closeInventory();
|
||||||
|
schemDialog(p, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
||||||
inv.open();
|
inv.open();
|
||||||
|
@ -5,13 +5,12 @@ import de.steamwar.fightsystem.commands.GUI;
|
|||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Kit {
|
public class Kit {
|
||||||
|
|
||||||
@ -74,20 +73,41 @@ public class Kit {
|
|||||||
return enterStage;
|
return enterStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStackInKit(ItemStack stack){
|
public boolean isEnchantmentInKit(ItemStack stack){
|
||||||
for(ItemStack is : inventory){
|
for(ItemStack is : inventory){
|
||||||
if(stack.equals(is))
|
if(similar(stack, is))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(armor != null){
|
if(armor != null){
|
||||||
for(ItemStack is : armor){
|
for(ItemStack is : armor){
|
||||||
if(stack.equals(is))
|
if(similar(stack, is))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean similar(ItemStack stack, ItemStack stack2){
|
||||||
|
if(stack == null || stack2 == null)
|
||||||
|
return false;
|
||||||
|
if(stack.getType() != stack2.getType())
|
||||||
|
return false;
|
||||||
|
if(stack.hasItemMeta() != stack2.hasItemMeta())
|
||||||
|
return false;
|
||||||
|
if(stack.getItemMeta() == null || stack2.getItemMeta() == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
//Enchantment Map comparison used for default similarity check does not work
|
||||||
|
Map<Enchantment, Integer> en = stack.getItemMeta().getEnchants();
|
||||||
|
Map<Enchantment, Integer> en2 = new HashMap<>(stack.getItemMeta().getEnchants());
|
||||||
|
|
||||||
|
for(Map.Entry<Enchantment, Integer> e : en.entrySet()){
|
||||||
|
if(!en2.remove(e.getKey(), e.getValue()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return en2.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadToPlayer(Player player) {
|
public void loadToPlayer(Player player) {
|
||||||
player.getInventory().setContents(inventory);
|
player.getInventory().setContents(inventory);
|
||||||
if(armor != null)
|
if(armor != null)
|
||||||
|
@ -3,6 +3,7 @@ package de.steamwar.fightsystem.listener;
|
|||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@ -22,4 +23,9 @@ public class FoodLevelChangeListener extends BasicListener {
|
|||||||
public void onWeatherChange(WeatherChangeEvent event){
|
public void onWeatherChange(WeatherChangeEvent event){
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawnerSpawn(SpawnerSpawnEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ 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;
|
||||||
|
@ -22,44 +22,49 @@ public class HotbarGUIListener extends BasicListener {
|
|||||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if(event.getItem() != null) {
|
if(!PersonalKitCreator.notInKitCreator(player))
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
return;
|
||||||
if(fightTeam == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
if(event.getItem() == null)
|
||||||
ItemMeta itemMeta = event.getItem().getItemMeta();
|
return;
|
||||||
String displayName = itemMeta.getDisplayName();
|
|
||||||
|
|
||||||
if(displayName == null)
|
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||||
return;
|
if(fightTeam == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if(displayName.equals("§e" + Config.GameName + " wählen")){
|
event.setCancelled(true);
|
||||||
GUI.preSchemDialog(player);
|
ItemMeta itemMeta = event.getItem().getItemMeta();
|
||||||
return;
|
String displayName = itemMeta.getDisplayName();
|
||||||
}
|
|
||||||
|
if(displayName == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(displayName.equals("§e" + Config.GameName + " wählen")){
|
||||||
|
GUI.preSchemDialog(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (displayName) {
|
||||||
|
case "§cSpieler rauswerfen":
|
||||||
|
GUI.chooseRemove(player);
|
||||||
|
break;
|
||||||
|
case "§eSpieler einladen":
|
||||||
|
GUI.chooseInvitation(player);
|
||||||
|
break;
|
||||||
|
case "§cNicht bereit":
|
||||||
|
fightTeam.setReady(true);
|
||||||
|
break;
|
||||||
|
case "§aBereit":
|
||||||
|
fightTeam.setReady(false);
|
||||||
|
break;
|
||||||
|
case "§eKit bearbeiten":
|
||||||
|
case "§eKit wählen":
|
||||||
|
GUI.kitSelection(player);
|
||||||
|
break;
|
||||||
|
case "§eRespawn":
|
||||||
|
player.teleport(fightTeam.getSpawn());
|
||||||
|
break;
|
||||||
|
|
||||||
switch (displayName) {
|
|
||||||
case "§cSpieler rauswerfen":
|
|
||||||
GUI.chooseRemove(player);
|
|
||||||
break;
|
|
||||||
case "§eSpieler einladen":
|
|
||||||
GUI.chooseInvitation(player);
|
|
||||||
break;
|
|
||||||
case "§cNicht bereit":
|
|
||||||
fightTeam.setReady(true);
|
|
||||||
break;
|
|
||||||
case "§aBereit":
|
|
||||||
fightTeam.setReady(false);
|
|
||||||
break;
|
|
||||||
case "§eKit bearbeiten":
|
|
||||||
case "§eKit wählen":
|
|
||||||
GUI.kitSelection(player);
|
|
||||||
break;
|
|
||||||
case "§eRespawn":
|
|
||||||
player.teleport(fightTeam.getSpawn());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,6 +73,14 @@ public class InFightInventoryListener extends BasicListener {
|
|||||||
Inventory inventory = event.getPlayer().getInventory();
|
Inventory inventory = event.getPlayer().getInventory();
|
||||||
|
|
||||||
Material type = event.getBlock().getType();
|
Material type = event.getBlock().getType();
|
||||||
|
switch(type){
|
||||||
|
case REDSTONE_WIRE:
|
||||||
|
type = Material.REDSTONE;
|
||||||
|
break;
|
||||||
|
case PISTON_HEAD:
|
||||||
|
type = Material.PISTON;
|
||||||
|
break;
|
||||||
|
}
|
||||||
ItemStack itemStack;
|
ItemStack itemStack;
|
||||||
|
|
||||||
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
|
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
|
||||||
|
@ -0,0 +1,187 @@
|
|||||||
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
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.fightsystem.kit.Kit;
|
||||||
|
import de.steamwar.fightsystem.kit.KitManager;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
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.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class PersonalKitCreator extends BasicListener {
|
||||||
|
|
||||||
|
private static final Map<HumanEntity, InventoryBackup> openKitCreators = new HashMap<>();
|
||||||
|
private static final EnumSet<FightState> enabled = Config.PersonalKits ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class);
|
||||||
|
|
||||||
|
public PersonalKitCreator(){
|
||||||
|
super(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openKitCreator(Player player){
|
||||||
|
if(!enabled.contains(FightSystem.getFightState()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
new InventoryBackup(player);
|
||||||
|
|
||||||
|
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||||
|
assert fightPlayer != null;
|
||||||
|
|
||||||
|
PersonalKit kit = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||||
|
if(kit == null){
|
||||||
|
fightPlayer.getKit().loadToPlayer(player);
|
||||||
|
}else{
|
||||||
|
player.getInventory().setContents(kit.getInventory());
|
||||||
|
player.getInventory().setArmorContents(kit.getArmor());
|
||||||
|
}
|
||||||
|
|
||||||
|
player.updateInventory();
|
||||||
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean notInKitCreator(HumanEntity player){
|
||||||
|
return !openKitCreators.containsKey(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable(){
|
||||||
|
while(!openKitCreators.isEmpty()){
|
||||||
|
openKitCreators.values().iterator().next().player.closeInventory();
|
||||||
|
}
|
||||||
|
super.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent e){
|
||||||
|
if(!openKitCreators.containsKey(e.getWhoClicked()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Player player = (Player) e.getWhoClicked();
|
||||||
|
//Deny bad items
|
||||||
|
if(isBadItem(e.getCursor(), player))
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
checkForClear(e, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMoveEvent(PlayerMoveEvent e){
|
||||||
|
if(!openKitCreators.containsKey(e.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClose(InventoryCloseEvent e) {
|
||||||
|
InventoryBackup backup = openKitCreators.get(e.getPlayer());
|
||||||
|
if(backup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
backup.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerExit(PlayerQuitEvent e){
|
||||||
|
InventoryBackup backup = openKitCreators.get(e.getPlayer());
|
||||||
|
if(backup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
backup.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForClear(InventoryClickEvent e, Player player){
|
||||||
|
if(e.getAction() != InventoryAction.PLACE_ALL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack[] items = e.getWhoClicked().getInventory().getContents();
|
||||||
|
for(int i = 0; i < items.length; i++){
|
||||||
|
ItemStack stack = items[i];
|
||||||
|
if(stack != null && i != e.getSlot())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||||
|
assert fightPlayer != null;
|
||||||
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isBadItem(ItemStack stack, Player player){
|
||||||
|
if(stack == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Check for forbidden item
|
||||||
|
if(Config.ForbiddenItems.contains(stack.getType().name()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
//Check for attribute modifiers
|
||||||
|
if(Core.getVersion() >= 14 && stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers()){
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Kit normal = KitManager.getKitByName(Config.MemberDefault);
|
||||||
|
assert normal != null;
|
||||||
|
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InventoryBackup{
|
||||||
|
private final Player player;
|
||||||
|
private final ItemStack[] contents;
|
||||||
|
private final ItemStack[] armor;
|
||||||
|
|
||||||
|
private InventoryBackup(Player player){
|
||||||
|
openKitCreators.put(player, this);
|
||||||
|
this.player = player;
|
||||||
|
this.contents = player.getInventory().getContents();
|
||||||
|
this.armor = player.getInventory().getArmorContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadBackup(){
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
inventory.setContents(contents);
|
||||||
|
inventory.setArmorContents(armor);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(){
|
||||||
|
openKitCreators.remove(player);
|
||||||
|
PersonalKit.save(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
|
||||||
|
loadBackup();
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack[] removeBadItems(ItemStack[] inventory){
|
||||||
|
Kit normal = KitManager.getKitByName(Config.MemberDefault);
|
||||||
|
assert normal != null;
|
||||||
|
|
||||||
|
for(int i = 0; i < inventory.length; i++){
|
||||||
|
if(isBadItem(inventory[i], player))
|
||||||
|
inventory[i] = null;
|
||||||
|
}
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class SleepListener extends BasicListener{
|
||||||
|
|
||||||
|
public SleepListener() {
|
||||||
|
super(EnumSet.allOf(FightState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSleep(PlayerBedEnterEvent e) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -1,135 +0,0 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
|
||||||
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
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.fightsystem.kit.Kit;
|
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
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.InventoryAction;
|
|
||||||
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;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
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(){
|
|
||||||
while(!openKitCreators.isEmpty()){
|
|
||||||
openKitCreators.values().iterator().next().player.closeInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean notInKitCreator(HumanEntity player){
|
|
||||||
return !openKitCreators.containsKey(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClick(InventoryClickEvent e){
|
|
||||||
if(!player.equals(e.getWhoClicked()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Deny bad items
|
|
||||||
if(e.getCursor() != null){
|
|
||||||
ItemStack stack = e.getCursor();
|
|
||||||
if(Config.ForbiddenItems.contains(stack.getType().name())){
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Kit normal = KitManager.getKitByName(Config.MemberDefault);
|
|
||||||
if(!normal.isStackInKit(stack)){
|
|
||||||
if(stack.getEnchantments().size() > 0){
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(Core.getVersion() >= 14 && stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers()){
|
|
||||||
e.setCancelled(true);
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check for clear
|
|
||||||
if(e.getAction() != InventoryAction.PLACE_ALL)
|
|
||||||
return;
|
|
||||||
ItemStack[] items = e.getWhoClicked().getInventory().getContents();
|
|
||||||
for(int i = 0; i < items.length; i++){
|
|
||||||
ItemStack stack = items[i];
|
|
||||||
if(stack != null && i != e.getSlot())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
|
||||||
assert fightPlayer != null;
|
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,7 @@ public class WinconditionPumpkinTechKO extends Wincondition {
|
|||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
private static boolean running = false;
|
||||||
|
|
||||||
public WinconditionPumpkinTechKO(){
|
public WinconditionPumpkinTechKO(){
|
||||||
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
||||||
@ -43,6 +44,9 @@ public class WinconditionPumpkinTechKO extends Wincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void recursiveCheck(){
|
private static void recursiveCheck(){
|
||||||
|
if(running)
|
||||||
|
return;
|
||||||
|
running = true;
|
||||||
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
|
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
|
||||||
Config.TeamRedCornerY,
|
Config.TeamRedCornerY,
|
||||||
Config.TeamRedCornerZ,
|
Config.TeamRedCornerZ,
|
||||||
@ -58,6 +62,7 @@ public class WinconditionPumpkinTechKO extends Wincondition {
|
|||||||
|
|
||||||
checkKO(Fight.getRedTeam(), teamRedPumpkins);
|
checkKO(Fight.getRedTeam(), teamRedPumpkins);
|
||||||
checkKO(Fight.getBlueTeam(), teamBluePumpkins);
|
checkKO(Fight.getBlueTeam(), teamBluePumpkins);
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
||||||
|
@ -61,6 +61,7 @@ public class WinconditionRelativePercent extends Wincondition{
|
|||||||
private final FightTeam team;
|
private final FightTeam team;
|
||||||
private final int blockCount;
|
private final int blockCount;
|
||||||
private final BukkitTask task;
|
private final BukkitTask task;
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
private int currentBlocks;
|
private int currentBlocks;
|
||||||
|
|
||||||
@ -70,8 +71,12 @@ public class WinconditionRelativePercent extends Wincondition{
|
|||||||
this.currentBlocks = blockCount;
|
this.currentBlocks = blockCount;
|
||||||
|
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
|
||||||
|
if(running)
|
||||||
|
return;
|
||||||
|
running = true;
|
||||||
currentBlocks = currentBlocks();
|
currentBlocks = currentBlocks();
|
||||||
checkPercentDefeat();
|
checkPercentDefeat();
|
||||||
|
running = false;
|
||||||
}, 400, 400);
|
}, 400, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +31,13 @@ public class WinconditionTechKO extends ListenerWincondition {
|
|||||||
private TechKOCountdown smallerZcountdown = null;
|
private TechKOCountdown smallerZcountdown = null;
|
||||||
private TechKOCountdown biggerZcountdown = null;
|
private TechKOCountdown biggerZcountdown = null;
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Works only for z-Axis fight direction for performance reasons
|
* Works only for z-Axis fight direction for performance reasons
|
||||||
*/
|
*/
|
||||||
public WinconditionTechKO(){
|
public WinconditionTechKO(){
|
||||||
super(Config.TechKO, EnumSet.of(FightState.RUNNING, FightState.SPECTATE));
|
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,6 +60,10 @@ public class WinconditionTechKO extends ListenerWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
|
if(running)
|
||||||
|
return;
|
||||||
|
running = true;
|
||||||
|
|
||||||
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
||||||
int id = tnt.getEntityId();
|
int id = tnt.getEntityId();
|
||||||
boolean smallerZ = tnt.getLocation().getZ() < toggle;
|
boolean smallerZ = tnt.getLocation().getZ() < toggle;
|
||||||
@ -87,6 +92,7 @@ public class WinconditionTechKO extends ListenerWincondition {
|
|||||||
|
|
||||||
smallerZtime--;
|
smallerZtime--;
|
||||||
biggerZtime--;
|
biggerZtime--;
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FightTeam smallerTeam(){
|
private FightTeam smallerTeam(){
|
||||||
|
@ -19,6 +19,7 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
public WinconditionWaterTechKO() {
|
public WinconditionWaterTechKO() {
|
||||||
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
||||||
@ -51,6 +52,9 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkTask() {
|
private void checkTask() {
|
||||||
|
if(running)
|
||||||
|
return;
|
||||||
|
running = true;
|
||||||
teamRedWater = calcWater(
|
teamRedWater = calcWater(
|
||||||
Config.TeamRedCornerX,
|
Config.TeamRedCornerX,
|
||||||
Config.TeamRedCornerY,
|
Config.TeamRedCornerY,
|
||||||
@ -68,6 +72,7 @@ public class WinconditionWaterTechKO extends Wincondition {
|
|||||||
|
|
||||||
checkEmpty(Fight.getRedTeam(), teamRedWater);
|
checkEmpty(Fight.getRedTeam(), teamRedWater);
|
||||||
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
|
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren