static public void loadMessage(){
File messageFile = new File("plugins" + File.separator + "PVPAsWantedManager" + File.separator + "message.yml");
if(!messageFile.exists()){
if(Config.getConfig("language").equals("CN")){
createCNMessage();
}else if(Config.getConfig("language").equals("EN")){
//TODO createENMessage();
}else{
createCNMessage();
}
}else{
Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §aFind Message.yml");
}
messages = new YamlConfiguration();
try {messages.load(messageFile);} catch (IOException | InvalidConfigurationException e) {e.printStackTrace();Bukkit.getConsoleSender().sendMessage("§8[§6PVPAsWantedManager§8] §a读取message时发生错误");}
}
java类org.bukkit.configuration.InvalidConfigurationException的实例源码
Message.java 文件源码
项目:PVPAsWantedManager
阅读 27
收藏 0
点赞 0
评论 0
PlayerEvent.java 文件源码
项目:WC
阅读 22
收藏 0
点赞 0
评论 0
@EventHandler
public void onJoin(PlayerJoinEvent event){
Player p = event.getPlayer();
if(!Files.user.contains("Users." + p.getName())){
Files.user.set("Users." + p.getName() + ".pvp", false);
manager.addNewbie(p);
try{
Files.user.save(Files.users);
Files.user.load(Files.users);
}catch(IOException | InvalidConfigurationException e){
e.printStackTrace();
}
return;
}
}
PlayerEvent.java 文件源码
项目:WC
阅读 22
收藏 0
点赞 0
评论 0
@EventHandler
public void onLeave(PlayerQuitEvent event){
Player p = event.getPlayer();
if(Files.user.contains("Users." + p.getName())){
try{
Files.user.save(Files.users);
Files.user.load(Files.users);
}catch(IOException | InvalidConfigurationException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
if(manager.isInPvP(p)){
p.setHealth(0D);
Bukkit.broadcastMessage(Message.prefix + ChatColor.GRAY + " ¡" + ChatColor.GOLD + p.getName() + Message.leave_in_pvp);
}
}
}
Files.java 文件源码
项目:WC
阅读 26
收藏 0
点赞 0
评论 0
public void saveFiles(){
try{
config.save(fileConfig);
users.save(fileUsers);
fl.save(fileFL);
casino.save(fileCasino);
rain.save(fileRain);
config.load(fileConfig);
users.load(fileUsers);
fl.load(fileFL);
casino.load(fileCasino);
rain.load(fileRain);
}catch (java.io.IOException | InvalidConfigurationException e){
e.printStackTrace();
}
}
InventoryUtils.java 文件源码
项目:Transport-Pipes
阅读 27
收藏 0
点赞 0
评论 0
public static ItemStack StringToItemStack(String string) {
if (string == null) {
return null;
}
YamlConfiguration yaml = new YamlConfiguration();
try {
yaml.loadFromString(string);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
if (yaml.contains("item")) {
return yaml.getItemStack("item", null);
} else {
return yaml.getItemStack("i", null);
}
}
BungeeCordController.java 文件源码
项目:BlockBall
阅读 26
收藏 0
点赞 0
评论 0
private void load(JavaPlugin plugin) {
try {
final FileConfiguration configuration = new YamlConfiguration();
final File file = new File(plugin.getDataFolder(), "bungeecord_signs.yml");
if (!file.exists()) {
if (!file.createNewFile()) {
Bukkit.getLogger().log(Level.WARNING, "File cannot get created.");
}
}
configuration.load(file);
if (configuration.getConfigurationSection("signs") != null) {
final Map<String, Object> data = configuration.getConfigurationSection("signs").getValues(false);
for (final String s : data.keySet()) {
this.signs.add(new BungeeCordSignInfo.Container(((ConfigurationSection) data.get(s)).getValues(true)));
}
}
} catch (IOException | InvalidConfigurationException e) {
Bukkit.getLogger().log(Level.WARNING, "Save load location.", e);
}
}
ArenaFileManager.java 文件源码
项目:BlockBall
阅读 25
收藏 0
点赞 0
评论 0
void save(Arena item) {
if (item != null && item.getName() != null) {
try {
final FileConfiguration configuration = new YamlConfiguration();
final File file = new File(this.getFolder(), "arena_" + item.getName() + ".yml");
if (file.exists()) {
if (!file.delete())
throw new IllegalStateException("Cannot delete file!");
}
if (!file.createNewFile())
throw new IllegalStateException("Cannot create file!");
configuration.load(file);
final Map<String, Object> data = item.serialize();
for (final String key : data.keySet()) {
configuration.set("arena." + key, data.get(key));
}
configuration.save(file);
} catch (IOException | InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.WARNING,"Cannot save arena." ,ex.getMessage());
}
}
}
ConfigManager.java 文件源码
项目:DogTags
阅读 27
收藏 0
点赞 0
评论 0
public static void create() throws IOException{
File pluginFolder = DogTags.getInstance().getDataFolder();
f = new File(pluginFolder, "config.yml");
if(!f.exists()){
f.getParentFile().mkdirs();
DogTags.getInstance().saveResource(f.getName(), false);
LogUtil.outputMsg("File &6%file% &fdoesn't exist, creating file!".replace("%file%", f.getName()));
}
fc = new YamlConfiguration();
try {
fc.load(f);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
Module.java 文件源码
项目:DungeonGen
阅读 25
收藏 0
点赞 0
评论 0
/**Static method to get a modules config alone, returns null if failed.
* The loading is tested during the initial yml test and should therefore work during DunGen runtime.
* @param parent The parent plugin
* @param name The modules name for witch the config should be loaded (file 'name'.yml)
* @return The config object. Returns null if errors occured and sets plugin state to ERROR.
*/
public static YamlConfiguration getConfig(DunGen parent, String name) {
File confFile = new File(parent.getDataFolder(),name+".yml");
if (!confFile.exists()) {
parent.setStateAndNotify(State.ERROR, "Config file for module " + name + " could not be found!");
return null;
}
YamlConfiguration conf = new YamlConfiguration();
try {
conf.load(confFile);
}catch (IOException | InvalidConfigurationException e) {
parent.setStateAndNotify(State.ERROR, "Loading of config file for module " + name + " failed:");
e.printStackTrace();
return null;
}
// everything ok, if code reached here.
parent.getLogger().info("YML file for module " + name + " loaded.");
return conf;
}
AudioConnectClient.java 文件源码
项目:AudioConnect
阅读 28
收藏 0
点赞 0
评论 0
private void finishHandshake(ChannelHandlerContext ctx, FullHttpResponse response) {
if (response.getStatus().equals(HttpResponseStatus.SWITCHING_PROTOCOLS)) {
try {
handshaker.finishHandshake(ctx.channel(), response);
connection.handshakeFuture.setSuccess();
logger.info("Successfully connected to AudioConnect server!");
return;
} catch (Exception e) {
connection.handshakeFuture.setFailure(e);
}
} else {
connection.handshakeFuture.setFailure(new InvalidConfigurationException());
}
String responseMsg = response.content().toString(StandardCharsets.UTF_8);
logger.severe("Failed to Connect with AudioConnect server: " + responseMsg);
logger.severe("Stopping client event loop due to failure to establish connection with AudioConnect server");
disconnect();
}
OptionCfg.java 文件源码
项目:GameBoxx
阅读 24
收藏 0
点赞 0
评论 0
/**
* Creates the config file if it doesn't exist yet.
* If there are exceptions the stacktrace will be printed.
*/
private void createFile() {
if (file == null) {
new InvalidConfigurationException("File cannot be null!").printStackTrace();
}
try {
if (!file.exists()) {
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
}
}
EasyConfig.java 文件源码
项目:GameBoxx
阅读 23
收藏 0
点赞 0
评论 0
/**
* Load the config file in to memory.
* The value of all fields will be set with the config values.
*/
public void load() {
if (file != null) {
try {
if (!file.exists()) {
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
conf.load(file);
if (fields == null) {
onLoad(conf);
} else {
onLoad(conf, fields);
}
conf.save(file);
} catch (Exception e) {
e.printStackTrace();
}
} else {
new InvalidConfigurationException("File cannot be null!").printStackTrace();
}
}
EasyConfig.java 文件源码
项目:GameBoxx
阅读 50
收藏 0
点赞 0
评论 0
/**
* Save the config file to disk.
* All values from the fields will be placed in the config.
*/
public void save() {
if (file != null) {
try {
if (!file.exists()) {
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
file.createNewFile();
}
if (fields == null) {
onSave(conf);
} else {
onSave(conf, fields);
}
conf.save(file);
} catch (Exception e) {
e.printStackTrace();
}
} else {
new InvalidConfigurationException("File cannot be null!").printStackTrace();
}
}
Database.java 文件源码
项目:HamsterEcoHelper
阅读 26
收藏 0
点赞 0
评论 0
public List<ItemStack> getTemporaryStorage(OfflinePlayer player) {
Query<TempStorageRepo> result = query(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString());
if (result == null || result.count() == 0) return Collections.emptyList();
YamlConfiguration cfg = new YamlConfiguration();
try {
cfg.loadFromString(result.selectUnique().yaml);
} catch (InvalidConfigurationException ex) {
ex.printStackTrace();
return Collections.emptyList();
}
List<ItemStack> ret = new ArrayList<>();
for (String key : cfg.getKeys(false)) {
ret.add(cfg.getItemStack(key));
}
return ret;
}
SignShop.java 文件源码
项目:HamsterEcoHelper
阅读 27
收藏 0
点赞 0
评论 0
public List<ShopItem> loadItems(String path) {
YamlConfiguration configuration = new YamlConfiguration();
try {
configuration.loadFromString(this.yaml);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
ArrayList<ShopItem> list = new ArrayList<>();
if (configuration.isConfigurationSection(path)) {
ConfigurationSection section = configuration.getConfigurationSection(path);
for (String k : section.getKeys(false)) {
list.add(new ShopItem(section.getConfigurationSection(k)));
}
}
return list;
}
SignShop.java 文件源码
项目:HamsterEcoHelper
阅读 24
收藏 0
点赞 0
评论 0
public void saveItems(String path, List<ShopItem> list) {
YamlConfiguration configuration = new YamlConfiguration();
try {
configuration.loadFromString(this.yaml);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
configuration.set(path, null);
ConfigurationSection section = configuration.createSection(path);
for (int i = 0; i < list.size(); i++) {
ShopItem item = list.get(i);
if (item.getAmount() > 0 && item.getItemStack(1).getType() != Material.AIR) {
list.get(i).save(section.createSection(String.valueOf(i)));
}
}
this.yaml = configuration.saveToString();
}
FileConfiguration.java 文件源码
项目:Thermos-Bukkit
阅读 22
收藏 0
点赞 0
评论 0
/**
* Loads this {@link FileConfiguration} from the specified reader.
* <p>
* All the values contained within this configuration will be removed,
* leaving only settings and defaults, and the new values will be loaded
* from the given stream.
*
* @param reader the reader to load from
* @throws IOException thrown when underlying reader throws an IOException
* @throws InvalidConfigurationException thrown when the reader does not
* represent a valid Configuration
* @throws IllegalArgumentException thrown when reader is null
*/
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());
}
EquipmentConfiguration.java 文件源码
项目:QuestManager
阅读 30
收藏 0
点赞 0
评论 0
public void load(ConfigurationSection config) throws InvalidConfigurationException {
if (!config.contains("type") || !config.getString("type").equals("ecnf")) {
throw new InvalidConfigurationException();
}
head = config.getItemStack("head");
chest = config.getItemStack("chest");
legs = config.getItemStack("legs");
boots = config.getItemStack("boots");
if (config.contains("held")) {
heldMain = config.getItemStack("held");
heldOff = null;
} else {
heldMain = config.getItemStack("main");
heldOff = config.getItemStack("offhand");
}
}
GoalState.java 文件源码
项目:QuestManager
阅读 18
收藏 0
点赞 0
评论 0
public void load(ConfigurationSection config) throws InvalidConfigurationException {
if (!config.contains("type") || !config.getString("type").equals("goalstate")
|| !config.contains("name")) {
throw new InvalidConfigurationException();
}
name = config.getString("name");
requirementStates = new LinkedList<>();
if (config.contains("requirementStates"))
for (String reqKey : config.getConfigurationSection("requirementStates").getKeys(false)) {
requirementStates.add(
new RequirementState(
config.getConfigurationSection("requirementStates")
.getConfigurationSection(reqKey))
);
}
}
InteractRequirement.java 文件源码
项目:QuestManager
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
/*
* type: intr
* location: [loc]
* [face]: [face enum name]
* [action]: {LEFT/RIGHT}
*/
if (!config.contains("type") || !config.getString("type").equals("intr")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'intr' but got " + config.get("type", "null"));
}
this.location = ((LocationState) config.get("location")).getLocation();
if (config.contains("face")) {
this.face = BlockFace.valueOf(config.getString("face"));
}
if (config.contains("action")) {
this.action = getAction(config.getString("action"));
}
this.desc = config.getString("description", config.getString("action", "Right")
+ " click the area");
}
TimeRequirement.java 文件源码
项目:QuestManager
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
//we'll need start and end times
//our config is
// type: "timer"
// startTime: <long>
// endTime: <long>
if (!config.contains("type") || !config.getString("type").equals("timer")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'timer' but got " + config.getString("type", "null"));
}
this.startTime = config.getLong("startTime");
this.endTime = config.getLong("endTime");
this.desc = config.getString("description", "Wait until between " + startTime + " and " + endTime);
}
ArriveRequirement.java 文件源码
项目:QuestManager
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config)
throws InvalidConfigurationException {
// same of Position Requirements's loading
// type: "arrr"
// range: [double]
// destination: [location]
if (!config.contains("type") || !config.getString("type").equals("arrr")) {
throw new InvalidConfigurationException();
}
this.desc = config.getString("description", "Arrive at the location");
this.targetRange = config.getDouble("range", 1.0);
this.destination = ((LocationState) config.get("destination")).getLocation();
}
TalkRequirement.java 文件源码
项目:QuestManager
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
/*
* type: talk
* npc: [name]
* message: [menu]
*/
if (!config.contains("type") || !config.getString("type").equals("talk")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'talk' but got " + config.get("type", "null"));
}
if (config.getString("npc") == null) {
System.out.println("npc-null");
}
npc = QuestManagerPlugin.questManagerPlugin.getManager().getNPC(
config.getString("npc")
);
Message message = (Message) config.get("message");
message.setSourceLabel(new FancyMessage(npc.getName()));
menu = ChatMenu.getDefaultMenu(message);
this.desc = config.getString("description", "Talk to " + npc.getName());
}
CraftRequirement.java 文件源码
项目:QuestManager
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
/*
* type: craft
* crafttype: [MATERIAL]
* craftname: [string]
* count: [int]
*/
if (!config.contains("type") || !config.getString("type").equals("craft")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'craft' but got " + config.get("type", "null"));
}
this.craftType = Material.matchMaterial(config.getString("craftType"));
this.craftName = config.getString("craftName");
this.targetCount = config.getInt("count");
this.desc = config.getString("description", "Craft " + targetCount + " "
+ (craftName == null ? YamlWriter.toStandardFormat(craftType.name()) : craftName) + "(s)");
}
DeliverRequirement.java 文件源码
项目:QuestManager
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
//we need to load information about what we need to possess and how much
//our config is
// type: "delr"
// itemYype: (Material. ENUM CONSTANT NAME)
// count: [int]
// name: [string]
if (!config.contains("type") || !config.getString("type").equals("delr")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'delr' but got " + config.getString("type", "null"));
}
this.itemType = Material.valueOf(
config.getString("itemType", "AIR"));
this.itemCount = config.getInt("count", 1);
this.itemName = config.getString("name", "");
if (itemName.trim().isEmpty()) {
itemName = null;
}
this.desc = config.getString("description", "Collect " + itemCount + " " +
itemName == null ? itemType.toString() : itemName);
}
PositionRequirement.java 文件源码
项目:QuestManager
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config)
throws InvalidConfigurationException {
//we need location information and range information
// type: "posr"
// range: [double]
// destination: [location]
if (!config.contains("type") || !config.getString("type").equals("posr")) {
throw new InvalidConfigurationException();
}
this.desc = config.getString("description", "Be in the target area");
this.targetRange = config.getDouble("range", 1.0);
this.destination = ((LocationState) config.get("destination")).getLocation();
}
ChestRequirement.java 文件源码
项目:QuestManager
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
/*
* type: chestr
* chest: [chest]
*/
if (!config.contains("type") || !config.getString("type").equals("chestr")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'chestr' but got " + config.get("type", "null"));
}
if (!config.contains("chest")) {
throw new InvalidConfigurationException("\nChest configuration did not contain chest information!");
}
this.chest = (Chest) config.get("chest");
this.inv = null;
this.desc = config.getString("description", "Search the chest");
}
PossessRequirement.java 文件源码
项目:QuestManager
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void fromConfig(ConfigurationSection config) throws InvalidConfigurationException {
//we need to load information about what we need to possess and how much
//our config is
// type: "pr"
// itemYype: (Material. ENUM CONSTANT NAME)
// count: [int]
if (!config.contains("type") || !config.getString("type").equals("pr")) {
throw new InvalidConfigurationException("\n ---Invalid type! Expected 'pr' but got " + config.getString("type", "null"));
}
this.itemType = Material.valueOf(
config.getString("itemType", "AIR"));
this.itemCount = config.getInt("count", 1);
this.itemName = config.getString("name", "");
if (itemName.trim().isEmpty()) {
itemName = null;
}
this.desc = config.getString("description", "Collect " + itemCount + " " +
itemName == null ? itemType.toString() : itemName);
}
History.java 文件源码
项目:QuestManager
阅读 59
收藏 0
点赞 0
评论 0
public static History fromConfig(ConfigurationSection configurationSection) throws InvalidConfigurationException {
if (configurationSection == null) {
return null;
}
if (!configurationSection.contains("HistoryEvents")) {
throw new InvalidConfigurationException();
}
History history = new History();
List<String> list;
list = configurationSection.getStringList("HistoryEvents");
if (list != null && !list.isEmpty()) {
for (String line : list) {
history.addHistoryEvent(new HistoryEvent(line));
}
}
return history;
}
Goal.java 文件源码
项目:QuestManager
阅读 25
收藏 0
点赞 0
评论 0
public void loadState(GoalState state) throws InvalidConfigurationException {
if (!state.getName().equals(name)) {
QuestManagerPlugin.logger.warning("Loading state information"
+ "from a file that has a mismatched goal name!");
}
//WARNING:
//this is assuming that the lists are maintianed in the right order.
//it should work this way, but this is a point of error!
ListIterator<RequirementState> states = state.getRequirementStates().listIterator();
for (Requirement req : requirements) {
req.sync();
try {
if (req instanceof StatekeepingRequirement) {
((StatekeepingRequirement) req).loadState(states.next());
}
} catch (NoSuchElementException e) {
QuestManagerPlugin.logger.warning("Error when loading state for quest"
+ this.getQuest().getName() + "; Not enough requirement states!");
}
}
}