moved away from old config structure
This commit is contained in:
parent
37b687b999
commit
3714ffa85a
@ -1,4 +1,8 @@
|
||||
name: Lobby
|
||||
main: de.slpnetwork.lobby.Lobby
|
||||
version: 0.1
|
||||
api-version: 1.18
|
||||
api-version: 1.18
|
||||
commands:
|
||||
slpl:
|
||||
description: does stuff in the plugin
|
||||
usage: /slpl <arg> <subarg>
|
38
src/main/java/de/slpnetwork/lobby/Commands/slpl.java
Normal file
38
src/main/java/de/slpnetwork/lobby/Commands/slpl.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.slpnetwork.lobby.Commands;
|
||||
|
||||
import de.slpnetwork.lobby.Commands.subcommands.admin;
|
||||
import de.slpnetwork.lobby.Manager.LobbyManager;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class slpl implements CommandExecutor {
|
||||
private LobbyManager lobbyManager;
|
||||
private admin cmdAdmin;
|
||||
|
||||
public slpl(LobbyManager lobbyManager) {
|
||||
this.lobbyManager = lobbyManager;
|
||||
cmdAdmin = new admin(this.lobbyManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = sender.getServer().getPlayer(sender.getName());
|
||||
|
||||
if(args.length >= 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "admin":
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "help" -> admin.sendHelp(player);
|
||||
case "setLoc" -> cmdAdmin.setLoc(player.getLocation(), args[2].toString().toLowerCase());
|
||||
case "remLoc" -> cmdAdmin.remLoc(args[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package de.slpnetwork.lobby.Commands.subcommands;
|
||||
|
||||
import de.slpnetwork.lobby.Manager.LobbyManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class admin {
|
||||
private LobbyManager lobbyManager;
|
||||
|
||||
public admin(LobbyManager lobbyManager) {
|
||||
this.lobbyManager = lobbyManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* sends administration help to player
|
||||
* @param player player reference
|
||||
*/
|
||||
public static void sendHelp(Player player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* handles command input and stores its give location
|
||||
* @param loc inworld location
|
||||
* @param name locations reference name
|
||||
*/
|
||||
public void setLoc(Location loc, String name){
|
||||
// set location in locations.yml
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a given location if it exists
|
||||
* @param name removing location name
|
||||
*/
|
||||
public void remLoc(String name){
|
||||
// set location in locations.yml
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package de.slpnetwork.lobby;
|
||||
|
||||
import de.slpnetwork.lobby.Commands.slpl;
|
||||
import de.slpnetwork.lobby.Manager.InventoryManager;
|
||||
import de.slpnetwork.lobby.Manager.LobbyManager;
|
||||
import org.bukkit.Material;
|
||||
@ -10,13 +11,16 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class Lobby extends JavaPlugin implements Listener, PluginMessageListener {
|
||||
public LobbyManager lobbyManager;
|
||||
@ -25,6 +29,8 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
|
||||
public FileConfiguration itemDataConfig;
|
||||
public File menuData;
|
||||
public FileConfiguration menuDataConfig;
|
||||
public File teleportData;
|
||||
public FileConfiguration teleportDataConfig;
|
||||
|
||||
|
||||
@Override
|
||||
@ -34,15 +40,37 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
|
||||
try {
|
||||
this.saveDefaultConfig();
|
||||
config = this.getConfig();
|
||||
itemData = new File(this.getDataFolder(), "items.yml");
|
||||
itemDataConfig = YamlConfiguration.loadConfiguration(itemData);
|
||||
menuData = new File(this.getDataFolder(), "menu.yml");
|
||||
menuDataConfig = YamlConfiguration.loadConfiguration(menuData);
|
||||
}catch (Exception ex) {
|
||||
|
||||
itemData = new File(this.getDataFolder(), "items.yml");
|
||||
menuData = new File(this.getDataFolder(), "menus.yml");
|
||||
teleportData = new File(this.getDataFolder(), "locations.yml");
|
||||
|
||||
if(!itemData.exists() || !menuData.exists() || !teleportData.exists()) {
|
||||
System.out.println("Loading config files");
|
||||
itemData = new File(this.getDataFolder(), "items.yml");
|
||||
menuData = new File(this.getDataFolder(), "menus.yml");
|
||||
teleportData = new File(this.getDataFolder(), "locations.yml");
|
||||
|
||||
itemDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("items.yml")));
|
||||
menuDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("menus.yml")));
|
||||
teleportDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("locations.yml")));
|
||||
|
||||
itemDataConfig.save(itemData);
|
||||
menuDataConfig.save(menuData);
|
||||
teleportDataConfig.save(teleportData);
|
||||
}
|
||||
|
||||
itemDataConfig = YamlConfiguration.loadConfiguration(itemData);
|
||||
menuDataConfig = YamlConfiguration.loadConfiguration(menuData);
|
||||
teleportDataConfig = YamlConfiguration.loadConfiguration(teleportData);
|
||||
}catch (Exception ex) {
|
||||
this.getServer().getLogger().warning("Could not load or create files due to exceotion: " + ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
this.lobbyManager = new LobbyManager(this);
|
||||
|
||||
this.getCommand("slpl").setExecutor(new slpl(this.lobbyManager));
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.getServer().getPluginManager().registerEvents(new InventoryManager(this.lobbyManager), this);
|
||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
@ -58,15 +86,15 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
e.getPlayer().getInventory().clear();
|
||||
|
||||
// TODO: loop over itemdataconfig(items)
|
||||
for (String key: this.config.getConfigurationSection("menu").getKeys(false)) {
|
||||
// TODO: replace current datapoints with new ones
|
||||
ItemStack is = new ItemStack(Material.getMaterial(this.config.getString("menu." + key + ".material")));
|
||||
// Fetch and set configured items
|
||||
for (String key: this.itemDataConfig.getConfigurationSection("items").getKeys(false)) {
|
||||
System.out.println("DEBUG -> " + "Material: " + key);
|
||||
ItemStack is = new ItemStack(Material.getMaterial(this.itemDataConfig.getString("items." + key + ".material")));
|
||||
ItemMeta im = is.getItemMeta();
|
||||
im.setDisplayName(this.config.getString("menu." + key + ".title"));
|
||||
im.setDisplayName(this.itemDataConfig.getString("items." + key + ".display"));
|
||||
im.addItemFlags();
|
||||
is.setItemMeta(im);
|
||||
e.getPlayer().getInventory().setItem(this.config.getInt("menu." + key + ".slot"), is);
|
||||
e.getPlayer().getInventory().setItem(this.itemDataConfig.getInt("items." + key + ".slot"), is);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,9 +104,7 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
|
||||
// The menu does not get opened
|
||||
try {
|
||||
Player p = e.getPlayer();
|
||||
// TODO: Replace current datapoints with new ones
|
||||
// TODO: Grab menu Datapoint based on Material Type
|
||||
this.lobbyManager.getInventoryManager().openInventory(p, p.getInventory().getItemInMainHand().getItemMeta().getDisplayName());
|
||||
this.lobbyManager.getInventoryManager().openInventory(p, this.itemDataConfig.getString("items." + e.getMaterial() + ".menu"));
|
||||
} catch (Exception ex) {
|
||||
// possibly nullpointer nothing else can happen here
|
||||
}
|
||||
|
@ -25,13 +25,11 @@ public class InventoryManager implements Listener {
|
||||
this.lobbyManager.setInventoryManager(this);
|
||||
this.inventories = new HashMap<String, Inventory>();
|
||||
|
||||
// TODO: replace default config with menudataconfig and iterate over its menu datapoint
|
||||
for(String key: this.lobbyManager.getLobby().config.getConfigurationSection("menu").getKeys(false)) {
|
||||
// TODO: replace current datapoints with new ones
|
||||
for(String key: this.lobbyManager.getLobby().menuDataConfig.getConfigurationSection("menus").getKeys(false)) {
|
||||
this.inventories.put(
|
||||
this.lobbyManager.getLobby().config.getString("menu." + key + ".title"), Bukkit.createInventory(null,
|
||||
this.lobbyManager.getLobby().config.getInt("menu." + key + ".slots"),
|
||||
this.lobbyManager.getLobby().config.getString("menu." + key + ".title")
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".identifier"), Bukkit.createInventory(null,
|
||||
this.lobbyManager.getLobby().menuDataConfig.getInt("menus." + key + ".slots"),
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".title")
|
||||
)
|
||||
);
|
||||
System.out.println(this.inventories.size() + " inventories stored"); // debugging inventories not beeing generated
|
||||
@ -40,21 +38,21 @@ public class InventoryManager implements Listener {
|
||||
}
|
||||
|
||||
void initializeItems(String key){
|
||||
Inventory inv = inventories.get(this.lobbyManager.getLobby().config.getString("menu." + key + ".title"));
|
||||
Inventory inv = inventories.get(this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".identifier"));
|
||||
|
||||
// Nullpointer debugging
|
||||
System.out.println(key + "0");
|
||||
if(this.lobbyManager.getLobby().config.get("menu." + key) == null) System.out.println("Error: no items have been set, Menu will not be created"); // fixes nullpointer
|
||||
if(this.lobbyManager.getLobby().config.get("menu." + key) == null) return; // fixes nullpointer
|
||||
if(this.lobbyManager.getLobby().menuDataConfig.get("menus." + key) == null) System.out.println("Error: no items have been set, Menu will not be created"); // fixes nullpointer
|
||||
if(this.lobbyManager.getLobby().menuDataConfig.get("menus." + key) == null) return; // fixes nullpointer
|
||||
|
||||
for(String keyItem : this.lobbyManager.getLobby().config.getConfigurationSection("menu." + key + ".items").getKeys(false)) {
|
||||
for(String keyItem : this.lobbyManager.getLobby().menuDataConfig.getConfigurationSection("menus." + key + ".items").getKeys(false)) {
|
||||
System.out.println("debug-> " + keyItem);
|
||||
System.out.println(this.lobbyManager.getLobby().config.getString("menu."+key+".items."+keyItem+".material") + "1");
|
||||
System.out.println(this.lobbyManager.getLobby().menuDataConfig.getString("menus."+key+".items."+keyItem+".material") + "1");
|
||||
|
||||
inv.setItem(this.lobbyManager.getLobby().config.getInt("menu." + key + ".items." + keyItem + ".slot"),
|
||||
createGuiItem(Material.getMaterial(this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".material")),
|
||||
this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".title"),
|
||||
this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".description")
|
||||
inv.setItem(this.lobbyManager.getLobby().menuDataConfig.getInt("menus." + key + ".items." + keyItem + ".slot"),
|
||||
createGuiItem(Material.getMaterial(this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".material")),
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".title"),
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + key + ".items." + keyItem + ".description")
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -99,8 +97,8 @@ public class InventoryManager implements Listener {
|
||||
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
this.lobbyManager.getCommandInterpreter().execute(p.getPlayer(),
|
||||
this.lobbyManager.getLobby().config.getString("menu." + e.getView().getTitle().toLowerCase()+ ".items."+ clickedItem.getItemMeta().getDisplayName().toLowerCase() + ".action.type"),
|
||||
this.lobbyManager.getLobby().config.getString("menu." + e.getView().getTitle().toLowerCase()+ ".items."+ clickedItem.getItemMeta().getDisplayName().toLowerCase() + ".action.argument"));
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + e.getView().getTitle().toLowerCase() + ".items."+ clickedItem.getType() + ".action.type"),
|
||||
this.lobbyManager.getLobby().menuDataConfig.getString("menus." + e.getView().getTitle().toLowerCase() + ".items."+ clickedItem.getType() + ".action.argument"));
|
||||
// Using slots click is a best option for your inventory click's
|
||||
p.sendMessage("You clicked at slot " + e.getRawSlot());
|
||||
}
|
||||
|
@ -14,12 +14,6 @@ public class PlayerManager {
|
||||
this.lobbyManager = lobbyManager;
|
||||
}
|
||||
|
||||
public void giveItems(Player player){
|
||||
player.getInventory().addItem(new ItemStack(Material.BOOK));
|
||||
player.getInventory().addItem(new ItemStack(Material.COMPASS));
|
||||
player.getInventory().addItem(new ItemStack(Material.PLAYER_HEAD));
|
||||
}
|
||||
|
||||
/**
|
||||
* teleports a player to a location
|
||||
* @param player the wanted player
|
||||
|
@ -23,15 +23,16 @@ public class CommandInterpreter {
|
||||
this.lobbyManager.getLobby().getServer().getLogger().warning("The Action: '" + action + "' is not defined");
|
||||
break;
|
||||
case "menu":
|
||||
// opens menu
|
||||
this.lobbyManager.getInventoryManager().openInventory(executor, args);
|
||||
break;
|
||||
case "teleport":
|
||||
this.lobbyManager.getPlayerManager().teleportPlayer(executor, this.lobbyManager.getLobby().teleportDataConfig.getLocation("locations." + args));
|
||||
break;
|
||||
case "connect":
|
||||
this.lobbyManager.getPlayerManager().moveFromServer(args, Objects.requireNonNull(executor.getPlayer()));
|
||||
break;
|
||||
case "execute":
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,10 @@ items:
|
||||
display: "Navigator"
|
||||
slot: 4
|
||||
material: "COMPASS"
|
||||
permission: "lobby.item.navigator"
|
||||
permission: "lobby.item.navigator"
|
||||
BOOK:
|
||||
menu: "profile"
|
||||
display: "Profile"
|
||||
slot: 2
|
||||
material: "BOOK"
|
||||
permission: "lobby.item.profil"
|
1
src/main/resources/locations.yml
Normal file
1
src/main/resources/locations.yml
Normal file
@ -0,0 +1 @@
|
||||
locations:
|
@ -1,15 +1,45 @@
|
||||
navigator:
|
||||
title: "Navigator"
|
||||
identifier: "navigator"
|
||||
slots: 54
|
||||
slot: 4
|
||||
permission: slpnet.lobby.navigator
|
||||
items:
|
||||
tridentwar:
|
||||
title: "TridentWar"
|
||||
material: "TRIDENT"
|
||||
description: "test\ntest"
|
||||
slot: 18
|
||||
action:
|
||||
type: "connect"
|
||||
argument: "tw1"
|
||||
menus:
|
||||
navigator:
|
||||
title: "Navigator"
|
||||
identifier: "navigator"
|
||||
slots: 54
|
||||
permission: slpnet.lobby.navigator
|
||||
items:
|
||||
TRIDENT:
|
||||
title: "TridentWar"
|
||||
material: "TRIDENT"
|
||||
description: "test\ntest"
|
||||
slot: 18
|
||||
action:
|
||||
type: "connect"
|
||||
argument: "tw1"
|
||||
RED_BED:
|
||||
title: "Bedwars"
|
||||
material: "RED_BED"
|
||||
description: "test\ntest"
|
||||
slot: 20
|
||||
action:
|
||||
type: "connect"
|
||||
argument: "tw1"
|
||||
CRAFTING_TABLE:
|
||||
title: "Master Builder"
|
||||
material: "CRAFTING_TABLE"
|
||||
description: "test\ntest"
|
||||
slot: 22
|
||||
action:
|
||||
type: "connect"
|
||||
argument: "tw1"
|
||||
profile:
|
||||
title: "Profile"
|
||||
identifier: "profile"
|
||||
slots: 54
|
||||
permission: slpnet.lobby.profile
|
||||
items:
|
||||
TRIDENT:
|
||||
title: "TridentWar"
|
||||
material: "TRIDENT"
|
||||
description: "test\ntest"
|
||||
slot: 18
|
||||
action:
|
||||
type: "connect"
|
||||
argument: "tw1"
|
Loading…
x
Reference in New Issue
Block a user