Compare commits

...

10 Commits
5.0.0 ... 5.1.0

Author SHA1 Message Date
Auxilor
8fbcf485b3 Renamed PlayerData to Data 2021-04-08 15:03:17 +01:00
Auxilor
6a64be2e25 Removed debug code 2021-04-08 15:01:57 +01:00
Auxilor
3f9f3991d8 Fixed cache on set in configs 2021-04-08 15:00:31 +01:00
Auxilor
54a8d942fa Fixed getSubsectionOrNull 2021-04-08 14:36:07 +01:00
Auxilor
6aa14be577 Updated to 5.1.0 2021-04-08 14:28:53 +01:00
Auxilor
d6db7673d8 Added data.yml 2021-04-08 14:28:19 +01:00
Auxilor
d002073124 Updated to 5.0.2 2021-04-06 18:03:03 +01:00
Auxilor
4bc98cae81 Fixed getVein 2021-04-06 18:02:50 +01:00
Auxilor
2696baf1d6 Updated to 5.0.1 2021-04-05 17:46:30 +01:00
Auxilor
3c3cc36403 Fixed fast sin and cos 2021-04-05 17:46:18 +01:00
9 changed files with 190 additions and 32 deletions

View 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;
}
}

View File

@@ -9,7 +9,7 @@ public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
*
* @param section The section.
*/
protected ConfigSection(@NotNull final ConfigurationSection section) {
public ConfigSection(@NotNull final ConfigurationSection section) {
this.init(section);
}
}

View File

@@ -64,6 +64,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
@Override
public void set(@NotNull final String path,
@Nullable final Object object) {
cache.remove(path);
handle.set(path, object);
}
@@ -81,7 +82,12 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
if (cache.containsKey(path)) {
return (Config) cache.get(path);
} 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);
}
}

View File

@@ -37,15 +37,6 @@ public class BlockUtils {
if (blocks.size() > limit || blocks.size() > 2500) {
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));
}
}

View File

@@ -10,20 +10,10 @@ import java.util.concurrent.ThreadLocalRandom;
@UtilityClass
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.
*/
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.
@@ -45,15 +35,11 @@ public class NumberUtils {
NUMERALS.put(4, "IV");
NUMERALS.put(1, "I");
for (int i = 0; i < SIN_LOOKUP.length; i++) {
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
for (int i = 0; i < 65536; ++i) {
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.
*
@@ -61,7 +47,8 @@ public class NumberUtils {
* @return The sin.
*/
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.
*/
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'];
}
/**

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.spigot;
import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin;
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.DisplayModule;
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.SkullProxy;
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.PacketChat;
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
@@ -42,6 +44,7 @@ import lombok.Getter;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -53,6 +56,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Getter
private static EcoSpigotPlugin instance;
/**
* data.yml.
*/
private final DataYml dataYml;
/**
* Create a new instance of eco.
*/
@@ -69,6 +77,9 @@ public class EcoSpigotPlugin extends EcoPlugin {
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
TridentUtils.initialize(tridentStackProxy::getTridentStack);
this.dataYml = new DataYml(this);
Data.init(this.dataYml);
}
@Override
@@ -83,7 +94,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
@Override
public void disable() {
try {
Data.save(this.dataYml);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override

View File

@@ -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);
}
}

View File

@@ -1,2 +1,2 @@
version = 5.0.0
version = 5.1.0
plugin-name = eco