Removed broken data
This commit is contained in:
@@ -6,11 +6,8 @@ import com.willfp.eco.util.interfaces.EcoRunnable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.talismans.commands.CommandTaldebug;
|
||||
import com.willfp.talismans.commands.CommandTalismans;
|
||||
import com.willfp.talismans.commands.CommandTalreload;
|
||||
import com.willfp.talismans.config.TalismansConfigs;
|
||||
import com.willfp.talismans.data.PlayerData;
|
||||
import com.willfp.talismans.data.inventory.TalismanInventoryListeners;
|
||||
import com.willfp.talismans.display.packets.PacketChat;
|
||||
import com.willfp.talismans.display.packets.PacketOpenWindowMerchant;
|
||||
import com.willfp.talismans.display.packets.PacketSetCreativeSlot;
|
||||
@@ -65,7 +62,6 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
@Override
|
||||
public void disable() {
|
||||
this.getExtensionLoader().unloadExtensions();
|
||||
PlayerData.save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,8 +90,6 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
}
|
||||
}, 1);
|
||||
});
|
||||
|
||||
PlayerData.save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +121,7 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandTaldebug(this),
|
||||
new CommandTalreload(this),
|
||||
new CommandTalismans(this)
|
||||
new CommandTalreload(this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -158,8 +151,7 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
return Arrays.asList(
|
||||
new WatcherTriggers(this),
|
||||
new BlockPlaceListener(),
|
||||
new TalismanCraftListener(),
|
||||
new TalismanInventoryListeners()
|
||||
new TalismanCraftListener()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.willfp.talismans.commands;
|
||||
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.talismans.data.inventory.TalismanInventoryUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandTalismans extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /talismans command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandTalismans(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, "talismans", "talismans.inventory", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
Player player = (Player) sender;
|
||||
TalismanInventoryUtils.showInventory(player);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.talismans.config;
|
||||
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.talismans.config.configs.Data;
|
||||
import com.willfp.talismans.config.configs.TalismanConfig;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -12,11 +11,6 @@ import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class TalismansConfigs {
|
||||
/**
|
||||
* data.yml.
|
||||
*/
|
||||
public static final Data DATA = new Data();
|
||||
|
||||
/**
|
||||
* All talisman-specific configs.
|
||||
*/
|
||||
@@ -28,7 +22,6 @@ public class TalismansConfigs {
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public void updateConfigs() {
|
||||
DATA.update();
|
||||
TALISMAN_CONFIGS.forEach(TalismanYamlConfig::update);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.willfp.talismans.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Data extends BaseConfig {
|
||||
/**
|
||||
* data.yml.
|
||||
*/
|
||||
public Data() {
|
||||
super("data", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config file.
|
||||
*
|
||||
* @return The file.
|
||||
*/
|
||||
public File getFile() {
|
||||
return this.getConfigFile();
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.willfp.talismans.data;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.talismans.config.TalismansConfigs;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PlayerData {
|
||||
/**
|
||||
* All currently loaded data.
|
||||
*/
|
||||
private static final BiMap<UUID, PlayerData> PLAYER_DATA = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* The UUID of the player that owns this data.
|
||||
*/
|
||||
@Getter
|
||||
private final UUID uuid;
|
||||
|
||||
/**
|
||||
* The player's talisman inventory.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private Map<Integer, ItemStack> inventory = new HashMap<>();
|
||||
|
||||
private PlayerData(@NotNull final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all player data to data.yml.
|
||||
*/
|
||||
public static void save() {
|
||||
PLAYER_DATA.forEach((uuid, playerData) -> {
|
||||
TalismansConfigs.DATA.getConfig().set(uuid.toString() + ".inventory", null);
|
||||
playerData.inventory.forEach((integer, itemStack) -> {
|
||||
TalismansConfigs.DATA.getConfig().set(uuid.toString() + ".inventory." + integer, itemStack);
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
TalismansConfigs.DATA.getConfig().save(TalismansConfigs.DATA.getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's data.
|
||||
*
|
||||
* @param player The player to get data for.
|
||||
* @return The data.
|
||||
*/
|
||||
public static PlayerData get(@NotNull final OfflinePlayer player) {
|
||||
if (PLAYER_DATA.containsKey(player.getUniqueId())) {
|
||||
return PLAYER_DATA.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
PlayerData data = new PlayerData(player.getUniqueId());
|
||||
|
||||
if (TalismansConfigs.DATA.getConfig().contains(player.getUniqueId().toString())) {
|
||||
TalismansConfigs.DATA.getConfig().getConfigurationSection(player.getUniqueId().toString() + ".inventory").getKeys(false).forEach(s -> {
|
||||
ItemStack inventoryStack = TalismansConfigs.DATA.getConfig().getItemStack(player.getUniqueId().toString() + ".inventory." + s);
|
||||
|
||||
data.inventory.put(Integer.parseInt(s), inventoryStack);
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
PLAYER_DATA.put(player.getUniqueId(), new PlayerData(player.getUniqueId()));
|
||||
return get(player);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.willfp.talismans.data.inventory;
|
||||
|
||||
import com.willfp.talismans.data.PlayerData;
|
||||
import com.willfp.talismans.talismans.util.TalismanChecks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TalismanInventoryListeners implements Listener {
|
||||
/**
|
||||
* On inventory close.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onTalismanInventoryClose(@NotNull final InventoryCloseEvent event) {
|
||||
if (!event.getView().getTitle().toLowerCase().contains("talisman")) {
|
||||
return;
|
||||
}
|
||||
Map<Integer, ItemStack> contents = new HashMap<>();
|
||||
for (int i = 0; i < event.getInventory().getSize(); i++) {
|
||||
contents.put(i, event.getInventory().getItem(i));
|
||||
}
|
||||
|
||||
PlayerData.get((Player) event.getPlayer()).setInventory(contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* On add item to talisman inventory.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPutItemInTalismanInventory(@NotNull final InventoryClickEvent event) {
|
||||
if (!event.getView().getTitle().toLowerCase().contains("talisman")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (TalismanChecks.getTalismanOnItem(item) == null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (Objects.equals(event.getClickedInventory(), event.getView().getTopInventory())) {
|
||||
ItemStack item = event.getCursor();
|
||||
if (TalismanChecks.getTalismanOnItem(item) == null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.willfp.talismans.data.inventory;
|
||||
|
||||
import com.willfp.talismans.data.PlayerData;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class TalismanInventoryUtils {
|
||||
/**
|
||||
* Show talisman inventory to player.
|
||||
*
|
||||
* @param player The player to show the inventory to.
|
||||
* @return The created inventory.
|
||||
*/
|
||||
public Inventory showInventory(@NotNull final Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Talisman Inventory");
|
||||
PlayerData.get(player).getInventory().forEach(inventory::setItem);
|
||||
player.openInventory(inventory);
|
||||
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user