1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-22 01:49:09 +00:00

Updata Project...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-07-17 14:24:25 +08:00
parent 6f7cd753c3
commit 1b0b841fc4
12 changed files with 712 additions and 381 deletions

17
pom.xml
View File

@ -24,15 +24,19 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>3.1</version>
<configuration> <configuration>
<source>1.6</source> <source>1.7</source>
<target>1.6</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<repositories> <repositories>
<repository>
<id>spigot-repo</id>
<url>http://ci.mengcraft.com:8080/plugin/repository/everything/</url>
</repository>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
@ -40,11 +44,10 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.spigotmc</groupId>
<artifactId>bukkit</artifactId> <artifactId>spigot-api</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>provided</scope> <version>1.8.3-R0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>

View File

@ -18,12 +18,14 @@ import com.me.tft_02.soulbound.commands.SoulboundCommand;
import com.me.tft_02.soulbound.commands.UnbindCommand; import com.me.tft_02.soulbound.commands.UnbindCommand;
import com.me.tft_02.soulbound.config.Config; import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.config.ItemsConfig; import com.me.tft_02.soulbound.config.ItemsConfig;
import com.me.tft_02.soulbound.configs.Message;
import com.me.tft_02.soulbound.hooks.EpicBossRecodedListener; import com.me.tft_02.soulbound.hooks.EpicBossRecodedListener;
import com.me.tft_02.soulbound.listeners.BlockListener; import com.me.tft_02.soulbound.listeners.BlockListener;
import com.me.tft_02.soulbound.listeners.EntityListener; import com.me.tft_02.soulbound.listeners.EntityListener;
import com.me.tft_02.soulbound.listeners.InventoryListener; import com.me.tft_02.soulbound.listeners.InventoryListener;
import com.me.tft_02.soulbound.listeners.PlayerListener; import com.me.tft_02.soulbound.listeners.PlayerListener;
import com.me.tft_02.soulbound.util.LogFilter; import com.me.tft_02.soulbound.util.LogFilter;
import com.me.tft_02.soulbound.util.VersionChecker;
public class Soulbound extends JavaPlugin { public class Soulbound extends JavaPlugin {
/* File Paths */ /* File Paths */
@ -43,11 +45,7 @@ public class Soulbound extends JavaPlugin {
} }
// Update Check // Update Check
private boolean updateAvailable; private boolean updateAvailable;
public File msgfile;
public FileConfiguration msgConfig;
public void debug(String message) { public void debug(String message) {
getLogger().info("[Debug] " + message); getLogger().info("[Debug] " + message);
@ -58,7 +56,7 @@ public class Soulbound extends JavaPlugin {
} }
public String getmessage(String path) { public String getmessage(String path) {
String message = this.msgConfig.getString(path).replaceAll("&", "§"); String message = Message.getInstance().getString(path).replaceAll("&", "§");
return message; return message;
} }
@ -74,9 +72,8 @@ public class Soulbound extends JavaPlugin {
return YamlConfiguration.loadConfiguration(cfgfile); return YamlConfiguration.loadConfiguration(cfgfile);
} }
public void LoadConfig(FileConfiguration cfg, File cfgfile) public void LoadConfig(FileConfiguration cfg, File cfgfile) throws FileNotFoundException,
throws FileNotFoundException, IOException, IOException, InvalidConfigurationException {
InvalidConfigurationException {
if (!cfgfile.exists()) { if (!cfgfile.exists()) {
saveResource(cfgfile.getName(), false); saveResource(cfgfile.getName(), false);
cfg.load(cfgfile); cfg.load(cfgfile);
@ -90,11 +87,10 @@ public class Soulbound extends JavaPlugin {
ItemsConfig.getInstance(); ItemsConfig.getInstance();
} }
/**
* Run things on disable.
*/
@Override @Override
public void onDisable() {} public void onLoad() {
Message.load(this);
};
/** /**
* Run things on enable. * Run things on enable.
@ -118,21 +114,8 @@ public class Soulbound extends JavaPlugin {
getCommand("bindonuse").setExecutor(new BindOnUseCommand()); getCommand("bindonuse").setExecutor(new BindOnUseCommand());
getCommand("bindonequip").setExecutor(new BindOnEquipCommand()); getCommand("bindonequip").setExecutor(new BindOnEquipCommand());
getCommand("unbind").setExecutor(new UnbindCommand()); getCommand("unbind").setExecutor(new UnbindCommand());
}
@Override new VersionChecker(this);
public void onLoad() {
msgfile = new File(this.getDataFolder(), "message.yml");
msgConfig = YamlConfiguration.loadConfiguration(msgfile);
try {
LoadConfig (msgConfig ,msgfile);
} catch (FileNotFoundException e) {
this.saveResource("message.yml", true);
} catch (IOException e) {
this.getLogger().info("语言文件读取错误...");
} catch (InvalidConfigurationException e) {
this.saveResource("message.yml", true);
}
} }
private void registerEvents() { private void registerEvents() {
@ -143,27 +126,6 @@ public class Soulbound extends JavaPlugin {
pm.registerEvents(new BlockListener(), this); pm.registerEvents(new BlockListener(), this);
} }
public void reloadmessage(){
try {
LoadConfig (msgConfig ,msgfile);
} catch (FileNotFoundException e) {
this.saveResource("message.yml", true);
} catch (IOException e) {
this.getLogger().info("语言文件读取错误...");
} catch (InvalidConfigurationException e) {
this.saveResource("message.yml", true);
}
}
public void Savecfg(FileConfiguration cfg, File cfgfile) {
try {
// cfg.saveToString();
cfg.save(cfgfile);
} catch (IOException e) {
getLogger().info("配置文件" + cfgfile.getName() + "已保存!");
}
}
private void setupEpicBossRecoded() { private void setupEpicBossRecoded() {
if (getServer().getPluginManager().isPluginEnabled("EpicBossRecoded")) { if (getServer().getPluginManager().isPluginEnabled("EpicBossRecoded")) {
epicBossRecodedEnabled = true; epicBossRecodedEnabled = true;

View File

@ -14,79 +14,77 @@ import com.me.tft_02.soulbound.util.ItemUtils;
public class BindCommand implements CommandExecutor { public class BindCommand implements CommandExecutor {
@SuppressWarnings("deprecation")
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) { if (CommandUtils.noConsoleUsage(sender)) {
return true; return true;
} }
if (!sender.hasPermission("soulbound.commands.bind")) { if (!sender.hasPermission("soulbound.commands.bind")) {
return false; return false;
} }
boolean bindFullInventory = false; boolean bindFullInventory = false;
Player player = (Player) sender; Player player = (Player) sender;
Player target; Player target;
switch (args.length) { switch (args.length) {
case 1: case 1:
target = Soulbound.p.getServer().getPlayerExact(args[0]); target = Soulbound.p.getServer().getPlayerExact(args[0]);
if (CommandUtils.isOffline(sender, target)) { if (CommandUtils.isOffline(sender, target)) {
return true; return true;
} }
break; break;
case 2: case 2:
if (!args[1].equalsIgnoreCase("inventory")) { if (!args[1].equalsIgnoreCase("inventory")) {
sender.sendMessage(Soulbound.p.getlang("BIND_INVENTORY")); sender.sendMessage(Soulbound.p.getlang("BIND_INVENTORY"));
return true; return true;
} }
bindFullInventory = true; bindFullInventory = true;
target = Soulbound.p.getServer().getPlayerExact(args[0]); target = Soulbound.p.getServer().getPlayerExact(args[0]);
if (CommandUtils.isOffline(sender, target)) { if (CommandUtils.isOffline(sender, target)) {
return true; return true;
} }
break; break;
default: default:
target = player; target = player;
} }
if (bindFullInventory) { if (bindFullInventory) {
return handleBindFullInventory(player, target); return handleBindFullInventory(player, target);
} }
ItemStack itemInHand = player.getItemInHand(); ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) { if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) {
sender.sendMessage(Soulbound.p.getlang("CAN_NOT_BIND")); sender.sendMessage(Soulbound.p.getlang("CAN_NOT_BIND"));
return false; return false;
} }
ItemUtils.soulbindItem(target, itemInHand); ItemUtils.soulbindItem(target, itemInHand);
if (ItemUtils.isSoulbound(itemInHand) && Config.getInstance().getFeedbackEnabled()) { if (ItemUtils.isSoulbound(itemInHand) && Config.getInstance().getFeedbackEnabled()) {
sender.sendMessage(Soulbound.p.getlang("BINDED").replace("%target%", target.getName())); sender.sendMessage(Soulbound.p.getlang("BINDED").replace("%target%", target.getName()));
} }
return true; return true;
} }
private boolean handleBindFullInventory(Player player, Player target) { private boolean handleBindFullInventory(Player player, Player target) {
for (ItemStack itemStack : player.getInventory().getContents()) { for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && itemStack.getType() != Material.AIR) { if (itemStack != null && itemStack.getType() != Material.AIR) {
ItemUtils.soulbindItem(target, itemStack); ItemUtils.soulbindItem(target, itemStack);
} }
} }
if (Config.getInstance().getFeedbackEnabled()) { if (Config.getInstance().getFeedbackEnabled()) {
player.sendMessage(Soulbound.p.getlang("BIND_FULL_INEVNTORY"). player.sendMessage(Soulbound.p.getlang("BIND_FULL_INEVNTORY")
replace("%player%", player.getName()). .replace("%player%", player.getName()).replace("%target%", target.getName()));
replace("%target%", target.getName())); }
} return true;
return true; }
}
} }

View File

@ -6,11 +6,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.me.tft_02.soulbound.Soulbound; import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.configs.Message;
public class SoulboundCommand implements CommandExecutor { public class SoulboundCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String label, String[] args) {
switch (args.length) { switch (args.length) {
case 0: case 0:
sender.sendMessage(Soulbound.p.getlang("VERSION") sender.sendMessage(Soulbound.p.getlang("VERSION")
@ -20,14 +20,12 @@ public class SoulboundCommand implements CommandExecutor {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
return reloadConfiguration(sender); return reloadConfiguration(sender);
} }
if (args[0].equalsIgnoreCase("help") if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
|| args[0].equalsIgnoreCase("?")) {
getHelpPage(1, sender); getHelpPage(1, sender);
return true; return true;
} }
default: default:
if (args[0].equalsIgnoreCase("help") if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
|| args[0].equalsIgnoreCase("?")) {
return helpPages(sender, args); return helpPages(sender, args);
} }
return false; return false;
@ -35,13 +33,12 @@ public class SoulboundCommand implements CommandExecutor {
} }
private boolean reloadConfiguration(CommandSender sender) { private boolean reloadConfiguration(CommandSender sender) {
if (sender instanceof Player if (sender instanceof Player && !sender.hasPermission("soulbound.commands.reload")) {
&& !sender.hasPermission("soulbound.commands.reload")) {
return false; return false;
} }
Soulbound.p.reloadConfig(); Soulbound.p.reloadConfig();
Soulbound.p.reloadmessage(); Message.load(Soulbound.p);
sender.sendMessage(Soulbound.p.getlang("RELOAD")); sender.sendMessage(Soulbound.p.getlang("RELOAD"));
return false; return false;
} }
@ -62,14 +59,12 @@ public class SoulboundCommand implements CommandExecutor {
int maxPages = 2; int maxPages = 2;
int nextPage = page + 1; int nextPage = page + 1;
if (page > maxPages) { if (page > maxPages) {
sender.sendMessage(Soulbound.p.getlang("PAGE_NOT_EXIST". sender.sendMessage(Soulbound.p.getlang("PAGE_NOT_EXIST".replace("%maxPages%", maxPages
replace("%maxPages%", maxPages+""))); + "")));
return; return;
} }
sender.sendMessage(Soulbound.p.getlang("HELP_TITLE"). sender.sendMessage(Soulbound.p.getlang("HELP_TITLE").replace("%page%", page + "")
replace("%page%", page+""). .replace("%maxPages%", maxPages + ""));
replace("%maxPages%", maxPages+"")
);
if (page == 1) { if (page == 1) {
sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK")); sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK"));
sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK_1")); sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK_1"));
@ -105,7 +100,7 @@ public class SoulboundCommand implements CommandExecutor {
} }
} }
if (nextPage <= maxPages) { if (nextPage <= maxPages) {
sender.sendMessage(Soulbound.p.getlang("CMD_NEXT").replace("%nextPage%", nextPage+"")); sender.sendMessage(Soulbound.p.getlang("CMD_NEXT").replace("%nextPage%", nextPage + ""));
} }
} }

View File

@ -0,0 +1,102 @@
package com.me.tft_02.soulbound.configs;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
public class ConfigLoader extends FileConfig {
protected static FileConfig config;
protected static boolean tip = true;
protected static Plugin plugin;
public ConfigLoader(Plugin p, File file) {
ConfigLoader.plugin = p;
config = loadConfig(p, file, null, true);
}
public ConfigLoader(Plugin p, File file, boolean res) {
ConfigLoader.plugin = p;
config = loadConfig(p, file, null, res);
}
public ConfigLoader(Plugin p, File file, String ver) {
ConfigLoader.plugin = p;
config = loadConfig(p, file, ver, true);
}
public ConfigLoader(Plugin p, File file, String ver, boolean res) {
ConfigLoader.plugin = p;
config = loadConfig(p, file, ver, res);
}
public ConfigLoader(Plugin p, String filename) {
ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), null,
true);
}
public ConfigLoader(Plugin p, String filename, boolean res) {
ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), null, res);
}
public ConfigLoader(Plugin p, String filename, String ver) {
ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
}
public ConfigLoader(Plugin p, String filename, String ver, boolean res) {
ConfigLoader.plugin = p;
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
}
public static FileConfig getInstance() {
return config;
}
public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) {
tip = res ;
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
p.getLogger().info("创建新的文件夹" + file.getAbsolutePath() + "...");
}
if (!file.exists()) {
fileCreate(p, file, res);
} else {
if (ver != null) {
FileConfig configcheck = init(file);
String version = configcheck.getString("version");
if (version == null || !version.equals(ver)) {
p.saveResource(file.getName(), true);
p.getLogger().warning(
"配置文件: " + file.getName() + " 版本过低 正在升级...");
}
}
}
if (tip)
p.getLogger().info(
"载入配置文件: " + file.getName()
+ (ver != null ? " 版本: " + ver : ""));
return init(file);
}
private void fileCreate(Plugin p, File file, boolean res) {
if (res) {
p.saveResource(file.getName(), false);
} else {
try {
p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "...");
file.createNewFile();
} catch (IOException e) {
p.getLogger().info("配置文件" + file.getName() + "创建失败...");
e.printStackTrace();
}
}
}
public static void saveError(File file) {
plugin.getLogger().info("配置文件" + file.getName() + "保存错误...");
}
}

View File

@ -0,0 +1,110 @@
package com.me.tft_02.soulbound.configs;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.YamlConstructor;
import org.bukkit.configuration.file.YamlRepresenter;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.representer.Representer;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
/**
* An implementation of {@link Configuration} which saves all files in Yaml.
* Note that this implementation is not synchronized.
*/
public class FileConfig extends YamlConfiguration {
public static FileConfig init(File file) {
return FileConfig.loadConfiguration(file);
}
public static FileConfig loadConfiguration(File file) {
Validate.notNull(file, "File cannot be null");
FileConfig config = new FileConfig();
try {
config.load(file);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
}
return config;
}
protected final DumperOptions yamlOptions = new DumperOptions();
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(),
yamlRepresenter, yamlOptions);
@Override
public void load(File file) throws FileNotFoundException, IOException,
InvalidConfigurationException {
Validate.notNull(file, "File cannot be null");
final FileInputStream stream = new FileInputStream(file);
load(new InputStreamReader(stream, Charsets.UTF_8));
}
@Override
public void load(Reader reader) throws IOException, InvalidConfigurationException {
BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader
: new BufferedReader(reader);
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
builder.append('\n');
}
} finally {
input.close();
}
loadFromString(builder.toString());
}
@Override
public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
Charsets.UTF_8);
try {
writer.write(data);
} finally {
writer.close();
}
}
@Override
public String saveToString() {
yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
String header = buildHeader();
String dump = yaml.dump(getValues(false));
if (dump.equals(BLANK_CONFIG)) {
dump = "";
}
return header + dump;
}
}

View File

@ -0,0 +1,63 @@
package com.me.tft_02.soulbound.configs;
import java.io.File;
import java.io.IOException;
import org.bukkit.plugin.Plugin;
public class Message extends ConfigLoader {
private static String CONFIG_NAME = "message.yml";
private static FileConfig instance;
private static File file;
public Message(Plugin p) {
super(p, CONFIG_NAME);
file = new File(p.getDataFolder(), CONFIG_NAME);
instance = super.getInstance();
}
public Message(Plugin p, String ver) {
super(p, CONFIG_NAME, ver);
instance = super.getInstance();
}
public static void load(Plugin p) {
new Message(p);
}
public static void load(Plugin p, String ver) {
new Message(p, ver);
}
public static FileConfig getInstance() {
return instance;
}
public static String getMessage(String path) {
String message = instance.getString(path);
if (message != null)
message = message.replaceAll("&", "§");
return message;
}
public static String getHead(String path, String prevName) {
String message = instance.getString(path);
if (message != null)
message = message.replaceAll("&", "§").replaceAll("%player%",
prevName);
return message;
}
public static String[] getStringArray(String path) {
return instance.getStringList(path).toArray(new String[0]);
}
public static void save() {
try {
instance.save(file);
} catch (IOException e) {
saveError(file);
e.printStackTrace();
}
}
}

View File

@ -37,236 +37,261 @@ import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(
private void onItemPickup(PlayerPickupItemEvent event) { priority = EventPriority.LOWEST,
Player player = event.getPlayer(); ignoreCancelled = true)
Item item = event.getItem(); private void onItemPickup(PlayerPickupItemEvent event) {
ItemStack itemStack = item.getItemStack(); Player player = event.getPlayer();
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) { if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
if (Permissions.pickupBypass(player)) { if (Permissions.pickupBypass(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (ItemUtils.isBindOnPickup(itemStack)) { if (ItemUtils.isBindOnPickup(itemStack)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) { if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(
private void onItemDrop(PlayerDropItemEvent event) { priority = EventPriority.HIGHEST,
Player player = event.getPlayer(); ignoreCancelled = true)
Item item = event.getItemDrop(); private void onItemDrop(PlayerDropItemEvent event) {
ItemStack itemStack = item.getItemStack(); Player player = event.getPlayer();
Item item = event.getItemDrop();
ItemStack itemStack = item.getItemStack();
if (Config.getInstance().getPreventItemDrop()) { if (Config.getInstance().getPreventItemDrop()) {
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
item.setPickupDelay(2 * 20); item.setPickupDelay(2 * 20);
event.setCancelled(true); event.setCancelled(true);
new UpdateInventoryTask(player).runTask(Soulbound.p); new UpdateInventoryTask(player).runTask(Soulbound.p);
} }
return; return;
} }
if (Config.getInstance().getDeleteOnDrop()) { if (Config.getInstance().getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove(); event.getItemDrop().remove();
return; return;
} }
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) { if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(
private void onPlayerDeath(PlayerDeathEvent event) { priority = EventPriority.HIGHEST,
Player player = event.getEntity(); ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
boolean deleteOnDeath = Permissions.deleteOnDeath(player); boolean deleteOnDeath = Permissions.deleteOnDeath(player);
boolean keepOnDeath = Permissions.keepOnDeath(player); boolean keepOnDeath = Permissions.keepOnDeath(player);
List<ItemStack> items = new ArrayList<ItemStack>(); List<ItemStack> items = new ArrayList<ItemStack>();
if (!keepOnDeath && !deleteOnDeath) { if (!keepOnDeath && !deleteOnDeath) {
return; return;
} }
for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) { for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) { if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) { if (keepOnDeath) {
items.add(item); items.add(item);
event.getDrops().remove(item); event.getDrops().remove(item);
} } else if (deleteOnDeath) {
else if (deleteOnDeath) { event.getDrops().remove(item);
event.getDrops().remove(item); }
} }
} }
}
PlayerData.storeItemsDeath(player, items); PlayerData.storeItemsDeath(player, items);
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(
private void onPlayerRespawn(PlayerRespawnEvent event) { priority = EventPriority.NORMAL,
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p); ignoreCancelled = true)
} private void onPlayerRespawn(PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(
private void onPlayerRespawnHighest(PlayerRespawnEvent event) { priority = EventPriority.HIGHEST,
Player player = event.getPlayer(); ignoreCancelled = true)
boolean keepOnDeath = Permissions.keepOnDeath(player); private void onPlayerRespawnHighest(PlayerRespawnEvent event) {
Player player = event.getPlayer();
boolean keepOnDeath = Permissions.keepOnDeath(player);
if (!keepOnDeath) { if (!keepOnDeath) {
return; return;
} }
List<ItemStack> items = new ArrayList<ItemStack>(); List<ItemStack> items = new ArrayList<ItemStack>();
items = PlayerData.retrieveItemsDeath(player); items = PlayerData.retrieveItemsDeath(player);
if (items != null) { if (items != null) {
for (ItemStack item : items) { for (ItemStack item : items) {
player.getInventory().addItem(item); player.getInventory().addItem(item);
} }
} }
new UpdateInventoryTask(player).runTask(Soulbound.p); new UpdateInventoryTask(player).runTask(Soulbound.p);
} }
/** /**
* Watch PlayerInteract events. * Watch PlayerInteract events.
* *
* @param event The event to watch * @param event
*/ * The event to watch
@EventHandler(priority = EventPriority.LOW) */
public void onPlayerInteract(PlayerInteractEvent event) { @EventHandler(
Player player = event.getPlayer(); priority = EventPriority.LOW)
Action action = event.getAction(); public void onPlayerInteract(PlayerInteractEvent event) {
ItemStack inHand = player.getItemInHand(); Player player = event.getPlayer();
Action action = event.getAction();
ItemStack inHand = player.getItemInHand();
switch (action) { switch (action) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_AIR: case RIGHT_CLICK_AIR:
case LEFT_CLICK_AIR: case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK: case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) { if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
} } else if (ItemUtils.isBindOnUse(inHand)) {
else if (ItemUtils.isBindOnUse(inHand)) { ItemUtils.soulbindItem(player, inHand);
ItemUtils.soulbindItem(player, inHand); }
} default:
default: break;
break; }
} }
}
/** /**
* Monitor PlayerFishEvent events. * Monitor PlayerFishEvent events.
* *
* @param event The event to monitor * @param event
*/ * The event to monitor
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) */
private void onPlayerFish(PlayerFishEvent event) { @EventHandler(
ItemStack itemInHand = event.getPlayer().getItemInHand(); priority = EventPriority.LOWEST,
ignoreCancelled = true)
private void onPlayerFish(PlayerFishEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand); DurabilityUtils.handleInfiniteDurability(itemInHand);
} }
/** /**
* Monitor PlayerShearEntityEvent events. * Monitor PlayerShearEntityEvent events.
* *
* @param event The event to monitor * @param event
*/ * The event to monitor
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) */
private void onPlayerShearEntity(PlayerShearEntityEvent event) { @EventHandler(
ItemStack itemInHand = event.getPlayer().getItemInHand(); priority = EventPriority.LOWEST,
ignoreCancelled = true)
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand); DurabilityUtils.handleInfiniteDurability(itemInHand);
} }
/** /**
* Watch PlayerCommandPreprocessEvent events. * Watch PlayerCommandPreprocessEvent events.
* *
* @param event The event to watch * @param event
*/ * The event to watch
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) */
public void onPlayerCommand(PlayerCommandPreprocessEvent event) { @EventHandler(
Player player = event.getPlayer(); priority = EventPriority.NORMAL,
ItemStack itemStack = player.getItemInHand(); ignoreCancelled = true)
String command = event.getMessage(); public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
String command = event.getMessage();
if (ItemUtils.isSoulbound(itemStack) && Config.getInstance().getBlockedCommands().contains(command)) { if (ItemUtils.isSoulbound(itemStack)
player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item."); && Config.getInstance().getBlockedCommands().contains(command)) {
event.setCancelled(true); player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD
} + command + ChatColor.RED + " command while holding a Soulbound item.");
} event.setCancelled(true);
}
}
/** /**
* Monitor PlayerCommandPreprocessEvent events. * Monitor PlayerCommandPreprocessEvent events.
* *
* @param event The event to monitor * @param event
*/ * The event to monitor
@SuppressWarnings("deprecation") */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) { priority = EventPriority.MONITOR,
Player player = event.getPlayer(); ignoreCancelled = true)
ItemStack inHand = player.getItemInHand(); public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
String command = event.getMessage(); Player player = event.getPlayer();
String[] args = CommandUtils.extractArgs(command); ItemStack inHand = player.getItemInHand();
String command = event.getMessage();
String[] args = CommandUtils.extractArgs(command);
if (!ItemUtils.isSoulbound(inHand) && Config.getInstance().getBindCommands().contains(command)) { if (!ItemUtils.isSoulbound(inHand)
ItemUtils.soulbindItem(player, inHand); && Config.getInstance().getBindCommands().contains(command)) {
return; ItemUtils.soulbindItem(player, inHand);
} return;
}
if (command.contains("kit")) { if (command.contains("kit")) {
Player target; Player target;
if (args.length >= 2) { if (args.length >= 2) {
target = Soulbound.p.getServer().getPlayer(args[1]); target = Soulbound.p.getServer().getPlayer(args[1]);
} } else {
else { target = player;
target = player; }
}
if (target == null) { if (target == null) {
return; return;
} }
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
} }
} }
/** /**
* Monitor ServerCommandEvent events. * Monitor ServerCommandEvent events.
* *
* @param event The event to monitor * @param event
*/ * The event to monitor
@SuppressWarnings("deprecation") */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(
public void onServerCommand(ServerCommandEvent event) { priority = EventPriority.MONITOR,
String command = event.getCommand(); ignoreCancelled = true)
String[] args = CommandUtils.extractArgs(command); public void onServerCommand(ServerCommandEvent event) {
String command = event.getCommand();
String[] args = CommandUtils.extractArgs(command);
if (!command.contains("kit")) { if (!command.contains("kit")) {
return; return;
} }
if (args.length < 2) { if (args.length < 2) {
return; return;
} }
Player target = Soulbound.p.getServer().getPlayer(args[1]); Player target = Soulbound.p.getServer().getPlayer(args[1]);
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
} }
} }

View File

@ -4,17 +4,16 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class UpdateInventoryTask extends BukkitRunnable { public class UpdateInventoryTask extends BukkitRunnable {
private Player player; private Player player;
public UpdateInventoryTask(Player player) { public UpdateInventoryTask(Player player) {
this.player = player; this.player = player;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void run() { public void run() {
if (player.isValid()) { if (player.isValid()) {
player.updateInventory(); player.updateInventory();
} }
} }
} }

View File

@ -0,0 +1,73 @@
package com.me.tft_02.soulbound.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import com.google.common.base.Charsets;
public class VersionChecker implements Listener {
Plugin plugin;
public VersionChecker(Plugin plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
this.VersionCheck(null);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
if (e.getPlayer().isOp()) {
this.VersionCheck(e.getPlayer());
}
}
public void VersionCheck(final Player player) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
String website = plugin.getDescription().getWebsite();
String readURL = website
+ (website.substring(website.length() - 1).equals("/") ? "" : "/")
+ "/lastSuccessfulBuild/artifact/src/plugin.yml";
FileConfiguration config;
String currentVersion = plugin.getDescription().getVersion();
try {
URL url = new URL(readURL);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),
Charsets.UTF_8));
config = YamlConfiguration.loadConfiguration(br);
String newVersion = config.getString("version");
br.close();
if (!newVersion.equals(currentVersion)) {
String[] msg = new String[] {
ChatColor.GREEN + plugin.getName() + "插件最新版本 v" + newVersion,
ChatColor.RED + "服务器运行版本: v" + currentVersion,
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE
+ plugin.getDescription().getWebsite()
};
if (player != null) {
player.sendMessage(msg);
} else {
plugin.getServer().getConsoleSender().sendMessage(msg);
}
}
} catch (IOException e) {
plugin.getLogger().warning("版本更新检查失败!");
}
}
});
}
}

View File

@ -1,44 +1,44 @@
#提示消息 #提示消息
Message: Message:
CAN_NOT_BIND: '&7你不能&c绑定&7这个物品' CAN_NOT_BIND: '&7你不能&c绑定&7这个物品'
CAN_NOT_UNBIND: '&7你不能&6解绑&7这个物品' CAN_NOT_UNBIND: '&7你不能&6解绑&7这个物品'
BINDED: '&7物品已经&a绑定&7到玩家&c%target%' BINDED: '&7物品已经&a绑定&7到玩家&c%target%'
UNBINDED: '&7物品已经解绑' UNBINDED: '&7物品已经解绑'
BIND_FULL_INEVNTORY: '&a玩家&c%player%&a背包内的所有物品已绑定到玩家&6%target%' BIND_FULL_INEVNTORY: '&a玩家&c%player%&a背包内的所有物品已绑定到玩家&6%target%'
BIND_INVENTORY: '&c你可能需要的命令: &a/bind <player> inventory' BIND_INVENTORY: '&c你可能需要的命令: &a/bind <player> inventory'
BIND_ON_EQUIP: '&7当前物品已标记为 &4装备后绑定' BIND_ON_EQUIP: '&7当前物品已标记为 &4装备后绑定'
BIND_ON_PICKUP: '&7当前物品已标记为 &4拾取后绑定' BIND_ON_PICKUP: '&7当前物品已标记为 &4拾取后绑定'
BIND_ON_USE: '&7当前物品已标记为 &4使用后绑定' BIND_ON_USE: '&7当前物品已标记为 &4使用后绑定'
CAN_NOT_BIND_ON_EQUIP: '&7当前物品不能标记为 &4装备后绑定' CAN_NOT_BIND_ON_EQUIP: '&7当前物品不能标记为 &4装备后绑定'
CAN_NOT_BIND_ON_PICKUP: '&7当前物品不能标记为 &4拾取后绑定' CAN_NOT_BIND_ON_PICKUP: '&7当前物品不能标记为 &4拾取后绑定'
CAN_NOT_BIND_ON_USE: '&7当前物品不能标记为 &4使用后绑定' CAN_NOT_BIND_ON_USE: '&7当前物品不能标记为 &4使用后绑定'
VERSION: '灵魂绑定(&3修改by喵♂呜) &r版本号' VERSION: '灵魂绑定(&3修改by喵♂呜) &r版本号'
CAN_NOT_USE_ON_CONSOLE: '抱歉 此命令不能在控制台使用' CAN_NOT_USE_ON_CONSOLE: '抱歉 此命令不能在控制台使用'
PAGE_NOT_EXIST: '&c帮助页面不存在 请输入 /Soulbound help [0-%maxPages%]' PAGE_NOT_EXIST: '&c帮助页面不存在 请输入 /Soulbound help [0-%maxPages%]'
HELP_TITLE: '&7--[ &6灵魂绑定 帮助 &a-汉化by邱 &3-修改by喵♂呜 &7 ]-- 页面 %page%/%maxPages%' HELP_TITLE: '&7--[ &6灵魂绑定 帮助 &a-汉化by邱 &3-修改by喵♂呜 &7 ]-- 页面 %page%/%maxPages%'
HOW_DOES_IT_WORK: '&4* &c它是如何工作的' HOW_DOES_IT_WORK: '&4* &c它是如何工作的'
HOW_DOES_IT_WORK_1: '&4* &c灵魂绑定的物品只有自己才能使用。' HOW_DOES_IT_WORK_1: '&4* &c灵魂绑定的物品只有自己才能使用。'
HOW_DOES_IT_WORK_2: '&4* &c绑定后的物品某些行为将会被阻止:' HOW_DOES_IT_WORK_2: '&4* &c绑定后的物品某些行为将会被阻止:'
HOW_DOES_IT_WORK_3: '&4* &c扔在地上、或者放到箱子里让其他玩家拿。' HOW_DOES_IT_WORK_3: '&4* &c扔在地上、或者放到箱子里让其他玩家拿。'
HOW_DOES_IT_WORK_4: '&4* &c标记为 &4拾取后绑定 &c的物品' HOW_DOES_IT_WORK_4: '&4* &c标记为 &4拾取后绑定 &c的物品'
HOW_DOES_IT_WORK_4_1: ' &c一旦被玩家捡起来就会立即绑定成为该玩家的物品。' HOW_DOES_IT_WORK_4_1: ' &c一旦被玩家捡起来就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_5: '&4* &c标记为 &4使用后绑定 &c的物品' HOW_DOES_IT_WORK_5: '&4* &c标记为 &4使用后绑定 &c的物品'
HOW_DOES_IT_WORK_5_1: ' &c只要拿在手中左键或者右键就会立即绑定成为该玩家的物品。' HOW_DOES_IT_WORK_5_1: ' &c只要拿在手中左键或者右键就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_6: '&4* &c标记为 &4装备后绑定 &c的物品' HOW_DOES_IT_WORK_6: '&4* &c标记为 &4装备后绑定 &c的物品'
HOW_DOES_IT_WORK_6_1: ' &c装备到身上后就能立即绑定成为该玩家的物品。' HOW_DOES_IT_WORK_6_1: ' &c装备到身上后就能立即绑定成为该玩家的物品。'
CMD: '&6指令:' CMD: '&6指令:'
CMDVERSION: '&4* &a/soulbound &7查看插件版本。' CMDVERSION: '&4* &a/soulbound &7查看插件版本。'
CMD_BIND: '&4* &a/bind <sender> &7绑定手上的物品。' CMD_BIND: '&4* &a/bind <sender> &7绑定手上的物品。'
CMD_BIND_FULL_INVENTORY: '&4* &a/bind <sender> inventory &7绑定玩家背包里的所有物品。' CMD_BIND_FULL_INVENTORY: '&4* &a/bind <sender> inventory &7绑定玩家背包里的所有物品。'
CMD_BIND_ON_EQUIP: '&4* &a/bindonequip &7将当前物品标记为 &4装备后绑定' CMD_BIND_ON_EQUIP: '&4* &a/bindonequip &7将当前物品标记为 &4装备后绑定'
CMD_BIND_ON_PICKUP: '&4* &a/bindonpickup &7将当前物品标记为 &4拾取后绑定' CMD_BIND_ON_PICKUP: '&4* &a/bindonpickup &7将当前物品标记为 &4拾取后绑定'
CMD_BIND_ON_USE: '&4* &a/bindonuse &7将当前物品标记为 &4使用后绑定' CMD_BIND_ON_USE: '&4* &a/bindonuse &7将当前物品标记为 &4使用后绑定'
CMD_UNBIND: '&4* &a/unbind &7解除手中物品的绑定。' CMD_UNBIND: '&4* &a/unbind &7解除手中物品的绑定。'
CMD_NEXT: '&6使用 /soulbound help %nextPage% 查看更多' CMD_NEXT: '&6使用 /soulbound help %nextPage% 查看更多'
CMD_USE: '使用: /soulbound [reload | help]' CMD_USE: '使用: /soulbound [reload | help]'
RELOAD: '&a配置文件已重载...' RELOAD: '&a配置文件已重载...'

View File

@ -1,7 +1,8 @@
name: Soulbound name: Soulbound
version: 1.1.10-SNAPSHOT-b84 version: 1.1.11
author: TfT_02 author: TfT_02,喵♂呜
main: com.me.tft_02.soulbound.Soulbound main: com.me.tft_02.soulbound.Soulbound
website: http://ci.citycraft.cn:8800/jenkins/job/Soulbound-Fix/
description: Soulbound items for your RPG servers! description: Soulbound items for your RPG servers!
softdepend: [EpicBossRecoded, LoreLocks] softdepend: [EpicBossRecoded, LoreLocks]
commands: commands: