Skip to content

Commit

Permalink
Added README
Browse files Browse the repository at this point in the history
Fixed order of players in `/itemrace leaderboard`
Ordered players in `/itemrace inventory` main menu
Moved `allow_damaged_tools` config option from `points` to `denylist`
Bumped version
  • Loading branch information
hopperelec committed Jul 30, 2024
1 parent ccb575f commit 03e4adb
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 17 deletions.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ItemRace is a Minecraft plugin for Paper servers that allows players to compete to get the most items. It is highly configurable, allowing it to be used for short events, long-term competitions, or just keeping track of what items players are getting!

## Default behaviour
*Keep in mind that this is only the default behavior and can be configured using the `config.yml` file created in the `ItemRace` directory when the plugin is enabled for the first time.
For example, you could make it so players are simply scored on the number of diamonds currently in their inventory and ender chest, or for every type of item they have had at least 3 of in their inventory at some point.*

Players must deposit items using `/itemrace deposit`, which will open up the deposit GUI for them to place items inside.

![Deposit GUI - Chest UI with title "Move all items to deposit here"](screenshots/deposit-gui.webp)

Players can deposit absolutely any item except for air. Once they close the deposit GUI, those items will move to their ItemRace inventory, which they cannot take items back out of.

Players can also deposit items directly into their ItemRace inventory using:
- `/itemrace deposit all`: deposit all items in their inventory with the same type as the item in their hand
- `/itemrace deposit inventory`: deposit all items in their inventory, regardless of type
- `/itemrace deposit (amount)`: deposit `amount` of the type of item in their hand from their inventory
- `/itemrace deposit (amount) (item)`: deposit `amount` of `item` from their inventory

Players are scored based on the items currently in their ItemRace inventory. Players will gain one point each time the amount of a type of item they have doubles. That is, they will get a point for their 1st, 2nd, 4th, 8th, 16th, 32nd, 64th, 128th... item of each type, with no limit. For example, if a player deposits 128 dirt and 4 cobblestone, they will earn 11 points (8 points for dirt and 3 points for cobblestone).

The current leaderboard can be viewed using `/itemrace leaderboard`

![ItemRace leaderboard shown in chat](screenshots/leaderboard-chat.webp)

or using the sidebar which can be toggled using `/itemrace togglescoreboard`.

![ItemRace leaderboard shown in sidebar](screenshots/scoreboard-sidebar.webp)

Players can view each other's ItemRace inventories using `/itemrace inventory`, which will open up a paginated GUI listing deposited items.

![Inventory GUI - Double chest with title "hopperelec's ItemRace inventory" and with two buttons on the bottom, one named "Next page"](screenshots/inventory-gui.webp)

From the inventory GUI, players can also access the main menu which will list other players to view the inventories of.

![Inventory GUI main menu - Double chest with title "ItemRace inventories" containing player skulls, one named "View Phantom_RX's ItemRace inventory"](screenshots/inventory-gui-mainmenu.webp)


## Point award modes
These are how the plugin chooses which items to award points for.

<details>
<summary>AUTO_DEPOSIT_ALL</summary>
<p>All items a player picks up are automatically moved into their ItemRace inventory, which they cannot take items out of.</p>
</details>
<details>
<summary>AUTO_DEPOSIT</summary>
<p>
Similar to AUTO_DEPOSIT_ALL but only items which the player can earn points for will be deposited.
This is only really useful if a denylist has been created
</p>
</details>
<details>
<summary>DEPOSIT_COMMAND</summary>
<p>
Similar to AUTO_DEPOSIT, but players choose which items to move to their ItemRace inventory using `/itemrace deposit`.
If no arguments are specified, the item in the player's hand is deposited.
</p>
</details>
<details>
<summary>DEPOSIT_GUI (default)</summary>
<p>
Similar to DEPOSIT_COMMAND except, if no arguments are specified, then an inventory GUI is opened.
Players can move any items they wish to deposit into that inventory.
</p>
</details>
<details>
<summary>MAX_INVENTORY</summary>
<p>Similar to AUTO_DEPOSIT, but players do not lose deposited items. Instead, their ItemRace inventory is based on the maximum amount of a given item they have held in their inventory at any time.</p>
</details>
<details>
<summary>INVENTORY</summary>
<p>Players are scored based on the items currently in their inventory.</p>
</details>
<details>
<summary>ENDER_CHEST</summary>
<p>Similar to INVENTORY, but also includes items in their ender chest.</p>
</details>

## ItemRace inventory persisting
For award modes which use the ItemRace inventory (which does not include INVENTORY or ENDER_CHEST), the plugin is able to persist (and auto-save at a configurable interval) the contents of each player's ItemRace inventory between server restarts. This data is saved to the file `plugins/ItemRace/deposited-items.yml`.

## Permissions
- **itemrace.admin:** Permission to use all ItemRace admin commands
- **itemrace.reset:** Allows resetting players' scores using `/itemrace reset [player]`
- **itemrace.deposit *(default)*:** Allows depositing items in MANUAL_DEPOSIT mode using `/itemrace deposit`
- **itemrace.inventory:** Allows viewing players' ItemRace inventories using `/itemrace inventory [player]`
- **itemrace.inventory.self *(default)*:** Allows viewing your own ItemRace inventory using `/itemrace inventory`
- **itemrace.leaderboard *(default)*:** Allows viewing the ItemRace leaderboard using `/itemrace leaderboard`
- **itemrace.togglescoreboard:** Allows toggling the scoreboard using `/itemrace togglescoreboard`
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>uk.co.hopperelec.mc</groupId>
<artifactId>itemrace</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>ItemRace</name>
Expand Down
Binary file added screenshots/deposit-gui.webp
Binary file not shown.
Binary file added screenshots/inventory-gui-mainmenu.webp
Binary file not shown.
Binary file added screenshots/inventory-gui.webp
Binary file not shown.
Binary file added screenshots/leaderboard-chat.webp
Binary file not shown.
Binary file added screenshots/scoreboard-sidebar.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uk.co.hopperelec.mc.itemrace.pointshandling.DepositedItems;
import uk.co.hopperelec.mc.itemrace.pointshandling.PointsAwardMode;

import java.util.Comparator;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -241,7 +242,7 @@ public void onLeaderboard(@NotNull CommandSender sender) {
int ownPosition = -1;
for (
Map.Entry<OfflinePlayer, Integer> score :
scores.entrySet().stream().sorted(Map.Entry.comparingByValue()).limit(10).toList()
scores.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(10).toList()
) {
if (score.getKey() == sender) ownPosition = positionI;
sender.sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ItemRaceConfig {
public final boolean awardPointForFirstItem;
public final int maxPointsPerItemType;
public final int maxItemsAwardedPoints; // Calculated
public final boolean allowDamagedTools;
// Inventory
public final boolean persistDepositedItems;
public final int autosaveFrequencyTicks;
Expand All @@ -31,34 +30,35 @@ public class ItemRaceConfig {
// Denylist
public final @NotNull ItemType @NotNull [] denylistItems;
public final boolean treatDenylistAsWhitelist;
public final boolean allowDamagedTools;

public ItemRaceConfig(
@NotNull PointsAwardMode pointsAwardMode,
int itemsPerPointGrowthRate,
boolean awardPointForFirstItem,
int maxPointsPerItemType,
boolean allowDamagedTools,
boolean persistDepositedItems,
int autosaveFrequencyTicks,
boolean defaultScoreboardState,
@NotNull DisplaySlot scoreboardDisplaySlot,
boolean splitItemsIntoStacks,
@NotNull ItemType @NotNull [] denylistItems,
boolean treatDenylistAsWhitelist
boolean treatDenylistAsWhitelist,
boolean allowDamagedTools
) {
this.pointsAwardMode = pointsAwardMode;
if (itemsPerPointGrowthRate < 1) throw new IllegalArgumentException("itemsPerPointGrowthRate must be at least 1");
this.itemsPerPointGrowthRate = itemsPerPointGrowthRate;
this.awardPointForFirstItem = awardPointForFirstItem;
this.maxPointsPerItemType = maxPointsPerItemType;
this.allowDamagedTools = allowDamagedTools;
this.persistDepositedItems = persistDepositedItems;
this.autosaveFrequencyTicks = autosaveFrequencyTicks;
this.defaultScoreboardState = defaultScoreboardState;
this.scoreboardDisplaySlot = scoreboardDisplaySlot;
this.splitItemsIntoStacks = splitItemsIntoStacks;
this.denylistItems = denylistItems;
this.treatDenylistAsWhitelist = treatDenylistAsWhitelist;
this.allowDamagedTools = allowDamagedTools;

maxItemsAwardedPoints =
maxPointsPerItemType < 0 ? Integer.MAX_VALUE : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public void init(@NotNull Player viewer, @NotNull InventoryContents contents) {
// Main menu
pagination.setItems(
plugin.pointsHandler.getEligiblePlayers().stream()
.map(player -> {
.sorted(Comparator.comparing(
player -> Objects.requireNonNull(player.getName()),
String.CASE_INSENSITIVE_ORDER
)).map(player -> {
final ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
final SkullMeta itemMeta = (SkullMeta) itemStack.getItemMeta();
final PlayerProfile playerProfile = player.getPlayerProfile();
Expand All @@ -114,7 +117,7 @@ public void init(@NotNull Player viewer, @NotNull InventoryContents contents) {
// Inventory menu
final List<ClickableItem> items = new ArrayList<>();
plugin.pointsHandler.getItems(player).entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.comparingInt(Integer::intValue).reversed()))
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEach(entry -> {
if (plugin.config.splitItemsIntoStacks)
for (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public ItemRacePlugin() throws IOException {
configFile.get("points").get("items_per_point_growth_rate").asInt(),
configFile.get("points").get("award_for_first_item").asBoolean(),
configFile.get("points").get("max_per_item_type").asInt(),
configFile.get("points").get("allow_damaged_tools").asBoolean(),
configFile.get("deposited_items").get("persist").asBoolean(),
(int)(configFile.get("deposited_items").get("autosave_frequency").asDouble() * 60 * 20),
configFile.get("scoreboard").get("default_state").asBoolean(),
Expand All @@ -67,7 +66,8 @@ public ItemRacePlugin() throws IOException {
.map(JsonNode::asText)
.map(ItemType::new)
.toArray(ItemType[]::new),
configFile.get("denylist").get("treat_as_allowlist").asBoolean()
configFile.get("denylist").get("treat_as_allowlist").asBoolean(),
configFile.get("denylist").get("allow_damaged_tools").asBoolean()
);

pointsHandler = switch (config.pointsAwardMode) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ points:
# players will be prevented from depositing more items than they can be awarded points for.
max_per_item_type: -1

# Whether damaged tools should count towards the total number of each tool a player has deposited (true/false)
# If this is false, players will not be able to deposit damaged tools in `DEPOSIT_COMMAND` or `DEPOSIT_INVENTORY` mode.
# If this is false, damaged tools will still be removed from players' inventories in AUTO_DEPOSIT_ALL mode
# but won't be added to their ItemRace inventory.
allow_damaged_tools: true


# These options have no effect if `points.award_mode` is `INVENTORY` or `ENDER_CHEST`
deposited_items:
Expand Down Expand Up @@ -87,4 +81,10 @@ denylist:
#- OAK_LEAVES

# Set this to true if there is only a limited number of items you want to allow players to deposit.
treat_as_allowlist: false
treat_as_allowlist: false

# Whether damaged tools should count towards the total number of each tool a player has deposited (true/false)
# If this is false, players will not be able to deposit damaged tools in `DEPOSIT_COMMAND` or `DEPOSIT_INVENTORY` mode.
# If this is false, damaged tools will still be removed from players' inventories in AUTO_DEPOSIT_ALL mode
# but won't be added to their ItemRace inventory.
allow_damaged_tools: true

0 comments on commit 03e4adb

Please sign in to comment.