mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-20 15:29:19 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c406f40898 | ||
|
|
7561762c25 | ||
|
|
d245245083 | ||
|
|
2b55e129b3 | ||
|
|
0caec74436 |
@@ -34,7 +34,7 @@ shadowJar {
|
||||
relocate 'org.apache.commons.lang3', 'net.william278.husksync.libraries.commons.lang3'
|
||||
relocate 'com.google.gson', 'net.william278.husksync.libraries.gson'
|
||||
relocate 'org.json', 'net.william278.husksync.libraries.json'
|
||||
relocate 'com.fatboyindustrial', 'net.william278.husktowns.libraries'
|
||||
relocate 'com.fatboyindustrial', 'net.william278.husksync.libraries'
|
||||
relocate 'de.themoep', 'net.william278.husksync.libraries'
|
||||
relocate 'net.kyori', 'net.william278.husksync.libraries'
|
||||
relocate 'org.jetbrains', 'net.william278.husksync.libraries'
|
||||
|
||||
@@ -28,10 +28,7 @@ import net.william278.husksync.HuskSync;
|
||||
import net.william278.husksync.adapter.Adaptable;
|
||||
import net.william278.husksync.user.BukkitUser;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.advancement.AdvancementProgress;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
@@ -98,14 +95,9 @@ public abstract class BukkitData implements Data {
|
||||
|
||||
@Override
|
||||
public void setContents(@NotNull Data.Items contents) {
|
||||
System.arraycopy(
|
||||
((BukkitData.Items) contents).getContents(),
|
||||
0, this.contents,
|
||||
0, this.contents.length
|
||||
);
|
||||
this.setContents(((BukkitData.Items) contents).getContents());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setContents(@NotNull ItemStack[] contents) {
|
||||
System.arraycopy(contents, 0, this.contents, 0, this.contents.length);
|
||||
}
|
||||
@@ -529,7 +521,7 @@ public abstract class BukkitData implements Data {
|
||||
}
|
||||
|
||||
public static class Statistics extends BukkitData implements Data.Statistics {
|
||||
private Map<Statistic, Integer> untypedStatistics;
|
||||
private Map<Statistic, Integer> genericStatistics;
|
||||
private Map<Statistic, Map<Material, Integer>> blockStatistics;
|
||||
private Map<Statistic, Map<Material, Integer>> itemStatistics;
|
||||
private Map<Statistic, Map<EntityType, Integer>> entityStatistics;
|
||||
@@ -538,7 +530,7 @@ public abstract class BukkitData implements Data {
|
||||
@NotNull Map<Statistic, Map<Material, Integer>> blockStatistics,
|
||||
@NotNull Map<Statistic, Map<Material, Integer>> itemStatistics,
|
||||
@NotNull Map<Statistic, Map<EntityType, Integer>> entityStatistics) {
|
||||
this.untypedStatistics = genericStatistics;
|
||||
this.genericStatistics = genericStatistics;
|
||||
this.blockStatistics = blockStatistics;
|
||||
this.itemStatistics = itemStatistics;
|
||||
this.entityStatistics = entityStatistics;
|
||||
@@ -659,7 +651,7 @@ public abstract class BukkitData implements Data {
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull BukkitUser user, @NotNull BukkitHuskSync plugin) throws IllegalStateException {
|
||||
untypedStatistics.forEach((stat, value) -> applyStat(user, stat, null, value));
|
||||
genericStatistics.forEach((stat, value) -> applyStat(user, stat, null, value));
|
||||
blockStatistics.forEach((stat, m) -> m.forEach((block, value) -> applyStat(user, stat, block, value)));
|
||||
itemStatistics.forEach((stat, m) -> m.forEach((item, value) -> applyStat(user, stat, item, value)));
|
||||
entityStatistics.forEach((stat, m) -> m.forEach((entity, value) -> applyStat(user, stat, entity, value)));
|
||||
@@ -682,45 +674,41 @@ public abstract class BukkitData implements Data {
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Integer> getGenericStatistics() {
|
||||
return untypedStatistics.entrySet().stream().collect(
|
||||
TreeMap::new,
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), e.getValue()), TreeMap::putAll
|
||||
);
|
||||
return convertStatistics(genericStatistics);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getBlockStatistics() {
|
||||
return blockStatistics.entrySet().stream().collect(
|
||||
return blockStatistics.entrySet().stream().filter(entry -> entry.getKey() != null).collect(
|
||||
TreeMap::new,
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), e.getValue().entrySet().stream().collect(
|
||||
TreeMap::new,
|
||||
(m2, e2) -> m2.put(e2.getKey().getKey().toString(), e2.getValue()), TreeMap::putAll
|
||||
)), TreeMap::putAll
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), convertStatistics(e.getValue())), TreeMap::putAll
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getItemStatistics() {
|
||||
return itemStatistics.entrySet().stream().collect(
|
||||
return itemStatistics.entrySet().stream().filter(entry -> entry.getKey() != null).collect(
|
||||
TreeMap::new,
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), e.getValue().entrySet().stream().collect(
|
||||
TreeMap::new,
|
||||
(m2, e2) -> m2.put(e2.getKey().getKey().toString(), e2.getValue()), TreeMap::putAll
|
||||
)), TreeMap::putAll
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), convertStatistics(e.getValue())), TreeMap::putAll
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Map<String, Integer>> getEntityStatistics() {
|
||||
return entityStatistics.entrySet().stream().collect(
|
||||
return entityStatistics.entrySet().stream().filter(entry -> entry.getKey() != null).collect(
|
||||
TreeMap::new,
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), e.getValue().entrySet().stream().collect(
|
||||
TreeMap::new,
|
||||
(m2, e2) -> m2.put(e2.getKey().getKey().toString(), e2.getValue()), TreeMap::putAll
|
||||
)), TreeMap::putAll
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), convertStatistics(e.getValue())), TreeMap::putAll
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <T extends Keyed> Map<String, Integer> convertStatistics(@NotNull Map<T, Integer> stats) {
|
||||
return stats.entrySet().stream().filter(entry -> entry.getKey() != null).collect(
|
||||
TreeMap::new,
|
||||
(m, e) -> m.put(e.getKey().getKey().toString(), e.getValue()), TreeMap::putAll
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,12 +133,15 @@ public interface BukkitMapPersister {
|
||||
final MapMeta meta = Objects.requireNonNull((MapMeta) map.getItemMeta());
|
||||
NBT.get(map, nbt -> {
|
||||
if (!nbt.hasTag(MAP_DATA_KEY)) {
|
||||
return nbt;
|
||||
return;
|
||||
}
|
||||
final ReadableNBT mapData = nbt.getCompound(MAP_DATA_KEY);
|
||||
final ReadableNBT mapIds = nbt.getCompound(MAP_VIEW_ID_MAPPINGS_KEY);
|
||||
if (mapData == null || mapIds == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Search for an existing map view
|
||||
final ReadableNBT mapIds = nbt.getCompound(MAP_VIEW_ID_MAPPINGS_KEY);
|
||||
Optional<String> world = Optional.empty();
|
||||
for (String worldUid : mapIds.getKeys()) {
|
||||
world = Bukkit.getWorlds().stream()
|
||||
@@ -157,7 +160,7 @@ public interface BukkitMapPersister {
|
||||
meta.setMapView(view);
|
||||
map.setItemMeta(meta);
|
||||
getPlugin().debug(String.format("View exists (#%s); updated map (UID: %s)", view.getId(), uid));
|
||||
return nbt;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,10 +168,11 @@ public interface BukkitMapPersister {
|
||||
final MapData canvasData;
|
||||
try {
|
||||
getPlugin().debug("Deserializing map data from NBT and generating view...");
|
||||
canvasData = MapData.fromByteArray(mapData.getByteArray(MAP_PIXEL_DATA_KEY));
|
||||
canvasData = MapData.fromByteArray(Objects.requireNonNull(mapData.getByteArray(MAP_PIXEL_DATA_KEY),
|
||||
"Map pixel data is null"));
|
||||
} catch (Throwable e) {
|
||||
getPlugin().log(Level.WARNING, "Failed to deserialize map data from NBT", e);
|
||||
return nbt;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a renderer to the map with the data
|
||||
@@ -179,10 +183,11 @@ public interface BukkitMapPersister {
|
||||
|
||||
// Set the map view ID in NBT
|
||||
NBT.modify(map, editable -> {
|
||||
editable.getCompound(MAP_VIEW_ID_MAPPINGS_KEY).setInteger(worldUid, view.getId());
|
||||
Objects.requireNonNull(editable.getCompound(MAP_VIEW_ID_MAPPINGS_KEY),
|
||||
"Map view ID mappings compound is null")
|
||||
.setInteger(worldUid, view.getId());
|
||||
});
|
||||
getPlugin().debug(String.format("Generated view (#%s) and updated map (UID: %s)", view.getId(), worldUid));
|
||||
return nbt;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8'
|
||||
org.gradle.daemon=true
|
||||
javaVersion=16
|
||||
|
||||
plugin_version=3.0.1
|
||||
plugin_version=3.0.2
|
||||
plugin_archive=husksync
|
||||
plugin_description=A modern, cross-server player data synchronization system
|
||||
|
||||
|
||||
Reference in New Issue
Block a user