Initial commit
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
package com.alttd.objects;
|
||||
|
||||
import com.alttd.VillagerUI;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.database.Queries;
|
||||
import com.alttd.util.Logger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import org.apache.commons.math3.analysis.function.Log;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EconUser {
|
||||
|
||||
private final static Object2ObjectArrayMap<UUID, EconUser> users = new Object2ObjectArrayMap<>();
|
||||
|
||||
private final UUID uuid;
|
||||
private final Object2ObjectArrayMap<String, Integer> pointsMap;
|
||||
|
||||
public EconUser(UUID uuid, Object2ObjectArrayMap<String, Integer> points) {
|
||||
this.uuid = uuid;
|
||||
this.pointsMap = points;
|
||||
users.put(this.uuid, this);
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Created EconUser for: %", uuid.toString());
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Object2ObjectArrayMap<String, Integer> getPointsMap() {
|
||||
return pointsMap;
|
||||
}
|
||||
|
||||
public void addPoints(String villagerType, int points) {
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Adding % points to % for %", String.valueOf(points), villagerType, uuid.toString());
|
||||
if (pointsMap.containsKey(villagerType))
|
||||
pointsMap.put(villagerType,pointsMap.get(villagerType) + points);
|
||||
else
|
||||
pointsMap.put(villagerType, points);
|
||||
}
|
||||
|
||||
public void syncPoints() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Queries.updateUserPoints(uuid, pointsMap);
|
||||
}
|
||||
}.runTaskAsynchronously(VillagerUI.getInstance());
|
||||
}
|
||||
|
||||
private void removePoints(String villagerType, int points, int remove)
|
||||
{
|
||||
if (points == 0)
|
||||
return;
|
||||
if (points > 0)
|
||||
if (points < remove)
|
||||
points = 0;
|
||||
else
|
||||
points -= remove;
|
||||
else
|
||||
if (-points < remove)
|
||||
points = 0;
|
||||
else
|
||||
points += remove;
|
||||
pointsMap.put(villagerType, points);
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Removed % points from villagerType: % for %",
|
||||
String.valueOf(points), villagerType, uuid.toString());
|
||||
}
|
||||
|
||||
public void removePoints(int remove) {
|
||||
pointsMap.forEach((villagerType, points) -> removePoints(villagerType, points, remove));
|
||||
}
|
||||
|
||||
public void removePoints() {
|
||||
pointsMap.forEach((villagerType, points) -> {
|
||||
if (points == 0)
|
||||
return;
|
||||
int remove = points;
|
||||
if (remove < 0)
|
||||
remove *= -1;
|
||||
removePoints(villagerType, points, (int) (0.9 * remove) - 10);
|
||||
});
|
||||
}
|
||||
|
||||
public static EconUser getUser(UUID uuid) {
|
||||
EconUser user = users.get(uuid);
|
||||
if (user == null) {
|
||||
user = Queries.getEconUser(uuid);
|
||||
EconUser.users.put(uuid, user);
|
||||
}
|
||||
return (user);
|
||||
}
|
||||
|
||||
public static void removeUser(UUID uuid) {
|
||||
users.remove(uuid);
|
||||
}
|
||||
|
||||
@Unmodifiable
|
||||
public static List<EconUser> getEconUsers() {
|
||||
return Collections.unmodifiableList(users.values().stream().toList());
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.alttd.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LoadedVillagers {
|
||||
private final static Map<UUID, VillagerType> loadedVillagers = new HashMap<>();
|
||||
|
||||
public static VillagerType getLoadedVillager(UUID uuid) {
|
||||
return loadedVillagers.get(uuid);
|
||||
}
|
||||
|
||||
public static void addLoadedVillager(UUID uuid, VillagerType villagerType) {
|
||||
loadedVillagers.put(uuid, villagerType);
|
||||
}
|
||||
|
||||
public static void removeLoadedVillager(UUID uuid) {
|
||||
loadedVillagers.remove(uuid);
|
||||
}
|
||||
|
||||
public static void clearLoadedVillagers() {
|
||||
loadedVillagers.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.alttd.objects;
|
||||
|
||||
import com.alttd.util.Utilities;
|
||||
import org.apache.commons.math3.analysis.function.StepFunction;
|
||||
import org.apache.commons.math3.analysis.integration.TrapezoidIntegrator;
|
||||
|
||||
public final class Price {
|
||||
private final double price;
|
||||
private final int points;
|
||||
|
||||
private static final double[] xMult = {Integer.MIN_VALUE, -4000, -2000, -500, 500, 2000, 4000};
|
||||
private static final double[] yMultSell = {2.5, 1.75, 1.25, 1, 1.5, 2.5, 5};
|
||||
private static final double[] yMultBuy = {5, 2.5, 1.5, 1, 1.25, 1.75, 2.5};
|
||||
|
||||
private static final StepFunction multiplierModelBuy = new StepFunction(xMult, yMultBuy);
|
||||
private static final StepFunction multiplierModelSell = new StepFunction(xMult, yMultSell);
|
||||
|
||||
public Price(double price) {
|
||||
this.price = price;
|
||||
this.points = (int) price;
|
||||
}
|
||||
|
||||
public static Price addPrice(Price one, Price two) {
|
||||
return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2)));
|
||||
}
|
||||
|
||||
public double getPrice(int multiplier) {
|
||||
return (Utilities.round(price * multiplier, 2));
|
||||
}
|
||||
|
||||
public double calculatePriceThing(int oldPoints, int transPts, boolean buying) {
|
||||
// Compute numerical integration to determine price
|
||||
TrapezoidIntegrator trapez = new TrapezoidIntegrator();
|
||||
if (buying) {
|
||||
return (Utilities.round(price * trapez.integrate(10, multiplierModelBuy, oldPoints, oldPoints + transPts), 2));
|
||||
} else {
|
||||
return (Utilities.round(price * trapez.integrate(10, multiplierModelSell, oldPoints - transPts, oldPoints), 2));
|
||||
}
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return (points);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.alttd.objects;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class VillagerType {
|
||||
private static final Set<VillagerType> villagerTypes = new HashSet<>();
|
||||
|
||||
public static Set<VillagerType> getVillagerTypes() {
|
||||
return villagerTypes;
|
||||
}
|
||||
|
||||
public static VillagerType getVillagerType(String name) {
|
||||
return villagerTypes.stream().filter(villagerType -> villagerType.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static void addVillagerType(VillagerType villagerType) {
|
||||
villagerTypes.add(villagerType);
|
||||
}
|
||||
|
||||
public static void clearVillagerTypes() {
|
||||
villagerTypes.clear();
|
||||
}
|
||||
private final String name;
|
||||
private final String displayName;
|
||||
private final Set<ItemStack> buying;
|
||||
private final Set<ItemStack> selling;
|
||||
private final double priceModifier;
|
||||
private final Villager.Profession profession;
|
||||
|
||||
public VillagerType(String name, String displayName, Set<ItemStack> buying, Set<ItemStack> selling, double priceModifier, String profession) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.buying = buying;
|
||||
this.selling = selling;
|
||||
this.priceModifier = priceModifier;
|
||||
this.profession = Villager.Profession.valueOf(profession.toUpperCase());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public Set<ItemStack> getBuying() {
|
||||
return buying;
|
||||
}
|
||||
|
||||
public Set<ItemStack> getSelling() {
|
||||
return selling;
|
||||
}
|
||||
|
||||
public double getPriceModifier() {
|
||||
return priceModifier;
|
||||
}
|
||||
|
||||
public Villager.Profession getProfession() {
|
||||
return profession;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return "villagerui.villager." + getName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user