|
|
|
|
@ -1,6 +1,8 @@ |
|
|
|
|
package xyz.soukup.ecoCraftCore.shop; |
|
|
|
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem; |
|
|
|
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; |
|
|
|
|
import com.github.stefvanschie.inventoryframework.gui.type.HopperGui; |
|
|
|
|
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; |
|
|
|
|
import com.github.stefvanschie.inventoryframework.pane.StaticPane; |
|
|
|
|
import io.papermc.paper.dialog.Dialog; |
|
|
|
|
import io.papermc.paper.dialog.DialogResponseView; |
|
|
|
|
@ -11,13 +13,16 @@ import io.papermc.paper.registry.data.dialog.input.DialogInput; |
|
|
|
|
import io.papermc.paper.registry.data.dialog.type.DialogType; |
|
|
|
|
import net.kyori.adventure.audience.Audience; |
|
|
|
|
import net.kyori.adventure.text.event.ClickCallback; |
|
|
|
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; |
|
|
|
|
import org.bukkit.Material; |
|
|
|
|
import org.bukkit.block.Block; |
|
|
|
|
import org.bukkit.block.Sign; |
|
|
|
|
import org.bukkit.entity.Player; |
|
|
|
|
import org.bukkit.event.EventHandler; |
|
|
|
|
import org.bukkit.event.EventPriority; |
|
|
|
|
import org.bukkit.event.Listener; |
|
|
|
|
import org.bukkit.event.block.Action; |
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent; |
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent; |
|
|
|
|
import org.bukkit.inventory.Inventory; |
|
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
|
@ -29,7 +34,7 @@ import xyz.soukup.ecoCraftCore.messages.Messages; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.Account; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.Shop; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.Transaction; |
|
|
|
|
import xyz.soukup.ecoCraftCore.inventory.VirtualChest; |
|
|
|
|
import xyz.soukup.ecoCraftCore.database.objects.VirtualChest; |
|
|
|
|
import xyz.soukup.ecoCraftCore.utilities.*; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
@ -87,6 +92,39 @@ public class ShopLogic implements Listener { |
|
|
|
|
gui.show(player); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGHEST) |
|
|
|
|
public void onDestroy(BlockBreakEvent event){ |
|
|
|
|
|
|
|
|
|
if (event.isCancelled()){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Block block = event.getBlock(); |
|
|
|
|
|
|
|
|
|
if (!(block.getState() instanceof Sign sign)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Integer id = PDC.getInteger(sign, "shop"); |
|
|
|
|
|
|
|
|
|
if (id == null){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Shop shop = Shop.findById(id); |
|
|
|
|
|
|
|
|
|
if (shop == null){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
Player player = event.getPlayer(); |
|
|
|
|
HopperGui gui = confirmBreakGui(block, shop); |
|
|
|
|
gui.show(player); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ChestGui buildShopGui(Player player, Shop shop){ |
|
|
|
|
@ -260,7 +298,7 @@ public class ShopLogic implements Listener { |
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
hashMap.put("count", Integer.toString(amount)); |
|
|
|
|
hashMap.put("price", String.format("%.2f", price)); |
|
|
|
|
hashMap.put("item", itemStack.displayName().toString()); |
|
|
|
|
hashMap.put("item", PlainTextComponentSerializer.plainText().serialize(itemStack.displayName())); |
|
|
|
|
|
|
|
|
|
Messages.send(player, "shop.buy", hashMap); |
|
|
|
|
|
|
|
|
|
@ -348,9 +386,48 @@ public class ShopLogic implements Listener { |
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
hashMap.put("count", Integer.toString(amount)); |
|
|
|
|
hashMap.put("price", String.format("%.2f", price)); |
|
|
|
|
hashMap.put("item", itemStack.displayName().toString()); |
|
|
|
|
hashMap.put("item", PlainTextComponentSerializer.plainText().serialize(itemStack.displayName())); |
|
|
|
|
|
|
|
|
|
Messages.send(player, "shop.sell", hashMap); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static HopperGui confirmBreakGui(Block block, Shop shop){ |
|
|
|
|
HopperGui gui = new HopperGui(Messages.getAsString("menu.destroy-confirmation.title")); |
|
|
|
|
OutlinePane pane = new OutlinePane(0,0, 5, 1); |
|
|
|
|
|
|
|
|
|
gui.setOnGlobalClick(inventoryClickEvent -> { |
|
|
|
|
inventoryClickEvent.setCancelled(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
GuiItem confirmButton = new GuiItemBuilder(Material.LIME_WOOL) |
|
|
|
|
.setName(Messages.get("menu.destroy-confirmation.confirm")) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
GuiItem cancelButton = new GuiItemBuilder(Material.RED_WOOL) |
|
|
|
|
.setName(Messages.get("menu.destroy-confirmation.cancel")) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
cancelButton.setAction(event -> { |
|
|
|
|
event.getClickedInventory().close(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
confirmButton.setAction(event -> { |
|
|
|
|
destroyShopAndBlock(block, shop); |
|
|
|
|
event.getClickedInventory().close(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
pane.addItem(confirmButton); |
|
|
|
|
pane.addItem(cancelButton); |
|
|
|
|
|
|
|
|
|
gui.getSlotsComponent().addPane(pane); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return gui; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void destroyShopAndBlock(Block block, Shop shop){ |
|
|
|
|
block.breakNaturally(); |
|
|
|
|
shop.delete(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|