1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-25 02:19:11 +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>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>http://ci.mengcraft.com:8080/plugin/repository/everything/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
@ -40,11 +44,10 @@
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<scope>provided</scope>
<version>1.8.3-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<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.config.Config;
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.listeners.BlockListener;
import com.me.tft_02.soulbound.listeners.EntityListener;
import com.me.tft_02.soulbound.listeners.InventoryListener;
import com.me.tft_02.soulbound.listeners.PlayerListener;
import com.me.tft_02.soulbound.util.LogFilter;
import com.me.tft_02.soulbound.util.VersionChecker;
public class Soulbound extends JavaPlugin {
/* File Paths */
@ -43,11 +45,7 @@ public class Soulbound extends JavaPlugin {
}
// Update Check
private boolean updateAvailable;
public File msgfile;
public FileConfiguration msgConfig;
private boolean updateAvailable;
public void debug(String message) {
getLogger().info("[Debug] " + message);
@ -58,7 +56,7 @@ public class Soulbound extends JavaPlugin {
}
public String getmessage(String path) {
String message = this.msgConfig.getString(path).replaceAll("&", "§");
String message = Message.getInstance().getString(path).replaceAll("&", "§");
return message;
}
@ -74,9 +72,8 @@ public class Soulbound extends JavaPlugin {
return YamlConfiguration.loadConfiguration(cfgfile);
}
public void LoadConfig(FileConfiguration cfg, File cfgfile)
throws FileNotFoundException, IOException,
InvalidConfigurationException {
public void LoadConfig(FileConfiguration cfg, File cfgfile) throws FileNotFoundException,
IOException, InvalidConfigurationException {
if (!cfgfile.exists()) {
saveResource(cfgfile.getName(), false);
cfg.load(cfgfile);
@ -90,11 +87,10 @@ public class Soulbound extends JavaPlugin {
ItemsConfig.getInstance();
}
/**
* Run things on disable.
*/
@Override
public void onDisable() {}
public void onLoad() {
Message.load(this);
};
/**
* Run things on enable.
@ -118,21 +114,8 @@ public class Soulbound extends JavaPlugin {
getCommand("bindonuse").setExecutor(new BindOnUseCommand());
getCommand("bindonequip").setExecutor(new BindOnEquipCommand());
getCommand("unbind").setExecutor(new UnbindCommand());
}
@Override
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);
}
new VersionChecker(this);
}
private void registerEvents() {
@ -143,27 +126,6 @@ public class Soulbound extends JavaPlugin {
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() {
if (getServer().getPluginManager().isPluginEnabled("EpicBossRecoded")) {
epicBossRecodedEnabled = true;

View File

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

View File

@ -6,11 +6,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.configs.Message;
public class SoulboundCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
sender.sendMessage(Soulbound.p.getlang("VERSION")
@ -20,14 +20,12 @@ public class SoulboundCommand implements CommandExecutor {
if (args[0].equalsIgnoreCase("reload")) {
return reloadConfiguration(sender);
}
if (args[0].equalsIgnoreCase("help")
|| args[0].equalsIgnoreCase("?")) {
if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
getHelpPage(1, sender);
return true;
}
default:
if (args[0].equalsIgnoreCase("help")
|| args[0].equalsIgnoreCase("?")) {
if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
return helpPages(sender, args);
}
return false;
@ -35,13 +33,12 @@ public class SoulboundCommand implements CommandExecutor {
}
private boolean reloadConfiguration(CommandSender sender) {
if (sender instanceof Player
&& !sender.hasPermission("soulbound.commands.reload")) {
if (sender instanceof Player && !sender.hasPermission("soulbound.commands.reload")) {
return false;
}
Soulbound.p.reloadConfig();
Soulbound.p.reloadmessage();
Message.load(Soulbound.p);
sender.sendMessage(Soulbound.p.getlang("RELOAD"));
return false;
}
@ -62,14 +59,12 @@ public class SoulboundCommand implements CommandExecutor {
int maxPages = 2;
int nextPage = page + 1;
if (page > maxPages) {
sender.sendMessage(Soulbound.p.getlang("PAGE_NOT_EXIST".
replace("%maxPages%", maxPages+"")));
sender.sendMessage(Soulbound.p.getlang("PAGE_NOT_EXIST".replace("%maxPages%", maxPages
+ "")));
return;
}
sender.sendMessage(Soulbound.p.getlang("HELP_TITLE").
replace("%page%", page+"").
replace("%maxPages%", maxPages+"")
);
sender.sendMessage(Soulbound.p.getlang("HELP_TITLE").replace("%page%", page + "")
.replace("%maxPages%", maxPages + ""));
if (page == 1) {
sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK"));
sender.sendMessage(Soulbound.p.getlang("HOW_DOES_IT_WORK_1"));
@ -105,7 +100,7 @@ public class SoulboundCommand implements CommandExecutor {
}
}
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 {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onItemPickup(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
@EventHandler(
priority = EventPriority.LOWEST,
ignoreCancelled = true)
private void onItemPickup(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
if (Permissions.pickupBypass(player)) {
return;
}
event.setCancelled(true);
return;
}
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
if (Permissions.pickupBypass(player)) {
return;
}
event.setCancelled(true);
return;
}
if (ItemUtils.isBindOnPickup(itemStack)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
if (ItemUtils.isBindOnPickup(itemStack)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItemDrop();
ItemStack itemStack = item.getItemStack();
@EventHandler(
priority = EventPriority.HIGHEST,
ignoreCancelled = true)
private void onItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItemDrop();
ItemStack itemStack = item.getItemStack();
if (Config.getInstance().getPreventItemDrop()) {
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
item.setPickupDelay(2 * 20);
event.setCancelled(true);
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
return;
}
if (Config.getInstance().getPreventItemDrop()) {
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
item.setPickupDelay(2 * 20);
event.setCancelled(true);
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
return;
}
if (Config.getInstance().getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove();
return;
}
if (Config.getInstance().getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove();
return;
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
@EventHandler(
priority = EventPriority.HIGHEST,
ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
boolean deleteOnDeath = Permissions.deleteOnDeath(player);
boolean keepOnDeath = Permissions.keepOnDeath(player);
boolean deleteOnDeath = Permissions.deleteOnDeath(player);
boolean keepOnDeath = Permissions.keepOnDeath(player);
List<ItemStack> items = new ArrayList<ItemStack>();
List<ItemStack> items = new ArrayList<ItemStack>();
if (!keepOnDeath && !deleteOnDeath) {
return;
}
if (!keepOnDeath && !deleteOnDeath) {
return;
}
for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) {
items.add(item);
event.getDrops().remove(item);
}
else if (deleteOnDeath) {
event.getDrops().remove(item);
}
}
}
for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) {
items.add(item);
event.getDrops().remove(item);
} else if (deleteOnDeath) {
event.getDrops().remove(item);
}
}
}
PlayerData.storeItemsDeath(player, items);
}
PlayerData.storeItemsDeath(player, items);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerRespawn(PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(
priority = EventPriority.NORMAL,
ignoreCancelled = true)
private void onPlayerRespawn(PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerRespawnHighest(PlayerRespawnEvent event) {
Player player = event.getPlayer();
boolean keepOnDeath = Permissions.keepOnDeath(player);
@EventHandler(
priority = EventPriority.HIGHEST,
ignoreCancelled = true)
private void onPlayerRespawnHighest(PlayerRespawnEvent event) {
Player player = event.getPlayer();
boolean keepOnDeath = Permissions.keepOnDeath(player);
if (!keepOnDeath) {
return;
}
if (!keepOnDeath) {
return;
}
List<ItemStack> items = new ArrayList<ItemStack>();
items = PlayerData.retrieveItemsDeath(player);
if (items != null) {
for (ItemStack item : items) {
player.getInventory().addItem(item);
}
}
List<ItemStack> items = new ArrayList<ItemStack>();
items = PlayerData.retrieveItemsDeath(player);
if (items != null) {
for (ItemStack item : items) {
player.getInventory().addItem(item);
}
}
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
/**
* Watch PlayerInteract events.
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Action action = event.getAction();
ItemStack inHand = player.getItemInHand();
/**
* Watch PlayerInteract events.
*
* @param event
* The event to watch
*/
@EventHandler(
priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Action action = event.getAction();
ItemStack inHand = player.getItemInHand();
switch (action) {
case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_AIR:
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
}
else if (ItemUtils.isBindOnUse(inHand)) {
ItemUtils.soulbindItem(player, inHand);
}
default:
break;
}
}
switch (action) {
case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_AIR:
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
} else if (ItemUtils.isBindOnUse(inHand)) {
ItemUtils.soulbindItem(player, inHand);
}
default:
break;
}
}
/**
* Monitor PlayerFishEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerFish(PlayerFishEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
/**
* Monitor PlayerFishEvent events.
*
* @param event
* The event to monitor
*/
@EventHandler(
priority = EventPriority.LOWEST,
ignoreCancelled = true)
private void onPlayerFish(PlayerFishEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* Monitor PlayerShearEntityEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
/**
* Monitor PlayerShearEntityEvent events.
*
* @param event
* The event to monitor
*/
@EventHandler(
priority = EventPriority.LOWEST,
ignoreCancelled = true)
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* Watch PlayerCommandPreprocessEvent events.
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
String command = event.getMessage();
/**
* Watch PlayerCommandPreprocessEvent events.
*
* @param event
* The event to watch
*/
@EventHandler(
priority = EventPriority.NORMAL,
ignoreCancelled = true)
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)) {
player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item.");
event.setCancelled(true);
}
}
if (ItemUtils.isSoulbound(itemStack)
&& Config.getInstance().getBlockedCommands().contains(command)) {
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.
*
* @param event The event to monitor
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack inHand = player.getItemInHand();
String command = event.getMessage();
String[] args = CommandUtils.extractArgs(command);
/**
* Monitor PlayerCommandPreprocessEvent events.
*
* @param event
* The event to monitor
*/
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true)
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack inHand = player.getItemInHand();
String command = event.getMessage();
String[] args = CommandUtils.extractArgs(command);
if (!ItemUtils.isSoulbound(inHand) && Config.getInstance().getBindCommands().contains(command)) {
ItemUtils.soulbindItem(player, inHand);
return;
}
if (!ItemUtils.isSoulbound(inHand)
&& Config.getInstance().getBindCommands().contains(command)) {
ItemUtils.soulbindItem(player, inHand);
return;
}
if (command.contains("kit")) {
Player target;
if (command.contains("kit")) {
Player target;
if (args.length >= 2) {
target = Soulbound.p.getServer().getPlayer(args[1]);
}
else {
target = player;
}
if (args.length >= 2) {
target = Soulbound.p.getServer().getPlayer(args[1]);
} else {
target = player;
}
if (target == null) {
return;
}
if (target == null) {
return;
}
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
}
}
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
}
}
/**
* Monitor ServerCommandEvent events.
*
* @param event The event to monitor
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onServerCommand(ServerCommandEvent event) {
String command = event.getCommand();
String[] args = CommandUtils.extractArgs(command);
/**
* Monitor ServerCommandEvent events.
*
* @param event
* The event to monitor
*/
@EventHandler(
priority = EventPriority.MONITOR,
ignoreCancelled = true)
public void onServerCommand(ServerCommandEvent event) {
String command = event.getCommand();
String[] args = CommandUtils.extractArgs(command);
if (!command.contains("kit")) {
return;
}
if (!command.contains("kit")) {
return;
}
if (args.length < 2) {
return;
}
if (args.length < 2) {
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;
public class UpdateInventoryTask extends BukkitRunnable {
private Player player;
private Player player;
public UpdateInventoryTask(Player player) {
this.player = player;
}
public UpdateInventoryTask(Player player) {
this.player = player;
}
@SuppressWarnings("deprecation")
@Override
public void run() {
if (player.isValid()) {
player.updateInventory();
}
}
public void run() {
if (player.isValid()) {
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:
CAN_NOT_BIND: '&7你不能&c绑定&7这个物品'
CAN_NOT_UNBIND: '&7你不能&6解绑&7这个物品'
BINDED: '&7物品已经&a绑定&7到玩家&c%target%'
UNBINDED: '&7物品已经解绑'
BIND_FULL_INEVNTORY: '&a玩家&c%player%&a背包内的所有物品已绑定到玩家&6%target%'
BIND_INVENTORY: '&c你可能需要的命令: &a/bind <player> inventory'
BIND_ON_EQUIP: '&7当前物品已标记为 &4装备后绑定'
BIND_ON_PICKUP: '&7当前物品已标记为 &4拾取后绑定'
BIND_ON_USE: '&7当前物品已标记为 &4使用后绑定'
CAN_NOT_BIND_ON_EQUIP: '&7当前物品不能标记为 &4装备后绑定'
CAN_NOT_BIND_ON_PICKUP: '&7当前物品不能标记为 &4拾取后绑定'
CAN_NOT_BIND_ON_USE: '&7当前物品不能标记为 &4使用后绑定'
VERSION: '灵魂绑定(&3修改by喵♂呜) &r版本号'
CAN_NOT_USE_ON_CONSOLE: '抱歉 此命令不能在控制台使用'
PAGE_NOT_EXIST: '&c帮助页面不存在 请输入 /Soulbound help [0-%maxPages%]'
HELP_TITLE: '&7--[ &6灵魂绑定 帮助 &a-汉化by邱 &3-修改by喵♂呜 &7 ]-- 页面 %page%/%maxPages%'
HOW_DOES_IT_WORK: '&4* &c它是如何工作的'
HOW_DOES_IT_WORK_1: '&4* &c灵魂绑定的物品只有自己才能使用。'
HOW_DOES_IT_WORK_2: '&4* &c绑定后的物品某些行为将会被阻止:'
HOW_DOES_IT_WORK_3: '&4* &c扔在地上、或者放到箱子里让其他玩家拿。'
HOW_DOES_IT_WORK_4: '&4* &c标记为 &4拾取后绑定 &c的物品'
HOW_DOES_IT_WORK_4_1: ' &c一旦被玩家捡起来就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_5: '&4* &c标记为 &4使用后绑定 &c的物品'
HOW_DOES_IT_WORK_5_1: ' &c只要拿在手中左键或者右键就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_6: '&4* &c标记为 &4装备后绑定 &c的物品'
HOW_DOES_IT_WORK_6_1: ' &c装备到身上后就能立即绑定成为该玩家的物品。'
CMD: '&6指令:'
CMDVERSION: '&4* &a/soulbound &7查看插件版本。'
CMD_BIND: '&4* &a/bind <sender> &7绑定手上的物品。'
CMD_BIND_FULL_INVENTORY: '&4* &a/bind <sender> inventory &7绑定玩家背包里的所有物品。'
CMD_BIND_ON_EQUIP: '&4* &a/bindonequip &7将当前物品标记为 &4装备后绑定'
CMD_BIND_ON_PICKUP: '&4* &a/bindonpickup &7将当前物品标记为 &4拾取后绑定'
CMD_BIND_ON_USE: '&4* &a/bindonuse &7将当前物品标记为 &4使用后绑定'
CMD_UNBIND: '&4* &a/unbind &7解除手中物品的绑定。'
CMD_NEXT: '&6使用 /soulbound help %nextPage% 查看更多'
CMD_USE: '使用: /soulbound [reload | help]'
RELOAD: '&a配置文件已重载...'
#提示消息
Message:
CAN_NOT_BIND: '&7你不能&c绑定&7这个物品'
CAN_NOT_UNBIND: '&7你不能&6解绑&7这个物品'
BINDED: '&7物品已经&a绑定&7到玩家&c%target%'
UNBINDED: '&7物品已经解绑'
BIND_FULL_INEVNTORY: '&a玩家&c%player%&a背包内的所有物品已绑定到玩家&6%target%'
BIND_INVENTORY: '&c你可能需要的命令: &a/bind <player> inventory'
BIND_ON_EQUIP: '&7当前物品已标记为 &4装备后绑定'
BIND_ON_PICKUP: '&7当前物品已标记为 &4拾取后绑定'
BIND_ON_USE: '&7当前物品已标记为 &4使用后绑定'
CAN_NOT_BIND_ON_EQUIP: '&7当前物品不能标记为 &4装备后绑定'
CAN_NOT_BIND_ON_PICKUP: '&7当前物品不能标记为 &4拾取后绑定'
CAN_NOT_BIND_ON_USE: '&7当前物品不能标记为 &4使用后绑定'
VERSION: '灵魂绑定(&3修改by喵♂呜) &r版本号'
CAN_NOT_USE_ON_CONSOLE: '抱歉 此命令不能在控制台使用'
PAGE_NOT_EXIST: '&c帮助页面不存在 请输入 /Soulbound help [0-%maxPages%]'
HELP_TITLE: '&7--[ &6灵魂绑定 帮助 &a-汉化by邱 &3-修改by喵♂呜 &7 ]-- 页面 %page%/%maxPages%'
HOW_DOES_IT_WORK: '&4* &c它是如何工作的'
HOW_DOES_IT_WORK_1: '&4* &c灵魂绑定的物品只有自己才能使用。'
HOW_DOES_IT_WORK_2: '&4* &c绑定后的物品某些行为将会被阻止:'
HOW_DOES_IT_WORK_3: '&4* &c扔在地上、或者放到箱子里让其他玩家拿。'
HOW_DOES_IT_WORK_4: '&4* &c标记为 &4拾取后绑定 &c的物品'
HOW_DOES_IT_WORK_4_1: ' &c一旦被玩家捡起来就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_5: '&4* &c标记为 &4使用后绑定 &c的物品'
HOW_DOES_IT_WORK_5_1: ' &c只要拿在手中左键或者右键就会立即绑定成为该玩家的物品。'
HOW_DOES_IT_WORK_6: '&4* &c标记为 &4装备后绑定 &c的物品'
HOW_DOES_IT_WORK_6_1: ' &c装备到身上后就能立即绑定成为该玩家的物品。'
CMD: '&6指令:'
CMDVERSION: '&4* &a/soulbound &7查看插件版本。'
CMD_BIND: '&4* &a/bind <sender> &7绑定手上的物品。'
CMD_BIND_FULL_INVENTORY: '&4* &a/bind <sender> inventory &7绑定玩家背包里的所有物品。'
CMD_BIND_ON_EQUIP: '&4* &a/bindonequip &7将当前物品标记为 &4装备后绑定'
CMD_BIND_ON_PICKUP: '&4* &a/bindonpickup &7将当前物品标记为 &4拾取后绑定'
CMD_BIND_ON_USE: '&4* &a/bindonuse &7将当前物品标记为 &4使用后绑定'
CMD_UNBIND: '&4* &a/unbind &7解除手中物品的绑定。'
CMD_NEXT: '&6使用 /soulbound help %nextPage% 查看更多'
CMD_USE: '使用: /soulbound [reload | help]'
RELOAD: '&a配置文件已重载...'

View File

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