1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-12-27 07:48:48 +00:00

feat: 添加阻止世界创建商店 重构命令

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-11-11 16:10:00 +08:00
parent 00f6466061
commit 16571a6035
7 changed files with 119 additions and 189 deletions

19
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId>
<version>1.9.4</version>
<version>1.9.5</version>
<description>快捷商店重置版本...</description>
<build>
<finalName>${project.name}</finalName>
@ -58,11 +58,11 @@
</ciManagement>
<properties>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<update.description>&amp;a全新版本 &amp;c虚拟悬浮物(橙子提供 对 就是那个汉化COI的逗比)&amp;e7老板修复逗比BUG...</update.description>
<update.description>§a全新版本 §c虚拟悬浮物(橙子提供 对 就是那个汉化COI的逗比)§e7老板修复逗比BUG...</update.description>
<update.changes>
&amp;b1.9.4 - &amp;a1.9+兼容虚拟悬浮物...;
&amp;b1.9.3 - &amp;a木牌第一行显示配置文件的guititle内容...;
&amp;b1.9.2 - &amp;c修复一个在删除商店时导致的报错...;
§b1.9.5 - §a1.10+兼容虚拟悬浮物...;
§b1.9.4 - §a1.9+兼容虚拟悬浮物...;
§b1.9.3 - §a木牌第一行显示配置文件的guititle内容...;
</update.changes>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -96,7 +96,7 @@
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<type>jar</type>
<version>1.0</version>
<version>1.1</version>
</dependency>
<dependency>
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
@ -110,13 +110,6 @@
<scope>system</scope>
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.6.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolLib-3.6.5.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>

View File

@ -1,9 +1,5 @@
package org.maxgamer.QuickShop.Command;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -14,25 +10,26 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Database.Database;
import org.maxgamer.QuickShop.Database.MySQLCore;
import org.maxgamer.QuickShop.Database.SQLiteCore;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopChunk;
import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.commands.CommandArgument;
import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandHelpParse;
import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.kit.StrKit;
import pw.yumc.YumCore.commands.interfaces.CommandExecutor;
import pw.yumc.YumCore.commands.interfaces.CommandHelpParse;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
QuickShop plugin = P.getPlugin();
@ -43,14 +40,13 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
@Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER)
@Help("command.description.buy")
public void buy(final CommandArgument e) {
changeShopType(e.getSender(), ShopType.BUYING);
public void buy(Player player) {
changeShopType(player, ShopType.BUYING);
}
@Cmd(aliases = "c", permission = "quickshop.clean")
@Help("command.description.clean")
public void clean(final CommandArgument e) {
final CommandSender sender = e.getSender();
public void clean(CommandSender sender) {
sender.sendMessage(MsgUtil.p("command.cleaning"));
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
int i = 0;
@ -73,11 +69,10 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
}
@Cmd(aliases = "e", permission = "quickshop.empty")
@Cmd(aliases = "e", permission = "quickshop.empty", executor = Executor.PLAYER)
@Help("command.description.empty")
public void empty(final CommandArgument e) {
final CommandSender sender = e.getSender();
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
public void empty(Player player) {
final BlockIterator bIt = new BlockIterator(player, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
@ -85,22 +80,19 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
cs.getInventory().clear();
sender.sendMessage(MsgUtil.p("empty-success"));
player.sendMessage(MsgUtil.p("empty-success"));
} else {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
player.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
player.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
@Cmd(minimumArguments = 1, permission = "quickshop.export")
@Help(value = "command.description.export", possibleArguments = "[mysql|sqlite]")
public void export(final CommandArgument e) {
final CommandSender sender = e.getSender();
final String type = e.getArgs()[0].toLowerCase();
public void export(CommandSender sender, String type) {
if (type.startsWith("mysql")) {
if (plugin.getDB().getCore() instanceof MySQLCore) {
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
@ -130,10 +122,8 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
return;
}
final File file = new File(plugin.getDataFolder(), "shops.db");
if (file.exists()) {
if (file.delete() == false) {
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
}
if (file.exists() && !file.delete()) {
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
}
final SQLiteCore core = new SQLiteCore(file);
try {
@ -144,17 +134,13 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
ex.printStackTrace();
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + ex.getMessage());
}
return;
}
}
@Cmd(aliases = "f", minimumArguments = 2, permission = "quickshop.find", executor = Executor.PLAYER)
@Help("command.description.find")
public void find(final CommandArgument e) {
final CommandSender sender = e.getSender();
String lookFor = StrKit.consolidateStrings(e.getArgs(), 0);
public void find(Player p, String lookFor) {
lookFor = lookFor.toLowerCase();
final Player p = (Player) sender;
final Location loc = p.getEyeLocation().clone();
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
double minDistanceSquared = minDistance * minDistance;
@ -177,20 +163,18 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
}
}
if (closest == null) {
sender.sendMessage(MsgUtil.p("no-nearby-shop", e.getArgs()[0]));
p.sendMessage(MsgUtil.p("no-nearby-shop", lookFor));
return;
}
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
// Hack fix to make /qs find not used by /back
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.PLUGIN);
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
return;
}
@Cmd(aliases = "i", permission = "quickshop.info")
@Help("command.description.info")
public void info(final CommandArgument e) {
final CommandSender sender = e.getSender();
public void info(CommandSender sender) {
int buying, selling, doubles, chunks, worlds, unlimited;
buying = selling = doubles = chunks = worlds = unlimited = 0;
int nostock = 0;
@ -229,18 +213,9 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
return MsgUtil.p(str);
}
@Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice")
@Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Executor.PLAYER)
@Help(value = "command.description.price", possibleArguments = "<价格>")
public void price(final CommandArgument e) {
final CommandSender sender = e.getSender();
final Player p = (Player) sender;
double price;
try {
price = Double.parseDouble(e.getArgs()[0]);
} catch (final NumberFormatException ex) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
public void price(Player sender, Double price) {
if (price < 0.01) {
sender.sendMessage(MsgUtil.p("price-too-cheap"));
return;
@ -248,24 +223,24 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
double fee = 0;
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
fee = plugin.getConfigManager().getFeeForPriceChange();
if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) {
if (fee > 0 && plugin.getEcon().getBalance(sender.getName()) < fee) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
}
final BlockIterator bIt = new BlockIterator(p, 10);
final BlockIterator bIt = new BlockIterator(sender, 10);
// Loop through every block they're looking at upto 10 blocks away
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && (shop.getOwner().equals(p.getName()) || sender.hasPermission("quickshop.other.price"))) {
if (shop != null && (shop.getOwner().equals(sender.getName()) || sender.hasPermission("quickshop.other.price"))) {
if (shop.getPrice() == price) {
// Stop here if there isn't a price change
sender.sendMessage(MsgUtil.p("no-price-change"));
return;
}
if (fee > 0) {
if (!plugin.getEcon().withdraw(p.getName(), fee)) {
if (!plugin.getEcon().withdraw(sender.getName(), fee)) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
@ -298,21 +273,12 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER)
@Help(value = "command.description.refill", possibleArguments = "<数量>")
public void refill(final CommandArgument e) {
final CommandSender sender = e.getSender();
int add;
try {
add = Integer.parseInt(e.getArgs()[0]);
} catch (final NumberFormatException ex) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
public void refill(Player sender, Integer add) {
final BlockIterator bIt = new BlockIterator(sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
@ -323,13 +289,11 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@Cmd(permission = "quickshop.reload")
@Help("command.description.reload")
public void reload(final CommandArgument e) {
final CommandSender sender = e.getSender();
public void reload(CommandSender sender) {
sender.sendMessage(MsgUtil.p("command.reloading"));
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
@ -338,8 +302,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
@Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER)
@Help("command.description.remove")
public void remove(final CommandArgument e) {
final Player p = (Player) e.getSender();
public void remove(Player p) {
final BlockIterator bIt = new BlockIterator(p, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
@ -357,17 +320,15 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
p.sendMessage(ChatColor.RED + "未找到商店!");
}
@Cmd(aliases = "s", permission = "quickshop.create.sell")
@Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Executor.PLAYER)
@Help("command.description.sell")
public void sell(final CommandArgument e) {
changeShopType(e.getSender(), ShopType.SELLING);
public void sell(Player player) {
changeShopType(player, ShopType.SELLING);
}
@Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER)
@Help("command.description.setowner")
public void setowner(final CommandArgument e) {
final CommandSender sender = e.getSender();
final String owner = e.getArgs()[0];
public void setowner(CommandSender sender, String owner) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
@ -384,9 +345,8 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
@Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER)
@Help("command.description.unlimited")
public void unlimited(final CommandArgument e) {
final CommandSender sender = e.getSender();
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
public void unlimited(Player sender) {
final BlockIterator bIt = new BlockIterator(sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
@ -400,12 +360,12 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
private void changeShopType(final CommandSender sender, final ShopType shopType) {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
private void changeShopType(final Player sender, final ShopType shopType) {
final BlockIterator bIt = new BlockIterator(sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null && shop.getOwner().equals(((Player) sender).getName())) {
if (shop != null && shop.getOwner().equals(sender.getName())) {
shop.setShopType(shopType);
shop.setSignText();
shop.update();

View File

@ -1,21 +1,17 @@
package org.maxgamer.QuickShop.Config;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.tellraw.Tellraw;
import java.util.*;
public class ConfigManager {
private boolean enableMagicLib = false;
/** Whether debug info should be shown in the console */
@ -50,7 +46,7 @@ public class ConfigManager {
private double tax = 0;
private final String taxAccount;
private boolean fakeItem = false;
private List<String> prevent;
/**
* A set of players who have been warned
* ("Your shop isn't automatically locked")
@ -70,7 +66,7 @@ public class ConfigManager {
}
try {
this.superItem = Material.valueOf(config.getString("superitem"));
} catch (final Exception e) {
} catch (final Exception ignored) {
}
this.tax = config.getDouble("tax");
this.showTax = config.getBoolean("show-tax");
@ -87,6 +83,7 @@ public class ConfigManager {
this.preventhopper = config.getBoolean("preventhopper");
this.guiTitle = config.getMessage("guititle", guiTitle);
this.warnings = Collections.emptySet();
this.prevent = config.getStringList("prevent");
if (config.getBoolean("fakeitem", true)) {
try {
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
@ -221,4 +218,11 @@ public class ConfigManager {
this.fakeItem = fakeItem;
}
public List<String> getPrevent() {
return prevent;
}
public void setPrevent(List<String> prevent) {
this.prevent = prevent;
}
}

View File

@ -18,9 +18,9 @@ public class Info {
* The location they clicked (Block.getLocation())
* @param action
* The action (ShopAction.*)
* @param material
* @param item
* The material they were holding
* @param data
* @param last
* The data value of the material
*/
public Info(Location loc, ShopAction action, ItemStack item, Block last) {
@ -38,9 +38,9 @@ public class Info {
* The location they clicked (Block.getLocation())
* @param action
* The action (ShopAction.*)
* @param material
* @param item
* The material they were holding
* @param data
* @param last
* The data value of the material
* @param shop
* The shop they interacted with, or null if none
@ -67,9 +67,7 @@ public class Info {
return true;
if (!this.shop.getLocation().equals(shop.getLocation()))
return true;
if (!this.shop.matches(shop.getItem()))
return true;
return false;
return !this.shop.matches(shop.getItem());
}
public ShopAction getAction() {

View File

@ -1,16 +1,6 @@
package org.maxgamer.QuickShop.Shop;
import java.util.HashMap;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -19,11 +9,16 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Sign;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Database.Database;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
public class ShopManager {
private final HashMap<String, Info> actions = new HashMap<>();
@ -45,6 +40,10 @@ public class ShopManager {
* @return True if they're allowed to place a shop there.
*/
public boolean canBuildShop(final Player p, final Block b, final BlockFace bf) {
if (plugin.getConfigManager().getPrevent().contains(b.getWorld().getName().toLowerCase())) {
p.sendMessage(MsgUtil.p("prevent-create"));
return false;
}
if (plugin.getConfigManager().isLimit()) {
int owned = 0;
final Iterator<Shop> it = getShopIterator();
@ -64,17 +63,12 @@ public class ShopManager {
final PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), b, bf); // PIE = PlayerInteractEvent - What else?
Bukkit.getPluginManager().callEvent(pie);
pie.getPlayer().closeInventory(); // If the player has chat open, this will close their chat.
if (pie.isCancelled()) {
return false;
}
} catch (final Exception e) {
if (pie.isCancelled()) { return false; }
} catch (final Exception ignored) {
}
final ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation());
Bukkit.getPluginManager().callEvent(spce);
if (spce.isCancelled()) {
return false;
}
return true;
return !spce.isCancelled();
}
/**
@ -106,7 +100,7 @@ public class ShopManager {
// Write it to the database
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
plugin.getDB().execute(q,
shop.getOwner().toString(),
shop.getOwner(),
shop.getPrice(),
Util.serialize(item),
loc.getBlockX(),
@ -149,9 +143,7 @@ public class ShopManager {
*/
public Shop getShop(final Location loc) {
final HashMap<Location, Shop> inChunk = getShops(loc.getChunk());
if (inChunk == null) {
return null;
}
if (inChunk == null) { return null; }
// We can do this because WorldListener updates the world reference so
// the world in loc is the same as world in inChunk.get(loc)
return inChunk.get(loc);
@ -186,11 +178,10 @@ public class ShopManager {
*/
public HashMap<Location, Shop> getShops(final Chunk c) {
// long start = System.nanoTime();
final HashMap<Location, Shop> shops = getShops(c.getWorld().getName(), c.getX(), c.getZ());
// long end = System.nanoTime();
// System.out.println("Chunk lookup in " + ((end - start)/1000000.0) +
// "ms.");
return shops;
return getShops(c.getWorld().getName(), c.getX(), c.getZ());
}
/**
@ -207,9 +198,7 @@ public class ShopManager {
public HashMap<Location, Shop> getShops(final String world, final int chunkX, final int chunkZ) {
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = this.getShops(world);
if (inWorld == null) {
return null;
}
if (inWorld == null) { return null; }
final ShopChunk shopChunk = new ShopChunk(world, chunkX, chunkZ);
return inWorld.get(shopChunk);
}
@ -219,14 +208,13 @@ public class ShopManager {
final HashMap<String, Info> actions = getActions();
// They wanted to do something.
final Info info = actions.remove(p.getName());
if (info == null) {
return; // multithreaded means this can happen
if (info == null) { return; // multithreaded means this can happen
}
/* Creation handling */
if (info.getAction() == ShopAction.CREATE) {
create(p, info, message);
} else if (/* Purchase Handling */info.getAction() == ShopAction.BUY) {
int amount = 0;
int amount;
try {
amount = Integer.parseInt(message);
} catch (final NumberFormatException e) {
@ -236,7 +224,7 @@ public class ShopManager {
// Get the shop they interacted with
final Shop shop = plugin.getShopManager().getShop(info.getLocation());
// It's not valid anymore
if (shop == null || Util.canBeShop(info.getLocation().getBlock()) == false) {
if (shop == null || !Util.canBeShop(info.getLocation().getBlock())) {
p.sendMessage(MsgUtil.p("chest-was-removed"));
return;
}
@ -250,9 +238,6 @@ public class ShopManager {
buy(p, shop, amount);
}
shop.setSignText(); // Update the signs count
} else {
/* If it was already cancelled (from destroyed) */
return; // It was cancelled, go away.
}
}
@ -333,15 +318,7 @@ public class ShopManager {
p.sendMessage(MsgUtil.p("you-dont-have-that-many-items", "" + count, shop.getDataName()));
return;
}
if (amount == 0) {
// Dumb.
MsgUtil.sendPurchaseSuccess(p, shop, amount);
return;
} else if (amount < 0) {
// & Dumber
p.sendMessage(MsgUtil.p("negative-amount"));
return;
}
if (!checkAmount(p, shop, amount)) { return; }
// Money handling
if (!p.getName().equals(shop.getOwner())) {
// Don't tax them if they're purchasing from
@ -390,7 +367,7 @@ public class ShopManager {
p.sendMessage(MsgUtil.p("no-double-chests"));
return;
}
if (Util.canBeShop(info.getLocation().getBlock()) == false) {
if (!Util.canBeShop(info.getLocation().getBlock())) {
p.sendMessage(MsgUtil.p("chest-was-removed"));
return;
}
@ -426,9 +403,7 @@ public class ShopManager {
}
final ShopCreateEvent e = new ShopCreateEvent(shop, p);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return;
}
if (e.isCancelled()) { return; }
shop.onLoad();
/* The shop has hereforth been successfully created */
createShop(shop);
@ -460,22 +435,19 @@ public class ShopManager {
});
shop.setSignText();
}
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
final Shop nextTo = cs.getAttachedShop();
if (nextTo.getPrice() > shop.getPrice()) {
// The one next to it must always be a
// buying shop.
p.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
final Shop nextTo = cs.getAttachedShop();
if (nextTo.getPrice() > shop.getPrice()) {
// The one next to it must always be a
// buying shop.
p.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
}
}
/* They didn't enter a number. */
catch (final NumberFormatException ex) {
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
return;
}
}
@ -485,15 +457,7 @@ public class ShopManager {
p.sendMessage(MsgUtil.p("shop-stock-too-low", "" + shop.getRemainingStock(), shop.getDataName()));
return;
}
if (amount == 0) {
// Dumb.
MsgUtil.sendPurchaseSuccess(p, shop, amount);
return;
} else if (amount < 0) {
// & Dumber
p.sendMessage(MsgUtil.p("negative-amount"));
return;
}
if (!checkAmount(p, shop, amount)) { return; }
final int pSpace = Util.countSpace(p.getInventory(), shop.getItem());
if (amount > pSpace) {
p.sendMessage(MsgUtil.p("not-enough-space", "" + pSpace));
@ -501,8 +465,7 @@ public class ShopManager {
}
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
return; // Cancelled
if (e.isCancelled()) { return; // Cancelled
}
// Money handling
if (!p.getName().equals(shop.getOwner())) {
@ -548,6 +511,19 @@ public class ShopManager {
plugin.log(String.format("玩家: %s 从 %s 购买了 %s 件商品 花费 %s", p.getName(), shop.toString(), amount, shop.getPrice() * amount));
}
private boolean checkAmount(Player p, Shop shop, int amount) {
if (amount == 0) {
// Dumb.
MsgUtil.sendPurchaseSuccess(p, shop, amount);
return false;
} else if (amount < 0) {
// & Dumber
p.sendMessage(MsgUtil.p("negative-amount"));
return false;
}
return true;
}
public class ShopIterator implements Iterator<Shop> {
private Iterator<HashMap<Location, Shop>> chunks;
private Shop current;
@ -565,9 +541,7 @@ public class ShopManager {
public boolean hasNext() {
if (shops == null || !shops.hasNext()) {
if (chunks == null || !chunks.hasNext()) {
if (!worlds.hasNext()) {
return false;
}
if (!worlds.hasNext()) { return false; }
chunks = worlds.next().values().iterator();
return hasNext();
}
@ -585,15 +559,12 @@ public class ShopManager {
public Shop next() {
if (shops == null || !shops.hasNext()) {
if (chunks == null || !chunks.hasNext()) {
if (!worlds.hasNext()) {
throw new NoSuchElementException("No more shops to iterate over!");
}
if (!worlds.hasNext()) { throw new NoSuchElementException("No more shops to iterate over!"); }
chunks = worlds.next().values().iterator();
}
shops = chunks.next().values().iterator();
}
if (!shops.hasNext()) {
return this.next(); // Skip to the next one (Empty iterator?)
if (!shops.hasNext()) { return this.next(); // Skip to the next one (Empty iterator?)
}
current = shops.next();
return current;

View File

@ -1,4 +1,4 @@
Version: 1.7
Version: 1.8
#超级工具(OP可以用该工具在创造模式打破所有商店)
superitem: GOLD_AXE
@ -10,6 +10,9 @@ guititle: '&6[&b快捷商店&6]&r'
usemagiclib: true
#启用虚拟悬浮物
fakeitem: true
#禁止使用商店的世界(请全部小写)
prevent:
- 'preventworld'
#税收数量 (decimal) - 例如 税收是0.05 玩家1 在玩家2的商店 购买了 50元的东西,那么,玩家1 减少 50, 玩家2 账户增加(1-0.05)*50, 并且 玩家2税收账户增加 (0.05)*50.
tax: 0.00

View File

@ -1,4 +1,4 @@
Version: 1.5
Version: 1.6
not-looking-at-shop: '&c没找到快捷商店. 你必须看着那个商店.'
no-permission: '&4你没有此命令的权限.'
@ -39,6 +39,7 @@ buying-more-than-selling: '&4警告: 你购买的物品超出了商店的库存!
not-enough-space: '&c你没有足够的空间装 {0} !'
refill-success: '&a库存补充成功!'
empty-success: '&a商店清理成功!'
prevent-create: '&c当前世界禁止使用商店插件!'
menu:
successful-purchase: '&a商品购买成功:'