Code cleanup
This commit is contained in:
parent
3be9124344
commit
624c9b52d7
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
target/
|
||||||
|
.idea/
|
2
pom.xml
2
pom.xml
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.milkbowl.vault</groupId>
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
|
@ -76,8 +76,7 @@ public class EconomyHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean useEconomy() {
|
public static boolean useEconomy() {
|
||||||
if(!economyEnabled || economy == null) return false;
|
return economyEnabled && economy != null;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ public class Gate {
|
|||||||
public static final int ENTRANCE = -2;
|
public static final int ENTRANCE = -2;
|
||||||
public static final int CONTROL = -3;
|
public static final int CONTROL = -3;
|
||||||
public static final int EXIT = -4;
|
public static final int EXIT = -4;
|
||||||
private static HashMap<String, Gate> gates = new HashMap<String, Gate>();
|
private static HashMap<String, Gate> gates = new HashMap<>();
|
||||||
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
|
private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<>();
|
||||||
private static HashSet<Integer> frameBlocks = new HashSet<Integer>();
|
private static HashSet<Integer> frameBlocks = new HashSet<>();
|
||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
private Character[][] layout;
|
private Character[][] layout;
|
||||||
@ -51,7 +51,7 @@ public class Gate {
|
|||||||
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
||||||
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
||||||
private RelativeBlockVector exitBlock = null;
|
private RelativeBlockVector exitBlock = null;
|
||||||
private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
|
private HashMap<RelativeBlockVector, Integer> exits = new HashMap<>();
|
||||||
private int portalBlockOpen = Material.PORTAL.getId();
|
private int portalBlockOpen = Material.PORTAL.getId();
|
||||||
private int portalBlockClosed = Material.AIR.getId();
|
private int portalBlockClosed = Material.AIR.getId();
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ public class Gate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populateCoordinates() {
|
private void populateCoordinates() {
|
||||||
ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
|
ArrayList<RelativeBlockVector> entranceList = new ArrayList<>();
|
||||||
ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
|
ArrayList<RelativeBlockVector> borderList = new ArrayList<>();
|
||||||
ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
|
ArrayList<RelativeBlockVector> controlList = new ArrayList<>();
|
||||||
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
||||||
int[] exitDepths = new int[layout[0].length];
|
int[] exitDepths = new int[layout[0].length];
|
||||||
RelativeBlockVector lastExit = null;
|
RelativeBlockVector lastExit = null;
|
||||||
@ -312,11 +312,11 @@ public class Gate {
|
|||||||
public static Gate loadGate(File file) {
|
public static Gate loadGate(File file) {
|
||||||
Scanner scanner = null;
|
Scanner scanner = null;
|
||||||
boolean designing = false;
|
boolean designing = false;
|
||||||
ArrayList<ArrayList<Character>> design = new ArrayList<ArrayList<Character>>();
|
ArrayList<ArrayList<Character>> design = new ArrayList<>();
|
||||||
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
HashMap<Character, Integer> types = new HashMap<>();
|
||||||
HashMap<Character, Integer> metadata = new HashMap<Character, Integer>();
|
HashMap<Character, Integer> metadata = new HashMap<>();
|
||||||
HashMap<String, String> config = new HashMap<String, String>();
|
HashMap<String, String> config = new HashMap<>();
|
||||||
HashSet<Integer> frameTypes = new HashSet<Integer>();
|
HashSet<Integer> frameTypes = new HashSet<>();
|
||||||
int cols = 0;
|
int cols = 0;
|
||||||
|
|
||||||
// Init types map
|
// Init types map
|
||||||
@ -331,7 +331,7 @@ public class Gate {
|
|||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
if (designing) {
|
if (designing) {
|
||||||
ArrayList<Character> row = new ArrayList<Character>();
|
ArrayList<Character> row = new ArrayList<>();
|
||||||
|
|
||||||
if (line.length() > cols) {
|
if (line.length() > cols) {
|
||||||
cols = line.length();
|
cols = line.length();
|
||||||
@ -460,13 +460,13 @@ public class Gate {
|
|||||||
{'X', '*', '.', 'X'},
|
{'X', '*', '.', 'X'},
|
||||||
{' ', 'X', 'X', ' '},
|
{' ', 'X', 'X', ' '},
|
||||||
};
|
};
|
||||||
HashMap<Character, Integer> types = new HashMap<Character, Integer>();
|
HashMap<Character, Integer> types = new HashMap<>();
|
||||||
types.put('.', ENTRANCE);
|
types.put('.', ENTRANCE);
|
||||||
types.put('*', EXIT);
|
types.put('*', EXIT);
|
||||||
types.put(' ', ANYTHING);
|
types.put(' ', ANYTHING);
|
||||||
types.put('X', Obsidian);
|
types.put('X', Obsidian);
|
||||||
types.put('-', Obsidian);
|
types.put('-', Obsidian);
|
||||||
HashMap<Character, Integer> metadata = new HashMap<Character, Integer>();
|
HashMap<Character, Integer> metadata = new HashMap<>();
|
||||||
|
|
||||||
Gate gate = new Gate("nethergate.gate", layout, types, metadata);
|
Gate gate = new Gate("nethergate.gate", layout, types, metadata);
|
||||||
gate.save(gateFolder);
|
gate.save(gateFolder);
|
||||||
@ -505,8 +505,8 @@ public class Gate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void clearGates() {
|
public static void clearGates() {
|
||||||
gates.clear();
|
gates.clear();
|
||||||
controlBlocks.clear();
|
controlBlocks.clear();
|
||||||
frameBlocks.clear();
|
frameBlocks.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,8 @@ public class LangLoader {
|
|||||||
// with missing lines from the in-JAR files
|
// with missing lines from the in-JAR files
|
||||||
private void updateLanguage(String lang) {
|
private void updateLanguage(String lang) {
|
||||||
// Load the current language file
|
// Load the current language file
|
||||||
ArrayList<String> keyList = new ArrayList<String>();
|
ArrayList<String> keyList = new ArrayList<>();
|
||||||
ArrayList<String> valList = new ArrayList<String>();
|
ArrayList<String> valList = new ArrayList<>();
|
||||||
|
|
||||||
HashMap<String, String> curLang = load(lang);
|
HashMap<String, String> curLang = load(lang);
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ public class LangLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> load(String lang, InputStream is) {
|
private HashMap<String, String> load(String lang, InputStream is) {
|
||||||
HashMap<String, String> strings = new HashMap<String, String>();
|
HashMap<String, String> strings = new HashMap<>();
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
InputStreamReader isr = null;
|
InputStreamReader isr = null;
|
||||||
try {
|
try {
|
||||||
@ -192,8 +192,9 @@ public class LangLoader {
|
|||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (fis != null) {
|
if (fis != null) {
|
||||||
try {fis.close();}
|
try {
|
||||||
catch (Exception ex) {}
|
fis.close();
|
||||||
|
} catch (Exception ex) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings;
|
return strings;
|
||||||
|
@ -1,398 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 Tyler Blair. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
|
||||||
* permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
||||||
* conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
|
||||||
* provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
|
||||||
* authors and contributors and should not be interpreted as representing official policies,
|
|
||||||
* either expressed or implied, of anybody else.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class MetricsLite {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current revision number
|
|
||||||
*/
|
|
||||||
private final static int REVISION = 6;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base url of the metrics domain
|
|
||||||
*/
|
|
||||||
private static final String BASE_URL = "http://mcstats.org";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The url used to report a server's status
|
|
||||||
*/
|
|
||||||
private static final String REPORT_URL = "/report/%s";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval of time to ping (in minutes)
|
|
||||||
*/
|
|
||||||
private final static int PING_INTERVAL = 10;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin this metrics submits for
|
|
||||||
*/
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin configuration file
|
|
||||||
*/
|
|
||||||
private final YamlConfiguration configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin configuration file
|
|
||||||
*/
|
|
||||||
private final File configurationFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unique server id
|
|
||||||
*/
|
|
||||||
private final String guid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Debug mode
|
|
||||||
*/
|
|
||||||
private final boolean debug;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lock for synchronization
|
|
||||||
*/
|
|
||||||
private final Object optOutLock = new Object();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id of the scheduled task
|
|
||||||
*/
|
|
||||||
private volatile BukkitTask task = null;
|
|
||||||
|
|
||||||
public MetricsLite(Plugin plugin) throws IOException {
|
|
||||||
if (plugin == null) {
|
|
||||||
throw new IllegalArgumentException("Plugin cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.plugin = plugin;
|
|
||||||
|
|
||||||
// load the config
|
|
||||||
configurationFile = getConfigFile();
|
|
||||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
|
||||||
|
|
||||||
// add some defaults
|
|
||||||
configuration.addDefault("opt-out", false);
|
|
||||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
|
||||||
configuration.addDefault("debug", false);
|
|
||||||
|
|
||||||
// Do we need to create the file?
|
|
||||||
if (configuration.get("guid", null) == null) {
|
|
||||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the guid then
|
|
||||||
guid = configuration.getString("guid");
|
|
||||||
debug = configuration.getBoolean("debug", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
|
|
||||||
* the initial data to the metrics backend, and then after that it will post in increments of
|
|
||||||
* PING_INTERVAL * 1200 ticks.
|
|
||||||
*
|
|
||||||
* @return True if statistics measuring is running, otherwise false.
|
|
||||||
*/
|
|
||||||
public boolean start() {
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Did we opt out?
|
|
||||||
if (isOptOut()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is metrics already running?
|
|
||||||
if (task != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin hitting the server with glorious data
|
|
||||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
|
||||||
|
|
||||||
private boolean firstPost = true;
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
// This has to be synchronized or it can collide with the disable method.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Disable Task, if it is running and the server owner decided to opt-out
|
|
||||||
if (isOptOut() && task != null) {
|
|
||||||
task.cancel();
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
|
||||||
// it is not a interval ping, so it evaluates to FALSE
|
|
||||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
|
||||||
postPlugin(!firstPost);
|
|
||||||
|
|
||||||
// After the first post we set firstPost to false
|
|
||||||
// Each post thereafter will be a ping
|
|
||||||
firstPost = false;
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, PING_INTERVAL * 1200);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Has the server owner denied plugin metrics?
|
|
||||||
*
|
|
||||||
* @return true if metrics should be opted out of it
|
|
||||||
*/
|
|
||||||
public boolean isOptOut() {
|
|
||||||
synchronized(optOutLock) {
|
|
||||||
try {
|
|
||||||
// Reload the metrics file
|
|
||||||
configuration.load(getConfigFile());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (InvalidConfigurationException ex) {
|
|
||||||
if (debug) {
|
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return configuration.getBoolean("opt-out", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void enable() throws IOException {
|
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
|
||||||
if (isOptOut()) {
|
|
||||||
configuration.set("opt-out", false);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable Task, if it is not running
|
|
||||||
if (task == null) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void disable() throws IOException {
|
|
||||||
// This has to be synchronized or it can collide with the check in the task.
|
|
||||||
synchronized (optOutLock) {
|
|
||||||
// Check if the server owner has already set opt-out, if not, set it.
|
|
||||||
if (!isOptOut()) {
|
|
||||||
configuration.set("opt-out", true);
|
|
||||||
configuration.save(configurationFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable Task, if it is running
|
|
||||||
if (task != null) {
|
|
||||||
task.cancel();
|
|
||||||
task = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
|
||||||
*
|
|
||||||
* @return the File object for the config file
|
|
||||||
*/
|
|
||||||
public File getConfigFile() {
|
|
||||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
|
||||||
// is to abuse the plugin object we already have
|
|
||||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
|
||||||
// pluginsFolder => base/plugins/
|
|
||||||
// The base is not necessarily relative to the startup directory.
|
|
||||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
|
||||||
|
|
||||||
// return => base/plugins/PluginMetrics/config.yml
|
|
||||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic method that posts a plugin to the metrics website
|
|
||||||
*/
|
|
||||||
private void postPlugin(boolean isPing) throws IOException {
|
|
||||||
// Server software specific section
|
|
||||||
PluginDescriptionFile description = plugin.getDescription();
|
|
||||||
String pluginName = description.getName();
|
|
||||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
|
||||||
String pluginVersion = description.getVersion();
|
|
||||||
String serverVersion = Bukkit.getVersion();
|
|
||||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
|
|
||||||
|
|
||||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
|
||||||
|
|
||||||
// Construct the post data
|
|
||||||
final StringBuilder data = new StringBuilder();
|
|
||||||
|
|
||||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
|
||||||
data.append(encode("guid")).append('=').append(encode(guid));
|
|
||||||
encodeDataPair(data, "version", pluginVersion);
|
|
||||||
encodeDataPair(data, "server", serverVersion);
|
|
||||||
encodeDataPair(data, "players", Integer.toString(playersOnline));
|
|
||||||
encodeDataPair(data, "revision", String.valueOf(REVISION));
|
|
||||||
|
|
||||||
// New data as of R6
|
|
||||||
String osname = System.getProperty("os.name");
|
|
||||||
String osarch = System.getProperty("os.arch");
|
|
||||||
String osversion = System.getProperty("os.version");
|
|
||||||
String java_version = System.getProperty("java.version");
|
|
||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
||||||
|
|
||||||
// normalize os arch .. amd64 -> x86_64
|
|
||||||
if (osarch.equals("amd64")) {
|
|
||||||
osarch = "x86_64";
|
|
||||||
}
|
|
||||||
|
|
||||||
encodeDataPair(data, "osname", osname);
|
|
||||||
encodeDataPair(data, "osarch", osarch);
|
|
||||||
encodeDataPair(data, "osversion", osversion);
|
|
||||||
encodeDataPair(data, "cores", Integer.toString(coreCount));
|
|
||||||
encodeDataPair(data, "online-mode", Boolean.toString(onlineMode));
|
|
||||||
encodeDataPair(data, "java_version", java_version);
|
|
||||||
|
|
||||||
// If we're pinging, append it
|
|
||||||
if (isPing) {
|
|
||||||
encodeDataPair(data, "ping", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the url
|
|
||||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName)));
|
|
||||||
|
|
||||||
// Connect to the website
|
|
||||||
URLConnection connection;
|
|
||||||
|
|
||||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
|
||||||
// It does not reroute POST requests so we need to go around it
|
|
||||||
if (isMineshafterPresent()) {
|
|
||||||
connection = url.openConnection(Proxy.NO_PROXY);
|
|
||||||
} else {
|
|
||||||
connection = url.openConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
// Write the data
|
|
||||||
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
|
||||||
writer.write(data.toString());
|
|
||||||
writer.flush();
|
|
||||||
|
|
||||||
// Now read the response
|
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
final String response = reader.readLine();
|
|
||||||
|
|
||||||
// close resources
|
|
||||||
writer.close();
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
if (response == null || response.startsWith("ERR")) {
|
|
||||||
throw new IOException(response); //Throw the exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
|
||||||
*
|
|
||||||
* @return true if mineshafter is installed on the server
|
|
||||||
*/
|
|
||||||
private boolean isMineshafterPresent() {
|
|
||||||
try {
|
|
||||||
Class.forName("mineshafter.MineServer");
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first
|
|
||||||
* key/value pair MUST be included manually, e.g:</p>
|
|
||||||
* <code>
|
|
||||||
* StringBuffer data = new StringBuffer();
|
|
||||||
* data.append(encode("guid")).append('=').append(encode(guid));
|
|
||||||
* encodeDataPair(data, "version", description.getVersion());
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param buffer the stringbuilder to append the data pair onto
|
|
||||||
* @param key the key value
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
|
|
||||||
buffer.append('&').append(encode(key)).append('=').append(encode(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode text as UTF-8
|
|
||||||
*
|
|
||||||
* @param text the text to encode
|
|
||||||
* @return the encoded text, as UTF-8
|
|
||||||
*/
|
|
||||||
private static String encode(final String text) throws UnsupportedEncodingException {
|
|
||||||
return URLEncoder.encode(text, "UTF-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -26,12 +27,13 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.StorageMinecart;
|
import org.bukkit.entity.minecart.StorageMinecart;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.material.Button;
|
import org.bukkit.material.Button;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
import org.bukkit.material.Step;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,15 +58,15 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
public class Portal {
|
public class Portal {
|
||||||
// Static variables used to store portal lists
|
// Static variables used to store portal lists
|
||||||
private static final HashMap<Blox, Portal> lookupBlocks = new HashMap<Blox, Portal>();
|
private static final HashMap<Blox, Portal> lookupBlocks = new HashMap<>();
|
||||||
private static final HashMap<Blox, Portal> lookupEntrances = new HashMap<Blox, Portal>();
|
private static final HashMap<Blox, Portal> lookupEntrances = new HashMap<>();
|
||||||
private static final HashMap<Blox, Portal> lookupControls = new HashMap<Blox, Portal>();
|
private static final HashMap<Blox, Portal> lookupControls = new HashMap<>();
|
||||||
private static final ArrayList<Portal> allPortals = new ArrayList<Portal>();
|
private static final ArrayList<Portal> allPortals = new ArrayList<>();
|
||||||
private static final HashMap<String, ArrayList<String>> allPortalsNet = new HashMap<String, ArrayList<String>>();
|
private static final HashMap<String, ArrayList<String>> allPortalsNet = new HashMap<>();
|
||||||
private static final HashMap<String, HashMap<String, Portal>> lookupNamesNet = new HashMap<String, HashMap<String, Portal>>();
|
private static final HashMap<String, HashMap<String, Portal>> lookupNamesNet = new HashMap<>();
|
||||||
|
|
||||||
// A list of Bungee gates
|
// A list of Bungee gates
|
||||||
private static final HashMap<String, Portal> bungeePortals = new HashMap<String, Portal>();
|
private static final HashMap<String, Portal> bungeePortals = new HashMap<>();
|
||||||
|
|
||||||
// Gate location block info
|
// Gate location block info
|
||||||
private Blox topLeft;
|
private Blox topLeft;
|
||||||
@ -103,7 +105,7 @@ public class Portal {
|
|||||||
// In-use information
|
// In-use information
|
||||||
private Player player;
|
private Player player;
|
||||||
private Player activePlayer;
|
private Player activePlayer;
|
||||||
private ArrayList<String> destinations = new ArrayList<String>();
|
private ArrayList<String> destinations = new ArrayList<>();
|
||||||
private boolean isOpen = false;
|
private boolean isOpen = false;
|
||||||
private long openTime;
|
private long openTime;
|
||||||
|
|
||||||
@ -496,19 +498,19 @@ public class Portal {
|
|||||||
|
|
||||||
// Get new velocity
|
// Get new velocity
|
||||||
final Vector newVelocity = new Vector();
|
final Vector newVelocity = new Vector();
|
||||||
switch ((int)id.getBlock().getData()) {
|
switch (id.getBlock().getData()) {
|
||||||
case 2:
|
case 2:
|
||||||
newVelocity.setZ(-1);
|
newVelocity.setZ(-1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
newVelocity.setZ(1);
|
newVelocity.setZ(1);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
newVelocity.setX(-1);
|
newVelocity.setX(-1);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
newVelocity.setX(1);
|
newVelocity.setX(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
newVelocity.multiply(velocity);
|
newVelocity.multiply(velocity);
|
||||||
|
|
||||||
@ -547,7 +549,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
if (getWorld().getBlockTypeIdAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) == Material.STEP.getId()) {
|
if (getWorld().getBlockAt(loc).getState().getData() instanceof Step) {
|
||||||
loc.setY(loc.getY() + 0.5);
|
loc.setY(loc.getY() + 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,9 +583,10 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getDestinations(Player player, String network) {
|
public ArrayList<String> getDestinations(Player player, String network) {
|
||||||
ArrayList<String> destinations = new ArrayList<String>();
|
ArrayList<String> destinations = new ArrayList<>();
|
||||||
for (String dest : allPortalsNet.get(network.toLowerCase())) {
|
for (String dest : allPortalsNet.get(network.toLowerCase())) {
|
||||||
Portal portal = getByName(dest, network);
|
Portal portal = getByName(dest, network);
|
||||||
|
if (portal == null) continue;
|
||||||
// Check if dest is a random gate
|
// Check if dest is a random gate
|
||||||
if (portal.isRandom()) continue;
|
if (portal.isRandom()) continue;
|
||||||
// Check if dest is always open (Don't show if so)
|
// Check if dest is always open (Don't show if so)
|
||||||
@ -1324,15 +1327,15 @@ public class Portal {
|
|||||||
String network = (split.length > 9) ? split[9] : Stargate.getDefaultNetwork();
|
String network = (split.length > 9) ? split[9] : Stargate.getDefaultNetwork();
|
||||||
if (network.isEmpty()) network = Stargate.getDefaultNetwork();
|
if (network.isEmpty()) network = Stargate.getDefaultNetwork();
|
||||||
String owner = (split.length > 10) ? split[10] : "";
|
String owner = (split.length > 10) ? split[10] : "";
|
||||||
boolean hidden = (split.length > 11) ? split[11].equalsIgnoreCase("true") : false;
|
boolean hidden = (split.length > 11) && split[11].equalsIgnoreCase("true");
|
||||||
boolean alwaysOn = (split.length > 12) ? split[12].equalsIgnoreCase("true") : false;
|
boolean alwaysOn = (split.length > 12) && split[12].equalsIgnoreCase("true");
|
||||||
boolean priv = (split.length > 13) ? split[13].equalsIgnoreCase("true") : false;
|
boolean priv = (split.length > 13) && split[13].equalsIgnoreCase("true");
|
||||||
boolean free = (split.length > 15) ? split[15].equalsIgnoreCase("true") : false;
|
boolean free = (split.length > 15) && split[15].equalsIgnoreCase("true");
|
||||||
boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false;
|
boolean backwards = (split.length > 16) && split[16].equalsIgnoreCase("true");
|
||||||
boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false;
|
boolean show = (split.length > 17) && split[17].equalsIgnoreCase("true");
|
||||||
boolean noNetwork = (split.length > 18) ? split[18].equalsIgnoreCase("true") : false;
|
boolean noNetwork = (split.length > 18) && split[18].equalsIgnoreCase("true");
|
||||||
boolean random = (split.length > 19) ? split[19].equalsIgnoreCase("true") : false;
|
boolean random = (split.length > 19) && split[19].equalsIgnoreCase("true");
|
||||||
boolean bungee = (split.length > 20) ? split[20].equalsIgnoreCase("true") : false;
|
boolean bungee = (split.length > 20) && split[20].equalsIgnoreCase("true");
|
||||||
|
|
||||||
Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork, random, bungee);
|
Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork, random, bungee);
|
||||||
portal.register();
|
portal.register();
|
||||||
|
@ -29,6 +29,7 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Minecart;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
import org.bukkit.event.Event.Result;
|
import org.bukkit.event.Event.Result;
|
||||||
@ -109,14 +110,14 @@ public class Stargate extends JavaPlugin {
|
|||||||
public static boolean debug = false;
|
public static boolean debug = false;
|
||||||
public static boolean permDebug = false;
|
public static boolean permDebug = false;
|
||||||
|
|
||||||
public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
|
public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<>();
|
||||||
public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
|
public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
// Used for populating gate open/closed material.
|
// Used for populating gate open/closed material.
|
||||||
public static Queue<BloxPopulator> blockPopulatorQueue = new LinkedList<BloxPopulator>();
|
public static Queue<BloxPopulator> blockPopulatorQueue = new LinkedList<>();
|
||||||
|
|
||||||
// HashMap of player names for Bungee support
|
// HashMap of player names for Bungee support
|
||||||
public static Map<String, String> bungeeQueue = new HashMap<String, String>();
|
public static Map<String, String> bungeeQueue = new HashMap<>();
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
Portal.closeAllGates();
|
Portal.closeAllGates();
|
||||||
@ -170,19 +171,6 @@ public class Stargate extends JavaPlugin {
|
|||||||
|
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L);
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new BlockPopulatorThread(), 0L, 1L);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new BlockPopulatorThread(), 0L, 1L);
|
||||||
|
|
||||||
// Enable Plugin Metrics
|
|
||||||
try {
|
|
||||||
MetricsLite ml = new MetricsLite(this);
|
|
||||||
if (!ml.isOptOut()) {
|
|
||||||
ml.start();
|
|
||||||
log.info("[Stargate] Plugin metrics enabled.");
|
|
||||||
} else {
|
|
||||||
log.info("[Stargate] Plugin metrics not enabled.");
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
log.warning("[Stargate] Error enabling plugin metrics: " + ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
@ -253,23 +241,6 @@ public class Stargate extends JavaPlugin {
|
|||||||
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
|
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
|
||||||
if (!newFile.exists()) {
|
if (!newFile.exists()) {
|
||||||
newFile.getParentFile().mkdirs();
|
newFile.getParentFile().mkdirs();
|
||||||
// Migrate not-so-old stargate db
|
|
||||||
File oldishFile = new File("plugins/Stargate/stargate.db");
|
|
||||||
if (oldishFile.exists()) {
|
|
||||||
Stargate.log.info("[Stargate] Migrating existing stargate.db");
|
|
||||||
oldishFile.renameTo(newFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate old gates if applicaple
|
|
||||||
File oldDir = new File("stargates");
|
|
||||||
if (oldDir.exists()) {
|
|
||||||
File newDir = new File(gateFolder);
|
|
||||||
if (!newDir.exists()) newDir.mkdirs();
|
|
||||||
for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) {
|
|
||||||
Stargate.log.info("[Stargate] Migrating existing gate " + file.getName());
|
|
||||||
file.renameTo(new File(gateFolder, file.getName()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,12 +367,10 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Can use all Stargate player features or access all worlds
|
// Can use all Stargate player features or access all worlds
|
||||||
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.world")) {
|
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.world")) {
|
||||||
// Do a deep check to see if the player lacks this specific world node
|
// Do a deep check to see if the player lacks this specific world node
|
||||||
if (!hasPermDeep(player, "stargate.world." + world)) return false;
|
return hasPermDeep(player, "stargate.world." + world);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Can access dest world
|
// Can access dest world
|
||||||
if (hasPerm(player, "stargate.world." + world)) return true;
|
return hasPerm(player, "stargate.world." + world);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -411,16 +380,14 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Can user all Stargate player features, or access all networks
|
// Can user all Stargate player features, or access all networks
|
||||||
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.network")) {
|
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.network")) {
|
||||||
// Do a deep check to see if the player lacks this specific network node
|
// Do a deep check to see if the player lacks this specific network node
|
||||||
if (!hasPermDeep(player, "stargate.network." + network)) return false;
|
return hasPermDeep(player, "stargate.network." + network);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Can access this network
|
// Can access this network
|
||||||
if (hasPerm(player, "stargate.network." + network)) return true;
|
if (hasPerm(player, "stargate.network." + network)) return true;
|
||||||
// Is able to create personal gates (Assumption is made they can also access them)
|
// Is able to create personal gates (Assumption is made they can also access them)
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
if (playerName.length() > 11) playerName = playerName.substring(0, 11);
|
if (playerName.length() > 11) playerName = playerName.substring(0, 11);
|
||||||
if (network.equals(playerName) && hasPerm(player, "stargate.create.personal")) return true;
|
return network.equals(playerName) && hasPerm(player, "stargate.create.personal");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -430,12 +397,10 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Can user all Stargate player features, or access all servers
|
// Can user all Stargate player features, or access all servers
|
||||||
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.servers")) {
|
if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.servers")) {
|
||||||
// Do a deep check to see if the player lacks this specific server node
|
// Do a deep check to see if the player lacks this specific server node
|
||||||
if (!hasPermDeep(player, "stargate.server." + server)) return false;
|
return hasPermDeep(player, "stargate.server." + server);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Can access this server
|
// Can access this server
|
||||||
if (hasPerm(player, "stargate.server." + server)) return true;
|
return hasPerm(player, "stargate.server." + server);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -444,8 +409,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
public static boolean canAccessPortal(Player player, Portal portal, boolean deny) {
|
public static boolean canAccessPortal(Player player, Portal portal, boolean deny) {
|
||||||
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
||||||
Stargate.server.getPluginManager().callEvent(event);
|
Stargate.server.getPluginManager().callEvent(event);
|
||||||
if (event.getDeny()) return false;
|
return !event.getDeny();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -457,8 +421,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Player gets free use
|
// Player gets free use
|
||||||
if (hasPerm(player, "stargate.free") || Stargate.hasPerm(player, "stargate.free.use")) return true;
|
if (hasPerm(player, "stargate.free") || Stargate.hasPerm(player, "stargate.free.use")) return true;
|
||||||
// Don't charge for free destination gates
|
// Don't charge for free destination gates
|
||||||
if (dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree()) return true;
|
return dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -470,8 +433,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// The player is an admin with the ability to see hidden gates
|
// The player is an admin with the ability to see hidden gates
|
||||||
if (hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.hidden")) return true;
|
if (hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.hidden")) return true;
|
||||||
// The player is the owner of the gate
|
// The player is the owner of the gate
|
||||||
if (portal.getOwner().equalsIgnoreCase(player.getName())) return true;
|
return portal.getOwner().equalsIgnoreCase(player.getName());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -481,8 +443,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check if the player is the owner of the gate
|
// Check if the player is the owner of the gate
|
||||||
if (portal.getOwner().equalsIgnoreCase(player.getName())) return true;
|
if (portal.getOwner().equalsIgnoreCase(player.getName())) return true;
|
||||||
// The player is an admin with the ability to use private gates
|
// The player is an admin with the ability to use private gates
|
||||||
if (hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.private")) return true;
|
return hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.private");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -492,8 +453,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check if the player can use all options
|
// Check if the player can use all options
|
||||||
if (hasPerm(player, "stargate.option")) return true;
|
if (hasPerm(player, "stargate.option")) return true;
|
||||||
// Check if they can use this specific option
|
// Check if they can use this specific option
|
||||||
if (hasPerm(player, "stargate.option." + option)) return true;
|
return hasPerm(player, "stargate.option." + option);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -505,13 +465,11 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check for all network create permission
|
// Check for all network create permission
|
||||||
if (hasPerm(player, "stargate.create.network")) {
|
if (hasPerm(player, "stargate.create.network")) {
|
||||||
// Do a deep check to see if the player lacks this specific network node
|
// Do a deep check to see if the player lacks this specific network node
|
||||||
if (!hasPermDeep(player, "stargate.create.network." + network)) return false;
|
return hasPermDeep(player, "stargate.create.network." + network);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Check for this specific network
|
// Check for this specific network
|
||||||
if (hasPerm(player, "stargate.create.network." + network)) return true;
|
return hasPerm(player, "stargate.create.network." + network);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -521,8 +479,7 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check for general create
|
// Check for general create
|
||||||
if (hasPerm(player, "stargate.create")) return true;
|
if (hasPerm(player, "stargate.create")) return true;
|
||||||
// Check for personal
|
// Check for personal
|
||||||
if (hasPerm(player, "stargate.create.personal")) return true;
|
return hasPerm(player, "stargate.create.personal");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -534,13 +491,10 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check for all gate create permissions
|
// Check for all gate create permissions
|
||||||
if (hasPerm(player, "stargate.create.gate")) {
|
if (hasPerm(player, "stargate.create.gate")) {
|
||||||
// Do a deep check to see if the player lacks this specific gate node
|
// Do a deep check to see if the player lacks this specific gate node
|
||||||
if (!hasPermDeep(player, "stargate.create.gate." + gate)) return false;
|
return hasPermDeep(player, "stargate.create.gate." + gate);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Check for this specific gate
|
// Check for this specific gate
|
||||||
if (hasPerm(player, "stargate.create.gate." + gate)) return true;
|
return hasPerm(player, "stargate.create.gate." + gate);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -553,14 +507,12 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Check for all network destroy permission
|
// Check for all network destroy permission
|
||||||
if (hasPerm(player, "stargate.destroy.network")) {
|
if (hasPerm(player, "stargate.destroy.network")) {
|
||||||
// Do a deep check to see if the player lacks permission for this network node
|
// Do a deep check to see if the player lacks permission for this network node
|
||||||
if (!hasPermDeep(player, "stargate.destroy.network." + network)) return false;
|
return hasPermDeep(player, "stargate.destroy.network." + network);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// Check for this specific network
|
// Check for this specific network
|
||||||
if (hasPerm(player, "stargate.destroy.network." + network)) return true;
|
if (hasPerm(player, "stargate.destroy.network." + network)) return true;
|
||||||
// Check for personal gate
|
// Check for personal gate
|
||||||
if (player.getName().equalsIgnoreCase(portal.getOwner()) && hasPerm(player, "stargate.destroy.personal")) return true;
|
return player.getName().equalsIgnoreCase(portal.getOwner()) && hasPerm(player, "stargate.destroy.personal");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1148,89 +1100,6 @@ public class Stargate extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Going to leave this commented out until they fix EntityDamagebyBlock
|
|
||||||
/*
|
|
||||||
@Override
|
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
|
||||||
if (!(event.getEntity() instanceof Player)) return;
|
|
||||||
if (!(event instanceof EntityDamageByBlockEvent)) return;
|
|
||||||
EntityDamageByBlockEvent bEvent = (EntityDamageByBlockEvent)event;
|
|
||||||
Player player = (Player)bEvent.getEntity();
|
|
||||||
Block block = bEvent.getDamager();
|
|
||||||
// Fucking null blocks, we'll do it live! This happens for lava only, as far as I know.
|
|
||||||
// So we're "borrowing" the code from World.java used to determine if we're intersecting a lava block
|
|
||||||
if (block == null) {
|
|
||||||
CraftEntity ce = (CraftEntity)event.getEntity();
|
|
||||||
net.minecraft.server.Entity entity = ce.getHandle();
|
|
||||||
AxisAlignedBB axisalignedbb = entity.boundingBox.b(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D);
|
|
||||||
int minx = MathHelper.floor(axisalignedbb.a);
|
|
||||||
int maxx = MathHelper.floor(axisalignedbb.d + 1.0D);
|
|
||||||
int miny = MathHelper.floor(axisalignedbb.b);
|
|
||||||
int maxy = MathHelper.floor(axisalignedbb.e + 1.0D);
|
|
||||||
int minz = MathHelper.floor(axisalignedbb.c);
|
|
||||||
int maxz = MathHelper.floor(axisalignedbb.f + 1.0D);
|
|
||||||
|
|
||||||
for (int x = minx; x < maxx; ++x) {
|
|
||||||
for (int y = miny; y < maxy; ++y) {
|
|
||||||
for (int z = minz; z < maxz; ++z) {
|
|
||||||
int blockType = player.getWorld().getBlockTypeIdAt(x, y, z);
|
|
||||||
if (blockType == Material.LAVA.getId() || blockType == Material.STATIONARY_LAVA.getId()) {
|
|
||||||
block = player.getWorld().getBlockAt(x, y, z);
|
|
||||||
log.info("Found block! " + block);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (block != null) break;
|
|
||||||
}
|
|
||||||
if (block != null) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (block == null) return;
|
|
||||||
Portal portal = Portal.getByEntrance(block);
|
|
||||||
if (portal == null) return;
|
|
||||||
log.info("Found portal");
|
|
||||||
bEvent.setDamage(0);
|
|
||||||
bEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEntityCombust(EntityCombustEvent event) {
|
|
||||||
if (!(event.getEntity() instanceof Player)) return;
|
|
||||||
Player player = (Player)event.getEntity();
|
|
||||||
// WHY DOESN'T THIS CANCEL IF YOU CANCEL LAVA DAMAGE?!
|
|
||||||
Block block = null;
|
|
||||||
CraftEntity ce = (CraftEntity)event.getEntity();
|
|
||||||
net.minecraft.server.Entity entity = ce.getHandle();
|
|
||||||
AxisAlignedBB axisalignedbb = entity.boundingBox.b(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D);
|
|
||||||
int minx = MathHelper.floor(axisalignedbb.a);
|
|
||||||
int maxx = MathHelper.floor(axisalignedbb.d + 1.0D);
|
|
||||||
int miny = MathHelper.floor(axisalignedbb.b);
|
|
||||||
int maxy = MathHelper.floor(axisalignedbb.e + 1.0D);
|
|
||||||
int minz = MathHelper.floor(axisalignedbb.c);
|
|
||||||
int maxz = MathHelper.floor(axisalignedbb.f + 1.0D);
|
|
||||||
|
|
||||||
for (int x = minx; x < maxx; ++x) {
|
|
||||||
for (int y = miny; y < maxy; ++y) {
|
|
||||||
for (int z = minz; z < maxz; ++z) {
|
|
||||||
int blockType = player.getWorld().getBlockTypeIdAt(x, y, z);
|
|
||||||
if (blockType == Material.LAVA.getId() || blockType == Material.STATIONARY_LAVA.getId()) {
|
|
||||||
block = player.getWorld().getBlockAt(x, y, z);
|
|
||||||
log.info("Found block! " + block);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (block != null) break;
|
|
||||||
}
|
|
||||||
if (block != null) break;
|
|
||||||
}
|
|
||||||
if (block == null) return;
|
|
||||||
log.info("What? " + block);
|
|
||||||
Portal portal = Portal.getByEntrance(block);
|
|
||||||
if (portal == null) return;
|
|
||||||
log.info("What2?");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class sListener implements Listener {
|
private class sListener implements Listener {
|
||||||
|
Loading…
Reference in New Issue
Block a user