mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +00:00
feat: 添加阻止世界创建商店 重构命令
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
00f6466061
commit
16571a6035
19
pom.xml
19
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.maxgamer</groupId>
|
<groupId>org.maxgamer</groupId>
|
||||||
<artifactId>QuickShop</artifactId>
|
<artifactId>QuickShop</artifactId>
|
||||||
<version>1.9.4</version>
|
<version>1.9.5</version>
|
||||||
<description>快捷商店重置版本...</description>
|
<description>快捷商店重置版本...</description>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
@ -58,11 +58,11 @@
|
|||||||
</ciManagement>
|
</ciManagement>
|
||||||
<properties>
|
<properties>
|
||||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||||
<update.description>&a全新版本 &c虚拟悬浮物(橙子提供 对 就是那个汉化COI的逗比)&e7老板修复逗比BUG...</update.description>
|
<update.description>§a全新版本 §c虚拟悬浮物(橙子提供 对 就是那个汉化COI的逗比)§e7老板修复逗比BUG...</update.description>
|
||||||
<update.changes>
|
<update.changes>
|
||||||
&b1.9.4 - &a1.9+兼容虚拟悬浮物...;
|
§b1.9.5 - §a1.10+兼容虚拟悬浮物...;
|
||||||
&b1.9.3 - &a木牌第一行显示配置文件的guititle内容...;
|
§b1.9.4 - §a1.9+兼容虚拟悬浮物...;
|
||||||
&b1.9.2 - &c修复一个在删除商店时导致的报错...;
|
§b1.9.3 - §a木牌第一行显示配置文件的guititle内容...;
|
||||||
</update.changes>
|
</update.changes>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
@ -96,7 +96,7 @@
|
|||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>YumCore</artifactId>
|
<artifactId>YumCore</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.0</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
|
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
|
||||||
@ -110,13 +110,6 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
|
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package org.maxgamer.QuickShop.Command;
|
package org.maxgamer.QuickShop.Command;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -14,25 +10,26 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.bukkit.util.BlockIterator;
|
import org.bukkit.util.BlockIterator;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
|
||||||
import org.maxgamer.QuickShop.Database.Database;
|
import org.maxgamer.QuickShop.Database.Database;
|
||||||
import org.maxgamer.QuickShop.Database.MySQLCore;
|
import org.maxgamer.QuickShop.Database.MySQLCore;
|
||||||
import org.maxgamer.QuickShop.Database.SQLiteCore;
|
import org.maxgamer.QuickShop.Database.SQLiteCore;
|
||||||
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
||||||
import org.maxgamer.QuickShop.Shop.Shop;
|
import org.maxgamer.QuickShop.Shop.Shop;
|
||||||
import org.maxgamer.QuickShop.Shop.ShopChunk;
|
import org.maxgamer.QuickShop.Shop.ShopChunk;
|
||||||
import org.maxgamer.QuickShop.Shop.ShopType;
|
import org.maxgamer.QuickShop.Shop.ShopType;
|
||||||
import org.maxgamer.QuickShop.Util.MsgUtil;
|
import org.maxgamer.QuickShop.Util.MsgUtil;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
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.CommandManager;
|
||||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
import pw.yumc.YumCore.commands.annotation.Cmd;
|
||||||
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
|
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
|
||||||
import pw.yumc.YumCore.commands.annotation.Help;
|
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 {
|
public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
||||||
QuickShop plugin = P.getPlugin();
|
QuickShop plugin = P.getPlugin();
|
||||||
@ -43,14 +40,13 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
|
|
||||||
@Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER)
|
@Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER)
|
||||||
@Help("command.description.buy")
|
@Help("command.description.buy")
|
||||||
public void buy(final CommandArgument e) {
|
public void buy(Player player) {
|
||||||
changeShopType(e.getSender(), ShopType.BUYING);
|
changeShopType(player, ShopType.BUYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(aliases = "c", permission = "quickshop.clean")
|
@Cmd(aliases = "c", permission = "quickshop.clean")
|
||||||
@Help("command.description.clean")
|
@Help("command.description.clean")
|
||||||
public void clean(final CommandArgument e) {
|
public void clean(CommandSender sender) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
sender.sendMessage(MsgUtil.p("command.cleaning"));
|
sender.sendMessage(MsgUtil.p("command.cleaning"));
|
||||||
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
|
final Iterator<Shop> shIt = plugin.getShopManager().getShopIterator();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -73,11 +69,10 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
sender.sendMessage(MsgUtil.p("command.cleaned", "" + i));
|
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")
|
@Help("command.description.empty")
|
||||||
public void empty(final CommandArgument e) {
|
public void empty(Player player) {
|
||||||
final CommandSender sender = e.getSender();
|
final BlockIterator bIt = new BlockIterator(player, 10);
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
||||||
@ -85,22 +80,19 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
if (shop instanceof ContainerShop) {
|
if (shop instanceof ContainerShop) {
|
||||||
final ContainerShop cs = (ContainerShop) shop;
|
final ContainerShop cs = (ContainerShop) shop;
|
||||||
cs.getInventory().clear();
|
cs.getInventory().clear();
|
||||||
sender.sendMessage(MsgUtil.p("empty-success"));
|
player.sendMessage(MsgUtil.p("empty-success"));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
player.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
player.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(minimumArguments = 1, permission = "quickshop.export")
|
@Cmd(minimumArguments = 1, permission = "quickshop.export")
|
||||||
@Help(value = "command.description.export", possibleArguments = "[mysql|sqlite]")
|
@Help(value = "command.description.export", possibleArguments = "[mysql|sqlite]")
|
||||||
public void export(final CommandArgument e) {
|
public void export(CommandSender sender, String type) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
final String type = e.getArgs()[0].toLowerCase();
|
|
||||||
if (type.startsWith("mysql")) {
|
if (type.startsWith("mysql")) {
|
||||||
if (plugin.getDB().getCore() instanceof MySQLCore) {
|
if (plugin.getDB().getCore() instanceof MySQLCore) {
|
||||||
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
|
sender.sendMessage(ChatColor.RED + "数据已保存在 MySQL 无需转换!");
|
||||||
@ -130,10 +122,8 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final File file = new File(plugin.getDataFolder(), "shops.db");
|
final File file = new File(plugin.getDataFolder(), "shops.db");
|
||||||
if (file.exists()) {
|
if (file.exists() && !file.delete()) {
|
||||||
if (file.delete() == false) {
|
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
|
||||||
sender.sendMessage(ChatColor.RED + "警告: 删除旧的数据文件 shops.db 失败. 可能会导致部分信息错误.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final SQLiteCore core = new SQLiteCore(file);
|
final SQLiteCore core = new SQLiteCore(file);
|
||||||
try {
|
try {
|
||||||
@ -144,17 +134,13 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + "导出数据到 SQLite: " + file.toString() + " 失败 由于: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(aliases = "f", minimumArguments = 2, permission = "quickshop.find", executor = Executor.PLAYER)
|
@Cmd(aliases = "f", minimumArguments = 2, permission = "quickshop.find", executor = Executor.PLAYER)
|
||||||
@Help("command.description.find")
|
@Help("command.description.find")
|
||||||
public void find(final CommandArgument e) {
|
public void find(Player p, String lookFor) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
String lookFor = StrKit.consolidateStrings(e.getArgs(), 0);
|
|
||||||
lookFor = lookFor.toLowerCase();
|
lookFor = lookFor.toLowerCase();
|
||||||
final Player p = (Player) sender;
|
|
||||||
final Location loc = p.getEyeLocation().clone();
|
final Location loc = p.getEyeLocation().clone();
|
||||||
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
|
final double minDistance = plugin.getConfig().getInt("shop.find-distance");
|
||||||
double minDistanceSquared = minDistance * minDistance;
|
double minDistanceSquared = minDistance * minDistance;
|
||||||
@ -177,20 +163,18 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closest == null) {
|
if (closest == null) {
|
||||||
sender.sendMessage(MsgUtil.p("no-nearby-shop", e.getArgs()[0]));
|
p.sendMessage(MsgUtil.p("no-nearby-shop", lookFor));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
|
final Location lookat = closest.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
// Hack fix to make /qs find not used by /back
|
// Hack fix to make /qs find not used by /back
|
||||||
p.teleport(this.lookAt(loc, lookat).add(0, -1.62, 0), TeleportCause.PLUGIN);
|
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))));
|
p.sendMessage(MsgUtil.p("nearby-shop-this-way", "" + (int) Math.floor(Math.sqrt(minDistanceSquared))));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(aliases = "i", permission = "quickshop.info")
|
@Cmd(aliases = "i", permission = "quickshop.info")
|
||||||
@Help("command.description.info")
|
@Help("command.description.info")
|
||||||
public void info(final CommandArgument e) {
|
public void info(CommandSender sender) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
int buying, selling, doubles, chunks, worlds, unlimited;
|
int buying, selling, doubles, chunks, worlds, unlimited;
|
||||||
buying = selling = doubles = chunks = worlds = unlimited = 0;
|
buying = selling = doubles = chunks = worlds = unlimited = 0;
|
||||||
int nostock = 0;
|
int nostock = 0;
|
||||||
@ -229,18 +213,9 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
return MsgUtil.p(str);
|
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 = "<价格>")
|
@Help(value = "command.description.price", possibleArguments = "<价格>")
|
||||||
public void price(final CommandArgument e) {
|
public void price(Player sender, Double price) {
|
||||||
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) {
|
if (price < 0.01) {
|
||||||
sender.sendMessage(MsgUtil.p("price-too-cheap"));
|
sender.sendMessage(MsgUtil.p("price-too-cheap"));
|
||||||
return;
|
return;
|
||||||
@ -248,24 +223,24 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
double fee = 0;
|
double fee = 0;
|
||||||
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
|
if (plugin.getConfigManager().isPriceChangeRequiresFee()) {
|
||||||
fee = plugin.getConfigManager().getFeeForPriceChange();
|
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)));
|
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
||||||
return;
|
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
|
// Loop through every block they're looking at upto 10 blocks away
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
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) {
|
if (shop.getPrice() == price) {
|
||||||
// Stop here if there isn't a price change
|
// Stop here if there isn't a price change
|
||||||
sender.sendMessage(MsgUtil.p("no-price-change"));
|
sender.sendMessage(MsgUtil.p("no-price-change"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fee > 0) {
|
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)));
|
sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -298,21 +273,12 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER)
|
@Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER)
|
||||||
@Help(value = "command.description.refill", possibleArguments = "<数量>")
|
@Help(value = "command.description.refill", possibleArguments = "<数量>")
|
||||||
public void refill(final CommandArgument e) {
|
public void refill(Player sender, Integer add) {
|
||||||
final CommandSender sender = e.getSender();
|
final BlockIterator bIt = new BlockIterator(sender, 10);
|
||||||
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()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
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"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(permission = "quickshop.reload")
|
@Cmd(permission = "quickshop.reload")
|
||||||
@Help("command.description.reload")
|
@Help("command.description.reload")
|
||||||
public void reload(final CommandArgument e) {
|
public void reload(CommandSender sender) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
sender.sendMessage(MsgUtil.p("command.reloading"));
|
sender.sendMessage(MsgUtil.p("command.reloading"));
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
@ -338,8 +302,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
|
|
||||||
@Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER)
|
@Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER)
|
||||||
@Help("command.description.remove")
|
@Help("command.description.remove")
|
||||||
public void remove(final CommandArgument e) {
|
public void remove(Player p) {
|
||||||
final Player p = (Player) e.getSender();
|
|
||||||
final BlockIterator bIt = new BlockIterator(p, 10);
|
final BlockIterator bIt = new BlockIterator(p, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
@ -357,17 +320,15 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
p.sendMessage(ChatColor.RED + "未找到商店!");
|
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")
|
@Help("command.description.sell")
|
||||||
public void sell(final CommandArgument e) {
|
public void sell(Player player) {
|
||||||
changeShopType(e.getSender(), ShopType.SELLING);
|
changeShopType(player, ShopType.SELLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER)
|
@Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER)
|
||||||
@Help("command.description.setowner")
|
@Help("command.description.setowner")
|
||||||
public void setowner(final CommandArgument e) {
|
public void setowner(CommandSender sender, String owner) {
|
||||||
final CommandSender sender = e.getSender();
|
|
||||||
final String owner = e.getArgs()[0];
|
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
@ -384,9 +345,8 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse {
|
|||||||
|
|
||||||
@Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER)
|
@Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER)
|
||||||
@Help("command.description.unlimited")
|
@Help("command.description.unlimited")
|
||||||
public void unlimited(final CommandArgument e) {
|
public void unlimited(Player sender) {
|
||||||
final CommandSender sender = e.getSender();
|
final BlockIterator bIt = new BlockIterator(sender, 10);
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
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"));
|
sender.sendMessage(MsgUtil.p("not-looking-at-shop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeShopType(final CommandSender sender, final ShopType shopType) {
|
private void changeShopType(final Player sender, final ShopType shopType) {
|
||||||
final BlockIterator bIt = new BlockIterator((Player) sender, 10);
|
final BlockIterator bIt = new BlockIterator(sender, 10);
|
||||||
while (bIt.hasNext()) {
|
while (bIt.hasNext()) {
|
||||||
final Block b = bIt.next();
|
final Block b = bIt.next();
|
||||||
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
|
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.setShopType(shopType);
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
shop.update();
|
shop.update();
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
package org.maxgamer.QuickShop.Config;
|
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.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
|
import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18;
|
||||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110;
|
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private boolean enableMagicLib = false;
|
private boolean enableMagicLib = false;
|
||||||
/** Whether debug info should be shown in the console */
|
/** Whether debug info should be shown in the console */
|
||||||
@ -50,7 +46,7 @@ public class ConfigManager {
|
|||||||
private double tax = 0;
|
private double tax = 0;
|
||||||
private final String taxAccount;
|
private final String taxAccount;
|
||||||
private boolean fakeItem = false;
|
private boolean fakeItem = false;
|
||||||
|
private List<String> prevent;
|
||||||
/**
|
/**
|
||||||
* A set of players who have been warned
|
* A set of players who have been warned
|
||||||
* ("Your shop isn't automatically locked")
|
* ("Your shop isn't automatically locked")
|
||||||
@ -70,7 +66,7 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.superItem = Material.valueOf(config.getString("superitem"));
|
this.superItem = Material.valueOf(config.getString("superitem"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
this.tax = config.getDouble("tax");
|
this.tax = config.getDouble("tax");
|
||||||
this.showTax = config.getBoolean("show-tax");
|
this.showTax = config.getBoolean("show-tax");
|
||||||
@ -87,6 +83,7 @@ public class ConfigManager {
|
|||||||
this.preventhopper = config.getBoolean("preventhopper");
|
this.preventhopper = config.getBoolean("preventhopper");
|
||||||
this.guiTitle = config.getMessage("guititle", guiTitle);
|
this.guiTitle = config.getMessage("guititle", guiTitle);
|
||||||
this.warnings = Collections.emptySet();
|
this.warnings = Collections.emptySet();
|
||||||
|
this.prevent = config.getStringList("prevent");
|
||||||
if (config.getBoolean("fakeitem", true)) {
|
if (config.getBoolean("fakeitem", true)) {
|
||||||
try {
|
try {
|
||||||
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
|
plugin.getLogger().info("启用虚拟悬浮物 尝试启动中...");
|
||||||
@ -221,4 +218,11 @@ public class ConfigManager {
|
|||||||
this.fakeItem = fakeItem;
|
this.fakeItem = fakeItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getPrevent() {
|
||||||
|
return prevent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrevent(List<String> prevent) {
|
||||||
|
this.prevent = prevent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ public class Info {
|
|||||||
* The location they clicked (Block.getLocation())
|
* The location they clicked (Block.getLocation())
|
||||||
* @param action
|
* @param action
|
||||||
* The action (ShopAction.*)
|
* The action (ShopAction.*)
|
||||||
* @param material
|
* @param item
|
||||||
* The material they were holding
|
* The material they were holding
|
||||||
* @param data
|
* @param last
|
||||||
* The data value of the material
|
* The data value of the material
|
||||||
*/
|
*/
|
||||||
public Info(Location loc, ShopAction action, ItemStack item, Block last) {
|
public Info(Location loc, ShopAction action, ItemStack item, Block last) {
|
||||||
@ -38,9 +38,9 @@ public class Info {
|
|||||||
* The location they clicked (Block.getLocation())
|
* The location they clicked (Block.getLocation())
|
||||||
* @param action
|
* @param action
|
||||||
* The action (ShopAction.*)
|
* The action (ShopAction.*)
|
||||||
* @param material
|
* @param item
|
||||||
* The material they were holding
|
* The material they were holding
|
||||||
* @param data
|
* @param last
|
||||||
* The data value of the material
|
* The data value of the material
|
||||||
* @param shop
|
* @param shop
|
||||||
* The shop they interacted with, or null if none
|
* The shop they interacted with, or null if none
|
||||||
@ -67,9 +67,7 @@ public class Info {
|
|||||||
return true;
|
return true;
|
||||||
if (!this.shop.getLocation().equals(shop.getLocation()))
|
if (!this.shop.getLocation().equals(shop.getLocation()))
|
||||||
return true;
|
return true;
|
||||||
if (!this.shop.matches(shop.getItem()))
|
return !this.shop.matches(shop.getItem());
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopAction getAction() {
|
public ShopAction getAction() {
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
package org.maxgamer.QuickShop.Shop;
|
package org.maxgamer.QuickShop.Shop;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import org.bukkit.*;
|
||||||
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.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -19,11 +9,16 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.Sign;
|
import org.bukkit.material.Sign;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
|
||||||
import org.maxgamer.QuickShop.Database.Database;
|
import org.maxgamer.QuickShop.Database.Database;
|
||||||
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Util.MsgUtil;
|
import org.maxgamer.QuickShop.Util.MsgUtil;
|
||||||
import org.maxgamer.QuickShop.Util.Util;
|
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 {
|
public class ShopManager {
|
||||||
private final HashMap<String, Info> actions = new HashMap<>();
|
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.
|
* @return True if they're allowed to place a shop there.
|
||||||
*/
|
*/
|
||||||
public boolean canBuildShop(final Player p, final Block b, final BlockFace bf) {
|
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()) {
|
if (plugin.getConfigManager().isLimit()) {
|
||||||
int owned = 0;
|
int owned = 0;
|
||||||
final Iterator<Shop> it = getShopIterator();
|
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?
|
final PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), b, bf); // PIE = PlayerInteractEvent - What else?
|
||||||
Bukkit.getPluginManager().callEvent(pie);
|
Bukkit.getPluginManager().callEvent(pie);
|
||||||
pie.getPlayer().closeInventory(); // If the player has chat open, this will close their chat.
|
pie.getPlayer().closeInventory(); // If the player has chat open, this will close their chat.
|
||||||
if (pie.isCancelled()) {
|
if (pie.isCancelled()) { return false; }
|
||||||
return false;
|
} catch (final Exception ignored) {
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
}
|
}
|
||||||
final ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation());
|
final ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation());
|
||||||
Bukkit.getPluginManager().callEvent(spce);
|
Bukkit.getPluginManager().callEvent(spce);
|
||||||
if (spce.isCancelled()) {
|
return !spce.isCancelled();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,7 +100,7 @@ public class ShopManager {
|
|||||||
// Write it to the database
|
// Write it to the database
|
||||||
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
final String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
plugin.getDB().execute(q,
|
plugin.getDB().execute(q,
|
||||||
shop.getOwner().toString(),
|
shop.getOwner(),
|
||||||
shop.getPrice(),
|
shop.getPrice(),
|
||||||
Util.serialize(item),
|
Util.serialize(item),
|
||||||
loc.getBlockX(),
|
loc.getBlockX(),
|
||||||
@ -149,9 +143,7 @@ public class ShopManager {
|
|||||||
*/
|
*/
|
||||||
public Shop getShop(final Location loc) {
|
public Shop getShop(final Location loc) {
|
||||||
final HashMap<Location, Shop> inChunk = getShops(loc.getChunk());
|
final HashMap<Location, Shop> inChunk = getShops(loc.getChunk());
|
||||||
if (inChunk == null) {
|
if (inChunk == null) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// We can do this because WorldListener updates the world reference so
|
// We can do this because WorldListener updates the world reference so
|
||||||
// the world in loc is the same as world in inChunk.get(loc)
|
// the world in loc is the same as world in inChunk.get(loc)
|
||||||
return inChunk.get(loc);
|
return inChunk.get(loc);
|
||||||
@ -186,11 +178,10 @@ public class ShopManager {
|
|||||||
*/
|
*/
|
||||||
public HashMap<Location, Shop> getShops(final Chunk c) {
|
public HashMap<Location, Shop> getShops(final Chunk c) {
|
||||||
// long start = System.nanoTime();
|
// long start = System.nanoTime();
|
||||||
final HashMap<Location, Shop> shops = getShops(c.getWorld().getName(), c.getX(), c.getZ());
|
|
||||||
// long end = System.nanoTime();
|
// long end = System.nanoTime();
|
||||||
// System.out.println("Chunk lookup in " + ((end - start)/1000000.0) +
|
// System.out.println("Chunk lookup in " + ((end - start)/1000000.0) +
|
||||||
// "ms.");
|
// "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) {
|
public HashMap<Location, Shop> getShops(final String world, final int chunkX, final int chunkZ) {
|
||||||
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = this.getShops(world);
|
final HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = this.getShops(world);
|
||||||
if (inWorld == null) {
|
if (inWorld == null) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final ShopChunk shopChunk = new ShopChunk(world, chunkX, chunkZ);
|
final ShopChunk shopChunk = new ShopChunk(world, chunkX, chunkZ);
|
||||||
return inWorld.get(shopChunk);
|
return inWorld.get(shopChunk);
|
||||||
}
|
}
|
||||||
@ -219,14 +208,13 @@ public class ShopManager {
|
|||||||
final HashMap<String, Info> actions = getActions();
|
final HashMap<String, Info> actions = getActions();
|
||||||
// They wanted to do something.
|
// They wanted to do something.
|
||||||
final Info info = actions.remove(p.getName());
|
final Info info = actions.remove(p.getName());
|
||||||
if (info == null) {
|
if (info == null) { return; // multithreaded means this can happen
|
||||||
return; // multithreaded means this can happen
|
|
||||||
}
|
}
|
||||||
/* Creation handling */
|
/* Creation handling */
|
||||||
if (info.getAction() == ShopAction.CREATE) {
|
if (info.getAction() == ShopAction.CREATE) {
|
||||||
create(p, info, message);
|
create(p, info, message);
|
||||||
} else if (/* Purchase Handling */info.getAction() == ShopAction.BUY) {
|
} else if (/* Purchase Handling */info.getAction() == ShopAction.BUY) {
|
||||||
int amount = 0;
|
int amount;
|
||||||
try {
|
try {
|
||||||
amount = Integer.parseInt(message);
|
amount = Integer.parseInt(message);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
@ -236,7 +224,7 @@ public class ShopManager {
|
|||||||
// Get the shop they interacted with
|
// Get the shop they interacted with
|
||||||
final Shop shop = plugin.getShopManager().getShop(info.getLocation());
|
final Shop shop = plugin.getShopManager().getShop(info.getLocation());
|
||||||
// It's not valid anymore
|
// 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"));
|
p.sendMessage(MsgUtil.p("chest-was-removed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -250,9 +238,6 @@ public class ShopManager {
|
|||||||
buy(p, shop, amount);
|
buy(p, shop, amount);
|
||||||
}
|
}
|
||||||
shop.setSignText(); // Update the signs count
|
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()));
|
p.sendMessage(MsgUtil.p("you-dont-have-that-many-items", "" + count, shop.getDataName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (amount == 0) {
|
if (!checkAmount(p, shop, amount)) { return; }
|
||||||
// Dumb.
|
|
||||||
MsgUtil.sendPurchaseSuccess(p, shop, amount);
|
|
||||||
return;
|
|
||||||
} else if (amount < 0) {
|
|
||||||
// & Dumber
|
|
||||||
p.sendMessage(MsgUtil.p("negative-amount"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Money handling
|
// Money handling
|
||||||
if (!p.getName().equals(shop.getOwner())) {
|
if (!p.getName().equals(shop.getOwner())) {
|
||||||
// Don't tax them if they're purchasing from
|
// Don't tax them if they're purchasing from
|
||||||
@ -390,7 +367,7 @@ public class ShopManager {
|
|||||||
p.sendMessage(MsgUtil.p("no-double-chests"));
|
p.sendMessage(MsgUtil.p("no-double-chests"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Util.canBeShop(info.getLocation().getBlock()) == false) {
|
if (!Util.canBeShop(info.getLocation().getBlock())) {
|
||||||
p.sendMessage(MsgUtil.p("chest-was-removed"));
|
p.sendMessage(MsgUtil.p("chest-was-removed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -426,9 +403,7 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
final ShopCreateEvent e = new ShopCreateEvent(shop, p);
|
final ShopCreateEvent e = new ShopCreateEvent(shop, p);
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
shop.onLoad();
|
shop.onLoad();
|
||||||
/* The shop has hereforth been successfully created */
|
/* The shop has hereforth been successfully created */
|
||||||
createShop(shop);
|
createShop(shop);
|
||||||
@ -460,22 +435,19 @@ public class ShopManager {
|
|||||||
});
|
});
|
||||||
shop.setSignText();
|
shop.setSignText();
|
||||||
}
|
}
|
||||||
if (shop instanceof ContainerShop) {
|
final ContainerShop cs = (ContainerShop) shop;
|
||||||
final ContainerShop cs = (ContainerShop) shop;
|
if (cs.isDoubleShop()) {
|
||||||
if (cs.isDoubleShop()) {
|
final Shop nextTo = cs.getAttachedShop();
|
||||||
final Shop nextTo = cs.getAttachedShop();
|
if (nextTo.getPrice() > shop.getPrice()) {
|
||||||
if (nextTo.getPrice() > shop.getPrice()) {
|
// The one next to it must always be a
|
||||||
// The one next to it must always be a
|
// buying shop.
|
||||||
// buying shop.
|
p.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
||||||
p.sendMessage(MsgUtil.p("buying-more-than-selling"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* They didn't enter a number. */
|
/* They didn't enter a number. */
|
||||||
catch (final NumberFormatException ex) {
|
catch (final NumberFormatException ex) {
|
||||||
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
|
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()));
|
p.sendMessage(MsgUtil.p("shop-stock-too-low", "" + shop.getRemainingStock(), shop.getDataName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (amount == 0) {
|
if (!checkAmount(p, shop, amount)) { return; }
|
||||||
// Dumb.
|
|
||||||
MsgUtil.sendPurchaseSuccess(p, shop, amount);
|
|
||||||
return;
|
|
||||||
} else if (amount < 0) {
|
|
||||||
// & Dumber
|
|
||||||
p.sendMessage(MsgUtil.p("negative-amount"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int pSpace = Util.countSpace(p.getInventory(), shop.getItem());
|
final int pSpace = Util.countSpace(p.getInventory(), shop.getItem());
|
||||||
if (amount > pSpace) {
|
if (amount > pSpace) {
|
||||||
p.sendMessage(MsgUtil.p("not-enough-space", "" + pSpace));
|
p.sendMessage(MsgUtil.p("not-enough-space", "" + pSpace));
|
||||||
@ -501,8 +465,7 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) { return; // Cancelled
|
||||||
return; // Cancelled
|
|
||||||
}
|
}
|
||||||
// Money handling
|
// Money handling
|
||||||
if (!p.getName().equals(shop.getOwner())) {
|
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));
|
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> {
|
public class ShopIterator implements Iterator<Shop> {
|
||||||
private Iterator<HashMap<Location, Shop>> chunks;
|
private Iterator<HashMap<Location, Shop>> chunks;
|
||||||
private Shop current;
|
private Shop current;
|
||||||
@ -565,9 +541,7 @@ public class ShopManager {
|
|||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
if (shops == null || !shops.hasNext()) {
|
if (shops == null || !shops.hasNext()) {
|
||||||
if (chunks == null || !chunks.hasNext()) {
|
if (chunks == null || !chunks.hasNext()) {
|
||||||
if (!worlds.hasNext()) {
|
if (!worlds.hasNext()) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
chunks = worlds.next().values().iterator();
|
chunks = worlds.next().values().iterator();
|
||||||
return hasNext();
|
return hasNext();
|
||||||
}
|
}
|
||||||
@ -585,15 +559,12 @@ public class ShopManager {
|
|||||||
public Shop next() {
|
public Shop next() {
|
||||||
if (shops == null || !shops.hasNext()) {
|
if (shops == null || !shops.hasNext()) {
|
||||||
if (chunks == null || !chunks.hasNext()) {
|
if (chunks == null || !chunks.hasNext()) {
|
||||||
if (!worlds.hasNext()) {
|
if (!worlds.hasNext()) { throw new NoSuchElementException("No more shops to iterate over!"); }
|
||||||
throw new NoSuchElementException("No more shops to iterate over!");
|
|
||||||
}
|
|
||||||
chunks = worlds.next().values().iterator();
|
chunks = worlds.next().values().iterator();
|
||||||
}
|
}
|
||||||
shops = chunks.next().values().iterator();
|
shops = chunks.next().values().iterator();
|
||||||
}
|
}
|
||||||
if (!shops.hasNext()) {
|
if (!shops.hasNext()) { return this.next(); // Skip to the next one (Empty iterator?)
|
||||||
return this.next(); // Skip to the next one (Empty iterator?)
|
|
||||||
}
|
}
|
||||||
current = shops.next();
|
current = shops.next();
|
||||||
return current;
|
return current;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Version: 1.7
|
Version: 1.8
|
||||||
|
|
||||||
#超级工具(OP可以用该工具在创造模式打破所有商店)
|
#超级工具(OP可以用该工具在创造模式打破所有商店)
|
||||||
superitem: GOLD_AXE
|
superitem: GOLD_AXE
|
||||||
@ -10,6 +10,9 @@ guititle: '&6[&b快捷商店&6]&r'
|
|||||||
usemagiclib: true
|
usemagiclib: true
|
||||||
#启用虚拟悬浮物
|
#启用虚拟悬浮物
|
||||||
fakeitem: true
|
fakeitem: true
|
||||||
|
#禁止使用商店的世界(请全部小写)
|
||||||
|
prevent:
|
||||||
|
- 'preventworld'
|
||||||
|
|
||||||
#税收数量 (decimal) - 例如 税收是0.05 玩家1 在玩家2的商店 购买了 50元的东西,那么,玩家1 减少 50, 玩家2 账户增加(1-0.05)*50, 并且 玩家2税收账户增加 (0.05)*50.
|
#税收数量 (decimal) - 例如 税收是0.05 玩家1 在玩家2的商店 购买了 50元的东西,那么,玩家1 减少 50, 玩家2 账户增加(1-0.05)*50, 并且 玩家2税收账户增加 (0.05)*50.
|
||||||
tax: 0.00
|
tax: 0.00
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Version: 1.5
|
Version: 1.6
|
||||||
|
|
||||||
not-looking-at-shop: '&c没找到快捷商店. 你必须看着那个商店.'
|
not-looking-at-shop: '&c没找到快捷商店. 你必须看着那个商店.'
|
||||||
no-permission: '&4你没有此命令的权限.'
|
no-permission: '&4你没有此命令的权限.'
|
||||||
@ -39,6 +39,7 @@ buying-more-than-selling: '&4警告: 你购买的物品超出了商店的库存!
|
|||||||
not-enough-space: '&c你没有足够的空间装 {0} !'
|
not-enough-space: '&c你没有足够的空间装 {0} !'
|
||||||
refill-success: '&a库存补充成功!'
|
refill-success: '&a库存补充成功!'
|
||||||
empty-success: '&a商店清理成功!'
|
empty-success: '&a商店清理成功!'
|
||||||
|
prevent-create: '&c当前世界禁止使用商店插件!'
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
successful-purchase: '&a商品购买成功:'
|
successful-purchase: '&a商品购买成功:'
|
||||||
|
Loading…
Reference in New Issue
Block a user