mirror of
https://e.coding.net/circlecloud/ResFly.git
synced 2024-11-24 11:18:47 +00:00
修复加载失败的问题 添加版本检查...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
9de1a57cae
commit
d0cb5d2660
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>ResFly</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
<name>ResFly</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
|
@ -5,34 +5,35 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.ResFly.config.Config;
|
||||
import cn.citycraft.ResFly.listen.PlayerListen;
|
||||
|
||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import cn.citycraft.ResFly.listen.PlayerListen;
|
||||
|
||||
public class ResFly extends JavaPlugin {
|
||||
|
||||
public String servername;
|
||||
public FileConfig config;
|
||||
public String pluginname;
|
||||
public String servername;
|
||||
|
||||
public String getfullmsg(String path) {
|
||||
return servername + pluginname + " " + getmessage(path);
|
||||
public String getfullmsg(final String path) {
|
||||
return this.servername + this.pluginname + " " + getmessage(path);
|
||||
}
|
||||
|
||||
public String getmessage(String path) {
|
||||
return Config.getMessage(path);
|
||||
public String getmessage(final String path) {
|
||||
return this.config.getMessage(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
Plugin res = pm.getPlugin("Residence");
|
||||
if (Config.getInstance().getBoolean("ResFly.Enable", true)) {
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
final Plugin res = pm.getPlugin("Residence");
|
||||
if (this.config.getBoolean("ResFly.Enable", true)) {
|
||||
if (res != null && res.isEnabled()) {
|
||||
FlagPermissions.addFlag("fly");
|
||||
FlagPermissions.addResidenceOnlyFlag("fly");
|
||||
Bukkit.getPluginManager()
|
||||
.registerEvents(new PlayerListen(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListen(this), this);
|
||||
getLogger().info("玩家领地飞行控制已加载!");
|
||||
} else {
|
||||
getLogger().info("未找到领地插件停止加载领地飞行!");
|
||||
@ -40,13 +41,14 @@ public class ResFly extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
}
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Config.load(this);
|
||||
servername = getmessage("servername");
|
||||
pluginname = getmessage("pluginname");
|
||||
this.config = new FileConfig(this);
|
||||
this.servername = getmessage("servername");
|
||||
this.pluginname = getmessage("pluginname");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
package cn.citycraft.ResFly.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class Config extends ConfigLoader {
|
||||
private static String CONFIG_NAME = "config.yml";
|
||||
private static FileConfig instance;
|
||||
private static File file;
|
||||
|
||||
public Config(Plugin p) {
|
||||
super(p, CONFIG_NAME);
|
||||
file = new File(p.getDataFolder(), CONFIG_NAME);
|
||||
instance = super.getInstance();
|
||||
}
|
||||
|
||||
public Config(Plugin p, String ver) {
|
||||
super(p, CONFIG_NAME, ver);
|
||||
instance = super.getInstance();
|
||||
}
|
||||
|
||||
public static void load(Plugin p) {
|
||||
new Config(p);
|
||||
}
|
||||
|
||||
public static void load(Plugin p, String ver) {
|
||||
new Config(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[] 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package cn.citycraft.ResFly.config;
|
||||
|
||||
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.getParentFile().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() + "保存错误...");
|
||||
}
|
||||
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package cn.citycraft.ResFly.config;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -9,47 +9,27 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
|
||||
import cn.citycraft.ResFly.ResFly;
|
||||
|
||||
import com.bekvon.bukkit.residence.event.ResidenceChangedEvent;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent;
|
||||
import com.bekvon.bukkit.residence.event.ResidenceFlagChangeEvent;
|
||||
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
||||
|
||||
import cn.citycraft.ResFly.ResFly;
|
||||
|
||||
public class PlayerListen implements Listener {
|
||||
|
||||
HashMap<Player, Player> fall = new HashMap<Player, Player>();
|
||||
ResFly plugin;
|
||||
|
||||
public PlayerListen(ResFly main) {
|
||||
plugin = main;
|
||||
public PlayerListen(final ResFly main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
void ChangePlayerFly(Player p, boolean fly) {
|
||||
if (p.getAllowFlight() && !fly) {
|
||||
if (p.isFlying()) {
|
||||
fall.put(p, p);
|
||||
}
|
||||
p.setAllowFlight(false);
|
||||
p.sendMessage(plugin.getfullmsg("Message.Not_Allow"));
|
||||
}
|
||||
if (!p.getAllowFlight() && fly) {
|
||||
if (p == fall.get(p)) {
|
||||
fall.remove(p);
|
||||
}
|
||||
p.setAllowFlight(true);
|
||||
p.sendMessage(plugin.getfullmsg("Message.Allow"));
|
||||
}
|
||||
}
|
||||
|
||||
// ResidenceDeleteEvent.class
|
||||
// ResidenceFlagChangeEvent.class
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void FlagChange(ResidenceFlagChangeEvent e) {
|
||||
ClaimedResidence res = e.getResidence();
|
||||
for (Player p : res.getPlayersInResidence()) {
|
||||
public void FlagChange(final ResidenceFlagChangeEvent e) {
|
||||
final ClaimedResidence res = e.getResidence();
|
||||
for (final Player p : res.getPlayersInResidence()) {
|
||||
if (!permCheck(p)) {
|
||||
if (!resPermCheck(res, p)) {
|
||||
ChangePlayerFly(p, false);
|
||||
@ -60,27 +40,23 @@ public class PlayerListen implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onFallDamage(EntityDamageEvent e) {
|
||||
public void onFallDamage(final EntityDamageEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player p = (Player) e.getEntity();
|
||||
final Player p = (Player) e.getEntity();
|
||||
if (e.getCause() == DamageCause.FALL) {
|
||||
if (p == fall.get(p)) {
|
||||
fall.remove(p);
|
||||
if (p == this.fall.get(p)) {
|
||||
this.fall.remove(p);
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(plugin.getfullmsg("Message.Protect"));
|
||||
p.sendMessage(this.plugin.getfullmsg("Message.Protect"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean permCheck(Player p) {
|
||||
return p.hasPermission("resfly.ignore") || p.isOp() || p.getGameMode() == GameMode.CREATIVE;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void resChange(ResidenceChangedEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ClaimedResidence resto = event.getTo();
|
||||
public void resChange(final ResidenceChangedEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final ClaimedResidence resto = event.getTo();
|
||||
if (!permCheck(player)) {
|
||||
if (!resPermCheck(resto, player)) {
|
||||
ChangePlayerFly(player, false);
|
||||
@ -91,19 +67,41 @@ public class PlayerListen implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void ResDelete(ResidenceDeleteEvent e) {
|
||||
ClaimedResidence res = e.getResidence();
|
||||
for (Player p : res.getPlayersInResidence()) {
|
||||
public void ResDelete(final ResidenceDeleteEvent e) {
|
||||
final ClaimedResidence res = e.getResidence();
|
||||
for (final Player p : res.getPlayersInResidence()) {
|
||||
if (!permCheck(p)) {
|
||||
ChangePlayerFly(p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean resPermCheck(ClaimedResidence res, Player p) {
|
||||
if (res == null)
|
||||
void ChangePlayerFly(final Player p, final boolean fly) {
|
||||
if (p.getAllowFlight() && !fly) {
|
||||
if (p.isFlying()) {
|
||||
this.fall.put(p, p);
|
||||
}
|
||||
p.setAllowFlight(false);
|
||||
p.sendMessage(this.plugin.getfullmsg("Message.Not_Allow"));
|
||||
}
|
||||
if (!p.getAllowFlight() && fly) {
|
||||
if (p == this.fall.get(p)) {
|
||||
this.fall.remove(p);
|
||||
}
|
||||
p.setAllowFlight(true);
|
||||
p.sendMessage(this.plugin.getfullmsg("Message.Allow"));
|
||||
}
|
||||
}
|
||||
|
||||
boolean permCheck(final Player p) {
|
||||
return p.hasPermission("ResFly.ignore") || p.isOp() || p.getGameMode() == GameMode.CREATIVE;
|
||||
}
|
||||
|
||||
boolean resPermCheck(final ClaimedResidence res, final Player p) {
|
||||
if (res == null) {
|
||||
return false;
|
||||
ResidencePermissions perms = res.getPermissions();
|
||||
}
|
||||
final ResidencePermissions perms = res.getPermissions();
|
||||
return perms.playerHas(p.getName(), "fly", false);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
name: ResFly
|
||||
main: cn.citycraft.ResFly.ResFly
|
||||
version: 0.0.1
|
||||
depended: [Residence]
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-Build#${env.BUILD_NUMBER}
|
||||
author: 喵♂呜
|
||||
website: ${jenkins.url}/job/${project.artifactId}/
|
||||
permissions:
|
||||
resfly.ignore:
|
||||
description: 允许忽略领地飞行限制!
|
||||
${project.artifactId}.ignore:
|
||||
description: 忽略飞行检测!
|
||||
default: op
|
Loading…
Reference in New Issue
Block a user