Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/fr/openmc/core/CommandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fr.openmc.core.features.adminshop.AdminShopCommand;
import fr.openmc.core.features.cube.CubeCommands;
import fr.openmc.core.features.cube.multiblocks.MultiBlockManager;
import fr.openmc.core.features.corporation.commands.ShopCommand;
import fr.openmc.core.features.friend.FriendCommand;
import fr.openmc.core.features.friend.FriendManager;
import fr.openmc.core.features.mailboxes.MailboxCommand;
Expand Down Expand Up @@ -57,7 +58,8 @@ private static void registerCommands() {
new SocialSpyCommand(),
new SettingsCommand(),
new Cooldowns(),
new CubeCommands()
new CubeCommands(),
new ShopCommand()
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/fr/openmc/core/ListenersManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.openmc.api.input.ChatInput;
import fr.openmc.api.input.location.ItemInteraction;
import fr.openmc.core.features.corporation.listener.ShopListener;
import fr.openmc.core.features.cube.listeners.CubeListener;
import fr.openmc.core.features.cube.listeners.RepulseEffectListener;
import fr.openmc.core.features.cube.multiblocks.MultiBlocksListeners;
Expand Down Expand Up @@ -40,7 +41,8 @@ public ListenersManager() {
new InteractListener(),
new ItemsAddersListener(),
new TicketListener(),
new AywenCapListener()
new AywenCapListener(),
new ShopListener()
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public void onEnable() {
if (!OMCPlugin.isUnitTestVersion()) {
new LeaderboardManager();
new MainMenu(this);
new HologramLoader();
}
new AdminShopManager();
new BossbarManager();
Expand Down Expand Up @@ -148,6 +147,9 @@ public void loadWithItemsAdder() {
ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130);
ParticleUtils.spawnContestParticlesInRegion("spawn", Bukkit.getWorld("world"), 10, 70, 135);
}
if (! OMCPlugin.isUnitTestVersion()) {
new HologramLoader();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.openmc.core.disabled.corporation.manager;
package fr.openmc.core.disabled.corporation;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
Expand All @@ -10,14 +10,18 @@
import fr.openmc.core.OMCPlugin;
import fr.openmc.core.disabled.corporation.CorpPermission;
import fr.openmc.core.disabled.corporation.MethodState;
import fr.openmc.core.features.city.City;
import fr.openmc.core.features.city.CityManager;
import fr.openmc.core.features.corporation.MethodState;
import fr.openmc.core.disabled.corporation.commands.CompanyCommand;
import fr.openmc.core.disabled.corporation.commands.ShopCommand;
import fr.openmc.core.features.corporation.commands.ShopCommand;
import fr.openmc.core.disabled.corporation.company.Company;
import fr.openmc.core.disabled.corporation.company.CompanyOwner;
import fr.openmc.core.disabled.corporation.data.MerchantData;
import fr.openmc.core.disabled.corporation.listener.CustomItemsCompanyListener;
import fr.openmc.core.disabled.corporation.listener.ShopListener;
import fr.openmc.core.features.corporation.data.MerchantData;
import fr.openmc.core.features.corporation.listener.ShopListener;
import fr.openmc.core.disabled.corporation.models.*;
import fr.openmc.core.features.corporation.manager.PlayerShopManager;
import fr.openmc.core.features.corporation.manager.ShopManager;
import fr.openmc.core.disabled.corporation.shops.Shop;
import fr.openmc.core.disabled.corporation.shops.ShopItem;
import fr.openmc.core.disabled.corporation.shops.Supply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import fr.openmc.core.features.city.City;
import fr.openmc.core.features.city.CityManager;
import fr.openmc.core.disabled.corporation.CorpPermission;
import fr.openmc.core.disabled.corporation.MethodState;
import fr.openmc.core.features.corporation.MethodState;
import fr.openmc.core.disabled.corporation.company.Company;
import fr.openmc.core.disabled.corporation.company.CompanyOwner;
import fr.openmc.core.disabled.corporation.manager.CompanyManager;
import fr.openmc.core.disabled.corporation.manager.PlayerShopManager;
import fr.openmc.core.disabled.corporation.CompanyManager;
import fr.openmc.core.features.corporation.manager.PlayerShopManager;
import fr.openmc.core.disabled.corporation.menu.company.CompanyBaltopMenu;
import fr.openmc.core.disabled.corporation.menu.company.CompanyMenu;
import fr.openmc.core.disabled.corporation.menu.company.CompanySearchMenu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import fr.openmc.api.menulib.utils.ItemUtils;
import fr.openmc.core.OMCPlugin;
import fr.openmc.core.disabled.corporation.CorpPermission;
import fr.openmc.core.disabled.corporation.MethodState;
import fr.openmc.core.disabled.corporation.data.MerchantData;
import fr.openmc.core.disabled.corporation.data.TransactionData;
import fr.openmc.core.disabled.corporation.manager.CompanyManager;
import fr.openmc.core.disabled.corporation.manager.ShopBlocksManager;
import fr.openmc.core.features.corporation.MethodState;
import fr.openmc.core.features.corporation.data.MerchantData;
import fr.openmc.core.features.corporation.data.TransactionData;
import fr.openmc.core.disabled.corporation.CompanyManager;
import fr.openmc.core.features.corporation.manager.ShopManager;
import fr.openmc.core.disabled.corporation.models.DBCompany;
import fr.openmc.core.disabled.corporation.shops.Shop;
import fr.openmc.core.disabled.corporation.shops.ShopOwner;
import fr.openmc.core.features.city.City;
import fr.openmc.core.features.city.CityManager;
import fr.openmc.core.features.city.CityPermission;
import fr.openmc.core.features.corporation.shops.Shop;
import fr.openmc.core.features.corporation.shops.ShopOwner;
import fr.openmc.core.features.economy.EconomyManager;
import fr.openmc.core.utils.Queue;
import fr.openmc.core.utils.messages.MessageType;
Expand Down Expand Up @@ -62,7 +62,7 @@ public Company(String name, CompanyOwner owner, UUID company_uuid) {
addPermission(owner.getPlayer(), CorpPermission.OWNER);
addMerchant(owner.getPlayer(), new MerchantData());
}

// à revoir, je l'utilisais pour les entreprises de ville
public Company(String name, CompanyOwner owner, UUID company_uuid, boolean newMember) {
this.name = name;
Expand Down Expand Up @@ -255,7 +255,7 @@ public boolean createShop(UUID playerUUID, Block barrel, Block cash) {
return false;
}

Shop newShop = new Shop(new ShopOwner(this), shopCounter);
Shop newShop = new Shop(new ShopOwner(), shopCounter);
EconomyManager.withdrawBalance(whoCreated.getUniqueId(), 100);

shops.add(newShop);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,209 +0,0 @@
package fr.openmc.core.disabled.corporation.listener;

import fr.openmc.core.disabled.corporation.CorpPermission;
import fr.openmc.core.disabled.corporation.company.Company;
import fr.openmc.core.disabled.corporation.manager.CompanyManager;
import fr.openmc.core.disabled.corporation.manager.ShopBlocksManager;
import fr.openmc.core.disabled.corporation.menu.shop.ShopMenu;
import fr.openmc.core.disabled.corporation.shops.Shop;
import fr.openmc.core.utils.messages.MessageType;
import fr.openmc.core.utils.messages.MessagesManager;
import fr.openmc.core.utils.messages.Prefix;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Barrel;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class ShopListener implements Listener {

private final Map<UUID, Boolean> inShopBarrel = new HashMap<>();

@EventHandler
public void onShopBreak(BlockBreakEvent event) {
if (ShopBlocksManager.getShop(event.getBlock().getLocation()) != null) {
event.setCancelled(true);
}
}

@EventHandler
public void onShopExplode(BlockExplodeEvent event){
event.blockList().removeIf(block -> ShopBlocksManager.getShop(block.getLocation()) != null);
}

@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().removeIf(block -> ShopBlocksManager.getShop(block.getLocation()) != null);
}

@EventHandler
public void onShopClick(PlayerInteractEvent event) {
if (event.getClickedBlock() == null) {
return;
}

// Check if the clicked block is a sign with tags
// Instead of getting the entire state of the block,
// This is much faster and avoids unnecessary overhead
if (!Tag.SIGNS.isTagged(event.getClickedBlock().getType()))
return;

if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;

Shop shop = ShopBlocksManager.getShop(event.getClickedBlock().getLocation());
if (shop == null)
return;

event.setCancelled(true);
ShopMenu menu = new ShopMenu(event.getPlayer(), shop, 0);
menu.open();
}

@EventHandler
public void onInteractWithBlock(PlayerInteractEvent e) {
Block block = e.getClickedBlock();
if (block != null && block.getType() == Material.BARREL) {
Shop shop = ShopBlocksManager.getShop(block.getLocation());
boolean isShop = shop!=null;
if (isShop){
Company company = CompanyManager.getCompany(e.getPlayer().getUniqueId());
if (company==null){
if (shop.getOwner().getPlayer()==null){
e.setCancelled(true);
return;
}
if (!shop.getOwner().getPlayer().equals(e.getPlayer().getUniqueId())){
e.setCancelled(true);
return;
}
} else {
if (!company.hasShop(shop.getUuid())){
e.setCancelled(true);
MessagesManager.sendMessage(e.getPlayer(), Component.text("Tu n'es pas dans l'entrprise possédant ce shop"), Prefix.SHOP, MessageType.INFO, false);
return;
}

if (!company.hasPermission(e.getPlayer().getUniqueId(), CorpPermission.SUPPLY)){
e.setCancelled(true);
MessagesManager.sendMessage(e.getPlayer(), Component.text("Tu n'as pas la permission de réapprovisionner le shop"), Prefix.SHOP, MessageType.INFO, false);
return;
}
}
}
inShopBarrel.put(e.getPlayer().getUniqueId(), isShop);
}
}

@EventHandler
public void onShopPutItem(InventoryClickEvent e) {
UUID playerUUID = e.getWhoClicked().getUniqueId();
if (inShopBarrel.getOrDefault(playerUUID, false)) {
Player player = (Player) e.getWhoClicked();
Company company = CompanyManager.getCompany(playerUUID);
if (company!=null){
if (!company.hasPermission(playerUUID, CorpPermission.SUPPLY)){
MessagesManager.sendMessage(player, Component.text("Vous n'avez pas la permission de réapprovisionner les shops dans l'entreprise"), Prefix.SHOP, MessageType.INFO, false);
player.closeInventory();
return;
}
}

Inventory clickedInventory = e.getClickedInventory();

if (clickedInventory == null) return;

if (clickedInventory.getHolder(false) instanceof Barrel) {
ItemStack currentItem = e.getCurrentItem();
ItemStack cursorItem = e.getCursor();

if (e.isShiftClick() && isValidItem(currentItem)) {
removeSupplierKey(currentItem);
}
// Vérifier si un item est retiré
else if (e.getAction().name().contains("PICKUP") && isValidItem(currentItem)) {
removeSupplierKey(currentItem);
}
else if (e.getAction().name().contains("SWAP") && isValidItem(currentItem)) {
removeSupplierKey(currentItem);
}
// Vérifier si un item est placé avec la souris
else if (e.getAction().name().contains("PLACE") && isValidItem(cursorItem)) {
setSupplierKey(cursorItem, player.getUniqueId().toString());
}
} else if (clickedInventory.getHolder(false) instanceof Player) {
ItemStack currentItem = e.getCurrentItem();

if (e.isShiftClick() && !e.getAction().name().contains("SWAP") && isValidItem(currentItem)) {
setSupplierKey(currentItem, player.getUniqueId().toString());
}
}
}
}

@EventHandler
public void onItemDrag(InventoryDragEvent e) {
UUID playerUUID = e.getWhoClicked().getUniqueId();
if (inShopBarrel.getOrDefault(playerUUID, false) && e.getInventory().getHolder(false) instanceof Barrel) {
ItemStack item = e.getOldCursor();
if (isValidItem(item)) {
removeSupplierKey(item);
}
}
}

/**
* check if an item is valid
*
* @param item the item to check
* @return true if it's a valid item
*/
private boolean isValidItem(ItemStack item) {
return item != null && item.getType() != Material.AIR;
}

/**
* add the SUPPLIER_KEY to an item
*
* @param item the item to add the key
* @param uuid the uuid of the player (the supplier_key)
*/
private void setSupplierKey(ItemStack item, String uuid) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.getPersistentDataContainer().set(CompanyManager.SUPPLIER_KEY, PersistentDataType.STRING, uuid);
item.setItemMeta(meta);
}
}

/**
* remove the SUPPLIER_KEY to an item
*
* @param item the item to remove the key
*/
private void removeSupplierKey(ItemStack item) {
ItemMeta meta = item.getItemMeta();
if (meta != null && meta.getPersistentDataContainer().has(CompanyManager.SUPPLIER_KEY)) {
meta.getPersistentDataContainer().remove(CompanyManager.SUPPLIER_KEY);
item.setItemMeta(meta);
}
}
}
Loading
Loading