YeetAPION #176
@ -19,13 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.config;
|
package de.steamwar.bausystem.config;
|
||||||
|
|
||||||
|
import de.steamwar.sql.UserConfig;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class YamlConfig implements ConfigurationSerializable {
|
public class YamlConfig implements ConfigurationSerializable {
|
||||||
@ -34,6 +38,14 @@ public class YamlConfig implements ConfigurationSerializable {
|
|||||||
ConfigurationSerialization.registerClass(configType);
|
ConfigurationSerialization.registerClass(configType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static YamlConfiguration fromUserConfig(UUID uuid, String name) {
|
||||||
|
String config = UserConfig.getConfig(uuid, name);
|
||||||
|
if(config == null)
|
||||||
|
return new YamlConfiguration();
|
||||||
|
|
||||||
|
return YamlConfiguration.loadConfiguration(new StringReader(config));
|
||||||
|
}
|
||||||
|
|
||||||
public YamlConfig() {}
|
public YamlConfig() {}
|
||||||
|
|
||||||
public YamlConfig(ConfigurationSection configuration) {
|
public YamlConfig(ConfigurationSection configuration) {
|
||||||
@ -73,4 +85,11 @@ public class YamlConfig implements ConfigurationSerializable {
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YamlConfiguration toYaml() {
|
||||||
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
|
for(Map.Entry<String, Object> entry : serialize().entrySet())
|
||||||
|
config.set(entry.getKey(), entry.getValue());
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,28 +21,29 @@ package de.steamwar.bausystem.configplayer;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigField;
|
import de.steamwar.bausystem.config.ConfigField;
|
||||||
import de.steamwar.bausystem.config.YamlConfig;
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
|
import de.steamwar.bausystem.features.testblock.depthcounter.CountMode;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.sql.UserConfig;
|
import de.steamwar.sql.UserConfig;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Config extends YamlConfig {
|
public class Config extends YamlConfig {
|
||||||
|
|
||||||
private static final Map<UUID, Config> playerConfigurations = new HashMap<>();
|
private static final Map<UUID, Config> playerConfigurations = new HashMap<>();
|
||||||
|
|
||||||
public static Config get(Player player) {
|
public static Config get(Player player) { //TODO: NULL
|
||||||
return playerConfigurations.computeIfAbsent(player.getUniqueId(), uuid -> new Config(uuid, YamlConfiguration.loadConfiguration(new StringReader(UserConfig.getConfig(uuid, "bausystem")))));
|
return playerConfigurations.computeIfAbsent(player.getUniqueId(), uuid -> new Config(uuid, fromUserConfig(uuid, "bausystem")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAll() {
|
public static void saveAll() {
|
||||||
@ -57,16 +58,58 @@ public class Config extends YamlConfig {
|
|||||||
@ConfigField
|
@ConfigField
|
||||||
private boolean nightvision;
|
private boolean nightvision;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ConfigField
|
||||||
|
private List<String> depthCounter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ConfigField
|
||||||
|
private final Map<String, Integer> baugui = new HashMap<>();
|
||||||
|
|
||||||
private Config(UUID uuid, ConfigurationSection configuration) {
|
private Config(UUID uuid, ConfigurationSection configuration) {
|
||||||
super(configuration);
|
super(configuration);
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
||||||
|
if(depthCounter == null)
|
||||||
|
depthCounter = CountMode.ALL().stream().map(CountMode::name).collect(Collectors.toList());
|
||||||
|
|
||||||
|
if(baugui.isEmpty()) {
|
||||||
|
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
||||||
|
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
||||||
|
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
||||||
|
// 27: 6 | 28: ? | 29: ? | 30: ? | 31: ? | 32: ? | 33: ? | 34: ? | 35: 18
|
||||||
|
// 36: ? | 37: 23 | 38: 20 | 39: 8 | 40: 22 | 41: 26 | 42: 12 | 43: 14 | 44: ?
|
||||||
|
|
||||||
|
baugui.put("size", 45);
|
||||||
|
baugui.put("10", 2);
|
||||||
|
baugui.put("3", 3);
|
||||||
|
baugui.put("7", 4);
|
||||||
|
baugui.put("17", 5);
|
||||||
|
baugui.put("15", 6);
|
||||||
|
baugui.put("5", 9);
|
||||||
|
baugui.put("16", 17);
|
||||||
|
baugui.put("4", 18);
|
||||||
|
baugui.put("19", 20);
|
||||||
|
baugui.put("21", 21);
|
||||||
|
baugui.put("9", 22);
|
||||||
|
baugui.put("0", 23);
|
||||||
|
baugui.put("1", 24);
|
||||||
|
baugui.put("11", 26);
|
||||||
|
baugui.put("6", 27);
|
||||||
|
baugui.put("18", 35);
|
||||||
|
baugui.put("23", 37);
|
||||||
|
baugui.put("20", 38);
|
||||||
|
baugui.put("8", 39);
|
||||||
|
baugui.put("22", 40);
|
||||||
|
baugui.put("26", 41);
|
||||||
|
baugui.put("12", 42);
|
||||||
|
baugui.put("14", 43);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
UserConfig.updatePlayerConfig(uuid, "bausystem", toYaml().saveToString());
|
||||||
for(Map.Entry<String, Object> entry : serialize().entrySet())
|
|
||||||
config.set(entry.getKey(), entry.getValue());
|
|
||||||
UserConfig.updatePlayerConfig(uuid, "bausystem", config.saveToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.configplayer;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.hotbar.DefaultHotbar;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class ConfigCreator {
|
|
||||||
|
|
||||||
public static final int currentVersion = 1;
|
|
||||||
|
|
||||||
public YAPIONObject createDefaultConfig() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
// This call should never be touched
|
|
||||||
yapionObject.add("@version", currentVersion);
|
|
||||||
|
|
||||||
// Any initialising goes into here
|
|
||||||
yapionObject.add("baugui", defaultBauGui());
|
|
||||||
|
|
||||||
// Default Hotbar Gui
|
|
||||||
yapionObject.add("hotbar", DefaultHotbar.defaultHotbar());
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
private YAPIONObject defaultBauGui() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
|
|
||||||
// 0: ? | 1: ? | 2: 10 | 3: 3 | 4: 7 | 5: 17 | 6: 15 | 7: ? | 8: ?
|
|
||||||
// 9: 5 | 10: ? | 11: ? | 12: ? | 13: ? | 14: ? | 15: ? | 16: ? | 17: 16
|
|
||||||
// 18: 4 | 19: ? | 20: 19 | 21: 21 | 22: 9 | 23: 0 | 24: 1 | 25: ? | 26: 11
|
|
||||||
// 27: 6 | 28: ? | 29: ? | 30: ? | 31: ? | 32: ? | 33: ? | 34: ? | 35: 18
|
|
||||||
// 36: ? | 37: 23 | 38: 20 | 39: 8 | 40: 22 | 41: 26 | 42: 12 | 43: 14 | 44: ?
|
|
||||||
|
|
||||||
yapionObject.add("10", 2).add("3", 3).add("7", 4).add("17", 5).add("15", 6);
|
|
||||||
yapionObject.add("5", 9).add("4", 18).add("6", 27);
|
|
||||||
yapionObject.add("16", 17).add("11", 26).add("18", 35);
|
|
||||||
yapionObject.add("19", 20).add("21", 21).add("9", 22).add("0", 23).add("1", 24);
|
|
||||||
yapionObject.add("23", 37).add("20", 38).add("8", 39).add("22", 40).add("26", 41).add("12", 42).add("14", 43);
|
|
||||||
yapionObject.add("size", 45);
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
}
|
|
@ -67,7 +67,7 @@ public class BauGUI {
|
|||||||
if (!updating) {
|
if (!updating) {
|
||||||
OPEN_INVS.add(p);
|
OPEN_INVS.add(p);
|
||||||
}
|
}
|
||||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||||
SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
|
SWInventory inv = new SWInventory(p, mapping.getSize(), BauSystem.MESSAGE.parse("GUI_NAME", p));
|
||||||
getITEMS().values().forEach(item -> {
|
getITEMS().values().forEach(item -> {
|
||||||
if (!mapping.isShown(item.getId())) {
|
if (!mapping.isShown(item.getId())) {
|
||||||
|
@ -53,7 +53,7 @@ public class BauGuiEditor implements Listener {
|
|||||||
private static final List<Player> open_Edits = new ArrayList<>();
|
private static final List<Player> open_Edits = new ArrayList<>();
|
||||||
|
|
||||||
public static void openGuiEditor(Player p, ItemStack cursor) {
|
public static void openGuiEditor(Player p, ItemStack cursor) {
|
||||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||||
Inventory inv = Bukkit.createInventory(null, mapping.getSize() + 9, BauSystem.MESSAGE.parse("GUI_EDITOR_TITLE", p));
|
Inventory inv = Bukkit.createInventory(null, mapping.getSize() + 9, BauSystem.MESSAGE.parse("GUI_EDITOR_TITLE", p));
|
||||||
for (Map.Entry<Integer, Integer> e : mapping.getMapping().entrySet()) {
|
for (Map.Entry<Integer, Integer> e : mapping.getMapping().entrySet()) {
|
||||||
if (e.getValue() >= 0) {
|
if (e.getValue() >= 0) {
|
||||||
@ -78,7 +78,6 @@ public class BauGuiEditor implements Listener {
|
|||||||
p.openInventory(inv);
|
p.openInventory(inv);
|
||||||
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
|
p.getOpenInventory().setCursor(cursor == null ? new SWItem().getItemStack() : cursor);
|
||||||
open_Edits.add(p);
|
open_Edits.add(p);
|
||||||
BauGuiMapping.startWatchdog();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack addId(ItemStack itemStack, int id) {
|
private static ItemStack addId(ItemStack itemStack, int id) {
|
||||||
@ -101,7 +100,7 @@ public class BauGuiEditor implements Listener {
|
|||||||
|
|
||||||
ItemStack i = event.getCurrentItem();
|
ItemStack i = event.getCurrentItem();
|
||||||
Player p = (Player) event.getWhoClicked();
|
Player p = (Player) event.getWhoClicked();
|
||||||
BauGuiMapping mapping = BauGuiMapping.getGuiMapping(p);
|
BauGuiMapping mapping = new BauGuiMapping(p);
|
||||||
if (event.getClickedInventory() == p.getInventory()) {
|
if (event.getClickedInventory() == p.getInventory()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -194,13 +193,10 @@ public class BauGuiEditor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveMapping(Player p) {
|
private void saveMapping(Player p) {
|
||||||
saveMapping(p.getOpenInventory(), BauGuiMapping.getGuiMapping(p));
|
saveMapping(p.getOpenInventory(), new BauGuiMapping(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveMapping(InventoryView view, BauGuiMapping mapping) {
|
private void saveMapping(InventoryView view, BauGuiMapping mapping) {
|
||||||
if (mapping.isSaved()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HashMap<Integer, Integer> newMapping = new HashMap<>();
|
HashMap<Integer, Integer> newMapping = new HashMap<>();
|
||||||
|
|
||||||
for (int i = 0; i < view.getTopInventory().getContents().length; i++) {
|
for (int i = 0; i < view.getTopInventory().getContents().length; i++) {
|
||||||
@ -216,7 +212,6 @@ public class BauGuiEditor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapping.setMapping(newMapping);
|
mapping.setMapping(newMapping);
|
||||||
mapping.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -227,7 +222,7 @@ public class BauGuiEditor implements Listener {
|
|||||||
|
|
||||||
Player p = (Player) event.getPlayer();
|
Player p = (Player) event.getPlayer();
|
||||||
|
|
||||||
saveMapping(event.getView(), BauGuiMapping.getGuiMapping(p));
|
saveMapping(event.getView(), new BauGuiMapping(p));
|
||||||
open_Edits.remove(p);
|
open_Edits.remove(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,82 +19,50 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.gui.editor;
|
package de.steamwar.bausystem.features.gui.editor;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.bausystem.features.gui.BauGUI;
|
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BauGuiMapping {
|
public class BauGuiMapping {
|
||||||
|
|
||||||
private static final HashMap<UUID, BauGuiMapping> fromUUID = new HashMap<>();
|
|
||||||
private static final List<BauGuiMapping> mappings = new ArrayList<>();
|
|
||||||
|
|
||||||
private static BukkitTask task;
|
|
||||||
|
|
||||||
public static void startWatchdog() {
|
|
||||||
if (task == null) {
|
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
|
||||||
mappings.forEach(BauGuiMapping::tick);
|
|
||||||
if (BauGuiEditor.getOpen_Edits().isEmpty()) {
|
|
||||||
bukkitTask.cancel();
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}, 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final YAPIONObject object;
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Player owner;
|
private final Player owner;
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private boolean saved;
|
|
||||||
|
|
||||||
protected BauGuiMapping(YAPIONObject object, Player p) {
|
public BauGuiMapping(Player p) {
|
||||||
this.object = object;
|
|
||||||
this.owner = p;
|
this.owner = p;
|
||||||
fromUUID.put(p.getUniqueId(), this);
|
|
||||||
mappings.add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BauGuiMapping getGuiMapping(Player p) {
|
private Map<String, Integer> getInternalMapping() {
|
||||||
BauGuiMapping mapping = fromUUID.get(p.getUniqueId());
|
return Config.get(owner).getBaugui();
|
||||||
|
|
||||||
if (mapping == null) {
|
|
||||||
YAPIONObject yapionObject = Config.getInstance().get(p);
|
|
||||||
mapping = new BauGuiMapping(yapionObject.getObject("baugui"), p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapping;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShown(int id) {
|
public boolean isShown(int id) {
|
||||||
return object.getPlainValueOrDefault(Integer.toString(id), -1) >= 0;
|
return getInternalMapping().getOrDefault(Integer.toString(id), -1) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot(int id) {
|
public int getSlot(int id) {
|
||||||
return object.getPlainValue(Integer.toString(id));
|
return getInternalMapping().getOrDefault(Integer.toString(id), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Integer> getMapping() {
|
public Map<Integer, Integer> getMapping() {
|
||||||
return internalReadMap();
|
return getInternalMapping().entrySet().stream().collect(Collectors.toMap(entry -> Integer.valueOf(entry.getKey()), Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMapping(Map<Integer, Integer> mapping) {
|
public void setMapping(Map<Integer, Integer> mapping) {
|
||||||
internalWriteMap(mapping);
|
Map<String, Integer> map = getInternalMapping();
|
||||||
|
map.clear();
|
||||||
|
|
||||||
|
for(Map.Entry<Integer, Integer> entry : mapping.entrySet())
|
||||||
|
map.put(String.valueOf(entry.getKey()), entry.getValue());
|
||||||
|
|
||||||
|
Config.get(owner).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return object.getPlainValueOrDefault("size", 45);
|
return getInternalMapping().getOrDefault("size", 45);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(int size) {
|
public void setSize(int size) {
|
||||||
@ -102,37 +70,6 @@ public class BauGuiMapping {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object.add("size", size);
|
getInternalMapping().put("size", size);
|
||||||
}
|
|
||||||
|
|
||||||
private void tick() {
|
|
||||||
this.saved = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (saved) return;
|
|
||||||
YAPIONObject config = Config.getInstance().get(owner);
|
|
||||||
config.add("baugui", object);
|
|
||||||
Config.getInstance().save(owner);
|
|
||||||
saved = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<Integer, Integer> internalReadMap() {
|
|
||||||
Map<Integer, Integer> map = new HashMap<>();
|
|
||||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
|
||||||
Integer value = object.getPlainValueOrDefault(e.getKey().toString(), -1);
|
|
||||||
if (value == -1) continue;
|
|
||||||
map.put(e.getKey(), value);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void internalWriteMap(Map<Integer, Integer> map) {
|
|
||||||
for (Map.Entry<Integer, BauGuiItem> e : BauGUI.getITEMS().entrySet()) {
|
|
||||||
object.remove(e.getKey().toString());
|
|
||||||
Integer value = map.getOrDefault(e.getKey(), -1);
|
|
||||||
if (value == -1) continue;
|
|
||||||
object.add(e.getKey().toString(), value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,75 +19,89 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.hotbar;
|
package de.steamwar.bausystem.features.hotbar;
|
||||||
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.config.ConfigField;
|
||||||
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import lombok.experimental.UtilityClass;
|
import de.steamwar.sql.UserConfig;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
import yapion.hierarchy.types.YAPIONValue;
|
|
||||||
import yapion.parser.YAPIONParser;
|
|
||||||
import yapion.serializing.YAPIONDeserializer;
|
|
||||||
import yapion.serializing.YAPIONSerializer;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
public class DefaultHotbar extends YamlConfig {
|
||||||
public class DefaultHotbar {
|
|
||||||
|
|
||||||
private final YAPIONArray DEFAULT_HOTBAR = YAPIONParser.parse("{[{@type(org.bukkit.inventory.ItemStack)v(2230)type(WOODEN_AXE)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(WorldEdit Wand)lore{@type(java.util.ArrayList)values[Left click: select pos #1,Right click: select pos #2]}}},{@type(org.bukkit.inventory.ItemStack)v(2230)type(COMPASS)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(Navigation Wand)lore{@type(java.util.ArrayList)values[Left click: jump to location,Right click: pass through walls]}}},null,null,null,null,null,null,{@type(org.bukkit.inventory.ItemStack)v(2230)type(NETHER_STAR)meta{@type(org.bukkit.inventory.meta.ItemMeta)meta-type(UNSPECIFIC)display-name(§eBau GUI)}},null,null,{@type(org.bukkit.inventory.ItemStack)v(3117)type(ELYTRA)},null]}").getArray("");
|
public static final String configName = "bauhotbar-" + Core.getVersion();
|
||||||
|
|
||||||
public void updateHotbar(Player p) {
|
public static DefaultHotbar get(Player p) {
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
return new DefaultHotbar(p, fromUserConfig(p.getUniqueId(), configName));
|
||||||
System.arraycopy(p.getInventory().getContents(), 0, hotbar, 0, 9);
|
}
|
||||||
System.arraycopy(p.getInventory().getArmorContents(), 0, hotbar, 9, 4);
|
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
private final Player player;
|
||||||
for (ItemStack itemStack : hotbar) {
|
|
||||||
if (itemStack != null) {
|
@Getter
|
||||||
yapionArray.add(YAPIONSerializer.serialize(itemStack));
|
@ConfigField
|
||||||
} else {
|
private final List<ItemStack> hotbar = new ArrayList<>(13);
|
||||||
yapionArray.add(new YAPIONValue<>(null));
|
|
||||||
}
|
public DefaultHotbar(Player player, ConfigurationSection config) {
|
||||||
|
super(config);
|
||||||
|
this.player = player;
|
||||||
|
|
||||||
|
if(hotbar.isEmpty()) {
|
||||||
|
hotbar.add(newNamedStack(Material.WOODEN_AXE, "WorldEdit Wand", "Left click: select pos #1", "Right click: select pos #2"));
|
||||||
|
hotbar.add(newNamedStack(Material.COMPASS, "Navigation Wand", "Left click: jump to location", "Right click: pass through walls"));
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(newNamedStack(Material.NETHER_STAR, "§eBau GUI"));
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(null);
|
||||||
|
hotbar.add(new ItemStack(Material.ELYTRA));
|
||||||
|
hotbar.add(null);
|
||||||
}
|
}
|
||||||
Config.getInstance().get(p).add("hotbar-" + Core.getVersion(), yapionArray);
|
|
||||||
Config.getInstance().save(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHotbar(Player p) {
|
public void update() {
|
||||||
ItemStack[] hotbar = getItems(p);
|
hotbar.clear();
|
||||||
ItemStack[] inv = p.getInventory().getContents();
|
|
||||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
for(int i = 0; i < 9; i++)
|
||||||
System.arraycopy(hotbar, 0, inv, 0, 9);
|
hotbar.add(player.getInventory().getContents()[i]);
|
||||||
System.arraycopy(hotbar, 9, armor, 0, 4);
|
|
||||||
p.getInventory().setContents(inv);
|
for(int i = 0; i < 4; i++)
|
||||||
p.getInventory().setArmorContents(armor);
|
hotbar.add(player.getInventory().getArmorContents()[i]);
|
||||||
|
|
||||||
|
UserConfig.updatePlayerConfig(player.getUniqueId(), configName, toYaml().saveToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getItems(Player p) {
|
public void load() {
|
||||||
Config.getInstance().get(p).remap("hotbar", "hotbar-19");
|
ItemStack[] inv = player.getInventory().getContents();
|
||||||
YAPIONArray yapionArray = Config.getInstance().get(p).getYAPIONArrayOrSetDefault("hotbar-" + Core.getVersion(), defaultHotbar());
|
ItemStack[] armor = player.getInventory().getArmorContents();
|
||||||
ItemStack[] hotbar = new ItemStack[13];
|
System.arraycopy(hotbar.toArray(new ItemStack[0]), 0, inv, 0, 9);
|
||||||
Set<Integer> invalid = new HashSet<>();
|
System.arraycopy(hotbar.toArray(new ItemStack[0]), 9, armor, 0, 4);
|
||||||
yapionArray.forEach((integer, yapionAnyType) -> {
|
player.getInventory().setContents(inv);
|
||||||
if (yapionAnyType instanceof YAPIONValue) {
|
player.getInventory().setArmorContents(armor);
|
||||||
hotbar[integer] = null;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
hotbar[integer] = YAPIONDeserializer.deserialize((YAPIONObject) yapionAnyType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
invalid.add(integer);
|
|
||||||
hotbar[integer] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
invalid.forEach(i -> yapionArray.set(i, new YAPIONValue<>(null)));
|
|
||||||
if (!invalid.isEmpty()) Config.getInstance().save(p);
|
|
||||||
return hotbar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public YAPIONArray defaultHotbar() {
|
private static ItemStack newNamedStack(Material material, String displayName, String... lore) {
|
||||||
return DEFAULT_HOTBAR;
|
ItemStack stack = new ItemStack(material);
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
|
||||||
|
if(displayName != null)
|
||||||
|
meta.setDisplayName(displayName);
|
||||||
|
|
||||||
|
if(lore.length > 0)
|
||||||
|
meta.setLore(Arrays.stream(lore).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import de.steamwar.linkage.Linked;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class HotbarCommand extends SWCommand {
|
public class HotbarCommand extends SWCommand {
|
||||||
|
|
||||||
@ -36,23 +38,23 @@ public class HotbarCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
@Register(value = "load", description = "HOTBAR_HELP_LOAD")
|
||||||
public void loadHotbar(Player p) {
|
public void loadHotbar(Player p) {
|
||||||
DefaultHotbar.setHotbar(p);
|
DefaultHotbar.get(p).load();
|
||||||
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "save", description = "HOTBAR_HELP_SAVE")
|
@Register(value = "save", description = "HOTBAR_HELP_SAVE")
|
||||||
public void saveHotbar(Player p) {
|
public void saveHotbar(Player p) {
|
||||||
DefaultHotbar.updateHotbar(p);
|
DefaultHotbar.get(p).update();
|
||||||
BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
|
BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
@Register(value = "show", description = "HOTBAR_HELP_SHOW")
|
||||||
public void showHotbar(Player p) {
|
public void showHotbar(Player p) {
|
||||||
SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
|
||||||
ItemStack[] hotbar = DefaultHotbar.getItems(p);
|
List<ItemStack> hotbar = DefaultHotbar.get(p).getHotbar();
|
||||||
for (int i = 0; i < hotbar.length; i++) {
|
for (int i = 0; i < hotbar.size(); i++) {
|
||||||
if (hotbar[i] == null) continue;
|
if (hotbar.get(i) == null) continue;
|
||||||
inv.setItem(i, hotbar[i], clickType -> {
|
inv.setItem(i, hotbar.get(i), clickType -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
inv.open();
|
inv.open();
|
||||||
|
@ -31,7 +31,7 @@ public class HotbarListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
if (allNull(event.getPlayer().getInventory().getContents()) && allNull(event.getPlayer().getInventory().getArmorContents())) {
|
||||||
DefaultHotbar.setHotbar(event.getPlayer());
|
DefaultHotbar.get(event.getPlayer()).load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,9 @@ import net.md_5.bungee.api.chat.ClickEvent;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import yapion.hierarchy.output.StringOutput;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class SkinCommand extends SWCommand {
|
public class SkinCommand extends SWCommand {
|
||||||
@ -98,17 +93,15 @@ public class SkinCommand extends SWCommand {
|
|||||||
Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile);
|
Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
Prototype.Skin skin = new Prototype.Skin(Collections.emptyMap());
|
||||||
yapionObject.add("name", name);
|
|
||||||
if (!creator.equals("public")) {
|
if (!creator.equals("public")) {
|
||||||
yapionObject.add("creator", creator);
|
skin.setCreator(creator);
|
||||||
}
|
}
|
||||||
yapionObject.add("type", typeKuerzel);
|
skin.setSchematic(arenaFile.getPath());
|
||||||
yapionObject.add("schematic", arenaFile.getPath());
|
|
||||||
if (testblockFile != null) {
|
if (testblockFile != null) {
|
||||||
yapionObject.add("testblockSchematic", testblockFile.getPath());
|
skin.setTestblockSchematic(testblockFile.getPath());
|
||||||
}
|
}
|
||||||
BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yapionObject.toYAPION(new StringOutput(true)).getResult()));
|
BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, skin.toYaml().saveToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register("boundary")
|
@Register("boundary")
|
||||||
|
@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.Region;
|
|||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -35,8 +34,6 @@ public class DepthCounter {
|
|||||||
|
|
||||||
public final Map<Region, Set<Depth>> depthMap = new HashMap<>();
|
public final Map<Region, Set<Depth>> depthMap = new HashMap<>();
|
||||||
|
|
||||||
private static final YAPIONObject DEFAULT = new YAPIONObject().add("X", "").add("Y", "").add("Z", "");
|
|
||||||
|
|
||||||
public void toggleMode(final Player p, final CountMode countMode) {
|
public void toggleMode(final Player p, final CountMode countMode) {
|
||||||
if (isActive(p, countMode)) {
|
if (isActive(p, countMode)) {
|
||||||
removeMode(p, countMode);
|
removeMode(p, countMode);
|
||||||
@ -46,29 +43,27 @@ public class DepthCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive(final Player p, final CountMode countMode) {
|
public boolean isActive(final Player p, final CountMode countMode) {
|
||||||
return Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).containsKey(countMode.name());
|
return Config.get(p).getDepthCounter().contains(countMode.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMode(final Player p, final CountMode countMode) {
|
public void addMode(final Player p, final CountMode countMode) {
|
||||||
if (!isActive(p, countMode)) {
|
if (!isActive(p, countMode)) {
|
||||||
Config.getInstance().get(p).getObject("depth-counter").add(countMode.name(), "");
|
Config.get(p).getDepthCounter().add(countMode.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMode(final Player p, final CountMode countMode) {
|
public void removeMode(final Player p, final CountMode countMode) {
|
||||||
if (isActive(p, countMode)) {
|
if (isActive(p, countMode)) {
|
||||||
Config.getInstance().get(p).getObject("depth-counter").remove(countMode.name());
|
Config.get(p).getDepthCounter().remove(countMode.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModes(final Player p, final Set<CountMode> countModes) {
|
public void setModes(final Player p, final Set<CountMode> countModes) {
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
Config.get(p).setDepthCounter(countModes.stream().map(CountMode::name).collect(Collectors.toList()));
|
||||||
countModes.forEach(countMode -> yapionObject.put(countMode.name(), ""));
|
|
||||||
Config.getInstance().get(p).put("depth-counter", yapionObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePlayer(final Player p) {
|
public void removePlayer(final Player p) {
|
||||||
Config.getInstance().get(p).put("depth-counter", new YAPIONObject());
|
Config.get(p).getDepthCounter().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector blockVector(Vector vector) {
|
public Vector blockVector(Vector vector) {
|
||||||
@ -76,11 +71,7 @@ public class DepthCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<CountMode> getModes(Player p) {
|
public Set<CountMode> getModes(Player p) {
|
||||||
Set<CountMode> countModes = new HashSet<>();
|
return Config.get(p).getDepthCounter().stream().map(CountMode::valueOf).sorted().collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).forEach((s, yapionAnyType) -> {
|
|
||||||
countModes.add(CountMode.valueOf(s));
|
|
||||||
});
|
|
||||||
return countModes.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasModes(Player p) {
|
public boolean hasModes(Player p) {
|
||||||
|
@ -33,9 +33,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import yapion.utils.ReflectionsUtils;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -45,7 +43,7 @@ import java.util.stream.Collectors;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class FreezeUtils {
|
public class FreezeUtils {
|
||||||
|
|
||||||
private static final Field field;
|
private static final Reflection.FieldAccessor<Boolean> field;
|
||||||
public static final boolean freezeEnabled;
|
public static final boolean freezeEnabled;
|
||||||
|
|
||||||
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null);
|
private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null);
|
||||||
@ -56,8 +54,11 @@ public class FreezeUtils {
|
|||||||
private static final World world;
|
private static final World world;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
field = ReflectionsUtils.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed");
|
Reflection.FieldAccessor<Boolean> f = null;
|
||||||
if (field != null) field.setAccessible(true);
|
try {
|
||||||
|
f = Reflection.getField("{nms.server.level}.WorldServer", "freezed", boolean.class);
|
||||||
|
} catch (IllegalArgumentException ignored) {}
|
||||||
|
field = f;
|
||||||
freezeEnabled = field != null;
|
freezeEnabled = field != null;
|
||||||
world = Bukkit.getWorlds().get(0);
|
world = Bukkit.getWorlds().get(0);
|
||||||
}
|
}
|
||||||
@ -76,13 +77,9 @@ public class FreezeUtils {
|
|||||||
|
|
||||||
private void setFreeze(World world, boolean state) {
|
private void setFreeze(World world, boolean state) {
|
||||||
if (freezeEnabled) {
|
if (freezeEnabled) {
|
||||||
try {
|
field.set(getWorldHandle.invoke(world), state);
|
||||||
field.set(getWorldHandle.invoke(world), state);
|
cacheEntityPackets(state);
|
||||||
cacheEntityPackets(state);
|
frozen = state;
|
||||||
frozen = state;
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
// Ignored;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,88 +19,70 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.warp;
|
package de.steamwar.bausystem.features.warp;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.config.ConfigField;
|
||||||
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.*;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.SoundCategory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Warp {
|
public class Warp extends YamlConfig {
|
||||||
|
|
||||||
private static Map<String, Warp> warpMap = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
Warp worldSpawn = new Warp("WorldSpawn");
|
|
||||||
worldSpawn.setLocation(Bukkit.getWorlds().get(0).getSpawnLocation());
|
|
||||||
worldSpawn.setMat(Material.NETHER_STAR);
|
|
||||||
warpMap.put("WorldSpawn", worldSpawn);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ConfigField
|
||||||
private String name;
|
private String name;
|
||||||
|
@ConfigField
|
||||||
private Location location;
|
private Location location;
|
||||||
|
@ConfigField
|
||||||
private Material mat;
|
private Material mat;
|
||||||
|
|
||||||
private Warp(String name) {
|
public Warp(String name, Location location, Material mat) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.location = location;
|
||||||
|
this.mat = mat;
|
||||||
|
|
||||||
|
WorldData.getInstance().addWarp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Warp(String name, Player player) {
|
public Warp(String name, Player player) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.location = player.getLocation();
|
this.location = player.getLocation();
|
||||||
this.mat = Material.COMPASS;
|
this.mat = Material.COMPASS;
|
||||||
warpMap.put(name, this);
|
|
||||||
|
WorldData.getInstance().addWarp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Warp(String name, YAPIONObject object) {
|
public Warp(Map<String, Object> map) {
|
||||||
this.name = name;
|
super(map);
|
||||||
double x = object.getPlainValue("x");
|
|
||||||
double y = object.getPlainValue("y");
|
|
||||||
double z = object.getPlainValue("z");
|
|
||||||
float yaw = object.getPlainValue("yaw");
|
|
||||||
float pitch = object.getPlainValue("pitch");
|
|
||||||
location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch);
|
|
||||||
mat = Material.getMaterial(object.getPlainValue("material"));
|
|
||||||
warpMap.put(name, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public YAPIONObject output() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("x", location.getX());
|
|
||||||
yapionObject.add("y", location.getY());
|
|
||||||
yapionObject.add("z", location.getZ());
|
|
||||||
yapionObject.add("yaw", location.getYaw());
|
|
||||||
yapionObject.add("pitch", location.getPitch());
|
|
||||||
yapionObject.add("material", mat.toString());
|
|
||||||
return yapionObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getWarpNames() {
|
public static Set<String> getWarpNames() {
|
||||||
return warpMap.keySet();
|
return WorldData.getInstance().getWarps().keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Warp> getWarps() {
|
public static List<Warp> getWarps() {
|
||||||
return new ArrayList<>(warpMap.values());
|
return new ArrayList<>(WorldData.getInstance().getWarps().values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Warp getWarp(String name) {
|
public static Warp getWarp(String name) {
|
||||||
return warpMap.get(name);
|
return WorldData.getInstance().getWarps().get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMat(Material mat) {
|
public void setMat(Material mat) {
|
||||||
this.mat = mat;
|
this.mat = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Location location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
warpMap.remove(name);
|
WorldData.getInstance().getWarps().remove(name);
|
||||||
WorldData.getWarpData().remove(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void teleport(Player player) {
|
public void teleport(Player player) {
|
||||||
|
@ -22,26 +22,22 @@ package de.steamwar.bausystem.features.warp;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.utils.ListChatView;
|
import de.steamwar.bausystem.utils.ListChatView;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.linkage.api.Disable;
|
|
||||||
import de.steamwar.linkage.api.Enable;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class WarpCommand extends SWCommand implements Disable, Enable {
|
public class WarpCommand extends SWCommand {
|
||||||
|
|
||||||
private static final String[] FORBIDDEN_NAMES = new String[]{
|
private static final String[] FORBIDDEN_NAMES = new String[]{
|
||||||
"add", "create", "delete", "list", "info", "gui"
|
"add", "create", "delete", "list", "info", "gui"
|
||||||
@ -141,19 +137,4 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
|
|||||||
player.performCommand("warp list " + String.join(" ", args));
|
player.performCommand("warp list " + String.join(" ", args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() {
|
|
||||||
WorldData.getWarpData().forEach((name, yapionAnyType) -> {
|
|
||||||
new Warp(name, (YAPIONObject) yapionAnyType);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
YAPIONObject yapionObject = WorldData.getWarpData();
|
|
||||||
for (Warp warp : Warp.getWarps()) {
|
|
||||||
yapionObject.add(warp.getName(), warp.output());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.bausystem.region;
|
|||||||
import de.steamwar.bausystem.config.ConfigField;
|
import de.steamwar.bausystem.config.ConfigField;
|
||||||
import de.steamwar.bausystem.config.YamlConfig;
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -53,6 +54,7 @@ public class Prototype extends YamlConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
public static class Skin extends YamlConfig {
|
public static class Skin extends YamlConfig {
|
||||||
@ConfigField
|
@ConfigField
|
||||||
private String creator;
|
private String creator;
|
||||||
|
@ -21,24 +21,17 @@ package de.steamwar.bausystem.worlddata;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.config.ConfigField;
|
import de.steamwar.bausystem.config.ConfigField;
|
||||||
import de.steamwar.bausystem.config.YamlConfig;
|
import de.steamwar.bausystem.config.YamlConfig;
|
||||||
|
import de.steamwar.bausystem.features.warp.Warp;
|
||||||
import de.steamwar.bausystem.region.FlagStorage;
|
import de.steamwar.bausystem.region.FlagStorage;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserConfig;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import yapion.hierarchy.output.FileOutput;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
import yapion.parser.InputStreamCharsets;
|
|
||||||
import yapion.parser.YAPIONParser;
|
|
||||||
import yapion.parser.options.StreamOptions;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -47,7 +40,8 @@ public class WorldData extends YamlConfig {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
ConfigurationSerialization.registerClass(FlagStorage.class);
|
ConfigurationSerialization.registerClass(FlagStorage.class);
|
||||||
YamlConfig.register(RegionConfig.class);
|
register(RegionConfig.class);
|
||||||
|
register(Warp.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yml");
|
private static final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yml");
|
||||||
@ -56,28 +50,29 @@ public class WorldData extends YamlConfig {
|
|||||||
|
|
||||||
@ConfigField
|
@ConfigField
|
||||||
private final Map<String, RegionConfig> regionConfigs = new HashMap<>();
|
private final Map<String, RegionConfig> regionConfigs = new HashMap<>();
|
||||||
|
@Getter
|
||||||
|
@ConfigField
|
||||||
|
private final Map<String, Warp> warps = new HashMap<>();
|
||||||
|
|
||||||
public WorldData(ConfigurationSection configuration) {
|
public WorldData(ConfigurationSection configuration) {
|
||||||
super(configuration);
|
super(configuration);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
if(warps.isEmpty()) {
|
||||||
|
new Warp("WorldSpawn", Bukkit.getWorlds().get(0).getSpawnLocation(), Material.NETHER_STAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegionConfig getRegionConfig(String region) {
|
public RegionConfig getRegionConfig(String region) {
|
||||||
return regionConfigs.computeIfAbsent(region, name -> new RegionConfig());
|
return regionConfigs.computeIfAbsent(region, name -> new RegionConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public YAPIONObject getWarpData() {
|
public void addWarp(Warp warp) {
|
||||||
return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject());
|
warps.put(warp.getName(), warp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
|
||||||
for(Map.Entry<String, Object> entry : serialize().entrySet())
|
|
||||||
config.set(entry.getKey(), entry.getValue());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config.save(optionsFile);
|
toYaml().save(optionsFile);
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
@Getter könnte hier stehen statt an jedem Field.