Update DepthCounter to save in PlayerConfig
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
399171f58e
Commit
7eb642793c
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bausystem;
|
package de.steamwar.bausystem;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.ColorConfig;
|
import de.steamwar.bausystem.config.ColorConfig;
|
||||||
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.bausystem.linkage.LinkageUtils;
|
import de.steamwar.bausystem.linkage.LinkageUtils;
|
||||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||||
@ -75,6 +76,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
LinkageUtils.unlink();
|
LinkageUtils.unlink();
|
||||||
|
|
||||||
RegionLoader.save();
|
RegionLoader.save();
|
||||||
|
Config.getInstance().saveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixLogging() {
|
private void fixLogging() {
|
||||||
|
@ -96,6 +96,14 @@ public class Config implements Listener {
|
|||||||
return playerConfigurations.get(uuid);
|
return playerConfigurations.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveAll() {
|
||||||
|
playerConfigurations.forEach((uuid, yapionObject) -> {
|
||||||
|
String string = yapionObject.toYAPION(new StringOutput()).getResult();
|
||||||
|
UserConfig.updatePlayerConfig(uuid, "bausystem", string);
|
||||||
|
});
|
||||||
|
playerConfigurations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a PlayerConfig, this does not remove the key value mapping from the map.
|
* Save a PlayerConfig, this does not remove the key value mapping from the map.
|
||||||
*
|
*
|
||||||
|
@ -21,10 +21,12 @@ package de.steamwar.bausystem.features.testblock.depthcounter;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.config.ColorConfig;
|
import de.steamwar.bausystem.config.ColorConfig;
|
||||||
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.bausystem.region.Region;
|
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;
|
||||||
@ -33,7 +35,8 @@ import java.util.stream.Collectors;
|
|||||||
public class DepthCounter {
|
public class DepthCounter {
|
||||||
|
|
||||||
public final Map<Region, Set<Depth>> depthMap = new HashMap<>();
|
public final Map<Region, Set<Depth>> depthMap = new HashMap<>();
|
||||||
public final Map<Player, Set<CountMode>> playerSettings = 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)) {
|
||||||
@ -44,35 +47,29 @@ public class DepthCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive(final Player p, final CountMode countMode) {
|
public boolean isActive(final Player p, final CountMode countMode) {
|
||||||
final Set<CountMode> countModes = playerSettings.get(p);
|
return Config.getInstance().get(p).getYAPIONObjectOrSetDefault("depth-counter", (YAPIONObject) DEFAULT.copy()).containsKey(countMode.name());
|
||||||
return countModes != null && countModes.contains(countMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMode(final Player p, final CountMode countMode) {
|
public void addMode(final Player p, final CountMode countMode) {
|
||||||
final Set<CountMode> countModes = playerSettings.get(p);
|
if (!isActive(p, countMode)) {
|
||||||
if (countModes != null) {
|
Config.getInstance().get(p).getObject("depth-counter").add(countMode.name(), "");
|
||||||
countModes.add(countMode);
|
|
||||||
} else {
|
|
||||||
playerSettings.put(p, new HashSet<>(Collections.singletonList(countMode)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMode(final Player p, final CountMode countMode) {
|
public void removeMode(final Player p, final CountMode countMode) {
|
||||||
final Set<CountMode> countModes = playerSettings.get(p);
|
if (isActive(p, countMode)) {
|
||||||
if (countModes != null) {
|
Config.getInstance().get(p).getObject("depth-counter").remove(countMode.name());
|
||||||
countModes.remove(countMode);
|
|
||||||
if (countModes.isEmpty()) {
|
|
||||||
removePlayer(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModes(final Player p, final Set<CountMode> countModes) {
|
public void setModes(final Player p, final Set<CountMode> countModes) {
|
||||||
playerSettings.put(p, countModes);
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
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) {
|
||||||
playerSettings.remove(p);
|
Config.getInstance().get(p).put("depth-counter", new YAPIONObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector blockVector(Vector vector) {
|
public Vector blockVector(Vector vector) {
|
||||||
@ -80,8 +77,11 @@ public class DepthCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<CountMode> getModes(Player p) {
|
public Set<CountMode> getModes(Player p) {
|
||||||
final Set<CountMode> countModes = playerSettings.get(p);
|
Set<CountMode> countModes = new HashSet<>();
|
||||||
return countModes == null ? Collections.emptySet() : countModes.stream().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) {
|
||||||
|
@ -27,13 +27,10 @@ import de.steamwar.bausystem.region.utils.RegionType;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class DepthCounterListener implements Listener {
|
public class DepthCounterListener implements Listener {
|
||||||
|
|
||||||
@ -54,14 +51,4 @@ public class DepthCounterListener implements Listener {
|
|||||||
}
|
}
|
||||||
depthSet.add(new Depth(region, event.blockList()));
|
depthSet.add(new Depth(region, event.blockList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLeave(PlayerQuitEvent event) {
|
|
||||||
DepthCounter.removePlayer(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
|
||||||
DepthCounter.setModes(event.getPlayer(), CountMode.ALL());
|
|
||||||
}
|
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren