Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fbcf485b3 | ||
|
|
6a64be2e25 | ||
|
|
3f9f3991d8 | ||
|
|
54a8d942fa | ||
|
|
6aa14be577 | ||
|
|
d6db7673d8 | ||
|
|
d002073124 | ||
|
|
4bc98cae81 | ||
|
|
2696baf1d6 | ||
|
|
3c3cc36403 |
142
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
142
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
package com.willfp.eco.core.data;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.config.BaseConfig;
|
||||||
|
import com.willfp.eco.core.config.Config;
|
||||||
|
import com.willfp.eco.internal.config.ConfigSection;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class Data {
|
||||||
|
/**
|
||||||
|
* Instance of eco data.yml.
|
||||||
|
*/
|
||||||
|
private static BaseConfig dataYml = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All cached player data.
|
||||||
|
*/
|
||||||
|
private static final Map<UUID, Config> PLAYER_DATA = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an integer to a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
* @param data The data.
|
||||||
|
*/
|
||||||
|
public void writeInt(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key,
|
||||||
|
final int data) {
|
||||||
|
getPlayerConfig(player).set(key.toString(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a string to a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
* @param data The data.
|
||||||
|
*/
|
||||||
|
public void writeString(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key,
|
||||||
|
@NotNull final String data) {
|
||||||
|
getPlayerConfig(player).set(key.toString(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a double to a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
* @param data The data.
|
||||||
|
*/
|
||||||
|
public void writeDouble(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key,
|
||||||
|
final double data) {
|
||||||
|
getPlayerConfig(player).set(key.toString(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read an integer from a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
*/
|
||||||
|
public int readInt(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key) {
|
||||||
|
return getPlayerConfig(player).getInt(key.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a string from a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
*/
|
||||||
|
public String readString(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key) {
|
||||||
|
return getPlayerConfig(player).getString(key.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a double from a player's data.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param key The key.
|
||||||
|
*/
|
||||||
|
public double readDouble(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final NamespacedKey key) {
|
||||||
|
return getPlayerConfig(player).getDouble(key.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the player data with an instance of data.yml.
|
||||||
|
*
|
||||||
|
* @param config data.yml.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void init(@NotNull final BaseConfig config) {
|
||||||
|
dataYml = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save to data.yml.
|
||||||
|
*
|
||||||
|
* @param config Instance of data.yml.
|
||||||
|
* @throws IOException Error during saving.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void save(@NotNull final BaseConfig config) throws IOException {
|
||||||
|
for (Map.Entry<UUID, Config> entry : PLAYER_DATA.entrySet()) {
|
||||||
|
for (String key : entry.getValue().getKeys(false)) {
|
||||||
|
config.set("player-data." + entry.getKey().toString() + "." + key, entry.getValue().get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Config getPlayerConfig(@NotNull final OfflinePlayer player) {
|
||||||
|
Config config = PLAYER_DATA.get(player.getUniqueId());
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
config = dataYml.getSubsectionOrNull("player-data." + player.getUniqueId());
|
||||||
|
if (config == null) {
|
||||||
|
config = new ConfigSection(new YamlConfiguration());
|
||||||
|
}
|
||||||
|
PLAYER_DATA.put(player.getUniqueId(), config);
|
||||||
|
return getPlayerConfig(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
|
|||||||
*
|
*
|
||||||
* @param section The section.
|
* @param section The section.
|
||||||
*/
|
*/
|
||||||
protected ConfigSection(@NotNull final ConfigurationSection section) {
|
public ConfigSection(@NotNull final ConfigurationSection section) {
|
||||||
this.init(section);
|
this.init(section);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
@Override
|
@Override
|
||||||
public void set(@NotNull final String path,
|
public void set(@NotNull final String path,
|
||||||
@Nullable final Object object) {
|
@Nullable final Object object) {
|
||||||
|
cache.remove(path);
|
||||||
handle.set(path, object);
|
handle.set(path, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +82,12 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
if (cache.containsKey(path)) {
|
if (cache.containsKey(path)) {
|
||||||
return (Config) cache.get(path);
|
return (Config) cache.get(path);
|
||||||
} else {
|
} else {
|
||||||
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path))));
|
ConfigurationSection raw = handle.getConfigurationSection(path);
|
||||||
|
if (raw == null) {
|
||||||
|
cache.put(path, null);
|
||||||
|
} else {
|
||||||
|
cache.put(path, new ConfigSection(raw));
|
||||||
|
}
|
||||||
return getSubsectionOrNull(path);
|
return getSubsectionOrNull(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,15 +37,6 @@ public class BlockUtils {
|
|||||||
if (blocks.size() > limit || blocks.size() > 2500) {
|
if (blocks.size() > limit || blocks.size() > 2500) {
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// Running twice to get more spherical shape.
|
|
||||||
for (BlockFace face : BlockFace.values()) {
|
|
||||||
Block block = start.getRelative(face);
|
|
||||||
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
|
|
||||||
if (blocks.size() > limit || blocks.size() > 2500) {
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,20 +10,10 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class NumberUtils {
|
public class NumberUtils {
|
||||||
/**
|
|
||||||
* Precision.
|
|
||||||
*/
|
|
||||||
private static final int FAST_TRIG_PRECISION = 100;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modulus.
|
|
||||||
*/
|
|
||||||
private static final int FAST_TRIG_MODULUS = 360 * FAST_TRIG_PRECISION;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sin lookup table.
|
* Sin lookup table.
|
||||||
*/
|
*/
|
||||||
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS];
|
private static final double[] SIN_LOOKUP = new double[65536];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of roman numerals to look up.
|
* Set of roman numerals to look up.
|
||||||
@@ -45,15 +35,11 @@ public class NumberUtils {
|
|||||||
NUMERALS.put(4, "IV");
|
NUMERALS.put(4, "IV");
|
||||||
NUMERALS.put(1, "I");
|
NUMERALS.put(1, "I");
|
||||||
|
|
||||||
for (int i = 0; i < SIN_LOOKUP.length; i++) {
|
for (int i = 0; i < 65536; ++i) {
|
||||||
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
|
SIN_LOOKUP[i] = Math.sin((double) i * 3.141592653589793D * 2.0D / 65536.0D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double sinLookup(final int a) {
|
|
||||||
return a >= 0 ? SIN_LOOKUP[a % FAST_TRIG_MODULUS] : -SIN_LOOKUP[-a % FAST_TRIG_MODULUS];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the sin of a number.
|
* Get the sin of a number.
|
||||||
*
|
*
|
||||||
@@ -61,7 +47,8 @@ public class NumberUtils {
|
|||||||
* @return The sin.
|
* @return The sin.
|
||||||
*/
|
*/
|
||||||
public static double fastSin(final double a) {
|
public static double fastSin(final double a) {
|
||||||
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f));
|
float f = (float) a;
|
||||||
|
return SIN_LOOKUP[(int) (f * 10430.378F) & '\uffff'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +58,8 @@ public class NumberUtils {
|
|||||||
* @return The cosine.
|
* @return The cosine.
|
||||||
*/
|
*/
|
||||||
public static double fastCos(final double a) {
|
public static double fastCos(final double a) {
|
||||||
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f));
|
float f = (float) a;
|
||||||
|
return SIN_LOOKUP[(int) (f * 10430.378F + 16384.0F) & '\uffff'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.eco.spigot;
|
|||||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.core.command.AbstractCommand;
|
import com.willfp.eco.core.command.AbstractCommand;
|
||||||
|
import com.willfp.eco.core.data.Data;
|
||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import com.willfp.eco.core.display.DisplayModule;
|
import com.willfp.eco.core.display.DisplayModule;
|
||||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||||
@@ -12,6 +13,7 @@ import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
|||||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||||
|
import com.willfp.eco.spigot.config.DataYml;
|
||||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||||
import com.willfp.eco.spigot.display.PacketChat;
|
import com.willfp.eco.spigot.display.PacketChat;
|
||||||
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
||||||
@@ -42,6 +44,7 @@ import lombok.Getter;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -53,6 +56,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
@Getter
|
@Getter
|
||||||
private static EcoSpigotPlugin instance;
|
private static EcoSpigotPlugin instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data.yml.
|
||||||
|
*/
|
||||||
|
private final DataYml dataYml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of eco.
|
* Create a new instance of eco.
|
||||||
*/
|
*/
|
||||||
@@ -69,6 +77,9 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
|
|
||||||
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
|
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
|
||||||
TridentUtils.initialize(tridentStackProxy::getTridentStack);
|
TridentUtils.initialize(tridentStackProxy::getTridentStack);
|
||||||
|
|
||||||
|
this.dataYml = new DataYml(this);
|
||||||
|
Data.init(this.dataYml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +94,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
try {
|
||||||
|
Data.save(this.dataYml);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.willfp.eco.spigot.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.config.BaseConfig;
|
||||||
|
import com.willfp.eco.spigot.EcoSpigotPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class DataYml extends BaseConfig {
|
||||||
|
/**
|
||||||
|
* Init data.yml.
|
||||||
|
*
|
||||||
|
* @param plugin EcoSpigotPlugin.
|
||||||
|
*/
|
||||||
|
public DataYml(@NotNull final EcoSpigotPlugin plugin) {
|
||||||
|
super("data", false, plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
0
eco-core/core-plugin/src/main/resources/data.yml
Normal file
0
eco-core/core-plugin/src/main/resources/data.yml
Normal file
@@ -1,2 +1,2 @@
|
|||||||
version = 5.0.0
|
version = 5.1.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user