Skip to content

Commit

Permalink
feat: update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Sep 27, 2024
1 parent 8689409 commit 2cf748b
Show file tree
Hide file tree
Showing 27 changed files with 191 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .run/TowerDefenceServer.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<env name="ENABLE_TEST_MODE" value="true" />
</envs>
<option name="MAIN_CLASS_NAME" value="pink.zak.minestom.towerdefence.TowerDefenceServer" />
<module name="towerdefence.main" />
<module name="pink.zak.minestom.towerdefence.main" />
<option name="WORKING_DIRECTORY" value="run" />
<extension name="coverage">
<pattern>
Expand Down
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ repositories {
}

dependencies {
implementation("dev.emortal.minestom:core:eafe4f7") {
implementation("dev.emortal.minestom:core:80be174") {
exclude(group = "net.minestom", module = "minestom-snapshots")
}
implementation("net.minestom:minestom-snapshots:7e59603d5f")
implementation("dev.emortal.api:common-proto-sdk:15284aa")

implementation("dev.hollowcube:schem:1.0.1")
implementation("net.minestom:minestom-snapshots:d0754f2a15")
implementation("dev.emortal.api:common-proto-sdk:2584fd2")

implementation("dev.hollowcube:schem:1.2.0")
// Polar world format
implementation("dev.hollowcube:polar:1.7.2")
implementation("dev.hollowcube:polar:1.11.3")

implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")
}
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/pink/zak/minestom/towerdefence/enums/TowerSize.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
package pink.zak.minestom.towerdefence.enums;

import java.util.HashSet;
import java.util.Set;
import net.kyori.adventure.text.format.TextColor;
import net.minestom.server.collision.Shape;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.Material;
import net.minestom.server.network.packet.server.SendablePacket;
import net.minestom.server.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle;
import net.minestom.server.particle.data.DustParticleData;
import org.jetbrains.annotations.NotNull;
import pink.zak.minestom.towerdefence.model.tower.placed.PlacedTower;
import pink.zak.minestom.towerdefence.world.TowerDefenceInstance;

public enum TowerSize {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ private void shutdownTask() {

if (Environment.isProduction()) {
KurushimiMinestomUtils.sendToLobby(MinecraftServer.getConnectionManager().getOnlinePlayers(), () -> {
this.kubernetesModule.getSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
this.kubernetesModule.getAgonesSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
}, () -> {
for (Player player : MinecraftServer.getConnectionManager().getOnlinePlayers()) {
player.kick(Component.text("Server shutting down"));
}
this.kubernetesModule.getSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
this.kubernetesModule.getAgonesSdk().shutdown(AgonesSDKProto.Empty.getDefaultInstance(), new IgnoredStreamObserver<>());
});
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minestom.server.event.player.PlayerUseItemEvent;
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
import net.minestom.server.inventory.click.ClickType;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import pink.zak.minestom.towerdefence.api.event.player.PlayerTeamSwitchEvent;
Expand Down Expand Up @@ -105,26 +106,28 @@ private void updateTeamItems() {
private synchronized void updateTeamItem(Team team) {
Material material;
String name;
List<? extends Component> lore;
List<Component> lore;
if (team == Team.BLUE) {
material = Material.BLUE_WOOL;
name = "Blue Team (" + this.lobbyManager.getTeamSize(Team.BLUE).get() + "/6)";
lore = this.lobbyManager.getLobbyPlayers().stream()
.filter(lobbyPlayer -> lobbyPlayer.getTeam() == Team.BLUE)
.map(lobbyPlayer -> Component.text(" - " + lobbyPlayer.getPlayer().getUsername(), Style.style(NamedTextColor.AQUA, TextDecoration.ITALIC.withState(TextDecoration.State.FALSE))))
.map(c -> (Component) c)
.toList();
} else {
material = Material.RED_WOOL;
name = "Red Team (" + this.lobbyManager.getTeamSize(Team.RED).get() + "/6)";
lore = this.lobbyManager.getLobbyPlayers().stream()
.filter(lobbyPlayer -> lobbyPlayer.getTeam() == Team.RED)
.map(lobbyPlayer -> Component.text(" - " + lobbyPlayer.getPlayer().getUsername(), Style.style(NamedTextColor.RED, TextDecoration.ITALIC.withState(TextDecoration.State.FALSE))))
.map(c -> (Component) c)
.toList();
}

ItemStack teamItem = ItemStack.builder(material)
.displayName(Component.text(name, team.getColor()).decoration(TextDecoration.ITALIC, false))
.lore(lore)
.set(ItemComponent.CUSTOM_NAME, Component.text(name, team.getColor()).decoration(TextDecoration.ITALIC, false))
.set(ItemComponent.LORE, lore)
.build();

if (team == Team.BLUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import pink.zak.minestom.towerdefence.model.mob.statuseffect.StatusEffectType;
import pink.zak.minestom.towerdefence.utils.ItemUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class EnemyMob {
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();

Expand Down Expand Up @@ -51,7 +53,7 @@ public EnemyMob(@NotNull JsonObject jsonObject) {

ItemStack item = jsonObject.has("item") ? ItemUtils.fromJsonObject(jsonObject.get("item").getAsJsonObject(), null) : null;
if (item == null) {
this.baseItem = ItemStack.builder(Material.BARRIER).displayName(Component.text("No item set")).build();
this.baseItem = ItemStack.builder(Material.BARRIER).set(ItemComponent.CUSTOM_NAME, Component.text("No item set")).build();
} else {
EnemyMobLevel levelOne = this.levels.get(1);
List<Component> lore = new ArrayList<>();
Expand All @@ -61,8 +63,10 @@ public EnemyMob(@NotNull JsonObject jsonObject) {
lore.addAll(levelOne.generateDiff(levelOne).generateStatLines());

this.baseItem = item
.withDisplayName(MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME, Placeholder.unparsed("mob_name", this.commonName)))
.withLore(lore);
.with(builder -> {
builder.set(ItemComponent.CUSTOM_NAME, MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME, Placeholder.unparsed("mob_name", this.commonName)));
builder.set(ItemComponent.LORE, lore);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package pink.zak.minestom.towerdefence.model.mob.config;

import com.google.gson.JsonObject;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerFlag;
import net.minestom.server.entity.EntityType;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
Expand All @@ -21,6 +18,10 @@
import pink.zak.minestom.towerdefence.utils.ItemUtils;
import pink.zak.minestom.towerdefence.utils.NumberUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class EnemyMobLevel implements Diffable<EnemyMobLevel>, Comparable<EnemyMobLevel> {
private static final String SEND_ITEM_NAME = "<i:false><mob_name> <level_numeral>";
private static final String UPGRADE_ITEM_NAME = "<i:false><%s><level_numeral> - <yellow>$<cost></yellow>";
Expand Down Expand Up @@ -70,25 +71,18 @@ public EnemyMobLevel(@NotNull String name, @NotNull JsonObject jsonObject) {
}

public ItemStack createSendItem() {
return ItemStack.builder(this.sendItem.material())
.meta(this.sendItem.meta())
.displayName(MiniMessage.miniMessage().deserialize(SEND_ITEM_NAME,
Placeholder.unparsed("mob_name", this.name),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(this.sendCost))))
.lore(this.createStatLore())
.build();
}

public @NotNull ItemStack createPreviewItem() {
return ItemStack.builder(this.sendItem.material())
.meta(this.sendItem.meta())
.build();
return this.sendItem.with(builder -> {
builder.set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(SEND_ITEM_NAME,
Placeholder.unparsed("mob_name", this.name),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(this.sendCost))));
builder.set(ItemComponent.LORE, this.createStatLore());
});
}

public ItemStack createStatUpgradeItem(int cost, boolean canAfford, boolean owned) {
return ItemStack.builder(owned ? Material.GREEN_STAINED_GLASS_PANE : canAfford ? Material.ORANGE_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE)
.displayName(MiniMessage.miniMessage().deserialize(
.set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(
UPGRADE_ITEM_NAME.formatted(owned ? "green" : canAfford ? "gold" : "red"),
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(cost))))
Expand All @@ -100,7 +94,7 @@ public ItemStack createStatUpgradeItem(int cost, boolean canAfford, boolean owne
String itemName = UPGRADE_ITEM_NAME.formatted(canAfford ? "gold" : "red");

return ItemStack.builder(canAfford ? Material.ORANGE_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE)
.displayName(MiniMessage.miniMessage().deserialize(itemName,
.set(ItemComponent.CUSTOM_NAME, MiniMessage.miniMessage().deserialize(itemName,
Placeholder.unparsed("level_numeral", NumberUtils.toRomanNumerals(this.level)),
Placeholder.unparsed("cost", String.valueOf(cost))))
.lore(this.createUpgradeLore(currentLevel))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package pink.zak.minestom.towerdefence.model.mob.living;

import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.minestom.server.MinecraftServer;
import net.minestom.server.attribute.Attribute;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Metadata;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.damage.DamageType;
import net.minestom.server.entity.attribute.Attribute;
import net.minestom.server.entity.damage.Damage;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
import net.minestom.server.network.packet.server.play.EntityHeadLookPacket;
Expand Down Expand Up @@ -49,6 +40,16 @@
import pink.zak.minestom.towerdefence.utils.DirectionUtil;
import pink.zak.minestom.towerdefence.utils.TDEnvUtils;

import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ThreadLocalRandom;

public class SingleEnemyTDMob extends SingleTDMob implements LivingTDEnemyMob {
protected final MobHandler mobHandler;
protected final EnemyMob enemyMob;
Expand Down Expand Up @@ -108,7 +109,7 @@ public SingleEnemyTDMob(@NotNull GameHandler gameHandler, @NotNull EnemyMob enem

this.currentCornerLengthModifier = this.getRandomLengthModifier();

this.getAttribute(Attribute.MAX_HEALTH).setBaseValue(this.level.getHealth());
this.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(this.level.getHealth());
this.health = this.level.getHealth();

this.setCustomNameVisible(true);
Expand Down Expand Up @@ -251,7 +252,7 @@ public float damage(@NotNull DamageSource source, float value) {
if (sound != null) {
Sound.Source soundSource = Sound.Source.PLAYER;

SoundEffectPacket damageSoundPacket = new SoundEffectPacket(sound, null, soundSource, this.getPosition(), 1.0f, 1.0f, 0);
SoundEffectPacket damageSoundPacket = new SoundEffectPacket(sound, soundSource, this.getPosition(), 1.0f, 1.0f, 0);
this.sendPacketToViewersAndSelf(damageSoundPacket);
}

Expand All @@ -268,7 +269,7 @@ public void updateCustomName() {
}

@Override
public boolean damage(@NotNull DamageType type, float value) {
public boolean damage(@NotNull Damage damage) {
throw new UnsupportedOperationException("Use damage(DamageSource, float) instead");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package pink.zak.minestom.towerdefence.model.mob.living;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import net.kyori.adventure.text.Component;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityCreature;
Expand All @@ -14,6 +11,10 @@
import net.minestom.server.network.packet.server.play.EntityMetaDataPacket;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class SingleTDMob extends EntityCreature implements LivingTDMob {
private final int level;

Expand All @@ -27,6 +28,11 @@ public int getLevel() {
return this.level;
}

@Override
public float getMaxHealth() {
return 0; // todo idk what this is meant to be??
}

@Override
public void updateCustomName() {
for (Player player : this.getViewers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.minestom.server.coordinate.Point;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,6 +20,11 @@
import pink.zak.minestom.towerdefence.utils.StringUtils;
import pink.zak.minestom.towerdefence.world.TowerDefenceInstance;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class Tower {
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();

Expand Down Expand Up @@ -58,10 +60,10 @@ public Tower(@NotNull JsonObject jsonObject, @NotNull Map<Integer, JsonObject> l
.toList();

this.baseItem = this.item.with(builder -> {
builder.displayName(MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME,
builder.set(ItemComponent.CUSTOM_NAME, MINI_MESSAGE.deserialize(BASE_ITEM_DISPLAY_NAME,
Placeholder.unparsed("tower_name", this.name),
Placeholder.unparsed("tower_cost", String.valueOf(this.levels.get(1).getCost())))
);
Placeholder.unparsed("tower_cost", String.valueOf(this.levels.get(1).getCost()))
));

List<Component> description = new ArrayList<>();
description.add(Component.empty());
Expand All @@ -71,7 +73,7 @@ public Tower(@NotNull JsonObject jsonObject, @NotNull Map<Integer, JsonObject> l
.append(Component.text(this.type.getSize().getFormattedName(), NamedTextColor.YELLOW))
.decoration(TextDecoration.ITALIC, false));

builder.lore(description);
builder.set(ItemComponent.LORE, description);
});
}

Expand Down
Loading

0 comments on commit 2cf748b

Please sign in to comment.