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
978 changes: 926 additions & 52 deletions src/com/minedhype/ishop/CommandShop.java

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions src/com/minedhype/ishop/EventShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class EventShop implements Listener {
public static boolean noShopNoStock = iShop.config.getBoolean("mustOwnShopForStock");
public static boolean placeFrameSign = iShop.config.getBoolean("placeItemFrameSigns");
public static boolean protectShopFromExplosion = iShop.config.getBoolean("protectShopBlocksFromExplosions");
public static boolean shuttingDown = false;
public static int soldMessageDelayTime = iShop.config.getInt("soldNotificationsDelayTime");
public static int stockRangeLimit = iShop.config.getInt("stockRangeLimitFromShop");
public static String shopBlock = iShop.config.getString("shopBlock");
Expand Down Expand Up @@ -88,6 +89,8 @@ public void onPlayerInteract(PlayerInteractEvent event) {
return;
}
event.setCancelled(true);
if(shuttingDown)
return;
if(InvStock.inShopInv.containsValue(shop.get().getOwner())) {
if(event.getHand().equals(EquipmentSlot.HAND))
event.getPlayer().sendMessage(Messages.SHOP_BUSY.toString());
Expand Down Expand Up @@ -122,6 +125,8 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
return;
}
event.setCancelled(true);
if(shuttingDown)
return;
if(InvStock.inShopInv.containsValue(shop.get().getOwner())) {
if(event.getHand().equals(EquipmentSlot.HAND))
event.getPlayer().sendMessage(Messages.SHOP_BUSY.toString());
Expand Down Expand Up @@ -159,6 +164,8 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
return;
}
event.setCancelled(true);
if(shuttingDown)
return;
if(InvStock.inShopInv.containsValue(shop.get().getOwner())) {
if(event.getHand().equals(EquipmentSlot.HAND))
event.getPlayer().sendMessage(Messages.SHOP_BUSY.toString());
Expand Down Expand Up @@ -186,6 +193,8 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
if(!isShopLoc || event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking())
return;
event.setCancelled(true);
if(shuttingDown)
return;
if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
if(Shop.getNumShops(event.getPlayer().getUniqueId()) < 1 && noShopNoStock) {
event.getPlayer().sendMessage(Messages.NO_SHOP_STOCK.toString());
Expand All @@ -201,6 +210,21 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
return;
} else { InvStock.inShopInv.put(event.getPlayer(), event.getPlayer().getUniqueId()); }
InvStock inv = InvStock.getInvStock(event.getPlayer().getUniqueId());
int maxStockPages = InvAdminShop.maxPages;
if(InvAdminShop.usePerms) {
String permPrefix = Permission.SHOP_STOCK_PREFIX.toString();
int maxPermPages = InvAdminShop.permissionMax;
boolean permissionFound = false;
for(int i=maxPermPages; i>0; i--)
if(event.getPlayer().hasPermission(permPrefix + i)) {
maxStockPages = i;
permissionFound = true;
break;
}
if(!permissionFound)
maxStockPages = maxPermPages;
}
inv.setMaxPages(maxStockPages);
inv.setPag(0);
inv.open(event.getPlayer());
}
Expand All @@ -218,6 +242,8 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
if(!isShopLoc || event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking())
return;
event.setCancelled(true);
if(shuttingDown)
return;
if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
if(Shop.getNumShops(event.getPlayer().getUniqueId()) < 1 && noShopNoStock) {
event.getPlayer().sendMessage(Messages.NO_SHOP_STOCK.toString());
Expand All @@ -233,6 +259,21 @@ else if(event.getHand().equals(EquipmentSlot.OFF_HAND))
return;
} else { InvStock.inShopInv.put(event.getPlayer(), event.getPlayer().getUniqueId()); }
InvStock inv = InvStock.getInvStock(event.getPlayer().getUniqueId());
int maxStockPages = InvAdminShop.maxPages;
if(InvAdminShop.usePerms) {
String permPrefix = Permission.SHOP_STOCK_PREFIX.toString();
int maxPermPages = InvAdminShop.permissionMax;
boolean permissionFound = false;
for(int i=maxPermPages; i>0; i--)
if(event.getPlayer().hasPermission(permPrefix + i)) {
maxStockPages = i;
permissionFound = true;
break;
}
if(!permissionFound)
maxStockPages = maxPermPages;
}
inv.setMaxPages(maxStockPages);
inv.setPag(0);
inv.open(event.getPlayer());
}
Expand Down
14 changes: 14 additions & 0 deletions src/com/minedhype/ishop/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public enum Messages {
ADMIN_SHOP_NUMBER("adminShopNumber"),
DISABLED_SHOP_BLOCK("disabledShopBlock"),
EXISTING_SHOP("existingShop"),
GP_CLAIM("noClaimPermission"),
NOT_A_PLAYER("notPlayer"),
NO_SHOP_CREATE_PERMISSION("noPermissionToCreateShop"),
NO_PERMISSION("noPermissions"),
NO_PLAYER_FOUND("noPlayerFound"),
NO_PLAYER_SHOP("noPlayerShop"),
Expand All @@ -20,9 +22,15 @@ public enum Messages {
SHOP_CLICK_MANAGE("clickManage"),
SHOP_CLICK_SHOP("clickShop"),
SHOP_CREATED("shopCreated"),
SHOP_CREATED_LOC("shopCreatedLoc"),
SHOP_CREATE_NO_MONEY("noMoney"),
SHOP_DELETED("shopDeleted"),
SHOP_DELETED_LOC("shopDeletedLoc"),
SHOP_FAR("outOfStockRange"),
SHOP_FIND("listFind"),
SHOP_FIND_COOLDOWN("cooldownMessageFind"),
SHOP_FIND_ERROR("findError"),
SHOP_FIND_NONE("nolistFind"),
SHOP_FOUND("foundShops"),
SHOP_IDDELETED("shopIDDeleted"),
SHOP_ID_INTEGER("shopIntegerError"),
Expand All @@ -31,7 +39,10 @@ public enum Messages {
SHOP_LIST_DISABLED("shopListDisabled"),
SHOP_LIST_OUT("listOutOfStock"),
SHOP_LOCATION("location"),
SHOP_LOCATION_ERROR_NUM("shopLocationErrorNum"),
SHOP_LOCATION_ERROR_WORLD("shopLocationErrorWorld"),
SHOP_MAX("shopLimit"),
SHOP_MOVED("shopMoved"),
SHOP_NOT_FOUND("noShopFound"),
SHOP_NOT_OUT("notOutOfStock"),
SHOP_NO_ADMINSHOPS_FOUND("noAdminShopsFound"),
Expand All @@ -44,9 +55,12 @@ public enum Messages {
SHOP_NUMBER("shopNumber"),
SHOP_OUT("outOfStock"),
SHOP_PAGE("page"),
SHOP_PAGE_SKIPAHEAD("pageSkipAhead"),
SHOP_PAGE_SKIPPREV("pageSkipPrev"),
SHOP_PURCHASE("buy"),
SHOP_RELOAD("reload"),
SHOP_REMOTE("noRemoteManage"),
SHOP_REMOVED_ALL_PLAYER("removedAllPlayer"),
SHOP_SELL("sell"),
SHOP_TITLE_ADMIN_SHOP("adminShop"),
SHOP_TITLE_BROADCAST_OFF("broadcastOff"),
Expand Down
10 changes: 9 additions & 1 deletion src/com/minedhype/ishop/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

public enum Permission {
SHOP_ADMIN("ishop.admin"),
SHOP_BYPASS_FIND_CD("ishop.bypassfindcooldown"),
SHOP_CREATE("ishop.create"),
SHOP_FIND("ishop.find"),
SHOP_LIMIT_BYPASS("ishop.create.limit.bypass"),
SHOP_LIMIT_PREFIX("ishop.create.limit."),
SHOP_STOCK("ishop.stock");
SHOP_LIST("ishop.list"),
SHOP_MOVE("ishop.move"),
SHOP_REMOTEMANAGE("ishop.remotemanage"),
SHOP_REMOTESHOPPING("ishop.remoteshopping"),
SHOP_SHOPS("ishop.shops"),
SHOP_STOCK("ishop.stock"),
SHOP_STOCK_PREFIX("ishop.pages.");

private final String perm;
Permission(String perms) {
Expand Down
74 changes: 36 additions & 38 deletions src/com/minedhype/ishop/RowStore.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.minedhype.ishop;

import java.sql.PreparedStatement;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class RowStore {
Expand All @@ -24,47 +25,36 @@ public RowStore(ItemStack itemOut, ItemStack itemOut2, ItemStack itemIn, ItemSta
public void saveData(int idTienda) {
PreparedStatement stmt = null;
try {
stmt = iShop.getConnection().prepareStatement("INSERT INTO zooMercaTiendasFilas (itemIn, itemIn2, itemOut, itemOut2, idTienda, broadcast) VALUES (?,?,?,?,?,?);");
YamlConfiguration configIn1 = new YamlConfiguration();
stmt = iShop.getConnection().prepareStatement("INSERT INTO zooMercaTiendasFilas (itemInNew, itemIn2New, itemOutNew, itemOut2New, idTienda, broadcast) VALUES (?,?,?,?,?,?);");
ItemStack[] saveAirItem = new ItemStack[]{airItem};
final Inventory invIn = Bukkit.createInventory(null,9);
final Inventory invIn2 = Bukkit.createInventory(null,9);
final Inventory invOut = Bukkit.createInventory(null,9);
final Inventory invOut2 = Bukkit.createInventory(null,9);
if(itemIn != null) {
itemIn.serialize().forEach(configIn1::set);
String itemInRaw = configIn1.saveToString();
stmt.setString(1, itemInRaw);
} else {
airItem.serialize().forEach(configIn1::set);
String itemInRaw = configIn1.saveToString();
stmt.setString(1, itemInRaw);
}
YamlConfiguration configIn2 = new YamlConfiguration();
ItemStack[] item = new ItemStack[]{itemIn};
invIn.addItem(item[0]);
} else
invIn.addItem(saveAirItem[0]);
stmt.setBytes(1, iShop.encodeByte(invIn.getContents()));
if(itemIn2 != null) {
itemIn2.serialize().forEach(configIn2::set);
String itemIn2Raw = configIn2.saveToString();
stmt.setString(2, itemIn2Raw);
} else {
airItem.serialize().forEach(configIn2::set);
String itemIn2Raw = configIn2.saveToString();
stmt.setString(2, itemIn2Raw);
}
YamlConfiguration configOut1 = new YamlConfiguration();
ItemStack[] item = new ItemStack[]{itemIn2};
invIn2.addItem(item[0]);
} else
invIn2.addItem(saveAirItem[0]);
stmt.setBytes(2, iShop.encodeByte(invIn2.getContents()));
if(itemOut != null) {
itemOut.serialize().forEach(configOut1::set);
String itemOutRaw = configOut1.saveToString();
stmt.setString(3, itemOutRaw);
} else {
airItem.serialize().forEach(configOut1::set);
String itemOutRaw = configOut1.saveToString();
stmt.setString(3, itemOutRaw);
}
YamlConfiguration configOut2 = new YamlConfiguration();
ItemStack[] item = new ItemStack[]{itemOut};
invOut.addItem(item[0]);
} else
invOut.addItem(saveAirItem[0]);
stmt.setBytes(3, iShop.encodeByte(invOut.getContents()));
if(itemOut2 != null) {
itemOut2.serialize().forEach(configOut2::set);
String itemOut2Raw = configOut2.saveToString();
stmt.setString(4, itemOut2Raw);
} else {
airItem.serialize().forEach(configOut2::set);
String itemOut2Raw = configOut2.saveToString();
stmt.setString(4, itemOut2Raw);
}
ItemStack[] item = new ItemStack[]{itemOut2};
invOut2.addItem(item[0]);
} else
invOut2.addItem(saveAirItem[0]);
stmt.setBytes(4, iShop.encodeByte(invOut2.getContents()));
stmt.setInt(5, idTienda);
stmt.setBoolean(6, broadcast);
stmt.execute();
Expand All @@ -81,15 +71,23 @@ public void toggleBroadcast() {
this.broadcast = !this.broadcast;
}
public ItemStack getItemIn() {
if(itemIn == null)
return airItem;
return itemIn;
}
public ItemStack getItemIn2() {
if(itemIn2 == null)
return airItem;
return itemIn2;
}
public ItemStack getItemOut() {
if(itemOut == null)
return airItem;
return itemOut;
}
public ItemStack getItemOut2() {
if(itemOut2 == null)
return airItem;
return itemOut2;
}
}
Loading