mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-26 04:12:22 +00:00
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:
parent
f9f5068f6d
commit
ddebe5c594
@ -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.
|
# 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"
|
disabled: "&7Disabled&e"
|
||||||
|
|
||||||
# Set the infinite message the player gets after entering '/shop info' ...
|
# Set the type message the player gets after entering '/shop info' ...
|
||||||
# ... when the shop is infinite.
|
|
||||||
is-infinite: "&6Type: &eInfinite"
|
|
||||||
|
|
||||||
# ... when the shop is normal.
|
# ... when the shop is normal.
|
||||||
is-normal: "&6Type: &eNormal"
|
is-normal: "&6Type: &eNormal"
|
||||||
|
|
||||||
@ -298,9 +295,6 @@ messages:
|
|||||||
# Set the message when a not permitted player tries to create a shop.
|
# Set the message when a not permitted player tries to create a shop.
|
||||||
create: "&cYou don't have permission 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.
|
# 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."
|
create-admin: "&cYou don't have permission to create an admin shop."
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ permissions:
|
|||||||
description: Gives access to all ShopChest permissions.
|
description: Gives access to all ShopChest permissions.
|
||||||
children:
|
children:
|
||||||
shopchest.create: true
|
shopchest.create: true
|
||||||
shopchest.create.infinite: true
|
|
||||||
shopchest.removeOther: true
|
shopchest.removeOther: true
|
||||||
shopchest.buy: true
|
shopchest.buy: true
|
||||||
shopchest.openOther: true
|
shopchest.openOther: true
|
||||||
@ -25,11 +24,6 @@ permissions:
|
|||||||
shopchest.create:
|
shopchest.create:
|
||||||
description: Allows you to create a shop.
|
description: Allows you to create a shop.
|
||||||
default: true
|
default: true
|
||||||
shopchest.create.infinite:
|
|
||||||
description: Allows you to create an infinite shop.
|
|
||||||
children:
|
|
||||||
shopchest.create: true
|
|
||||||
default: op
|
|
||||||
shopchest.create.admin:
|
shopchest.create.admin:
|
||||||
description: Allows you to create an admin shop.
|
description: Allows you to create an admin shop.
|
||||||
children:
|
children:
|
||||||
|
@ -57,15 +57,7 @@ public class Commands extends BukkitCommand {
|
|||||||
create(args, ShopType.NORMAL, p);
|
create(args, ShopType.NORMAL, p);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length == 5) {
|
} else if (args.length == 5) {
|
||||||
if (args[4].equalsIgnoreCase("infinite")) {
|
if (args[4].equalsIgnoreCase("normal")) {
|
||||||
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")) {
|
|
||||||
create(args, ShopType.NORMAL, p);
|
create(args, ShopType.NORMAL, p);
|
||||||
return true;
|
return true;
|
||||||
} else if (args[4].equalsIgnoreCase("admin")) {
|
} else if (args[4].equalsIgnoreCase("admin")) {
|
||||||
@ -305,7 +297,7 @@ public class Commands extends BukkitCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendBasicHelpMessage(Player player) {
|
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() + " remove - " + Config.cmdDesc_remove());
|
||||||
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
|
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " info - " + Config.cmdDesc_info());
|
||||||
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());
|
player.sendMessage(ChatColor.GREEN + "/" + Config.main_command_name() + " reload - " + Config.cmdDesc_reload());
|
||||||
|
@ -82,21 +82,6 @@ public class ShopChest extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
Graph shopType = metrics.createGraph("Shop Type");
|
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") {
|
shopType.addPlotter(new Plotter("Normal") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,10 +147,6 @@ public class Config {
|
|||||||
return plugin.getConfig().getString("messages.command-description.limits").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
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() {
|
public static String shopInfo_isNormal() {
|
||||||
return plugin.getConfig().getString("messages.shop-info.is-normal").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
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");
|
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() {
|
public static String noPermission_createAdmin() {
|
||||||
return plugin.getConfig().getString("messages.no-permission.create-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
return plugin.getConfig().getString("messages.no-permission.create-admin").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
|
||||||
}
|
}
|
||||||
|
@ -155,13 +155,7 @@ public class InteractShop implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
if (shop.getBuyPrice() > 0) {
|
if (shop.getBuyPrice() > 0) {
|
||||||
if (perm.has(p, "shopchest.buy")) {
|
if (perm.has(p, "shopchest.buy")) {
|
||||||
if (shop.getShopType() == ShopType.INFINITE) {
|
if (shop.getShopType() == ShopType.ADMIN) {
|
||||||
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
|
||||||
buy(p, shop);
|
|
||||||
} else {
|
|
||||||
e.setCancelled(false);
|
|
||||||
}
|
|
||||||
} else if (shop.getShopType() == ShopType.ADMIN) {
|
|
||||||
buy(p, shop);
|
buy(p, shop);
|
||||||
} else {
|
} else {
|
||||||
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
if (!shop.getVendor().getUniqueId().equals(p.getUniqueId())) {
|
||||||
@ -196,17 +190,7 @@ public class InteractShop implements Listener {
|
|||||||
|
|
||||||
if (shop.getSellPrice() > 0) {
|
if (shop.getSellPrice() > 0) {
|
||||||
if (perm.has(p, "shopchest.sell")) {
|
if (perm.has(p, "shopchest.sell")) {
|
||||||
if (shop.getShopType() == ShopType.INFINITE) {
|
if (shop.getShopType() == ShopType.ADMIN) {
|
||||||
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 (Utils.getAmount(p.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()) >= shop.getProduct().getAmount()) {
|
if (Utils.getAmount(p.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()) >= shop.getProduct().getAmount()) {
|
||||||
sell(p, shop);
|
sell(p, shop);
|
||||||
} else {
|
} else {
|
||||||
@ -287,7 +271,6 @@ public class InteractShop implements Listener {
|
|||||||
String stock = Config.shopInfo_stock(amount);
|
String stock = Config.shopInfo_stock(amount);
|
||||||
|
|
||||||
if (shop.getShopType() == ShopType.NORMAL) shopType = Config.shopInfo_isNormal();
|
if (shop.getShopType() == ShopType.NORMAL) shopType = Config.shopInfo_isNormal();
|
||||||
else if (shop.getShopType() == ShopType.INFINITE) shopType = Config.shopInfo_isInfinite();
|
|
||||||
else shopType = Config.shopInfo_isAdmin();
|
else shopType = Config.shopInfo_isAdmin();
|
||||||
|
|
||||||
Map<Enchantment, Integer> enchantmentMap;
|
Map<Enchantment, Integer> enchantmentMap;
|
||||||
@ -543,54 +526,6 @@ public class InteractShop implements Listener {
|
|||||||
executor.sendMessage(Config.chest_not_enough_inventory_space());
|
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) {
|
} else if (shop.getShopType() == ShopType.ADMIN) {
|
||||||
|
|
||||||
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
||||||
|
@ -207,7 +207,6 @@ public class Shop {
|
|||||||
|
|
||||||
public enum ShopType {
|
public enum ShopType {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
INFINITE,
|
|
||||||
ADMIN;
|
ADMIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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() {
|
public int getNextFreeID() {
|
||||||
for (int i = 1; i < getHighestID() + 1; i++) {
|
for (int i = 1; i < getHighestID() + 1; i++) {
|
||||||
if (getProduct(i) == null) {
|
if (getProduct(i) == null) {
|
||||||
@ -442,22 +410,10 @@ public abstract class Database {
|
|||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (rs.getInt("id") == id) {
|
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"));
|
return ShopType.valueOf(rs.getString("shoptype"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
if (ex.getMessage().equals("no such column: 'shoptype'")) {
|
|
||||||
renameColumnInfiniteToShopType();
|
|
||||||
return getShopType(id);
|
|
||||||
}
|
|
||||||
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user