Skip to content

Commit

Permalink
feat: port changes from SBW 0.2.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Nov 30, 2024
1 parent aad855d commit ba31f5c
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public interface ItemSpawner extends Upgrade {
/**
* @return
*/
ItemSpawnerType getItemSpawnerType();
ItemSpawnerTypeHolder getItemSpawnerType();

void setItemSpawnerType(ItemSpawnerType spawnerType);
void setItemSpawnerType(ItemSpawnerTypeHolder spawnerType);

/**
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public interface ItemSpawnerType {
* @return
*/
ItemStackHolder getItem(int amount);

/**
* @since 0.3.0
*/
ItemSpawnerTypeHolder toHolder();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.screamingsandals.bedwars.api.game;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.screamingsandals.bedwars.api.variants.Variant;

/**
* @since 0.3.0
*/
public interface ItemSpawnerTypeHolder {
/**
* @since 0.3.0
*/
@NotNull String configKey();

/**
* @since 0.3.0
*/
@Nullable ItemSpawnerType toSpawnerType(@NotNull LocalGame variant);

/**
* @since 0.3.0
*/
@Nullable ItemSpawnerType toSpawnerType(@Nullable Variant variant);

/**
* @since 0.3.0
*/
default boolean isValid(@NotNull LocalGame game) {
return toSpawnerType(game) != null;
}

/**
* @since 0.3.0
*/
default boolean isValid(@Nullable Variant variant) {
return toSpawnerType(variant) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public List<Upgrade> findItemSpawnerUpgrades(LocalGame game, Team team, ItemSpaw
}

final var name = itemSpawner.getTeam();
if (name != null && team.getName().equals(name.getName()) && itemSpawnerType.getName().equals(itemSpawner.getItemSpawnerType().getName())) {
final var type = itemSpawner.getItemSpawnerType().toSpawnerType(game);
if (name != null && type != null && team.getName().equals(name.getName()) && itemSpawnerType.getName().equals(type.getName())) {
upgrades.add(upgrade);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.screamingsandals.bedwars.api.variants;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.screamingsandals.bedwars.api.config.GameConfigurationContainer;
Expand All @@ -32,6 +33,7 @@
* @author ScreamingSandals
* @since 0.3.0
*/
@ApiStatus.NonExtendable
public interface Variant {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void construct(Command.Builder<CommandSender> commandSenderWrapperBuil
"pos2", locationToMap(game.getPos2()),
"weather", game.getArenaWeather() != null ? game.getArenaWeather().location().asString() : null,
"spawners", game.getSpawners().stream().map(itemSpawner -> nullValuesAllowingMap(
"type", itemSpawner.getItemSpawnerType().getConfigKey(),
"type", itemSpawner.getItemSpawnerType().configKey(),
"location", locationToMap(itemSpawner.getLocation()),
"maxSpawnedResources", itemSpawner.getMaxSpawnedResources(),
"startLevel", itemSpawner.getBaseAmountPerSpawn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.screamingsandals.bedwars.lang.LangKeys;
import org.screamingsandals.lib.lang.Message;
import org.screamingsandals.lib.sender.CommandSender;
import org.screamingsandals.lib.spectator.Color;
import org.screamingsandals.lib.spectator.Component;
import org.screamingsandals.lib.spectator.event.ClickEvent;
import org.screamingsandals.lib.utils.annotations.Service;
Expand Down Expand Up @@ -240,9 +241,11 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
spawnerTeam = Message.of(LangKeys.ADMIN_INFO_SPAWNER_NO_TEAM).asComponent(sender);
}

var spawnerType = spawner.getItemSpawnerType().toSpawnerType(game);

Message
.of(LangKeys.ADMIN_INFO_SPAWNER)
.placeholder("resource", spawner.getItemSpawnerType().getItemName())
.placeholder("resource", spawnerType == null ? Component.text(spawner.getItemSpawnerType().configKey(), Color.RED) : spawnerType.getItemName())
.placeholder("x", loc_spawner.getBlockX())
.placeholder("y", loc_spawner.getBlockY())
.placeholder("z", loc_spawner.getBlockZ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.screamingsandals.lib.lang.Message;
import org.screamingsandals.lib.player.Player;
import org.screamingsandals.lib.sender.CommandSender;
import org.screamingsandals.lib.spectator.Color;
import org.screamingsandals.lib.spectator.Component;
import org.screamingsandals.lib.spectator.event.ClickEvent;
import org.screamingsandals.lib.tasker.TaskerTime;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
loc = loc.withYaw(0).withPitch(0);
var spawnerType = game.getGameVariant().getItemSpawnerType(type);
if (spawnerType != null) {
game.getSpawners().add(new ItemSpawnerImpl(loc, spawnerType));
game.getSpawners().add(new ItemSpawnerImpl(loc, spawnerType.toHolder()));
sender.sendMessage(
Message
.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_ADDED)
Expand Down Expand Up @@ -145,7 +146,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setMaxSpawnedResources(amount);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_MAX_SPAWNED_RESOURCES_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("amount", amount)
.defaultPrefix()
);
Expand All @@ -162,7 +163,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setRotationMode(rotationMode);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_ROTATION_MODE_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("rotation", rotationMode.name())
.defaultPrefix()
);
Expand All @@ -183,9 +184,9 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
var spawnerType = game.getGameVariant().getItemSpawnerType(type);
if (spawnerType != null) {
var old = itemSpawner.getItemSpawnerType();
itemSpawner.setItemSpawnerType(spawnerType);
itemSpawner.setItemSpawnerType(spawnerType.toHolder());
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_TYPE_CHANGED)
.placeholder("type", old.getItemName())
.placeholder("type", old.toSpawnerType(game).getItemName())
.placeholder("new_type", spawnerType.getItemName())
.defaultPrefix()
);
Expand All @@ -208,7 +209,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
itemSpawner.setCustomName(customName);
}
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_CUSTOM_NAME_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("name", customName)
.defaultPrefix()
);
Expand All @@ -225,7 +226,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setHologramType(type);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_HOLOGRAM_TYPE_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("type", type.name())
.defaultPrefix()
);
Expand Down Expand Up @@ -255,12 +256,12 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
itemSpawner.setTeam(team);
if (team == null) {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_TEAM_UNLINKED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.defaultPrefix()
);
} else {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_TEAM_LINKED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("team", team.getName())
.defaultPrefix()
);
Expand All @@ -278,7 +279,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setBaseAmountPerSpawn(amount);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_BASE_AMOUNT_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("amount", amount)
.defaultPrefix()
);
Expand All @@ -296,10 +297,10 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
itemSpawner.setFloatingBlockEnabled(enabled);
if (enabled) {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_FLOATING_ENABLED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName()).defaultPrefix());
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName()).defaultPrefix());
} else {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_FLOATING_DISABLED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName()).defaultPrefix());
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName()).defaultPrefix());
}
}))
);
Expand All @@ -316,10 +317,10 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
itemSpawner.setHologramEnabled(enabled);
if (enabled) {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_HOLOGRAM_ENABLED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName()).defaultPrefix());
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName()).defaultPrefix());
} else {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_HOLOGRAM_DISABLED)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName()).defaultPrefix());
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName()).defaultPrefix());
}
}))
);
Expand All @@ -336,7 +337,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setInitialInterval(Pair.of(value, unit));
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_INITIAL_INTERVAL_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("interval", value)
.placeholder("unit", Message.of(LangKeys.toUnitLangKey(unit, value != 1)))
.defaultPrefix()
Expand All @@ -352,7 +353,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
.handler(commandContext -> changeSettingCommand(commandContext, (sender, game, itemSpawner) -> {
itemSpawner.setInitialInterval(null);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_INITIAL_INTERVAL_RESET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.defaultPrefix());
}))
);
Expand All @@ -367,7 +368,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com

itemSpawner.setCustomSpread(spread);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_SPREAD_SET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.placeholder("spread", spread)
.defaultPrefix());
}))
Expand All @@ -381,7 +382,7 @@ public void construct(CommandManager<CommandSender> manager, Command.Builder<Com
.handler(commandContext -> changeSettingCommand(commandContext, (sender, game, itemSpawner) -> {
itemSpawner.setCustomSpread(null);
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SPAWNER_SPREAD_RESET)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", itemSpawner.getItemSpawnerType().toSpawnerType(game).getItemName())
.defaultPrefix());
}))
);
Expand Down Expand Up @@ -424,7 +425,7 @@ private void changeSettingCommand(CommandContext<CommandSender> commandContext,
.filter(spawner -> spawner.getLocation().getBlock().equals(loc.getBlock()))
.collect(Collectors.toList());

if (spawners.size() == 0) {
if (spawners.isEmpty()) {
sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_ERRORS_NO_SPAWNER).defaultPrefix());
} else if (spawners.size() == 1) {
var itemSpawner = spawners.get(0);
Expand All @@ -441,8 +442,9 @@ private void changeSettingCommand(CommandContext<CommandSender> commandContext,
var rawInput = new ArrayList<>(commandContext.getRawInput());
rawInput.remove(rawInput.size() - 1);
var command = String.join(" ", rawInput) + " " + number.getAndIncrement();
var type = itemSpawner.getItemSpawnerType().toSpawnerType(game);
Message.of(LangKeys.ADMIN_ARENA_EDIT_ERRORS_MULTIPLE_SPAWNERS_LINE)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", type == null ? Component.text(itemSpawner.getItemSpawnerType().configKey(), Color.RED) : type.getItemName())
.placeholder("command", Component.text().content(command).clickEvent(ClickEvent.runCommand(command)))
.send(sender);
});
Expand All @@ -452,8 +454,9 @@ private void changeSettingCommand(CommandContext<CommandSender> commandContext,
AtomicInteger number = new AtomicInteger(1);
spawners.forEach(itemSpawner -> {
var command = commandContext.getRawInputJoined() + " " + number.getAndIncrement();
var type = itemSpawner.getItemSpawnerType().toSpawnerType(game);
Message.of(LangKeys.ADMIN_ARENA_EDIT_ERRORS_MULTIPLE_SPAWNERS_LINE)
.placeholder("type", itemSpawner.getItemSpawnerType().getItemName())
.placeholder("type", type == null ? Component.text(itemSpawner.getItemSpawnerType().configKey(), Color.RED) : type.getItemName())
.placeholder("command", Component.text().content(command).clickEvent(ClickEvent.runCommand(command)))
.send(sender);
});
Expand Down
Loading

0 comments on commit ba31f5c

Please sign in to comment.