cleaned up the code

This commit is contained in:
Alastair 2016-03-29 12:38:03 +01:00
parent 08d2a58c45
commit 5430c27999
25 changed files with 2309 additions and 2427 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,100 +14,99 @@ import java.lang.reflect.InvocationTargetException;
public class AdvancedPortalsPlugin extends JavaPlugin {
public NMS nmsAccess;
public NMS nmsAccess;
public boolean useCustomPrefix = false;
public boolean useCustomPrefix = false;
public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]";
public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]";
public void onEnable() {
public void onEnable() {
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1];
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1];
try {
Class<?> nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version);
if(NMS.class.isAssignableFrom(nmsClass)){
this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance();
}else
{
System.out.println("Something went wrong, please notify the author and tell them this version v:" + version);
this.setEnabled(false);
}
} catch (ClassNotFoundException e) {
System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version);
this.setEnabled(false);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException |
NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
try {
Class<?> nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version);
if (NMS.class.isAssignableFrom(nmsClass)) {
this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance();
} else {
System.out.println("Something went wrong, please notify the author and tell them this version v:" + version);
this.setEnabled(false);
}
} catch (ClassNotFoundException e) {
System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version);
this.setEnabled(false);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException |
NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
saveDefaultConfig();
saveDefaultConfig();
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
// only copy the file if it doesnt exist!
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
// only copy the file if it doesnt exist!
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix");
if(useCustomPrefix){
this.customPrefix = config.getConfig().getString("CustomPrefix");
}
this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix");
if (useCustomPrefix) {
this.customPrefix = config.getConfig().getString("CustomPrefix");
}
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
portalConfig.saveDefaultConfig();
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
portalConfig.saveDefaultConfig();
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
destinationConfig.saveDefaultConfig();
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
destinationConfig.saveDefaultConfig();
new Assets(this);
// Opens a channel that messages bungeeCord
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
new Assets(this);
// Opens a channel that messages bungeeCord
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
// Loads the portal and destination editors
new Portal(this);
new Destination(this);
new DataCollector(this);
// These register the commands
new AdvancedPortalsCommand(this);
new DestinationCommand(this);
new WarpCommand(this);
new AdvancedPortalsCommand(this);
new DestinationCommand(this);
new WarpCommand(this);
new WarpEffects(this);
// These register the listeners
new Listeners(this);
new FlowStopper(this);
new PortalProtect(this);
new PortalPlacer(this);
Selection.LoadData(this);
DataCollector.setupMetrics();
new WarpEffects(this);
// These register the listeners
new Listeners(this);
new FlowStopper(this);
new PortalProtect(this);
new PortalPlacer(this);
Selection.LoadData(this);
DataCollector.setupMetrics();
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
}
public void onDisable() {
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
}
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
}
public void onDisable() {
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
}
}

View File

@ -9,62 +9,62 @@ import java.util.logging.Level;
public class DataCollector {
private static AdvancedPortalsPlugin plugin;
private static AdvancedPortalsPlugin plugin;
public DataCollector(AdvancedPortalsPlugin plugin) {
DataCollector.plugin = plugin;
}
/**
*
* This is currently being tested as it doesn't fully work at the moment.
*
*/
/**public static void playerWarped() {
try {
Metrics metrics = new Metrics(plugin);
public DataCollector(AdvancedPortalsPlugin plugin) {
DataCollector.plugin = plugin;
}
Graph TotalWarps = metrics.createGraph("Total Warps");
TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") {
/**
*
* This is currently being tested as it doesn't fully work at the moment.
*
*/
@Override
public int getValue() {
return 1; // number of warps
}
/**
* public static void playerWarped() {
* try {
* Metrics metrics = new Metrics(plugin);
* <p>
* Graph TotalWarps = metrics.createGraph("Total Warps");
* <p>
* TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") {
*
* @Override public int getValue() {
* return 1; // number of warps
* }
* <p>
* });
* <p>
* metrics.start();
* } catch (IOException e) {
* plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
* }
* }
*/
});
public static void setupMetrics() {
metrics.start();
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
}
}*/
public static void setupMetrics() {
try {
Metrics metrics = new Metrics(plugin);
Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks");
/**List<Material> MaterialList = new ArrayList<Material>();
for(AdvancedPortal portal : Portal.Portals){
MaterialList.add(portal.trigger);
}*/
try {
Metrics metrics = new Metrics(plugin);
Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks");
/**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) {
/**List<Material> MaterialList = new ArrayList<Material>();
for(AdvancedPortal portal : Portal.Portals){
MaterialList.add(portal.trigger);
}*/
@Override
public int getValue() {
return 1; // number of portals created
}
/**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) {
});*/
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
}
}
@Override public int getValue() {
return 1; // number of portals created
}
});*/
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
}
}
}

View File

@ -14,163 +14,146 @@ import java.util.List;
public class DestinationCommand implements CommandExecutor, TabCompleter {
public static int PortalMessagesDisplay = 0;
public static int PortalMessagesDisplay = 0;
private AdvancedPortalsPlugin plugin;
public DestinationCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
plugin.getCommand("destination").setExecutor(this);
private AdvancedPortalsPlugin plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
public DestinationCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
}
plugin.getCommand("destination").setExecutor(this);
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){
if(args[0].toLowerCase().equals("create")){
if(sender.hasPermission("advancedportals.desti.create")){
if(args.length > 1){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X");
if(posX == null){
sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!");
Player player = sender.getServer().getPlayer(sender.getName());
Destination.create(player.getLocation(), args[1]);
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A destination by that name already exists!");
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Please state the name of the destination you would like to create!");
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!");
}
}
else if(args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml");
if(args.length > 1){
String posX = portalConfig.getConfig().getString(args[1] + ".pos.X");
if(posX != null){
Destination.remove(args[1]);
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!");
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove.");
}
}
else if(args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) {
if(args.length > 1){
//System.out.println(args[1]);
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if(configDesti.getConfig().getString(args[1] + ".world") != null){
Destination.warp(sender, args[1]);
if(PortalMessagesDisplay == 1){
sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
}
else if(PortalMessagesDisplay == 2){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to.");
}
}
else if(args[0].toLowerCase().equals("list")) {
List<String> destiList = Destination.destiList();
if(destiList.size() >= 1){
if(args.length > 1){
try
{
int page = Integer.parseInt(args[1]);
if(page * 5 >= destiList.size() - 5){ // add this if statement so that the user cant select a list page higher than the max
if(destiList.size() / 5 == destiList.size()){
}
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = (page - 1) * 5; i < page * 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
return true;
}
catch(Exception e)
{
}
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations.");
}
}
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help");
}
return true;
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
}
else if(args[0].toLowerCase().equals("create")){
}
}
Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){
autoComplete.remove(result);
}
}
return autoComplete;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if (args.length > 0) {
if (args[0].toLowerCase().equals("create")) {
if (sender.hasPermission("advancedportals.desti.create")) {
if (args.length > 1) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X");
if (posX == null) {
sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!");
Player player = sender.getServer().getPlayer(sender.getName());
Destination.create(player.getLocation(), args[1]);
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A destination by that name already exists!");
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Please state the name of the destination you would like to create!");
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!");
}
} else if (args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml");
if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos.X");
if (posX != null) {
Destination.remove(args[1]);
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!");
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove.");
}
} else if (args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) {
if (args.length > 1) {
//System.out.println(args[1]);
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (configDesti.getConfig().getString(args[1] + ".world") != null) {
Destination.warp(sender, args[1]);
if (PortalMessagesDisplay == 1) {
sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
} else if (PortalMessagesDisplay == 2) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to.");
}
} else if (args[0].toLowerCase().equals("list")) {
List<String> destiList = Destination.destiList();
if (destiList.size() >= 1) {
if (args.length > 1) {
try {
int page = Integer.parseInt(args[1]);
if (page * 5 >= destiList.size() - 5) { // add this if statement so that the user cant select a list page higher than the max
if (destiList.size() / 5 == destiList.size()) {
}
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for (int i = (page - 1) * 5; i < page * 5; i++) {
if (i > destiList.size()) {
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
return true;
} catch (Exception e) {
}
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for (int i = 0; i < 5; i++) {
if (i > destiList.size()) {
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for (int i = 0; i < 5; i++) {
if (i > destiList.size()) {
break;
}
sender.sendMessage(" \u00A7e" + destiList.get(i));
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations.");
}
}
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help");
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
if (sender.hasPermission("AdvancedPortals.CreatePortal")) {
if (args.length == 1) {
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
} else if (args[0].toLowerCase().equals("create")) {
}
}
Collections.sort(autoComplete);
for (Object result : autoComplete.toArray()) {
if (!result.toString().startsWith(args[args.length - 1])) {
autoComplete.remove(result);
}
}
return autoComplete;
}
}

View File

@ -3,17 +3,17 @@ package com.sekwah.advancedportals;
import org.bukkit.command.CommandSender;
public class PluginMessages {
// This class is so then the common messages in commands or just messages over the commands are the same and can be
// easily changed.
public static void UnknownCommand(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + "\n");
sender.sendMessage("\u00A7cIf you do not know what you can put or would like some help with the commands please type \u00A7e" + '"' + "\u00A7e/" + command + " help" + '"' + "\u00A7c\n");
}
public static void NoPermission(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!");
}
// This class is so then the common messages in commands or just messages over the commands are the same and can be
// easily changed.
public static void UnknownCommand(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + "\n");
sender.sendMessage("\u00A7cIf you do not know what you can put or would like some help with the commands please type \u00A7e" + '"' + "\u00A7e/" + command + " help" + '"' + "\u00A7c\n");
}
public static void NoPermission(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!");
}
}

View File

@ -6,275 +6,269 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
public class Selection {
public static Material blockType = Material.STAINED_GLASS;
public static int timeout = 10;
public static byte metadata = 14;
@SuppressWarnings("deprecation")
public static void LoadData(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
timeout = config.getConfig().getInt("ShowSelectionShowDuration");
String BlockID = config.getConfig().getString("ShowSelectionBlockID");
try
{
blockType = Material.getMaterial(Integer.parseInt(BlockID));
}
catch(Exception e)
{
blockType = Material.getMaterial(BlockID);
}
if(blockType == null){
blockType = Material.STAINED_GLASS;
}
metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData");
}
@SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X");
int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y");
int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z");
int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X");
int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y");
int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z");
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
public static Material blockType = Material.STAINED_GLASS;
public static int timeout = 10;
public static byte metadata = 14;
@SuppressWarnings("deprecation")
public static void LoadData(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
timeout = config.getConfig().getInt("ShowSelectionShowDuration");
String BlockID = config.getConfig().getString("ShowSelectionBlockID");
try {
blockType = Material.getMaterial(Integer.parseInt(BlockID));
} catch (Exception e) {
blockType = Material.getMaterial(BlockID);
}
if (blockType == null) {
blockType = Material.STAINED_GLASS;
}
metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData");
}
@SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X");
int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y");
int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z");
int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X");
int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y");
int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z");
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
/*
* There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements
* then i will change it, but for now its the best way i can think of for doing this.
*/
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
}
@SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin) {
int LowX = 0;
int LowY = 0;
int LowZ = 0;
int HighX = 0;
int HighY = 0;
int HighZ = 0;
if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) {
LowX = player.getMetadata("Pos2X").get(0).asInt();
HighX = player.getMetadata("Pos1X").get(0).asInt();
} else {
LowX = player.getMetadata("Pos1X").get(0).asInt();
HighX = player.getMetadata("Pos2X").get(0).asInt();
}
if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) {
LowY = player.getMetadata("Pos2Y").get(0).asInt();
HighY = player.getMetadata("Pos1Y").get(0).asInt();
} else {
LowY = player.getMetadata("Pos1Y").get(0).asInt();
HighY = player.getMetadata("Pos2Y").get(0).asInt();
}
if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) {
LowZ = player.getMetadata("Pos2Z").get(0).asInt();
HighZ = player.getMetadata("Pos1Z").get(0).asInt();
} else {
LowZ = player.getMetadata("Pos1Z").get(0).asInt();
HighZ = player.getMetadata("Pos2Z").get(0).asInt();
}
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
/*
* There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements
* then i will change it, but for now its the best way i can think of for doing this.
*/
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
}
@SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin) {
int LowX = 0;
int LowY = 0;
int LowZ = 0;
int HighX = 0;
int HighY = 0;
int HighZ = 0;
if(player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()){
LowX = player.getMetadata("Pos2X").get(0).asInt();
HighX = player.getMetadata("Pos1X").get(0).asInt();
}
else{
LowX = player.getMetadata("Pos1X").get(0).asInt();
HighX = player.getMetadata("Pos2X").get(0).asInt();
}
if(player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()){
LowY = player.getMetadata("Pos2Y").get(0).asInt();
HighY = player.getMetadata("Pos1Y").get(0).asInt();
}
else{
LowY = player.getMetadata("Pos1Y").get(0).asInt();
HighY = player.getMetadata("Pos2Y").get(0).asInt();
}
if(player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()){
LowZ = player.getMetadata("Pos2Z").get(0).asInt();
HighZ = player.getMetadata("Pos1Z").get(0).asInt();
}
else{
LowZ = player.getMetadata("Pos1Z").get(0).asInt();
HighZ = player.getMetadata("Pos2Z").get(0).asInt();
}
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ);
/*
* There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements
* then i will change it, but for now its the best way i can think of for doing this.
*/
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata);
}
@SuppressWarnings("deprecation")
protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) {
int LowX = pos1.getBlockX();
int LowY = pos1.getBlockY();
int LowZ = pos1.getBlockZ();
int HighX = pos2.getBlockX();
int HighY = pos2.getBlockY();
int HighZ = pos2.getBlockZ();
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int y = LowY; y <= HighY; y++){
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int x = LowX; x <= HighX; x++){
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for(int z = LowZ; z <= HighZ; z++){
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
}
@SuppressWarnings("deprecation")
protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) {
int LowX = pos1.getBlockX();
int LowY = pos1.getBlockY();
int LowZ = pos1.getBlockZ();
int HighX = pos2.getBlockX();
int HighY = pos2.getBlockY();
int HighZ = pos2.getBlockZ();
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}
}
}

View File

@ -12,70 +12,67 @@ import java.util.List;
public class WarpCommand implements CommandExecutor, TabCompleter {
@SuppressWarnings("unused")
private AdvancedPortalsPlugin plugin;
public WarpCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
@SuppressWarnings("unused")
private AdvancedPortalsPlugin plugin;
public WarpCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand");
//plugin.getCommand("warp").setExecutor(this);
plugin.getCommand("awarp").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){
if(Destination.warp(sender, args[0], false)){
if(DestinationCommand.PortalMessagesDisplay == 1){
sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
}
else if(DestinationCommand.PortalMessagesDisplay == 2){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
}
else{
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!");
sender.sendMessage("");
}
}
else{
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!");
sender.sendMessage("");
}
return true;
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand");
//plugin.getCommand("warp").setExecutor(this);
plugin.getCommand("awarp").setExecutor(this);
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
/**if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
}
else if(args[0].toLowerCase().equals("create")){
}
}
Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){
autoComplete.remove(result);
}
}*/
return autoComplete;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if (args.length > 0) {
if (Destination.warp(sender, args[0], false)) {
if (DestinationCommand.PortalMessagesDisplay == 1) {
sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
} else if (DestinationCommand.PortalMessagesDisplay == 2) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
} else {
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!");
sender.sendMessage("");
}
} else {
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!");
sender.sendMessage("");
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
/**if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
}
else if(args[0].toLowerCase().equals("create")){
}
}
Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){
autoComplete.remove(result);
}
}*/
return autoComplete;
}
}

View File

@ -3,8 +3,8 @@ package com.sekwah.advancedportals.compat.bukkit;
import org.bukkit.entity.Player;
public interface NMS {
void sendRawMessage(String rawMessage, Player player);
void sendActionBarMessage(String rawMessage, Player player);
void sendRawMessage(String rawMessage, Player player);
void sendActionBarMessage(String rawMessage, Player player);
}

View File

@ -8,21 +8,21 @@ import org.bukkit.entity.Player;
public class v1_8_R1 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -7,21 +7,21 @@ import org.bukkit.entity.Player;
public class v1_8_R2 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -7,21 +7,21 @@ import org.bukkit.entity.Player;
public class v1_8_R3 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -7,21 +7,21 @@ import org.bukkit.entity.Player;
public class v1_9_R1 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
@Override
public void sendActionBarMessage(String rawMessage, Player player) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage);
// "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar)
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -18,187 +18,184 @@ import java.util.Set;
import java.util.logging.Level;
public class Destination {
private static AdvancedPortalsPlugin plugin;
public Destination(AdvancedPortalsPlugin plugin) {
Destination.plugin = plugin;
public Destination(AdvancedPortalsPlugin plugin) {
Destination.plugin = plugin;
}
// TODO add permissions for destinations.
public static void create(Location location, String name){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch());
config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw());
config.saveConfig();
}
public static void move(Location location, String name){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch());
config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw());
config.saveConfig();
}
public static void rename(String oldName, String newName){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world"));
config.getConfig().set(newName.toLowerCase() + ".pos.X", config.getConfig().getDouble(oldName + ".pos.X"));
config.getConfig().set(newName.toLowerCase() + ".pos.Y", config.getConfig().getDouble(oldName + ".pos.Y"));
config.getConfig().set(newName.toLowerCase() + ".pos.Z", config.getConfig().getDouble(oldName + ".pos.Z"));
config.getConfig().set(newName.toLowerCase() + ".pos.pitch", config.getConfig().getDouble(oldName + ".pos.pitch"));
config.getConfig().set(newName.toLowerCase() + ".pos.yaw", config.getConfig().getDouble(oldName + ".pos.yaw"));
// TODO add permissions for destinations.
remove(oldName);
config.saveConfig();
}
public static void remove(String name){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", null);
config.getConfig().set(name.toLowerCase() + ".pos.X", null);
config.getConfig().set(name.toLowerCase() + ".pos.Y", null);
config.getConfig().set(name.toLowerCase() + ".pos.Z", null);
config.getConfig().set(name.toLowerCase() + ".pos.pitch", null);
config.getConfig().set(name.toLowerCase() + ".pos.yaw", null);
config.getConfig().set(name.toLowerCase() + ".pos", null);
config.getConfig().set(name.toLowerCase(), null);
config.saveConfig();
}
public static boolean warp(Player player, String name, boolean senderror){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
if(config.getConfig().getString(name + ".world") != null){
Location loc = player.getLocation();
if(Bukkit.getWorld(config.getConfig().getString(name + ".world")) != null){
loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world")));
loc.setX(config.getConfig().getDouble(name + ".pos.X"));
loc.setY(config.getConfig().getDouble(name + ".pos.Y"));
loc.setZ(config.getConfig().getDouble(name + ".pos.Z"));
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
Chunk c = loc.getChunk();
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
if(player.getVehicle() != null){
riding.eject();
riding.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
riding.setPassenger(player);
}
else{
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
return true;
}
else{
if(senderror){
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
}
return false;
}
}
else{
if(senderror){
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
}
return false;
}
}
/**
* Same as other warp but changes sender to player for you.
*
* @param player the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(Player player, String name) {
return warp(player, name, true);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name, boolean senderror) {
Player player = (Player)sender;
return warp(player, name, senderror);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name) {
Player player = (Player)sender;
return warp(player, name, true);
}
public static List<String> destiList(){
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
LinkedList<String> destiList = new LinkedList<>();
Set<String> destiSet = config.getConfig().getKeys(false);
if(destiSet.size() > 0){
for(Object desti: destiSet.toArray()){
destiSet.add(desti.toString());
}
}
Collections.sort(destiList);
return destiList;
}
public static void create(Location location, String name) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch());
config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw());
config.saveConfig();
}
public static void move(Location location, String name) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
config.getConfig().set(name.toLowerCase() + ".pos.pitch", location.getPitch());
config.getConfig().set(name.toLowerCase() + ".pos.yaw", location.getYaw());
config.saveConfig();
}
public static void rename(String oldName, String newName) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world"));
config.getConfig().set(newName.toLowerCase() + ".pos.X", config.getConfig().getDouble(oldName + ".pos.X"));
config.getConfig().set(newName.toLowerCase() + ".pos.Y", config.getConfig().getDouble(oldName + ".pos.Y"));
config.getConfig().set(newName.toLowerCase() + ".pos.Z", config.getConfig().getDouble(oldName + ".pos.Z"));
config.getConfig().set(newName.toLowerCase() + ".pos.pitch", config.getConfig().getDouble(oldName + ".pos.pitch"));
config.getConfig().set(newName.toLowerCase() + ".pos.yaw", config.getConfig().getDouble(oldName + ".pos.yaw"));
remove(oldName);
config.saveConfig();
}
public static void remove(String name) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", null);
config.getConfig().set(name.toLowerCase() + ".pos.X", null);
config.getConfig().set(name.toLowerCase() + ".pos.Y", null);
config.getConfig().set(name.toLowerCase() + ".pos.Z", null);
config.getConfig().set(name.toLowerCase() + ".pos.pitch", null);
config.getConfig().set(name.toLowerCase() + ".pos.yaw", null);
config.getConfig().set(name.toLowerCase() + ".pos", null);
config.getConfig().set(name.toLowerCase(), null);
config.saveConfig();
}
public static boolean warp(Player player, String name, boolean senderror) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
if (config.getConfig().getString(name + ".world") != null) {
Location loc = player.getLocation();
if (Bukkit.getWorld(config.getConfig().getString(name + ".world")) != null) {
loc.setWorld(Bukkit.getWorld(config.getConfig().getString(name + ".world")));
loc.setX(config.getConfig().getDouble(name + ".pos.X"));
loc.setY(config.getConfig().getDouble(name + ".pos.Y"));
loc.setZ(config.getConfig().getDouble(name + ".pos.Z"));
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
Chunk c = loc.getChunk();
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
if (player.getVehicle() != null) {
riding.eject();
riding.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
riding.setPassenger(player);
} else {
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
return true;
} else {
if (senderror) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
}
return false;
}
} else {
if (senderror) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
}
return false;
}
}
/**
* Same as other warp but changes sender to player for you.
*
* @param player the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(Player player, String name) {
return warp(player, name, true);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name, boolean senderror) {
Player player = (Player) sender;
return warp(player, name, senderror);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name) {
Player player = (Player) sender;
return warp(player, name, true);
}
public static List<String> destiList() {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
LinkedList<String> destiList = new LinkedList<>();
Set<String> destiSet = config.getConfig().getKeys(false);
if (destiSet.size() > 0) {
for (Object desti : destiSet.toArray()) {
destiSet.add(desti.toString());
}
}
Collections.sort(destiList);
return destiList;
}
}

View File

@ -10,54 +10,54 @@ import org.bukkit.entity.Player;
public class WarpEffects {
public boolean oldSoundLoc = true;
public static Sound[] sounds = new Sound[1];
public static boolean soundError = false;
public boolean oldSoundLoc = true;
public static Sound[] sounds = new Sound[1];
public WarpEffects(AdvancedPortalsPlugin plugin) {
try {
sounds[0] = Sound.valueOf("ENTITY_ENDERMEN_TELEPORT");
plugin.getLogger().info("Sounds found");
} catch (IllegalArgumentException e) {
plugin.getLogger().info("Using old effect names");
try {
sounds[0] = Sound.valueOf("ENDERMAN_TELEPORT");
} catch (IllegalArgumentException e2) {
plugin.getLogger().warning("There was an error using both the old and new names.");
soundError = true;
}
}
}
public static boolean soundError = false;
public static void activateParticles(Player player) {
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles) {
case 1:
for (int i = 0; i < 10; i++) {
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
}
loc.add(0D, 1D, 0D);
for (int i = 0; i < 10; i++) {
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
}
default:
break;
}
public WarpEffects(AdvancedPortalsPlugin plugin) {
try {
sounds[0] = Sound.valueOf("ENTITY_ENDERMEN_TELEPORT");
plugin.getLogger().info("Sounds found");
} catch (IllegalArgumentException e) {
plugin.getLogger().info("Using old effect names");
try {
sounds[0] = Sound.valueOf("ENDERMAN_TELEPORT");
} catch (IllegalArgumentException e2) {
plugin.getLogger().warning("There was an error using both the old and new names.");
soundError = true;
}
}
}
}
public static void activateParticles(Player player) {
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles){
case 1:
for(int i = 0; i < 10; i++){
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
}
loc.add(0D, 1D, 0D);
for(int i = 0; i < 10; i++){
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
}
default: break;
}
}
public static void activateSound(Player player) {
if(!soundError){
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles){
case 1:
world.playSound(loc, sounds[0], 1F, 1F);
default: break;
}
}
}
public static void activateSound(Player player) {
if (!soundError) {
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles) {
case 1:
world.playSound(loc, sounds[0], 1F, 1F);
default:
break;
}
}
}
}

View File

@ -5,76 +5,76 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public final class WarpEvent extends Event implements Cancellable {
/**
* Use listeners so you can add new triggers easier and also other plugins can listen for the event
* and add their own triggers
*/
/**
* Use listeners so you can add new triggers easier and also other plugins can listen for the event
* and add their own triggers
*/
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
private Player player;
private Player player;
@SuppressWarnings("unused")
private AdvancedPortal portalData;
private AdvancedPortal portalData;
private boolean hasWarped = false;
private boolean hasWarped = false;
public WarpEvent(Player player, AdvancedPortal portalData) {
this.player = player;
this.portalData = portalData;
this.player = player;
this.portalData = portalData;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Returns if the event has been cancelled
*
*
* @return cancelled
*/
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
public AdvancedPortal getPortalData(){return portalData;}
public AdvancedPortal getPortalData() {
return portalData;
}
/**
* If the
*
* This will return true if another plugin has warped the player(and set this to true)
*
* @return hasWarped
*/
public boolean getHasWarped() {
return hasWarped;
}
/**
* If the
*
* @param warped
*/
@SuppressWarnings("unused")
public void setHasWarped(boolean warped){
this.hasWarped = warped;
public void setHasWarped(boolean warped) {
this.hasWarped = warped;
}
/**
* This will return true if another plugin has warped the player(and set this to true)
*
* @return hasWarped
*/
public boolean getHasWarped(){
return hasWarped;
public Player getPlayer() {
return player;
}
public Player getPlayer(){
return player;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -12,62 +12,62 @@ import org.bukkit.event.block.BlockFromToEvent;
public class FlowStopper implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean WaterFlow = true;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean WaterFlow = true;
public FlowStopper(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
public FlowStopper(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
if(WaterFlow){
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
if (WaterFlow) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event) {
// when checking positions check the block and the to block
Block blockTo = event.getToBlock();
Block block = event.getBlock();
@EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event) {
// when checking positions check the block and the to block
Block blockTo = event.getToBlock();
Block block = event.getBlock();
if(!Portal.portalsActive){
return;
}
if (!Portal.portalsActive) {
return;
}
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){
if ((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()) {
if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){
event.setCancelled(true);
if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) {
}
}
event.setCancelled(true);
}
if(portal.worldName.equals(blockTo.getWorld().getName())){
}
}
if((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()){
}
if((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()){
event.setCancelled(true);
if (portal.worldName.equals(blockTo.getWorld().getName())) {
}
}
if ((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()) {
}
}
}
if ((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()) {
event.setCancelled(true);
}
}
}
}
}
}

View File

@ -25,320 +25,305 @@ import org.bukkit.metadata.FixedMetadataValue;
public class Listeners implements Listener {
private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP...
private static boolean UseOnlyServerAxe = false;
private static Material WandMaterial;
private static boolean ShowBungeeMessage;
private final AdvancedPortalsPlugin plugin;
private int PortalMessagesDisplay = 2;
private int PortalMessagesDisplay = 2;
@SuppressWarnings("deprecation")
public Listeners(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP...
private static boolean UseOnlyServerAxe = false;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
private static Material WandMaterial;
String ItemID = config.getConfig().getString("AxeItemId");
private static boolean ShowBungeeMessage;
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
@SuppressWarnings("deprecation")
public Listeners(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
try {
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
} catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
String ItemID = config.getConfig().getString("AxeItemId");
@SuppressWarnings("deprecation")
public static void reloadValues(AdvancedPortalsPlugin plugin) {
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
try
{
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
}
catch(Exception e)
{
WandMaterial = Material.getMaterial(ItemID);
}
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
String ItemID = config.getConfig().getString("AxeItemId");
@SuppressWarnings("deprecation")
public static void reloadValues(AdvancedPortalsPlugin plugin) {
try {
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
} catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
@EventHandler(priority = EventPriority.HIGHEST)
public void onMoveEvent(PlayerMoveEvent event) {
// will check if the player is in the portal or not.
if (!Portal.portalsActive) {
return;
}
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
Player player = event.getPlayer();
String ItemID = config.getConfig().getString("AxeItemId");
try
{
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
}
catch(Exception e)
{
WandMaterial = Material.getMaterial(ItemID);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onMoveEvent(PlayerMoveEvent event) {
// will check if the player is in the portal or not.
if(!Portal.portalsActive){
return;
}
Player player = event.getPlayer();
Location fromloc = event.getFrom();
Location loc = event.getTo();
// Potentially fixes that stupid error cauzed by a bukkit update.
// Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players.
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
// This is probably the culprite of the bloody problem, setting the location its pointing to the event location
// rather than sorta making a clone of the object.
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
for(AdvancedPortal portal : Portal.Portals){
if(loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())){
if(portal.trigger.equals(loc.getBlock().getType())
|| portal.trigger.equals(eyeLoc.getBlock().getType())){
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){
Location fromloc = event.getFrom();
Location loc = event.getTo();
// Potentially fixes that stupid error cauzed by a bukkit update.
// Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players.
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
// This is probably the culprite of the bloody problem, setting the location its pointing to the event location
// rather than sorta making a clone of the object.
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
for (AdvancedPortal portal : Portal.Portals) {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if (portal.trigger.equals(loc.getBlock().getType())
|| portal.trigger.equals(eyeLoc.getBlock().getType())) {
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) {
WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent);
WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!event.isCancelled()) {
boolean warped = Portal.activate(player, portal);
if(PortalMessagesDisplay == 1 && warped){
player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
player.sendMessage("");
}
else if(PortalMessagesDisplay == 2 && warped){
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
if (!event.isCancelled()) {
boolean warped = Portal.activate(player, portal);
if (PortalMessagesDisplay == 1 && warped) {
player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
player.sendMessage("");
} else if (PortalMessagesDisplay == 2 && warped) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
if(warped){
//event.setFrom(player.getLocation());
//event.setTo(player.getLocation());
if (warped) {
//event.setFrom(player.getLocation());
//event.setTo(player.getLocation());
//event.setCancelled(true);
}
else{
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
event.setCancelled(true);
}
}
//event.setCancelled(true);
} else {
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
event.setCancelled(true);
}
}
if(portal.trigger.equals(Material.PORTAL)){
if(player.getGameMode().equals(GameMode.CREATIVE)){
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
if(player != null && player.isOnline()){
player.removeMetadata("hasWarped", plugin);
}
}
}, 10);
}
}
else if(portal.trigger.equals(Material.LAVA)){
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
player.removeMetadata("lavaWarped", plugin);
player.setFireTicks(0);
}
}, 10);
}
if (portal.trigger.equals(Material.PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
if (player != null && player.isOnline()) {
player.removeMetadata("hasWarped", plugin);
}
}
}, 10);
}
} else if (portal.trigger.equals(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
player.removeMetadata("lavaWarped", plugin);
player.setFireTicks(0);
}
}, 10);
}
}
}
}
}
}
}
}
}
}
}
}
}
@EventHandler
public void onCombustEntityEvent(EntityCombustEvent event) {
if(!Portal.portalsActive){
return;
}
Location loc = event.getEntity().getLocation();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(loc.getWorld().getName())){
@EventHandler
public void onCombustEntityEvent(EntityCombustEvent event) {
if (!Portal.portalsActive) {
return;
}
Location loc = event.getEntity().getLocation();
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(loc.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
event.setCancelled(true);
return;
}
}
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true);
return;
}
}
}
}
}
}
}
}
@EventHandler
public void onDamEvent(EntityDamageEvent event) {
if(!Portal.portalsActive){
return;
}
//System.out.println(event.getCause());
if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){
Location loc = event.getEntity().getLocation();
if(event.getEntity().hasMetadata("lavaWarped")){
event.setCancelled(true);
return;
}
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(loc.getWorld().getName())){
@EventHandler
public void onDamEvent(EntityDamageEvent event) {
if (!Portal.portalsActive) {
return;
}
//System.out.println(event.getCause());
if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) {
Location loc = event.getEntity().getLocation();
if (event.getEntity().hasMetadata("lavaWarped")) {
event.setCancelled(true);
return;
}
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(loc.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
event.setCancelled(true);
return;
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true);
return;
}
}
}
}
}
}
}
}
}
}
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPortalEvent(PlayerPortalEvent event) {
if(!Portal.portalsActive){
return;
}
Player player = event.getPlayer();
@SuppressWarnings("deprecation")
@EventHandler
public void onPortalEvent(PlayerPortalEvent event) {
if (!Portal.portalsActive) {
return;
}
Player player = event.getPlayer();
if(player.hasMetadata("hasWarped")){
event.setCancelled(true);
return;
}
if (player.hasMetadata("hasWarped")) {
event.setCancelled(true);
return;
}
Location loc = player.getLocation();
Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(player.getWorld().getName())){
Location loc = player.getLocation();
Object[] portals = Portal.Portals;
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(player.getWorld().getName())) {
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) {
event.setCancelled(true);
event.setCancelled(true);
}
}
}
}
}
}
}
}
}
}
@EventHandler
public void onItemInteract(PlayerInteractEvent event) {
@EventHandler
public void onItemInteract(PlayerInteractEvent event) {
// will detect if the player is using an axe so the points of a portal can be set
// also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer();
// will detect if the player is using an axe so the points of a portal can be set
// also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer();
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
if(!Portal.portalsActive){
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
}
Block block = event.getClickedBlock();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
if (!Portal.portalsActive) {
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
}
Block block = event.getClickedBlock();
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){
if ((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()) {
if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
if ((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()) {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
}
}
}
}
}
}
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
event.setCancelled(true);
return;
}
}
}
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
event.setCancelled(true);
return;
}
if(player.hasPermission("AdvancedPortals.CreatePortal")){
if (player.hasPermission("AdvancedPortals.CreatePortal")) {
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
// as a weapon.
// Null pointer exeption detected here on some servers(try decompiling the jar file to double check)
/*try {
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
// as a weapon.
// Null pointer exeption detected here on some servers(try decompiling the jar file to double check)
/*try {
// Use this to surround the code if needed
}
catch(NullPointerException e){
}*/
if(event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id
&& (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) {
if (event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id
&& (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) {
// This checks if the action was a left or right click and if it was directly effecting a block.
if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
// stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will
// have to be selected again if the player joins, also it does not affect any other players.
player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// This checks if the action was a left or right click and if it was directly effecting a block.
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
// stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will
// have to be selected again if the player joins, also it does not affect any other players.
player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// Stops the event so the block is not damaged
event.setCancelled(true);
// Stops the event so the block is not damaged
event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed)
}
else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// Returns the event so no more code is executed(stops unnecessary code being executed)
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName());
// Stops the event so the block is not interacted with
event.setCancelled(true);
// Stops the event so the block is not interacted with
event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed)
}
// Returns the event so no more code is executed(stops unnecessary code being executed)
}
}
}
}
}
}
}
}

View File

@ -13,40 +13,39 @@ import org.bukkit.event.block.BlockPhysicsEvent;
public class PortalPlacer implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
private final double PortalProtectionRadius;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalPlace = true;
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalPlace = true;
public PortalPlacer(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalPlace){
if (PortalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
Material material = block.getType();
if (material == Material.PORTAL)
{
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
Material material = block.getType();
if (material == Material.PORTAL) {
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
@ -56,10 +55,10 @@ public class PortalPlacer implements Listener {
}
}
//event.getChangedType();
//event.setCancelled(true);
}
}
//event.getChangedType();
//event.setCancelled(true);
}
}
}

View File

@ -16,111 +16,111 @@ import java.util.List;
public class PortalProtect implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalProtect = true;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalProtect = true;
private double PortalProtectionRadius = 5D;
private double PortalProtectionRadius = 5D;
public PortalProtect(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalProtect = config.getConfig().getBoolean("PortalProtection");
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalProtect){
if (PortalProtect) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@SuppressWarnings("unused")
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event){
public void onBlockBreak(BlockBreakEvent event) {
if(!Portal.portalsActive){
return;
}
if (!Portal.portalsActive) {
return;
}
if(!event.getPlayer().hasPermission("advancedportals.build")){
Block block = event.getBlock();
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
event.setCancelled(true);
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
}
}
}
}
}
}
}
}
}
}
}
@SuppressWarnings("unused")
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event){
public void onBlockPlace(BlockPlaceEvent event) {
if(!Portal.portalsActive){
return;
}
if(!event.getPlayer().hasPermission("advancedportals.build")){
Block block = event.getBlock();
if (!Portal.portalsActive) {
return;
}
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
event.setCancelled(true);
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
}
}
}
}
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onExplosion(EntityExplodeEvent event){
public void onExplosion(EntityExplodeEvent event) {
if(!Portal.portalsActive){
return;
}
if (!Portal.portalsActive) {
return;
}
List<Block> blockList = event.blockList();
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){ // change for format for(int i = 0; i < portals.length; i++){
if(portal.worldName.equals(block.getWorld().getName())){
List<Block> blockList = event.blockList();
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
Object[] portals = Portal.Portals;
for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
blockList.remove(i);
i--;
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
}
}
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
blockList.remove(i);
i--;
}
}
}
}
}
}
}
}
}

View File

@ -132,6 +132,121 @@ public class Metrics {
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
* website. Plotters can be added to the graph object returned.
@ -475,31 +590,6 @@ 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
*
@ -514,96 +604,6 @@ 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
*/

View File

@ -4,57 +4,57 @@ import org.bukkit.Location;
import org.bukkit.Material;
public class AdvancedPortal {
public Material trigger = null;
public String worldName = null;
public Location pos1 = null;
public Location pos2 = null;
public String portalName = null;
public Material trigger = null;
// 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
public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file
public String worldName = null;
// Bungee will be stored inside the destination.
public Location pos1 = null;
public PortalArg[] portalArgs = null;
public Location pos2 = null;
// TODO think of relaying out the data input to a more logical format.
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination;
}
public String portalName = null;
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
}
// 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
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){
this(portalName, trigger, pos1, pos2, worldName, portalArgs);
this.destiation = destination;
}
public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){
this.portalName = portalName;
this.trigger = trigger;
this.pos1 = pos1;
this.pos2 = pos2;
this.worldName = worldName;
this.portalArgs = portalArgs;
}
// Bungee will be stored inside the destination.
public String getArg(String arg){
for(PortalArg portalArg : portalArgs){
if(arg.equals(portalArg.argName)){
return portalArg.value;
}
}
return null;
}
public PortalArg[] portalArgs = null;
// TODO think of relaying out the data input to a more logical format.
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
}
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, worldName, portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this.portalName = portalName;
this.trigger = trigger;
this.pos1 = pos1;
this.pos2 = pos2;
this.worldName = worldName;
this.portalArgs = portalArgs;
}
public String getArg(String arg) {
for (PortalArg portalArg : portalArgs) {
if (arg.equals(portalArg.argName)) {
return portalArg.value;
}
}
return null;
}
}

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.portals;
/**
* Created by on 29/02/2016.
*
* <p>
* TODO create argument registry for easier altering and control :) also allows other coders to add custom args
*
* @author sekwah41
@ -10,5 +10,4 @@ package com.sekwah.advancedportals.portals;
public class ArgRegistry {
}

View File

@ -19,430 +19,416 @@ import java.util.logging.Level;
public class Portal {
private static AdvancedPortalsPlugin plugin;
public static boolean portalsActive = false;
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
private static AdvancedPortalsPlugin plugin;
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
private static boolean ShowBungeeMessage;
public static boolean portalsActive = false;
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
Portal.plugin = plugin;
Portal.loadPortals();
}
private static boolean ShowBungeeMessage;
/**
* This can be used to move the get keys to different sections
* <p>
* ConfigurationSection section = portalData.getSection("sectionname");
* <p>
* section.getKeys(false);
*/
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
Portal.plugin = plugin;
Portal.loadPortals();
}
/**
* This can be used to move the get keys to different sections
*
* ConfigurationSection section = portalData.getSection("sectionname");
*
* section.getKeys(false);
*
*/
public static void loadPortals(){
portalData = new ConfigAccessor(plugin, "portals.yml");
Set<String> PortalSet = portalData.getConfig().getKeys(false);
if(PortalSet.size() > 0){
Portals = new AdvancedPortal[PortalSet.toArray().length];
public static void loadPortals() {
portalData = new ConfigAccessor(plugin, "portals.yml");
Set<String> PortalSet = portalData.getConfig().getKeys(false);
if (PortalSet.size() > 0) {
Portals = new AdvancedPortal[PortalSet.toArray().length];
/*for(int i = 0; i <= PortalSet.toArray().length - 1; i++){
Portals[i] = new AdvancedPortal();
Portals[i] = new AdvancedPortal();
}*/
int portalId = 0;
for(Object portal: PortalSet.toArray()){
ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString());
Material blockType = Material.PORTAL;
String BlockID = portalConfigSection.getString("triggerblock");
try
{
Integer.parseInt(BlockID);
System.out.println("Block names must be given not IDs");
}
catch(NumberFormatException e)
{
blockType = Material.getMaterial(BlockID);
}
if(blockType == null){
blockType = Material.PORTAL;
}
int portalId = 0;
for (Object portal : PortalSet.toArray()) {
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
ConfigurationSection portalConfigSection = portalData.getConfig().getConfigurationSection(portal.toString());
Material blockType = Material.PORTAL;
String BlockID = portalConfigSection.getString("triggerblock");
try {
Integer.parseInt(BlockID);
System.out.println("Block names must be given not IDs");
} catch (NumberFormatException e) {
blockType = Material.getMaterial(BlockID);
}
ArrayList<PortalArg> extraData = new ArrayList<>();
if (blockType == null) {
blockType = Material.PORTAL;
}
if (portalArgsConf != null) {
Set<String> argsSet = portalArgsConf.getKeys(true);
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
for(Object argName : argsSet.toArray()){
if(portalArgsConf.isString(argName.toString())){
extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
}
}
}
ArrayList<PortalArg> extraData = new ArrayList<>();
if (portalArgsConf != null) {
Set<String> argsSet = portalArgsConf.getKeys(true);
for (Object argName : argsSet.toArray()) {
if (portalArgsConf.isString(argName.toString())) {
extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
}
}
}
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
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 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"));
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs);
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 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"));
Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs);
Portals[portalId].bungee = portalConfigSection.getString("bungee");
Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
Portals[portalId].destiation = portalConfigSection.getString("destination");
Portals[portalId].bungee = portalConfigSection.getString("bungee");
portalId++;
}
portalsActive = true;
}
else{
portalsActive = false;
}
Portals[portalId].destiation = portalConfigSection.getString("destination");
}
portalId++;
}
portalsActive = true;
} else {
portalsActive = false;
}
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArg... extraData) {
return create(pos1, pos2, name, destination, triggerBlock, null, extraData);
}
}
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) {
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) {
return create(pos1, pos2, name, destination, triggerBlock, null, extraData);
}
if(!pos1.getWorld().equals(pos2.getWorld())){
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!";
}
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) {
int LowX = 0;
int LowY = 0;
int LowZ = 0;
if (!pos1.getWorld().equals(pos2.getWorld())) {
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!";
}
int HighX = 0;
int HighY = 0;
int HighZ = 0;
int LowX = 0;
int LowY = 0;
int LowZ = 0;
if(pos1.getX() > pos2.getX()){
LowX = (int) pos2.getX();
HighX = (int) pos1.getX();
}
else{
LowX = (int) pos1.getX();
HighX = (int) pos2.getX();
}
if(pos1.getY() > pos2.getY()){
LowY = (int) pos2.getY();
HighY = (int) pos1.getY();
}
else{
LowY = (int) pos1.getY();
HighY = (int) pos2.getY();
}
if(pos1.getZ() > pos2.getZ()){
LowZ = (int) pos2.getZ();
HighZ = (int) pos1.getZ();
}
else{
LowZ = (int) pos1.getZ();
HighZ = (int) pos2.getZ();
}
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
if(checkPortalOverlap(checkpos1, checkpos2)){
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
return "\u00A7cPortal creation error, portals must not overlap!";
}
int HighX = 0;
int HighY = 0;
int HighZ = 0;
portalData.getConfig().set(name + ".world", pos1.getWorld().getName());
if (pos1.getX() > pos2.getX()) {
LowX = (int) pos2.getX();
HighX = (int) pos1.getX();
} else {
LowX = (int) pos1.getX();
HighX = (int) pos2.getX();
}
if (pos1.getY() > pos2.getY()) {
LowY = (int) pos2.getY();
HighY = (int) pos1.getY();
} else {
LowY = (int) pos1.getY();
HighY = (int) pos2.getY();
}
if (pos1.getZ() > pos2.getZ()) {
LowZ = (int) pos2.getZ();
HighZ = (int) pos1.getZ();
} else {
LowZ = (int) pos1.getZ();
HighZ = (int) pos2.getZ();
}
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
if (checkPortalOverlap(checkpos1, checkpos2)) {
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
return "\u00A7cPortal creation error, portals must not overlap!";
}
portalData.getConfig().set(name + ".world", pos1.getWorld().getName());
portalData.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock));
portalData.getConfig().set(name + ".destination", destination);
portalData.getConfig().set(name + ".bungee", serverName);
portalData.getConfig().set(name + ".pos1.X", HighX);
portalData.getConfig().set(name + ".pos1.Y", HighY);
portalData.getConfig().set(name + ".pos1.Z", HighZ);
portalData.getConfig().set(name + ".pos2.X", LowX);
portalData.getConfig().set(name + ".pos2.Y", LowY);
portalData.getConfig().set(name + ".pos2.Z", LowZ);
for (PortalArg arg : portalArgs) {
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
}
portalData.saveConfig();
loadPortals();
return "\u00A7aPortal creation successful!";
}
// make this actually work!
private static boolean checkPortalOverlap(Location pos1, Location pos2) {
if (portalsActive) {
int portalId = 0;
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 (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
return true;
}
}
portalId++;
}
}
return false;
}
private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) {
if (pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ) {
if ((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ) {
return true;
}
}
return false;
}
portalData.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock));
private static String checkMaterial(Material triggerBlock) {
if (triggerBlock.equals(Material.WATER)) {
return "STATIONARY_WATER";
} else if (triggerBlock.equals(Material.LAVA)) {
return "STATIONARY_LAVA";
}
return triggerBlock.toString();
}
portalData.getConfig().set(name + ".destination", destination);
@SuppressWarnings("deprecation")
public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
portalData.getConfig().set(name + ".bungee", serverName);
Material triggerBlockType;
String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock");
try {
triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID));
} catch (Exception e) {
triggerBlockType = Material.getMaterial(BlockID);
}
portalData.getConfig().set(name + ".pos1.X", HighX);
portalData.getConfig().set(name + ".pos1.Y", HighY);
portalData.getConfig().set(name + ".pos1.Z", HighZ);
if (triggerBlockType == null) {
triggerBlockType = Material.PORTAL;
}
portalData.getConfig().set(name + ".pos2.X", LowX);
portalData.getConfig().set(name + ".pos2.Y", LowY);
portalData.getConfig().set(name + ".pos2.Z", LowZ);
// TODO add a for loop which scans through the addArgs and adds them to the portalData so that the application can use them
for(PortalArg arg: portalArgs){
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
}
String result = create(pos1, pos2, name, destination, triggerBlockType, serverName, extraData);
portalData.saveConfig();
return result;
}
loadPortals();
public static void redefine(Location pos1, Location pos2, String name) {
return "\u00A7aPortal creation successful!";
}
portalData.getConfig().set(name + ".pos1.X", pos1.getX());
portalData.getConfig().set(name + ".pos1.Y", pos1.getY());
portalData.getConfig().set(name + ".pos1.Z", pos1.getZ());
// make this actually work!
private static boolean checkPortalOverlap(Location pos1, Location pos2) {
portalData.getConfig().set(name + ".pos2.X", pos2.getX());
portalData.getConfig().set(name + ".pos2.Y", pos2.getY());
portalData.getConfig().set(name + ".pos2.Z", pos2.getZ());
if(portalsActive){
int portalId = 0;
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(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;}
portalData.saveConfig();
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;}
loadPortals();
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())){return true;}
if(checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())){return true;}
}
portalId++;
}
}
return false;
}
private static boolean checkOverLapPortal(Location pos1, Location pos2, int posX, int posY, int posZ) {
if(pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ){
if((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ){
return true;
}
}
}
return false;
}
public static String getDestination(String portalName) {
return portalData.getConfig().getString(portalName + ".destination");
}
private static String checkMaterial(Material triggerBlock) {
if(triggerBlock.equals(Material.WATER)){
return "STATIONARY_WATER";
}
else if(triggerBlock.equals(Material.LAVA)){
return "STATIONARY_LAVA";
}
return triggerBlock.toString();
}
public static void remove(String name) {
@SuppressWarnings("deprecation")
public static String create(Location pos1, Location pos2, String name, String destination, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
Object[] keys = portalData.getConfig().getKeys(true).toArray();
for (int i = keys.length - 1; i >= 0; i--) {
String key = keys[i].toString();
if (key.startsWith(name + ".")) {
portalData.getConfig().set(key, null);
}
}
portalData.getConfig().set(name, null);
Material triggerBlockType;
String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock");
try
{
triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID));
}
catch(Exception e)
{
triggerBlockType = Material.getMaterial(BlockID);
}
// TODO add code to check if people have the portal selected and notify if removed.
if(triggerBlockType == null){
triggerBlockType = Material.PORTAL;
}
/**Set<String> keys = portalData.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(name)){
portalData.getConfig().set(key, null);
}
}*/
// TODO add a for loop which scans through the addArgs and adds them to the portalData so that the application can use them
/**portalData.getConfig().set(name + ".world", null);
portalData.getConfig().set(name + ".triggerblock", null);
portalData.getConfig().set(name + ".destination", null);
String result = create(pos1, pos2, name, destination, triggerBlockType, serverName, extraData);
portalData.getConfig().set(name + ".pos1.X", null);
portalData.getConfig().set(name + ".pos1.Y", null);
portalData.getConfig().set(name + ".pos1.Z", null);
return result;
}
portalData.getConfig().set(name + ".pos2.X", null);
portalData.getConfig().set(name + ".pos2.Y", null);
portalData.getConfig().set(name + ".pos2.Z", null);
public static void redefine(Location pos1, Location pos2, String name){
portalData.getConfig().set(name + ".pos1", null);
portalData.getConfig().set(name + ".pos2", null);
portalData.getConfig().set(name + ".pos1.X", pos1.getX());
portalData.getConfig().set(name + ".pos1.Y", pos1.getY());
portalData.getConfig().set(name + ".pos1.Z", pos1.getZ());
portalData.getConfig().set(name, null);*/
portalData.getConfig().set(name + ".pos2.X", pos2.getX());
portalData.getConfig().set(name + ".pos2.Y", pos2.getY());
portalData.getConfig().set(name + ".pos2.Z", pos2.getZ());
portalData.saveConfig();
portalData.saveConfig();
loadPortals();
}
loadPortals();
public static boolean portalExists(String portalName) {
}
String posX = portalData.getConfig().getString(portalName + ".pos1.X");
public static String getDestination(String portalName){
return portalData.getConfig().getString(portalName + ".destination");
}
return posX != null;
}
public static void remove(String name){
public static boolean activate(Player player, String portalName) {
for (AdvancedPortal portal : Portal.Portals) {
if (portal.portalName.equals(portalName)) return activate(player, portal);
}
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
return false;
}
Object[] keys = portalData.getConfig().getKeys(true).toArray();
for(int i = keys.length - 1; i >= 0; i--){
String key = keys[i].toString();
if(key.startsWith(name + ".")){
portalData.getConfig().set(key, null);
}
}
portalData.getConfig().set(name, null);
public static boolean activate(Player player, AdvancedPortal portal) {
// TODO add code to check if people have the portal selected and notify if removed.
// add other variables or filter code here, or somehow have a way to register them
/**Set<String> keys = portalData.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(name)){
portalData.getConfig().set(key, null);
}
}*/
/**portalData.getConfig().set(name + ".world", null);
portalData.getConfig().set(name + ".triggerblock", null);
portalData.getConfig().set(name + ".destination", null);
portalData.getConfig().set(name + ".pos1.X", null);
portalData.getConfig().set(name + ".pos1.Y", null);
portalData.getConfig().set(name + ".pos1.Z", null);
portalData.getConfig().set(name + ".pos2.X", null);
portalData.getConfig().set(name + ".pos2.Y", null);
portalData.getConfig().set(name + ".pos2.Z", null);
portalData.getConfig().set(name + ".pos1", null);
portalData.getConfig().set(name + ".pos2", null);
portalData.getConfig().set(name, null);*/
portalData.saveConfig();
loadPortals();
}
public static boolean portalExists(String portalName){
String posX = portalData.getConfig().getString(portalName + ".pos1.X");
if(posX == null){
return false;
}
else{
return true;
}
}
public static boolean activate(Player player, String portalName) {
for(AdvancedPortal portal : Portal.Portals){
if(portal.portalName.equals(portalName)) return activate(player, portal);
}
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
return false;
}
public static boolean activate(Player player, AdvancedPortal portal) {
// add other variables or filter code here, or somehow have a way to register them
String permission = portal.getArg("permission");
String permission = portal.getArg("permission");
/*if((permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())){*/
if(!((permission != null && player.hasPermission(permission)) || player.isOp())){
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!");
return false;
}
if (!((permission != null && player.hasPermission(permission)) || player.isOp())) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!");
return false;
}
if(portal.bungee != null){
if(ShowBungeeMessage){
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(portal.bungee);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return false;
if (portal.bungee != null) {
if (ShowBungeeMessage) {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(portal.bungee);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return false;
}
else{
boolean showFailMessage = true;
} else {
boolean showFailMessage = true;
if(portal.getArg("command.1") != null){
showFailMessage = false;
int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do{
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
if(command.startsWith("#")){
command = command.substring(1);
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
else if(command.startsWith("!")){
command = command.substring(1);
boolean wasOp = player.isOp();
try{
player.setOp(true);
player.performCommand(command);
}
finally {
player.setOp(wasOp);
}
}
else if(command.startsWith("^")){
command = command.substring(1);
PermissionAttachment permissionAttachment = null;
try{
permissionAttachment = player.addAttachment(plugin, "*", true);
player.performCommand(command);
}
finally {
player.removeAttachment(permissionAttachment);
}
}
else{
player.performCommand(command);
}
command = portal.getArg("command." + ++commandLine);
}while(command != null);
}
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if(portal.destiation != null){
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if(configDesti.getConfig().getString(portal.destiation + ".world") != null){
boolean warped = Destination.warp(player, portal.destiation);
return warped;
}
else{
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
}
else{
if(showFailMessage) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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 "
+ "attempt and either the data is corrupt or portal doesn't exist!");
}
return false;
}
if (portal.getArg("command.1") != null) {
showFailMessage = false;
int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do {
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
if (command.startsWith("#")) {
command = command.substring(1);
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} else if (command.startsWith("!")) {
command = command.substring(1);
boolean wasOp = player.isOp();
try {
player.setOp(true);
player.performCommand(command);
} finally {
player.setOp(wasOp);
}
} else if (command.startsWith("^")) {
command = command.substring(1);
PermissionAttachment permissionAttachment = null;
try {
permissionAttachment = player.addAttachment(plugin, "*", true);
player.performCommand(command);
} finally {
player.removeAttachment(permissionAttachment);
}
} else {
player.performCommand(command);
}
command = portal.getArg("command." + ++commandLine);
} while (command != null);
}
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if (portal.destiation != null) {
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
boolean warped = Destination.warp(player, portal.destiation);
return warped;
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
} else {
if (showFailMessage) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\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 "
+ "attempt and either the data is corrupt or portal doesn't exist!");
}
return false;
}
/*if(configDesti.getConfig().getString(destiName + ".world") != null){
String permission = portalData.getConfig().getString(portalName + ".portalArgs.permission");
@ -462,52 +448,49 @@ public class Portal {
return false;
}*/
}
}
}
}
public static void rename(String oldName, String newName){
public static void rename(String oldName, String newName) {
// set it so it gets all data from one and puts it into another place
// set it so it gets all data from one and puts it into another place
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
Set<String> keys = config.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(oldName + ".")){
if(config.getConfig().getString(key) != null){
try
{
int intData = Integer.parseInt(config.getConfig().getString(key));
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
}
catch(Exception e)
{
config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key));
}
Set<String> keys = config.getConfig().getKeys(true);
for (String key : keys) {
if (key.startsWith(oldName + ".")) {
if (config.getConfig().getString(key) != null) {
try {
int intData = Integer.parseInt(config.getConfig().getString(key));
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
} catch (Exception e) {
config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key));
}
}
}
}
}
}
}
config.saveConfig();
config.saveConfig();
remove(oldName);
remove(oldName);
}
}
public static boolean addCommand(String portalName, String portalCommand) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
if(portalExists(portalName)){
int commandLine = 0;
while(config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null); //Loops increasing commandLine till 1 is null
config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand);
config.saveConfig();
loadPortals();
return true;
}
else{
return false;
}
}
public static boolean addCommand(String portalName, String portalCommand) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
if (portalExists(portalName)) {
int commandLine = 0;
while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null)
; //Loops increasing commandLine till 1 is null
config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand);
config.saveConfig();
loadPortals();
return true;
} else {
return false;
}
}
}

View File

@ -6,7 +6,7 @@ public class PortalArg {
public final String value;
//public final int type;
public PortalArg(String argName, String value/*, int type*/){
public PortalArg(String argName, String value/*, int type*/) {
this.argName = argName;
this.value = value;
// may be used if values need to be 100% not string

View File

@ -6,7 +6,7 @@ import java.util.Map;
/**
* Created by on 29/03/2016.
*
* <p>
* TODO add all the normal tags then add the extradata tags
*
* @author sekwah41
@ -15,12 +15,12 @@ public class PortalTags {
// TODO create a list or hashmap of tags to check for.
public Map<String, String> tagDesc = new HashMap<String,String>();
public Map<String, String> tagDesc = new HashMap<String, String>();
public ArrayList<String> tags = new ArrayList<String>();
public void registerTag(String tagName){
public void registerTag(String tagName) {
this.registerTag(tagName, false);
}
@ -31,11 +31,11 @@ public class PortalTags {
* @param tagName
* @param description
*/
public void registerTag(String tagName, boolean multiWord, String description){
public void registerTag(String tagName, boolean multiWord, String description) {
this.registerTag(tagName, multiWord);
}
public void registerTag(String tagName, boolean multiWord){
public void registerTag(String tagName, boolean multiWord) {
}