Skip to content

Commit

Permalink
SpectatorPlus S1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
pgmann committed Jun 9, 2014
1 parent 8cd1d54 commit 88e947c
Show file tree
Hide file tree
Showing 6 changed files with 1,049 additions and 961 deletions.
50 changes: 25 additions & 25 deletions SpectatorPlus/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: SpectatorPlus
main: com.pgcraft.spectatorplus.SpectatorPlus
version: '1.8'
description: "Lets players spectate other competitors in events, games, etc. when they're not playing. Allows them to fly but stops them helping other players. Do [/spec help] for help!"
author: pgmann
commands:
spectate:
description: 'See [/spec help] for help'
usage: 'Do /spectate help to see the plugin help'
aliases: spec
permissions:
spectate.*:
description: Allows you to spectate and stops players spectating you
children:
spectate.use: true
spectate.hide: true
default: false
spectate.use:
description: Allows you to spectate
default: op
spectate.hide:
description: Stops players spectating you
default: false
spectate.set:
description: Allows you to set the spectator lobby
name: SpectatorPlus
main: com.pgcraft.spectatorplus.SpectatorPlus
version: '1.8'
description: "Lets players spectate other competitors in events, games, etc. when they're not playing. Allows them to fly but stops them helping other players. Do [/spec help] for help!"
author: pgmann
commands:
spectate:
description: 'See [/spec help] for help'
usage: 'Do /spectate help to see the plugin help'
aliases: spec
permissions:
spectate.*:
description: Allows you to spectate and stops players spectating you
children:
spectate.use: true
spectate.hide: true
default: false
spectate.use:
description: Allows you to spectate
default: op
spectate.hide:
description: Stops players spectating you
default: false
spectate.admin:
description: Allows you to set the spectator lobby
default: op
1 change: 1 addition & 0 deletions SpectatorPlus/spectators.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# List of all players in spectator mode
188 changes: 97 additions & 91 deletions SpectatorPlus/src/com/pgcraft/spectatorplus/ConfigAccessor.java
Original file line number Diff line number Diff line change
@@ -1,92 +1,98 @@
/*
* Copyright (C) 2012
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* <pgmann> Thanks to author of this class! All credit goes to them.
*/
package com.pgcraft.spectatorplus;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

public class ConfigAccessor {

private final String fileName;
private final JavaPlugin plugin;

private File configFile;
private FileConfiguration fileConfiguration;

public ConfigAccessor(JavaPlugin plugin, String fileName) {
if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}
this.plugin = plugin;
this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (dataFolder == null) {
throw new IllegalStateException();
}
this.configFile = new File(plugin.getDataFolder(), fileName+".yml");
}

public void reloadConfig() {
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);

// Look for defaults in the jar
InputStream defConfigStream = plugin.getResource(fileName+".yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
fileConfiguration.setDefaults(defConfig);
}
}

public FileConfiguration getConfig() {
if (fileConfiguration == null) {
this.reloadConfig();
}
return fileConfiguration;
}

public void saveConfig() {
if (fileConfiguration == null || configFile == null) {
return;
} else {
try {
getConfig().save(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}

public void saveDefaultConfig() {
if (!configFile.exists()) {
this.plugin.saveResource(fileName+".yml", false);
}
}

/*
* Copyright (C) 2012
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* <pgmann> Thanks to author of this class! All credit goes to them.
*/
package com.pgcraft.spectatorplus;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

public class ConfigAccessor {

private final String fileName;
private final JavaPlugin plugin;

private File configFile;
private FileConfiguration fileConfiguration;

public ConfigAccessor(JavaPlugin plugin, String fileName) {
if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}
this.plugin = plugin;
this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (dataFolder == null) {
throw new IllegalStateException();
}
this.configFile = new File(plugin.getDataFolder(), fileName+".yml");
}

public void reloadConfig() {
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);

// Look for defaults in the jar
InputStream defConfigStream = plugin.getResource(fileName+".yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
fileConfiguration.setDefaults(defConfig);
}
}

public FileConfiguration getConfig() {
if (fileConfiguration == null) {
this.reloadConfig();
}
return fileConfiguration;
}

public void saveConfig() {
if (fileConfiguration == null || configFile == null) {
return;
} else {
try {
getConfig().save(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}

public void saveDefaultConfig() {
if (!configFile.exists()) {
this.plugin.saveResource(fileName+".yml", false);
}
}

public void saveDefaultConfig(boolean force) {
if (force) {
this.plugin.saveResource(fileName+".yml", true);
}
}

}
Loading

0 comments on commit 88e947c

Please sign in to comment.