Implemented buying prizes
This commit is contained in:
parent
31b3cc69e4
commit
1c135be1ba
|
|
@ -232,7 +232,9 @@ public class Config extends AbstractConfig {
|
||||||
itemStack.setItemMeta(itemMeta);
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
|
||||||
prizes.add(
|
prizes.add(
|
||||||
new Prize(itemStack,
|
new Prize(
|
||||||
|
itemStack,
|
||||||
|
config.getString(prefix, "command", "example command for <player>"),
|
||||||
config.getString(prefix, "permission", "example.permission"),
|
config.getString(prefix, "permission", "example.permission"),
|
||||||
config.getString(prefix, "prize-name", "Prize Name"),
|
config.getString(prefix, "prize-name", "Prize Name"),
|
||||||
config.getInt(prefix, "prize-price", 1))
|
config.getInt(prefix, "prize-price", 1))
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ public class Messages extends AbstractConfig {
|
||||||
public static String SELL_GUI_NAME = "<green>Sell GUI</green>";;
|
public static String SELL_GUI_NAME = "<green>Sell GUI</green>";;
|
||||||
public static String NOT_INITIALIZED = "<red>There was an error initializing this GUI, please contact staff</red>";
|
public static String NOT_INITIALIZED = "<red>There was an error initializing this GUI, please contact staff</red>";
|
||||||
public static String EARNED_POINTS = "<green>You earned <gold><earned_points></gold> points from this sale, you are now at <gold><total_points></gold> points!";
|
public static String EARNED_POINTS = "<green>You earned <gold><earned_points></gold> points from this sale, you are now at <gold><total_points></gold> points!";
|
||||||
|
public static String NOT_ENOUGH_POINTS = "<red>You do not have enough points to purchase this, it costs <gold><price></gold> and you only have <gold><points></gold> points</red>";
|
||||||
|
public static String PURCHASED = "<green>You purchased the <prize> prize. You have <remaining_points> points remaining.";
|
||||||
|
public static String ALREADY_PURCHASED = "<red>You already purchased the <prize> prize.</red>";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
|
|
@ -64,6 +67,9 @@ public class Messages extends AbstractConfig {
|
||||||
SELL_GUI_NAME = config.getString(prefix, "sell-gui-name", SELL_GUI_NAME);
|
SELL_GUI_NAME = config.getString(prefix, "sell-gui-name", SELL_GUI_NAME);
|
||||||
NOT_INITIALIZED = config.getString(prefix, "not-initialized", NOT_INITIALIZED);
|
NOT_INITIALIZED = config.getString(prefix, "not-initialized", NOT_INITIALIZED);
|
||||||
EARNED_POINTS = config.getString(prefix, "earned-points", EARNED_POINTS);
|
EARNED_POINTS = config.getString(prefix, "earned-points", EARNED_POINTS);
|
||||||
|
NOT_ENOUGH_POINTS = config.getString(prefix, "not-enough-points", NOT_ENOUGH_POINTS);
|
||||||
|
PURCHASED = config.getString(prefix, "purchased", PURCHASED);
|
||||||
|
ALREADY_PURCHASED = config.getString(prefix, "already-purchased", ALREADY_PURCHASED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,30 +3,64 @@ package com.alttd.fishingevent.gui.windows;
|
||||||
import com.alttd.fishingevent.config.Messages;
|
import com.alttd.fishingevent.config.Messages;
|
||||||
import com.alttd.fishingevent.gui.GUI;
|
import com.alttd.fishingevent.gui.GUI;
|
||||||
import com.alttd.fishingevent.objects.Prize;
|
import com.alttd.fishingevent.objects.Prize;
|
||||||
|
import com.alttd.fishingevent.points.PointsManagement;
|
||||||
import com.alttd.fishingevent.util.Logger;
|
import com.alttd.fishingevent.util.Logger;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PrizesWindow extends GUI {
|
public class PrizesWindow extends GUI {
|
||||||
|
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
private final ItemStack alreadyPurchasedItem = new ItemStack(Material.BARRIER, 1);
|
||||||
|
|
||||||
public PrizesWindow(Player player, Logger logger, List<Prize> prizes) {
|
public PrizesWindow(Player player, Logger logger, List<Prize> prizes) {
|
||||||
super(InventoryType.CHEST, MiniMessage.miniMessage().deserialize(Messages.GUI.PRIZES_GUI_NAME));
|
super(InventoryType.CHEST, MiniMessage.miniMessage().deserialize(Messages.GUI.PRIZES_GUI_NAME));
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Prize prize : prizes) {
|
for (Prize prize : prizes) {
|
||||||
setItem(i, prize.itemStack().clone(), clickingPlayer -> buy(clickingPlayer, prize));
|
if (player.hasPermission(prize.permission()))
|
||||||
|
setItem(i, alreadyPurchasedItem.clone(), clickingPlayer -> alreadyPurchased(clickingPlayer, prize));
|
||||||
|
else
|
||||||
|
setItem(i, prize.itemStack().clone(), clickingPlayer -> buy(clickingPlayer, prize));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void alreadyPurchased(Player clickingPlayer, Prize prize) {
|
||||||
|
clickingPlayer.sendMiniMessage(Messages.GUI.ALREADY_PURCHASED, Placeholder.parsed("prize", prize.name()));
|
||||||
|
}
|
||||||
|
|
||||||
private void buy(Player player, Prize prize) {
|
private void buy(Player player, Prize prize) {
|
||||||
player.sendMiniMessage("<red>Buying is not implemented yet</red>", null);
|
player.sendMiniMessage("<red>Buying is not implemented yet</red>", null);
|
||||||
//TODO implement selling
|
UUID uuid = player.getUniqueId();
|
||||||
|
PointsManagement pointsManagement = PointsManagement.getInstance();
|
||||||
|
int playerPoints = pointsManagement.getPoints(uuid);
|
||||||
|
if (prize.price() < playerPoints) {
|
||||||
|
player.sendMiniMessage(Messages.GUI.NOT_ENOUGH_POINTS, TagResolver.resolver(
|
||||||
|
Placeholder.parsed("price", String.valueOf(prize.price())),
|
||||||
|
Placeholder.parsed("points", String.valueOf(playerPoints))
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int remainingPoints;
|
||||||
|
try {
|
||||||
|
remainingPoints = pointsManagement.removePoints(uuid, prize.price());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.sendMiniMessage(Messages.GUI.PURCHASED, TagResolver.resolver(
|
||||||
|
Placeholder.parsed("remaining_points", String.valueOf(remainingPoints)),
|
||||||
|
Placeholder.parsed("prize", prize.name())
|
||||||
|
));
|
||||||
|
player.getServer().dispatchCommand(player.getServer().getConsoleSender(), prize.command().replace("<player>", player.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@ package com.alttd.fishingevent.objects;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public record Prize(ItemStack itemStack, String permission, String name, int price) {
|
public record Prize(ItemStack itemStack, String command, String permission, String name, int price) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
package com.alttd.fishingevent.points;
|
package com.alttd.fishingevent.points;
|
||||||
|
|
||||||
import com.alttd.fishingevent.FishingEvent;
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
import it.unimi.dsi.fastutil.io.BinIO;
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class LoadTask implements Runnable {
|
public class LoadTask implements Runnable {
|
||||||
|
|
||||||
|
|
@ -20,15 +14,15 @@ public class LoadTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
File file = new File(fishingEvent.getDataFolder(), "map.bin");
|
// File file = new File(fishingEvent.getDataFolder(), "map.bin");
|
||||||
Object2IntOpenHashMap<UUID> loadedMap;
|
// Object2IntOpenHashMap<UUID> loadedMap;
|
||||||
try {
|
// try {
|
||||||
//noinspection unchecked
|
// //noinspection unchecked
|
||||||
loadedMap = (Object2IntOpenHashMap<UUID>) BinIO.loadObject(file);
|
// loadedMap = (Object2IntOpenHashMap<UUID>) BinIO.loadObject(file);
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
// } catch (IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
pointsManagement.setMap(loadedMap);
|
// pointsManagement.setMap(loadedMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user