mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-12-29 08:08:49 +00:00
add command class...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
1babb8e362
commit
10341806f6
45
src/main/java/org/maxgamer/QuickShop/Command/CommandBuy.java
Normal file
45
src/main/java/org/maxgamer/QuickShop/Command/CommandBuy.java
Normal file
@ -0,0 +1,45 @@
|
||||
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("buy");
|
||||
this.plugin = plugin;
|
||||
setPermission("quickshop.create.buy");
|
||||
setOnlyPlayerExecutable();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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("clean");
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
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("empty");
|
||||
this.plugin = plugin;
|
||||
setPermission("quickshop.refill");
|
||||
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"));
|
||||
return;
|
||||
} else {
|
||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
108
src/main/java/org/maxgamer/QuickShop/Command/CommandFind.java
Normal file
108
src/main/java/org/maxgamer/QuickShop/Command/CommandFind.java
Normal file
@ -0,0 +1,108 @@
|
||||
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("setowner");
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
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("clean");
|
||||
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;
|
||||
buying = selling = doubles = chunks = worlds = 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.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.double", doubles));
|
||||
sender.sendMessage(MsgUtil.p("info.canclean", nostock));
|
||||
}
|
||||
}
|
102
src/main/java/org/maxgamer/QuickShop/Command/CommandPrice.java
Normal file
102
src/main/java/org/maxgamer/QuickShop/Command/CommandPrice.java
Normal file
@ -0,0 +1,102 @@
|
||||
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("price");
|
||||
this.plugin = plugin;
|
||||
setMinimumArguments(1);
|
||||
setOnlyPlayerExecutable();
|
||||
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;
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(MsgUtil.p("no-price-given"));
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(args[1]);
|
||||
} 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(((Player) sender).getUniqueId()) || 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
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("clean");
|
||||
this.plugin = plugin;
|
||||
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 {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(MsgUtil.p("command.no-amount-given"));
|
||||
return;
|
||||
}
|
||||
int add;
|
||||
try {
|
||||
add = Integer.parseInt(args[1]);
|
||||
} 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
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");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
sender.sendMessage(MsgUtil.p("command.reloading"));
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
Bukkit.getPluginManager().enablePlugin(plugin);
|
||||
plugin.reloadConfig();
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
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 cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||
|
||||
public class CommandRemove extends BaseCommand {
|
||||
QuickShop plugin;
|
||||
|
||||
public CommandRemove(final QuickShop plugin) {
|
||||
super("remove", "delete");
|
||||
this.plugin = plugin;
|
||||
setPermission("quickshop.delete");
|
||||
setOnlyPlayerExecutable();
|
||||
}
|
||||
|
||||
@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 + "Success. Deleted shop.");
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "That's not your shop!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.sendMessage(ChatColor.RED + "No shop found!");
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
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("sell");
|
||||
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).getUniqueId())) {
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.maxgamer.QuickShop.Command;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
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("setowner");
|
||||
this.plugin = plugin;
|
||||
setPermission("quickshop.setowner");
|
||||
setOnlyPlayerExecutable();
|
||||
setDescription(MsgUtil.p("command.description.setowner"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(MsgUtil.p("command.no-owner-given"));
|
||||
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) {
|
||||
final OfflinePlayer p = this.plugin.getServer().getOfflinePlayer(args[1]);
|
||||
shop.setOwner(p.getName());
|
||||
shop.update();
|
||||
sender.sendMessage(MsgUtil.p("command.new-owner", this.plugin.getServer().getOfflinePlayer(shop.getOwner()).getName()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
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("unlimited");
|
||||
this.plugin = plugin;
|
||||
setOnlyPlayerExecutable();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user