The big refactoring #238
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_10 {
|
public class PersonalKitCreator_10 {
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_12 {
|
public class PersonalKitCreator_12 {
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
@ -44,12 +43,8 @@ class TechHider_12 {
|
|||||||
|
|
||||||
private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4);
|
private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4);
|
||||||
|
|
||||||
static void start(){
|
static PacketAdapter chunkHider(){
|
||||||
chunkHider();
|
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||||
}
|
|
||||||
|
|
||||||
private static void chunkHider(){
|
|
||||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent e) {
|
public void onPacketSending(PacketEvent e) {
|
||||||
PacketContainer packet = e.getPacket();
|
PacketContainer packet = e.getPacket();
|
||||||
@ -123,6 +118,6 @@ class TechHider_12 {
|
|||||||
byteArray.write(0, data);
|
byteArray.write(0, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start(ITechHider.threadMultiplier * 4);
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,8 @@ class FightTeam_14 {
|
|||||||
e.flushSession();
|
e.flushSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
static EditSession pasteSchematic(Schematic schematic, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
static EditSession pasteSchematic(Clipboard clipboard, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
||||||
BlockVector3 paste = BlockVector3.at(pX, pY, pZ);
|
BlockVector3 paste = BlockVector3.at(pX, pY, pZ);
|
||||||
Clipboard clipboard = schematic.load();
|
|
||||||
|
|
||||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||||
BlockVector3 dimensions = clipboard.getDimensions();
|
BlockVector3 dimensions = clipboard.getDimensions();
|
||||||
|
@ -26,14 +26,14 @@ import java.util.HashSet;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_14 {
|
public class PersonalKitCreator_14 {
|
||||||
private PersonalKitCreator_14(){}
|
private PersonalKitCreator_14(){}
|
||||||
|
|
||||||
static boolean hasAttributeModifier(ItemStack stack){
|
public static boolean hasAttributeModifier(ItemStack stack){
|
||||||
return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers();
|
return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
@ -40,12 +39,8 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
|||||||
public class TechHider_14 {
|
public class TechHider_14 {
|
||||||
private TechHider_14(){}
|
private TechHider_14(){}
|
||||||
|
|
||||||
static void start(){
|
static PacketAdapter chunkHider(){
|
||||||
chunkHider();
|
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||||
}
|
|
||||||
|
|
||||||
static void chunkHider(){
|
|
||||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent e) {
|
public void onPacketSending(PacketEvent e) {
|
||||||
PacketContainer packet = e.getPacket();
|
PacketContainer packet = e.getPacket();
|
||||||
@ -146,6 +141,6 @@ public class TechHider_14 {
|
|||||||
byteArray.write(0, data);
|
byteArray.write(0, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start(ITechHider.threadMultiplier * 4);
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_15 {
|
public class PersonalKitCreator_15 {
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
@ -42,15 +41,11 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
|||||||
public class TechHider_15 {
|
public class TechHider_15 {
|
||||||
private TechHider_15(){}
|
private TechHider_15(){}
|
||||||
|
|
||||||
static void start(){
|
static PacketAdapter chunkHider(){
|
||||||
chunkHider();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void chunkHider(){
|
|
||||||
/*
|
/*
|
||||||
* Bevor editing this function read and understand: https://wiki.vg/Chunk_Format
|
* Bevor editing this function read and understand: https://wiki.vg/Chunk_Format
|
||||||
* */
|
* */
|
||||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent e) {
|
public void onPacketSending(PacketEvent e) {
|
||||||
PacketContainer packet = e.getPacket();
|
PacketContainer packet = e.getPacket();
|
||||||
@ -158,7 +153,7 @@ public class TechHider_15 {
|
|||||||
byteArray.write(0, data);
|
byteArray.write(0, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start(ITechHider.threadMultiplier * 4);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class VariableValueArray {
|
private static final class VariableValueArray {
|
||||||
|
@ -87,9 +87,7 @@ class FightTeam_8 {
|
|||||||
e.flushQueue();
|
e.flushQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
static EditSession pasteSchematic(Clipboard clipboard, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
||||||
Clipboard clipboard = schematic.load();
|
|
||||||
|
|
||||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||||
Vector dimensions = clipboard.getDimensions();
|
Vector dimensions = clipboard.getDimensions();
|
||||||
Vector v = new Vector(pasteX, pasteY, pasteZ);
|
Vector v = new Vector(pasteX, pasteY, pasteZ);
|
||||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_8 {
|
public class PersonalKitCreator_8 {
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class PersonalKitCreator_9 {
|
public class PersonalKitCreator_9 {
|
||||||
|
|
||||||
static boolean hasItems(ItemStack stack){
|
public static boolean hasItems(ItemStack stack){
|
||||||
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c());
|
||||||
keys.remove("Enchantments");
|
keys.remove("Enchantments");
|
||||||
keys.remove("Damage");
|
keys.remove("Damage");
|
||||||
|
@ -171,19 +171,19 @@ public class Config {
|
|||||||
PreFightDuration = config.getInt("Times.PreFightDuration");
|
PreFightDuration = config.getInt("Times.PreFightDuration");
|
||||||
SpectatorDuration = config.getInt("Times.SpectatorDuration");
|
SpectatorDuration = config.getInt("Times.SpectatorDuration");
|
||||||
|
|
||||||
int schemsizeX = worldconfig.getInt("Arena.Schemsize.x");
|
int schemsizeX = config.getInt("Arena.Schemsize.x");
|
||||||
int schemsizeY = worldconfig.getInt("Arena.Schemsize.y");
|
int schemsizeY = config.getInt("Arena.Schemsize.y");
|
||||||
int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z");
|
int schemsizeZ = config.getInt("Arena.Schemsize.z");
|
||||||
int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x");
|
int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x");
|
||||||
int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y");
|
int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y");
|
||||||
int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z");
|
int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z");
|
||||||
TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x");
|
TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x");
|
||||||
TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y");
|
TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y");
|
||||||
TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z");
|
TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z");
|
||||||
Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x");
|
Schem2BorderX = config.getInt("Arena.Schem2Border.x");
|
||||||
Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z");
|
Schem2BorderZ = config.getInt("Arena.Schem2Border.z");
|
||||||
underArenaBorder = worldconfig.getInt("Arena.underArenaBorder");
|
underArenaBorder = worldconfig.getInt("Arena.underArenaBorder");
|
||||||
BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic");
|
BorderFromSchematic = config.getInt("Arena.BorderFromSchematic");
|
||||||
AlignWater = worldconfig.getBoolean("Arena.AlignWater");
|
AlignWater = worldconfig.getBoolean("Arena.AlignWater");
|
||||||
WaterDepth = worldconfig.getInt("Arena.WaterDepth");
|
WaterDepth = worldconfig.getInt("Arena.WaterDepth");
|
||||||
GroundWalkable = config.getBoolean("Arena.GroundWalkable");
|
GroundWalkable = config.getBoolean("Arena.GroundWalkable");
|
||||||
@ -417,6 +417,9 @@ public class Config {
|
|||||||
public static boolean check(){
|
public static boolean check(){
|
||||||
return CheckSchemID != 0;
|
return CheckSchemID != 0;
|
||||||
}
|
}
|
||||||
|
public static boolean fixedTeams(){
|
||||||
|
return event() || Ranked;
|
||||||
|
}
|
||||||
public static boolean recording(){
|
public static boolean recording(){
|
||||||
return event();
|
return event();
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ import de.steamwar.fightsystem.countdown.*;
|
|||||||
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.KitManager;
|
|
||||||
import de.steamwar.fightsystem.listener.*;
|
import de.steamwar.fightsystem.listener.*;
|
||||||
import de.steamwar.fightsystem.record.RecordSystem;
|
import de.steamwar.fightsystem.record.RecordSystem;
|
||||||
import de.steamwar.fightsystem.record.Recorder;
|
import de.steamwar.fightsystem.record.Recorder;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.utils.EnterHandler;
|
||||||
import de.steamwar.fightsystem.utils.*;
|
import de.steamwar.fightsystem.utils.FightStatistics;
|
||||||
|
import de.steamwar.fightsystem.utils.TechHider;
|
||||||
import de.steamwar.fightsystem.winconditions.*;
|
import de.steamwar.fightsystem.winconditions.*;
|
||||||
import de.steamwar.sql.EventFight;
|
import de.steamwar.sql.EventFight;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
@ -41,9 +41,6 @@ import org.bukkit.GameMode;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class FightSystem extends JavaPlugin {
|
public class FightSystem extends JavaPlugin {
|
||||||
@ -51,36 +48,19 @@ public class FightSystem extends JavaPlugin {
|
|||||||
public static final String PREFIX = "§eArena§8» ";
|
public static final String PREFIX = "§eArena§8» ";
|
||||||
private static FightSystem plugin;
|
private static FightSystem plugin;
|
||||||
|
|
||||||
private static FightState fightState = FightState.PRE_LEADER_SETUP;
|
|
||||||
private static Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
|
|
||||||
private static int fightTime = 0;
|
|
||||||
private static Countdown mainCountdown;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
setPlugin(this);
|
plugin = this;
|
||||||
IFightSystem.init(this);
|
IFightSystem.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Fight.init();
|
Fight.init();
|
||||||
KitManager.loadAllKits();
|
|
||||||
TechHider.init();
|
|
||||||
FightScoreboard.init();
|
|
||||||
RecordSystem.init();
|
RecordSystem.init();
|
||||||
|
|
||||||
try {
|
|
||||||
CommandRemover.removeAll("gamemode");
|
|
||||||
CommandInjector.injectCommand(new GamemodeCommand());
|
|
||||||
} catch (Exception e) {
|
|
||||||
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
|
|
||||||
Bukkit.shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new EntityDamageListener();
|
new EntityDamageListener();
|
||||||
new EntityExplodeListener();
|
new WaterRemover();
|
||||||
new FoodLevelChangeListener();
|
new FoodLevelChangeListener();
|
||||||
new PistonListener();
|
new PistonListener();
|
||||||
new PlayerChatListener();
|
new PlayerChatListener();
|
||||||
@ -105,6 +85,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new VersionDependentListener();
|
new VersionDependentListener();
|
||||||
|
|
||||||
new EnterHandler();
|
new EnterHandler();
|
||||||
|
new TechHider();
|
||||||
|
|
||||||
new WinconditionAllDead();
|
new WinconditionAllDead();
|
||||||
new WinconditionCaptainDead();
|
new WinconditionCaptainDead();
|
||||||
@ -116,40 +97,44 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new WinconditionTimeout();
|
new WinconditionTimeout();
|
||||||
new WinconditionHeartRatioTimeout();
|
new WinconditionHeartRatioTimeout();
|
||||||
new WinconditionTechKO();
|
new WinconditionTechKO();
|
||||||
|
new EventTeamOffWincondition();
|
||||||
|
|
||||||
Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand());
|
new NoPlayersOnlineCountdown();
|
||||||
Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand());
|
new PreSchemPasteCountdown();
|
||||||
Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand());
|
new SetupOverCountdown();
|
||||||
Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand());
|
new PreRunningCountdown();
|
||||||
Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand());
|
new SpectateOverCountdown();
|
||||||
Objects.requireNonNull(getCommand("invite")).setExecutor(new InviteCommand());
|
|
||||||
Objects.requireNonNull(getCommand("ready")).setExecutor(new ReadyCommand());
|
|
||||||
Objects.requireNonNull(getCommand("ak")).setExecutor(new AkCommand());
|
|
||||||
Objects.requireNonNull(getCommand("leader")).setExecutor(new LeaderCommand());
|
|
||||||
Objects.requireNonNull(getCommand("lockschem")).setExecutor(new LockschemCommand());
|
|
||||||
|
|
||||||
mainCountdown = new NoPlayersOnlineCountdown();
|
new LeaveCommand();
|
||||||
fightTime = Config.TimeoutTime;
|
new KitCommand();
|
||||||
|
new RemoveCommand();
|
||||||
|
new AcceptCommand();
|
||||||
|
new DeclineCommand();
|
||||||
|
new InviteCommand();
|
||||||
|
new ReadyCommand();
|
||||||
|
new AkCommand();
|
||||||
|
new LeaderCommand();
|
||||||
|
new LockschemCommand();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CommandRemover.removeAll("gamemode");
|
||||||
|
CommandInjector.injectCommand(new GamemodeCommand());
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
|
||||||
|
Bukkit.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(Config.event() || Config.Ranked) {
|
if(Config.event() || Config.Ranked) {
|
||||||
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
|
|
||||||
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
|
|
||||||
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
|
|
||||||
Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand());
|
|
||||||
|
|
||||||
setPreSchemState();
|
setPreSchemState();
|
||||||
}else if(Config.test()){
|
}else if(Config.test()){
|
||||||
if(Config.check()){
|
if(Config.check()){
|
||||||
Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0);
|
Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
|
||||||
}else{
|
|
||||||
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
|
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
|
|
||||||
|
|
||||||
setPreSchemState();
|
setPreSchemState();
|
||||||
setPostSchemState();
|
Bukkit.getScheduler().runTaskLater(this, FightSystem::setPostSchemState, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -158,63 +143,36 @@ public class FightSystem extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setPreSchemState() {
|
public static void setPreSchemState() {
|
||||||
if(fightState != FightState.PRE_LEADER_SETUP)
|
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
||||||
throw new SecurityException(fightState.name());
|
|
||||||
setFightState(FightState.PRE_SCHEM_SETUP);
|
|
||||||
|
|
||||||
Fight.calcAvailibleSchemTypes();
|
|
||||||
mainCountdown = new PreSchemPasteCountdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPostSchemState() {
|
public static void setPostSchemState() {
|
||||||
if(fightState != FightState.PRE_SCHEM_SETUP)
|
FightState.setFightState(FightState.POST_SCHEM_SETUP);
|
||||||
throw new SecurityException(fightState.name());
|
|
||||||
setFightState(FightState.POST_SCHEM_SETUP);
|
|
||||||
|
|
||||||
TechHider.start();
|
Fight.getBlueTeam().pasteSchematic();
|
||||||
if(!Config.test()){
|
Fight.getRedTeam().pasteSchematic();
|
||||||
Fight.getBlueTeam().pasteSchematic();
|
|
||||||
Fight.getRedTeam().pasteSchematic();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Config.test())
|
|
||||||
mainCountdown = null;
|
|
||||||
else
|
|
||||||
mainCountdown = new SetupOverCountdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPreRunningState() {
|
public static void setPreRunningState() {
|
||||||
if(fightState != FightState.POST_SCHEM_SETUP)
|
FightState.setFightState(FightState.PRE_RUNNING);
|
||||||
throw new SecurityException(fightState.name());
|
|
||||||
setFightState(FightState.PRE_RUNNING);
|
|
||||||
|
|
||||||
Fight.getBlueTeam().loadKits();
|
Fight.getBlueTeam().loadKits();
|
||||||
Fight.getRedTeam().loadKits();
|
Fight.getRedTeam().loadKits();
|
||||||
setAllPlayersGM(GameMode.SURVIVAL);
|
setAllPlayersGM(GameMode.SURVIVAL);
|
||||||
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
||||||
|
|
||||||
mainCountdown = new PreRunningCountdown();
|
|
||||||
|
|
||||||
Fight.replaceSync();
|
Fight.replaceSync();
|
||||||
|
|
||||||
if(Config.event())
|
|
||||||
new EventTeamOffWincondition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRunningState() {
|
public static void setRunningState() {
|
||||||
if(fightState != FightState.PRE_RUNNING)
|
FightState.setFightState(FightState.RUNNING);
|
||||||
throw new SecurityException(fightState.name());
|
|
||||||
setFightState(FightState.RUNNING);
|
|
||||||
setAllPlayersGM(GameMode.SURVIVAL);
|
|
||||||
|
|
||||||
FightStatistics.start();
|
FightStatistics.start();
|
||||||
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
|
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
|
||||||
if(fightState == FightState.SPECTATE)
|
FightState.setFightState(FightState.SPECTATE);
|
||||||
return;
|
|
||||||
setFightState(FightState.SPECTATE);
|
|
||||||
|
|
||||||
setAllPlayersGM(GameMode.SPECTATOR);
|
setAllPlayersGM(GameMode.SPECTATOR);
|
||||||
Fight.getBlueTeam().teleportToSpawn();
|
Fight.getBlueTeam().teleportToSpawn();
|
||||||
@ -239,15 +197,10 @@ public class FightSystem extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!Config.test()){
|
if(!Config.test()){
|
||||||
new SpectateOverCountdown();
|
|
||||||
FightStatistics.saveStats(winFightTeam, windescription);
|
FightStatistics.saveStats(winFightTeam, windescription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFightTime(int fightTime) {
|
|
||||||
FightSystem.fightTime = fightTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setEventLeiter(Player el){
|
public static void setEventLeiter(Player el){
|
||||||
IFightSystem.setEventLeiter(el);
|
IFightSystem.setEventLeiter(el);
|
||||||
}
|
}
|
||||||
@ -260,35 +213,14 @@ public class FightSystem extends JavaPlugin {
|
|||||||
return IFightSystem.getEventFight();
|
return IFightSystem.getEventFight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setPlugin(FightSystem pl){
|
|
||||||
plugin = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FightSystem getPlugin() {
|
public static FightSystem getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FightState getFightState() {
|
|
||||||
return fightState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getFightTime() {
|
|
||||||
return fightTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shutdown(String reason){
|
public static void shutdown(String reason){
|
||||||
IFightSystem.shutdown(reason);
|
IFightSystem.shutdown(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerStateDependent(StateDependent stateDependent){
|
|
||||||
if(stateDependent.enabled().isEmpty())
|
|
||||||
return;
|
|
||||||
boolean enabled = stateDependent.enabled().contains(fightState);
|
|
||||||
stateDependentFeatures.put(stateDependent, enabled);
|
|
||||||
if(enabled)
|
|
||||||
stateDependent.enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setAllPlayersGM(GameMode gm) {
|
private static void setAllPlayersGM(GameMode gm) {
|
||||||
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
|
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
|
||||||
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm);
|
||||||
@ -298,32 +230,4 @@ public class FightSystem extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setFightState(FightState state){
|
|
||||||
fightState = state;
|
|
||||||
if(mainCountdown != null){
|
|
||||||
mainCountdown.disable();
|
|
||||||
mainCountdown = null;
|
|
||||||
}
|
|
||||||
postStateChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void postStateChange(){
|
|
||||||
for(Map.Entry<StateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
|
|
||||||
//Enable feature if should be enabled and currently disabled
|
|
||||||
if(feature.getKey().enabled().contains(fightState)){
|
|
||||||
if(!feature.getValue()){
|
|
||||||
feature.getKey().enable();
|
|
||||||
feature.setValue(true);
|
|
||||||
}
|
|
||||||
feature.getKey().stateChange(fightState);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Disable feature if should be disabled and currently enabled
|
|
||||||
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
|
|
||||||
feature.getKey().disable();
|
|
||||||
feature.setValue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class AcceptCommand implements CommandExecutor {
|
public class AcceptCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public AcceptCommand() {
|
||||||
|
super(!Config.fixedTeams(), FightState.SETUP, "accept");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -19,211 +19,34 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.fightsystem.fight.Kit;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.sql.UserGroup;
|
import de.steamwar.sql.UserGroup;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class AkCommand extends BasicCommand {
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AkCommand implements CommandExecutor {
|
public AkCommand() {
|
||||||
|
super(Config.test(), FightState.ALL, "ak");
|
||||||
private static final String SCHEMLIST_COMMAND = "/ak schemlist ";
|
}
|
||||||
private static final int FILES_PER_PAGE = 15;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
switch(args.length){
|
if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){
|
||||||
case 1:
|
Commands.sendHelp(player);
|
||||||
if(args[0].equalsIgnoreCase("schem") || args[0].equalsIgnoreCase("schemlist")){
|
return false;
|
||||||
|
|
||||||
//TEXT COMPONENTS
|
|
||||||
TextComponent publicList = new TextComponent("PUBLIC");
|
|
||||||
publicList.setColor(ChatColor.YELLOW);
|
|
||||||
publicList.setBold(true);
|
|
||||||
publicList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePublic Liste...").create()));
|
|
||||||
publicList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist public"));
|
|
||||||
|
|
||||||
TextComponent privateList = new TextComponent("PRIVATE");
|
|
||||||
privateList.setColor(ChatColor.YELLOW);
|
|
||||||
privateList.setBold(true);
|
|
||||||
privateList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePrivate Liste...").create()));
|
|
||||||
privateList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist 0"));
|
|
||||||
//TEXT COMPONENTS
|
|
||||||
|
|
||||||
player.spigot().sendMessage(publicList);
|
|
||||||
player.spigot().sendMessage(privateList);
|
|
||||||
}else
|
|
||||||
Commands.sendHelp(player);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if(args[0].equalsIgnoreCase("addkit")){
|
|
||||||
if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){
|
|
||||||
Commands.sendHelp(player);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
KitManager.saveInventory(args[1], player);
|
|
||||||
} else if(args[0].equalsIgnoreCase("schemlist") && FightSystem.getFightState() == FightState.PRE_SCHEM_SETUP) {
|
|
||||||
try {
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam != null && fightTeam.getFightPlayer(player).isLeader()) {
|
|
||||||
if(args[1].equalsIgnoreCase("public")) {
|
|
||||||
sendPlayerSchematicList(true, 0, player, Config.SchematicType);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
int page;
|
|
||||||
page = Integer.parseInt(args[1]);
|
|
||||||
sendPlayerSchematicList(false, page, player, Config.SchematicType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDu musst eine Seitenzahl angeben!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
Commands.sendHelp(player);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if(args[0].equalsIgnoreCase("schem")) {
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam == null) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDu bist in keinem Team!");
|
|
||||||
return false;
|
|
||||||
}else if(fightTeam.hasSchematic()) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDie Schematic ist bereits gewählt!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Schematic schem;
|
|
||||||
if(args[2].equalsIgnoreCase("public")) {
|
|
||||||
schem = Schematic.getSchemFromDB(args[1], SteamwarUser.get(0).getUUID());
|
|
||||||
} else if(args[2].equalsIgnoreCase("private")) {
|
|
||||||
schem = Schematic.getSchemFromDB(args[1], player.getUniqueId());
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
if(schem == null) {
|
|
||||||
schem = Schematic.getSchemFromDB(args[1], 0);
|
|
||||||
if(schem == null){
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic gibt es nicht!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(schem.getSchemType() != Config.SchematicType) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic ist kein " + Config.GameName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fightTeam.setSchematic(schem);
|
|
||||||
}else
|
|
||||||
Commands.sendHelp(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Commands.sendHelp(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kit.createKit(args[0], player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPlayerSchematicList(boolean publicSchematics, int currentPage, Player player, SchematicType schematicType) {
|
|
||||||
List<Schematic> preSchematicList;
|
|
||||||
List<Schematic> schematicList = new ArrayList<>();
|
|
||||||
if(publicSchematics) {
|
|
||||||
preSchematicList = Schematic.getSchemsAccessibleByUser(0);
|
|
||||||
} else {
|
|
||||||
preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Schematic s : preSchematicList) {
|
|
||||||
if(s.getSchemType() == schematicType)
|
|
||||||
schematicList.add(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(schematicList.isEmpty()) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDu hast noch keine Schematic(s)!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pages;
|
|
||||||
|
|
||||||
double doublePages = (double) schematicList.size() / (double) FILES_PER_PAGE;
|
|
||||||
int intPages = schematicList.size() / FILES_PER_PAGE;
|
|
||||||
|
|
||||||
if(schematicList.size() <= FILES_PER_PAGE) {
|
|
||||||
pages = 1;
|
|
||||||
} else if(doublePages > intPages) {
|
|
||||||
pages = (intPages + 1);
|
|
||||||
} else
|
|
||||||
pages = intPages;
|
|
||||||
|
|
||||||
if(currentPage >= pages) return;
|
|
||||||
|
|
||||||
player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======");
|
|
||||||
|
|
||||||
for(int i = currentPage * FILES_PER_PAGE; i < (currentPage * FILES_PER_PAGE) + FILES_PER_PAGE; i++) {
|
|
||||||
if(schematicList.size() <= i) break;
|
|
||||||
|
|
||||||
Schematic schem = schematicList.get(i);
|
|
||||||
|
|
||||||
TextComponent schematics = new TextComponent("§b" + schem.getSchemName());
|
|
||||||
schematics.setBold(true);
|
|
||||||
|
|
||||||
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic benutzen...").create()));
|
|
||||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schem " + schem.getSchemName() + (publicSchematics ? " public" : " private")));
|
|
||||||
|
|
||||||
player.spigot().sendMessage(schematics);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pages <= 1) return;
|
|
||||||
|
|
||||||
if(currentPage == 0) {
|
|
||||||
TextComponent nextPage = new TextComponent("Nächste Seite >>");
|
|
||||||
nextPage.setColor(ChatColor.RED);
|
|
||||||
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
|
|
||||||
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + "1"));
|
|
||||||
player.spigot().sendMessage(nextPage);
|
|
||||||
} else if((currentPage + 1) == pages) {
|
|
||||||
TextComponent beforePage = new TextComponent("<< Vorherige Seite");
|
|
||||||
beforePage.setColor(ChatColor.RED);
|
|
||||||
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
|
|
||||||
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1)));
|
|
||||||
player.spigot().sendMessage(beforePage);
|
|
||||||
} else {
|
|
||||||
TextComponent beforePage = new TextComponent("<< Seite ");
|
|
||||||
beforePage.setColor(ChatColor.RED);
|
|
||||||
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
|
|
||||||
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1)));
|
|
||||||
|
|
||||||
TextComponent nextPage = new TextComponent(">>");
|
|
||||||
nextPage.setColor(ChatColor.RED);
|
|
||||||
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
|
|
||||||
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage + 1)));
|
|
||||||
|
|
||||||
beforePage.addExtra(nextPage);
|
|
||||||
player.spigot().sendMessage(beforePage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public abstract class BasicCommand implements CommandExecutor, StateDependent {
|
||||||
|
|
||||||
|
private final Set<FightState> enabled;
|
||||||
|
private final PluginCommand command;
|
||||||
|
|
||||||
|
protected BasicCommand(boolean condition, Set<FightState> enabled, String name){
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.command = FightSystem.getPlugin().getCommand(name);
|
||||||
|
assert command != null;
|
||||||
|
disable();
|
||||||
|
|
||||||
|
if(condition)
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
command.setExecutor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
command.setExecutor(new UnavailableCommand());
|
||||||
|
}
|
||||||
|
}
|
@ -19,12 +19,15 @@
|
|||||||
|
|
||||||
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.fight.Kit;
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -36,7 +39,7 @@ public class Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean checkSetup(Player p){
|
static boolean checkSetup(Player p){
|
||||||
if(!FightSystem.getFightState().setup()){
|
if(!FightState.setup()){
|
||||||
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
|
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -201,14 +204,21 @@ public class Commands {
|
|||||||
if(fightPlayer == null)
|
if(fightPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Kit k = KitManager.getKitByName(kitName);
|
Kit k = null;
|
||||||
|
if(Config.PersonalKits){
|
||||||
|
PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName);
|
||||||
|
if(kit != null)
|
||||||
|
kit.setInUse();
|
||||||
|
}else{
|
||||||
|
k = Kit.getKitByName(kitName);
|
||||||
|
}
|
||||||
|
|
||||||
if(k == null){
|
if(k == null){
|
||||||
p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!");
|
p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((fightPlayer.isLeader() && !k.isLeaderAllowed()) ||
|
if(!k.canUseKit(fightPlayer.isLeader())){
|
||||||
(!fightPlayer.isLeader() && !k.isMemberAllowed())){
|
|
||||||
p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!");
|
p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -227,7 +237,6 @@ public class Commands {
|
|||||||
p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams");
|
p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams");
|
||||||
}else{
|
}else{
|
||||||
if(fightPlayer.isLeader()){
|
if(fightPlayer.isLeader()){
|
||||||
p.sendMessage("§8/§eak schem §8<§eSchematic§8> - §7Setze deine Schematic");
|
|
||||||
p.sendMessage("§8/§eready §8- §7Setzt das eigene Team auf bereit");
|
p.sendMessage("§8/§eready §8- §7Setzt das eigene Team auf bereit");
|
||||||
p.sendMessage("§8/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein");
|
p.sendMessage("§8/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein");
|
||||||
p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team");
|
p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team");
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class DeclineCommand implements CommandExecutor {
|
public class DeclineCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public DeclineCommand() {
|
||||||
|
super(!Config.fixedTeams(), FightState.SETUP, "decline");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -24,13 +24,14 @@ 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.fight.Kit;
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
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;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -91,30 +92,59 @@ public class GUI {
|
|||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void kitSelection(Player p){
|
public static void kitSelection(Player p, String query){
|
||||||
FightPlayer fightPlayer = Fight.getFightPlayer(p);
|
FightPlayer fightPlayer = Fight.getFightPlayer(p);
|
||||||
if(fightPlayer == null)
|
if(fightPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
List<SWListInv.SWListEntry<Kit>> entries = new ArrayList<>();
|
||||||
|
|
||||||
if(Config.PersonalKits){
|
if(Config.PersonalKits){
|
||||||
PersonalKitCreator.openKitSelector(p, "");
|
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||||
return;
|
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), new Kit(kit))));
|
||||||
|
}else{
|
||||||
|
List<Kit> kitList = Kit.getAvailableKits(fightPlayer.isLeader());
|
||||||
|
for(Kit k : kitList){
|
||||||
|
entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, k.leaderExclusive(), null), k));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SWListInv.SWListEntry<Kit>> iconList = new ArrayList<>();
|
entries.removeIf(entry -> !entry.getObject().getName().toLowerCase().contains(query.toLowerCase()));
|
||||||
|
|
||||||
List<Kit> kitList = KitManager.getKits(fightPlayer.isLeader());
|
SWListInv<Kit> inv = new SWListInv<>(p, "Kitauswahl", false, entries, (clickType, kit) -> kit.preview(p));
|
||||||
for(Kit k : kitList){
|
|
||||||
iconList.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, !k.isMemberAllowed(), null), k));
|
|
||||||
}
|
|
||||||
|
|
||||||
SWListInv<Kit> inv = new SWListInv<>(p, "Kitauswahl", iconList, (ClickType click, Kit k) -> k.preview(p));
|
|
||||||
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
||||||
|
if(entries.isEmpty()) {
|
||||||
|
inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden"));
|
||||||
|
}
|
||||||
|
if(Config.PersonalKits){
|
||||||
|
inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> {
|
||||||
|
SWAnvilInv anvilInv = new SWAnvilInv(p, "Kitname eingeben");
|
||||||
|
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
|
||||||
|
anvilInv.setCallback(s -> {
|
||||||
|
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
|
||||||
|
if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) {
|
||||||
|
p.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!");
|
||||||
|
p.closeInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Kit prototype = Kit.getAvailableKits(Fight.getFightPlayer(p).isLeader()).get(0);
|
||||||
|
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
|
||||||
|
PersonalKitCreator.openKitCreator(p, kit);
|
||||||
|
});
|
||||||
|
anvilInv.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> {
|
||||||
|
SWAnvilInv anvilInv = new SWAnvilInv(p, "§eNach Kit suchen");
|
||||||
|
anvilInv.setItem(Material.PAPER);
|
||||||
|
anvilInv.setCallback(s -> kitSelection(p, s));
|
||||||
|
anvilInv.open();
|
||||||
|
});
|
||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void preSchemDialog(Player p){
|
public static void preSchemDialog(Player p){
|
||||||
if(!Config.test() && FightSystem.getFightState() != FightState.PRE_SCHEM_SETUP){
|
if(!Config.test() && FightState.getFightState() != FightState.PRE_SCHEM_SETUP){
|
||||||
p.sendMessage(FightSystem.PREFIX + "§cDu kannst ohne Gegner keine Schematic wählen");
|
p.sendMessage(FightSystem.PREFIX + "§cDu kannst ohne Gegner keine Schematic wählen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -153,7 +183,7 @@ public class GUI {
|
|||||||
FightTeam fightTeam = Fight.getPlayerTeam(p);
|
FightTeam fightTeam = Fight.getPlayerTeam(p);
|
||||||
if(fightTeam == null)
|
if(fightTeam == null)
|
||||||
return;
|
return;
|
||||||
if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
|
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||||
fightTeam.setSchematic(s);
|
fightTeam.setSchematic(s);
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
});
|
});
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class InviteCommand implements CommandExecutor {
|
public class InviteCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public InviteCommand() {
|
||||||
|
super(!Config.fixedTeams(), FightState.SETUP, "invite");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class KitCommand implements CommandExecutor {
|
public class KitCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public KitCommand() {
|
||||||
|
super(true, FightState.SETUP, "kit");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
@ -33,7 +38,7 @@ public class KitCommand implements CommandExecutor {
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if(args.length != 1)
|
if(args.length != 1)
|
||||||
GUI.kitSelection(player);
|
GUI.kitSelection(player, "");
|
||||||
else{
|
else{
|
||||||
Commands.kit(player, args[0]);
|
Commands.kit(player, args[0]);
|
||||||
}
|
}
|
||||||
|
@ -19,23 +19,28 @@
|
|||||||
|
|
||||||
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.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class LeaderCommand implements CommandExecutor {
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class LeaderCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public LeaderCommand() {
|
||||||
|
super(!Config.fixedTeams(), Config.test() ? FightState.ALL : EnumSet.of(FightState.PRE_LEADER_SETUP), "leader");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player))
|
if(!(sender instanceof Player))
|
||||||
return false;
|
return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if(Commands.checkSetup(player))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(args.length == 0){
|
if(args.length == 0){
|
||||||
if(Fight.getFightPlayer(player) == null){
|
if(Fight.getFightPlayer(player) == null){
|
||||||
if(!Fight.getBlueTeam().hasTeamLeader())
|
if(!Fight.getBlueTeam().hasTeamLeader())
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class LeaveCommand implements CommandExecutor {
|
public class LeaveCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public LeaveCommand() {
|
||||||
|
super(true, FightState.SETUP, "leave");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -22,16 +22,21 @@ package de.steamwar.fightsystem.commands;
|
|||||||
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.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.sql.UserGroup;
|
import de.steamwar.sql.UserGroup;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class LockschemCommand implements CommandExecutor {
|
public class LockschemCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public LockschemCommand() {
|
||||||
|
super(true, FightState.ALL, "lockschem");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player))
|
if(!(sender instanceof Player))
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ReadyCommand implements CommandExecutor {
|
public class ReadyCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public ReadyCommand() {
|
||||||
|
super(true, FightState.SETUP, "ready");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.commands;
|
package de.steamwar.fightsystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class RemoveCommand implements CommandExecutor {
|
public class RemoveCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public RemoveCommand() {
|
||||||
|
super(!Config.fixedTeams(), FightState.SETUP, "remove");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if(!(sender instanceof Player)) {
|
||||||
|
@ -24,10 +24,10 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class EventDummyCommand implements CommandExecutor {
|
public class UnavailableCommand implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
sender.sendMessage(FightSystem.PREFIX + "§cWährend des Events ist der Befehl nicht verfügbar.");
|
sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,11 +34,12 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
|
|
||||||
public abstract class Countdown {
|
public abstract class Countdown {
|
||||||
|
|
||||||
private int time;
|
protected int time;
|
||||||
private final BukkitTask task;
|
|
||||||
private final Sound sound;
|
private final Sound sound;
|
||||||
private final boolean level;
|
private final boolean level;
|
||||||
|
|
||||||
|
private BukkitTask task = null;
|
||||||
|
|
||||||
abstract String countdownCounting();
|
abstract String countdownCounting();
|
||||||
abstract void countdownFinished();
|
abstract void countdownFinished();
|
||||||
|
|
||||||
@ -46,8 +47,6 @@ public abstract class Countdown {
|
|||||||
this.time = time;
|
this.time = time;
|
||||||
this.sound = getSound(sound);
|
this.sound = getSound(sound);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
|
||||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 0, 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Sound getSound(SWSound sound){
|
public static Sound getSound(SWSound sound){
|
||||||
@ -68,8 +67,15 @@ public abstract class Countdown {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enable() {
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20);
|
||||||
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
task.cancel();
|
if(task != null){
|
||||||
|
task.cancel();
|
||||||
|
task = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void broadcast(String message){
|
private void broadcast(String message){
|
||||||
@ -80,7 +86,13 @@ public abstract class Countdown {
|
|||||||
BasicListener.toActionbar(p, msg);
|
BasicListener.toActionbar(p, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTimeLeft(){
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
void count(){
|
void count(){
|
||||||
|
time--;
|
||||||
|
|
||||||
switch (time) {
|
switch (time) {
|
||||||
case 900: case 600: case 300: case 180: case 120:
|
case 900: case 600: case 300: case 180: case 120:
|
||||||
broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting());
|
broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting());
|
||||||
@ -106,14 +118,8 @@ public abstract class Countdown {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.level)
|
if(this.level)
|
||||||
Fight.setLevel(time);
|
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(time));
|
||||||
|
|
||||||
time--;
|
|
||||||
onTime(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onTime(int time){
|
|
||||||
//Implemented in some countdowns
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,9 @@ public class EnternCountdown extends Countdown {
|
|||||||
private List<TechHider.ChunkPos> chunkPos;
|
private List<TechHider.ChunkPos> chunkPos;
|
||||||
|
|
||||||
public EnternCountdown(FightPlayer fp) {
|
public EnternCountdown(FightPlayer fp) {
|
||||||
super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false);
|
super(Config.EnterStages.get(fp.getKit().getEnterStage()), SWSound.BLOCK_NOTE_PLING, false);
|
||||||
fightPlayer = fp;
|
fightPlayer = fp;
|
||||||
|
enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,13 +53,9 @@ public class EnternCountdown extends Countdown {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void count(){
|
void count(){
|
||||||
if(!fightPlayer.isLiving()){
|
time--;
|
||||||
disable();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = fightPlayer.getPlayer();
|
Player player = fightPlayer.getPlayer();
|
||||||
int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage());
|
|
||||||
switch (time) {
|
switch (time) {
|
||||||
case 900: case 600: case 300: case 180: case 120:
|
case 900: case 600: case 300: case 180: case 120:
|
||||||
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()));
|
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()));
|
||||||
|
@ -20,12 +20,19 @@
|
|||||||
package de.steamwar.fightsystem.countdown;
|
package de.steamwar.fightsystem.countdown;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public class NoPlayersOnlineCountdown extends Countdown {
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class NoPlayersOnlineCountdown extends Countdown implements StateDependent {
|
||||||
|
private static final Set<FightState> enabled = EnumSet.of(FightState.PRE_LEADER_SETUP);
|
||||||
|
|
||||||
public NoPlayersOnlineCountdown() {
|
public NoPlayersOnlineCountdown() {
|
||||||
super(Config.NoPlayerOnlineDuration, null, false);
|
super(Config.NoPlayerOnlineDuration, null, false);
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,4 +44,9 @@ public class NoPlayersOnlineCountdown extends Countdown {
|
|||||||
public void countdownFinished() {
|
public void countdownFinished() {
|
||||||
Bukkit.getServer().shutdown();
|
Bukkit.getServer().shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
public class PreRunningCountdown extends Countdown {
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class PreRunningCountdown extends Countdown implements StateDependent {
|
||||||
|
private static final Set<FightState> enabled = EnumSet.of(FightState.PRE_RUNNING);
|
||||||
|
|
||||||
public PreRunningCountdown() {
|
public PreRunningCountdown() {
|
||||||
super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true);
|
super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true);
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,4 +44,9 @@ public class PreRunningCountdown extends Countdown {
|
|||||||
public void countdownFinished() {
|
public void countdownFinished() {
|
||||||
FightSystem.setRunningState();
|
FightSystem.setRunningState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,18 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
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.states.FightState;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
public class PreSchemPasteCountdown extends Countdown {
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class PreSchemPasteCountdown extends Countdown implements StateDependent {
|
||||||
|
private static final Set<FightState> enabled = EnumSet.of(FightState.PRE_SCHEM_SETUP);
|
||||||
|
|
||||||
public PreSchemPasteCountdown() {
|
public PreSchemPasteCountdown() {
|
||||||
super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false);
|
super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false);
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,13 +42,11 @@ public class PreSchemPasteCountdown extends Countdown {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void countdownFinished() {
|
void countdownFinished() {
|
||||||
checkTeam(Fight.getBlueTeam());
|
|
||||||
checkTeam(Fight.getRedTeam());
|
|
||||||
FightSystem.setPostSchemState();
|
FightSystem.setPostSchemState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTeam(FightTeam team){
|
@Override
|
||||||
if(!team.hasSchematic())
|
public Set<FightState> enabled() {
|
||||||
team.pasteDummy();
|
return enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
public class SetupOverCountdown extends Countdown {
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class SetupOverCountdown extends Countdown implements StateDependent {
|
||||||
|
private static final Set<FightState> enabled = Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.POST_SCHEM_SETUP);
|
||||||
|
|
||||||
public SetupOverCountdown() {
|
public SetupOverCountdown() {
|
||||||
super(Config.SetupDuration, null, false);
|
super(Config.SetupDuration, null, false);
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,4 +44,9 @@ public class SetupOverCountdown extends Countdown {
|
|||||||
public void countdownFinished() {
|
public void countdownFinished() {
|
||||||
FightSystem.setPreRunningState();
|
FightSystem.setPreRunningState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
public class SpectateOverCountdown extends Countdown {
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class SpectateOverCountdown extends Countdown implements StateDependent {
|
||||||
|
private static final Set<FightState> enabled = Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.SPECTATE);
|
||||||
|
|
||||||
public SpectateOverCountdown() {
|
public SpectateOverCountdown() {
|
||||||
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
|
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,4 +44,9 @@ public class SpectateOverCountdown extends Countdown {
|
|||||||
public void countdownFinished() {
|
public void countdownFinished() {
|
||||||
FightSystem.shutdown(null);
|
FightSystem.shutdown(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class TechKOCountdown extends Countdown {
|
|||||||
public TechKOCountdown(FightTeam team, int countdownTime) {
|
public TechKOCountdown(FightTeam team, int countdownTime) {
|
||||||
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
|
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
|
||||||
this.team = team;
|
this.team = team;
|
||||||
|
enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,11 +25,15 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class TimeOverCountdown extends Countdown {
|
public class TimeOverCountdown extends Countdown {
|
||||||
|
|
||||||
|
private static TimeOverCountdown instance = null;
|
||||||
|
|
||||||
private final Runnable timeOver;
|
private final Runnable timeOver;
|
||||||
|
|
||||||
public TimeOverCountdown(Runnable timeOver) {
|
public TimeOverCountdown(Runnable timeOver) {
|
||||||
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
|
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
|
||||||
this.timeOver = timeOver;
|
this.timeOver = timeOver;
|
||||||
|
instance = this;
|
||||||
|
enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,8 +47,9 @@ public class TimeOverCountdown extends Countdown {
|
|||||||
timeOver.run();
|
timeOver.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static int getRemainingTime(){
|
||||||
void onTime(int time) {
|
if(instance == null)
|
||||||
FightSystem.setFightTime(time);
|
return -1;
|
||||||
|
return instance.getTimeLeft();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,8 @@ import java.util.logging.Level;
|
|||||||
public class Fight {
|
public class Fight {
|
||||||
private Fight(){}
|
private Fight(){}
|
||||||
|
|
||||||
public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader);
|
private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader);
|
||||||
public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
||||||
private static int schemRank;
|
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
IFight.init(redTeam, blueTeam);
|
IFight.init(redTeam, blueTeam);
|
||||||
@ -99,10 +98,6 @@ public class Fight {
|
|||||||
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch));
|
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLevel(int level) {
|
|
||||||
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FightTeam getTeamByName(String name) {
|
public static FightTeam getTeamByName(String name) {
|
||||||
if(redTeam.getName().equalsIgnoreCase(name))
|
if(redTeam.getName().equalsIgnoreCase(name))
|
||||||
return redTeam;
|
return redTeam;
|
||||||
@ -112,11 +107,8 @@ public class Fight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceSync() {
|
public static void replaceSync() {
|
||||||
Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
redTeam.replaceSync();
|
||||||
Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
blueTeam.replaceSync();
|
||||||
|
|
||||||
Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
|
||||||
Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
||||||
@ -159,33 +151,26 @@ public class Fight {
|
|||||||
|
|
||||||
public static int getMaxRank(){
|
public static int getMaxRank(){
|
||||||
/* MaxRank of 0 is Pubonly*/
|
/* MaxRank of 0 is Pubonly*/
|
||||||
return schemRank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void calcAvailibleSchemTypes() {
|
|
||||||
if(Config.OnlyPublicSchematics){
|
if(Config.OnlyPublicSchematics){
|
||||||
schemRank = 0;
|
return 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
|
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
|
||||||
schemRank = 1000;
|
return 1000;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
|
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
|
||||||
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
|
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
|
||||||
schemRank = 1000;
|
return 1000;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Config.RanksEnabled)
|
if(Config.RanksEnabled)
|
||||||
schemRank = Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader()));
|
return Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader()));
|
||||||
else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() ||
|
else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() ||
|
||||||
Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty())
|
Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty())
|
||||||
schemRank = 0;
|
return 0;
|
||||||
else
|
else
|
||||||
schemRank = 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int schemRank(FightPlayer fightPlayer){
|
private static int schemRank(FightPlayer fightPlayer){
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.kit.Kit;
|
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class FightPlayer {
|
public class FightPlayer {
|
||||||
@ -32,22 +32,41 @@ public class FightPlayer {
|
|||||||
private boolean isOut;
|
private boolean isOut;
|
||||||
private Kit kit;
|
private Kit kit;
|
||||||
private int kills;
|
private int kills;
|
||||||
|
private EnternCountdown enternCountdown = null;
|
||||||
|
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
if (this.player != null && this.player.isOnline())
|
this.player.sendMessage(message);
|
||||||
this.player.sendMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FightPlayer(Player player, FightTeam team) {
|
FightPlayer(Player player, FightTeam team) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.isOut = false;
|
this.isOut = false;
|
||||||
kit = KitManager.getKitByName(Config.MemberDefault);
|
kit = Kit.getKitByName(Config.MemberDefault);
|
||||||
|
if(Config.PersonalKits){
|
||||||
|
PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||||
|
if(personalKit != null){
|
||||||
|
kit = new Kit(personalKit);
|
||||||
|
}
|
||||||
|
}
|
||||||
kills = 0;
|
kills = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOut() {
|
public void setOut() {
|
||||||
isOut = true;
|
isOut = true;
|
||||||
|
if(enternCountdown != null){
|
||||||
|
enternCountdown.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnternCountdown(EnternCountdown countdown){
|
||||||
|
enternCountdown = countdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopEnternCountdown(){
|
||||||
|
if(enternCountdown != null){
|
||||||
|
enternCountdown.disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
@ -84,8 +103,8 @@ public class FightPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canEntern(){
|
public boolean canEntern(){
|
||||||
if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0)
|
if(enternCountdown == null)
|
||||||
return false;
|
return false;
|
||||||
return Config.EnterStages.get(kit.getEnterStage()) >= FightSystem.getFightTime();
|
return enternCountdown.getTimeLeft() == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
201
FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java
Normale Datei
201
FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java
Normale Datei
@ -0,0 +1,201 @@
|
|||||||
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
|
import de.steamwar.core.VersionedRunnable;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.IFightSystem;
|
||||||
|
import de.steamwar.fightsystem.record.RecordSystem;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
import de.steamwar.fightsystem.utils.ColorConverter;
|
||||||
|
import de.steamwar.sql.NoClipboardException;
|
||||||
|
import de.steamwar.sql.Schematic;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.*;
|
||||||
|
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class FightSchematic implements StateDependent {
|
||||||
|
|
||||||
|
private final FightTeam team;
|
||||||
|
private final int pasteX;
|
||||||
|
private final int pasteY;
|
||||||
|
private final int pasteZ;
|
||||||
|
private final int cornerX;
|
||||||
|
private final int cornerY;
|
||||||
|
private final int cornerZ;
|
||||||
|
private final boolean rotate;
|
||||||
|
|
||||||
|
private Clipboard clipboard = null;
|
||||||
|
private int schematic = 0;
|
||||||
|
|
||||||
|
public FightSchematic(FightTeam team, int pasteX, int pasteY, int pasteZ, int cornerX, int cornerY, int cornerZ, boolean rotate) {
|
||||||
|
this.team = team;
|
||||||
|
this.pasteX = pasteX;
|
||||||
|
this.pasteY = pasteY;
|
||||||
|
this.pasteZ = pasteZ;
|
||||||
|
this.cornerX = cornerX;
|
||||||
|
this.cornerY = cornerY;
|
||||||
|
this.cornerZ = cornerZ;
|
||||||
|
this.rotate = rotate;
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSchematic(){
|
||||||
|
return clipboard == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(){
|
||||||
|
return schematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchematic(Schematic schem) {
|
||||||
|
schematic = schem.getSchemID();
|
||||||
|
try {
|
||||||
|
clipboard = schem.load();
|
||||||
|
} catch (IOException e) {
|
||||||
|
team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!");
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Couldn't load Schematic " + schem.getSchemName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<FightState> enabled() {
|
||||||
|
return FightState.SCHEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
if(clipboard == null){
|
||||||
|
List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType);
|
||||||
|
if(publics.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
setSchematic(publics.get(new Random().nextInt(publics.size())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Config.recording()){
|
||||||
|
if(team.isBlue())
|
||||||
|
RecordSystem.blueSchem(schematic);
|
||||||
|
else
|
||||||
|
RecordSystem.redSchem(schematic);
|
||||||
|
}
|
||||||
|
|
||||||
|
FreezeWorld freezer = new FreezeWorld();
|
||||||
|
DyeColor c = ColorConverter.chat2dye(team.getColor());
|
||||||
|
|
||||||
|
try {
|
||||||
|
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||||
|
try {
|
||||||
|
EditSession e = FightTeam_8.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate);
|
||||||
|
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
||||||
|
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
||||||
|
throw new SecurityException("Error pasting arena in schematic", ex);
|
||||||
|
}
|
||||||
|
}, 8), new VersionedRunnable(() -> {
|
||||||
|
try {
|
||||||
|
EditSession e = FightTeam_8.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate);
|
||||||
|
FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
||||||
|
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
||||||
|
throw new SecurityException("Error pasting arena in schematic", ex);
|
||||||
|
}
|
||||||
|
}, 12), new VersionedRunnable(() -> {
|
||||||
|
try {
|
||||||
|
EditSession e = FightTeam_14.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate);
|
||||||
|
FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
||||||
|
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
||||||
|
throw new SecurityException("Error pasting arena in schematic", ex);
|
||||||
|
}
|
||||||
|
}, 14));
|
||||||
|
} catch (SecurityException securityException) {
|
||||||
|
team.broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
|
||||||
|
throw securityException;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3);
|
||||||
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceSync(boolean replace, Material target, Material replacement){
|
||||||
|
if(!replace)
|
||||||
|
return;
|
||||||
|
|
||||||
|
World world = Bukkit.getWorlds().get(0);
|
||||||
|
Location minPoint = new Location(world,cornerX, cornerY, cornerZ);
|
||||||
|
Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ));
|
||||||
|
|
||||||
|
FreezeWorld freezer = null;
|
||||||
|
if(!Config.ReplaceWithBlockupdates)
|
||||||
|
freezer = new FreezeWorld();
|
||||||
|
|
||||||
|
for(int x = minPoint.getBlockX(); x < maxPoint.getBlockX(); x++) {
|
||||||
|
for(int z = minPoint.getBlockZ(); z < maxPoint.getBlockZ(); z++) {
|
||||||
|
for(int y = minPoint.getBlockY(); y < maxPoint.getBlockY(); y++) {
|
||||||
|
Block block = world.getBlockAt(x, y, z);
|
||||||
|
if(block.getType() == target)
|
||||||
|
block.setType(replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Config.ReplaceWithBlockupdates)
|
||||||
|
HandlerList.unregisterAll(freezer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable() {
|
||||||
|
//TODO: Reset team area
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FreezeWorld implements Listener {
|
||||||
|
private FreezeWorld(){
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPistonExtend(BlockPistonExtendEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPistonRetract(BlockPistonRetractEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockGrow(BlockGrowEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onRedstoneEvent(BlockRedstoneEvent e){
|
||||||
|
e.setNewCurrent(e.getOldCurrent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockDispense(BlockDispenseEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,41 +19,27 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import de.steamwar.comms.packets.TablistNamePacket;
|
import de.steamwar.comms.packets.TablistNamePacket;
|
||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.IFightSystem;
|
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||||
import de.steamwar.fightsystem.record.RecordSystem;
|
import de.steamwar.fightsystem.record.RecordSystem;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.utils.ColorConverter;
|
|
||||||
import de.steamwar.fightsystem.utils.FightScoreboard;
|
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||||
import de.steamwar.fightsystem.utils.ItemBuilder;
|
import de.steamwar.fightsystem.utils.ItemBuilder;
|
||||||
import de.steamwar.fightsystem.utils.TechHider;
|
import de.steamwar.fightsystem.utils.TechHider;
|
||||||
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
|
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.sql.NoClipboardException;
|
|
||||||
import de.steamwar.sql.PersonalKit;
|
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.*;
|
|
||||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.scoreboard.NameTagVisibility;
|
import org.bukkit.scoreboard.NameTagVisibility;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +53,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final ChatColor color;
|
private final ChatColor color;
|
||||||
private int schematic = 0;
|
private FightSchematic schematic;
|
||||||
private final Team team;
|
private final Team team;
|
||||||
private final boolean blue;
|
private final boolean blue;
|
||||||
|
|
||||||
@ -92,6 +78,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
this.cornerX = cornerX;
|
this.cornerX = cornerX;
|
||||||
this.cornerY = cornerY;
|
this.cornerY = cornerY;
|
||||||
this.cornerZ = cornerZ;
|
this.cornerZ = cornerZ;
|
||||||
|
this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, cornerX, cornerY, cornerZ, rotate);
|
||||||
this.blue = blue;
|
this.blue = blue;
|
||||||
this.designatedLeader = designatedLeader;
|
this.designatedLeader = designatedLeader;
|
||||||
color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
|
color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
|
||||||
@ -168,7 +155,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 || Config.PersonalKits)
|
if(Kit.getAvailableKits(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());
|
||||||
if(!Config.test())
|
if(!Config.test())
|
||||||
@ -187,7 +174,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
team.removeEntry(player.getName());
|
team.removeEntry(player.getName());
|
||||||
fightPlayer.getPlayer().getInventory().clear();
|
fightPlayer.getPlayer().getInventory().clear();
|
||||||
|
|
||||||
if(fightPlayer.equals(leader) && FightSystem.getFightState().setup())
|
if(fightPlayer.equals(leader) && FightState.setup())
|
||||||
setLeader(null);
|
setLeader(null);
|
||||||
|
|
||||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||||
@ -231,9 +218,11 @@ public class FightTeam implements IFightTeam{
|
|||||||
if(ready)
|
if(ready)
|
||||||
setReady(false);
|
setReady(false);
|
||||||
|
|
||||||
leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
|
if(!Config.PersonalKits)
|
||||||
|
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
|
||||||
|
|
||||||
Inventory inventory = leader.getPlayer().getInventory();
|
Inventory inventory = leader.getPlayer().getInventory();
|
||||||
if (KitManager.getKits(true).size() > 1)
|
if (Kit.getAvailableKits(true).size() > 1)
|
||||||
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 if(Config.PersonalKits)
|
else if(Config.PersonalKits)
|
||||||
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit bearbeiten").build());
|
inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit bearbeiten").build());
|
||||||
@ -247,7 +236,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
|
|
||||||
inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
|
inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
|
||||||
|
|
||||||
if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
|
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||||
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build());
|
inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,68 +249,12 @@ public class FightTeam implements IFightTeam{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pasteSchematic(){
|
public void pasteSchematic(){
|
||||||
if(Config.recording()){
|
|
||||||
if(blue)
|
|
||||||
RecordSystem.blueSchem(schematic);
|
|
||||||
else
|
|
||||||
RecordSystem.redSchem(schematic);
|
|
||||||
}
|
|
||||||
|
|
||||||
FreezeWorld freezer = new FreezeWorld();
|
|
||||||
DyeColor c = ColorConverter.chat2dye(color);
|
|
||||||
Schematic schem;
|
|
||||||
try{
|
|
||||||
schem = Schematic.getSchemFromDB(this.schematic);
|
|
||||||
}catch(SecurityException e){
|
|
||||||
pasteDummy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> {
|
|
||||||
try {
|
|
||||||
EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
|
|
||||||
FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
|
||||||
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
|
||||||
throw new SecurityException("Error pasting arena in schematic", ex);
|
|
||||||
}
|
|
||||||
}, 8), new VersionedRunnable(() -> {
|
|
||||||
try {
|
|
||||||
EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
|
|
||||||
FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
|
||||||
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
|
||||||
throw new SecurityException("Error pasting arena in schematic", ex);
|
|
||||||
}
|
|
||||||
}, 12), new VersionedRunnable(() -> {
|
|
||||||
try {
|
|
||||||
EditSession e = FightTeam_14.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate);
|
|
||||||
FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ);
|
|
||||||
} catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) {
|
|
||||||
throw new SecurityException("Error pasting arena in schematic", ex);
|
|
||||||
}
|
|
||||||
}, 14));
|
|
||||||
} catch (SecurityException securityException) {
|
|
||||||
broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
|
|
||||||
throw securityException;
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3);
|
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pasteDummy(){
|
|
||||||
List<Schematic> publics = Schematic.getSchemsOfType(0, Config.SchematicType);
|
|
||||||
if(publics.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
schematic = publics.get(new Random().nextInt(publics.size())).getSchemID();
|
|
||||||
pasteSchematic();
|
|
||||||
|
|
||||||
if(!Config.test() && leader != null)
|
if(!Config.test() && leader != null)
|
||||||
leader.getPlayer().getInventory().clear(0);
|
leader.getPlayer().getInventory().clear(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchematic(Schematic schematic){
|
public void setSchematic(Schematic schematic){
|
||||||
this.schematic = schematic.getSchemID();
|
setNotPastingSchem(schematic);
|
||||||
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
|
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
|
||||||
|
|
||||||
if(!Config.test())
|
if(!Config.test())
|
||||||
@ -334,14 +267,18 @@ public class FightTeam implements IFightTeam{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNotPastingSchem(Schematic schematic){
|
||||||
|
this.schematic.setSchematic(schematic);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasSchematic(){
|
public boolean hasSchematic(){
|
||||||
return schematic != 0;
|
return schematic.hasSchematic();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReady(boolean ready) {
|
public void setReady(boolean ready) {
|
||||||
Player l = leader.getPlayer();
|
Player l = leader.getPlayer();
|
||||||
|
|
||||||
if(schematic == 0){
|
if(!schematic.hasSchematic()){
|
||||||
l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
|
l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -375,7 +312,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getSchematic() {
|
public int getSchematic() {
|
||||||
return schematic;
|
return schematic.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getSpawn() {
|
public Location getSpawn() {
|
||||||
@ -399,47 +336,14 @@ public class FightTeam implements IFightTeam{
|
|||||||
|
|
||||||
public void loadKits(){
|
public void loadKits(){
|
||||||
for(FightPlayer fightPlayer : players.values()) {
|
for(FightPlayer fightPlayer : players.values()) {
|
||||||
if(fightPlayer.getPlayer() == null)
|
|
||||||
continue;
|
|
||||||
fightPlayer.getPlayer().getInventory().clear();
|
fightPlayer.getPlayer().getInventory().clear();
|
||||||
|
fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer());
|
||||||
PersonalKit personalKit = null;
|
|
||||||
if(Config.PersonalKits)
|
|
||||||
personalKit = PersonalKit.getKitInUse(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) {
|
void replaceSync() {
|
||||||
if(!replace)
|
schematic.replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
||||||
return;
|
schematic.replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
||||||
|
|
||||||
World world = Bukkit.getWorlds().get(0);
|
|
||||||
Location minPoint = new Location(world, cornerX, cornerY, cornerZ);
|
|
||||||
Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ));
|
|
||||||
|
|
||||||
FreezeWorld freezer = null;
|
|
||||||
if(!Config.ReplaceWithBlockupdates)
|
|
||||||
freezer = new FreezeWorld();
|
|
||||||
|
|
||||||
for(int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) {
|
|
||||||
for(int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) {
|
|
||||||
for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) {
|
|
||||||
Block block = world.getBlockAt(x, y, z);
|
|
||||||
if(block.getType() == target)
|
|
||||||
block.setType(replacement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Config.ReplaceWithBlockupdates)
|
|
||||||
HandlerList.unregisterAll(freezer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTeamColor(Team team, ChatColor color){
|
private void setTeamColor(Team team, ChatColor color){
|
||||||
@ -449,44 +353,7 @@ public class FightTeam implements IFightTeam{
|
|||||||
new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14));
|
new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FreezeWorld implements Listener {
|
public ChatColor getColor() {
|
||||||
private FreezeWorld(){
|
return color;
|
||||||
Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPistonExtend(BlockPistonExtendEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPistonRetract(BlockPistonRetractEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockGrow(BlockGrowEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onRedstoneEvent(BlockRedstoneEvent e){
|
|
||||||
e.setNewCurrent(e.getOldCurrent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onBlockDispense(BlockDispenseEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryMoveEvent(InventoryMoveItemEvent e){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
349
FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java
Normale Datei
349
FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java
Normale Datei
@ -0,0 +1,349 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.commands.Commands;
|
||||||
|
import de.steamwar.fightsystem.commands.GUI;
|
||||||
|
import de.steamwar.fightsystem.listener.*;
|
||||||
|
import de.steamwar.inventory.SWInventory;
|
||||||
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.sql.PersonalKit;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class Kit {
|
||||||
|
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
|
||||||
|
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
if(!kits.exists()) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
|
||||||
|
ConfigurationSection kitSection = kitData.getConfigurationSection("Kits");
|
||||||
|
|
||||||
|
for(String key : Objects.requireNonNull(kitSection).getKeys(false)) {
|
||||||
|
loadedKits.add(new Kit(Objects.requireNonNull(kitSection.getConfigurationSection(key))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final ItemStack[] inventory;
|
||||||
|
private final ItemStack[] armor;
|
||||||
|
private final Collection<PotionEffect> effects;
|
||||||
|
private final int enterStage;
|
||||||
|
private final boolean tnt;
|
||||||
|
private final boolean leaderAllowed;
|
||||||
|
private final boolean memberAllowed;
|
||||||
|
|
||||||
|
public Kit(String name, Player player) {
|
||||||
|
this.name = name;
|
||||||
|
this.inventory = player.getInventory().getContents();
|
||||||
|
this.armor = player.getInventory().getArmorContents();
|
||||||
|
this.effects = player.getActivePotionEffects();
|
||||||
|
this.leaderAllowed = true;
|
||||||
|
this.memberAllowed = true;
|
||||||
|
this.enterStage = 0;
|
||||||
|
this.tnt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kit(ConfigurationSection kit){
|
||||||
|
name = kit.getName();
|
||||||
|
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
|
||||||
|
if(kit.isList("Armor"))
|
||||||
|
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
|
||||||
|
else
|
||||||
|
armor = null;
|
||||||
|
leaderAllowed = kit.getBoolean("LeaderAllowed");
|
||||||
|
memberAllowed = kit.getBoolean("MemberAllowed");
|
||||||
|
if(kit.isList("Effects"))
|
||||||
|
effects = (List<PotionEffect>) kit.getList("Effects");
|
||||||
|
else
|
||||||
|
effects = null;
|
||||||
|
enterStage = kit.getInt("EnterStage", 0);
|
||||||
|
tnt = kit.getBoolean("TNT", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Kit(PersonalKit kit){
|
||||||
|
this.name = kit.getName();
|
||||||
|
this.inventory = kit.getInventory();
|
||||||
|
this.armor = kit.getArmor();
|
||||||
|
this.effects = Collections.emptyList();
|
||||||
|
this.leaderAllowed = true;
|
||||||
|
this.memberAllowed = true;
|
||||||
|
this.enterStage = 0;
|
||||||
|
this.tnt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Kit getKitByName(String kitName) {
|
||||||
|
for(Kit kit : loadedKits) {
|
||||||
|
if(kit.getName().equalsIgnoreCase(kitName))
|
||||||
|
return kit;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Kit> getAvailableKits(boolean leader){
|
||||||
|
List<Kit> kits = new ArrayList<>();
|
||||||
|
for (Kit k : loadedKits) {
|
||||||
|
if (k.canUseKit(leader)){
|
||||||
|
kits.add(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return kits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canUseKit(boolean leader){
|
||||||
|
if (leader) {
|
||||||
|
return leaderAllowed;
|
||||||
|
} else {
|
||||||
|
return memberAllowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean leaderExclusive() {
|
||||||
|
return !memberAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack[] getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack[] getArmor() {
|
||||||
|
return armor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this kit allowed to set/handle tnt? */
|
||||||
|
public boolean isTnt(){
|
||||||
|
return tnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* In which stage is entern allowed? */
|
||||||
|
public int getEnterStage() {
|
||||||
|
return enterStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toPersonalKit(PersonalKit kit) {
|
||||||
|
kit.setContainer(inventory, armor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBadItems(){
|
||||||
|
Kit normal = Kit.getKitByName(Config.MemberDefault);
|
||||||
|
assert normal != null;
|
||||||
|
|
||||||
|
for(int i = 0; i < inventory.length; i++){
|
||||||
|
if(isBadItem(inventory[i]))
|
||||||
|
inventory[i] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isBadItem(ItemStack stack){
|
||||||
|
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 && PersonalKitCreator_14.hasAttributeModifier(stack)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.hasItemMeta()){
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData())
|
||||||
|
return true; //Blocks always upwards slabs etc.
|
||||||
|
|
||||||
|
if(VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8),
|
||||||
|
new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9),
|
||||||
|
new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10),
|
||||||
|
new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12),
|
||||||
|
new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14),
|
||||||
|
new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15)))
|
||||||
|
return true; //Blocks prefilled inventories
|
||||||
|
}
|
||||||
|
|
||||||
|
Kit normal = Kit.getKitByName(Config.MemberDefault);
|
||||||
|
assert normal != null;
|
||||||
|
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEnchantmentInKit(ItemStack stack){
|
||||||
|
for(ItemStack is : inventory){
|
||||||
|
if(similar(stack, is))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(armor != null){
|
||||||
|
for(ItemStack is : armor){
|
||||||
|
if(similar(stack, is))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
player.getInventory().setContents(inventory);
|
||||||
|
if(armor != null)
|
||||||
|
player.getInventory().setArmorContents(armor);
|
||||||
|
player.updateInventory();
|
||||||
|
if(effects != null)
|
||||||
|
player.addPotionEffects(effects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a kit preview with the options to go back to kit selection or to select the kit.
|
||||||
|
*/
|
||||||
|
public void preview(Player player){
|
||||||
|
SWInventory inv = new SWInventory(player, 54, name);
|
||||||
|
|
||||||
|
//36 = Inventargröße
|
||||||
|
for(int i = 0; i < 36; i++){
|
||||||
|
if(inventory[i] == null)
|
||||||
|
continue;
|
||||||
|
SWItem item = new SWItem();
|
||||||
|
item.setItemStack(inventory[i]);
|
||||||
|
inv.setItem(i, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(armor != null){
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
if(armor[i] == null)
|
||||||
|
continue;
|
||||||
|
SWItem item = new SWItem();
|
||||||
|
item.setItemStack(armor[i]);
|
||||||
|
inv.setItem(36 + i, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(effects != null){
|
||||||
|
Iterator<PotionEffect> it = effects.iterator();
|
||||||
|
int pos = 44;
|
||||||
|
while(it.hasNext()){
|
||||||
|
PotionEffect effect = it.next();
|
||||||
|
SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName());
|
||||||
|
inv.setItem(pos, item);
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inv.setCallback(-999, click -> player.closeInventory());
|
||||||
|
if(Config.PersonalKits){
|
||||||
|
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), name)));
|
||||||
|
inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> {
|
||||||
|
player.closeInventory();
|
||||||
|
SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?");
|
||||||
|
conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory());
|
||||||
|
conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> {
|
||||||
|
player.closeInventory();
|
||||||
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
|
PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB(), name);
|
||||||
|
if(kit.isInUse()) {
|
||||||
|
List<PersonalKit> kits = PersonalKit.get(user.getId(), Config.SchematicType.toDB());
|
||||||
|
if(!kits.isEmpty()){
|
||||||
|
PersonalKit kit1 = kits.get(0);
|
||||||
|
kit1.setInUse();
|
||||||
|
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
||||||
|
assert fightPlayer != null;
|
||||||
|
fightPlayer.setKit(new Kit(kit1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kit.delete();
|
||||||
|
});
|
||||||
|
conf.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", click -> {
|
||||||
|
Commands.kit(player, name);
|
||||||
|
player.closeInventory();
|
||||||
|
});
|
||||||
|
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", click -> GUI.kitSelection(player, ""));
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createKit(String kitName, Player player){
|
||||||
|
loadedKits.add(new Kit(kitName, player));
|
||||||
|
YamlConfiguration yamlConfiguration = new YamlConfiguration();
|
||||||
|
for(Kit k : loadedKits){
|
||||||
|
ConfigurationSection section = yamlConfiguration.createSection("Kits." + k.getName());
|
||||||
|
section.set("Items", k.inventory);
|
||||||
|
if(k.armor != null)
|
||||||
|
section.set("Armor", k.armor);
|
||||||
|
section.set("LeaderAllowed", k.leaderAllowed);
|
||||||
|
section.set("MemberAllowed", k.memberAllowed);
|
||||||
|
section.set("Effects", k.effects);
|
||||||
|
section.set("EnterStage", k.enterStage);
|
||||||
|
section.set("TNT", k.tnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfiguration.save(kits);
|
||||||
|
}catch(IOException e){
|
||||||
|
throw new SecurityException("Failed to save kits.data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,207 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.fightsystem.kit;
|
|
||||||
|
|
||||||
import de.steamwar.fightsystem.commands.Commands;
|
|
||||||
import de.steamwar.fightsystem.commands.GUI;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Kit {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final boolean leaderAllowed;
|
|
||||||
private final boolean memberAllowed;
|
|
||||||
private final ItemStack[] inventory;
|
|
||||||
private final ItemStack[] armor;
|
|
||||||
private final Collection<PotionEffect> effects;
|
|
||||||
private final int enterStage;
|
|
||||||
private final boolean tnt;
|
|
||||||
|
|
||||||
Kit(String name, Player player) {
|
|
||||||
this.name = name;
|
|
||||||
this.leaderAllowed = true;
|
|
||||||
this.memberAllowed = true;
|
|
||||||
this.inventory = player.getInventory().getContents();
|
|
||||||
this.armor = player.getInventory().getArmorContents();
|
|
||||||
this.effects = player.getActivePotionEffects();
|
|
||||||
this.enterStage = 0;
|
|
||||||
this.tnt = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Kit(ConfigurationSection kit){
|
|
||||||
name = kit.getName();
|
|
||||||
inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]);
|
|
||||||
if(kit.isList("Armor"))
|
|
||||||
armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]);
|
|
||||||
else
|
|
||||||
armor = null;
|
|
||||||
leaderAllowed = kit.getBoolean("LeaderAllowed");
|
|
||||||
memberAllowed = kit.getBoolean("MemberAllowed");
|
|
||||||
if(kit.isList("Effects"))
|
|
||||||
effects = (Collection<PotionEffect>) kit.getList("Effects");
|
|
||||||
else
|
|
||||||
effects = null;
|
|
||||||
enterStage = kit.getInt("EnterStage", 0);
|
|
||||||
tnt = kit.getBoolean("TNT", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLeaderAllowed() {
|
|
||||||
return leaderAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMemberAllowed() {
|
|
||||||
return memberAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack[] getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack[] getArmor() {
|
|
||||||
return armor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this kit allowed to set/handle tnt? */
|
|
||||||
public boolean isTnt(){
|
|
||||||
return tnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In which stage is entern allowed? */
|
|
||||||
public int getEnterStage() {
|
|
||||||
return enterStage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnchantmentInKit(ItemStack stack){
|
|
||||||
for(ItemStack is : inventory){
|
|
||||||
if(similar(stack, is))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(armor != null){
|
|
||||||
for(ItemStack is : armor){
|
|
||||||
if(similar(stack, is))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
player.getInventory().setContents(inventory);
|
|
||||||
if(armor != null)
|
|
||||||
player.getInventory().setArmorContents(armor);
|
|
||||||
player.updateInventory();
|
|
||||||
if(effects != null)
|
|
||||||
player.addPotionEffects(effects);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveKit(ConfigurationSection section){
|
|
||||||
section.set("Items", inventory);
|
|
||||||
if(armor != null)
|
|
||||||
section.set("Armor", armor);
|
|
||||||
section.set("LeaderAllowed", leaderAllowed);
|
|
||||||
section.set("MemberAllowed", memberAllowed);
|
|
||||||
section.set("Effects", effects);
|
|
||||||
section.set("EnterStage", enterStage);
|
|
||||||
section.set("TNT", tnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens a kit preview with the options to go back to kit selection or to select the kit.
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
public void preview(Player player){
|
|
||||||
SWInventory inv = new SWInventory(player, 54, name);
|
|
||||||
|
|
||||||
preview(inv, inventory, armor, effects);
|
|
||||||
|
|
||||||
inv.setCallback(-999, (click) -> player.closeInventory());
|
|
||||||
inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> {
|
|
||||||
Commands.kit(player, name);
|
|
||||||
player.closeInventory();
|
|
||||||
});
|
|
||||||
inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> GUI.kitSelection(player));
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void preview(SWInventory inv, ItemStack[] inventory, ItemStack[] armor, Collection<PotionEffect> effects) {
|
|
||||||
//36 = Inventargröße
|
|
||||||
for(int i = 0; i < 36; i++){
|
|
||||||
if(inventory[i] == null)
|
|
||||||
continue;
|
|
||||||
SWItem item = new SWItem();
|
|
||||||
item.setItemStack(inventory[i]);
|
|
||||||
inv.setItem(i, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(armor != null){
|
|
||||||
for(int i = 0; i < 4; i++){
|
|
||||||
if(armor[i] == null)
|
|
||||||
continue;
|
|
||||||
SWItem item = new SWItem();
|
|
||||||
item.setItemStack(armor[i]);
|
|
||||||
inv.setItem(36 + i, item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(effects != null){
|
|
||||||
Iterator<PotionEffect> it = effects.iterator();
|
|
||||||
int pos = 44;
|
|
||||||
while(it.hasNext()){
|
|
||||||
PotionEffect effect = it.next();
|
|
||||||
SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName());
|
|
||||||
inv.setItem(pos, item);
|
|
||||||
pos--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.fightsystem.kit;
|
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class KitManager {
|
|
||||||
private KitManager(){}
|
|
||||||
|
|
||||||
private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile);
|
|
||||||
private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits);
|
|
||||||
|
|
||||||
private static final ArrayList<Kit> loadedKits = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void saveInventory(String kitName, Player player){
|
|
||||||
loadedKits.add(new Kit(kitName, player));
|
|
||||||
saveAllKits();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Kit getKitByName(String kitName) {
|
|
||||||
for(Kit kit : loadedKits) {
|
|
||||||
if(kit.getName().equalsIgnoreCase(kitName))
|
|
||||||
return kit;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Kit> getKits(boolean leader){
|
|
||||||
List<Kit> kits = new ArrayList<>();
|
|
||||||
if(leader){
|
|
||||||
for (Kit k : loadedKits)
|
|
||||||
if (k.isLeaderAllowed())
|
|
||||||
kits.add(k);
|
|
||||||
}else{
|
|
||||||
for (Kit k : loadedKits)
|
|
||||||
if (k.isMemberAllowed())
|
|
||||||
kits.add(k);
|
|
||||||
}
|
|
||||||
return kits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadAllKits() {
|
|
||||||
if(!kits.exists()) {
|
|
||||||
saveAllKits();
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "kit config fehlend!");
|
|
||||||
FightSystem.shutdown(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(kitData.getConfigurationSection("Kits") != null) {
|
|
||||||
for(String key : kitData.getConfigurationSection("Kits").getKeys(false)) {
|
|
||||||
loadedKits.add(new Kit(kitData.getConfigurationSection("Kits." + key)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void saveAllKits(){
|
|
||||||
YamlConfiguration yamlConfiguration = new YamlConfiguration();
|
|
||||||
for(Kit k : loadedKits)
|
|
||||||
k.saveKit(yamlConfiguration.createSection("Kits." + k.getName()));
|
|
||||||
|
|
||||||
try {
|
|
||||||
yamlConfiguration.save(kits);
|
|
||||||
}catch(IOException e){
|
|
||||||
throw new SecurityException("Failed to save kits.data", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -38,7 +38,7 @@ public abstract class BasicListener implements Listener, StateDependent {
|
|||||||
|
|
||||||
BasicListener(Set<FightState> enabled){
|
BasicListener(Set<FightState> enabled){
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
FightSystem.registerStateDependent(this);
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean notFighting(Player p){
|
boolean notFighting(Player p){
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.fightsystem.listener;
|
|
||||||
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
public class EntityExplodeListener extends BasicListener {
|
|
||||||
|
|
||||||
public EntityExplodeListener() {
|
|
||||||
super(EnumSet.of(FightState.RUNNING));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
|
||||||
event.setYield(0); //No drops (additionally to world config)
|
|
||||||
WaterRemover.add(event.blockList());
|
|
||||||
}
|
|
||||||
}
|
|
@ -185,7 +185,7 @@ public class EventRecordListener extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setKitItems(FightTeam team){
|
private void setKitItems(FightTeam team){
|
||||||
if(FightSystem.getFightState() != FightState.PRE_RUNNING)
|
if(FightState.getFightState() != FightState.PRE_RUNNING)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(FightPlayer fp : team.getPlayers()){
|
for(FightPlayer fp : team.getPlayers()){
|
||||||
@ -222,6 +222,6 @@ public class EventRecordListener extends BasicListener {
|
|||||||
|
|
||||||
private boolean isNotSent(Player p){
|
private boolean isNotSent(Player p){
|
||||||
FightPlayer fp = Fight.getFightPlayer(p);
|
FightPlayer fp = Fight.getFightPlayer(p);
|
||||||
return fp == null || !fp.isLiving() || FightSystem.getFightState() == FightState.SPECTATE;
|
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public class HotbarGUIListener extends BasicListener {
|
|||||||
break;
|
break;
|
||||||
case "§eKit bearbeiten":
|
case "§eKit bearbeiten":
|
||||||
case "§eKit wählen":
|
case "§eKit wählen":
|
||||||
GUI.kitSelection(player);
|
GUI.kitSelection(player, "");
|
||||||
break;
|
break;
|
||||||
case "§eRespawn":
|
case "§eRespawn":
|
||||||
player.teleport(fightTeam.getSpawn());
|
player.teleport(fightTeam.getSpawn());
|
||||||
|
@ -19,25 +19,16 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.listener;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import de.steamwar.core.VersionedCallable;
|
|
||||||
import de.steamwar.fightsystem.Config;
|
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.kit.Kit;
|
import de.steamwar.fightsystem.fight.Kit;
|
||||||
import de.steamwar.fightsystem.kit.KitManager;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import de.steamwar.sql.PersonalKit;
|
import de.steamwar.sql.PersonalKit;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
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;
|
||||||
@ -47,12 +38,11 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.EnumSet;
|
||||||
import java.util.logging.Level;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PersonalKitCreator extends BasicListener {
|
public class PersonalKitCreator extends BasicListener {
|
||||||
|
|
||||||
@ -63,85 +53,10 @@ public class PersonalKitCreator extends BasicListener {
|
|||||||
super(enabled);
|
super(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openKitSelector(Player player, String qry) {
|
|
||||||
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB());
|
|
||||||
kits.removeIf(kit -> !kit.getName().toLowerCase().contains(qry.toLowerCase()));
|
|
||||||
List<SWListInv.SWListEntry<PersonalKit>> entries = new ArrayList<>(kits.size());
|
|
||||||
kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), kit)));
|
|
||||||
SWListInv<PersonalKit> inv = new SWListInv<>(player, "§eKit wählen", false, entries, (clickType, kit) -> preview(player, kit));
|
|
||||||
if(entries.isEmpty())
|
|
||||||
inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden"));
|
|
||||||
inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> {
|
|
||||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Kitname eingeben");
|
|
||||||
anvilInv.setItem(Material.LEATHER_CHESTPLATE);
|
|
||||||
anvilInv.setCallback(s -> {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) {
|
|
||||||
player.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!");
|
|
||||||
player.closeInventory();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Kit prototype = KitManager.getKits(Fight.getFightPlayer(player).isLeader()).get(0);
|
|
||||||
PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor());
|
|
||||||
openKitCreator(player, kit);
|
|
||||||
});
|
|
||||||
anvilInv.open();
|
|
||||||
});
|
|
||||||
inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> {
|
|
||||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "§eNach Kit suchen");
|
|
||||||
anvilInv.setItem(Material.PAPER);
|
|
||||||
anvilInv.setCallback(s -> openKitSelector(player, s));
|
|
||||||
anvilInv.open();
|
|
||||||
});
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void preview(Player player, PersonalKit kit){
|
|
||||||
SWInventory inv = new SWInventory(player, 54, kit.getName());
|
|
||||||
|
|
||||||
Kit.preview(inv, kit.getInventory(), kit.getArmor(), null);
|
|
||||||
|
|
||||||
inv.setItem(45, Material.LEATHER_CHESTPLATE, "§aKit benutzen", clickType -> useKit(player, kit));
|
|
||||||
inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> openKitCreator(player, kit));
|
|
||||||
inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> {
|
|
||||||
player.closeInventory();
|
|
||||||
SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?");
|
|
||||||
conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory());
|
|
||||||
conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> {
|
|
||||||
player.closeInventory();
|
|
||||||
if(kit.isInUse()) {
|
|
||||||
useKit(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()).get(0));
|
|
||||||
}
|
|
||||||
kit.delete();
|
|
||||||
});
|
|
||||||
conf.open();
|
|
||||||
});
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void useKit(Player player, PersonalKit kit) {
|
|
||||||
kit.setInUse();
|
|
||||||
player.closeInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openKitCreator(Player player, PersonalKit kit){
|
public static void openKitCreator(Player player, PersonalKit kit){
|
||||||
if(!enabled.contains(FightSystem.getFightState()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
new InventoryBackup(player, kit);
|
new InventoryBackup(player, kit);
|
||||||
|
new Kit(kit).loadToPlayer(player);
|
||||||
FightPlayer fightPlayer = Fight.getFightPlayer(player);
|
|
||||||
assert fightPlayer != null;
|
|
||||||
|
|
||||||
if(kit == null){
|
|
||||||
fightPlayer.getKit().loadToPlayer(player);
|
|
||||||
}else{
|
|
||||||
player.getInventory().setContents(kit.getInventory());
|
|
||||||
player.getInventory().setArmorContents(kit.getArmor());
|
|
||||||
}
|
|
||||||
|
|
||||||
player.updateInventory();
|
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!"));
|
toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!"));
|
||||||
}
|
}
|
||||||
@ -165,10 +80,23 @@ public class PersonalKitCreator extends BasicListener {
|
|||||||
|
|
||||||
Player player = (Player) e.getWhoClicked();
|
Player player = (Player) e.getWhoClicked();
|
||||||
//Deny bad items
|
//Deny bad items
|
||||||
if(isBadItem(e.getCursor(), player))
|
if(Kit.isBadItem(e.getCursor()))
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
||||||
checkForClear(e, player);
|
/* Should the inventory reset? */
|
||||||
|
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
|
@EventHandler
|
||||||
@ -198,97 +126,28 @@ public class PersonalKitCreator extends BasicListener {
|
|||||||
backup.close();
|
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 && PersonalKitCreator_14.hasAttributeModifier(stack)){
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(stack.hasItemMeta()){
|
|
||||||
ItemMeta meta = stack.getItemMeta();
|
|
||||||
if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData())
|
|
||||||
return true; //Blocks always upwards slabs etc.
|
|
||||||
|
|
||||||
if(hasItems(stack))
|
|
||||||
return true; //Blocks prefilled inventories
|
|
||||||
}
|
|
||||||
|
|
||||||
Kit normal = KitManager.getKitByName(Config.MemberDefault);
|
|
||||||
assert normal != null;
|
|
||||||
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean hasItems(ItemStack stack){
|
|
||||||
return VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8),
|
|
||||||
new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9),
|
|
||||||
new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10),
|
|
||||||
new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12),
|
|
||||||
new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14),
|
|
||||||
new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InventoryBackup{
|
private static class InventoryBackup{
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final ItemStack[] contents;
|
|
||||||
private final ItemStack[] armor;
|
|
||||||
private final PersonalKit kit;
|
private final PersonalKit kit;
|
||||||
|
private final Kit backup;
|
||||||
|
|
||||||
private InventoryBackup(Player player, PersonalKit kit){
|
private InventoryBackup(Player player, PersonalKit kit){
|
||||||
openKitCreators.put(player, this);
|
openKitCreators.put(player, this);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.contents = player.getInventory().getContents();
|
this.backup = new Kit("backup", player);
|
||||||
this.armor = player.getInventory().getArmorContents();
|
|
||||||
this.kit = kit;
|
this.kit = kit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBackup(){
|
|
||||||
PlayerInventory inventory = player.getInventory();
|
|
||||||
inventory.setContents(contents);
|
|
||||||
inventory.setArmorContents(armor);
|
|
||||||
player.updateInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void close(){
|
private void close(){
|
||||||
openKitCreators.remove(player);
|
openKitCreators.remove(player);
|
||||||
kit.setContainer(removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
|
Kit kit1 = new Kit(kit.getName(), player);
|
||||||
loadBackup();
|
kit1.removeBadItems();
|
||||||
|
kit1.toPersonalKit(kit);
|
||||||
|
backup.loadToPlayer(player);
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
useKit(player, kit);
|
kit.setInUse();
|
||||||
}
|
player.closeInventory();
|
||||||
|
Objects.requireNonNull(Fight.getFightPlayer(player)).setKit(new Kit(kit));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class PlayerMoveListener extends BasicListener {
|
|||||||
if(to.getY() <= Config.underArenaBorder) {
|
if(to.getY() <= Config.underArenaBorder) {
|
||||||
if(player.getGameMode() == GameMode.SPECTATOR || team == null)
|
if(player.getGameMode() == GameMode.SPECTATOR || team == null)
|
||||||
reset(event, DENY_ARENA);
|
reset(event, DENY_ARENA);
|
||||||
else if(FightSystem.getFightState().infight())
|
else if(FightState.getFightState().infight())
|
||||||
player.damage(2);
|
player.damage(2);
|
||||||
else if(!Config.GroundWalkable)
|
else if(!Config.GroundWalkable)
|
||||||
player.teleport(team.getSpawn());
|
player.teleport(team.getSpawn());
|
||||||
|
@ -68,7 +68,7 @@ public class PlayerStateListener extends BasicListener{
|
|||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5);
|
||||||
} else {
|
} else {
|
||||||
player.teleport(fightTeam.getSpawn());
|
player.teleport(fightTeam.getSpawn());
|
||||||
if(FightSystem.getFightState().setup())
|
if(FightState.setup())
|
||||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||||
else
|
else
|
||||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||||
@ -103,13 +103,12 @@ public class PlayerStateListener extends BasicListener{
|
|||||||
if(fightTeam == null)
|
if(fightTeam == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightState fightState = FightSystem.getFightState();
|
if(FightState.setup()){
|
||||||
if(fightState.setup()){
|
|
||||||
fightTeam.removePlayer(player);
|
fightTeam.removePlayer(player);
|
||||||
|
|
||||||
if(Config.recording())
|
if(Config.recording())
|
||||||
RecordSystem.entityDespawns(player);
|
RecordSystem.entityDespawns(player);
|
||||||
}else if(fightState.ingame()){
|
}else if(FightState.ingame()){
|
||||||
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
|
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
|
||||||
if(fightPlayer.isLiving()) {
|
if(fightPlayer.isLiving()) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!");
|
||||||
|
@ -17,22 +17,31 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import de.steamwar.core.VersionedCallable;
|
import de.steamwar.core.VersionedCallable;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class WaterRemover {
|
public class WaterRemover extends BasicListener {
|
||||||
private WaterRemover(){}
|
|
||||||
|
|
||||||
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
|
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
|
||||||
|
|
||||||
public static void add(List<Block> l) {
|
public WaterRemover() {
|
||||||
for(Block b : l){
|
super(EnumSet.of(FightState.RUNNING));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handleEntityExplode(EntityExplodeEvent event) {
|
||||||
|
event.setYield(0); //No drops (additionally to world config)
|
||||||
|
|
||||||
|
for(Block b : event.blockList()){
|
||||||
//b cannot be water or air due to current explosion
|
//b cannot be water or air due to current explosion
|
||||||
|
|
||||||
checkBlock(b.getRelative(BlockFace.UP));
|
checkBlock(b.getRelative(BlockFace.UP));
|
||||||
@ -43,8 +52,10 @@ public class WaterRemover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkBlock(Block b) {
|
private void checkBlock(Block b) {
|
||||||
if(!removeWater(b))
|
//checks for water and removes it, if present
|
||||||
|
if(!VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8),
|
||||||
|
new VersionedCallable<>(() -> WaterRemover_14.removeWater(b), 14)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(b.getY() < MIN_Y)
|
if(b.getY() < MIN_Y)
|
||||||
@ -61,10 +72,4 @@ public class WaterRemover {
|
|||||||
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8),
|
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8),
|
||||||
new VersionedCallable<>(() -> WaterRemover_14.isWater(block), 14));
|
new VersionedCallable<>(() -> WaterRemover_14.isWater(block), 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeWater(Block block){
|
|
||||||
//checks for water and removes it, if present
|
|
||||||
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(block), 8),
|
|
||||||
new VersionedCallable<>(() -> WaterRemover_14.removeWater(block), 14));
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -274,7 +274,7 @@ public class RecordSystem {
|
|||||||
private static void checkWorldState(){
|
private static void checkWorldState(){
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
if(FightSystem.getFightState() == FightState.SPECTATE)
|
if(FightState.getFightState() == FightState.SPECTATE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){
|
for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){
|
||||||
|
@ -19,39 +19,70 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.states;
|
package de.steamwar.fightsystem.states;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public enum FightState {
|
public enum FightState {
|
||||||
PRE_LEADER_SETUP(true, true, false, false),
|
PRE_LEADER_SETUP,
|
||||||
PRE_SCHEM_SETUP(true, true, false, false),
|
PRE_SCHEM_SETUP,
|
||||||
POST_SCHEM_SETUP(true, true, false, false),
|
POST_SCHEM_SETUP,
|
||||||
PRE_RUNNING(false, false, true, false),
|
PRE_RUNNING,
|
||||||
RUNNING(false, false, true, true),
|
RUNNING,
|
||||||
SPECTATE(false, true, false, false);
|
SPECTATE;
|
||||||
|
|
||||||
private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP
|
public static Set<FightState> SETUP = EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP);
|
||||||
private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE
|
public static Set<FightState> INGAME = EnumSet.of(PRE_RUNNING, RUNNING);
|
||||||
private final boolean ingame; //PRE_RUNNING, RUNNING
|
public static Set<FightState> ALL = EnumSet.allOf(FightState.class);
|
||||||
private final boolean infight; //RUNNING
|
public static Set<FightState> SCHEM = EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP));
|
||||||
|
|
||||||
FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){
|
private static final Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
|
||||||
this.setup = setup;
|
private static FightState fightState = PRE_LEADER_SETUP;
|
||||||
this.outgame = outgame;
|
|
||||||
this.ingame = ingame;
|
public static FightState getFightState() {
|
||||||
this.infight = infight;
|
return fightState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setup(){
|
public static void registerStateDependent(StateDependent stateDependent){
|
||||||
return setup;
|
if(stateDependent.enabled().isEmpty())
|
||||||
|
return;
|
||||||
|
boolean enabled = stateDependent.enabled().contains(fightState);
|
||||||
|
stateDependentFeatures.put(stateDependent, enabled);
|
||||||
|
if(enabled)
|
||||||
|
stateDependent.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean outgame(){
|
public static void setFightState(FightState state){
|
||||||
return outgame;
|
fightState = state;
|
||||||
|
|
||||||
|
for(Map.Entry<StateDependent, Boolean> feature : stateDependentFeatures.entrySet()){
|
||||||
|
//Enable feature if should be enabled and currently disabled
|
||||||
|
if(feature.getKey().enabled().contains(fightState)){
|
||||||
|
if(!feature.getValue()){
|
||||||
|
feature.getKey().enable();
|
||||||
|
feature.setValue(true);
|
||||||
|
}
|
||||||
|
feature.getKey().stateChange(fightState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Disable feature if should be disabled and currently enabled
|
||||||
|
if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){
|
||||||
|
feature.getKey().disable();
|
||||||
|
feature.setValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ingame(){
|
public static boolean setup(){
|
||||||
return ingame;
|
return SETUP.contains(fightState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean infight(){
|
public static boolean ingame(){
|
||||||
return infight;
|
return INGAME.contains(fightState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean infight(){
|
||||||
|
return fightState == RUNNING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||||
@ -29,15 +28,13 @@ import de.steamwar.fightsystem.states.FightState;
|
|||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EnterHandler implements StateDependent {
|
public class EnterHandler implements StateDependent {
|
||||||
private static final Set<FightState> enabled = EnumSet.of(FightState.RUNNING);
|
private static final Set<FightState> enabled = EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING);
|
||||||
private static final Set<EnternCountdown> countdowns = new HashSet<>();
|
|
||||||
|
|
||||||
public EnterHandler(){
|
public EnterHandler(){
|
||||||
FightSystem.registerStateDependent(this);
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,13 +42,6 @@ public class EnterHandler implements StateDependent {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTeam(FightTeam team){
|
|
||||||
for(FightPlayer fp : team.getPlayers()){
|
|
||||||
if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0)
|
|
||||||
countdowns.add(new EnternCountdown(fp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
registerTeam(Fight.getBlueTeam());
|
registerTeam(Fight.getBlueTeam());
|
||||||
@ -60,9 +50,20 @@ public class EnterHandler implements StateDependent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
for(EnternCountdown countdown : countdowns){
|
unregisterTeam(Fight.getBlueTeam());
|
||||||
countdown.disable();
|
unregisterTeam(Fight.getRedTeam());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerTeam(FightTeam team){
|
||||||
|
for(FightPlayer fp : team.getPlayers()){
|
||||||
|
if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0)
|
||||||
|
fp.setEnternCountdown(new EnternCountdown(fp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterTeam(FightTeam team){
|
||||||
|
for(FightPlayer fp : team.getPlayers()){
|
||||||
|
fp.stopEnternCountdown();
|
||||||
}
|
}
|
||||||
countdowns.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils;
|
|||||||
import de.steamwar.core.TPSWatcher;
|
import de.steamwar.core.TPSWatcher;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.record.RecordSystem;
|
import de.steamwar.fightsystem.record.RecordSystem;
|
||||||
@ -44,7 +45,7 @@ public class FightScoreboard {
|
|||||||
private static String title = "";
|
private static String title = "";
|
||||||
private static final HashMap<String, Integer> scores = new HashMap<>();
|
private static final HashMap<String, Integer> scores = new HashMap<>();
|
||||||
|
|
||||||
public static void init(){
|
static {
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +85,8 @@ public class FightScoreboard {
|
|||||||
title = "§6Kampf";
|
title = "§6Kampf";
|
||||||
if(Config.recording())
|
if(Config.recording())
|
||||||
RecordSystem.scoreboardTitle(title);
|
RecordSystem.scoreboardTitle(title);
|
||||||
if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) {
|
int fightTime = TimeOverCountdown.getRemainingTime();
|
||||||
int fightTime = FightSystem.getFightTime();
|
if (fightTime != -1) {
|
||||||
if (fightTime >= 60)
|
if (fightTime >= 60)
|
||||||
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
||||||
else
|
else
|
||||||
@ -94,7 +95,7 @@ public class FightScoreboard {
|
|||||||
|
|
||||||
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
||||||
|
|
||||||
if(fullScoreboard.contains(FightSystem.getFightState())){
|
if(fullScoreboard.contains(FightState.getFightState())){
|
||||||
if (Config.PercentSystem){
|
if (Config.PercentSystem){
|
||||||
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
|
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
|
||||||
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
|
||||||
@ -120,9 +121,9 @@ public class FightScoreboard {
|
|||||||
index = 0;
|
index = 0;
|
||||||
FightTeam team = null;
|
FightTeam team = null;
|
||||||
if(index == 1)
|
if(index == 1)
|
||||||
team = Fight.redTeam;
|
team = Fight.getRedTeam();
|
||||||
if(index == 2)
|
if(index == 2)
|
||||||
team = Fight.blueTeam;
|
team = Fight.getBlueTeam();
|
||||||
scores.clear();
|
scores.clear();
|
||||||
if(team != null)
|
if(team != null)
|
||||||
teamScoreboard(team);
|
teamScoreboard(team);
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
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;
|
||||||
@ -76,7 +77,7 @@ public class FightStatistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(),
|
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, TimeOverCountdown.getRemainingTime(),
|
||||||
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
|
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
|
||||||
|
|
||||||
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
|
|||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
@ -30,32 +31,44 @@ import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
|||||||
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
||||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedCallable;
|
||||||
import de.steamwar.core.events.ChunkListener;
|
import de.steamwar.core.events.ChunkListener;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.IFightSystem;
|
import de.steamwar.fightsystem.IFightSystem;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
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 java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||||
|
|
||||||
public class TechHider {
|
public class TechHider implements StateDependent {
|
||||||
private TechHider(){}
|
|
||||||
|
|
||||||
private static boolean running = false;
|
private static final boolean DISABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
|
||||||
|
|
||||||
public static void init(){
|
private final Set<FightState> enabled;
|
||||||
if(disabled())
|
private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
private final PacketAdapter chunkHider;
|
||||||
|
|
||||||
|
public TechHider(){
|
||||||
|
FightState.registerStateDependent(this);
|
||||||
|
enabled = DISABLED
|
||||||
|
? EnumSet.noneOf(FightState.class)
|
||||||
|
: EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP));
|
||||||
|
chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8),
|
||||||
|
new VersionedCallable<>(TechHider_12::chunkHider, 12),
|
||||||
|
new VersionedCallable<>(TechHider_14::chunkHider, 14),
|
||||||
|
new VersionedCallable<>(TechHider_15::chunkHider, 15));
|
||||||
|
|
||||||
|
if(DISABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(Core.getVersion() > 8){
|
if(Core.getVersion() > 8){
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) {
|
protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent e) {
|
public void onPacketReceiving(PacketEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
@ -65,7 +78,7 @@ public class TechHider {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) {
|
protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent e) {
|
public void onPacketReceiving(PacketEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
@ -76,133 +89,136 @@ public class TechHider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start(){
|
@Override
|
||||||
if(running)
|
public Set<FightState> enabled() {
|
||||||
return;
|
return enabled;
|
||||||
running = true;
|
|
||||||
|
|
||||||
if(disabled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
blockActionHider();
|
|
||||||
blockHider();
|
|
||||||
multiBlockHider();
|
|
||||||
updateBlockEntity();
|
|
||||||
VersionedRunnable.call(new VersionedRunnable(TechHider_12::start, 12),
|
|
||||||
new VersionedRunnable(TechHider_14::start, 14),
|
|
||||||
new VersionedRunnable(TechHider_15::start, 15));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void multiBlockHider(){
|
@Override
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
public void enable() {
|
||||||
@Override
|
protocolManager.addPacketListener(blockHider);
|
||||||
public void onPacketSending(PacketEvent e) {
|
protocolManager.addPacketListener(multiBlockHider);
|
||||||
PacketContainer packet = e.getPacket();
|
protocolManager.addPacketListener(blockActionHider);
|
||||||
|
if(Core.getVersion() > 8) {
|
||||||
|
protocolManager.addPacketListener(updateBlockEntity);
|
||||||
|
}
|
||||||
|
if(chunkHider != null) {
|
||||||
|
protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(ITechHider.threadMultiplier * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Player p = e.getPlayer();
|
@Override
|
||||||
ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0);
|
public void disable() {
|
||||||
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
protocolManager.removePacketListener(blockHider);
|
||||||
return;
|
protocolManager.removePacketListener(multiBlockHider);
|
||||||
|
protocolManager.removePacketListener(blockActionHider);
|
||||||
|
if(Core.getVersion() > 8) {
|
||||||
|
protocolManager.removePacketListener(updateBlockEntity);
|
||||||
|
}
|
||||||
|
if(chunkHider != null) {
|
||||||
|
protocolManager.getAsynchronousManager().unregisterAsyncHandler(chunkHider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PacketContainer cached = ITechHider.packetCache.get(packet);
|
private final PacketAdapter multiBlockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||||
if(cached != null){
|
@Override
|
||||||
e.setPacket(cached);
|
public void onPacketSending(PacketEvent e) {
|
||||||
return;
|
PacketContainer packet = e.getPacket();
|
||||||
}
|
|
||||||
|
|
||||||
cached = packet.shallowClone();
|
Player p = e.getPlayer();
|
||||||
ITechHider.packetCache.put(packet, cached);
|
ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0);
|
||||||
|
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
PacketContainer cached = ITechHider.packetCache.get(packet);
|
||||||
|
if(cached != null){
|
||||||
e.setPacket(cached);
|
e.setPacket(cached);
|
||||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
return;
|
||||||
MultiBlockChangeInfo[] changes = blockStructure.read(0).clone();
|
|
||||||
boolean changed = false;
|
|
||||||
for(MultiBlockChangeInfo mbci : changes){
|
|
||||||
WrappedBlockData block = mbci.getData();
|
|
||||||
if(Config.HiddenBlockTags.contains(block.getType().name())){
|
|
||||||
changed = true;
|
|
||||||
block.setType(ITechHider.obfuscateMaterial);
|
|
||||||
mbci.setData(block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(changed){
|
|
||||||
blockStructure.write(0, changes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void blockHider(){
|
cached = packet.shallowClone();
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
ITechHider.packetCache.put(packet, cached);
|
||||||
@Override
|
e.setPacket(cached);
|
||||||
public void onPacketSending(PacketEvent e) {
|
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
||||||
PacketContainer packet = e.getPacket();
|
MultiBlockChangeInfo[] changes = blockStructure.read(0).clone();
|
||||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
boolean changed = false;
|
||||||
|
for(MultiBlockChangeInfo mbci : changes){
|
||||||
Player p = e.getPlayer();
|
WrappedBlockData block = mbci.getData();
|
||||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
|
||||||
return;
|
|
||||||
|
|
||||||
PacketContainer cached = ITechHider.packetCache.get(packet);
|
|
||||||
if(cached != null){
|
|
||||||
e.setPacket(cached);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cached = packet.deepClone();
|
|
||||||
ITechHider.packetCache.put(packet, cached);
|
|
||||||
e.setPacket(cached);
|
|
||||||
StructureModifier<WrappedBlockData> blockStructure = cached.getBlockData();
|
|
||||||
WrappedBlockData block = blockStructure.read(0);
|
|
||||||
if(Config.HiddenBlockTags.contains(block.getType().name())){
|
if(Config.HiddenBlockTags.contains(block.getType().name())){
|
||||||
|
changed = true;
|
||||||
block.setType(ITechHider.obfuscateMaterial);
|
block.setType(ITechHider.obfuscateMaterial);
|
||||||
blockStructure.write(0, block);
|
mbci.setData(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void blockActionHider(){
|
if(changed){
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
|
blockStructure.write(0, changes);
|
||||||
@Override
|
|
||||||
public void onPacketSending(PacketEvent e) {
|
|
||||||
PacketContainer packet = e.getPacket();
|
|
||||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
|
||||||
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
private static void updateBlockEntity(){
|
private final PacketAdapter blockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||||
if(Core.getVersion() < 9)
|
@Override
|
||||||
return;
|
public void onPacketSending(PacketEvent e) {
|
||||||
|
PacketContainer packet = e.getPacket();
|
||||||
|
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.TILE_ENTITY_DATA) {
|
Player p = e.getPlayer();
|
||||||
@Override
|
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||||
public void onPacketSending(PacketEvent event) {
|
return;
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
|
||||||
|
|
||||||
Player p = event.getPlayer();
|
PacketContainer cached = ITechHider.packetCache.get(packet);
|
||||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
if(cached != null){
|
||||||
return;
|
e.setPacket(cached);
|
||||||
|
return;
|
||||||
// 9 == Set sign text
|
|
||||||
if(packet.getIntegers().read(0) != 9)
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
cached = packet.deepClone();
|
||||||
|
ITechHider.packetCache.put(packet, cached);
|
||||||
|
e.setPacket(cached);
|
||||||
|
StructureModifier<WrappedBlockData> blockStructure = cached.getBlockData();
|
||||||
|
WrappedBlockData block = blockStructure.read(0);
|
||||||
|
if(Config.HiddenBlockTags.contains(block.getType().name())){
|
||||||
|
block.setType(ITechHider.obfuscateMaterial);
|
||||||
|
blockStructure.write(0, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final PacketAdapter blockActionHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent e) {
|
||||||
|
PacketContainer packet = e.getPacket();
|
||||||
|
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||||
|
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||||
|
return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final PacketAdapter updateBlockEntity = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.TILE_ENTITY_DATA) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||||
|
|
||||||
|
Player p = event.getPlayer();
|
||||||
|
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 9 == Set sign text
|
||||||
|
if(packet.getIntegers().read(0) != 9)
|
||||||
|
return;
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static List<ChunkPos> prepareChunkReload(Player p){
|
public static List<ChunkPos> prepareChunkReload(Player p){
|
||||||
if(disabled())
|
if(DISABLED)
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
List<ChunkPos> chunksToReload = new ArrayList<>();
|
List<ChunkPos> chunksToReload = new ArrayList<>();
|
||||||
for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++)
|
for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++)
|
||||||
@ -213,7 +229,7 @@ public class TechHider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadChunks(Player p, List<ChunkPos> chunksToReload){
|
public static void reloadChunks(Player p, List<ChunkPos> chunksToReload){
|
||||||
if(disabled())
|
if(DISABLED)
|
||||||
return;
|
return;
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
||||||
for(ChunkPos chunk : chunksToReload){
|
for(ChunkPos chunk : chunksToReload){
|
||||||
@ -223,10 +239,6 @@ public class TechHider {
|
|||||||
}, 40);
|
}, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean disabled(){
|
|
||||||
return Config.OnlyPublicSchematics || Config.test() || !Config.TechhiderActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ChunkPos{
|
public static class ChunkPos{
|
||||||
final int x;
|
final int x;
|
||||||
final int z;
|
final int z;
|
||||||
|
@ -42,7 +42,7 @@ public class EventTeamOffWincondition extends Wincondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
//Team off is a on time trigger
|
//Team off is a one time trigger
|
||||||
}
|
}
|
||||||
|
|
||||||
private void teamOff(FightTeam team){
|
private void teamOff(FightTeam team){
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ abstract class Wincondition implements StateDependent {
|
|||||||
Wincondition(boolean condition, Set<FightState> enabled){
|
Wincondition(boolean condition, Set<FightState> enabled){
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
if(condition)
|
if(condition)
|
||||||
FightSystem.registerStateDependent(this);
|
FightState.registerStateDependent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +55,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
|
|||||||
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
|
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
|
||||||
bluePercent = destroyPercent;
|
bluePercent = destroyPercent;
|
||||||
if(destroyPercent >= Config.PercentWin) {
|
if(destroyPercent >= Config.PercentWin) {
|
||||||
FightSystem.setSpectateState(Fight.redTeam, "Percent");
|
FightSystem.setSpectateState(Fight.getRedTeam(), "Percent");
|
||||||
}
|
}
|
||||||
//Team Red
|
//Team Red
|
||||||
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) {
|
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) {
|
||||||
@ -64,7 +64,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
|
|||||||
double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
|
double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
|
||||||
redPercent = destroyPercent;
|
redPercent = destroyPercent;
|
||||||
if(destroyPercent >= Config.PercentWin) {
|
if(destroyPercent >= Config.PercentWin) {
|
||||||
FightSystem.setSpectateState(Fight.blueTeam, "Percent");
|
FightSystem.setSpectateState(Fight.getBlueTeam(), "Percent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class WinconditionPercentTimeout extends Wincondition {
|
||||||
|
|
||||||
|
private static final String WINDESCRIPTION = "PercentTimeout";
|
||||||
|
|
||||||
|
private TimeOverCountdown countdown;
|
||||||
|
|
||||||
|
public WinconditionPercentTimeout() {
|
||||||
|
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
countdown = new TimeOverCountdown(() -> {
|
||||||
|
double bluePercent = WinconditionPercentSystem.getBluePercent();
|
||||||
|
double redPercent = WinconditionPercentSystem.getRedPercent();
|
||||||
|
|
||||||
|
if(bluePercent > redPercent)
|
||||||
|
FightSystem.setSpectateState(Fight.getBlueTeam(), WINDESCRIPTION);
|
||||||
|
else if(bluePercent < redPercent)
|
||||||
|
FightSystem.setSpectateState(Fight.getRedTeam(), WINDESCRIPTION);
|
||||||
|
else
|
||||||
|
FightSystem.setSpectateState(null, WINDESCRIPTION);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disable(){
|
||||||
|
countdown.disable();
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.winconditions;
|
|||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
@ -114,7 +115,7 @@ public class WinconditionRelativePercent extends Wincondition{
|
|||||||
|
|
||||||
private int currentBlocks(){
|
private int currentBlocks(){
|
||||||
// Entern active
|
// Entern active
|
||||||
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= FightSystem.getFightTime())
|
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeOverCountdown.getRemainingTime())
|
||||||
return currentBlocks;
|
return currentBlocks;
|
||||||
|
|
||||||
int blocks = 0;
|
int blocks = 0;
|
||||||
|
@ -23,8 +23,8 @@ 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.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.listener.WaterRemover;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren