mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-26 04:25:30 +01:00
updated variable calls
This commit is contained in:
parent
3832c43148
commit
c403e59360
@ -461,7 +461,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
|||||||
String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a";
|
String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a";
|
||||||
LinkedList<String> portals = new LinkedList<>();
|
LinkedList<String> portals = new LinkedList<>();
|
||||||
for (AdvancedPortal portal : Portal.portals) {
|
for (AdvancedPortal portal : Portal.portals) {
|
||||||
portals.add(portal.portalName);
|
portals.add(portal.getName());
|
||||||
}
|
}
|
||||||
Collections.sort(portals);
|
Collections.sort(portals);
|
||||||
for (Object portalName : portals.toArray()) {
|
for (Object portalName : portals.toArray()) {
|
||||||
|
@ -7,6 +7,7 @@ import com.sekwah.advancedportals.effects.WarpEffects;
|
|||||||
import com.sekwah.advancedportals.listeners.*;
|
import com.sekwah.advancedportals.listeners.*;
|
||||||
import com.sekwah.advancedportals.metrics.Metrics;
|
import com.sekwah.advancedportals.metrics.Metrics;
|
||||||
import com.sekwah.advancedportals.portals.Portal;
|
import com.sekwah.advancedportals.portals.Portal;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -26,6 +27,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
|
|
||||||
metrics.start();
|
metrics.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Failed to submit the stats :-(
|
// Failed to submit the stats :-(
|
||||||
@ -105,6 +107,21 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
|
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MaterialPlotter extends Metrics.Plotter {
|
||||||
|
|
||||||
|
private final int count;
|
||||||
|
|
||||||
|
public MaterialPlotter(Material triggerBlock, int count){
|
||||||
|
super(triggerBlock.toString());
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getValue() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Settings getSettings() {
|
public Settings getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
|
@ -90,19 +90,21 @@ public class Listeners implements Listener {
|
|||||||
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
|
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
|
||||||
for (AdvancedPortal portal : Portal.portals) {
|
for (AdvancedPortal portal : Portal.portals) {
|
||||||
if (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc)) {
|
if (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc)) {
|
||||||
if (portal.trigger.equals(Material.PORTAL)) {
|
if (portal.getTrigger().equals(Material.PORTAL)) {
|
||||||
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||||
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
|
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10);
|
||||||
}
|
}
|
||||||
} else if (portal.trigger.equals(Material.LAVA)) {
|
} else if (portal.getTrigger().equals(Material.LAVA)) {
|
||||||
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10);
|
||||||
}
|
}
|
||||||
if (portal.inPortal.contains(player)) return;
|
if (portal.inPortal.contains(player)) return;
|
||||||
WarpEvent warpEvent = new WarpEvent(player, portal);
|
WarpEvent warpEvent = new WarpEvent(player, portal);
|
||||||
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
plugin.getServer().getPluginManager().callEvent(warpEvent);
|
||||||
|
|
||||||
if (!event.isCancelled()) Portal.activate(player, portal);
|
if (!event.isCancelled()) Portal.activate(player, portal);
|
||||||
|
|
||||||
portal.inPortal.add(player);
|
portal.inPortal.add(player);
|
||||||
} else portal.inPortal.remove(player);
|
} else portal.inPortal.remove(player);
|
||||||
}
|
}
|
||||||
@ -175,8 +177,8 @@ public class Listeners implements Listener {
|
|||||||
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
||||||
for (AdvancedPortal portal : Portal.portals) {
|
for (AdvancedPortal portal : Portal.portals) {
|
||||||
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
|
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
|
||||||
player.sendMessage(PluginMessages.customPrefix + "\u00A7a You have selected: \u00A7e" + portal.portalName);
|
player.sendMessage(PluginMessages.customPrefix + "\u00A7a You have selected: \u00A7e" + portal.getName());
|
||||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
|
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.getName())); // adds the name to the metadata of the character
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.removeMetadata("selectingPortal", plugin);
|
player.removeMetadata("selectingPortal", plugin);
|
||||||
return;
|
return;
|
||||||
|
@ -28,18 +28,33 @@
|
|||||||
package com.sekwah.advancedportals.metrics;
|
package com.sekwah.advancedportals.metrics;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
@ -132,121 +147,6 @@ public class Metrics {
|
|||||||
debug = configuration.getBoolean("debug", false);
|
debug = configuration.getBoolean("debug", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* GZip compress a string of bytes
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static byte[] gzip(String input) {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
GZIPOutputStream gzos = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
gzos = new GZIPOutputStream(baos);
|
|
||||||
gzos.write(input.getBytes("UTF-8"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (gzos != null) try {
|
|
||||||
gzos.close();
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return baos.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends a json encoded key/value pair to the given string builder.
|
|
||||||
*
|
|
||||||
* @param json
|
|
||||||
* @param key
|
|
||||||
* @param value
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
|
||||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
|
||||||
boolean isValueNumeric = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (value.equals("0") || !value.endsWith("0")) {
|
|
||||||
Double.parseDouble(value);
|
|
||||||
isValueNumeric = true;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
isValueNumeric = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.charAt(json.length() - 1) != '{') {
|
|
||||||
json.append(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
json.append(escapeJSON(key));
|
|
||||||
json.append(':');
|
|
||||||
|
|
||||||
if (isValueNumeric) {
|
|
||||||
json.append(value);
|
|
||||||
} else {
|
|
||||||
json.append(escapeJSON(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape a string to create a valid JSON string
|
|
||||||
*
|
|
||||||
* @param text
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String escapeJSON(String text) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
builder.append('"');
|
|
||||||
for (int index = 0; index < text.length(); index++) {
|
|
||||||
char chr = text.charAt(index);
|
|
||||||
|
|
||||||
switch (chr) {
|
|
||||||
case '"':
|
|
||||||
case '\\':
|
|
||||||
builder.append('\\');
|
|
||||||
builder.append(chr);
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
builder.append("\\b");
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
builder.append("\\t");
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
builder.append("\\n");
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
builder.append("\\r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (chr < ' ') {
|
|
||||||
String t = "000" + Integer.toHexString(chr);
|
|
||||||
builder.append("\\u" + t.substring(t.length() - 4));
|
|
||||||
} else {
|
|
||||||
builder.append(chr);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.append('"');
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode text as UTF-8
|
|
||||||
*
|
|
||||||
* @param text the text to encode
|
|
||||||
* @return the encoded text, as UTF-8
|
|
||||||
*/
|
|
||||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
|
||||||
return URLEncoder.encode(text, "UTF-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
|
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
|
||||||
* website. Plotters can be added to the graph object returned.
|
* website. Plotters can be added to the graph object returned.
|
||||||
@ -426,6 +326,28 @@ public class Metrics {
|
|||||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the online player (backwards compatibility)
|
||||||
|
*
|
||||||
|
* @return online player amount
|
||||||
|
*/
|
||||||
|
private int getOnlinePlayers() {
|
||||||
|
try {
|
||||||
|
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
|
||||||
|
if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
|
||||||
|
return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
|
||||||
|
} else {
|
||||||
|
return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (debug) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic method that posts a plugin to the metrics website
|
* Generic method that posts a plugin to the metrics website
|
||||||
*/
|
*/
|
||||||
@ -436,9 +358,7 @@ public class Metrics {
|
|||||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||||
String pluginVersion = description.getVersion();
|
String pluginVersion = description.getVersion();
|
||||||
String serverVersion = Bukkit.getVersion();
|
String serverVersion = Bukkit.getVersion();
|
||||||
// make sure that the older versions of CraftBukkit are added first in project imports, so it can be compiled
|
int playersOnline = this.getOnlinePlayers();
|
||||||
// against an older version
|
|
||||||
int playersOnline = Bukkit.getOnlinePlayers().size(); //CraftBukkit.getServer().getOnlinePlayers().length;
|
|
||||||
|
|
||||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||||
|
|
||||||
@ -590,6 +510,31 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GZip compress a string of bytes
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static byte[] gzip(String input) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
GZIPOutputStream gzos = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
gzos = new GZIPOutputStream(baos);
|
||||||
|
gzos.write(input.getBytes("UTF-8"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (gzos != null) try {
|
||||||
|
gzos.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||||
*
|
*
|
||||||
@ -604,6 +549,96 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a json encoded key/value pair to the given string builder.
|
||||||
|
*
|
||||||
|
* @param json
|
||||||
|
* @param key
|
||||||
|
* @param value
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*/
|
||||||
|
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||||
|
boolean isValueNumeric = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (value.equals("0") || !value.endsWith("0")) {
|
||||||
|
Double.parseDouble(value);
|
||||||
|
isValueNumeric = true;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
isValueNumeric = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.charAt(json.length() - 1) != '{') {
|
||||||
|
json.append(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
json.append(escapeJSON(key));
|
||||||
|
json.append(':');
|
||||||
|
|
||||||
|
if (isValueNumeric) {
|
||||||
|
json.append(value);
|
||||||
|
} else {
|
||||||
|
json.append(escapeJSON(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape a string to create a valid JSON string
|
||||||
|
*
|
||||||
|
* @param text
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String escapeJSON(String text) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder.append('"');
|
||||||
|
for (int index = 0; index < text.length(); index++) {
|
||||||
|
char chr = text.charAt(index);
|
||||||
|
|
||||||
|
switch (chr) {
|
||||||
|
case '"':
|
||||||
|
case '\\':
|
||||||
|
builder.append('\\');
|
||||||
|
builder.append(chr);
|
||||||
|
break;
|
||||||
|
case '\b':
|
||||||
|
builder.append("\\b");
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
builder.append("\\t");
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
builder.append("\\n");
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
builder.append("\\r");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (chr < ' ') {
|
||||||
|
String t = "000" + Integer.toHexString(chr);
|
||||||
|
builder.append("\\u" + t.substring(t.length() - 4));
|
||||||
|
} else {
|
||||||
|
builder.append(chr);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.append('"');
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode text as UTF-8
|
||||||
|
*
|
||||||
|
* @param text the text to encode
|
||||||
|
* @return the encoded text, as UTF-8
|
||||||
|
*/
|
||||||
|
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||||
|
return URLEncoder.encode(text, "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a custom graph on the website
|
* Represents a custom graph on the website
|
||||||
*/
|
*/
|
||||||
|
@ -9,24 +9,24 @@ import java.util.HashSet;
|
|||||||
|
|
||||||
public class AdvancedPortal {
|
public class AdvancedPortal {
|
||||||
|
|
||||||
public Material trigger = null;
|
private Material trigger = null;
|
||||||
|
|
||||||
public String worldName = null;
|
private String worldName = null;
|
||||||
|
|
||||||
public Location pos1 = null;
|
private Location pos1 = null;
|
||||||
|
|
||||||
public Location pos2 = null;
|
private Location pos2 = null;
|
||||||
|
|
||||||
public String portalName = null;
|
private String portalName = null;
|
||||||
|
|
||||||
// TODO store destinations also as variables like portals
|
// TODO store destinations also as variables like portals
|
||||||
public String destiation = null; // Could possibly store the destination name to stop the server having to read the config file
|
private String destiation = null; // Could possibly store the destination name to stop the server having to read the config file
|
||||||
|
|
||||||
public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file
|
private String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file
|
||||||
|
|
||||||
// Bungee will be stored inside the destination.
|
// Bungee will be stored inside the destination.
|
||||||
|
|
||||||
public PortalArg[] portalArgs = null;
|
private PortalArg[] portalArgs = null;
|
||||||
|
|
||||||
public HashSet<Player> inPortal = new HashSet<Player>();
|
public HashSet<Player> inPortal = new HashSet<Player>();
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class AdvancedPortal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getArg(String arg) {
|
public String getArg(String arg) {
|
||||||
for (PortalArg portalArg : portalArgs) {
|
for (PortalArg portalArg : this.portalArgs) {
|
||||||
if (arg.equals(portalArg.argName)) {
|
if (arg.equals(portalArg.argName)) {
|
||||||
return portalArg.value;
|
return portalArg.value;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,47 @@ public class AdvancedPortal {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PortalArg[] getArgs(){
|
||||||
|
return this.portalArgs;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasArg(String arg) {
|
public boolean hasArg(String arg) {
|
||||||
return this.getArg(arg) != null;
|
return this.getArg(arg) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Material getTrigger() {
|
||||||
|
return this.trigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorldName() {
|
||||||
|
return this.worldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getPos1() {
|
||||||
|
return this.pos1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getPos2() {
|
||||||
|
return this.pos2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.portalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDestiation() {
|
||||||
|
return this.destiation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestiation(String destiation) {
|
||||||
|
this.destiation = destiation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBungee() {
|
||||||
|
return this.bungee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBungee(String bungee) {
|
||||||
|
this.bungee = bungee;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,17 +96,17 @@ public class Portal {
|
|||||||
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
|
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
|
||||||
if(worldName != null) {
|
if(worldName != null) {
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z"));
|
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".getPos1().X"), portalData.getConfig().getInt(portal.toString() + ".getPos1().Y"), portalData.getConfig().getInt(portal.toString() + ".getPos1().Z"));
|
||||||
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z"));
|
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".getPos2().X"), portalData.getConfig().getInt(portal.toString() + ".getPos2().Y"), portalData.getConfig().getInt(portal.toString() + ".getPos2().Z"));
|
||||||
|
|
||||||
PortalArg[] portalArgs = new PortalArg[extraData.size()];
|
PortalArg[] portalArgs = new PortalArg[extraData.size()];
|
||||||
extraData.toArray(portalArgs);
|
extraData.toArray(portalArgs);
|
||||||
|
|
||||||
portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
|
portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
|
||||||
|
|
||||||
portals[portalId].bungee = portalConfigSection.getString("bungee");
|
portals[portalId].setBungee(portalConfigSection.getString("bungee"));
|
||||||
|
|
||||||
portals[portalId].destiation = portalConfigSection.getString("destination");
|
portals[portalId].setDestiation(portalConfigSection.getString("destination"));
|
||||||
|
|
||||||
portalId++;
|
portalId++;
|
||||||
}
|
}
|
||||||
@ -122,7 +122,6 @@ public class Portal {
|
|||||||
} else {
|
} else {
|
||||||
portalsActive = false;
|
portalsActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) {
|
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) {
|
||||||
@ -180,15 +179,15 @@ public class Portal {
|
|||||||
|
|
||||||
portalData.getConfig().set(name + ".destination", destination);
|
portalData.getConfig().set(name + ".destination", destination);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".bungee", serverName);
|
portalData.getConfig().set(name + ".getBungee()", serverName);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos1.X", HighX);
|
portalData.getConfig().set(name + ".getPos1().X", HighX);
|
||||||
portalData.getConfig().set(name + ".pos1.Y", HighY);
|
portalData.getConfig().set(name + ".getPos1().Y", HighY);
|
||||||
portalData.getConfig().set(name + ".pos1.Z", HighZ);
|
portalData.getConfig().set(name + ".getPos1().Z", HighZ);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos2.X", LowX);
|
portalData.getConfig().set(name + ".getPos2().X", LowX);
|
||||||
portalData.getConfig().set(name + ".pos2.Y", LowY);
|
portalData.getConfig().set(name + ".getPos2().Y", LowY);
|
||||||
portalData.getConfig().set(name + ".pos2.Z", LowZ);
|
portalData.getConfig().set(name + ".getPos2().Z", LowZ);
|
||||||
|
|
||||||
for (PortalArg arg : portalArgs) {
|
for (PortalArg arg : portalArgs) {
|
||||||
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
|
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
|
||||||
@ -207,36 +206,36 @@ public class Portal {
|
|||||||
if (portalsActive) {
|
if (portalsActive) {
|
||||||
int portalId = 0;
|
int portalId = 0;
|
||||||
for (@SuppressWarnings("unused") Object portal : Portal.portals) {
|
for (@SuppressWarnings("unused") Object portal : Portal.portals) {
|
||||||
if (portals[portalId].worldName.equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another
|
if (portals[portalId].getWorldName().equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos1.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos2.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos1.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos1.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos2.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos2.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos1().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos2.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos1().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos2().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos1.getBlockZ())) {
|
if (checkOverLapPortal(pos1, pos2, portals[portalId].getPos2().getBlockX(), portals[portalId].getPos2().getBlockY(), portals[portalId].getPos1().getBlockZ())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,13 +289,13 @@ public class Portal {
|
|||||||
|
|
||||||
public static void redefine(Location pos1, Location pos2, String name) {
|
public static void redefine(Location pos1, Location pos2, String name) {
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos1.X", pos1.getX());
|
portalData.getConfig().set(name + ".getPos1().X", pos1.getX());
|
||||||
portalData.getConfig().set(name + ".pos1.Y", pos1.getY());
|
portalData.getConfig().set(name + ".getPos1().Y", pos1.getY());
|
||||||
portalData.getConfig().set(name + ".pos1.Z", pos1.getZ());
|
portalData.getConfig().set(name + ".getPos1().Z", pos1.getZ());
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos2.X", pos2.getX());
|
portalData.getConfig().set(name + ".getPos2().X", pos2.getX());
|
||||||
portalData.getConfig().set(name + ".pos2.Y", pos2.getY());
|
portalData.getConfig().set(name + ".getPos2().Y", pos2.getY());
|
||||||
portalData.getConfig().set(name + ".pos2.Z", pos2.getZ());
|
portalData.getConfig().set(name + ".getPos2().Z", pos2.getZ());
|
||||||
|
|
||||||
portalData.saveConfig();
|
portalData.saveConfig();
|
||||||
|
|
||||||
@ -332,16 +331,16 @@ public class Portal {
|
|||||||
portalData.getConfig().set(name + ".triggerblock", null);
|
portalData.getConfig().set(name + ".triggerblock", null);
|
||||||
portalData.getConfig().set(name + ".destination", null);
|
portalData.getConfig().set(name + ".destination", null);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos1.X", null);
|
portalData.getConfig().set(name + ".getPos1().X", null);
|
||||||
portalData.getConfig().set(name + ".pos1.Y", null);
|
portalData.getConfig().set(name + ".getPos1().Y", null);
|
||||||
portalData.getConfig().set(name + ".pos1.Z", null);
|
portalData.getConfig().set(name + ".getPos1().Z", null);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos2.X", null);
|
portalData.getConfig().set(name + ".getPos2().X", null);
|
||||||
portalData.getConfig().set(name + ".pos2.Y", null);
|
portalData.getConfig().set(name + ".getPos2().Y", null);
|
||||||
portalData.getConfig().set(name + ".pos2.Z", null);
|
portalData.getConfig().set(name + ".getPos2().Z", null);
|
||||||
|
|
||||||
portalData.getConfig().set(name + ".pos1", null);
|
portalData.getConfig().set(name + ".getPos1()", null);
|
||||||
portalData.getConfig().set(name + ".pos2", null);
|
portalData.getConfig().set(name + ".getPos2()", null);
|
||||||
|
|
||||||
portalData.getConfig().set(name, null);*/
|
portalData.getConfig().set(name, null);*/
|
||||||
|
|
||||||
@ -352,14 +351,14 @@ public class Portal {
|
|||||||
|
|
||||||
public static boolean portalExists(String portalName) {
|
public static boolean portalExists(String portalName) {
|
||||||
|
|
||||||
String posX = portalData.getConfig().getString(portalName + ".pos1.X");
|
String posX = portalData.getConfig().getString(portalName + ".getPos1().X");
|
||||||
|
|
||||||
return posX != null;
|
return posX != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean activate(Player player, String portalName) {
|
public static boolean activate(Player player, String portalName) {
|
||||||
for (AdvancedPortal portal : Portal.portals) {
|
for (AdvancedPortal portal : Portal.portals) {
|
||||||
if (portal.portalName.equals(portalName)) return activate(player, portal);
|
if (portal.getName().equals(portalName)) return activate(player, portal);
|
||||||
}
|
}
|
||||||
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
|
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
|
||||||
return false;
|
return false;
|
||||||
@ -396,22 +395,22 @@ public class Portal {
|
|||||||
cooldown.put(player, System.currentTimeMillis());
|
cooldown.put(player, System.currentTimeMillis());
|
||||||
boolean showFailMessage = !portal.hasArg("command.1");
|
boolean showFailMessage = !portal.hasArg("command.1");
|
||||||
|
|
||||||
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
|
//plugin.getLogger().info(portal.getName() + ":" + portal.getDestiation());
|
||||||
boolean warped = false;
|
boolean warped = false;
|
||||||
if (portal.bungee != null) {
|
if (portal.getBungee() != null) {
|
||||||
if (showBungeeMessage) {
|
if (showBungeeMessage) {
|
||||||
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
|
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.getBungee() + "\u00A7a.");
|
||||||
}
|
}
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("Connect");
|
out.writeUTF("Connect");
|
||||||
out.writeUTF(portal.bungee);
|
out.writeUTF(portal.getBungee());
|
||||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||||
// Down to bungee to sort out the teleporting but yea theoretically they should warp.
|
// Down to bungee to sort out the teleporting but yea theoretically they should warp.
|
||||||
}
|
}
|
||||||
else if (portal.destiation != null) {
|
else if (portal.getDestiation() != null) {
|
||||||
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
|
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
|
||||||
if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
|
if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) {
|
||||||
warped = Destination.warp(player, portal.destiation);
|
warped = Destination.warp(player, portal.getDestiation());
|
||||||
if(!warped){
|
if(!warped){
|
||||||
throwPlayerBack(player);
|
throwPlayerBack(player);
|
||||||
}
|
}
|
||||||
@ -419,7 +418,7 @@ public class Portal {
|
|||||||
} else {
|
} else {
|
||||||
if (showFailMessage) {
|
if (showFailMessage) {
|
||||||
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The portal you are trying to use doesn't have a destination!");
|
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The portal you are trying to use doesn't have a destination!");
|
||||||
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
|
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.getName() + "' has just had a warp "
|
||||||
+ "attempt and either the data is corrupt or portal doesn't exist!");
|
+ "attempt and either the data is corrupt or portal doesn't exist!");
|
||||||
throwPlayerBack(player);
|
throwPlayerBack(player);
|
||||||
failSound(player, portal);
|
failSound(player, portal);
|
||||||
@ -428,7 +427,7 @@ public class Portal {
|
|||||||
|
|
||||||
if (portal.hasArg("command.1")) {
|
if (portal.hasArg("command.1")) {
|
||||||
int commandLine = 1;
|
int commandLine = 1;
|
||||||
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
|
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.getName()+ ".portalArgs.command." + commandLine);
|
||||||
do {
|
do {
|
||||||
// (?i) makes the search case insensitive
|
// (?i) makes the search case insensitive
|
||||||
command = command.replaceAll("@player", player.getName());
|
command = command.replaceAll("@player", player.getName());
|
||||||
@ -471,7 +470,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void failSound(Player player, AdvancedPortal portal) {
|
private static void failSound(Player player, AdvancedPortal portal) {
|
||||||
if(!(portal.trigger == Material.PORTAL && player.getGameMode() == GameMode.CREATIVE)){
|
if(!(portal.getTrigger() == Material.PORTAL && player.getGameMode() == GameMode.CREATIVE)){
|
||||||
player.playSound(player.getLocation(), Sound.BLOCK_PORTAL_TRAVEL, 0.5f, new Random().nextFloat() * 0.4F + 0.8F);
|
player.playSound(player.getLocation(), Sound.BLOCK_PORTAL_TRAVEL, 0.5f, new Random().nextFloat() * 0.4F + 0.8F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +526,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {
|
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {
|
||||||
if (portal.trigger.equals(loc.getBlock().getType()))
|
if (portal.getTrigger().equals(loc.getBlock().getType()))
|
||||||
return locationInPortal(portal, loc, 0);
|
return locationInPortal(portal, loc, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -549,9 +548,9 @@ public class Portal {
|
|||||||
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
|
public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) {
|
||||||
if (!portalsActive)
|
if (!portalsActive)
|
||||||
return false;
|
return false;
|
||||||
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName()))
|
if (loc.getWorld() != null && portal.getWorldName().equals(loc.getWorld().getName()))
|
||||||
if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + 1 + additionalArea) > loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ())
|
if ((portal.getPos1().getX() + 1 + additionalArea) >= loc.getX() && (portal.getPos1().getY() + 1 + additionalArea) > loc.getY() && (portal.getPos1().getZ() + 1 + additionalArea) >= loc.getZ())
|
||||||
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ())
|
if (portal.getPos2().getX() - additionalArea <= loc.getX() && portal.getPos2().getY() - additionalArea <= loc.getY() && portal.getPos2().getZ() - additionalArea <= loc.getZ())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user