style: reformat project

This commit is contained in:
darksaid98 committed 2024-02-03 06:13:15 +01:00
1 parent eecff93f3f
commit 038b94f01d
28 files changed
+135 -115

No files matched your search

@@ -1,10 +1,10 @@
package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.enums.CommandArgsSiege;
import com.github.alathra.AlathranWars.enums.CommandArgsWar;
import com.github.alathra.AlathranWars.hooks.TownyHook;
@@ -648,7 +648,8 @@ public class CommandUtil {
}
if (AlathranWars.getInstance().getConfig().getInt("minimumPlayTime") > 0) {
//check playtime, if its less than min its true
if (playTicks < (AlathranWars.getInstance().getConfig().getInt("minimumPlayTime") * (60 * 60 * 20))) out = 2;
if (playTicks < (AlathranWars.getInstance().getConfig().getInt("minimumPlayTime") * (60 * 60 * 20)))
out = 2;
}
return out;
@@ -1,10 +1,10 @@
package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -8,15 +8,20 @@ import java.util.UUID;
public interface Battle {
void start(); // Initiates battle
void stop(); // Ends battle
void resume(); // Resume battle after server restart or plugin reload
void attackersWin(BattleVictoryReason reason); // A Attacker victory
void defendersWin(BattleVictoryReason reason); // A Defender victory
void equalWin(BattleVictoryReason reason); // A Draw
UUID uuid = null; // Battle UUID
default @NotNull UUID getUUID() {
return uuid;
}
@@ -42,6 +47,7 @@ public interface Battle {
}
BattleType battleType = null;
default BattleType getBattleType() {
return battleType;
}
@@ -34,7 +34,10 @@ import org.bukkit.scheduler.BukkitRunnable;
import space.arim.morepaperlib.scheduling.ScheduledTask;
import java.time.Duration;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -164,7 +167,7 @@ public abstract class Laser {
/**
* Gets laser status.
*
* @return <code>true</code> if the laser is currently running
* @return <code>true</code> if the laser is currently running
* (i.e. {@link #start} has been called and the duration is not over)
*/
public boolean isStarted() {
@@ -161,7 +161,7 @@ class Packets {
ColorParser.of("Laser reflection failed to initialize. The utility is disabled. Please ensure your version (<version>) is supported.")
.parseMinimessagePlaceholder("version", Bukkit.getServer().getClass().getPackage().getName())
.build()
, e);
, e);
}
}
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.conflict.battle.raid;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
import com.github.alathra.AlathranWars.enums.battle.*;
import com.github.alathra.AlathranWars.events.battle.BattleResultEvent;
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.conflict.battle.siege;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
import com.github.alathra.AlathranWars.enums.battle.*;
@@ -25,7 +25,9 @@ import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -164,6 +166,7 @@ public class Siege implements Battle {
/**
* Stop a battle in favor of the attackers
*
* @param reason what triggered the end
*/
public void attackersWin(BattleVictoryReason reason) {
@@ -191,6 +194,7 @@ public class Siege implements Battle {
/**
* Stop a battle in favor of the defenders
*
* @param reason what triggered the end
*/
public void defendersWin(BattleVictoryReason reason) {
@@ -206,6 +210,7 @@ public class Siege implements Battle {
/**
* End a battle in favor of no one
*
* @param reason what triggered the end
*/
public void equalWin(BattleVictoryReason reason) {
@@ -606,38 +611,38 @@ public class Siege implements Battle {
.filter(p -> p.isConnected() && !attackers.contains(p))
.collect(Collectors.toSet())
.forEach(p -> {
// TODO Player left battlefield
// TODO Player left battlefield
}
);
}
);
// Entering attackers
attackers.stream()
.filter(p -> p.isConnected() && !previousAttackersOnBattlefield.contains(p))
.collect(Collectors.toSet())
.forEach(p -> {
// TODO Player entered battlefield
// TODO Player entered battlefield
}
);
}
);
// Leaving defenders
previousDefendersOnBattlefield.stream()
.filter(p -> p.isConnected() && !defenders.contains(p))
.collect(Collectors.toSet())
.forEach(p -> {
// TODO Player left battlefield
// TODO Player left battlefield
}
);
}
);
// Entering defenders
defenders.stream()
.filter(p -> p.isConnected() && !previousDefendersOnBattlefield.contains(p))
.collect(Collectors.toSet())
.forEach(p -> {
// TODO Player entered battlefield
}
);
// TODO Player entered battlefield
}
);
}
}
@@ -3,8 +3,8 @@ package com.github.alathra.AlathranWars.conflict.battle.siege;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.battle.beam.CrystalLaser;
import com.github.alathra.AlathranWars.conflict.battle.beam.Laser;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import com.github.alathra.AlathranWars.enums.CaptureProgressDirection;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -1,6 +1,7 @@
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.*;
import com.github.alathra.AlathranWars.conflict.Conflict;
import com.github.alathra.AlathranWars.conflict.Occupation;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.side.SideCreationException;
import com.github.alathra.AlathranWars.enums.ConflictType;
import com.palmergames.bukkit.towny.object.Government;
import com.palmergames.bukkit.towny.object.Nation;
@@ -28,17 +28,18 @@ public class WarBuilder {
private Government aggressor;
private Government victim;
public WarBuilder() {}
public WarBuilder() {
}
public War resume() {
if (
uuid == null ||
name == null ||
label == null ||
side1 == null ||
side2 == null ||
sieges == null ||
raids == null
name == null ||
label == null ||
side1 == null ||
side2 == null ||
sieges == null ||
raids == null
) {
throw new IllegalStateException();
}
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.conflict.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.db.DatabaseQueries;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
@@ -28,7 +28,8 @@ public class SideBuilder {
private Instant siegeGrace;
private Instant raidGrace;
public SideBuilder() {}
public SideBuilder() {
}
public Side rebuild() throws SideCreationException {
// if (warUUID == null || uuid == null || town == null || side == null || team == null || name == null ||
@@ -45,8 +46,8 @@ public class SideBuilder {
if (side == null
) throw new IllegalStateException("Missing state to create Side 1.1");
if ( team == null || name == null ||
towns == null || nations == null
if (team == null || name == null ||
towns == null || nations == null
) throw new IllegalStateException("Missing state to create Side 1");
if (playersIncludingOffline == null ||
@@ -30,23 +30,23 @@ public enum DatabaseType {
* MariaDB database type.
*/
MARIADB("MariaDB", org.mariadb.jdbc.Driver.class.getName(), MariaDbDataSource.class.getName(), "mariadb", '?', '&'),
;
;
private final String driverName;
private final String driverClassName;
private final String dataSourceClassName;
private final String jdbcPrefix;
private final char jdbcPropertyPrefix;
private final char jdbcPropertySeparator;
private final String dataSourceClassName;
private final String jdbcPrefix;
private final char jdbcPropertyPrefix;
private final char jdbcPropertySeparator;
DatabaseType(String driverName, String driverClassName, String dataSourceClassName, String jdbcPrefix, char jdbcPropertyPrefix, char jdbcPropertySeparator) {
this.driverName = driverName;
this.driverClassName = driverClassName;
this.dataSourceClassName = dataSourceClassName;
DatabaseType(String driverName, String driverClassName, String dataSourceClassName, String jdbcPrefix, char jdbcPropertyPrefix, char jdbcPropertySeparator) {
this.driverName = driverName;
this.driverClassName = driverClassName;
this.dataSourceClassName = dataSourceClassName;
this.jdbcPrefix = jdbcPrefix;
this.jdbcPropertyPrefix = jdbcPropertyPrefix;
this.jdbcPropertySeparator = jdbcPropertySeparator;
}
this.jdbcPropertyPrefix = jdbcPropertyPrefix;
this.jdbcPropertySeparator = jdbcPropertySeparator;
}
/**
* Gets driver name.
@@ -109,14 +109,14 @@ public enum DatabaseType {
* @return the string
*/
public String formatJdbcConnectionProperties(Map<String, Object> properties) {
if (properties.isEmpty()) return "";
if (properties.isEmpty()) return "";
List<String> connectionProperties = properties.entrySet().stream()
.map(map -> "%s=%s".formatted(map.getKey(), map.getValue()))
.toList();
return jdbcPropertyPrefix + String.join(Character.toString(jdbcPropertySeparator), connectionProperties);
}
return jdbcPropertyPrefix + String.join(Character.toString(jdbcPropertySeparator), connectionProperties);
}
/**
@@ -130,7 +130,8 @@ public enum DatabaseType {
for (DatabaseType type : DatabaseType.values()) {
if (type.equals(prefix.toLowerCase())) {
return type;
};
}
;
}
return null;
@@ -14,24 +14,24 @@ import java.util.regex.Pattern;
* Utility class for getting jOOQ Context to use with HikariCP.
*/
public final class JooqContext {
static {
JooqLogger.globalThreshold(Log.Level.ERROR); // Silence JOOQ warnings
}
static {
JooqLogger.globalThreshold(Log.Level.ERROR); // Silence JOOQ warnings
}
private static final String TABLE_PREFIX = Cfg.get().getOrDefault("db.prefix", "example_"); // The table prefix as grabbed from config
private static final Pattern MATCH_ALL_EXCEPT_INFORMATION_SCHEMA = Pattern.compile("^(?!INFORMATION_SCHEMA)(.*?)$");
private static final Pattern MATCH_ALL = Pattern.compile("^(.*?)$");
private static final String REPLACEMENT = "%s$0".formatted(TABLE_PREFIX); //
private final SQLDialect dialect;
private static final String TABLE_PREFIX = Cfg.get().getOrDefault("db.prefix", "example_"); // The table prefix as grabbed from config
private static final Pattern MATCH_ALL_EXCEPT_INFORMATION_SCHEMA = Pattern.compile("^(?!INFORMATION_SCHEMA)(.*?)$");
private static final Pattern MATCH_ALL = Pattern.compile("^(.*?)$");
private static final String REPLACEMENT = "%s$0".formatted(TABLE_PREFIX); //
private final SQLDialect dialect;
/**
* Instantiates a new Jooq context.
*
* @param dialect the getSQLDialect
* @param dialect the getSQLDialect
*/
public JooqContext(SQLDialect dialect) {
this.dialect = dialect;
}
this.dialect = dialect;
}
/**
* Create DSL Context.
@@ -40,53 +40,54 @@ public final class JooqContext {
* @return the dsl context
*/
public DSLContext createContext(Connection connection) {
record SimpleConnectionProvider(Connection connection) implements ConnectionProvider {
record SimpleConnectionProvider(Connection connection) implements ConnectionProvider {
@Override
public Connection acquire() throws DataAccessException {
return connection;
}
@Override
public Connection acquire() throws DataAccessException {
return connection;
}
@Override
public void release(Connection connection) throws DataAccessException {}
}
return createWith(new SimpleConnectionProvider(connection));
}
@Override
public void release(Connection connection) throws DataAccessException {
}
}
return createWith(new SimpleConnectionProvider(connection));
}
/**
/**
* Applies default configuration
*
* @param connectionProvider A connection lifecycle handler API.
* @return DSLContext
*/
private DSLContext createWith(ConnectionProvider connectionProvider) {
return new DefaultConfiguration()
.set(connectionProvider)
.set(dialect)
.set(createSettings())
.set(new ExecuteListenerProvider[0])
.dsl();
}
private DSLContext createWith(ConnectionProvider connectionProvider) {
return new DefaultConfiguration()
.set(connectionProvider)
.set(dialect)
.set(createSettings())
.set(new ExecuteListenerProvider[0])
.dsl();
}
/**
* Returns base settings for DSL Contexts.
*
* @return Settings
*/
private Settings createSettings() {
return new Settings()
.withBackslashEscaping(BackslashEscaping.OFF)
.withRenderSchema(false)
.withRenderMapping(new RenderMapping() // Support the tables having custom prefix
.withSchemata(new MappedSchema()
.withInputExpression(MATCH_ALL_EXCEPT_INFORMATION_SCHEMA)
.withTables(new MappedTable()
.withInputExpression(MATCH_ALL)
.withOutput(REPLACEMENT)
)
)
)
private Settings createSettings() {
return new Settings()
.withBackslashEscaping(BackslashEscaping.OFF)
.withRenderSchema(false)
.withRenderMapping(new RenderMapping() // Support the tables having custom prefix
.withSchemata(new MappedSchema()
.withInputExpression(MATCH_ALL_EXCEPT_INFORMATION_SCHEMA)
.withTables(new MappedTable()
.withInputExpression(MATCH_ALL)
.withOutput(REPLACEMENT)
)
)
)
.withRenderQuotedNames(RenderQuotedNames.ALWAYS)
.withRenderNameCase(RenderNameCase.LOWER);
}
}
}
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.enums.battle.BattleVictor;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import org.bukkit.event.Event;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import com.github.alathra.AlathranWars.enums.battle.BattleVictor;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.events.battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.Battle;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.utility.Utils;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.items;
import com.github.alathra.AlathranWars.AlathranWars;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.enums.battle.BattleSide;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.enums.battle.BattleType;
import com.github.alathra.AlathranWars.enums.battle.BattleVictoryReason;
import com.github.alathra.AlathranWars.events.battle.BattleResultEvent;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.palmergames.bukkit.towny.event.NationAddTownEvent;
import com.palmergames.bukkit.towny.event.NationPreRenameEvent;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.war;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.conflict.war.War;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.war.side.Side;
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.event.TownAddResidentEvent;
@@ -1,7 +1,7 @@
package com.github.alathra.AlathranWars.utility;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.conflict.war.WarController;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Location;
import org.bukkit.Material;