Skip to content
Open
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: 4 additions & 0 deletions src/main/java/shift/mceconomy2/MCEconomy2.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraftforge.common.MinecraftForge;
import shift.mceconomy2.api.MCEconomyAPI;
import shift.mceconomy2.api.shop.ShopAPI;
import shift.mceconomy2.event.CommonEventManager;
import shift.mceconomy2.event.MPManager;
import shift.mceconomy2.gui.HUDMP;
import shift.mceconomy2.item.MCEItems;
import shift.mceconomy2.packet.PacketHandler;
import shift.mceconomy2.proxy.CommonProxy;
import shift.mceconomy2.shop.ShopAPIHandler;

@Mod(modid = MCEconomy2.MODID, version = MCEconomy2.VERSION, dependencies = MCEconomy2.DEPENDENCY)
public class MCEconomy2 {
Expand Down Expand Up @@ -46,6 +48,8 @@ public void preInit(FMLPreInitializationEvent event) {
MCEconomyAPI.ShopManager = new ShopManager();
MCEconomyAPI.registerPurchaseItem();

ShopAPI.apiHandler = new ShopAPIHandler();

}

@EventHandler
Expand Down
57 changes: 13 additions & 44 deletions src/main/java/shift/mceconomy2/ShopManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Iterator;
import java.util.Map.Entry;

import com.google.common.collect.Lists;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand All @@ -15,30 +17,21 @@
import shift.mceconomy2.api.shop.IProductList;
import shift.mceconomy2.api.shop.IShop;
import shift.mceconomy2.api.shop.IShopManager;
import shift.mceconomy2.api.shop.ShopAPI;
import shift.mceconomy2.api.shop.ShopAdapter;
import shift.mceconomy2.packet.PacketGuiId;
import shift.mceconomy2.packet.PacketHandler;

public class ShopManager implements IShopManager {

//private final ArrayList<IProductList> ProductList = new ArrayList<IProductList>();

private final ArrayList<IShop> shopList = new ArrayList<IShop>();

private static final HashMap<ItemStack, Integer> purchaseList = new HashMap<ItemStack, Integer>();

private static final HashMap<Integer, Double> purchaseFluidList = new HashMap<Integer, Double>();

private static final HashMap<Class<? extends Entity>, Integer> purchaseEntityList = new HashMap<Class<? extends Entity>, Integer>();

public ShopManager() {

shopList.add(null);
shopList.add(null);

}
//ショップ関係

//shop関係
@Override
public int registerProductList(IProductList list) {

Expand Down Expand Up @@ -68,51 +61,27 @@ public ArrayList<IProductList> getProductLists() {
}

@Override
public int registerShop(IShop list) {

shopList.add(list);

return shopList.indexOf(list);
public int registerShop(IShop shop) {

return ShopAPI.registerShop("deprecated", shop);
}

@Override
public IShop getShop(int id) {

if (shopList.size() < id) {
return null;
}
return shopList.get(id);
return ShopAPI.getShop("deprecated", id);
}

@Override
public ArrayList<IShop> getShops() {
return shopList;
}

//ショップ関係
return Lists.newArrayList(ShopAPI.getShops("deprecated"));
}

@Override
public void openShopGui(int id, EntityPlayer player, World world, int x, int y, int z) {

/*OpenShopGuiEvent event = new OpenShopGuiEvent(player, id, world, x, y, z);

if (MinecraftForge.EVENT_BUS.post(event))
{
return;
}

if (event.getResult() == Result.ALLOW)
{
return ;
}*/

if (world.isRemote) {
PacketHandler.INSTANCE.sendToServer(new PacketGuiId(id));
} else {
player.openGui(MCEconomy2.instance, id, world, x, y, z);
}

ShopAPI.openShop(player, "deprecated", id);
}

@Override
Expand Down Expand Up @@ -156,7 +125,7 @@ private boolean func_151397_a(ItemStack p_151397_1_, ItemStack p_151397_2_) {

@Override
public boolean hasPurchase(ItemStack item) {
return (this.getPurchase(item) != -1 && this.getPurchase(item) != -2);
return this.getPurchase(item) != -1 && this.getPurchase(item) != -2;
}

@Override
Expand All @@ -180,7 +149,7 @@ public double getFluidPurchase(Fluid fluid) {

@Override
public boolean hasFluidPurchase(Fluid fluid) {
return (this.getFluidPurchase(fluid) != -1 && this.getFluidPurchase(fluid) != -2);
return this.getFluidPurchase(fluid) != -1 && this.getFluidPurchase(fluid) != -2;
}

@Override
Expand All @@ -206,7 +175,7 @@ public int getEntityPurchase(Entity entity) {

@Override
public boolean hasEntityPurchase(Entity entity) {
return (this.getEntityPurchase(entity) != -1 && this.getEntityPurchase(entity) != -2);
return this.getEntityPurchase(entity) != -1 && this.getEntityPurchase(entity) != -2;
}

}
3 changes: 3 additions & 0 deletions src/main/java/shift/mceconomy2/api/MCEconomyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static IProductList getProductList(int id) {
* @see IShop
* @return ShopID
*/
@Deprecated
public static int registerShop(IShop shop) {
return ShopManager.registerShop(shop);
}
Expand All @@ -159,6 +160,7 @@ public static int registerShop(IShop shop) {
* @param id ShopID
* @return IShop
*/
@Deprecated
public static IShop getShop(int id) {
return ShopManager.getShop(id);
}
Expand All @@ -172,6 +174,7 @@ public static IShop getShop(int id) {
* @param y y軸
* @param z z軸
*/
@Deprecated
public static void openShopGui(int id, EntityPlayer player, World world, int x, int y, int z) {
ShopManager.openShopGui(id, player, world, x, y, z);
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/shift/mceconomy2/api/event/ShopEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package shift.mceconomy2.api.event;

import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import shift.mceconomy2.api.shop.IShop;

public class ShopEvent extends Event {

public final IShop shop;

public ShopEvent(IShop shop) {
this.shop = shop;
}

/**
* ショップが登録される前に呼ばれるイベントです。<br>
* このイベントをキャンセルすると、そのショップは登録されません。<br>
* このイベントは、{@link MinecraftForge#EVENT_BUS}で呼ばれます。
*/
@Cancelable
public static class Register extends ShopEvent {

public final String modId;

public Register(String modId, IShop shop) {
super(shop);
this.modId = modId;
}
}

/**
* ショップが開かれる前に呼ばれるイベントです。<br>
* このイベントをキャンセルすると、そのショップは開かれません。<br>
* このイベントは、{@link MinecraftForge#EVENT_BUS}で呼ばれます。
*/
@Cancelable
public static class OpenShop extends ShopEvent {

public final EntityPlayer player;
public final String modId;
public final int shopId;

public OpenShop(EntityPlayer player, String modId, int shopId, IShop shop) {
super(shop);
this.player = player;
this.modId = modId;
this.shopId = shopId;
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/shift/mceconomy2/api/shop/IShopAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package shift.mceconomy2.api.shop;

import java.util.List;
import java.util.Map;

import net.minecraft.entity.player.EntityPlayer;

public interface IShopAPI {

public int registerShop(String modid, IShop shop);

public IShop getShop(String modid, int id);

public List<IShop> getShops(String modid);

public Map<String, List<IShop>> getShopEntries();

public void openShop(EntityPlayer player, String modid, int id);
}
93 changes: 93 additions & 0 deletions src/main/java/shift/mceconomy2/api/shop/ShopAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package shift.mceconomy2.api.shop;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import net.minecraft.entity.player.EntityPlayer;

/**
* MOD別にショップを管理します。<br>
* MODIDごとにショップリストが生成されます。
* @author kegare
*/
public final class ShopAPI {

public static IShopAPI apiHandler;

/**
* ショップを登録します。
* @param modid 登録するMODのID
* @param shop 登録するショップ
* @return MOD別のショップIDを返します。登録に失敗した場合は、-1を返します。
*/
public static int registerShop(String modid, IShop shop) {

if (apiHandler != null) {

return apiHandler.registerShop(modid, shop);
}

return -1;
}

/**
* ショップを取得します。
* @param modid ショップのMODID
* @param id ショップID
* @return ショップが取得できなかった場合は、nullを返します。
*/
public static IShop getShop(String modid, int id) {

if (apiHandler != null) {

return apiHandler.getShop(modid, id);
}

return null;
}

/**
* ショップリストを取得します。
* @return ショップリストが取得できなかった場合は、不変の空のリストを返します。
*/
public static List<IShop> getShops(String modid) {

if (apiHandler != null) {

return apiHandler.getShops(modid);
}

return Collections.emptyList();
}

/**
* ショップリストのエントリマップを取得します。<br>
* マップのキーにはMODID、値には対応するショップリストが格納されています。
*/
public static Map<String, List<IShop>> getShopEntries() {

if (apiHandler != null) {

return apiHandler.getShopEntries();
}

return Collections.emptyMap();
}

/**
* ショップを開きます。<br>
* クライアントからでもサーバーからでも呼び出すことができます。<br>
* 片側のみで呼び出すようにしてください。
* @param player プレイヤー
* @param modid ショップのMODID
* @param id ショップID
*/
public static void openShop(EntityPlayer player, String modid, int id) {

if (apiHandler != null) {

apiHandler.openShop(player, modid, id);
}
}
}
Loading