Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ tasks {
options.compilerArgs.add("-Xlint:deprecation")
}
javadoc {
val options = options as StandardJavadocDocletOptions
options.docTitle = "HungerGames API - $projectVersion"
options.overview = "src/main/javadoc/overview.html"
options.encoding = Charsets.UTF_8.name()

exclude("com/shanebeestudios/hg/plugin/commands")
exclude("com/shanebeestudios/hg/plugin/listeners")
(options as StandardJavadocDocletOptions).links(
"https://jd.papermc.io/paper/1.21.5/",
"https://jd.advntr.dev/api/4.17.0/",
options.links(
"https://jd.papermc.io/paper/26.1.2/",
"https://jd.advntr.dev/api/4.25.0/",
"https://tr7zw.github.io/Item-NBT-API/v2-api/"
)

Expand Down
58 changes: 31 additions & 27 deletions src/main/java/com/shanebeestudios/hg/api/data/ItemData.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
package com.shanebeestudios.hg.api.data;

import com.shanebeestudios.hg.api.game.Game;
import com.shanebeestudios.hg.api.util.WeightedList;
import org.bukkit.inventory.ItemStack;

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

/**
* Holder of {@link ItemStack Items} for a {@link Game}
*/
public class ItemData {

private final Map<ChestType, List<ItemStack>> items = new HashMap<>();
private final Map<ChestType, Integer> count = new HashMap<>();
private final Map<ChestType, WeightedList<ItemStack>> weightedItems = new HashMap<>();

public ItemData() {
for (ChestType chestType : ChestType.values()) {
this.items.put(chestType, new ArrayList<>());
this.weightedItems.put(chestType, new WeightedList<>());
}
}

public void setItems(ChestType type, List<ItemStack> items) {
this.items.put(type, items);
}

public List<ItemStack> getItems(ChestType type) {
return this.items.get(type);
}

/**
* Set item count
* Add a weighted item to the item data.
*
* @param chestType ChestType to count
* @param itemCount Amount of items
* @param type Chest type
* @param item Item to add
* @param weight Weight of item
*/
public void setItemCount(ChestType chestType, int itemCount) {
this.count.put(chestType, itemCount);
public void addEntry(ChestType type, ItemStack item, int weight) {
this.weightedItems.get(type).add(item, weight);
}

/**
* Get item count by ChestType
* Get a random item.
*
* @param chestType ChestType to get count from
* @return AMount of items by ChestType
* @param type Type of chest
* @return Random item
*/
public int getItemCount(ChestType chestType) {
return this.count.get(chestType);
public ItemStack getRandomItem(ChestType type) {
return this.weightedItems.get(type).nextEntry();
}

public void setWeightedItems(ChestType type, WeightedList<ItemStack> weightedItems) {
this.weightedItems.put(type, weightedItems);
}

public WeightedList<ItemStack> getWeightedItems(ChestType type) {
return this.weightedItems.get(type);
}

/**
* Get total item count for all chest types
* Get the total item count for all chest types.
*
* @return Total item count
*/
public int getTotalItemCount() {
int count = 0;
for (int value : this.count.values()) {
count += value;
for (WeightedList<ItemStack> value : this.weightedItems.values()) {
count += value.size();
}
return count;
}

/**
* Represents the type of chests in game
* Represents the type of chests in a game.
* <p>Used for logging and refilling</p>
*/
public enum ChestType {
Expand Down Expand Up @@ -97,4 +100,5 @@ public String getName() {
return this.name;
}
}

}
40 changes: 17 additions & 23 deletions src/main/java/com/shanebeestudios/hg/api/data/MobData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.shanebeestudios.hg.api.data;

import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.ApiStatus;
import com.shanebeestudios.hg.api.util.WeightedList;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -12,8 +12,8 @@
public class MobData {

private final Random random = new Random();
private final List<MobEntry> dayMobs = new ArrayList<>();
private final List<MobEntry> nightMobs = new ArrayList<>();
private final WeightedList<MobEntry> dayMobs = new WeightedList<>();
private final WeightedList<MobEntry> nightMobs = new WeightedList<>();
private int mobCount;

/**
Expand All @@ -22,7 +22,7 @@ public class MobData {
* @return List of MobEntries
*/
public List<MobEntry> getDayMobs() {
return ImmutableList.copyOf(this.dayMobs);
return ImmutableList.copyOf(this.dayMobs.getEntries());
}

/**
Expand All @@ -32,16 +32,17 @@ public List<MobEntry> getDayMobs() {
*/
public @Nullable MobEntry getRandomDayMob() {
if (this.dayMobs.isEmpty()) return null;
return this.dayMobs.get(this.random.nextInt(this.dayMobs.size()));
return this.dayMobs.nextEntry();
}

/**
* Add a new mob entry to the day mobs
*
* @param mobEntry Mob entry to add
* @param weight Weight of mob entry
*/
public void addDayMob(MobEntry mobEntry) {
this.dayMobs.add(mobEntry);
public void addDayMob(MobEntry mobEntry, int weight) {
this.dayMobs.add(mobEntry, weight);
}

/**
Expand All @@ -50,7 +51,7 @@ public void addDayMob(MobEntry mobEntry) {
* @return List of MobEntries
*/
public List<MobEntry> getNightMobs() {
return ImmutableList.copyOf(this.nightMobs);
return ImmutableList.copyOf(this.nightMobs.getEntries());
}

/**
Expand All @@ -60,24 +61,17 @@ public List<MobEntry> getNightMobs() {
*/
public @Nullable MobEntry getRandomNightMob() {
if (this.nightMobs.isEmpty()) return null;
return this.nightMobs.get(this.random.nextInt(this.nightMobs.size()));
return this.nightMobs.nextEntry();
}

/**
* Add a new mob entry to the night mobs
*
* @param mobEntry Mob entry to add
* @param weight Weight of mob entry
*/
public void addNightMob(MobEntry mobEntry) {
this.nightMobs.add(mobEntry);
}

/**
* @hidden
*/
@ApiStatus.Internal
public void setMobCount(int mobCount) {
this.mobCount = mobCount;
public void addNightMob(MobEntry mobEntry, int weight) {
this.nightMobs.add(mobEntry, weight);
}

/**
Expand All @@ -86,18 +80,18 @@ public void setMobCount(int mobCount) {
* @return Count of all mobs
*/
public int getMobCount() {
return this.mobCount;
return this.dayMobs.size() + this.nightMobs.size();
}

/**
* Get list of all MobEntries
* Get a list of all MobEntries
*
* @return List of MobEntries
*/
public List<MobEntry> getAllMobs() {
List<MobEntry> mobs = new ArrayList<>();
mobs.addAll(this.dayMobs);
mobs.addAll(this.nightMobs);
mobs.addAll(this.dayMobs.getEntries());
mobs.addAll(this.nightMobs.getEntries());
return mobs;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shanebeestudios/hg/api/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public void stop() {
*/
public void stop(boolean death) {
if (Config.WORLD_BORDER_ENABLED) {
this.gameBorderData.resetBorder();
this.gameBorderData.resetBorder(false);
}
this.gameEntityData.removeEntities();
this.gameScoreboard.resetSidebars();
Expand Down
60 changes: 44 additions & 16 deletions src/main/java/com/shanebeestudios/hg/api/game/GameBorderData.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.shanebeestudios.hg.api.game;

import com.shanebeestudios.hg.api.util.Util;
import com.shanebeestudios.hg.plugin.configs.Config;
import com.shanebeestudios.hg.plugin.tasks.WorldBorderTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.WorldBorder;
import org.bukkit.util.BoundingBox;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

Expand All @@ -18,7 +20,7 @@ public class GameBorderData extends Data {

private final Random random = new Random();
private boolean isDefault;
private Location centerLocation;
private final List<Location> centerLocations = new ArrayList<>();
private int finalBorderSize;
private int borderCountdownStart;
private int borderCountdownEnd;
Expand All @@ -32,11 +34,11 @@ public class GameBorderData extends Data {
this.isDefault = true;
}

GameBorderData(Game game, Location centerLocation, int finalSize, int start, int end) {
GameBorderData(Game game, Location centerLocations, int finalSize, int start, int end) {
super(game);
this.gamePlayerData = game.getGamePlayerData();
this.worldBorder = Bukkit.createWorldBorder();
this.centerLocation = centerLocation;
this.centerLocations.add(centerLocations);
this.finalBorderSize = finalSize;
this.borderCountdownStart = start;
this.borderCountdownEnd = end;
Expand All @@ -56,26 +58,34 @@ public WorldBorder getWorldBorder() {
* Initialize the {@link WorldBorder} of this game
*/
public void initialize() {
resetBorder();
resetBorder(true);
this.gamePlayerData.getPlayers().forEach(player -> player.setWorldBorder(this.worldBorder));
this.worldBorderTask = new WorldBorderTask(this.game);
}

/**
* Reset the {@link WorldBorder} of this game
*
* @param start Whether this is a game start or end reset
*/
public void resetBorder() {
public void resetBorder(boolean start) {
Location center;
GameArenaData gameArenaData = this.game.getGameArenaData();
List<Location> spawns = gameArenaData.getSpawns();
if (this.centerLocation != null) {
center = this.centerLocation;
} else {
if (this.centerLocations.isEmpty()) {
switch (Config.WORLD_BORDER_CENTER) { // 'first-spawn', 'random-spawn' and 'arena-center'
case "first-spawn" -> center = spawns.getFirst();
case "random-spawn" -> center = spawns.get(this.random.nextInt(spawns.size()));
default -> center = gameArenaData.getGameRegion().getCenter();
}
} else {
if (start) {
// If starting a new game, pick a random center location
center = this.centerLocations.get(this.random.nextInt(this.centerLocations.size()));
} else {
// If game is ending, reset to arena center
center = gameArenaData.getGameRegion().getCenter();
}
}
this.worldBorder.setCenter(center);

Expand Down Expand Up @@ -103,22 +113,40 @@ public void startShrinking(int closingIn) {
}

/**
* Set the center of the border of this game
* Add a center location to the border of this game
*
* @param centerLocation Location of the center
*/
public void setCenterLocation(Location centerLocation) {
this.centerLocation = centerLocation;
public void addCenterLocation(Location centerLocation) {
this.centerLocations.add(centerLocation);
}

/**
* Clear all center locations from the border of this game
*/
public void clearCenterLocations() {
this.centerLocations.clear();
}

/**
* Set the center of the border of this game
*
* @param centerLocations Location of the center
*/
public void setCenterLocations(List<Location> centerLocations) {
Util.log("Setting center locations for game border");
this.centerLocations.clear();
this.centerLocations.addAll(centerLocations);
this.isDefault = false;
}

/**
* Get the center location of the border
* Get a list of center locations of the border
*
* @return Center location
* @return Center locations
*/
public @Nullable Location getCenterLocation() {
return this.centerLocation;
public @NotNull List<Location> getCenterLocations() {
return this.centerLocations;
}

/**
Expand Down
Loading
Loading