1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-25 12:06:24 +01:00

Added random warp button to warps panel

https://github.com/BentoBoxWorld/Warps/issues/20
This commit is contained in:
tastybento 2019-09-19 14:23:29 -07:00
parent b98d83fffc
commit 38c5496118
4 changed files with 53 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Material;
@ -46,6 +47,19 @@ public class WarpPanelManager {
}
}
private PanelItem getRandomButton(World world, User user, UUID warpOwner) {
///give @p minecraft:player_head{display:{Name:"{\"text\":\"Question Mark\"}"},SkullOwner:"MHF_Question"} 1
return new PanelItemBuilder()
.name(addon.getSettings().getNameFormat() + user.getTranslation("warps.random"))
.clickHandler((panel, clicker, click, slot) -> { {
clicker.closeInventory();
addon.getWarpSignsManager().warpPlayer(world, clicker, warpOwner);
return true;
}
})
.icon(Material.END_CRYSTAL).build();
}
private Material getSignIcon(World world, UUID warpOwner) {
// Add the worlds if we haven't seen this before
cachedSigns.putIfAbsent(world, new HashMap<>());
@ -83,6 +97,12 @@ public class WarpPanelManager {
*/
public void showWarpPanel(World world, User user, int index) {
List<UUID> warps = new ArrayList<>(addon.getWarpSignsManager().getSortedWarps(world));
UUID randomWarp = null;
// Add random UUID
if (!warps.isEmpty() && addon.getSettings().isRandomAllowed()) {
randomWarp = warps.get(new Random().nextInt(warps.size()));
warps.add(0, randomWarp);
}
if (index < 0) {
index = 0;
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
@ -94,14 +114,18 @@ public class WarpPanelManager {
int i = index * PANEL_MAX_SIZE;
for (; i < (index * PANEL_MAX_SIZE + PANEL_MAX_SIZE) && i < warps.size(); i++) {
if (i == 0 && randomWarp != null) {
panelBuilder.item(getRandomButton(world, user, randomWarp));
} else {
panelBuilder.item(getPanelItem(world, warps.get(i)));
}
}
final int panelNum = index;
// Add signs
if (i < warps.size()) {
// Next
panelBuilder.item(new PanelItemBuilder()
.name("Next")
.name(user.getTranslation("warps.next"))
.icon(new ItemStack(Material.STONE))
.clickHandler((panel, clicker, click, slot) -> {
user.closeInventory();
@ -112,7 +136,7 @@ public class WarpPanelManager {
if (i > PANEL_MAX_SIZE) {
// Previous
panelBuilder.item(new PanelItemBuilder()
.name("Previous")
.name(user.getTranslation("warps.previous"))
.icon(new ItemStack(Material.COBBLESTONE))
.clickHandler((panel, clicker, click, slot) -> {
user.closeInventory();

View File

@ -57,6 +57,11 @@ public class Settings implements ConfigObject
@ConfigEntry(path = "lore-format")
private String loreFormat = "&f";
@ConfigComment("")
@ConfigComment("Allow random teleport - adds a button to the warp panel that goes to a random warp sign")
@ConfigEntry(path = "random-allowed")
private boolean randomAllowed = true;
// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
@ -189,4 +194,20 @@ public class Settings implements ConfigObject
}
/**
* @return the randomAllowed
*/
public boolean isRandomAllowed() {
return randomAllowed;
}
/**
* @param randomAllowed the randomAllowed to set
*/
public void setRandomAllowed(boolean randomAllowed) {
this.randomAllowed = randomAllowed;
}
}

View File

@ -31,3 +31,7 @@ name-format: &f
# Warp panel default lore formatting.
# Example: &c will make lore red. &f is white
lore-format: &f
#
# Allow random teleport - adds a button to the warp panel that goes to a random warp sign
random-allowed: true

View File

@ -23,6 +23,7 @@ warps:
next: "&6Next page"
player-warped: "&2[name] warped to your warp sign!"
previous: "&6Previous page"
random: "&4Random Warp"
sign-removed: "&CWarp sign removed!"
success: "&ASuccess!"
title: "Warp Signs"