Fixed stuff and did stuff and i forgot sorry to anyone reading this
This commit is contained in:
parent
861d3ea2a3
commit
d45c2f9ace
|
|
@ -25,12 +25,12 @@ public class GUIListener implements Listener {
|
|||
|
||||
GUI gui = GUI.GUIByUUID.get(player.getUniqueId());
|
||||
if (gui == null || gui.getInventory() == null) {
|
||||
if (event.getSlotType().equals(InventoryType.SlotType.CRAFTING) && event.getRawSlot() < 2)
|
||||
event.setCancelled(true);
|
||||
else if (event.getRawSlot() == 2 && event.getSlotType().equals(InventoryType.SlotType.RESULT)) {
|
||||
event.setCancelled(true);
|
||||
onResultSlotClick(event, gui);
|
||||
}
|
||||
// if (event.getSlotType().equals(InventoryType.SlotType.CRAFTING) && event.getRawSlot() < 2)
|
||||
// event.setCancelled(true);
|
||||
// else if (event.getRawSlot() == 2 && event.getSlotType().equals(InventoryType.SlotType.RESULT)) {
|
||||
// event.setCancelled(true);
|
||||
// onResultSlotClick(event, gui);
|
||||
// }
|
||||
return;
|
||||
}
|
||||
if (!gui.getInventory().equals(event.getInventory())) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class BuyGUI extends GUIMerchant {
|
|||
0)))
|
||||
)), villagerType);
|
||||
for (ItemStack itemStack : villagerType.getBuying()) {
|
||||
Price price = Utilities.getPrice(itemStack);
|
||||
Price price = Utilities.getPrice(itemStack, WorthConfig.buy);
|
||||
if (price == null)
|
||||
continue;
|
||||
addItem(itemStack,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class OpenGUI extends GUIInventory {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class SellGUI extends GUIMerchant {
|
|||
.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName())
|
||||
, 0))))), villagerType);
|
||||
for (ItemStack itemStack : villagerType.getSelling()) {
|
||||
Price price = Utilities.getPrice(itemStack);
|
||||
Price price = Utilities.getPrice(itemStack, WorthConfig.sell);
|
||||
if (price == null)
|
||||
continue;
|
||||
addItem(itemStack,
|
||||
|
|
|
|||
|
|
@ -46,12 +46,10 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER, List.of(
|
||||
Template.template("commands", subCommands.stream()
|
||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<config>", subCommands.stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getHelpMessage)
|
||||
.collect(Collectors.joining("\n")))
|
||||
));
|
||||
.collect(Collectors.joining("\n"))), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@ public class CommandHelp extends SubCommand {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER,
|
||||
List.of(Template.template("commands", commandManager
|
||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
|
||||
.getSubCommands().stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getHelpMessage)
|
||||
.collect(Collectors.joining("\n")))));
|
||||
.collect(Collectors.joining("\n"))), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ public final class Config extends AbstractConfig {
|
|||
villagerType.getString("name"),
|
||||
loadProducts(villagerType.getConfigurationSection("buying")),
|
||||
loadProducts(villagerType.getConfigurationSection("selling")),
|
||||
villagerType.getDouble("price-modifier"),
|
||||
villagerType.getString("profession"))
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,12 +28,18 @@ public class WorthConfig extends AbstractConfig {
|
|||
config.readConfig(WorthConfig.class, null);
|
||||
}
|
||||
|
||||
public static Object2ObjectOpenHashMap<Material, Price> prices = new Object2ObjectOpenHashMap<>();
|
||||
public static Object2ObjectOpenHashMap<Material, Price> buy = new Object2ObjectOpenHashMap<>();
|
||||
public static Object2ObjectOpenHashMap<Material, Price> sell = new Object2ObjectOpenHashMap<>();
|
||||
private static void loadWorth() { //TODO test after removing points
|
||||
prices.clear();
|
||||
ConfigurationSection worth = config.getConfigurationSection("worth");
|
||||
loadWorth("buy", buy);
|
||||
loadWorth("sell", sell);
|
||||
}
|
||||
|
||||
private static void loadWorth(String path, Object2ObjectOpenHashMap<Material, Price> map) {
|
||||
map.clear();
|
||||
ConfigurationSection worth = config.getConfigurationSection(path);
|
||||
if (worth == null) {
|
||||
Logger.severe("No worth in worth.yml! Stopping VillagerUI.");
|
||||
Logger.severe("No ? in worth.yml! Stopping VillagerUI.", path);
|
||||
VillagerUI.getInstance().getServer().getPluginManager().disablePlugin(VillagerUI.getInstance());
|
||||
return;
|
||||
}
|
||||
|
|
@ -43,7 +49,7 @@ public class WorthConfig extends AbstractConfig {
|
|||
Logger.severe("Null key in worth.yml?");
|
||||
continue;
|
||||
}
|
||||
prices.put(Material.getMaterial(key), new Price(Utilities.round(worth.getDouble(key), 2)));
|
||||
map.put(Material.getMaterial(key), new Price(Utilities.round(worth.getDouble(key), 2)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alttd.config.Config;
|
|||
import com.alttd.database.Queries;
|
||||
import com.alttd.objects.EconUser;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
|
@ -15,17 +16,18 @@ import java.util.UUID;
|
|||
public class LoginEvent implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
UUID uuid = player.getUniqueId();
|
||||
EconUser user = EconUser.getUser(uuid);
|
||||
int minutes = Queries.getMinutesSinceUpdated(uuid);
|
||||
|
||||
user.removePoints(minutes * 2);
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Loaded EconUser for % and removed % points",
|
||||
event.getPlayer().getName(), String.valueOf(minutes * 2));
|
||||
player.getName(), String.valueOf(minutes * 2));
|
||||
}
|
||||
}.runTask(VillagerUI.getInstance());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,20 +57,27 @@ public class EconUser {
|
|||
{
|
||||
if (points == 0)
|
||||
return;
|
||||
if (points > 0)
|
||||
if (points > 0) {
|
||||
if (points < remove)
|
||||
points = 0;
|
||||
else
|
||||
points -= remove;
|
||||
else
|
||||
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());
|
||||
String.valueOf(remove), villagerType, uuid.toString());
|
||||
}
|
||||
|
||||
private void setPoints(String villagerType, int points) {
|
||||
if (pointsMap.get(villagerType) < 0)
|
||||
points *= -1;
|
||||
pointsMap.put(villagerType, points);
|
||||
}
|
||||
|
||||
public void removePoints(int remove) {
|
||||
|
|
@ -84,7 +91,8 @@ public class EconUser {
|
|||
int remove = points;
|
||||
if (remove < 0)
|
||||
remove *= -1;
|
||||
removePoints(villagerType, points, (int) (0.9 * remove) - 10);
|
||||
int i = (int) (0.9 * remove) - 10;
|
||||
setPoints(villagerType, i < 10 && i > -10 ? 0 : i);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ public final class Price {
|
|||
private final int points;
|
||||
|
||||
private static final double[] xMult = {Integer.MIN_VALUE, -4000, -2000, -500, 500, 2000, 4000, Integer.MAX_VALUE};
|
||||
private static final double[] yMultBuy = {2.5, 1.75, 1.25, 1, 1.5, 2.5, 5};
|
||||
private static final double[] yMultSell = {5, 2.5, 1.5, 1, 1.25, 1.75, 2.5};
|
||||
private static final double[] yMultBuy = {0.4, 0.65, 0.85, 1, 1.5, 2.5, 5};
|
||||
private static final double[] yMultSell = {5, 2.5, 1.5, 1, 0.85, 0.65, 0.4};
|
||||
|
||||
public Price(double price) {
|
||||
this.price = price;
|
||||
|
|
|
|||
|
|
@ -28,15 +28,13 @@ public class VillagerType {
|
|||
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) {
|
||||
public VillagerType(String name, String displayName, Set<ItemStack> buying, Set<ItemStack> selling, String profession) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.buying = buying;
|
||||
this.selling = selling;
|
||||
this.priceModifier = priceModifier;
|
||||
this.profession = Villager.Profession.valueOf(profession.toUpperCase());
|
||||
}
|
||||
|
||||
|
|
@ -56,10 +54,6 @@ public class VillagerType {
|
|||
return selling;
|
||||
}
|
||||
|
||||
public double getPriceModifier() {
|
||||
return priceModifier;
|
||||
}
|
||||
|
||||
public Villager.Profession getProfession() {
|
||||
return profession;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.util;
|
|||
|
||||
import com.alttd.config.WorthConfig;
|
||||
import com.alttd.objects.Price;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.*;
|
||||
|
|
@ -36,14 +37,14 @@ public class Utilities {
|
|||
* @param item to calculate price for
|
||||
* @return price or int < 0 for error
|
||||
*/
|
||||
public static Price getPrice(ItemStack item) {
|
||||
if (WorthConfig.prices.containsKey(item.getType()))
|
||||
return (WorthConfig.prices.get(item.getType()));
|
||||
Price price = getWorth(item, null);
|
||||
public static Price getPrice(ItemStack item, Object2ObjectOpenHashMap<Material, Price> map) {
|
||||
if (map.containsKey(item.getType()))
|
||||
return (map.get(item.getType()));
|
||||
Price price = getWorth(item, null, map);
|
||||
if (price == null)
|
||||
return (null);
|
||||
WorthConfig.prices.put(item.getType(), price);
|
||||
return (WorthConfig.prices.get(item.getType()));
|
||||
map.put(item.getType(), price);
|
||||
return (map.get(item.getType()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,13 +54,13 @@ public class Utilities {
|
|||
* @param blockedMaterial Material to ignore set to null on initial call
|
||||
* @return Worth of the item as a double
|
||||
*/
|
||||
private static Price getWorth(ItemStack item, Material blockedMaterial) {
|
||||
private static Price getWorth(ItemStack item, Material blockedMaterial, Object2ObjectOpenHashMap<Material, Price> map) {
|
||||
Price price = null;
|
||||
|
||||
if (item == null)
|
||||
return (null);
|
||||
if (WorthConfig.prices.containsKey(item.getType()))
|
||||
return (WorthConfig.prices.get(item.getType()));
|
||||
if (map.containsKey(item.getType()))
|
||||
return (map.get(item.getType()));
|
||||
|
||||
List<Recipe> recipes = Bukkit.getRecipesFor(item);
|
||||
for (Recipe recipe : recipes) {
|
||||
|
|
@ -70,7 +71,7 @@ public class Utilities {
|
|||
if (!values.isEmpty() && blockedMaterial != null && values.stream()
|
||||
.anyMatch(itemStack -> itemStack != null && itemStack.getType().equals(blockedMaterial)))
|
||||
continue;
|
||||
possiblePrice = getWorth(values, item.getType());
|
||||
possiblePrice = getWorth(values, item.getType(), map);
|
||||
if (possiblePrice == null)
|
||||
continue;
|
||||
if (price == null || price.getPrice(1) > possiblePrice.getPrice(1))
|
||||
|
|
@ -79,19 +80,19 @@ public class Utilities {
|
|||
if (shapelessRecipe.getIngredientList().stream()
|
||||
.anyMatch(itemStack -> itemStack.getType().equals(blockedMaterial)))
|
||||
continue;
|
||||
possiblePrice = getWorth(shapelessRecipe.getIngredientList(), item.getType());
|
||||
possiblePrice = getWorth(shapelessRecipe.getIngredientList(), item.getType(), map);
|
||||
if (possiblePrice == null)
|
||||
continue;
|
||||
if (price == null || price.getPrice(1) > possiblePrice.getPrice(1))
|
||||
price = possiblePrice;
|
||||
} else if (recipe instanceof CampfireRecipe campfireRecipe) {
|
||||
possiblePrice = getWorth(campfireRecipe.getInput(), item.getType());
|
||||
possiblePrice = getWorth(campfireRecipe.getInput(), item.getType(), map);
|
||||
if (possiblePrice == null)
|
||||
continue;
|
||||
if (price == null || price.getPrice(1) > possiblePrice.getPrice(1))
|
||||
price = possiblePrice;
|
||||
} else if (recipe instanceof StonecuttingRecipe stonecuttingRecipe) {
|
||||
possiblePrice = getWorth(stonecuttingRecipe.getInput(), item.getType());
|
||||
possiblePrice = getWorth(stonecuttingRecipe.getInput(), item.getType(), map);
|
||||
if (possiblePrice == null)
|
||||
continue;
|
||||
if (price == null || price.getPrice(1) > possiblePrice.getPrice(1))
|
||||
|
|
@ -101,7 +102,7 @@ public class Utilities {
|
|||
!cookingRecipe.getInput().getType().isBlock() &&
|
||||
!cookingRecipe.getInput().getType().equals(Material.CLAY_BALL)) //Needs exception for clay ball idk a better way to do it...
|
||||
continue;
|
||||
possiblePrice = getWorth(cookingRecipe.getInput(), item.getType());
|
||||
possiblePrice = getWorth(cookingRecipe.getInput(), item.getType(), map);
|
||||
if (possiblePrice == null)
|
||||
continue;
|
||||
if (price == null || price.getPrice(1) > possiblePrice.getPrice(1))
|
||||
|
|
@ -118,15 +119,15 @@ public class Utilities {
|
|||
* @param blockedMaterial Material to ignore set to null on initial call
|
||||
* @return Worth of ItemStack as a double
|
||||
*/
|
||||
private static Price getWorth(List<ItemStack> items, Material blockedMaterial) {
|
||||
private static Price getWorth(List<ItemStack> items, Material blockedMaterial, Object2ObjectOpenHashMap<Material, Price> map) {
|
||||
Price price = null;
|
||||
for (ItemStack item : items) {
|
||||
if (item == null)
|
||||
continue;
|
||||
Price tmp = getWorth(new ItemStack(item.getType()), blockedMaterial);
|
||||
Price tmp = getWorth(new ItemStack(item.getType()), blockedMaterial, map);
|
||||
if (tmp == null || tmp.getPrice(1) == -1)
|
||||
return null;
|
||||
WorthConfig.prices.put(item.getType(), tmp);
|
||||
map.put(item.getType(), tmp);
|
||||
if (price == null)
|
||||
price = tmp;
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user