Add reload command and fix a small bug.
The bug is it not loading systems by players that are not online when the plugin loads, or when the player doesn't join.
This commit is contained in:
parent
1ffd0340dc
commit
1273936d76
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>net.seanomik</groupId>
|
<groupId>net.seanomik</groupId>
|
||||||
<artifactId>energeticstorage</artifactId>
|
<artifactId>energeticstorage</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EnergeticStorage</name>
|
<name>EnergeticStorage</name>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.seanomik.energeticstorage;
|
package net.seanomik.energeticstorage;
|
||||||
|
|
||||||
import net.seanomik.energeticstorage.commands.ESGiveCommand;
|
import net.seanomik.energeticstorage.commands.ESGiveCommand;
|
||||||
|
import net.seanomik.energeticstorage.commands.ESReloadCommand;
|
||||||
import net.seanomik.energeticstorage.files.PlayersFile;
|
import net.seanomik.energeticstorage.files.PlayersFile;
|
||||||
import net.seanomik.energeticstorage.listeners.BlockBreakListener;
|
import net.seanomik.energeticstorage.listeners.BlockBreakListener;
|
||||||
import net.seanomik.energeticstorage.listeners.BlockPlaceListener;
|
import net.seanomik.energeticstorage.listeners.BlockPlaceListener;
|
||||||
|
@ -28,13 +29,12 @@ public final class EnergeticStorage extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
PlayersFile.getConfig().saveDefaultConfig();
|
PlayersFile.getConfig().saveDefaultConfig();
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
Reference.ES_SYSTEMS = PlayersFile.getAllSystems();
|
||||||
cachePlayersSystems(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
getCommand("esgive").setExecutor(new ESGiveCommand());
|
getCommand("esgive").setExecutor(new ESGiveCommand());
|
||||||
|
getCommand("esreload").setExecutor(new ESReloadCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListener() {
|
private void registerListener() {
|
||||||
|
@ -48,17 +48,17 @@ public final class EnergeticStorage extends JavaPlugin implements Listener {
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cachePlayersSystems(Player player) {
|
/*public void cachePlayersSystems(Player player) {
|
||||||
if (PlayersFile.doesPlayerHaveSystem(player.getUniqueId())) {
|
if (PlayersFile.doesPlayerHaveSystem(player.getUniqueId())) {
|
||||||
Reference.ES_SYSTEMS.put(player.getUniqueId(), PlayersFile.getPlayersSystems(player.getUniqueId()));
|
Reference.ES_SYSTEMS.put(player.getUniqueId(), PlayersFile.getPlayersSystems(player.getUniqueId()));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
cachePlayersSystems(player);
|
//cachePlayersSystems(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package net.seanomik.energeticstorage.commands;
|
||||||
|
|
||||||
|
import net.seanomik.energeticstorage.files.ConfigFile;
|
||||||
|
import net.seanomik.energeticstorage.files.PlayersFile;
|
||||||
|
import net.seanomik.energeticstorage.utils.ItemConstructor;
|
||||||
|
import net.seanomik.energeticstorage.utils.PermissionChecks;
|
||||||
|
import net.seanomik.energeticstorage.utils.Reference;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ESReloadCommand implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
ConfigFile.getConfig().reloadConfig();
|
||||||
|
PlayersFile.getConfig().reloadConfig();
|
||||||
|
|
||||||
|
// Recache the systems
|
||||||
|
Reference.ES_SYSTEMS = PlayersFile.getAllSystems();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -99,6 +99,68 @@ public class PlayersFile extends YamlConfiguration {
|
||||||
return getConfig().contains("players." + uuid + ".systems");
|
return getConfig().contains("players." + uuid + ".systems");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<UUID, List<ESSystem>> getAllSystems() {
|
||||||
|
Map<UUID, List<ESSystem>> allSystems = new HashMap<>();
|
||||||
|
|
||||||
|
for (String playerUUID : getConfig().getConfigurationSection("players").getKeys(false)) {
|
||||||
|
List<ESSystem> playersSystems = new ArrayList<>();
|
||||||
|
for (String systemUUID : getConfig().getConfigurationSection("players." + playerUUID + ".systems").getKeys(false)) {
|
||||||
|
String systemPath = "players." + playerUUID + ".systems." + systemUUID + ".";
|
||||||
|
List<ESDrive> drives = new ArrayList<>();
|
||||||
|
|
||||||
|
if (getConfig().contains(systemPath + "drives")) {
|
||||||
|
for (String driveUUID : getConfig().getConfigurationSection(systemPath + "drives").getKeys(false)) {
|
||||||
|
|
||||||
|
Map<ItemStack, Integer> items = new HashMap();
|
||||||
|
if (getConfig().contains(systemPath + "drives." + driveUUID + ".items")) {
|
||||||
|
try {
|
||||||
|
JSONParser jsonParser = new JSONParser();
|
||||||
|
JSONArray itemJsonArray = (JSONArray) jsonParser.parse(getConfig().getString(systemPath + "drives." + driveUUID + ".items"));
|
||||||
|
|
||||||
|
for (int i = 0; i < itemJsonArray.size(); i++) {
|
||||||
|
JSONObject itemObject = (JSONObject) itemJsonArray.get(i);
|
||||||
|
|
||||||
|
Map.Entry<ItemStack, Integer> item = ItemSerialization.deserializeItem((String) itemObject.get("itemYAML"));
|
||||||
|
|
||||||
|
items.put(item.getKey(), item.getValue());
|
||||||
|
}
|
||||||
|
} catch (ParseException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = getConfig().getInt(systemPath + "drives." + driveUUID + ".size");
|
||||||
|
|
||||||
|
drives.add(new ESDrive(size, items));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UUID> trustedUUIDs = new ArrayList<>();
|
||||||
|
if (getConfig().contains(systemPath + "trustedUUIDs")) {
|
||||||
|
try {
|
||||||
|
JSONArray trustedJson = (JSONArray) new JSONParser().parse(getConfig().getString(systemPath + "trustedUUIDs"));
|
||||||
|
for (int i = 0; i < trustedJson.size(); i++) {
|
||||||
|
JSONObject object = (JSONObject) trustedJson.get(i);
|
||||||
|
|
||||||
|
trustedUUIDs.add(UUID.fromString((String) object.get("UUID")));
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPublic = getConfig().getBoolean(systemPath + "public");
|
||||||
|
|
||||||
|
Location loc = Utils.convertStringToLocation(getConfig().getString(systemPath + "loc"));
|
||||||
|
playersSystems.add(new ESSystem(UUID.fromString(playerUUID), UUID.fromString(systemUUID), loc, drives, trustedUUIDs, isPublic));
|
||||||
|
}
|
||||||
|
|
||||||
|
allSystems.put(UUID.fromString(playerUUID), playersSystems);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allSystems;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<ESSystem> getPlayersSystems(UUID uuid) {
|
public static List<ESSystem> getPlayersSystems(UUID uuid) {
|
||||||
List<ESSystem> systems = new ArrayList<>();
|
List<ESSystem> systems = new ArrayList<>();
|
||||||
for (String systemUUID : getConfig().getConfigurationSection("players." + uuid + ".systems").getKeys(false)) {
|
for (String systemUUID : getConfig().getConfigurationSection("players." + uuid + ".systems").getKeys(false)) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.seanomik.energeticstorage.utils;
|
package net.seanomik.energeticstorage.utils;
|
||||||
|
|
||||||
import jdk.internal.jline.internal.Nullable;
|
|
||||||
import net.seanomik.energeticstorage.objects.ESSystem;
|
import net.seanomik.energeticstorage.objects.ESSystem;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -9,6 +8,7 @@ import org.bukkit.World;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
|
@ -8,6 +8,10 @@ commands:
|
||||||
aliases: [egive]
|
aliases: [egive]
|
||||||
description: Give a Energetic Storage item.
|
description: Give a Energetic Storage item.
|
||||||
usage: /esgive
|
usage: /esgive
|
||||||
|
esreload:
|
||||||
|
aliases: [ereload]
|
||||||
|
description: Reload all Energetic Storage configs.
|
||||||
|
usage: /esreload
|
||||||
permissions:
|
permissions:
|
||||||
energeticstorage.*:
|
energeticstorage.*:
|
||||||
description: All Energetic Storage permissions.
|
description: All Energetic Storage permissions.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
driveMaxTypes: 128
|
driveMaxTypes: 128
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: EnergeticStorage
|
name: EnergeticStorage
|
||||||
version: 0.1-SNAPSHOT
|
version: 0.2-SNAPSHOT
|
||||||
main: net.seanomik.energeticstorage.EnergeticStorage
|
main: net.seanomik.energeticstorage.EnergeticStorage
|
||||||
api-version: 1.15
|
api-version: 1.15
|
||||||
authors: [SeanOMik]
|
authors: [SeanOMik]
|
||||||
|
@ -8,6 +8,10 @@ commands:
|
||||||
aliases: [egive]
|
aliases: [egive]
|
||||||
description: Give a Energetic Storage item.
|
description: Give a Energetic Storage item.
|
||||||
usage: /esgive
|
usage: /esgive
|
||||||
|
esreload:
|
||||||
|
aliases: [ereload]
|
||||||
|
description: Reload all Energetic Storage configs.
|
||||||
|
usage: /esreload
|
||||||
permissions:
|
permissions:
|
||||||
energeticstorage.*:
|
energeticstorage.*:
|
||||||
description: All Energetic Storage permissions.
|
description: All Energetic Storage permissions.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Apr 07 00:41:39 CDT 2020
|
#Mon Jul 06 23:29:34 CDT 2020
|
||||||
groupId=net.seanomik
|
groupId=net.seanomik
|
||||||
artifactId=energeticstorage
|
artifactId=energeticstorage
|
||||||
version=0.1-SNAPSHOT
|
version=0.2-SNAPSHOT
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\gui\ESTerminalGUI.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\gui\ESTerminalGUI.java
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\ItemRecipies.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\ItemRecipies.java
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\commands\ESGiveCommand.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\commands\ESGiveCommand.java
|
||||||
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\commands\ESReloadCommand.java
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\Utils.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\Utils.java
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\gui\ESSystemSecurityGUI.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\gui\ESSystemSecurityGUI.java
|
||||||
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\ItemConstructor.java
|
D:\Code\java\spigotPlugins\myPlugins\EnergeticStorage\src\main\java\net\seanomik\energeticstorage\utils\ItemConstructor.java
|
||||||
|
|
Loading…
Reference in New Issue