1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-22 01:58:54 +00:00

使用注解处理命令...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-03-03 20:56:24 +08:00
parent a8f0fe2600
commit ad95e07c94
18 changed files with 458 additions and 781 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
<description>快捷商店重置版本...</description>
<build>
<finalName>${project.name}</finalName>
@ -56,7 +56,11 @@
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<update.description>&amp;a全新版本 &amp;c虚拟悬浮物(橙子提供 对 就是那个汉化COI的逗比) &amp;e7老板修复逗比BUG...</update.description>
<update.changes>&amp;b1.8.3 - &amp;c修复漏斗传输NPE错误...;&amp;b1.8.2 - &amp;c修复箱子的标题为Null是产生的报错...;&amp;b1.8.1 - &amp;c修复PlayerInteractEvent错误参数导致GuiShopManager的报错...;
<update.changes>
&amp;b1.8.4 - &amp;c清理多余的监听事件...;
&amp;b1.8.3 - &amp;c修复漏斗传输NPE错误...;
&amp;b1.8.2 - &amp;c修复箱子的标题为Null是产生的报错...;
&amp;b1.8.1 - &amp;c修复PlayerInteractEvent错误参数导致GuiShopManager的报错...;
</update.changes>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -1,45 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandBuy extends BaseCommand {
QuickShop plugin;
public CommandBuy(final QuickShop plugin) {
super("b");
this.plugin = plugin;
setOnlyPlayerExecutable();
setPermission("quickshop.create.buy");
setDescription(MsgUtil.p("command.description.buy"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final BlockIterator bIt = new BlockIterator((Player) 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())) {
shop.setShopType(ShopType.BUYING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-buying", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,49 +0,0 @@
package org.maxgamer.QuickShop.Command;
import java.util.Iterator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandClean extends BaseCommand {
QuickShop plugin;
public CommandClean(final QuickShop plugin) {
super("c");
this.plugin = plugin;
setPermission("quickshop.clean");
setDescription(MsgUtil.p("command.description.clean"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage(MsgUtil.p("command.cleaning"));
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
int i = 0;
while (shIt.hasNext()) {
final Shop shop = shIt.next();
try {
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
continue;
}
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
i++;
}
} catch (final IllegalStateException e) {
// shIt.remove(); // The shop is not there anymore, remove it
}
}
MsgUtil.clean();
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
return;
}
}

View File

@ -1,46 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandEmpty extends BaseCommand {
QuickShop plugin;
public CommandEmpty(final QuickShop plugin) {
super("e");
this.plugin = plugin;
setPermission("quickshop.empty");
setDescription(MsgUtil.p("command.description.empty"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
cs.getInventory().clear();
sender.sendMessage(MsgUtil.p("empty-success"));
} else {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,79 +0,0 @@
package org.maxgamer.QuickShop.Command;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
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.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandExport extends BaseCommand {
QuickShop plugin;
public CommandExport(final QuickShop plugin) {
super("export");
this.plugin = plugin;
setPermission("quickshop.export");
setMinimumArguments(1);
setPossibleArguments("[mysql|sqlite]");
setDescription(MsgUtil.p("command.description.export"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String type = args[0].toLowerCase();
if (type.startsWith("mysql")) {
if (plugin.getDB().getCore() instanceof MySQLCore) {
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
return;
}
final ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
final String host = cfg.getString("host");
final String port = cfg.getString("port");
final String user = cfg.getString("user");
final String pass = cfg.getString("password");
final String name = cfg.getString("database");
final MySQLCore core = new MySQLCore(host, user, pass, name, port);
Database target;
try {
target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 MySQL " + user + "@" + host + "." + name);
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "导出数据到 MySQL 失败 " + user + "@" + host + "." + name + ChatColor.DARK_RED + " 由于: " + e.getMessage());
}
return;
}
if (type.startsWith("sql") || type.contains("file")) {
if (plugin.getDB().getCore() instanceof SQLiteCore) {
sender.sendMessage(ChatColor.RED + "数据已保存在 SQLite 无需转换!");
return;
}
final File file = new File(plugin.getDataFolder(), "shops.db");
if (file.exists()) {
if (file.delete() == false) {
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
}
}
final SQLiteCore core = new SQLiteCore(file);
try {
final Database target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 SQLite: " + file.toString());
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + e.getMessage());
}
return;
}
}
}

View File

@ -1,108 +0,0 @@
package org.maxgamer.QuickShop.Command;
import java.util.HashMap;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
public class CommandFind extends BaseCommand {
QuickShop plugin;
public CommandFind(final QuickShop plugin) {
super("f");
this.plugin = plugin;
setMinimumArguments(2);
setOnlyPlayerExecutable();
setPermission("quickshop.find");
setDescription(MsgUtil.p("command.description.find"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
String lookFor = StringUtil.consolidateStrings(args, 0);
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;
final int chunkRadius = (int) minDistance / 16 + 1;
Shop closest = null;
final Chunk c = loc.getChunk();
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
final Chunk d = c.getWorld().getChunkAt(x, z);
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
if (inChunk == null) {
continue;
}
for (final Shop shop : inChunk.values()) {
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
}
}
}
if (closest == null) {
sender.sendMessage(MsgUtil.p("no-nearby-shop", args[0]));
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;
}
/**
* Returns loc with modified pitch/yaw angles so it faces lookat
*
* @param loc
* The location a players head is
* @param lookat
* The location they should be looking
* @return The location the player should be facing to have their crosshairs
* on the location lookAt Kudos to bergerkiller for most of this
* function
*/
public Location lookAt(Location loc, final Location lookat) {
// Clone the loc to prevent applied changes to the input loc
loc = loc.clone();
// Values of change in distance (make it relative)
final double dx = lookat.getX() - loc.getX();
final double dy = lookat.getY() - loc.getY();
final double dz = lookat.getZ() - loc.getZ();
// Set yaw
if (dx != 0) {
// Set yaw start value based on dx
if (dx < 0) {
loc.setYaw((float) (1.5 * Math.PI));
} else {
loc.setYaw((float) (0.5 * Math.PI));
}
loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
} else if (dz < 0) {
loc.setYaw((float) Math.PI);
}
// Get the distance from dx/dz
final double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
final float pitch = (float) -Math.atan(dy / dxz);
// Set values, convert to degrees
// Minecraft yaw (vertical) angles are inverted (negative)
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
// But pitch angles are normal
loc.setPitch(pitch * 180f / (float) Math.PI);
return loc;
}
}

View File

@ -1,62 +0,0 @@
package org.maxgamer.QuickShop.Command;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
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.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandInfo extends BaseCommand {
QuickShop plugin;
public CommandInfo(final QuickShop plugin) {
super("i");
this.plugin = plugin;
setPermission("quickshop.info");
setDescription(MsgUtil.p("command.description.info"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
int buying, selling, doubles, chunks, worlds, unlimited;
buying = selling = doubles = chunks = worlds = unlimited = 0;
int nostock = 0;
sender.sendMessage(ChatColor.RED + "开始检索商店信息中...");
for (final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
worlds++;
for (final HashMap<Location, Shop> inChunk : inWorld.values()) {
chunks++;
for (final Shop shop : inChunk.values()) {
if (shop.isUnlimited()) {
unlimited++;
}
if (shop.isBuying()) {
buying++;
} else if (shop.isSelling()) {
selling++;
}
if (shop instanceof ContainerShop && ((ContainerShop) shop).isDoubleShop()) {
doubles++;
} else if (shop.isSelling() && shop.getRemainingStock() == 0) {
nostock++;
}
}
}
}
sender.sendMessage(MsgUtil.p("info.title", chunks, buying + selling, worlds));
sender.sendMessage(MsgUtil.p("info.selling", selling));
sender.sendMessage(MsgUtil.p("info.buying", buying));
sender.sendMessage(MsgUtil.p("info.unlimited", unlimited));
sender.sendMessage(MsgUtil.p("info.double", doubles));
sender.sendMessage(MsgUtil.p("info.canclean", nostock));
}
}

View File

@ -1,99 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandPrice extends BaseCommand {
QuickShop plugin;
public CommandPrice(final QuickShop plugin) {
super("p");
this.plugin = plugin;
setMinimumArguments(1);
setOnlyPlayerExecutable();
setPossibleArguments("<价格>");
setPermission("quickshop.create.changeprice");
setDescription(MsgUtil.p("command.description.price"));
}
@SuppressWarnings("deprecation")
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final Player p = (Player) sender;
double price;
try {
price = Double.parseDouble(args[0]);
} catch (final NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
if (price < 0.01) {
sender.sendMessage(MsgUtil.p("price-too-cheap"));
return;
}
double fee = 0;
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
fee = plugin.getConfigManager().getFeeForPriceChange();
if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
}
final BlockIterator bIt = new BlockIterator(p, 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.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)) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
}
// Update the shop
shop.setPrice(price);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
// Chest shops can be double shops.
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
final Shop nextTo = cs.getAttachedShop();
if (cs.isSelling()) {
if (cs.getPrice() < nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
} else {
// Buying
if (cs.getPrice() > nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
}
}
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,49 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandRefill extends BaseCommand {
QuickShop plugin;
public CommandRefill(final QuickShop plugin) {
super("r");
this.plugin = plugin;
setMinimumArguments(1);
setPossibleArguments("<数量>");
setPermission("quickshop.refill");
setDescription(MsgUtil.p("command.description.refill"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
int add;
try {
add = Integer.parseInt(args[0]);
} catch (final NumberFormatException e) {
sender.sendMessage(MsgUtil.p("thats-not-a-number"));
return;
}
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.add(shop.getItem(), add);
sender.sendMessage(MsgUtil.p("refill-success"));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,30 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandReload extends BaseCommand {
QuickShop plugin;
public CommandReload(final QuickShop plugin) {
super("reload");
this.plugin = plugin;
setPermission("quickshop.reload");
setDescription(MsgUtil.p("command.description.reload"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage(MsgUtil.p("command.reloading"));
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
return;
}
}

View File

@ -1,46 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandRemove extends BaseCommand {
QuickShop plugin;
public CommandRemove(final QuickShop plugin) {
super("r");
this.plugin = plugin;
setOnlyPlayerExecutable();
setPermission("quickshop.delete");
setDescription(MsgUtil.p("command.description.remove"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final Player p = (Player) sender;
final BlockIterator bIt = new BlockIterator(p, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop.getOwner().equals(p.getName())) {
shop.delete();
sender.sendMessage(ChatColor.GREEN + "商店已成功移除");
} else {
p.sendMessage(ChatColor.RED + "这个不是你的商店!");
}
return;
}
}
p.sendMessage(ChatColor.RED + "未找到商店!");
}
}

View File

@ -1,44 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandSell extends BaseCommand {
QuickShop plugin;
public CommandSell(final QuickShop plugin) {
super("s");
this.plugin = plugin;
setPermission("quickshop.create.sell");
setOnlyPlayerExecutable();
setDescription(MsgUtil.p("command.description.sell"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final BlockIterator bIt = new BlockIterator((Player) 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())) {
shop.setShopType(ShopType.SELLING);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("command.now-selling", shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,44 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandSetOwner extends BaseCommand {
QuickShop plugin;
public CommandSetOwner(final QuickShop plugin) {
super("so");
this.plugin = plugin;
setOnlyPlayerExecutable();
setMinimumArguments(1);
setPermission("quickshop.setowner");
setDescription(MsgUtil.p("command.description.setowner"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setOwner(args[0]);
shop.update();
sender.sendMessage(MsgUtil.p("command.new-owner", args[0]));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,43 +0,0 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import org.maxgamer.QuickShop.Util.MsgUtil;
import cn.citycraft.PluginHelper.commands.BaseCommand;
public class CommandUnlimited extends BaseCommand {
QuickShop plugin;
public CommandUnlimited(final QuickShop plugin) {
super("u");
this.plugin = plugin;
setOnlyPlayerExecutable();
setPermission("quickshop.unlimited");
setDescription(MsgUtil.p("command.description.unlimited"));
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setUnlimited(!shop.isUnlimited());
shop.update();
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "无限模式" : "有限模式")));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
}

View File

@ -1,39 +1,459 @@
package org.maxgamer.QuickShop.Command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
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.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 cn.citycraft.PluginHelper.commands.DefaultCommand;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.HandlerDescription;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
public class QuickShopCommands implements DefaultCommand {
HandlerSubCommand hsc;
public class QuickShopCommands implements HandlerCommands, HandlerDescription {
QuickShop plugin;
public QuickShopCommands(final QuickShop plugin) {
this.plugin = plugin;
hsc = new HandlerSubCommand(plugin, "qs");
hsc.setDefaultCommand(this);
hsc.registerCommand(new CommandClean(plugin));
hsc.registerCommand(new CommandEmpty(plugin));
hsc.registerCommand(new CommandExport(plugin));
hsc.registerCommand(new CommandFind(plugin));
hsc.registerCommand(new CommandInfo(plugin));
hsc.registerCommand(new CommandPrice(plugin));
hsc.registerCommand(new CommandRefill(plugin));
hsc.registerCommand(new CommandReload(plugin));
hsc.registerCommand(new CommandRemove(plugin));
hsc.registerCommand(new CommandBuy(plugin));
hsc.registerCommand(new CommandSetOwner(plugin));
hsc.registerCommand(new CommandSell(plugin));
hsc.registerCommand(new CommandUnlimited(plugin));
final InvokeSubCommand ics = new InvokeSubCommand(plugin, "qs");
ics.registerCommands(this);
ics.setHandlerDescription(this);
}
@HandlerCommand(name = "buy", aliases = { "b" }, permission = "quickshop.create.buy", onlyPlayerExecutable = true, description = "command.description.buy")
public void buy(final InvokeCommandEvent e) {
changeShopType(e.getSender(), ShopType.BUYING);
}
@HandlerCommand(name = "clean", aliases = "c", permission = "quickshop.clean", description = "command.description.clean")
public void clean(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
sender.sendMessage(MsgUtil.p("command.cleaning"));
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
int i = 0;
while (shIt.hasNext()) {
final Shop shop = shIt.next();
try {
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
continue;
}
shIt.remove(); // Is selling, but has no stock, and is a chest shop, but is not a double shop. Can be deleted safely.
i++;
}
} catch (final IllegalStateException ex) {
// shIt.remove(); // The shop is not there anymore, remove it
}
}
MsgUtil.clean();
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
}
@HandlerCommand(name = "empty", aliases = "e", permission = "quickshop.empty", description = "command.description.empty")
public void empty(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
cs.getInventory().clear();
sender.sendMessage(MsgUtil.p("empty-success"));
} else {
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@HandlerCommand(name = "export", minimumArguments = 1, possibleArguments = "[mysql|sqlite]", permission = "quickshop.export", description = "command.description.export")
public void export(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final String type = e.getArgs()[0].toLowerCase();
if (type.startsWith("mysql")) {
if (plugin.getDB().getCore() instanceof MySQLCore) {
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
return;
}
final ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("database");
final String host = cfg.getString("host");
final String port = cfg.getString("port");
final String user = cfg.getString("user");
final String pass = cfg.getString("password");
final String name = cfg.getString("database");
final MySQLCore core = new MySQLCore(host, user, pass, name, port);
Database target;
try {
target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 MySQL " + user + "@" + host + "." + name);
} catch (final Exception ex) {
ex.printStackTrace();
sender.sendMessage(ChatColor.RED + "导出数据到 MySQL 失败 " + user + "@" + host + "." + name + ChatColor.DARK_RED + " 由于: " + ex.getMessage());
}
return;
}
if (type.startsWith("sql") || type.contains("file")) {
if (plugin.getDB().getCore() instanceof SQLiteCore) {
sender.sendMessage(ChatColor.RED + "数据已保存在 SQLite 无需转换!");
return;
}
final File file = new File(plugin.getDataFolder(), "shops.db");
if (file.exists()) {
if (file.delete() == false) {
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
}
}
final SQLiteCore core = new SQLiteCore(file);
try {
final Database target = new Database(core);
QuickShop.instance.getDB().copyTo(target);
sender.sendMessage(ChatColor.GREEN + "导出成功 - 数据已保存至 SQLite: " + file.toString());
} catch (final Exception ex) {
ex.printStackTrace();
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + ex.getMessage());
}
return;
}
}
@HandlerCommand(name = "find", aliases = "f", minimumArguments = 2, onlyPlayerExecutable = true, permission = "quickshop.find", description = "command.description.find")
public void find(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
String lookFor = StringUtil.consolidateStrings(e.getArgs(), 0);
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;
final int chunkRadius = (int) minDistance / 16 + 1;
Shop closest = null;
final Chunk c = loc.getChunk();
for (int x = -chunkRadius + c.getX(); x < chunkRadius + c.getX(); x++) {
for (int z = -chunkRadius + c.getZ(); z < chunkRadius + c.getZ(); z++) {
final Chunk d = c.getWorld().getChunkAt(x, z);
final HashMap<Location, Shop> inChunk = plugin.getShopManager().getShops(d);
if (inChunk == null) {
continue;
}
for (final Shop shop : inChunk.values()) {
if (shop.getDataName().toLowerCase().contains(lookFor) && shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
}
}
}
if (closest == null) {
sender.sendMessage(MsgUtil.p("no-nearby-shop", e.getArgs()[0]));
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;
}
@Override
public void defaultExecute(final CommandSender sender, final Command command, final String label) throws CommandException {
hsc.sendHelp(sender, label);
public String handler(final String arg0) {
return MsgUtil.p(arg0);
}
@HandlerCommand(name = "info", aliases = "i", permission = "quickshop.info", description = "command.description.info")
public void info(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
int buying, selling, doubles, chunks, worlds, unlimited;
buying = selling = doubles = chunks = worlds = unlimited = 0;
int nostock = 0;
sender.sendMessage(ChatColor.RED + "开始检索商店信息中...");
for (final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld : plugin.getShopManager().getShops().values()) {
worlds++;
for (final HashMap<Location, Shop> inChunk : inWorld.values()) {
chunks++;
for (final Shop shop : inChunk.values()) {
if (shop.isUnlimited()) {
unlimited++;
}
if (shop.isBuying()) {
buying++;
} else if (shop.isSelling()) {
selling++;
}
if (shop instanceof ContainerShop && ((ContainerShop) shop).isDoubleShop()) {
doubles++;
} else if (shop.isSelling() && shop.getRemainingStock() == 0) {
nostock++;
}
}
}
}
sender.sendMessage(MsgUtil.p("info.title", chunks, buying + selling, worlds));
sender.sendMessage(MsgUtil.p("info.selling", selling));
sender.sendMessage(MsgUtil.p("info.buying", buying));
sender.sendMessage(MsgUtil.p("info.unlimited", unlimited));
sender.sendMessage(MsgUtil.p("info.double", doubles));
sender.sendMessage(MsgUtil.p("info.canclean", nostock));
}
@HandlerCommand(name = "price", aliases = "p", minimumArguments = 1, onlyPlayerExecutable = true, possibleArguments = "<价格>", permission = "quickshop.create.changeprice", description = "command.description.price")
public void price(final InvokeCommandEvent 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;
}
if (price < 0.01) {
sender.sendMessage(MsgUtil.p("price-too-cheap"));
return;
}
double fee = 0;
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
fee = plugin.getConfigManager().getFeeForPriceChange();
if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
}
final BlockIterator bIt = new BlockIterator(p, 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.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)) {
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
return;
}
sender.sendMessage(MsgUtil.p("fee-charged-for-price-change", plugin.getEcon().format(fee)));
plugin.getEcon().deposit(plugin.getConfig().getString("tax-account"), fee);
}
// Update the shop
shop.setPrice(price);
shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil.p("price-is-now", plugin.getEcon().format(shop.getPrice())));
// Chest shops can be double shops.
if (shop instanceof ContainerShop) {
final ContainerShop cs = (ContainerShop) shop;
if (cs.isDoubleShop()) {
final Shop nextTo = cs.getAttachedShop();
if (cs.isSelling()) {
if (cs.getPrice() < nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
} else {
// Buying
if (cs.getPrice() > nextTo.getPrice()) {
sender.sendMessage(MsgUtil.p("buying-more-than-selling"));
}
}
}
}
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@HandlerCommand(name = "refill", minimumArguments = 1, possibleArguments = "<数量>", permission = "quickshop.refill", description = "command.description.refill")
public void refill(final InvokeCommandEvent 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);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.add(shop.getItem(), add);
sender.sendMessage(MsgUtil.p("refill-success"));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@HandlerCommand(name = "reload", permission = "quickshop.reload", description = "command.description.reload")
public void reload(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
sender.sendMessage(MsgUtil.p("command.reloading"));
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
return;
}
@HandlerCommand(name = "remove", aliases = "r", onlyPlayerExecutable = true, permission = "quickshop.delete", description = "command.description.remove")
public void remove(final InvokeCommandEvent e) {
final Player p = (Player) e.getSender();
final BlockIterator bIt = new BlockIterator(p, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
if (shop.getOwner().equals(p.getName())) {
shop.delete();
p.sendMessage(ChatColor.GREEN + "商店已成功移除");
} else {
p.sendMessage(ChatColor.RED + "这个不是你的商店!");
}
return;
}
}
p.sendMessage(ChatColor.RED + "未找到商店!");
}
@HandlerCommand(name = "sell", aliases = { "s" }, permission = "quickshop.create.sell", onlyPlayerExecutable = true, description = "command.description.sell")
public void sell(final InvokeCommandEvent e) {
changeShopType(e.getSender(), ShopType.SELLING);
}
@HandlerCommand(name = "setowner", aliases = "so", onlyPlayerExecutable = true, minimumArguments = 1, permission = "quickshop.setowner", description = "command.description.setowner")
public void setowner(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final String owner = e.getArgs()[0];
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setOwner(owner);
shop.update();
sender.sendMessage(MsgUtil.p("command.new-owner", owner));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
@HandlerCommand(name = "unlimited", onlyPlayerExecutable = true, permission = "quickshop.unlimited", description = "command.description.unlimited")
public void unlimited(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
while (bIt.hasNext()) {
final Block b = bIt.next();
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
if (shop != null) {
shop.setUnlimited(!shop.isUnlimited());
shop.update();
sender.sendMessage(MsgUtil.p("command.toggle-unlimited", (shop.isUnlimited() ? "无限模式" : "有限模式")));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
return;
}
private void changeShopType(final CommandSender sender, final ShopType shopType) {
final BlockIterator bIt = new BlockIterator((Player) 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())) {
shop.setShopType(shopType);
shop.setSignText();
shop.update();
String msgtype = "";
switch (shopType) {
case BUYING:
msgtype = "command.now-buying";
break;
case SELLING:
msgtype = "command.now-selling";
break;
}
sender.sendMessage(MsgUtil.p(msgtype, shop.getDataName()));
return;
}
}
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
}
/**
* Returns loc with modified pitch/yaw angles so it faces lookat
*
* @param loc
* The location a players head is
* @param lookat
* The location they should be looking
* @return The location the player should be facing to have their crosshairs
* on the location lookAt Kudos to bergerkiller for most of this
* function
*/
private Location lookAt(Location loc, final Location lookat) {
// Clone the loc to prevent applied changes to the input loc
loc = loc.clone();
// Values of change in distance (make it relative)
final double dx = lookat.getX() - loc.getX();
final double dy = lookat.getY() - loc.getY();
final double dz = lookat.getZ() - loc.getZ();
// Set yaw
if (dx != 0) {
// Set yaw start value based on dx
if (dx < 0) {
loc.setYaw((float) (1.5 * Math.PI));
} else {
loc.setYaw((float) (0.5 * Math.PI));
}
loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
} else if (dz < 0) {
loc.setYaw((float) Math.PI);
}
// Get the distance from dx/dz
final double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
final float pitch = (float) -Math.atan(dy / dxz);
// Set values, convert to degrees
// Minecraft yaw (vertical) angles are inverted (negative)
loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI + 360);
// But pitch angles are normal
loc.setPitch(pitch * 180f / (float) Math.PI);
return loc;
}
}

View File

@ -16,7 +16,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockIterator;
@ -75,7 +74,12 @@ public class PlayerListener implements Listener {
return;
}
// Handles creating shops
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE
else if (shop == null
&& item != null
&& item.getType() != Material.AIR
&& p.hasPermission("quickshop.create.sell")
&& Util.canBeShop(b)
&& p.getGameMode() != GameMode.CREATIVE
&& (plugin.getConfigManager().isSneakCreate() == p.isSneaking())) {
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
// As of the new checking system, most plugins will tell the
@ -192,10 +196,4 @@ public class PlayerListener implements Listener {
}
}
}
@EventHandler(ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
final PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
onMove(me);
}
}

View File

@ -285,15 +285,14 @@ public class QuickShop extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
if (loadEcon() == false) {
return;
}
configManager = new ConfigManager(this);
LocalUtil.init(this);
// Initialize Util
Util.initialize();
// Create the shop manager.
configManager = new ConfigManager(this);
shopManager = new ShopManager(this);
if (configManager.isLogAction()) {
// Logger Handler
@ -307,7 +306,7 @@ public class QuickShop extends JavaPlugin {
try {
final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database");
DatabaseCore dbCore;
if (dbCfg.getBoolean("mysql")) {
if (dbCfg != null && dbCfg.getBoolean("mysql")) {
getLogger().info("启用MySQL 开始连接数据库...");
// MySQL database - Required database be created first.
final String user = dbCfg.getString("user");
@ -371,6 +370,7 @@ public class QuickShop extends JavaPlugin {
@Override
public void onLoad() {
instance = this;
config = new FileConfig(this);
MsgUtil.init(this);
}

View File

@ -218,7 +218,6 @@ public class Util {
blacklist.clear();
shoppables.clear();
transparent.clear();
plugin = QuickShop.instance;
for (final String s : plugin.getConfig().getStringList("shop-blocks")) {
Material mat = Material.getMaterial(s.toUpperCase());