Skip to content

Commit

Permalink
iShop 2.26 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Beez0r committed Jul 11, 2024
1 parent a51b6b2 commit 9ca491d
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 86 deletions.
170 changes: 170 additions & 0 deletions src/com/minedhype/ishop/CommandShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else if(args[0].equalsIgnoreCase("deletelocation") && args.length > 4) {
Bukkit.getServer().getScheduler().runTaskAsynchronously(iShop.getPlugin(), () -> deleteLocation(null, args[1], args[2], args[3], args[4]));
return true;
} else if(args[0].equalsIgnoreCase("convertdatabase")) {
Shop.convertData();
return true;
} else {
sender.sendMessage(ChatColor.GOLD + "iShop Console Commands:");
sender.sendMessage(ChatColor.GRAY + label + " createlocation <player> <x> <y> <z> <world>");
sender.sendMessage(ChatColor.GRAY + label + " convertdatabase");
sender.sendMessage(ChatColor.GRAY + label + " deletelocation <x> <y> <z> <world>");
sender.sendMessage(ChatColor.GRAY + label + " deleteid <id>");
sender.sendMessage(ChatColor.GRAY + label + " reload");
Expand All @@ -80,6 +84,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(sender instanceof ConsoleCommandSender) {
sender.sendMessage(ChatColor.GOLD + "iShop Console Commands:");
sender.sendMessage(ChatColor.GRAY + label + " createlocation <player> <x> <y> <z> <world>");
sender.sendMessage(ChatColor.GRAY + label + " convertdatabase");
sender.sendMessage(ChatColor.GRAY + label + " deletelocation <x> <y> <z> <world>");
sender.sendMessage(ChatColor.GRAY + label + " deleteid <id>");
sender.sendMessage(ChatColor.GRAY + label + " reload");
Expand All @@ -93,6 +98,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Bukkit.getServer().getScheduler().runTaskAsynchronously(iShop.getPlugin(), () -> listSubCmd(player, label));
else if(args[0].equalsIgnoreCase("adminshop"))
adminShop(player);
else if(args[0].equalsIgnoreCase("copy") && args.length >= 2)
Bukkit.getServer().getScheduler().runTaskAsynchronously(iShop.getPlugin(), () -> copyShop(player, args[1]));
else if(args[0].equalsIgnoreCase("count") && args.length >= 2)
Bukkit.getServer().getScheduler().runTaskAsynchronously(iShop.getPlugin(), () -> count(player, args[1]));
else if(args[0].equalsIgnoreCase("create"))
Expand Down Expand Up @@ -153,6 +160,7 @@ else if(args[0].equalsIgnoreCase("view") && args.length >= 2)

private void listSubCmd(Player player, String label) {
player.sendMessage(ChatColor.GOLD + "iShop Commands:");
player.sendMessage(ChatColor.GRAY + "/" + label + " copy <shop id>");
player.sendMessage(ChatColor.GRAY + "/" + label + " count <item>");
player.sendMessage(ChatColor.GRAY + "/" + label + " create");
player.sendMessage(ChatColor.GRAY + "/" + label + " delete");
Expand Down Expand Up @@ -529,6 +537,168 @@ private void createShop(Player player, String playerShop) {
} else { player.sendMessage(Messages.EXISTING_SHOP.toString()); }
}

private void copyShop(Player player, String shopId) {
if(iShop.config.getBoolean("usePermissions") && !player.hasPermission(Permission.SHOP_CREATE.toString())) {
player.sendMessage(Messages.NO_PERMISSION.toString());
return;
}
if(!iShop.config.getBoolean("enableShopBlock")) {
player.sendMessage(Messages.DISABLED_SHOP_BLOCK.toString());
return;
}
Block block = player.getTargetBlockExact(5);
if(block == null) {
player.sendMessage(Messages.TARGET_MISMATCH.toString());
return;
}
if(iShop.config.getBoolean("disableShopInWorld")) {
List<String> disabledWorldsList = iShop.config.getStringList("disabledWorldList");
for(String disabledWorlds:disabledWorldsList) {
if(disabledWorlds != null && block.getWorld().getName().equals(disabledWorlds)) {
player.sendMessage(Messages.SHOP_WORLD_DISABLED.toString());
return;
}
}
}
String shopBlock = iShop.config.getString("shopBlock");
Material match = Material.matchMaterial(shopBlock);
if(match == null) {
try {
match = Material.matchMaterial(shopBlock.split("minecraft:")[1].toUpperCase());
} catch(Exception ignored) { }
if(match == null)
match = Material.BARREL;
}
if(!EventShop.multipleShopBlocks) {
if(!block.getType().equals(match)) {
player.sendMessage(Messages.TARGET_MISMATCH.toString());
return;
}
} else {
boolean shopMatch = false;
for(String shopBlocks:EventShop.multipleShopBlock) {
Material shopListBlocks = Material.matchMaterial(shopBlocks);
if(shopListBlocks != null && block.getType().equals(shopListBlocks)) {
shopMatch = true;
break;
}
}
if(!block.getType().equals(match) && !shopMatch) {
player.sendMessage(Messages.TARGET_MISMATCH.toString());
return;
}
}
boolean isShopLoc;
if(iShop.wgLoader != null)
isShopLoc = iShop.wgLoader.checkRegion(block);
else
isShopLoc = true;
if(!isShopLoc) {
player.sendMessage(Messages.WG_REGION.toString());
return;
}
boolean allowShopCreateInClaim = false;
if(iShop.gpLoader != null) {
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(block.getLocation(), false, false, null);
if(claim == null || claim.checkPermission(player, ClaimPermission.Access, null) == null || claim.checkPermission(player, ClaimPermission.Build, null) == null || claim.checkPermission(player, ClaimPermission.Edit, null) == null || claim.checkPermission(player, ClaimPermission.Manage, null) == null || claim.checkPermission(player, ClaimPermission.Inventory, null) == null)
allowShopCreateInClaim = true;
}
else
allowShopCreateInClaim = true;
if(!allowShopCreateInClaim) {
player.sendMessage(Messages.GP_CLAIM.toString());
return;
}
boolean allowShopCreateWithinLands = false;
if(iShop.lands != null) {
LandWorld world = iShop.lands.getWorld(player.getWorld());
if(world != null)
if(world.hasRoleFlag(player.getUniqueId(), block.getLocation(), Flags.BLOCK_PLACE))
allowShopCreateWithinLands = true;
}
else
allowShopCreateWithinLands = true;
if(!allowShopCreateWithinLands) {
player.sendMessage(Messages.NO_SHOP_CREATE_PERMISSION.toString());
return;
}
if(iShop.superiorSkyblock2Check) {
Island island = SuperiorSkyblockAPI.getIslandAt(block.getLocation());
if(island != null) {
IslandPrivilege islandPrivilege = IslandPrivilege.getByName("Build");
SuperiorPlayer superiorPlayer = SuperiorSkyblockAPI.getPlayer(player.getUniqueId());
if(!island.hasPermission(superiorPlayer, islandPrivilege)) {
player.sendMessage(Messages.NO_SHOP_CREATE_PERMISSION.toString());
return;
}
}
}
if(iShop.townyCheck) {
if(!ShopPlotUtil.doesPlayerHaveAbilityToEditShopPlot(player, block.getLocation())) {
player.sendMessage(Messages.NO_SHOP_CREATE_PERMISSION.toString());
return;
}
}
Optional<Shop> shop = Shop.getShopByLocation(block.getLocation());
if(shop.isPresent()) {
player.sendMessage(Messages.EXISTING_SHOP.toString());
return;
}
boolean limitShops;
int numShops = Shop.getNumShops(player.getUniqueId());
if(iShop.config.getBoolean("usePermissions")) {
int maxShops = 0;
String permPrefix = Permission.SHOP_LIMIT_PREFIX.toString();
for(PermissionAttachmentInfo attInfo : player.getEffectivePermissions()) {
String perm = attInfo.getPermission();
if(perm.startsWith(permPrefix)) {
int num;
try {
num = Integer.parseInt(perm.substring(perm.lastIndexOf(".")+1));
} catch(Exception e) { num = 0; }
if(num > maxShops)
maxShops = num;
}
}
limitShops = numShops >= maxShops;
}
else {
int numConfig = iShop.config.getInt("defaultShopLimit");
limitShops = numShops >= numConfig && numConfig >= 0;
}
if(player.hasPermission(Permission.SHOP_LIMIT_BYPASS.toString()))
limitShops = false;
if(limitShops) {
player.sendMessage(Messages.SHOP_MAX.toString());
return;
}
double cost = iShop.config.getDouble("createCost");
Optional<Economy> economy = iShop.getEconomy();
if(cost > 0 && economy.isPresent()) {
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(player.getUniqueId());
EconomyResponse res = economy.get().withdrawPlayer(offPlayer, cost);
if(!res.transactionSuccess()) {
player.sendMessage(Messages.SHOP_CREATE_NO_MONEY.toString()+cost);
return;
}
}
int shopNumber = Integer.parseInt(shopId);
Optional<Shop> copyShop = Shop.getShopById(shopNumber);
if(!copyShop.isPresent()) {
player.sendMessage(Messages.SHOP_NOT_FOUND.toString());
return;
}
Optional<Shop> shopCopy = Shop.getShopByLocation(block.getLocation());
if(!shopCopy.isPresent()) {
Shop.duplicateShop(block.getLocation(),player.getUniqueId(), shopNumber);
player.sendMessage(Messages.SHOP_CREATED.toString());
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(iShop.getPlugin(), () -> {
Optional<Shop> shops = Shop.getShopByLocation(block.getLocation());
Shop.shopList.put(shops.get().shopId(), player.getUniqueId());
}, 10);
} else { player.sendMessage(Messages.EXISTING_SHOP.toString()); }
}

private void createLocation(Player player, String playerShop, String x, String y, String z, String worldString) {
if(player != null && !player.hasPermission(Permission.SHOP_ADMIN.toString())) {
player.sendMessage(Messages.NO_PERMISSION.toString());
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

0 comments on commit 9ca491d

Please sign in to comment.