mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-07-03 08:15:42 +00:00
addon ability set world slots manually - RTPMenu
This commit is contained in:
parent
7fd8b6d172
commit
c8d076c2af
@ -7,7 +7,7 @@
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTPAddons</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.8.7</version>
|
||||
<version>1.8.8</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
|
@ -22,6 +22,7 @@ import java.util.*;
|
||||
public class AddonRTPMenu implements Addon, Listener {
|
||||
|
||||
public static String name = "RTPMenu";
|
||||
@Getter private final RTPMenu_Settings settings = new RTPMenu_Settings();
|
||||
private final HashMap<Player, MenuData> playerData = new HashMap<>();
|
||||
@Getter private HashMap<String, RTPMenuWorldInfo> worlds = new HashMap<>();
|
||||
|
||||
@ -41,6 +42,7 @@ public class AddonRTPMenu implements Addon, Listener {
|
||||
for (Player p : playerData.keySet())
|
||||
p.closeInventory();
|
||||
playerData.clear();
|
||||
settings.load(name); //Load settings
|
||||
ConfigurationSection config = getFile(Files.FILETYPE.CONFIG).getConfigurationSection("RTPMenu");
|
||||
List<Map<?, ?>> map = config.getMapList("WorldList");
|
||||
for (Map<?, ?> m : map) {
|
||||
@ -64,8 +66,13 @@ public class AddonRTPMenu implements Addon, Listener {
|
||||
if (test.get("Lore").getClass() == ArrayList.class)
|
||||
lore = new ArrayList<String>((ArrayList) test.get("Lore"));
|
||||
}
|
||||
int slot = 0;
|
||||
if (test.get("Slot") != null) {
|
||||
if (test.get("Slot").getClass() == Integer.class)
|
||||
slot = (Integer) test.get("Slot");
|
||||
}
|
||||
try {
|
||||
worlds.put(world, new RTPMenuWorldInfo(name, Material.valueOf(item.toUpperCase()), lore));
|
||||
worlds.put(world, new RTPMenuWorldInfo(name, Material.valueOf(item.toUpperCase()), lore, slot));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
Main.getInstance().getLogger().warning("The item " + item + " is an unknown item id! Set to a map!");
|
||||
}
|
||||
@ -100,9 +107,8 @@ public class AddonRTPMenu implements Addon, Listener {
|
||||
private void onTeleport(RTP_CommandEvent e) {
|
||||
if (e.getCmd() instanceof CmdTeleport && e.getSendi() instanceof Player) {
|
||||
e.setCancelled(true);
|
||||
int refresh = Files.FILETYPE.CONFIG.getInt(AddonRTPMenu.name + ".AutoRefresh");
|
||||
Player player = (Player) e.getSendi();
|
||||
new RTPMenu_Refresh(this, player, refresh);
|
||||
new RTPMenu_Refresh(this, player, settings.getRefresh());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,12 @@ public class RTPMenuWorldInfo {
|
||||
public final String name;
|
||||
public final Material item;
|
||||
public final List<String> lore;
|
||||
public final int slot;
|
||||
|
||||
RTPMenuWorldInfo(String name, Material item, List<String> lore) {
|
||||
RTPMenuWorldInfo(String name, Material item, List<String> lore, int slot) {
|
||||
this.name = name;
|
||||
this.item = item;
|
||||
this.lore = lore;
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
|
@ -34,15 +34,17 @@ public class RTPMenu_SelectWorld {
|
||||
CmdTeleport.teleport(p, "rtp", null, null);
|
||||
return false;
|
||||
}
|
||||
int size = Math.floorDiv(actual_worlds.size(), 9) * 9;
|
||||
if (size < actual_worlds.size()) size += 9;
|
||||
Inventory inv = createInventory(color(p, Files.FILETYPE.CONFIG.getString(AddonRTPMenu.name + ".Title")), size);
|
||||
int lines = pl.getSettings().getLines();
|
||||
if (lines == 0)
|
||||
lines = Math.floorDiv(actual_worlds.size(), 9);
|
||||
if (lines < actual_worlds.size() / 9) lines++;
|
||||
Inventory inv = createInventory(color(p, pl.getSettings().getTitle()), Math.min(lines * 9, 6 * 9));
|
||||
|
||||
HashMap<Integer, World> world_slots = centerWorlds(new ArrayList<>(actual_worlds));
|
||||
HashMap<Integer, World> world_slots = centerWorlds(pl, new ArrayList<>(actual_worlds));
|
||||
|
||||
for (Map.Entry<Integer, World> world : world_slots.entrySet()) {
|
||||
String worldName = world.getValue().getName();
|
||||
RTPMenuWorldInfo worldInfo = pl.getWorlds().getOrDefault(worldName, new RTPMenuWorldInfo(worldName, Material.MAP, null));
|
||||
RTPMenuWorldInfo worldInfo = pl.getWorlds().getOrDefault(worldName, new RTPMenuWorldInfo(worldName, Material.MAP, null, 0));
|
||||
int slot = world.getKey();
|
||||
ItemStack item = new ItemStack(worldInfo.item, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -61,20 +63,26 @@ public class RTPMenu_SelectWorld {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static HashMap<Integer, World> centerWorlds(List<World> actual_worlds) {
|
||||
private static HashMap<Integer, World> centerWorlds(AddonRTPMenu pl, List<World> actual_worlds) {
|
||||
HashMap<Integer, World> map = new HashMap<>();
|
||||
while(actual_worlds.size() >= 9) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
map.put(map.size(), actual_worlds.get(0));
|
||||
actual_worlds.remove(0);
|
||||
if (actual_worlds.size() >= 9) {
|
||||
for (int i = 0; i < actual_worlds.size(); i++) {
|
||||
map.put(map.size(), actual_worlds.get(i));
|
||||
//actual_worlds.remove(0);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
int slot = map.size();
|
||||
//BetterRTP.getInstance().getLogger().log(Level.INFO, "- " + actual_worlds.size());
|
||||
for (int i = 0; i < actual_worlds.size(); i++) {
|
||||
int offset = getSlotOffset(actual_worlds.size(), i);
|
||||
//BetterRTP.getInstance().getLogger().log(Level.INFO, "- " + offset);
|
||||
map.put(slot + offset + i, actual_worlds.get(i));
|
||||
if (pl.getSettings().getAutoCenter()) {
|
||||
for (int i = 0; i < actual_worlds.size(); i++) {
|
||||
int offset = getSlotOffset(actual_worlds.size(), i);
|
||||
map.put(offset + i, actual_worlds.get(i));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < actual_worlds.size(); i++) {
|
||||
RTPMenuWorldInfo info = pl.getWorlds().get(actual_worlds.get(i).getName());
|
||||
if (info != null)
|
||||
map.put(info.slot, actual_worlds.get(i));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.rtpmenu;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
|
||||
|
||||
public class RTPMenu_Settings {
|
||||
@Getter private int refresh, lines;
|
||||
@Getter private String title;
|
||||
@Getter private Boolean autoCenter;
|
||||
|
||||
void load(String prefix) {
|
||||
refresh = Files.FILETYPE.CONFIG.getInt(prefix + ".AutoRefresh");
|
||||
lines = Files.FILETYPE.CONFIG.getInt(prefix + ".Lines");
|
||||
title = Files.FILETYPE.CONFIG.getString(prefix + ".Title");
|
||||
autoCenter = Files.FILETYPE.CONFIG.getBoolean(prefix + ".AutoCenter");
|
||||
}
|
||||
}
|
@ -66,10 +66,13 @@ RTPMenu:
|
||||
Enabled: false
|
||||
AutoRefresh: 0 #0 means menu will not refresh! (in ticks)
|
||||
Title: "Choose World"
|
||||
AutoCenter: true #If true, will ignore `Slot`, does not work if world list >= 9
|
||||
Lines: 3
|
||||
WorldList:
|
||||
- world:
|
||||
Name: '&7World'
|
||||
Item: 'map'
|
||||
Slot: 3
|
||||
Lore:
|
||||
- ''
|
||||
- '&8Click to rtp in world!'
|
||||
@ -78,6 +81,7 @@ RTPMenu:
|
||||
- world_nether:
|
||||
Name: '&cNether'
|
||||
Item: 'netherrack'
|
||||
Slot: 5
|
||||
Lore:
|
||||
- ''
|
||||
- '&8Click to rtp in world!'
|
||||
|
Loading…
x
Reference in New Issue
Block a user