Removed Infinite Shops

I don't see any sense, why infinite shops should exist. They are
basically the same as admin shops, except that money gets withdrawn from
the vendor for something he doesn't even get or money gets deposited to
the vendor for something that he sold, but didn't even have.
Also the  possibility to convert the database column 'infinite' to
'shoptype' has been removed, so server owners, who update from a version
below 1.7.1 first have to download a version below 1.8.0 to let the
resource convert the database columns.
This commit is contained in:
Eric 2016-05-29 13:41:14 +02:00
parent f9f5068f6d
commit ddebe5c594
8 changed files with 5 additions and 158 deletions

View File

@ -141,10 +141,7 @@ messages:
# If the sell price or buy price is disabled, this message will be displayed instead of the price and the currency symbol in the message above.
disabled: "&7Disabled&e"
# Set the infinite message the player gets after entering '/shop info' ...
# ... when the shop is infinite.
is-infinite: "&6Type: &eInfinite"
# Set the type message the player gets after entering '/shop info' ...
# ... when the shop is normal.
is-normal: "&6Type: &eNormal"
@ -298,9 +295,6 @@ messages:
# Set the message when a not permitted player tries to create a shop.
create: "&cYou don't have permission to create a shop."
# Set the message when a not permitted player tries to create an infinite shop.
create-infinite: "&cYou don't have permission to create an infinite shop."
# Set the message when a not permitted player tries to create an admin shop.
create-admin: "&cYou don't have permission to create an admin shop."

View File

@ -14,7 +14,6 @@ permissions:
description: Gives access to all ShopChest permissions.
children:
shopchest.create: true
shopchest.create.infinite: true
shopchest.removeOther: true
shopchest.buy: true
shopchest.openOther: true
@ -25,11 +24,6 @@ permissions:
shopchest.create:
description: Allows you to create a shop.
default: true
shopchest.create.infinite:
description: Allows you to create an infinite shop.
children:
shopchest.create: true
default: op
shopchest.create.admin:
description: Allows you to create an admin shop.
children:

View File

@ -57,15 +57,7 @@ public class Commands extends BukkitCommand {
create(args, ShopType.NORMAL, p);
return true;
} else if (args.length == 5) {
if (args[4].equalsIgnoreCase("infinite")) {
if (perm.has(p, "shopchest.create.infinite")) {
create(args, ShopType.INFINITE, p);
return true;
} else {
p.sendMessage(Config.noPermission_createInfinite());
return true;
}
} else if (args[4].equalsIgnoreCase("normal")) {
if (args[4].equalsIgnoreCase("normal")) {
create(args, ShopType.NORMAL, p);
return true;
} else if (args[4].equalsIgnoreCase("admin")) {
@ -305,7 +297,7 @@ public class Commands extends BukkitCommand {
}
private void sendBasicHelpMessage(Player player) {
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " create <amount> <buy-price> <sell-price> [infinite|normal|admin] - " + Config.cmdDesc_create());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " create <amount> <buy-price> <sell-price> [normal|admin] - " + Config.cmdDesc_create());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " remove - " + Config.cmdDesc_remove());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());

View File

@ -82,21 +82,6 @@ public class ShopChest extends JavaPlugin {
try {
Metrics metrics = new Metrics(this);
Graph shopType = metrics.createGraph("Shop Type");
shopType.addPlotter(new Plotter("Infinite") {
@Override
public int getValue() {
int value = 0;
for (Shop shop : ShopUtils.getShops()) {
if (shop.getShopType() == ShopType.INFINITE) value++;
}
return value;
}
});
shopType.addPlotter(new Plotter("Normal") {
@Override

View File

@ -147,10 +147,6 @@ public class Config {
return plugin.getConfig().getString("messages.command-description.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_isInfinite() {
return plugin.getConfig().getString("messages.shop-info.is-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String shopInfo_isNormal() {
return plugin.getConfig().getString("messages.shop-info.is-normal").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
@ -163,10 +159,6 @@ public class Config {
return plugin.getConfig().getString("messages.no-permission.create").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_createInfinite() {
return plugin.getConfig().getString("messages.no-permission.create-infinite").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}
public static String noPermission_createAdmin() {
return plugin.getConfig().getString("messages.no-permission.create-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
}

View File

@ -155,13 +155,7 @@ public class InteractShop implements Listener {
} else {
if (shop.getBuyPrice() > 0) {
if (perm.has(p, "shopchest.buy")) {
if (shop.getShopType() == ShopType.INFINITE) {
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
buy(p, shop);
} else {
e.setCancelled(false);
}
} else if (shop.getShopType() == ShopType.ADMIN) {
if (shop.getShopType() == ShopType.ADMIN) {
buy(p, shop);
} else {
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
@ -196,17 +190,7 @@ public class InteractShop implements Listener {
if (shop.getSellPrice() > 0) {
if (perm.has(p, "shopchest.sell")) {
if (shop.getShopType() == ShopType.INFINITE) {
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
if (Utils.getAmount(p.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()) >= shop.getProduct().getAmount()) {
sell(p, shop);
} else {
p.sendMessage(Config.not_enough_items());
}
} else {
e.setCancelled(false);
}
} else if (shop.getShopType() == ShopType.ADMIN) {
if (shop.getShopType() == ShopType.ADMIN) {
if (Utils.getAmount(p.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()) >= shop.getProduct().getAmount()) {
sell(p, shop);
} else {
@ -287,7 +271,6 @@ public class InteractShop implements Listener {
String stock = Config.shopInfo_stock(amount);
if (shop.getShopType() == ShopType.NORMAL) shopType = Config.shopInfo_isNormal();
else if (shop.getShopType() == ShopType.INFINITE) shopType = Config.shopInfo_isInfinite();
else shopType = Config.shopInfo_isAdmin();
Map<Enchantment, Integer> enchantmentMap;
@ -543,54 +526,6 @@ public class InteractShop implements Listener {
executor.sendMessage(Config.chest_not_enough_inventory_space());
}
} else if (shop.getShopType() == ShopType.INFINITE) {
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
EconomyResponse r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
if (r.transactionSuccess()) {
if (r2.transactionSuccess()) {
for (int i = leftAmount; i > 0; i--) {
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
soldProduct.setItemMeta(product.clone().getItemMeta());
if (Utils.getVersion(Bukkit.getServer()).contains("1_9")) {
if (executor.getInventory().getItem(40) != null) {
ItemStack is = executor.getInventory().getItem(40);
if (is.getType().equals(shop.getProduct().getType()) && is.getDurability() == shop.getProduct().getDurability() && is.getData().equals(shop.getProduct().getData()) && is.getItemMeta().equals(shop.getProduct().getItemMeta())) {
ItemStack isNew = new ItemStack(is);
int amount = is.getAmount();
isNew.setAmount(amount - 1);
if (amount <= 1) {
executor.getInventory().setItem(40, null);
} else {
executor.getInventory().setItem(40, isNew);
}
}
} else {
executor.getInventory().removeItem(soldProduct);
}
} else {
executor.getInventory().removeItem(soldProduct);
}
executor.updateInventory();
}
executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName()));
if (shop.getVendor().isOnline())
shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName()));
} else {
executor.sendMessage(Config.error_occurred(r2.errorMessage));
}
} else {
executor.sendMessage(Config.error_occurred(r.errorMessage));
}
} else {
executor.sendMessage(Config.vendor_not_enough_money());
}
} else if (shop.getShopType() == ShopType.ADMIN) {
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());

View File

@ -207,7 +207,6 @@ public class Shop {
public enum ShopType {
NORMAL,
INFINITE,
ADMIN;
}

View File

@ -62,38 +62,6 @@ public abstract class Database {
}
}
public void renameColumnInfiniteToShopType() {
Connection conn = null;
Statement s = null;
try {
conn = getSQLConnection();
s = conn.createStatement();
s.execute("ALTER TABLE " + table + " RENAME TO " + table + "_old");
s.close();
s.execute(SQLiteCreateTokensTable);
s.close();
s.execute("INSERT INTO " + table + "(id, vendor, product, world, x, y, z, buyprice, sellprice, shoptype) SELECT id, vendor, product, world, x, y, z, buyprice, sellprice, infinite FROM " + table + "_old");
s.close();
conn.close();
conn = getSQLConnection();
s = conn.createStatement();
s.execute("DROP TABLE " + table + "_old");
s.close();
} catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally {
try {
if (s != null)
s.close();
if (conn != null)
conn.close();
} catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
}
}
}
public int getNextFreeID() {
for (int i = 1; i < getHighestID() + 1; i++) {
if (getProduct(i) == null) {
@ -442,22 +410,10 @@ public abstract class Database {
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("id") == id) {
if (rs.getString("shoptype").equals("0") || rs.getString("shoptype").equals("1")) {
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '0', 'NORMAL')");
ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("UPDATE " + table + " SET shoptype = REPLACE(shoptype, '1', 'INFINITE')");
ps.executeUpdate();
return getShopType(id);
}
return ShopType.valueOf(rs.getString("shoptype"));
}
}
} catch (SQLException ex) {
if (ex.getMessage().equals("no such column: 'shoptype'")) {
renameColumnInfiniteToShopType();
return getShopType(id);
}
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally {
try {