mirror of
https://github.com/Artillex-Studios/AxTrade.git
synced 2024-11-10 10:11:06 +01:00
1.8.0
This commit is contained in:
parent
fc88f0e88d
commit
3d945b12c7
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Artillex-Studios
|
||||
Copyright (c) 2024 Artillex-Studios
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.artillexstudios</groupId>
|
||||
<artifactId>AxTrade</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>AxTrade</name>
|
||||
@ -112,7 +112,7 @@
|
||||
<dependency>
|
||||
<groupId>com.artillexstudios.axapi</groupId>
|
||||
<artifactId>axapi</artifactId>
|
||||
<version>1.4.329</version>
|
||||
<version>1.4.332</version>
|
||||
<scope>compile</scope>
|
||||
<classifier>all</classifier>
|
||||
</dependency>
|
||||
|
@ -136,6 +136,12 @@ public class Commands implements OrphanCommand {
|
||||
Trades.addTrade(sender, other);
|
||||
}
|
||||
|
||||
// @Subcommand("test")
|
||||
// @CommandPermission(value = "axtrade.admin")
|
||||
// public void test(@NotNull Player sender) {
|
||||
// Trades.addTrade(sender, sender);
|
||||
// }
|
||||
|
||||
private static BukkitCommandHandler handler = null;
|
||||
public static void registerCommand() {
|
||||
if (handler == null) {
|
||||
|
@ -6,11 +6,13 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlaceholderCurrencyHook implements CurrencyHook {
|
||||
private final String name;
|
||||
private final Section section;
|
||||
private DecimalFormat df;
|
||||
|
||||
public PlaceholderCurrencyHook(String name, Section section) {
|
||||
this.name = name;
|
||||
@ -19,6 +21,7 @@ public class PlaceholderCurrencyHook implements CurrencyHook {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
df = new DecimalFormat("#");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,6 +77,6 @@ public class PlaceholderCurrencyHook implements CurrencyHook {
|
||||
}
|
||||
|
||||
private String parseNumber(double amount) {
|
||||
return usesDouble() ? "" + amount : "" + Math.round(amount);
|
||||
return df.format(usesDouble() ? amount : Math.round(amount));
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import com.artillexstudios.axtrade.trade.Trades;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -58,12 +59,21 @@ public class TradeListeners implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickup(@NotNull EntityPickupItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
final Trade trade = Trades.getTrade(player);
|
||||
if (trade == null) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(@NotNull PlayerMoveEvent event) {
|
||||
if (event.getTo() == null) return;
|
||||
final Player player = event.getPlayer();
|
||||
final Trade trade = Trades.getTrade(player);
|
||||
if (trade == null) return;
|
||||
if (System.currentTimeMillis() - trade.getPrepTime() < 1_000L) return;
|
||||
if (event.getFrom().distanceSquared(event.getTo()) == 0) return;
|
||||
trade.abort();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.artillexstudios.axtrade.trade;
|
||||
|
||||
import com.artillexstudios.axapi.config.Config;
|
||||
import com.artillexstudios.axapi.nms.NMSHandlers;
|
||||
import com.artillexstudios.axapi.utils.NumberUtils;
|
||||
import com.artillexstudios.axapi.utils.Pair;
|
||||
import com.artillexstudios.axtrade.utils.ItemBuilderUtil;
|
||||
import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.BaseGui;
|
||||
@ -14,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -23,10 +26,12 @@ public class GuiFrame {
|
||||
protected BaseGui gui;
|
||||
protected Player player;
|
||||
protected boolean opened = false;
|
||||
protected final Trade trade;
|
||||
|
||||
public GuiFrame(Config file, Player player) {
|
||||
public GuiFrame(Config file, Player player, Trade trade) {
|
||||
this.file = file;
|
||||
this.player = player;
|
||||
this.trade = trade;
|
||||
}
|
||||
|
||||
public void setGui(BaseGui gui) {
|
||||
@ -46,7 +51,18 @@ public class GuiFrame {
|
||||
|
||||
protected ItemStack buildItem(@NotNull String key, Map<String, String> replacements) {
|
||||
if (file.getSection(key) == null) return air;
|
||||
return ItemBuilderUtil.newBuilder(file.getSection(key), replacements, player).get();
|
||||
|
||||
final Pair<String, String> selfTextures = NMSHandlers.getNmsHandler().textures(player.getPlayer());
|
||||
final Pair<String, String> otherTextures = NMSHandlers.getNmsHandler().textures(trade.getOtherPlayer(player.getPlayer()));
|
||||
|
||||
final HashMap<String, String> map = new HashMap<>(Map.of(
|
||||
"%own-head%", selfTextures == null ? "" : selfTextures.getFirst(),
|
||||
"%partner-head%", otherTextures == null ? "" : otherTextures.getFirst()
|
||||
));
|
||||
|
||||
map.putAll(replacements);
|
||||
|
||||
return ItemBuilderUtil.newBuilder(file.getSection(key), map, player).get();
|
||||
}
|
||||
|
||||
protected void createItem(@NotNull String route) {
|
||||
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.artillexstudios.axtrade.AxTrade.CONFIG;
|
||||
import static com.artillexstudios.axtrade.AxTrade.LANG;
|
||||
import static com.artillexstudios.axtrade.AxTrade.MESSAGEUTILS;
|
||||
|
||||
@ -91,8 +92,10 @@ public class Trade {
|
||||
String currencyName = Utils.getFormattedCurrency(entry.getKey());
|
||||
String currencyAm = NumberUtils.formatNumber(entry.getValue());
|
||||
player1Currencies.add(currencyName + ": " + currencyAm);
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.give.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.get.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
if (CONFIG.getBoolean("enable-trade-summaries")) {
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.get.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.give.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
}
|
||||
}
|
||||
|
||||
List<String> player2Currencies = new ArrayList<>();
|
||||
@ -102,8 +105,10 @@ public class Trade {
|
||||
String currencyName = Utils.getFormattedCurrency(entry.getKey());
|
||||
String currencyAm = NumberUtils.formatNumber(entry.getValue());
|
||||
player2Currencies.add(currencyName + ": " + currencyAm);
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.give.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.get.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
if (CONFIG.getBoolean("enable-trade-summaries")) {
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.give.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.get.currency"), Map.of("%amount%", currencyAm, "%currency%", currencyName));
|
||||
}
|
||||
}
|
||||
|
||||
List<String> player1Items = new ArrayList<>();
|
||||
@ -115,8 +120,10 @@ public class Trade {
|
||||
final String itemName = Utils.getFormattedItemName(itemStack);
|
||||
int itemAm = itemStack.getAmount();
|
||||
player1Items.add(itemAm + "x " + itemName);
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.give.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.get.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
if (CONFIG.getBoolean("enable-trade-summaries")) {
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.give.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.get.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
}
|
||||
});
|
||||
|
||||
List<String> player2Items = new ArrayList<>();
|
||||
@ -128,8 +135,10 @@ public class Trade {
|
||||
final String itemName = Utils.getFormattedItemName(itemStack);
|
||||
int itemAm = itemStack.getAmount();
|
||||
player2Items.add(itemAm + "x " + itemName);
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.give.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.get.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
if (CONFIG.getBoolean("enable-trade-summaries")) {
|
||||
MESSAGEUTILS.sendFormatted(player2.getPlayer(), LANG.getString("summary.give.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
MESSAGEUTILS.sendFormatted(player1.getPlayer(), LANG.getString("summary.get.item"), Map.of("%amount%", "" + itemAm, "%item%", itemName));
|
||||
}
|
||||
});
|
||||
|
||||
HistoryUtils.writeToHistory(
|
||||
|
@ -42,7 +42,7 @@ public class TradeGui extends GuiFrame {
|
||||
// private final ItemStack fullSlot;
|
||||
|
||||
public TradeGui(@NotNull Trade trade, @NotNull TradePlayer player) {
|
||||
super(GUIS, player.getPlayer());
|
||||
super(GUIS, player.getPlayer(), trade);
|
||||
this.trade = trade;
|
||||
this.player = player;
|
||||
this.gui = Gui.storage()
|
||||
@ -160,34 +160,27 @@ public class TradeGui extends GuiFrame {
|
||||
// private final HashSet<Integer> lockedSlot = new HashSet<>();
|
||||
|
||||
public void update() {
|
||||
final Pair<String, String> selfTextures = NMSHandlers.getNmsHandler().textures(player.getPlayer());
|
||||
final Pair<String, String> otherTextures = NMSHandlers.getNmsHandler().textures(trade.getOtherPlayer(player.getPlayer()));
|
||||
|
||||
final Map<String, String> replacements = Map.of(
|
||||
"%own-head%", selfTextures == null ? "" : selfTextures.getFirst(),
|
||||
"%partner-head%", otherTextures == null ? "" : otherTextures.getFirst()
|
||||
);
|
||||
if (player.hasConfirmed()) {
|
||||
super.createItem("own.confirm-item.slot", "own.confirm-item.cancel", event -> {
|
||||
event.setCancelled(true);
|
||||
player.cancel();
|
||||
trade.update();
|
||||
}, replacements, player.getConfirmed());
|
||||
}, Map.of(), player.getConfirmed());
|
||||
} else {
|
||||
super.createItem("own.confirm-item.slot", "own.confirm-item.accept", event -> {
|
||||
event.setCancelled(true);
|
||||
player.confirm();
|
||||
}, replacements);
|
||||
}, Map.of());
|
||||
}
|
||||
|
||||
if (player.getOtherPlayer().hasConfirmed()) {
|
||||
super.createItem("partner.confirm-item.slot", "partner.confirm-item.cancel", event -> {
|
||||
event.setCancelled(true);
|
||||
}, replacements, player.getOtherPlayer().getConfirmed());
|
||||
}, Map.of(), player.getOtherPlayer().getConfirmed());
|
||||
} else {
|
||||
super.createItem("partner.confirm-item.slot", "partner.confirm-item.accept", event -> {
|
||||
event.setCancelled(true);
|
||||
}, replacements);
|
||||
}, Map.of());
|
||||
}
|
||||
|
||||
for (String currencyItem : GUIS.getSection("own").getRoutesAsStrings(false)) {
|
||||
|
@ -1,126 +0,0 @@
|
||||
package com.artillexstudios.axtrade.utils;
|
||||
|
||||
import com.artillexstudios.axapi.items.WrappedItemStack;
|
||||
import com.artillexstudios.axapi.items.component.DataComponents;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NBTUtils {
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, @NotNull String content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putString(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, int content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putInt(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, boolean content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putBoolean(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, double content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putDouble(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, long content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putLong(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, float content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putFloat(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static void writeToNBT(@NotNull ItemStack item, @NotNull String namespace, UUID content) {
|
||||
WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
var customData = wrappedItemStack.get(DataComponents.customData());
|
||||
customData.putUUID(namespace, content);
|
||||
wrappedItemStack.set(DataComponents.customData(), customData);
|
||||
return wrappedItemStack;
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean containsNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).contains(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String readStringFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
final String str = wrappedItemStack.get(DataComponents.customData()).getString(namespace);
|
||||
return str.isEmpty() ? null : str;
|
||||
});
|
||||
}
|
||||
|
||||
public static int readIntegerFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getInt(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
public static float readFloatFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getFloat(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
public static long readLongFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getLong(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
public static double readDoubleFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getDouble(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UUID readUUIDFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getUUID(namespace);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean readBooleanFromNBT(@NotNull ItemStack item, @NotNull String namespace) {
|
||||
return WrappedItemStack.edit(item, wrappedItemStack -> {
|
||||
return wrappedItemStack.get(DataComponents.customData()).getBoolean(namespace);
|
||||
});
|
||||
}
|
||||
}
|
@ -25,6 +25,9 @@ trade-max-distance: 10
|
||||
# should shift + right clicking on another player send them a trade request?
|
||||
shift-click-send-request: true
|
||||
|
||||
# the trade summaries will not be sent after trades end to players if disabled
|
||||
enable-trade-summaries: true
|
||||
|
||||
number-formatting:
|
||||
# modes:
|
||||
# 0 - formatted (customizable, look at the formatted part)
|
||||
@ -60,4 +63,4 @@ update-notifier:
|
||||
on-join: true
|
||||
|
||||
# do not change this
|
||||
version: 3
|
||||
version: 4
|
Loading…
Reference in New Issue
Block a user