Skip to content

Commit

Permalink
refactor: updates to API
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Feb 28, 2024
1 parent d3ac493 commit 43b37ee
Show file tree
Hide file tree
Showing 96 changed files with 813 additions and 854 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.screamingsandals.bedwars.api.utils.ColorChanger;
import org.screamingsandals.bedwars.api.utils.EventUtils;
import org.screamingsandals.bedwars.api.variants.VariantManager;
import org.screamingsandals.lib.api.Wrapper;

import java.util.List;

Expand All @@ -39,7 +38,7 @@
* @author ScreamingSandals
*/
@ApiStatus.NonExtendable
public interface BedwarsAPI extends Wrapper {
public interface BedwarsAPI {
/**
* <p>Retrieves the game manager instance.</p>
*
Expand Down
76 changes: 22 additions & 54 deletions api/src/main/java/org/screamingsandals/bedwars/api/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
package org.screamingsandals.bedwars.api;

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.lib.api.Wrapper;
import org.screamingsandals.lib.api.types.server.BlockHolder;
import org.screamingsandals.lib.api.types.server.BlockPlacementHolder;
import org.screamingsandals.lib.api.types.server.BlockSnapshotHolder;
import org.screamingsandals.lib.api.types.server.ChunkHolder;
import org.screamingsandals.lib.api.types.server.LocationHolder;

/**
* <p>Abstract region API.</p>
Expand All @@ -36,122 +40,86 @@ public interface Region {
* @return was the supplied location modified?
* @since 0.3.0
*/
boolean isLocationModifiedDuringGame(Object loc);

/**
* <p>Determines if the supplied location was modified during a BedWars game.</p>
*
* @param loc the location
* @return was the supplied location modified?
* @deprecated in favor of {@link Region#isLocationModifiedDuringGame(Object)}
*/
@Deprecated
default boolean isBlockAddedDuringGame(Object loc) {
return isLocationModifiedDuringGame(loc);
}
boolean isLocationModifiedDuringGame(LocationHolder loc);

/**
* <p>Marks a location for rollback.</p>
* <p>This should be used for restoring a broken block that was a part of the original world.</p>
*
* @param loc the location
* @param blockState old block state (BlockStateHolder or the platform impl)
* @param blockSnapshot old block state
* @since 0.3.0
*/
void markForRollback(Object loc, Object blockState);

/**
* <p>Marks a location for rollback.</p>
* <p>This should be used for restoring a broken block that was a part of the original world.</p>
*
* @param loc the location
* @param blockState old block state (BlockStateHolder or the platform impl)
* @deprecated in favor of {@link Region#markForRollback(Object, Object)}
*/
@Deprecated
default void putOriginalBlock(Object loc, Object blockState) {
markForRollback(loc, blockState);
}
void markForRollback(LocationHolder loc, BlockSnapshotHolder blockSnapshot);

/**
* <p>Schedules a location for removal (set to AIR) while rolling back.</p>
*
* @param loc the location
*/
void addBuiltDuringGame(Object loc);
void addBuiltDuringGame(LocationHolder loc);

/**
* <p>Schedules a location for removal (set to AIR) while rolling back.</p>
*
* @param loc the location
* @since 0.3.0
*/
void removeBuiltDuringGame(Object loc);

/**
* <p>Schedules a location for removal (set to AIR) while rolling back.</p>
*
* @param loc the location
* @deprecated in favor of {@link Region#removeBuiltDuringGame(Object)}
*/
@Deprecated
default void removeBlockBuiltDuringGame(Object loc) {
removeBuiltDuringGame(loc);
}
void removeBuiltDuringGame(LocationHolder loc);

/**
* <p>Checks if a material is a liquid.</p>
*
* @param material the material (BlockTypeHolder or the platform impl)
* @param blockHolder the material
* @return is the material a liquid?
*/
boolean isLiquid(Object material);
boolean isLiquid(BlockHolder blockHolder);

/**
* <p>Checks if a block state matches a bed block.</p>
*
* @param blockState the block state (BlockStateHolder or the platform impl)
* @param blockSnapshot the block state
* @return does the block state match a bed block?
*/
boolean isBedBlock(Object blockState);
boolean isBedBlock(BlockSnapshotHolder blockSnapshot);

/**
* <p>Checks if a block state matches a bed head block.</p>
*
* @param blockState the block state (BlockStateHolder or the platform impl)
* @param blockSnapshot the block state (BlockStateHolder or the platform impl)
* @return does the block state match a bed head block?
*/
boolean isBedHead(Object blockState);
boolean isBedHead(BlockSnapshotHolder blockSnapshot);

/**
* <p>Gets the bed's neighbor block (the second part of the bed) from the bed head block.</p>
*
* @param blockHead the bed head block
* @return the bed neighbor block
*/
Wrapper getBedNeighbor(Object blockHead);
BlockPlacementHolder getBedNeighbor(BlockPlacementHolder blockHead);

/**
* <p>Determines if anything was modified in the supplied chunk.</p>
*
* @param chunk the chunk
* @return was anything in the chunk modified?
*/
boolean isChunkUsed(Object chunk);
boolean isChunkUsed(ChunkHolder chunk);

/**
* <p>Checks if a block state matches a door block.</p>
*
* @param blockState the block state (BlockStateHolder or the platform impl)
* @param blockSnapshot the block state
* @return does the block state match a door block?
*/
boolean isDoorBlock(Object blockState);
boolean isDoorBlock(BlockSnapshotHolder blockSnapshot);

/**
* <p>Checks if a block state matches a bottom door block.</p>
*
* @param blockState the block state (BlockStateHolder or the platform impl)
* @param blockSnapshot the block state
* @return does the block state match a bottom door block?
*/
boolean isDoorBottomBlock(Object blockState);
boolean isDoorBottomBlock(BlockSnapshotHolder blockSnapshot);
}
19 changes: 10 additions & 9 deletions api/src/main/java/org/screamingsandals/bedwars/api/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.UnknownNullability;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.LocalGame;
import org.screamingsandals.bedwars.api.game.target.Target;
import org.screamingsandals.bedwars.api.player.BWPlayer;
import org.screamingsandals.lib.api.Wrapper;
import org.screamingsandals.lib.api.types.server.ContainerHolder;
import org.screamingsandals.lib.api.types.server.LocationHolder;

import java.util.List;

Expand All @@ -40,7 +41,7 @@ public interface Team {
*
* @return the game
*/
Game getGame();
LocalGame getGame();

/**
* <p>Gets the team's name.</p>
Expand All @@ -61,14 +62,14 @@ public interface Team {
*
* @return the spawn locations
*/
List<? extends Wrapper> getTeamSpawns();
List<? extends LocationHolder> getTeamSpawns();

/**
* <p>Gets one of the team's spawn locations.</p>
*
* @return the spawn location
*/
Wrapper getRandomSpawn();
LocationHolder getRandomSpawn();

/**
* Gets the team's target (e.g. block, countdown).
Expand All @@ -92,31 +93,31 @@ public interface Team {
*
* @return the team chest inventory
*/
Wrapper getTeamChestInventory();
ContainerHolder getTeamChestInventory();

/**
* <p>Adds a new team chest at the specified location.</p>
* <p>If a team chest is already present at the specified location, this method will fail silently (do nothing).</p>
*
* @param location the team chest location or block
*/
void addTeamChest(Object location);
void addTeamChest(LocationHolder location);

/**
* <p>Removes a team chest at the specified location.</p>
* <p>If a team chest is not present at the specified location, this method will fail silently (do nothing).</p>
*
* @param location the team chest location or block
*/
void removeTeamChest(Object location);
void removeTeamChest(LocationHolder location);

/**
* <p>Determines if a team chest is present at the specified location.</p>
*
* @param location the team chest location
* @return is a team chest present at the specified location?
*/
boolean isTeamChestRegistered(Object location);
boolean isTeamChestRegistered(LocationHolder location);

/**
* <p>Gets the amount of chests bound to this team.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.screamingsandals.lib.api.Wrapper;
import org.screamingsandals.lib.api.types.ComponentHolder;

/**
* @author ScreamingSandals
Expand All @@ -32,12 +33,12 @@ public interface BossBar extends StatusBar {
/**
* @return current message
*/
Wrapper getMessage();
ComponentHolder getMessage();

/**
* @param message
*/
void setMessage(@Nullable Object message);
void setMessage(@Nullable ComponentHolder message);

/**
* @return color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
package org.screamingsandals.bedwars.api.config;

import org.screamingsandals.bedwars.api.ArenaTime;

import java.util.List;
import org.screamingsandals.lib.api.types.server.ItemStackHolder;

/**
* @author ScreamingSandals
Expand Down Expand Up @@ -93,9 +92,9 @@ public interface GameConfigurationContainer extends ConfigurationContainer {
ConfigurationListKey<String> SIDEBAR_LOBBY_CONTENT = ConfigurationListKey.of(String.class, "sidebar", "lobby", "content");

ConfigurationKey<Boolean> GAME_START_ITEMS_ENABLED = ConfigurationKey.of(Boolean.class, "game-start-items", "enabled");
ConfigurationListKey<Object> GAME_START_ITEMS_ITEMS = ConfigurationListKey.of(Object.class, "game-start-items", "items"); // Object in API, registered as Item
ConfigurationListKey<Object> GAME_START_ITEMS_ITEMS = ConfigurationListKey.of(Object.class, "game-start-items", "items"); // Object in API, registered as Item, TODO switch to ItemStackHolder
ConfigurationKey<Boolean> PLAYER_RESPAWN_ITEMS_ENABLED = ConfigurationKey.of(Boolean.class, "player-respawn-items", "enabled");
ConfigurationListKey<Object> PLAYER_RESPAWN_ITEMS_ITEMS = ConfigurationListKey.of(Object.class, "player-respawn-items", "items"); // Object in API, registered as Item
ConfigurationListKey<Object> PLAYER_RESPAWN_ITEMS_ITEMS = ConfigurationListKey.of(Object.class, "player-respawn-items", "items"); // Object in API, registered as Item, TODO switch to ItemStackHolder

ConfigurationKey<Boolean> TARGET_BLOCK_RESPAWN_ANCHOR_FILL_ON_START = ConfigurationKey.of(Boolean.class, "target-block", "respawn-anchor", "fill-on-start");
ConfigurationKey<Boolean> TARGET_BLOCK_RESPAWN_ANCHOR_ENABLE_DECREASE = ConfigurationKey.of(Boolean.class, "target-block", "respawn-anchor", "enable-decrease");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@
package org.screamingsandals.bedwars.api.entities;

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.LocalGame;
import org.screamingsandals.lib.api.types.server.EntityHolder;

import java.util.List;
import java.util.Optional;

@ApiStatus.NonExtendable
public interface EntitiesManager {

List<? extends GameEntity> getEntities(Game game);
List<? extends GameEntity> getEntities(LocalGame game);

default boolean isEntityInGame(Object entity) {
default boolean isEntityInGame(EntityHolder entity) {
return getGameOfEntity(entity).isPresent();
}

Optional<? extends Game> getGameOfEntity(Object entity);
Optional<? extends LocalGame> getGameOfEntity(EntityHolder entity);

GameEntity addEntityToGame(Object entity, Game game);
GameEntity addEntityToGame(EntityHolder entity, LocalGame game);

void removeEntityFromGame(Object entity);
void removeEntityFromGame(EntityHolder entity);

void removeEntityFromGame(GameEntity entityObject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package org.screamingsandals.bedwars.api.entities;

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.lib.api.Wrapper;
import org.screamingsandals.bedwars.api.game.LocalGame;
import org.screamingsandals.lib.api.types.server.EntityHolder;

@ApiStatus.NonExtendable
public interface GameEntity {
Game getGame();
LocalGame getGame();

Wrapper getEntity();
EntityHolder getEntity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.BedwarsAPI;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.player.BWPlayer;
import org.screamingsandals.lib.api.Wrapper;

import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.BedwarsAPI;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.player.BWPlayer;
import org.screamingsandals.lib.api.Wrapper;

import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,27 @@

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.BedwarsAPI;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.LocalGame;
import org.screamingsandals.bedwars.api.player.BWPlayer;
import org.screamingsandals.bedwars.api.utils.EventUtils;
import org.screamingsandals.lib.api.Wrapper;
import org.screamingsandals.lib.api.types.server.ItemStackHolder;

import java.util.Map;
import java.util.function.Consumer;

@ApiStatus.NonExtendable
public interface ApplyPropertyToItemEvent {
Game getGame();
LocalGame getGame();

BWPlayer getPlayer();

Wrapper getStack();
ItemStackHolder getStack();

String getPropertyName();

// TODO - Special wrapper for ConfigurationNodes
Map<String, Object> getProperties();

/**
*
* @param stack wrapper or platform item
*/
void setStack(Object stack);
void setStack(ItemStackHolder stack);

static void handle(Object plugin, Consumer<ApplyPropertyToItemEvent> consumer) {
BedwarsAPI.getInstance().getEventUtils().handle(plugin, ApplyPropertyToItemEvent.class, consumer);
Expand Down
Loading

0 comments on commit 43b37ee

Please sign in to comment.