Skip to content

Commit

Permalink
Add changing hotbar and add options to change sorting and lobby item
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Aug 20, 2022
1 parent 774fd19 commit 62bea47
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>dev.efnilite</groupId>
<artifactId>IP</artifactId>
<packaging>pom</packaging>
<version>3.8.0</version>
<version>3.8.1</version>
<modules>
<module>witp</module>
</modules>
Expand Down
22 changes: 20 additions & 2 deletions witp/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
<parent>
<artifactId>IP</artifactId>
<groupId>dev.efnilite</groupId>
<version>3.8.0</version>
<version>3.8.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>witp</artifactId>
<version>3.8.0</version>
<version>3.8.1</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>clean package</defaultGoal>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>lang/items-v3.yml</include>
<include>lang/messages-v3.yml</include>
<include>lang/scoreboard-v3.yml</include>
<include>config.yml</include>
<include>generation.yml</include>
<include>rewards-v2.yml</include>
<include>schematics.yml</include>
</includes>
</resource>
</resources>
<finalName>${project.name}-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
23 changes: 21 additions & 2 deletions witp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,38 @@
<parent>
<artifactId>IP</artifactId>
<groupId>dev.efnilite</groupId>
<version>3.8.0</version>
<version>3.8.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>witp</artifactId>
<version>3.8.0</version>
<version>3.8.1</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<finalName>${project.name}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<targetPath>.</targetPath>
<includes>
<include>lang/items-v3.yml</include>
<include>lang/messages-v3.yml</include>
<include>lang/scoreboard-v3.yml</include>
<include>config.yml</include>
<include>generation.yml</include>
<include>rewards-v2.yml</include>
<include>schematics.yml</include>
</includes>
</resource>
</resources>

<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public void checkRewards() {
return;
}

if (getGamemode() instanceof DefaultGamemode) {
if (!(getGamemode() instanceof DefaultGamemode)) {
return;
}

Expand Down
9 changes: 8 additions & 1 deletion witp/src/main/java/dev/efnilite/ip/menu/LeaderboardMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ public static void openSingle(Player player, Gamemode gamemode, Sort sort) {
default -> Sort.SCORE;
};

List<String> values = IP.getConfiguration().getFile("items").getStringList("locale." + locale + ".options.leaderboard-sort.values");
String name = switch (next) {
case SCORE -> values.get(0);
case TIME -> values.get(1);
case DIFFICULTY -> values.get(2);
};

menu
.displayRows(0, 1)
.addToDisplay(items)
Expand All @@ -175,7 +182,7 @@ public static void openSingle(Player player, Gamemode gamemode, Sort sort) {
.prevPage(27, new Item(Material.RED_DYE, "<#DE1F1F><bold>" + Unicodes.DOUBLE_ARROW_LEFT) // previous page
.click(event -> menu.page(-1)))

.item(31, config.getFromItemData(locale, "options.leaderboard-sort", next.name().toLowerCase())
.item(31, config.getFromItemData(locale, "options.leaderboard-sort", name.toLowerCase())
.click(event -> openSingle(player, gamemode, next)))

.item(32, config.getFromItemData(locale, "general.close")
Expand Down
17 changes: 17 additions & 0 deletions witp/src/main/java/dev/efnilite/ip/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -331,6 +333,21 @@ public static double angle(Vector3D base, Vector3D other) {
return Math.toDegrees(Math.atan2(base.z, base.x) - Math.atan2(other.z, other.x));
}

public static List<Integer> getEvenlyDistributedSlots(int amountInRow) {
return switch (amountInRow) {
case 0 -> Collections.emptyList();
case 1 -> Collections.singletonList(4);
case 2 -> Arrays.asList(3, 5);
case 3 -> Arrays.asList(3, 4, 5);
case 4 -> Arrays.asList(2, 3, 5, 6);
case 5 -> Arrays.asList(2, 3, 4, 5, 6);
case 6 -> Arrays.asList(1, 2, 3, 5, 6, 7);
case 7 -> Arrays.asList(1, 2, 3, 4, 5, 6, 7);
case 8 -> Arrays.asList(0, 1, 2, 3, 5, 6, 7, 8);
default -> Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8);
};
}

/**
* Translates any placeholders found by PlaceholderAPI
*
Expand Down
47 changes: 27 additions & 20 deletions witp/src/main/java/dev/efnilite/ip/world/WorldDivider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.*;

/**
* Divides the Parkour world into sections so there can be an infinite amount of players in 1 world.
Expand Down Expand Up @@ -232,33 +228,44 @@ public void setup(ParkourPlayer pp, Location to, boolean giveCompass, boolean ru
Task.create(IP.getPlugin())
.delay(5)
.execute(() -> {
List<Item> items = new ArrayList<>();

player.getInventory().clear();

if (Option.SETTINGS_ENABLED.get() && giveCompass) {
ItemStack mat = IP.getConfiguration().getFromItemData(pp, "general.menu").build();
if (mat == null) {
Item item = IP.getConfiguration().getFromItemData(pp, "general.menu");
if (item != null) {
items.add(item);
} else {
IP.logging().error("Material for options in items.yml is null");
player.getInventory().setItem(4, new Item(Material.COMPASS, "&c&l-= Options =-").build());
items.add(new Item(Material.COMPASS, "&c&l-= Options =-"));
}
}
boolean enabled = IP.getConfiguration().getFile("items").getBoolean("items.lobby.item.enabled");
if (enabled) {
Item item = IP.getConfiguration().getFromItemData(pp, "lobby.item");

if (item != null) {
items.add(item);
} else {
player.getInventory().setItem(4, mat);
IP.logging().error("Material for lobby item in config is null");
items.add(new Item(Material.BEACON, "&c&l-= Lobbies =-"));
}
}
if (Option.HOTBAR_QUIT_ITEM.get()) {
ItemStack mat = IP.getConfiguration().getFromItemData(pp, "general.quit").build();
if (mat == null) {
IP.logging().error("Material for quitting in items is null");
player.getInventory().setItem(5, new Item(Material.BARRIER, "&c&l-= Quit =-").build());
Item item = IP.getConfiguration().getFromItemData(pp, "general.quit");
if (item != null) {
items.add(item);
} else {
player.getInventory().setItem(5, mat);
IP.logging().error("Material for quitting in items is null");
items.add(new Item(Material.BARRIER, "&c&l-= Quit =-"));
}
}

ItemStack mat = IP.getConfiguration().getFromItemData(pp, "lobby.item").build();
if (mat == null) {
IP.logging().error("Material for lobby in config is null");
player.getInventory().setItem(5, new Item(Material.BEACON, "&c&l-= Lobbies =-").build());
} else {
player.getInventory().setItem(5, mat);

List<Integer> slots = Util.getEvenlyDistributedSlots(items.size());
for (int i = 0; i < items.size(); i++) {
player.getInventory().setItem(slots.get(i), items.get(i).build());
}

})
Expand Down
6 changes: 6 additions & 0 deletions witp/src/main/resources/lang/items-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ items:
lobby:
item:
item: iron_ingot
enabled: true
chat:
item: feather
visibility:
Expand Down Expand Up @@ -211,6 +212,7 @@ locale:
leaderboard-sort:
name: '<#DEA11F><bold>Sort by %s'
lore: '<dark_gray>Sortieren • 种类||<dark_gray>Trier • 選別 • Sorteren'
values: ['score', 'time', 'difficulty']
leaderboard-head:
name: '<#6693E7><bold>#%r - %p'
lore: '<#5574AF>Score: <gray>%s||<#5574AF>Time: <gray>%t||<#5574AF>Difficulty: <gray>%d<dark_gray>/1.0'
Expand Down Expand Up @@ -328,6 +330,7 @@ locale:
leaderboard-sort:
name: '<#DEA11F><bold>Sorteren op %s'
lore: '<dark_gray>Sortieren • 种类||<dark_gray>Trier • 選別 • Sort'
values: ['score', 'tijd', 'moeilijkheid']
leaderboard-head:
name: '<#6693E7><bold>#%r - %p'
lore: '<#5574AF>Score: <gray>%s||<#5574AF>Tijd: <gray>%t||<#5574AF>Moeilijkheid: <gray>%d<dark_gray>/1.0'
Expand Down Expand Up @@ -445,6 +448,7 @@ locale:
leaderboard-sort:
name: '<#DEA11F><bold>Trier par %s'
lore: '<dark_gray>Sortieren • 种类||<dark_gray>Sorteren • 選別 • Sort'
values: ['score', 'time', 'difficulty']
leaderboard-head:
name: '<#6693E7><bold>#%r - %p'
lore: '<#5574AF>Score: <gray>%s||<#5574AF>Temps: <gray>%t||<#5574AF>Difficulté: <gray>%d<dark_gray>/1.0'
Expand Down Expand Up @@ -565,6 +569,7 @@ locale:
leaderboard-sort:
name: '<#DEA11F><bold>排序方式 %s'
lore: '<dark_gray>Sortieren • Trier||<dark_gray>Sorteren • 選別 • Sort'
values: ['score', 'time', 'difficulty']
language:
name: '<#6693E7><bold>語言'
lore: '<#5574AF>目前: <gray>%s'
Expand Down Expand Up @@ -680,6 +685,7 @@ locale:
leaderboard-sort:
name: '<#DEA11F><bold>排序方式 %s'
lore: '<dark_gray>Sortieren • Trier||<dark_gray>Sorteren • 選別 • Sort'
values: ['score', 'time', 'difficulty']
leaderboard-head:
name: '<#6693E7><bold>#%r - %p'
lore: '<#5574AF>分数: <gray>%s||<#5574AF>时间: <gray>%t||<#5574AF>难道: <gray>%d<dark_gray>/1.0'
Expand Down
2 changes: 1 addition & 1 deletion witp/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'WITP'
description: 'Infinitely automatically generating parkour plugin.'
author: Efnilite, Ice_Pancake
version: 3.8.0
version: ${project.version}
api-version: 1.16
main: dev.efnilite.ip.IP
softdepend: [floodgate, vilib, Vault, PlaceholderAPI, Multiverse-Core, HolographicDisplays, VoidGen]
Expand Down

0 comments on commit 62bea47

Please sign in to comment.