The big refactoring #238
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashSet;
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashSet;
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
@ -44,12 +43,8 @@ class TechHider_12 {
|
||||
|
||||
private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4);
|
||||
|
||||
static void start(){
|
||||
chunkHider();
|
||||
}
|
||||
|
||||
private static void chunkHider(){
|
||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
static PacketAdapter chunkHider(){
|
||||
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
@ -123,6 +118,6 @@ class TechHider_12 {
|
||||
byteArray.write(0, data);
|
||||
}
|
||||
}
|
||||
}).start(ITechHider.threadMultiplier * 4);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -79,9 +79,8 @@ class FightTeam_14 {
|
||||
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);
|
||||
Clipboard clipboard = schematic.load();
|
||||
|
||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
|
@ -26,14 +26,14 @@ import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
class PersonalKitCreator_14 {
|
||||
public class PersonalKitCreator_14 {
|
||||
private PersonalKitCreator_14(){}
|
||||
|
||||
static boolean hasAttributeModifier(ItemStack stack){
|
||||
public static boolean hasAttributeModifier(ItemStack stack){
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -17,7 +17,7 @@
|
||||
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.block.Block;
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
@ -40,12 +39,8 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
public class TechHider_14 {
|
||||
private TechHider_14(){}
|
||||
|
||||
static void start(){
|
||||
chunkHider();
|
||||
}
|
||||
|
||||
static void chunkHider(){
|
||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
static PacketAdapter chunkHider(){
|
||||
return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
@ -146,6 +141,6 @@ public class TechHider_14 {
|
||||
byteArray.write(0, data);
|
||||
}
|
||||
}
|
||||
}).start(ITechHider.threadMultiplier * 4);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashSet;
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
@ -42,15 +41,11 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
public class TechHider_15 {
|
||||
private TechHider_15(){}
|
||||
|
||||
static void start(){
|
||||
chunkHider();
|
||||
}
|
||||
|
||||
static void chunkHider(){
|
||||
static PacketAdapter chunkHider(){
|
||||
/*
|
||||
* 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
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
@ -158,7 +153,7 @@ public class TechHider_15 {
|
||||
byteArray.write(0, data);
|
||||
}
|
||||
}
|
||||
}).start(ITechHider.threadMultiplier * 4);
|
||||
};
|
||||
}
|
||||
|
||||
private static final class VariableValueArray {
|
||||
|
@ -87,9 +87,7 @@ class FightTeam_8 {
|
||||
e.flushQueue();
|
||||
}
|
||||
|
||||
static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
||||
Clipboard clipboard = schematic.load();
|
||||
|
||||
static EditSession pasteSchematic(Clipboard clipboard, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
|
||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
Vector dimensions = clipboard.getDimensions();
|
||||
Vector v = new Vector(pasteX, pasteY, pasteZ);
|
||||
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashSet;
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -17,7 +17,7 @@
|
||||
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.block.Block;
|
@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.HashSet;
|
||||
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());
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
|
@ -171,19 +171,19 @@ public class Config {
|
||||
PreFightDuration = config.getInt("Times.PreFightDuration");
|
||||
SpectatorDuration = config.getInt("Times.SpectatorDuration");
|
||||
|
||||
int schemsizeX = worldconfig.getInt("Arena.Schemsize.x");
|
||||
int schemsizeY = worldconfig.getInt("Arena.Schemsize.y");
|
||||
int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z");
|
||||
int schemsizeX = config.getInt("Arena.Schemsize.x");
|
||||
int schemsizeY = config.getInt("Arena.Schemsize.y");
|
||||
int schemsizeZ = config.getInt("Arena.Schemsize.z");
|
||||
int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x");
|
||||
int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y");
|
||||
int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z");
|
||||
TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x");
|
||||
TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y");
|
||||
TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z");
|
||||
Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x");
|
||||
Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z");
|
||||
Schem2BorderX = config.getInt("Arena.Schem2Border.x");
|
||||
Schem2BorderZ = config.getInt("Arena.Schem2Border.z");
|
||||
underArenaBorder = worldconfig.getInt("Arena.underArenaBorder");
|
||||
BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic");
|
||||
BorderFromSchematic = config.getInt("Arena.BorderFromSchematic");
|
||||
AlignWater = worldconfig.getBoolean("Arena.AlignWater");
|
||||
WaterDepth = worldconfig.getInt("Arena.WaterDepth");
|
||||
GroundWalkable = config.getBoolean("Arena.GroundWalkable");
|
||||
@ -417,6 +417,9 @@ public class Config {
|
||||
public static boolean check(){
|
||||
return CheckSchemID != 0;
|
||||
}
|
||||
public static boolean fixedTeams(){
|
||||
return event() || Ranked;
|
||||
}
|
||||
public static boolean recording(){
|
||||
return event();
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ import de.steamwar.fightsystem.countdown.*;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.listener.*;
|
||||
import de.steamwar.fightsystem.record.RecordSystem;
|
||||
import de.steamwar.fightsystem.record.Recorder;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.fightsystem.utils.EnterHandler;
|
||||
import de.steamwar.fightsystem.utils.FightStatistics;
|
||||
import de.steamwar.fightsystem.utils.TechHider;
|
||||
import de.steamwar.fightsystem.winconditions.*;
|
||||
import de.steamwar.sql.EventFight;
|
||||
import de.steamwar.sql.Schematic;
|
||||
@ -41,9 +41,6 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class FightSystem extends JavaPlugin {
|
||||
@ -51,36 +48,19 @@ public class FightSystem extends JavaPlugin {
|
||||
public static final String PREFIX = "§eArena§8» ";
|
||||
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
|
||||
public void onLoad() {
|
||||
setPlugin(this);
|
||||
plugin = this;
|
||||
IFightSystem.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Fight.init();
|
||||
KitManager.loadAllKits();
|
||||
TechHider.init();
|
||||
FightScoreboard.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 EntityExplodeListener();
|
||||
new WaterRemover();
|
||||
new FoodLevelChangeListener();
|
||||
new PistonListener();
|
||||
new PlayerChatListener();
|
||||
@ -105,6 +85,7 @@ public class FightSystem extends JavaPlugin {
|
||||
new VersionDependentListener();
|
||||
|
||||
new EnterHandler();
|
||||
new TechHider();
|
||||
|
||||
new WinconditionAllDead();
|
||||
new WinconditionCaptainDead();
|
||||
@ -116,40 +97,44 @@ public class FightSystem extends JavaPlugin {
|
||||
new WinconditionTimeout();
|
||||
new WinconditionHeartRatioTimeout();
|
||||
new WinconditionTechKO();
|
||||
new EventTeamOffWincondition();
|
||||
|
||||
Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand());
|
||||
Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand());
|
||||
Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand());
|
||||
Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand());
|
||||
Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand());
|
||||
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());
|
||||
new NoPlayersOnlineCountdown();
|
||||
new PreSchemPasteCountdown();
|
||||
new SetupOverCountdown();
|
||||
new PreRunningCountdown();
|
||||
new SpectateOverCountdown();
|
||||
|
||||
mainCountdown = new NoPlayersOnlineCountdown();
|
||||
fightTime = Config.TimeoutTime;
|
||||
new LeaveCommand();
|
||||
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) {
|
||||
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();
|
||||
}else if(Config.test()){
|
||||
if(Config.check()){
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0);
|
||||
}else{
|
||||
Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0);
|
||||
Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0);
|
||||
|
||||
setPreSchemState();
|
||||
setPostSchemState();
|
||||
Bukkit.getScheduler().runTaskLater(this, FightSystem::setPostSchemState, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,63 +143,36 @@ public class FightSystem extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void setPreSchemState() {
|
||||
if(fightState != FightState.PRE_LEADER_SETUP)
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.PRE_SCHEM_SETUP);
|
||||
|
||||
Fight.calcAvailibleSchemTypes();
|
||||
mainCountdown = new PreSchemPasteCountdown();
|
||||
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
||||
}
|
||||
|
||||
public static void setPostSchemState() {
|
||||
if(fightState != FightState.PRE_SCHEM_SETUP)
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.POST_SCHEM_SETUP);
|
||||
FightState.setFightState(FightState.POST_SCHEM_SETUP);
|
||||
|
||||
TechHider.start();
|
||||
if(!Config.test()){
|
||||
Fight.getBlueTeam().pasteSchematic();
|
||||
Fight.getRedTeam().pasteSchematic();
|
||||
}
|
||||
|
||||
if(Config.test())
|
||||
mainCountdown = null;
|
||||
else
|
||||
mainCountdown = new SetupOverCountdown();
|
||||
Fight.getBlueTeam().pasteSchematic();
|
||||
Fight.getRedTeam().pasteSchematic();
|
||||
}
|
||||
|
||||
public static void setPreRunningState() {
|
||||
if(fightState != FightState.POST_SCHEM_SETUP)
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.PRE_RUNNING);
|
||||
FightState.setFightState(FightState.PRE_RUNNING);
|
||||
|
||||
Fight.getBlueTeam().loadKits();
|
||||
Fight.getRedTeam().loadKits();
|
||||
setAllPlayersGM(GameMode.SURVIVAL);
|
||||
Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!");
|
||||
|
||||
mainCountdown = new PreRunningCountdown();
|
||||
|
||||
Fight.replaceSync();
|
||||
|
||||
if(Config.event())
|
||||
new EventTeamOffWincondition();
|
||||
}
|
||||
|
||||
public static void setRunningState() {
|
||||
if(fightState != FightState.PRE_RUNNING)
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.RUNNING);
|
||||
setAllPlayersGM(GameMode.SURVIVAL);
|
||||
FightState.setFightState(FightState.RUNNING);
|
||||
|
||||
FightStatistics.start();
|
||||
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
||||
}
|
||||
|
||||
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
|
||||
if(fightState == FightState.SPECTATE)
|
||||
return;
|
||||
setFightState(FightState.SPECTATE);
|
||||
FightState.setFightState(FightState.SPECTATE);
|
||||
|
||||
setAllPlayersGM(GameMode.SPECTATOR);
|
||||
Fight.getBlueTeam().teleportToSpawn();
|
||||
@ -239,15 +197,10 @@ public class FightSystem extends JavaPlugin {
|
||||
}
|
||||
|
||||
if(!Config.test()){
|
||||
new SpectateOverCountdown();
|
||||
FightStatistics.saveStats(winFightTeam, windescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFightTime(int fightTime) {
|
||||
FightSystem.fightTime = fightTime;
|
||||
}
|
||||
|
||||
public static void setEventLeiter(Player el){
|
||||
IFightSystem.setEventLeiter(el);
|
||||
}
|
||||
@ -260,35 +213,14 @@ public class FightSystem extends JavaPlugin {
|
||||
return IFightSystem.getEventFight();
|
||||
}
|
||||
|
||||
private static void setPlugin(FightSystem pl){
|
||||
plugin = pl;
|
||||
}
|
||||
|
||||
public static FightSystem getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static FightState getFightState() {
|
||||
return fightState;
|
||||
}
|
||||
|
||||
public static int getFightTime() {
|
||||
return fightTime;
|
||||
}
|
||||
|
||||
public static void shutdown(String 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) {
|
||||
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
|
||||
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;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AcceptCommand implements CommandExecutor {
|
||||
public class AcceptCommand extends BasicCommand {
|
||||
|
||||
public AcceptCommand() {
|
||||
super(!Config.fixedTeams(), FightState.SETUP, "accept");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -19,211 +19,34 @@
|
||||
|
||||
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.sql.Schematic;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
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.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class AkCommand extends BasicCommand {
|
||||
|
||||
public class AkCommand implements CommandExecutor {
|
||||
|
||||
private static final String SCHEMLIST_COMMAND = "/ak schemlist ";
|
||||
private static final int FILES_PER_PAGE = 15;
|
||||
public AkCommand() {
|
||||
super(Config.test(), FightState.ALL, "ak");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if(!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
switch(args.length){
|
||||
case 1:
|
||||
if(args[0].equalsIgnoreCase("schem") || args[0].equalsIgnoreCase("schemlist")){
|
||||
|
||||
//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);
|
||||
if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){
|
||||
Commands.sendHelp(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Kit.createKit(args[0], player);
|
||||
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;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.kit.Kit;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -36,7 +39,7 @@ public class Commands {
|
||||
}
|
||||
|
||||
static boolean checkSetup(Player p){
|
||||
if(!FightSystem.getFightState().setup()){
|
||||
if(!FightState.setup()){
|
||||
p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!");
|
||||
return true;
|
||||
}
|
||||
@ -201,14 +204,21 @@ public class Commands {
|
||||
if(fightPlayer == null)
|
||||
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){
|
||||
p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
if((fightPlayer.isLeader() && !k.isLeaderAllowed()) ||
|
||||
(!fightPlayer.isLeader() && !k.isMemberAllowed())){
|
||||
if(!k.canUseKit(fightPlayer.isLeader())){
|
||||
p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!");
|
||||
return;
|
||||
}
|
||||
@ -227,7 +237,6 @@ public class Commands {
|
||||
p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams");
|
||||
}else{
|
||||
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/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein");
|
||||
p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team");
|
||||
|
@ -19,12 +19,18 @@
|
||||
|
||||
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.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeclineCommand implements CommandExecutor {
|
||||
public class DeclineCommand extends BasicCommand {
|
||||
|
||||
public DeclineCommand() {
|
||||
super(!Config.fixedTeams(), FightState.SETUP, "decline");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -24,13 +24,14 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.kit.Kit;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||
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.Schematic;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -91,30 +92,59 @@ public class GUI {
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public static void kitSelection(Player p){
|
||||
public static void kitSelection(Player p, String query){
|
||||
FightPlayer fightPlayer = Fight.getFightPlayer(p);
|
||||
if(fightPlayer == null)
|
||||
return;
|
||||
|
||||
List<SWListInv.SWListEntry<Kit>> entries = new ArrayList<>();
|
||||
|
||||
if(Config.PersonalKits){
|
||||
PersonalKitCreator.openKitSelector(p, "");
|
||||
return;
|
||||
List<PersonalKit> kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB());
|
||||
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());
|
||||
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));
|
||||
SWListInv<Kit> inv = new SWListInv<>(p, "Kitauswahl", false, entries, (clickType, kit) -> kit.preview(p));
|
||||
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();
|
||||
}
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
@ -153,7 +183,7 @@ public class GUI {
|
||||
FightTeam fightTeam = Fight.getPlayerTeam(p);
|
||||
if(fightTeam == null)
|
||||
return;
|
||||
if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||
if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||
fightTeam.setSchematic(s);
|
||||
p.closeInventory();
|
||||
});
|
||||
|
@ -19,12 +19,18 @@
|
||||
|
||||
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.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class InviteCommand implements CommandExecutor {
|
||||
public class InviteCommand extends BasicCommand {
|
||||
|
||||
public InviteCommand() {
|
||||
super(!Config.fixedTeams(), FightState.SETUP, "invite");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -19,12 +19,17 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class KitCommand implements CommandExecutor {
|
||||
public class KitCommand extends BasicCommand {
|
||||
|
||||
public KitCommand() {
|
||||
super(true, FightState.SETUP, "kit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
@ -33,7 +38,7 @@ public class KitCommand implements CommandExecutor {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(args.length != 1)
|
||||
GUI.kitSelection(player);
|
||||
GUI.kitSelection(player, "");
|
||||
else{
|
||||
Commands.kit(player, args[0]);
|
||||
}
|
||||
|
@ -19,23 +19,28 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
return false;
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(Commands.checkSetup(player))
|
||||
return false;
|
||||
|
||||
if(args.length == 0){
|
||||
if(Fight.getFightPlayer(player) == null){
|
||||
if(!Fight.getBlueTeam().hasTeamLeader())
|
||||
|
@ -19,12 +19,17 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LeaveCommand implements CommandExecutor {
|
||||
public class LeaveCommand extends BasicCommand {
|
||||
|
||||
public LeaveCommand() {
|
||||
super(true, FightState.SETUP, "leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -22,16 +22,21 @@ package de.steamwar.fightsystem.commands;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserGroup;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LockschemCommand implements CommandExecutor {
|
||||
public class LockschemCommand extends BasicCommand {
|
||||
|
||||
public LockschemCommand() {
|
||||
super(true, FightState.ALL, "lockschem");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player))
|
||||
|
@ -19,12 +19,17 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ReadyCommand implements CommandExecutor {
|
||||
public class ReadyCommand extends BasicCommand {
|
||||
|
||||
public ReadyCommand() {
|
||||
super(true, FightState.SETUP, "ready");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -19,12 +19,18 @@
|
||||
|
||||
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.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RemoveCommand implements CommandExecutor {
|
||||
public class RemoveCommand extends BasicCommand {
|
||||
|
||||
public RemoveCommand() {
|
||||
super(!Config.fixedTeams(), FightState.SETUP, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -24,10 +24,10 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class EventDummyCommand implements CommandExecutor {
|
||||
public class UnavailableCommand implements CommandExecutor {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
@ -34,11 +34,12 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public abstract class Countdown {
|
||||
|
||||
private int time;
|
||||
private final BukkitTask task;
|
||||
protected int time;
|
||||
private final Sound sound;
|
||||
private final boolean level;
|
||||
|
||||
private BukkitTask task = null;
|
||||
|
||||
abstract String countdownCounting();
|
||||
abstract void countdownFinished();
|
||||
|
||||
@ -46,8 +47,6 @@ public abstract class Countdown {
|
||||
this.time = time;
|
||||
this.sound = getSound(sound);
|
||||
this.level = level;
|
||||
|
||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 0, 20);
|
||||
}
|
||||
|
||||
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() {
|
||||
task.cancel();
|
||||
if(task != null){
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcast(String message){
|
||||
@ -80,7 +86,13 @@ public abstract class Countdown {
|
||||
BasicListener.toActionbar(p, msg);
|
||||
}
|
||||
|
||||
public int getTimeLeft(){
|
||||
return time;
|
||||
}
|
||||
|
||||
void count(){
|
||||
time--;
|
||||
|
||||
switch (time) {
|
||||
case 900: case 600: case 300: case 180: case 120:
|
||||
broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting());
|
||||
@ -106,14 +118,8 @@ public abstract class Countdown {
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if(this.level)
|
||||
Fight.setLevel(time);
|
||||
|
||||
time--;
|
||||
onTime(time);
|
||||
}
|
||||
|
||||
void onTime(int time){
|
||||
//Implemented in some countdowns
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(time));
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,9 @@ public class EnternCountdown extends Countdown {
|
||||
private List<TechHider.ChunkPos> chunkPos;
|
||||
|
||||
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;
|
||||
enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,13 +53,9 @@ public class EnternCountdown extends Countdown {
|
||||
|
||||
@Override
|
||||
void count(){
|
||||
if(!fightPlayer.isLiving()){
|
||||
disable();
|
||||
return;
|
||||
}
|
||||
time--;
|
||||
|
||||
Player player = fightPlayer.getPlayer();
|
||||
int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage());
|
||||
switch (time) {
|
||||
case 900: case 600: case 300: case 180: case 120:
|
||||
BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()));
|
||||
|
@ -20,12 +20,19 @@
|
||||
package de.steamwar.fightsystem.countdown;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
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() {
|
||||
super(Config.NoPlayerOnlineDuration, null, false);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +44,9 @@ public class NoPlayersOnlineCountdown extends Countdown {
|
||||
public void countdownFinished() {
|
||||
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.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() {
|
||||
super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +44,9 @@ public class PreRunningCountdown extends Countdown {
|
||||
public void countdownFinished() {
|
||||
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.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
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() {
|
||||
super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,13 +42,11 @@ public class PreSchemPasteCountdown extends Countdown {
|
||||
|
||||
@Override
|
||||
void countdownFinished() {
|
||||
checkTeam(Fight.getBlueTeam());
|
||||
checkTeam(Fight.getRedTeam());
|
||||
FightSystem.setPostSchemState();
|
||||
}
|
||||
|
||||
private void checkTeam(FightTeam team){
|
||||
if(!team.hasSchematic())
|
||||
team.pasteDummy();
|
||||
@Override
|
||||
public Set<FightState> enabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
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() {
|
||||
super(Config.SetupDuration, null, false);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +44,9 @@ public class SetupOverCountdown extends Countdown {
|
||||
public void countdownFinished() {
|
||||
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.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() {
|
||||
super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +44,9 @@ public class SpectateOverCountdown extends Countdown {
|
||||
public void countdownFinished() {
|
||||
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) {
|
||||
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
|
||||
this.team = team;
|
||||
enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,11 +25,15 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class TimeOverCountdown extends Countdown {
|
||||
|
||||
private static TimeOverCountdown instance = null;
|
||||
|
||||
private final Runnable timeOver;
|
||||
|
||||
public TimeOverCountdown(Runnable timeOver) {
|
||||
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
|
||||
this.timeOver = timeOver;
|
||||
instance = this;
|
||||
enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,8 +47,9 @@ public class TimeOverCountdown extends Countdown {
|
||||
timeOver.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
void onTime(int time) {
|
||||
FightSystem.setFightTime(time);
|
||||
public static int getRemainingTime(){
|
||||
if(instance == null)
|
||||
return -1;
|
||||
return instance.getTimeLeft();
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,8 @@ import java.util.logging.Level;
|
||||
public class 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);
|
||||
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 int schemRank;
|
||||
private 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 blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader);
|
||||
|
||||
public static void init(){
|
||||
IFight.init(redTeam, blueTeam);
|
||||
@ -99,10 +98,6 @@ public class Fight {
|
||||
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) {
|
||||
if(redTeam.getName().equalsIgnoreCase(name))
|
||||
return redTeam;
|
||||
@ -112,11 +107,8 @@ public class Fight {
|
||||
}
|
||||
|
||||
public static void replaceSync() {
|
||||
Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
||||
Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
||||
|
||||
Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
||||
Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
||||
redTeam.replaceSync();
|
||||
blueTeam.replaceSync();
|
||||
}
|
||||
|
||||
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
||||
@ -159,33 +151,26 @@ public class Fight {
|
||||
|
||||
public static int getMaxRank(){
|
||||
/* MaxRank of 0 is Pubonly*/
|
||||
return schemRank;
|
||||
}
|
||||
|
||||
public static void calcAvailibleSchemTypes() {
|
||||
if(Config.OnlyPublicSchematics){
|
||||
schemRank = 0;
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
|
||||
schemRank = 1000;
|
||||
return;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null ||
|
||||
blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){
|
||||
schemRank = 1000;
|
||||
return;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
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() ||
|
||||
Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty())
|
||||
schemRank = 0;
|
||||
return 0;
|
||||
else
|
||||
schemRank = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int schemRank(FightPlayer fightPlayer){
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
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.kit.Kit;
|
||||
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FightPlayer {
|
||||
@ -32,22 +32,41 @@ public class FightPlayer {
|
||||
private boolean isOut;
|
||||
private Kit kit;
|
||||
private int kills;
|
||||
private EnternCountdown enternCountdown = null;
|
||||
|
||||
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) {
|
||||
this.player = player;
|
||||
this.team = team;
|
||||
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;
|
||||
}
|
||||
|
||||
public void setOut() {
|
||||
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() {
|
||||
@ -84,8 +103,8 @@ public class FightPlayer {
|
||||
}
|
||||
|
||||
public boolean canEntern(){
|
||||
if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0)
|
||||
if(enternCountdown == null)
|
||||
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;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.comms.packets.TablistNamePacket;
|
||||
import de.steamwar.core.VersionedRunnable;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
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.record.RecordSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.ColorConverter;
|
||||
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||
import de.steamwar.fightsystem.utils.ItemBuilder;
|
||||
import de.steamwar.fightsystem.utils.TechHider;
|
||||
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
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.PlayerInventory;
|
||||
import org.bukkit.scoreboard.NameTagVisibility;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -67,7 +53,7 @@ public class FightTeam implements IFightTeam{
|
||||
private final String name;
|
||||
private final String prefix;
|
||||
private final ChatColor color;
|
||||
private int schematic = 0;
|
||||
private FightSchematic schematic;
|
||||
private final Team team;
|
||||
private final boolean blue;
|
||||
|
||||
@ -92,6 +78,7 @@ public class FightTeam implements IFightTeam{
|
||||
this.cornerX = cornerX;
|
||||
this.cornerY = cornerY;
|
||||
this.cornerZ = cornerZ;
|
||||
this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, cornerX, cornerY, cornerZ, rotate);
|
||||
this.blue = blue;
|
||||
this.designatedLeader = designatedLeader;
|
||||
color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
|
||||
@ -168,7 +155,7 @@ public class FightTeam implements IFightTeam{
|
||||
|
||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||
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(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build());
|
||||
if(!Config.test())
|
||||
@ -187,7 +174,7 @@ public class FightTeam implements IFightTeam{
|
||||
team.removeEntry(player.getName());
|
||||
fightPlayer.getPlayer().getInventory().clear();
|
||||
|
||||
if(fightPlayer.equals(leader) && FightSystem.getFightState().setup())
|
||||
if(fightPlayer.equals(leader) && FightState.setup())
|
||||
setLeader(null);
|
||||
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
@ -231,9 +218,11 @@ public class FightTeam implements IFightTeam{
|
||||
if(ready)
|
||||
setReady(false);
|
||||
|
||||
leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
|
||||
if(!Config.PersonalKits)
|
||||
leader.setKit(Kit.getKitByName(Config.LeaderDefault));
|
||||
|
||||
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());
|
||||
else if(Config.PersonalKits)
|
||||
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());
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@ -260,68 +249,12 @@ public class FightTeam implements IFightTeam{
|
||||
}
|
||||
|
||||
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)
|
||||
leader.getPlayer().getInventory().clear(0);
|
||||
}
|
||||
|
||||
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!");
|
||||
|
||||
if(!Config.test())
|
||||
@ -334,14 +267,18 @@ public class FightTeam implements IFightTeam{
|
||||
}
|
||||
}
|
||||
|
||||
public void setNotPastingSchem(Schematic schematic){
|
||||
this.schematic.setSchematic(schematic);
|
||||
}
|
||||
|
||||
public boolean hasSchematic(){
|
||||
return schematic != 0;
|
||||
return schematic.hasSchematic();
|
||||
}
|
||||
|
||||
public void setReady(boolean ready) {
|
||||
Player l = leader.getPlayer();
|
||||
|
||||
if(schematic == 0){
|
||||
if(!schematic.hasSchematic()){
|
||||
l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
|
||||
return;
|
||||
}
|
||||
@ -375,7 +312,7 @@ public class FightTeam implements IFightTeam{
|
||||
}
|
||||
|
||||
public int getSchematic() {
|
||||
return schematic;
|
||||
return schematic.getId();
|
||||
}
|
||||
|
||||
public Location getSpawn() {
|
||||
@ -399,47 +336,14 @@ public class FightTeam implements IFightTeam{
|
||||
|
||||
public void loadKits(){
|
||||
for(FightPlayer fightPlayer : players.values()) {
|
||||
if(fightPlayer.getPlayer() == null)
|
||||
continue;
|
||||
fightPlayer.getPlayer().getInventory().clear();
|
||||
|
||||
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());
|
||||
fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
void replaceSync() {
|
||||
schematic.replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT);
|
||||
schematic.replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK);
|
||||
}
|
||||
|
||||
private void setTeamColor(Team team, ChatColor color){
|
||||
@ -449,44 +353,7 @@ public class FightTeam implements IFightTeam{
|
||||
new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
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){
|
||||
this.enabled = enabled;
|
||||
FightSystem.registerStateDependent(this);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
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){
|
||||
if(FightSystem.getFightState() != FightState.PRE_RUNNING)
|
||||
if(FightState.getFightState() != FightState.PRE_RUNNING)
|
||||
return;
|
||||
|
||||
for(FightPlayer fp : team.getPlayers()){
|
||||
@ -222,6 +222,6 @@ public class EventRecordListener extends BasicListener {
|
||||
|
||||
private boolean isNotSent(Player 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;
|
||||
case "§eKit bearbeiten":
|
||||
case "§eKit wählen":
|
||||
GUI.kitSelection(player);
|
||||
GUI.kitSelection(player, "");
|
||||
break;
|
||||
case "§eRespawn":
|
||||
player.teleport(fightTeam.getSpawn());
|
||||
|
@ -19,25 +19,16 @@
|
||||
|
||||
package de.steamwar.fightsystem.listener;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.kit.Kit;
|
||||
import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.fight.Kit;
|
||||
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.SteamwarUser;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
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.PlayerQuitEvent;
|
||||
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.logging.Level;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PersonalKitCreator extends BasicListener {
|
||||
|
||||
@ -63,85 +53,10 @@ public class PersonalKitCreator extends BasicListener {
|
||||
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){
|
||||
if(!enabled.contains(FightSystem.getFightState()))
|
||||
return;
|
||||
|
||||
player.closeInventory();
|
||||
new InventoryBackup(player, kit);
|
||||
|
||||
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();
|
||||
new Kit(kit).loadToPlayer(player);
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
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();
|
||||
//Deny bad items
|
||||
if(isBadItem(e.getCursor(), player))
|
||||
if(Kit.isBadItem(e.getCursor()))
|
||||
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
|
||||
@ -198,97 +126,28 @@ public class PersonalKitCreator extends BasicListener {
|
||||
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 final Player player;
|
||||
private final ItemStack[] contents;
|
||||
private final ItemStack[] armor;
|
||||
private final PersonalKit kit;
|
||||
private final Kit backup;
|
||||
|
||||
private InventoryBackup(Player player, PersonalKit kit){
|
||||
openKitCreators.put(player, this);
|
||||
this.player = player;
|
||||
this.contents = player.getInventory().getContents();
|
||||
this.armor = player.getInventory().getArmorContents();
|
||||
this.backup = new Kit("backup", player);
|
||||
this.kit = kit;
|
||||
}
|
||||
|
||||
private void loadBackup(){
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
inventory.setContents(contents);
|
||||
inventory.setArmorContents(armor);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
private void close(){
|
||||
openKitCreators.remove(player);
|
||||
kit.setContainer(removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents()));
|
||||
loadBackup();
|
||||
Kit kit1 = new Kit(kit.getName(), player);
|
||||
kit1.removeBadItems();
|
||||
kit1.toPersonalKit(kit);
|
||||
backup.loadToPlayer(player);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
useKit(player, 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;
|
||||
kit.setInUse();
|
||||
player.closeInventory();
|
||||
Objects.requireNonNull(Fight.getFightPlayer(player)).setKit(new Kit(kit));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class PlayerMoveListener extends BasicListener {
|
||||
if(to.getY() <= Config.underArenaBorder) {
|
||||
if(player.getGameMode() == GameMode.SPECTATOR || team == null)
|
||||
reset(event, DENY_ARENA);
|
||||
else if(FightSystem.getFightState().infight())
|
||||
else if(FightState.getFightState().infight())
|
||||
player.damage(2);
|
||||
else if(!Config.GroundWalkable)
|
||||
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);
|
||||
} else {
|
||||
player.teleport(fightTeam.getSpawn());
|
||||
if(FightSystem.getFightState().setup())
|
||||
if(FightState.setup())
|
||||
Fight.setPlayerGamemode(player, GameMode.SURVIVAL);
|
||||
else
|
||||
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
|
||||
@ -103,13 +103,12 @@ public class PlayerStateListener extends BasicListener{
|
||||
if(fightTeam == null)
|
||||
return;
|
||||
|
||||
FightState fightState = FightSystem.getFightState();
|
||||
if(fightState.setup()){
|
||||
if(FightState.setup()){
|
||||
fightTeam.removePlayer(player);
|
||||
|
||||
if(Config.recording())
|
||||
RecordSystem.entityDespawns(player);
|
||||
}else if(fightState.ingame()){
|
||||
}else if(FightState.ingame()){
|
||||
FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
|
||||
if(fightPlayer.isLiving()) {
|
||||
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/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
package de.steamwar.fightsystem.listener;
|
||||
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import org.bukkit.block.Block;
|
||||
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 {
|
||||
private WaterRemover(){}
|
||||
public class WaterRemover extends BasicListener {
|
||||
|
||||
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
|
||||
|
||||
public static void add(List<Block> l) {
|
||||
for(Block b : l){
|
||||
public WaterRemover() {
|
||||
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
|
||||
|
||||
checkBlock(b.getRelative(BlockFace.UP));
|
||||
@ -43,8 +52,10 @@ public class WaterRemover {
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkBlock(Block b) {
|
||||
if(!removeWater(b))
|
||||
private void checkBlock(Block 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;
|
||||
|
||||
if(b.getY() < MIN_Y)
|
||||
@ -61,10 +72,4 @@ public class WaterRemover {
|
||||
return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8),
|
||||
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(){
|
||||
tick();
|
||||
|
||||
if(FightSystem.getFightState() == FightState.SPECTATE)
|
||||
if(FightState.getFightState() == FightState.SPECTATE)
|
||||
return;
|
||||
|
||||
for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){
|
||||
|
@ -19,39 +19,70 @@
|
||||
|
||||
package de.steamwar.fightsystem.states;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public enum FightState {
|
||||
PRE_LEADER_SETUP(true, true, false, false),
|
||||
PRE_SCHEM_SETUP(true, true, false, false),
|
||||
POST_SCHEM_SETUP(true, true, false, false),
|
||||
PRE_RUNNING(false, false, true, false),
|
||||
RUNNING(false, false, true, true),
|
||||
SPECTATE(false, true, false, false);
|
||||
PRE_LEADER_SETUP,
|
||||
PRE_SCHEM_SETUP,
|
||||
POST_SCHEM_SETUP,
|
||||
PRE_RUNNING,
|
||||
RUNNING,
|
||||
SPECTATE;
|
||||
|
||||
private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP
|
||||
private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE
|
||||
private final boolean ingame; //PRE_RUNNING, RUNNING
|
||||
private final boolean infight; //RUNNING
|
||||
public static Set<FightState> SETUP = EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP);
|
||||
public static Set<FightState> INGAME = EnumSet.of(PRE_RUNNING, RUNNING);
|
||||
public static Set<FightState> ALL = EnumSet.allOf(FightState.class);
|
||||
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){
|
||||
this.setup = setup;
|
||||
this.outgame = outgame;
|
||||
this.ingame = ingame;
|
||||
this.infight = infight;
|
||||
private static final Map<StateDependent, Boolean> stateDependentFeatures = new HashMap<>();
|
||||
private static FightState fightState = PRE_LEADER_SETUP;
|
||||
|
||||
public static FightState getFightState() {
|
||||
return fightState;
|
||||
}
|
||||
|
||||
public boolean setup(){
|
||||
return setup;
|
||||
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();
|
||||
}
|
||||
|
||||
public boolean outgame(){
|
||||
return outgame;
|
||||
public static void setFightState(FightState state){
|
||||
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(){
|
||||
return ingame;
|
||||
public static boolean setup(){
|
||||
return SETUP.contains(fightState);
|
||||
}
|
||||
|
||||
public boolean infight(){
|
||||
return infight;
|
||||
public static boolean ingame(){
|
||||
return INGAME.contains(fightState);
|
||||
}
|
||||
|
||||
public static boolean infight(){
|
||||
return fightState == RUNNING;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
@ -29,15 +28,13 @@ import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EnterHandler implements StateDependent {
|
||||
private static final Set<FightState> enabled = EnumSet.of(FightState.RUNNING);
|
||||
private static final Set<EnternCountdown> countdowns = new HashSet<>();
|
||||
private static final Set<FightState> enabled = EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING);
|
||||
|
||||
public EnterHandler(){
|
||||
FightSystem.registerStateDependent(this);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,13 +42,6 @@ public class EnterHandler implements StateDependent {
|
||||
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
|
||||
public void enable() {
|
||||
registerTeam(Fight.getBlueTeam());
|
||||
@ -60,9 +50,20 @@ public class EnterHandler implements StateDependent {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
for(EnternCountdown countdown : countdowns){
|
||||
countdown.disable();
|
||||
unregisterTeam(Fight.getBlueTeam());
|
||||
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.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.record.RecordSystem;
|
||||
@ -44,7 +45,7 @@ public class FightScoreboard {
|
||||
private static String title = "";
|
||||
private static final HashMap<String, Integer> scores = new HashMap<>();
|
||||
|
||||
public static void init(){
|
||||
static {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200);
|
||||
}
|
||||
|
||||
@ -84,8 +85,8 @@ public class FightScoreboard {
|
||||
title = "§6Kampf";
|
||||
if(Config.recording())
|
||||
RecordSystem.scoreboardTitle(title);
|
||||
if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) {
|
||||
int fightTime = FightSystem.getFightTime();
|
||||
int fightTime = TimeOverCountdown.getRemainingTime();
|
||||
if (fightTime != -1) {
|
||||
if (fightTime >= 60)
|
||||
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
||||
else
|
||||
@ -94,7 +95,7 @@ public class FightScoreboard {
|
||||
|
||||
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
||||
|
||||
if(fullScoreboard.contains(FightSystem.getFightState())){
|
||||
if(fullScoreboard.contains(FightState.getFightState())){
|
||||
if (Config.PercentSystem){
|
||||
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);
|
||||
@ -120,9 +121,9 @@ public class FightScoreboard {
|
||||
index = 0;
|
||||
FightTeam team = null;
|
||||
if(index == 1)
|
||||
team = Fight.redTeam;
|
||||
team = Fight.getRedTeam();
|
||||
if(index == 2)
|
||||
team = Fight.blueTeam;
|
||||
team = Fight.getBlueTeam();
|
||||
scores.clear();
|
||||
if(team != null)
|
||||
teamScoreboard(team);
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
|
||||
|
||||
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.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
@ -76,7 +77,7 @@ public class FightStatistics {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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.WrappedBlockData;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.VersionedRunnable;
|
||||
import de.steamwar.core.VersionedCallable;
|
||||
import de.steamwar.core.events.ChunkListener;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.IFightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
|
||||
public class TechHider {
|
||||
private TechHider(){}
|
||||
public class TechHider implements StateDependent {
|
||||
|
||||
private static boolean running = false;
|
||||
private static final boolean DISABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive;
|
||||
|
||||
public static void init(){
|
||||
if(disabled())
|
||||
private final Set<FightState> enabled;
|
||||
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;
|
||||
|
||||
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
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
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
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
@ -76,133 +89,136 @@ public class TechHider {
|
||||
});
|
||||
}
|
||||
|
||||
public static void start(){
|
||||
if(running)
|
||||
return;
|
||||
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));
|
||||
@Override
|
||||
public Set<FightState> enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private static void multiBlockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
@Override
|
||||
public void enable() {
|
||||
protocolManager.addPacketListener(blockHider);
|
||||
protocolManager.addPacketListener(multiBlockHider);
|
||||
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();
|
||||
ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0);
|
||||
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
||||
return;
|
||||
@Override
|
||||
public void disable() {
|
||||
protocolManager.removePacketListener(blockHider);
|
||||
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);
|
||||
if(cached != null){
|
||||
e.setPacket(cached);
|
||||
return;
|
||||
}
|
||||
private final PacketAdapter multiBlockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
|
||||
cached = packet.shallowClone();
|
||||
ITechHider.packetCache.put(packet, cached);
|
||||
Player p = e.getPlayer();
|
||||
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);
|
||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
||||
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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||
@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;
|
||||
|
||||
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);
|
||||
cached = packet.shallowClone();
|
||||
ITechHider.packetCache.put(packet, cached);
|
||||
e.setPacket(cached);
|
||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
||||
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);
|
||||
blockStructure.write(0, block);
|
||||
mbci.setData(block);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockActionHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(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);
|
||||
if(changed){
|
||||
blockStructure.write(0, changes);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static void updateBlockEntity(){
|
||||
if(Core.getVersion() < 9)
|
||||
return;
|
||||
private final PacketAdapter blockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||
@Override
|
||||
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) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||
return;
|
||||
|
||||
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);
|
||||
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())){
|
||||
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){
|
||||
if(disabled())
|
||||
if(DISABLED)
|
||||
return Collections.emptyList();
|
||||
List<ChunkPos> chunksToReload = new ArrayList<>();
|
||||
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){
|
||||
if(disabled())
|
||||
if(DISABLED)
|
||||
return;
|
||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
||||
for(ChunkPos chunk : chunksToReload){
|
||||
@ -223,10 +239,6 @@ public class TechHider {
|
||||
}, 40);
|
||||
}
|
||||
|
||||
private static boolean disabled(){
|
||||
return Config.OnlyPublicSchematics || Config.test() || !Config.TechhiderActive;
|
||||
}
|
||||
|
||||
public static class ChunkPos{
|
||||
final int x;
|
||||
final int z;
|
||||
|
@ -42,7 +42,7 @@ public class EventTeamOffWincondition extends Wincondition {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
//Team off is a on time trigger
|
||||
//Team off is a one time trigger
|
||||
}
|
||||
|
||||
private void teamOff(FightTeam team){
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
|
||||
@ -32,7 +31,7 @@ abstract class Wincondition implements StateDependent {
|
||||
Wincondition(boolean condition, Set<FightState> enabled){
|
||||
this.enabled = enabled;
|
||||
if(condition)
|
||||
FightSystem.registerStateDependent(this);
|
||||
FightState.registerStateDependent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,7 +55,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
|
||||
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
|
||||
bluePercent = destroyPercent;
|
||||
if(destroyPercent >= Config.PercentWin) {
|
||||
FightSystem.setSpectateState(Fight.redTeam, "Percent");
|
||||
FightSystem.setSpectateState(Fight.getRedTeam(), "Percent");
|
||||
}
|
||||
//Team Red
|
||||
}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;
|
||||
redPercent = destroyPercent;
|
||||
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.FightSystem;
|
||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
@ -114,7 +115,7 @@ public class WinconditionRelativePercent extends Wincondition{
|
||||
|
||||
private int currentBlocks(){
|
||||
// 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;
|
||||
|
||||
int blocks = 0;
|
||||
|
@ -23,8 +23,8 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.WaterRemover;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren