mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
full rtp menu revamp
This commit is contained in:
parent
91ef3ff3c8
commit
8fc4824190
@ -7,7 +7,7 @@
|
||||
<groupId>me.SuperRonanCraft</groupId>
|
||||
<artifactId>BetterRTPAddons</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.8.1</version>
|
||||
<version>1.8.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.rtpmenu;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
||||
import me.SuperRonanCraft.BetterRTP.player.commands.types.CmdTeleport;
|
||||
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_CommandEvent;
|
||||
@ -8,19 +9,21 @@ import me.SuperRonanCraft.BetterRTPAddons.Main;
|
||||
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import javax.security.auth.login.Configuration;
|
||||
import java.util.*;
|
||||
|
||||
public class AddonRTPMenu implements Addon, Listener {
|
||||
|
||||
public static String name = "RTPMenu";
|
||||
private final HashMap<Player, MenuData> playerData = new HashMap<>();
|
||||
@Getter private HashMap<String, RTPMenuWorldInfo> worlds = new HashMap<>();
|
||||
|
||||
public MenuData getData(Player p) {
|
||||
if (!playerData.containsKey(p))
|
||||
@ -38,12 +41,44 @@ public class AddonRTPMenu implements Addon, Listener {
|
||||
for (Player p : playerData.keySet())
|
||||
p.closeInventory();
|
||||
playerData.clear();
|
||||
ConfigurationSection config = getFile(Files.FILETYPE.CONFIG).getConfigurationSection("RTPMenu");
|
||||
List<Map<?, ?>> map = config.getMapList("WorldList");
|
||||
for (Map<?, ?> m : map) {
|
||||
for (Map.Entry<?, ?> entry : m.entrySet()) {
|
||||
String world = entry.getKey().toString();
|
||||
Map<?, ?> test = ((Map<?, ?>) m.get(world));
|
||||
if (test == null)
|
||||
continue;
|
||||
String item = "MAP";
|
||||
String name = world;
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (test.get("Item") != null) {
|
||||
if (test.get("Item").getClass() == String.class)
|
||||
item = String.valueOf(test.get("Item").toString());
|
||||
}
|
||||
if (test.get("Name") != null) {
|
||||
if (test.get("Name").getClass() == String.class)
|
||||
name = String.valueOf(test.get("Name").toString());
|
||||
}
|
||||
if (test.get("Lore") != null) {
|
||||
if (test.get("Lore").getClass() == ArrayList.class)
|
||||
lore = new ArrayList<String>((ArrayList) test.get("Lore"));
|
||||
}
|
||||
try {
|
||||
worlds.put(world, new RTPMenuWorldInfo(name, Material.valueOf(item.toUpperCase()), lore));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
Main.getInstance().getLogger().warning("The item " + item + " is an unknown item id! Set to a map!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, Main.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
HandlerList.unregisterAll(this);
|
||||
for (Player p : playerData.keySet())
|
||||
p.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,18 @@
|
||||
package me.SuperRonanCraft.BetterRTPAddons.addons.rtpmenu;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RTPMenuWorldInfo {
|
||||
|
||||
public final String name;
|
||||
public final Material item;
|
||||
public final List<String> lore;
|
||||
|
||||
RTPMenuWorldInfo(String name, Material item, List<String> lore) {
|
||||
this.name = name;
|
||||
this.item = item;
|
||||
this.lore = lore;
|
||||
}
|
||||
}
|
@ -21,31 +21,30 @@ public class RTPMenu_SelectWorld {
|
||||
|
||||
public static void createInv(AddonRTPMenu pl, Player p) {
|
||||
List<World> bukkit_worlds = Bukkit.getWorlds();
|
||||
List<String> display_worlds = Files.FILETYPE.CONFIG.getStringList(AddonRTPMenu.name + ".Worlds");
|
||||
List<World> actual_worlds = new ArrayList<>();
|
||||
for (World world : bukkit_worlds) {
|
||||
if (display_worlds.contains(world.getName()) && BetterRTP.getInstance().getPerms().getAWorld(p, world.getName()))
|
||||
if (pl.getWorlds().containsKey(world.getName()) && BetterRTP.getInstance().getPerms().getAWorld(p, world.getName()))
|
||||
actual_worlds.add(world);
|
||||
}
|
||||
if (actual_worlds.size() <= 1) {
|
||||
if (actual_worlds.isEmpty() || (actual_worlds.size() <= 1 && !BetterRTP.getInstance().getSettings().isDebug())) {
|
||||
CmdTeleport.teleport(p, "rtp", null, null);
|
||||
return;
|
||||
}
|
||||
int size = Math.floorDiv(actual_worlds.size(), 9) * 9;
|
||||
if (size < actual_worlds.size()) size += 9;
|
||||
Inventory inv = createInventory(color(Files.FILETYPE.CONFIG.getString(AddonRTPMenu.name + ".Menu.Title")), size);
|
||||
Inventory inv = createInventory(color(Files.FILETYPE.CONFIG.getString(AddonRTPMenu.name + ".Title")), size);
|
||||
|
||||
HashMap<Integer, World> world_slots = centerWorlds(new ArrayList<>(actual_worlds));
|
||||
|
||||
String item_name = Files.FILETYPE.CONFIG.getString(AddonRTPMenu.name + ".Menu.Items.Name");
|
||||
List<String > item_lore = Files.FILETYPE.CONFIG.getStringList(AddonRTPMenu.name + ".Menu.Items.Lore");
|
||||
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));
|
||||
int slot = world.getKey();
|
||||
ItemStack item = new ItemStack(Material.MAP, 1);
|
||||
ItemStack item = new ItemStack(worldInfo.item, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(color(item_name.replace("%world%", world.getValue().getName())));
|
||||
List<String> lore = new ArrayList<>(item_lore);
|
||||
meta.setDisplayName(color(worldInfo.name));
|
||||
List<String> lore = new ArrayList<>(worldInfo.lore);
|
||||
lore.forEach(s -> lore.set(lore.indexOf(s), color(s).replace("%world%", world.getValue().getName())));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
@ -64,13 +64,17 @@ Parties:
|
||||
#Addon RTPMenu (Enable `/rtp` world select menu)
|
||||
RTPMenu:
|
||||
Enabled: false
|
||||
Menu:
|
||||
Title: "Choose World"
|
||||
Items:
|
||||
Name: '&7%world%'
|
||||
Lore:
|
||||
- ''
|
||||
- '&8Click to rtp into this world!'
|
||||
Worlds:
|
||||
- world
|
||||
- world_nether
|
||||
Title: "Choose World"
|
||||
WorldList:
|
||||
- world:
|
||||
Name: '&7World'
|
||||
Item: 'map'
|
||||
Lore:
|
||||
- ''
|
||||
- '&8Click to rtp in world!'
|
||||
- world_nether:
|
||||
Name: '&cNether'
|
||||
Item: 'netherrack'
|
||||
Lore:
|
||||
- ''
|
||||
- '&8Click to rtp in world!'
|
Loading…
x
Reference in New Issue
Block a user