Skip to content

Commit

Permalink
More reformatting + null checks in mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
PyPylia committed Sep 21, 2023
1 parent a271c93 commit 09bcba4
Show file tree
Hide file tree
Showing 57 changed files with 885 additions and 1,131 deletions.
39 changes: 11 additions & 28 deletions src/main/java/io/icker/factions/FactionsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,22 @@ public void onInitialize() {
}

private static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher,
CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> factions = CommandManager
.literal("factions")
.build();
CommandRegistryAccess registryAccess,
CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> factions =
CommandManager.literal("factions").build();

LiteralCommandNode<ServerCommandSource> alias = CommandManager
.literal("f")
.build();
LiteralCommandNode<ServerCommandSource> alias = CommandManager.literal("f").build();

dispatcher.getRoot().addChild(factions);
dispatcher.getRoot().addChild(alias);

Command[] commands = new Command[] {
new AdminCommand(),
new SettingsCommand(),
new ClaimCommand(),
new CreateCommand(),
new DeclareCommand(),
new DisbandCommand(),
new HomeCommand(),
new InfoCommand(),
new InviteCommand(),
new JoinCommand(),
new KickCommand(),
new LeaveCommand(),
new ListCommand(),
new MapCommand(),
new MemberCommand(),
new ModifyCommand(),
new RankCommand(),
new SafeCommand(),
new PermissionCommand()
};
Command[] commands = new Command[] {new AdminCommand(), new SettingsCommand(),
new ClaimCommand(), new CreateCommand(), new DeclareCommand(), new DisbandCommand(),
new HomeCommand(), new InfoCommand(), new InviteCommand(), new JoinCommand(),
new KickCommand(), new LeaveCommand(), new ListCommand(), new MapCommand(),
new MemberCommand(), new ModifyCommand(), new RankCommand(), new SafeCommand(),
new PermissionCommand()};

for (Command command : commands) {
factions.addChild(command.getNode());
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/icker/factions/api/events/ClaimEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ public final class ClaimEvents {
/**
* Called when a chunk claim is added by a faction (See {@link Claim})
*/
public static final Event<Add> ADD = EventFactory.createArrayBacked(Add.class, callbacks -> (claim) -> {
for (Add callback : callbacks) {
callback.onAdd(claim);
}
});
public static final Event<Add> ADD =
EventFactory.createArrayBacked(Add.class, callbacks -> (claim) -> {
for (Add callback : callbacks) {
callback.onAdd(claim);
}
});

/**
* Called when a faction removes a claim (See {@link Claim})
*/
public static final Event<Remove> REMOVE = EventFactory.createArrayBacked(Remove.class,
callbacks -> (x, z, level, faction) -> {
public static final Event<Remove> REMOVE =
EventFactory.createArrayBacked(Remove.class, callbacks -> (x, z, level, faction) -> {
for (Remove callback : callbacks) {
callback.onRemove(x, z, level, faction);
}
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/io/icker/factions/api/events/FactionEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public final class FactionEvents {
/**
* Called when a {@link Faction} is created
*/
public static final Event<Create> CREATE = EventFactory.createArrayBacked(Create.class,
callbacks -> (faction, user) -> {
public static final Event<Create> CREATE =
EventFactory.createArrayBacked(Create.class, callbacks -> (faction, user) -> {
for (Create callback : callbacks) {
callback.onCreate(faction, user);
}
Expand All @@ -23,8 +23,8 @@ public final class FactionEvents {
/**
* Called when a {@link Faction} is disbanded
*/
public static final Event<Disband> DISBAND = EventFactory.createArrayBacked(Disband.class,
callbacks -> (faction) -> {
public static final Event<Disband> DISBAND =
EventFactory.createArrayBacked(Disband.class, callbacks -> (faction) -> {
for (Disband callback : callbacks) {
callback.onDisband(faction);
}
Expand All @@ -33,8 +33,8 @@ public final class FactionEvents {
/**
* Called when a {@link User} joins a {@link Faction}
*/
public static final Event<MemberJoin> MEMBER_JOIN = EventFactory.createArrayBacked(MemberJoin.class,
callbacks -> (faction, user) -> {
public static final Event<MemberJoin> MEMBER_JOIN =
EventFactory.createArrayBacked(MemberJoin.class, callbacks -> (faction, user) -> {
for (MemberJoin callback : callbacks) {
callback.onMemberJoin(faction, user);
}
Expand All @@ -43,28 +43,28 @@ public final class FactionEvents {
/**
* Called when a {@link User} leaves a {@link Faction}
*/
public static final Event<MemberLeave> MEMBER_LEAVE = EventFactory.createArrayBacked(MemberLeave.class,
callbacks -> (faction, user) -> {
public static final Event<MemberLeave> MEMBER_LEAVE =
EventFactory.createArrayBacked(MemberLeave.class, callbacks -> (faction, user) -> {
for (MemberLeave callback : callbacks) {
callback.onMemberLeave(faction, user);
}
});

/**
* Called when a factions name, description, MOTD, color or open status is
* modified
* Called when a factions name, description, MOTD, color or open status is modified
*/
public static final Event<Modify> MODIFY = EventFactory.createArrayBacked(Modify.class, callbacks -> (faction) -> {
for (Modify callback : callbacks) {
callback.onModify(faction);
}
});
public static final Event<Modify> MODIFY =
EventFactory.createArrayBacked(Modify.class, callbacks -> (faction) -> {
for (Modify callback : callbacks) {
callback.onModify(faction);
}
});

/**
* Called when a factions power changes
*/
public static final Event<PowerChange> POWER_CHANGE = EventFactory.createArrayBacked(PowerChange.class,
callbacks -> (faction, oldPower) -> {
public static final Event<PowerChange> POWER_CHANGE =
EventFactory.createArrayBacked(PowerChange.class, callbacks -> (faction, oldPower) -> {
for (PowerChange callback : callbacks) {
callback.onPowerChange(faction, oldPower);
}
Expand All @@ -73,19 +73,19 @@ public final class FactionEvents {
/**
* Called when a faction sets its {@link Home}
*/
public static final Event<SetHome> SET_HOME = EventFactory.createArrayBacked(SetHome.class,
callbacks -> (faction, home) -> {
public static final Event<SetHome> SET_HOME =
EventFactory.createArrayBacked(SetHome.class, callbacks -> (faction, home) -> {
for (SetHome callback : callbacks) {
callback.onSetHome(faction, home);
}
});

/**
* Called when a faction removes all its claims. (Note that each claim will also
* run a {@link ClaimEvents} REMOVE event)
* Called when a faction removes all its claims. (Note that each claim will also run a
* {@link ClaimEvents} REMOVE event)
*/
public static final Event<RemoveAllClaims> REMOVE_ALL_CLAIMS = EventFactory.createArrayBacked(RemoveAllClaims.class,
callbacks -> (faction) -> {
public static final Event<RemoveAllClaims> REMOVE_ALL_CLAIMS =
EventFactory.createArrayBacked(RemoveAllClaims.class, callbacks -> (faction) -> {
for (RemoveAllClaims callback : callbacks) {
callback.onRemoveAllClaims(faction);
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/io/icker/factions/api/events/MiscEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
*/
public final class MiscEvents {
/**
* Called when the Factions database is saved (which is also when the server
* saves world and player files)
* Called when the Factions database is saved (which is also when the server saves world and
* player files)
*/
public static final Event<Save> ON_SAVE = EventFactory.createArrayBacked(Save.class, callbacks -> (server) -> {
for (Save callback : callbacks) {
callback.onSave(server);
}
});
public static final Event<Save> ON_SAVE =
EventFactory.createArrayBacked(Save.class, callbacks -> (server) -> {
for (Save callback : callbacks) {
callback.onSave(server);
}
});

/**
* Called when the game attempts to spawn in mobs (UNIMPLEMENTED)
*/
public static final Event<MobSpawnAttempt> ON_MOB_SPAWN_ATTEMPT = EventFactory
.createArrayBacked(MobSpawnAttempt.class, callbacks -> () -> {
public static final Event<MobSpawnAttempt> ON_MOB_SPAWN_ATTEMPT =
EventFactory.createArrayBacked(MobSpawnAttempt.class, callbacks -> () -> {
for (MobSpawnAttempt callback : callbacks) {
callback.onMobSpawnAttempt();
}
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/io/icker/factions/api/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class PlayerEvents {
/**
* Called when a player tries to interact with an entity
*/
public static final Event<UseEntity> USE_ENTITY = EventFactory.createArrayBacked(UseEntity.class,
callbacks -> (source, target, world) -> {
public static final Event<UseEntity> USE_ENTITY = EventFactory
.createArrayBacked(UseEntity.class, callbacks -> (source, target, world) -> {
for (UseEntity callback : callbacks) {
ActionResult result = callback.onUseEntity(source, target, world);
if (result != ActionResult.PASS) {
Expand All @@ -30,8 +30,8 @@ public class PlayerEvents {
return ActionResult.PASS;
});

public static final Event<PlaceBlock> PLACE_BLOCK = EventFactory.createArrayBacked(PlaceBlock.class,
callbacks -> (context) -> {
public static final Event<PlaceBlock> PLACE_BLOCK =
EventFactory.createArrayBacked(PlaceBlock.class, callbacks -> (context) -> {
for (PlaceBlock callback : callbacks) {
ActionResult result = callback.onPlaceBlock(context);
if (result != ActionResult.PASS) {
Expand All @@ -42,11 +42,10 @@ public class PlayerEvents {
});

/**
* Called when a player tries to use a block that has an inventory (uses the
* locking mechanism)
* Called when a player tries to use a block that has an inventory (uses the locking mechanism)
*/
public static final Event<UseInventory> USE_INVENTORY = EventFactory.createArrayBacked(UseInventory.class,
callbacks -> (source, pos, world) -> {
public static final Event<UseInventory> USE_INVENTORY = EventFactory
.createArrayBacked(UseInventory.class, callbacks -> (source, pos, world) -> {
for (UseInventory callback : callbacks) {
ActionResult result = callback.onUseInventory(source, pos, world);
if (result != ActionResult.PASS) {
Expand All @@ -59,8 +58,8 @@ public class PlayerEvents {
/**
* Called when a player is attacked and decides whether to allow the hit
*/
public static final Event<IsInvulnerable> IS_INVULNERABLE = EventFactory.createArrayBacked(IsInvulnerable.class,
callbacks -> (source, target) -> {
public static final Event<IsInvulnerable> IS_INVULNERABLE =
EventFactory.createArrayBacked(IsInvulnerable.class, callbacks -> (source, target) -> {
for (IsInvulnerable callback : callbacks) {
ActionResult result = callback.isInvulnerable(source, target);
if (result != ActionResult.PASS) {
Expand All @@ -73,17 +72,18 @@ public class PlayerEvents {
/**
* Called when a player moves
*/
public static final Event<Move> ON_MOVE = EventFactory.createArrayBacked(Move.class, callbacks -> (player) -> {
for (Move callback : callbacks) {
callback.onMove(player);
}
});
public static final Event<Move> ON_MOVE =
EventFactory.createArrayBacked(Move.class, callbacks -> (player) -> {
for (Move callback : callbacks) {
callback.onMove(player);
}
});

/**
* Called when a player is killed by another player
*/
public static final Event<KilledByPlayer> ON_KILLED_BY_PLAYER = EventFactory.createArrayBacked(KilledByPlayer.class,
callbacks -> (player, source) -> {
public static final Event<KilledByPlayer> ON_KILLED_BY_PLAYER =
EventFactory.createArrayBacked(KilledByPlayer.class, callbacks -> (player, source) -> {
for (KilledByPlayer callback : callbacks) {
callback.onKilledByPlayer(player, source);
}
Expand All @@ -92,8 +92,8 @@ public class PlayerEvents {
/**
* Called on a power reward will be given
*/
public static final Event<PowerTick> ON_POWER_TICK = EventFactory.createArrayBacked(PowerTick.class,
callbacks -> (player) -> {
public static final Event<PowerTick> ON_POWER_TICK =
EventFactory.createArrayBacked(PowerTick.class, callbacks -> (player) -> {
for (PowerTick callback : callbacks) {
callback.onPowerTick(player);
}
Expand All @@ -102,8 +102,8 @@ public class PlayerEvents {
/**
* Called when a player attempts to open a safe
*/
public static final Event<OpenSafe> OPEN_SAFE = EventFactory.createArrayBacked(OpenSafe.class,
callbacks -> (player, faction) -> {
public static final Event<OpenSafe> OPEN_SAFE =
EventFactory.createArrayBacked(OpenSafe.class, callbacks -> (player, faction) -> {
for (OpenSafe callback : callbacks) {
ActionResult result = callback.onOpenSafe(player, faction);
if (result != ActionResult.PASS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public final class RelationshipEvents {
/**
* When a faction is declared as a different status
*/
public static final Event<NewDecleration> NEW_DECLARATION = EventFactory.createArrayBacked(NewDecleration.class,
callbacks -> (relationship) -> {
public static final Event<NewDecleration> NEW_DECLARATION =
EventFactory.createArrayBacked(NewDecleration.class, callbacks -> (relationship) -> {
for (NewDecleration callback : callbacks) {
callback.onNewDecleration(relationship);
}
Expand All @@ -23,8 +23,8 @@ public final class RelationshipEvents {
*
* For example, mutual allies
*/
public static final Event<NewMutual> NEW_MUTUAL = EventFactory.createArrayBacked(NewMutual.class,
callbacks -> (relationship) -> {
public static final Event<NewMutual> NEW_MUTUAL =
EventFactory.createArrayBacked(NewMutual.class, callbacks -> (relationship) -> {
for (NewMutual callback : callbacks) {
callback.onNewMutual(relationship);
}
Expand All @@ -33,8 +33,8 @@ public final class RelationshipEvents {
/**
* When a mutual relationship is ended by either of the two factions
*/
public static final Event<EndMutual> END_MUTUAL = EventFactory.createArrayBacked(EndMutual.class,
callbacks -> (relationship, oldStatus) -> {
public static final Event<EndMutual> END_MUTUAL = EventFactory
.createArrayBacked(EndMutual.class, callbacks -> (relationship, oldStatus) -> {
for (EndMutual callback : callbacks) {
callback.onEndMutual(relationship, oldStatus);
}
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/io/icker/factions/api/persistents/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import io.icker.factions.api.events.ClaimEvents;
import io.icker.factions.api.persistents.User.Rank;
import io.icker.factions.database.Database;
Expand Down Expand Up @@ -42,8 +41,7 @@ public Claim(int x, int z, String level, UUID factionID) {
}

@SuppressWarnings("unused")
public Claim() {
}
public Claim() {}

public String getKey() {
return String.format("%s-%d-%d", level, x, z);
Expand All @@ -54,14 +52,12 @@ public static Claim get(int x, int z, String level) {
}

public static List<Claim> getByFaction(UUID factionID) {
return STORE.values()
.stream()
.filter(c -> c.factionID.equals(factionID))
.toList();
return STORE.values().stream().filter(c -> c.factionID.equals(factionID)).toList();
}

public static void audit() {
STORE.values().removeIf((claim) -> Faction.get(claim.factionID) == null || !WorldUtils.isValid(claim.level));
STORE.values().removeIf((claim) -> Faction.get(claim.factionID) == null
|| !WorldUtils.isValid(claim.level));
}

public static void add(Claim claim) {
Expand Down
Loading

0 comments on commit 09bcba4

Please sign in to comment.