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

View File

@ -9,62 +9,62 @@ import java.util.logging.Level;
public class DataCollector { public class DataCollector {
private static AdvancedPortalsPlugin plugin; private static AdvancedPortalsPlugin plugin;
public DataCollector(AdvancedPortalsPlugin plugin) { public DataCollector(AdvancedPortalsPlugin plugin) {
DataCollector.plugin = plugin; DataCollector.plugin = plugin;
} }
/** /**
* *
* This is currently being tested as it doesn't fully work at the moment. * This is currently being tested as it doesn't fully work at the moment.
* *
*/ */
/**public static void playerWarped() { /**
try { * public static void playerWarped() {
Metrics metrics = new Metrics(plugin); * 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);
* }
* }
*/
Graph TotalWarps = metrics.createGraph("Total Warps"); public static void setupMetrics() {
TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") { try {
Metrics metrics = new Metrics(plugin);
Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks");
@Override /**List<Material> MaterialList = new ArrayList<Material>();
public int getValue() { for(AdvancedPortal portal : Portal.Portals){
return 1; // number of warps MaterialList.add(portal.trigger);
} }*/
}); /**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) {
metrics.start(); @Override public int getValue() {
} catch (IOException e) { return 1; // number of portals created
plugin.getLogger().log(Level.SEVERE, "Could not submit data", e); }
}
}*/
public static void setupMetrics() { });*/
try { } catch (IOException e) {
Metrics metrics = new Metrics(plugin); plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks"); }
}
/**List<Material> MaterialList = new ArrayList<Material>();
for(AdvancedPortal portal : Portal.Portals){
MaterialList.add(portal.trigger);
}*/
/**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) {
@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 class DestinationCommand implements CommandExecutor, TabCompleter {
public static int PortalMessagesDisplay = 0; public static int PortalMessagesDisplay = 0;
private AdvancedPortalsPlugin plugin; private AdvancedPortalsPlugin plugin;
public DestinationCommand(AdvancedPortalsPlugin plugin) { public DestinationCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
plugin.getCommand("destination").setExecutor(this); plugin.getCommand("destination").setExecutor(this);
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){ if (args.length > 0) {
if(args[0].toLowerCase().equals("create")){ if (args[0].toLowerCase().equals("create")) {
if(sender.hasPermission("advancedportals.desti.create")){ if (sender.hasPermission("advancedportals.desti.create")) {
if(args.length > 1){ if (args.length > 1) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X");
if(posX == null){ if (posX == null) {
sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!"); sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!");
Player player = sender.getServer().getPlayer(sender.getName()); Player player = sender.getServer().getPlayer(sender.getName());
Destination.create(player.getLocation(), args[1]); Destination.create(player.getLocation(), args[1]);
} } else {
else{ sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A destination by that name already exists!");
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] 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{ } else if (args[0].toLowerCase().equals("remove")) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml");
} if (args.length > 1) {
} String posX = portalConfig.getConfig().getString(args[1] + ".pos.X");
else if(args[0].toLowerCase().equals("remove")) { if (posX != null) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); Destination.remove(args[1]);
if(args.length > 1){ sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!");
String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); } else {
if(posX != null){ sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
Destination.remove(args[1]); }
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); } else {
} sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove.");
else{ }
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); } else if (args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) {
} if (args.length > 1) {
} //System.out.println(args[1]);
else{ ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove."); if (configDesti.getConfig().getString(args[1] + ".world") != null) {
} Destination.warp(sender, args[1]);
} if (PortalMessagesDisplay == 1) {
else if(args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) { sender.sendMessage("");
if(args.length > 1){ sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.");
//System.out.println(args[1]); sender.sendMessage("");
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); } else if (PortalMessagesDisplay == 2) {
if(configDesti.getConfig().getString(args[1] + ".world") != null){ ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
Destination.warp(sender, args[1]); plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
if(PortalMessagesDisplay == 1){ /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
sender.sendMessage(""); + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a."); }
sender.sendMessage(""); } else {
} sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
else if(PortalMessagesDisplay == 2){ }
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); } else {
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to.");
/**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 if (args[0].toLowerCase().equals("list")) {
} List<String> destiList = Destination.destiList();
} if (destiList.size() >= 1) {
else{ if (args.length > 1) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); 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
else{ if (destiList.size() / 5 == destiList.size()) {
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"); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = (page - 1) * 5; i < page * 5; i++){ for (int i = (page - 1) * 5; i < page * 5; i++) {
if(i > destiList.size()){ if (i > destiList.size()) {
break; break;
} }
sender.sendMessage(" \u00A7e" + destiList.get(i)); sender.sendMessage(" \u00A7e" + destiList.get(i));
} }
return true; return true;
} } catch (Exception e) {
catch(Exception e) }
{ }
}
}
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++) {
if(i > destiList.size()){ if (i > destiList.size()) {
break; break;
} }
sender.sendMessage(" \u00A7e" + destiList.get(i)); sender.sendMessage(" \u00A7e" + destiList.get(i));
} }
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++) {
if(i > destiList.size()){ if (i > destiList.size()) {
break; break;
} }
sender.sendMessage(" \u00A7e" + destiList.get(i)); sender.sendMessage(" \u00A7e" + destiList.get(i));
} }
} } else {
else{ sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations.");
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");
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;
} }
return true;
}
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>(); LinkedList<String> autoComplete = new LinkedList<String>();
if(sender.hasPermission("AdvancedPortals.CreatePortal")){ if (sender.hasPermission("AdvancedPortals.CreatePortal")) {
if(args.length == 1){ if (args.length == 1) {
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
} } else if (args[0].toLowerCase().equals("create")) {
else if(args[0].toLowerCase().equals("create")){ }
} }
} Collections.sort(autoComplete);
Collections.sort(autoComplete); for (Object result : autoComplete.toArray()) {
for(Object result: autoComplete.toArray()){ if (!result.toString().startsWith(args[args.length - 1])) {
if(!result.toString().startsWith(args[args.length - 1])){ autoComplete.remove(result);
autoComplete.remove(result); }
} }
} return autoComplete;
return autoComplete; }
}
} }

View File

@ -4,16 +4,16 @@ import org.bukkit.command.CommandSender;
public class PluginMessages { 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 // This class is so then the common messages in commands or just messages over the commands are the same and can be
// easily changed. // easily changed.
public static void UnknownCommand(CommandSender sender, String command) { public static void UnknownCommand(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + "\n"); 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"); 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) { public static void NoPermission(CommandSender sender, String command) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!"); sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!");
} }
} }

View File

@ -7,274 +7,268 @@ import org.bukkit.entity.Player;
public class Selection { public class Selection {
public static Material blockType = Material.STAINED_GLASS; public static Material blockType = Material.STAINED_GLASS;
public static int timeout = 10; public static int timeout = 10;
public static byte metadata = 14; public static byte metadata = 14;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void LoadData(AdvancedPortalsPlugin plugin) { public static void LoadData(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
timeout = config.getConfig().getInt("ShowSelectionShowDuration"); timeout = config.getConfig().getInt("ShowSelectionShowDuration");
String BlockID = config.getConfig().getString("ShowSelectionBlockID"); String BlockID = config.getConfig().getString("ShowSelectionBlockID");
try try {
{ blockType = Material.getMaterial(Integer.parseInt(BlockID));
blockType = Material.getMaterial(Integer.parseInt(BlockID)); } catch (Exception e) {
} blockType = Material.getMaterial(BlockID);
catch(Exception e) }
{
blockType = Material.getMaterial(BlockID);
}
if(blockType == null){ if (blockType == null) {
blockType = Material.STAINED_GLASS; blockType = Material.STAINED_GLASS;
} }
metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData"); metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData");
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) { public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X"); int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X");
int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y"); int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y");
int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z"); int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z");
int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X"); int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X");
int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y"); int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y");
int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z"); int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z");
final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); 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 * 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. * 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++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ); Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ); Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z); Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z); Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ); Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ); Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ); Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ); Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ); Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ); Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z); Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z); Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run(){ public void run() {
Selection.Hide(player, plugin, pos1, pos2); Selection.Hide(player, plugin, pos1, pos2);
} }
}, timeout * 20); }, timeout * 20);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void Show(final Player player, final AdvancedPortalsPlugin plugin) { public static void Show(final Player player, final AdvancedPortalsPlugin plugin) {
int LowX = 0; int LowX = 0;
int LowY = 0; int LowY = 0;
int LowZ = 0; int LowZ = 0;
int HighX = 0; int HighX = 0;
int HighY = 0; int HighY = 0;
int HighZ = 0; int HighZ = 0;
if(player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()){ if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) {
LowX = player.getMetadata("Pos2X").get(0).asInt(); LowX = player.getMetadata("Pos2X").get(0).asInt();
HighX = player.getMetadata("Pos1X").get(0).asInt(); HighX = player.getMetadata("Pos1X").get(0).asInt();
} } else {
else{ LowX = player.getMetadata("Pos1X").get(0).asInt();
LowX = player.getMetadata("Pos1X").get(0).asInt(); HighX = player.getMetadata("Pos2X").get(0).asInt();
HighX = player.getMetadata("Pos2X").get(0).asInt(); }
} if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) {
if(player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()){ LowY = player.getMetadata("Pos2Y").get(0).asInt();
LowY = player.getMetadata("Pos2Y").get(0).asInt(); HighY = player.getMetadata("Pos1Y").get(0).asInt();
HighY = player.getMetadata("Pos1Y").get(0).asInt(); } else {
} LowY = player.getMetadata("Pos1Y").get(0).asInt();
else{ HighY = player.getMetadata("Pos2Y").get(0).asInt();
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();
if(player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()){ HighZ = player.getMetadata("Pos1Z").get(0).asInt();
LowZ = player.getMetadata("Pos2Z").get(0).asInt(); } else {
HighZ = player.getMetadata("Pos1Z").get(0).asInt(); LowZ = player.getMetadata("Pos1Z").get(0).asInt();
} HighZ = player.getMetadata("Pos2Z").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 pos1 = new Location(player.getWorld(), LowX, LowY, LowZ);
final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); 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 * 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. * 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++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ); Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ); Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z); Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z); Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ); Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ); Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ); Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ); Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ); Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ); Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z); Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z); Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, blockType, metadata); player.sendBlockChange(loc, blockType, metadata);
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run(){ public void run() {
Selection.Hide(player, plugin, pos1, pos2); Selection.Hide(player, plugin, pos1, pos2);
} }
}, timeout * 20); }, timeout * 20);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) { protected static void Hide(Player player, AdvancedPortalsPlugin plugin, Location pos1, Location pos2) {
int LowX = pos1.getBlockX(); int LowX = pos1.getBlockX();
int LowY = pos1.getBlockY(); int LowY = pos1.getBlockY();
int LowZ = pos1.getBlockZ(); int LowZ = pos1.getBlockZ();
int HighX = pos2.getBlockX(); int HighX = pos2.getBlockX();
int HighY = pos2.getBlockY(); int HighY = pos2.getBlockY();
int HighZ = pos2.getBlockZ(); int HighZ = pos2.getBlockZ();
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, LowZ); Location loc = new Location(player.getWorld(), x, LowY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, LowY, HighZ); Location loc = new Location(player.getWorld(), x, LowY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, LowY, z); Location loc = new Location(player.getWorld(), LowX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, LowY, z); Location loc = new Location(player.getWorld(), HighX, LowY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, LowZ); Location loc = new Location(player.getWorld(), LowX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), LowX, y, HighZ); Location loc = new Location(player.getWorld(), LowX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, LowZ); Location loc = new Location(player.getWorld(), HighX, y, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int y = LowY; y <= HighY; y++){ for (int y = LowY; y <= HighY; y++) {
Location loc = new Location(player.getWorld(), HighX, y, HighZ); Location loc = new Location(player.getWorld(), HighX, y, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, HighZ); Location loc = new Location(player.getWorld(), x, HighY, HighZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int x = LowX; x <= HighX; x++){ for (int x = LowX; x <= HighX; x++) {
Location loc = new Location(player.getWorld(), x, HighY, LowZ); Location loc = new Location(player.getWorld(), x, HighY, LowZ);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), LowX, HighY, z); Location loc = new Location(player.getWorld(), LowX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
} }
for(int z = LowZ; z <= HighZ; z++){ for (int z = LowZ; z <= HighZ; z++) {
Location loc = new Location(player.getWorld(), HighX, HighY, z); Location loc = new Location(player.getWorld(), HighX, HighY, z);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData()); 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 { public class WarpCommand implements CommandExecutor, TabCompleter {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private AdvancedPortalsPlugin plugin; private AdvancedPortalsPlugin plugin;
public WarpCommand(AdvancedPortalsPlugin plugin) { public WarpCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand"); boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand");
//plugin.getCommand("warp").setExecutor(this); //plugin.getCommand("warp").setExecutor(this);
plugin.getCommand("awarp").setExecutor(this); plugin.getCommand("awarp").setExecutor(this);
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){ if (args.length > 0) {
if(Destination.warp(sender, args[0], false)){ if (Destination.warp(sender, args[0], false)) {
if(DestinationCommand.PortalMessagesDisplay == 1){ if (DestinationCommand.PortalMessagesDisplay == 1) {
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a."); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage(""); sender.sendMessage("");
} } else if (DestinationCommand.PortalMessagesDisplay == 2) {
else if(DestinationCommand.PortalMessagesDisplay == 2){ ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
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\":\"\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("_", " ")
/**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);*/
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ }
} } else {
} sender.sendMessage("");
else{ sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!");
sender.sendMessage(""); 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 + "!");
else{ sender.sendMessage("");
sender.sendMessage(""); }
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!"); return true;
sender.sendMessage(""); }
}
return true;
}
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>(); LinkedList<String> autoComplete = new LinkedList<String>();
/**if(sender.hasPermission("AdvancedPortals.CreatePortal")){ /**if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){ if(args.length == 1){
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
} }
else if(args[0].toLowerCase().equals("create")){ else if(args[0].toLowerCase().equals("create")){
} }
} }
Collections.sort(autoComplete); Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){ for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){ if(!result.toString().startsWith(args[args.length - 1])){
autoComplete.remove(result); autoComplete.remove(result);
} }
}*/ }*/
return autoComplete; return autoComplete;
} }
} }

View File

@ -4,7 +4,7 @@ import org.bukkit.entity.Player;
public interface NMS { public interface NMS {
void sendRawMessage(String rawMessage, Player player); void sendRawMessage(String rawMessage, Player player);
void sendActionBarMessage(String rawMessage, Player player); void sendActionBarMessage(String rawMessage, Player player);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,54 +10,54 @@ import org.bukkit.entity.Player;
public class WarpEffects { 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) { public static void activateSound(Player player) {
Location loc = player.getLocation(); if (!soundError) {
World world = player.getWorld(); Location loc = player.getLocation();
switch (Assets.currentWarpParticles){ World world = player.getWorld();
case 1: switch (Assets.currentWarpParticles) {
for(int i = 0; i < 10; i++){ case 1:
world.playEffect(loc, Effect.ENDER_SIGNAL, 0); world.playSound(loc, sounds[0], 1F, 1F);
} default:
loc.add(0D, 1D, 0D); break;
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;
}
}
}
} }

View File

@ -8,28 +8,31 @@ import org.bukkit.event.HandlerList;
public final class WarpEvent extends Event implements Cancellable { 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 * Use listeners so you can add new triggers easier and also other plugins can listen for the event
* and add their own triggers * and add their own triggers
*/ */
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false; private boolean cancelled = false;
private Player player; private Player player;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private AdvancedPortal portalData; private AdvancedPortal portalData;
private boolean hasWarped = false; private boolean hasWarped = false;
public WarpEvent(Player player, AdvancedPortal portalData) { public WarpEvent(Player player, AdvancedPortal portalData) {
this.player = player; this.player = player;
this.portalData = portalData; this.portalData = portalData;
} }
public static HandlerList getHandlerList() {
return handlers;
}
/** /**
* Returns if the event has been cancelled * Returns if the event has been cancelled
@ -44,16 +47,8 @@ public final class WarpEvent extends Event implements Cancellable {
cancelled = cancel; cancelled = cancel;
} }
public AdvancedPortal getPortalData(){return portalData;} public AdvancedPortal getPortalData() {
return portalData;
/**
* If the
*
* @param warped
*/
@SuppressWarnings("unused")
public void setHasWarped(boolean warped){
this.hasWarped = warped;
} }
/** /**
@ -61,20 +56,25 @@ public final class WarpEvent extends Event implements Cancellable {
* *
* @return hasWarped * @return hasWarped
*/ */
public boolean getHasWarped(){ public boolean getHasWarped() {
return hasWarped; return hasWarped;
} }
public Player getPlayer(){ /**
return player; * If the
*
* @param warped
*/
@SuppressWarnings("unused")
public void setHasWarped(boolean warped) {
this.hasWarped = warped;
} }
public Player getPlayer() {
return player;
}
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; 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 { public class FlowStopper implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later // 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... // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean WaterFlow = true; private boolean WaterFlow = true;
public FlowStopper(AdvancedPortalsPlugin plugin) { public FlowStopper(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow"); this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
if(WaterFlow){ if (WaterFlow) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event) { public void onBlockFromTo(BlockFromToEvent event) {
// when checking positions check the block and the to block // when checking positions check the block and the to block
Block blockTo = event.getToBlock(); Block blockTo = event.getToBlock();
Block block = event.getBlock(); Block block = event.getBlock();
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(block.getWorld().getName())){ 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()){ if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
if(portal.worldName.equals(blockTo.getWorld().getName())){ 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.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()){ if ((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
} }
} }
} }

View File

@ -25,320 +25,305 @@ import org.bukkit.metadata.FixedMetadataValue;
public class Listeners implements Listener { 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 ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
private static boolean UseOnlyServerAxe = false;
private static Material WandMaterial; String ItemID = config.getConfig().getString("AxeItemId");
private static boolean ShowBungeeMessage; PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
@SuppressWarnings("deprecation") try {
public Listeners(AdvancedPortalsPlugin plugin) { WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
this.plugin = plugin; } catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); plugin.getServer().getPluginManager().registerEvents(this, plugin);
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); }
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 ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
{
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
}
catch(Exception e)
{
WandMaterial = Material.getMaterial(ItemID);
}
plugin.getServer().getPluginManager().registerEvents(this, plugin); String ItemID = config.getConfig().getString("AxeItemId");
}
@SuppressWarnings("deprecation") try {
public static void reloadValues(AdvancedPortalsPlugin plugin) { WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
} catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
}
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); @EventHandler(priority = EventPriority.HIGHEST)
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); 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"); Location fromloc = event.getFrom();
Location loc = event.getTo();
try // 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.
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); 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
catch(Exception e) // 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.
WandMaterial = Material.getMaterial(ItemID); //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())
@EventHandler(priority = EventPriority.HIGHEST) || portal.trigger.equals(eyeLoc.getBlock().getType())) {
public void onMoveEvent(PlayerMoveEvent event) { if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
// will check if the player is in the portal or not. if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) {
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()){
WarpEvent warpEvent = new WarpEvent(player, portal); WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent); plugin.getServer().getPluginManager().callEvent(warpEvent);
if (!event.isCancelled()) { if (!event.isCancelled()) {
boolean warped = Portal.activate(player, portal); boolean warped = Portal.activate(player, portal);
if(PortalMessagesDisplay == 1 && warped){ if (PortalMessagesDisplay == 1 && warped) {
player.sendMessage(""); player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
player.sendMessage(""); player.sendMessage("");
} } else if (PortalMessagesDisplay == 2 && warped) {
else if(PortalMessagesDisplay == 2 && warped){ ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
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\":\"\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("_", " ")
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ }
}
if(warped){ if (warped) {
//event.setFrom(player.getLocation()); //event.setFrom(player.getLocation());
//event.setTo(player.getLocation()); //event.setTo(player.getLocation());
//event.setCancelled(true); //event.setCancelled(true);
} } else {
else{ player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); event.setCancelled(true);
event.setCancelled(true); }
} }
}
if(portal.trigger.equals(Material.PORTAL)){ if (portal.trigger.equals(Material.PORTAL)) {
if(player.getGameMode().equals(GameMode.CREATIVE)){ if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run(){ public void run() {
if(player != null && player.isOnline()){ if (player != null && player.isOnline()) {
player.removeMetadata("hasWarped", plugin); player.removeMetadata("hasWarped", plugin);
} }
} }
}, 10); }, 10);
} }
} } else if (portal.trigger.equals(Material.LAVA)) {
else if(portal.trigger.equals(Material.LAVA)){ player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ public void run() {
public void run(){ player.removeMetadata("lavaWarped", plugin);
player.removeMetadata("lavaWarped", plugin); player.setFireTicks(0);
player.setFireTicks(0); }
} }, 10);
}, 10); }
}
} }
} }
} }
} }
} }
} }
@EventHandler @EventHandler
public void onCombustEntityEvent(EntityCombustEvent event) { public void onCombustEntityEvent(EntityCombustEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
Location loc = event.getEntity().getLocation(); Location loc = event.getEntity().getLocation();
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(loc.getWorld().getName())){ 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()){ if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} }
} }
} }
@EventHandler @EventHandler
public void onDamEvent(EntityDamageEvent event) { public void onDamEvent(EntityDamageEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
//System.out.println(event.getCause()); //System.out.println(event.getCause());
if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){ if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) {
Location loc = event.getEntity().getLocation(); Location loc = event.getEntity().getLocation();
if(event.getEntity().hasMetadata("lavaWarped")){ if (event.getEntity().hasMetadata("lavaWarped")) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(loc.getWorld().getName())){ 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()){ if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} }
} }
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onPortalEvent(PlayerPortalEvent event) { public void onPortalEvent(PlayerPortalEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("hasWarped")){ if (player.hasMetadata("hasWarped")) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
Location loc = player.getLocation(); Location loc = player.getLocation();
Object[] portals = Portal.Portals; Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(player.getWorld().getName())){ 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 @EventHandler
public void onItemInteract(PlayerInteractEvent event) { public void onItemInteract(PlayerInteractEvent event) {
// will detect if the player is using an axe so the points of a portal can be set // 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 // also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){ if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled."); player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
event.setCancelled(true); event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin); player.removeMetadata("selectingPortal", plugin);
return; return;
} }
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(block.getWorld().getName())){ 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()){ 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.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 player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
event.setCancelled(true); event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin); player.removeMetadata("selectingPortal", plugin);
return; return;
} }
} }
} }
} }
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); 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); event.setCancelled(true);
return; 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, // 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 // 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. // as a weapon.
// Null pointer exeption detected here on some servers(try decompiling the jar file to double check) // Null pointer exeption detected here on some servers(try decompiling the jar file to double check)
/*try { /*try {
// Use this to surround the code if needed // Use this to surround the code if needed
} }
catch(NullPointerException e){ catch(NullPointerException e){
}*/ }*/
if(event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id 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")))) { && (!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. // 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) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation(); 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 // 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. // 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("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); 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()); 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 // Stops the event so the block is not damaged
event.setCancelled(true); 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)
} } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { Location blockloc = event.getClickedBlock().getLocation();
Location blockloc = event.getClickedBlock().getLocation(); player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ()));
player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName()));
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());
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 // Stops the event so the block is not interacted with
event.setCancelled(true); 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,14 +13,14 @@ import org.bukkit.event.block.BlockPhysicsEvent;
public class PortalPlacer implements Listener { public class PortalPlacer implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
private final double PortalProtectionRadius; private final double PortalProtectionRadius;
// The needed config values will be stored so they are easier to access later // 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... // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalPlace = true; private boolean PortalPlace = true;
public PortalPlacer(AdvancedPortalsPlugin plugin) { public PortalPlacer(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -30,23 +30,22 @@ public class PortalPlacer implements Listener {
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalPlace){ if (PortalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Material material = block.getType(); Material material = block.getType();
if (material == Material.PORTAL) if (material == Material.PORTAL) {
{ for (AdvancedPortal portal : Portal.Portals) {
for(AdvancedPortal portal : Portal.Portals){ if (portal.worldName.equals(block.getWorld().getName())) {
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); event.setCancelled(true);
break; break;
@ -56,10 +55,10 @@ public class PortalPlacer implements Listener {
} }
} }
//event.getChangedType(); //event.getChangedType();
//event.setCancelled(true); //event.setCancelled(true);
} }
} }
} }

View File

@ -16,14 +16,14 @@ import java.util.List;
public class PortalProtect implements Listener { public class PortalProtect implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later // 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... // 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 boolean PortalProtect = true;
private double PortalProtectionRadius = 5D; private double PortalProtectionRadius = 5D;
public PortalProtect(AdvancedPortalsPlugin plugin) { public PortalProtect(AdvancedPortalsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -33,94 +33,94 @@ public class PortalProtect implements Listener {
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalProtect){ if (PortalProtect) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event){ public void onBlockBreak(BlockBreakEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
if(!event.getPlayer().hasPermission("advancedportals.build")){ if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock(); Block block = event.getBlock();
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(block.getWorld().getName())){ 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); event.setCancelled(true);
break; break;
} }
} }
} }
} }
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event){ public void onBlockPlace(BlockPlaceEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
if(!event.getPlayer().hasPermission("advancedportals.build")){ if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock(); Block block = event.getBlock();
for(AdvancedPortal portal : Portal.Portals){ for (AdvancedPortal portal : Portal.Portals) {
if(portal.worldName.equals(block.getWorld().getName())){ 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); event.setCancelled(true);
break; break;
} }
} }
} }
} }
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onExplosion(EntityExplodeEvent event){ public void onExplosion(EntityExplodeEvent event) {
if(!Portal.portalsActive){ if (!Portal.portalsActive) {
return; return;
} }
List<Block> blockList = event.blockList(); List<Block> blockList = event.blockList();
for (int i = 0; i < blockList.size(); i++) { for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i); Block block = blockList.get(i);
Object[] portals = Portal.Portals; Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){ // change for format for(int i = 0; i < portals.length; i++){ 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.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()) {
blockList.remove(i); blockList.remove(i);
i--; i--;
} }
} }
} }
} }
} }
} }

View File

@ -132,6 +132,121 @@ public class Metrics {
debug = configuration.getBoolean("debug", false); debug = configuration.getBoolean("debug", false);
} }
/**
* GZip compress a string of bytes
*
* @param input
* @return
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzos != null) try {
gzos.close();
} catch (IOException ignore) {
}
}
return baos.toByteArray();
}
/**
* Appends a json encoded key/value pair to the given string builder.
*
* @param json
* @param key
* @param value
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false;
try {
if (value.equals("0") || !value.endsWith("0")) {
Double.parseDouble(value);
isValueNumeric = true;
}
} catch (NumberFormatException e) {
isValueNumeric = false;
}
if (json.charAt(json.length() - 1) != '{') {
json.append(',');
}
json.append(escapeJSON(key));
json.append(':');
if (isValueNumeric) {
json.append(value);
} else {
json.append(escapeJSON(value));
}
}
/**
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder();
builder.append('"');
for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index);
switch (chr) {
case '"':
case '\\':
builder.append('\\');
builder.append(chr);
break;
case '\b':
builder.append("\\b");
break;
case '\t':
builder.append("\\t");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
default:
if (chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
} else {
builder.append(chr);
}
break;
}
}
builder.append('"');
return builder.toString();
}
/**
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/** /**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned. * website. Plotters can be added to the graph object returned.
@ -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 * 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 * Represents a custom graph on the website
*/ */

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ public class PortalArg {
public final String value; public final String value;
//public final int type; //public final int type;
public PortalArg(String argName, String value/*, int type*/){ public PortalArg(String argName, String value/*, int type*/) {
this.argName = argName; this.argName = argName;
this.value = value; this.value = value;
// may be used if values need to be 100% not string // 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. * Created by on 29/03/2016.
* * <p>
* TODO add all the normal tags then add the extradata tags * TODO add all the normal tags then add the extradata tags
* *
* @author sekwah41 * @author sekwah41
@ -15,12 +15,12 @@ public class PortalTags {
// TODO create a list or hashmap of tags to check for. // 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 ArrayList<String> tags = new ArrayList<String>();
public void registerTag(String tagName){ public void registerTag(String tagName) {
this.registerTag(tagName, false); this.registerTag(tagName, false);
} }
@ -31,11 +31,11 @@ public class PortalTags {
* @param tagName * @param tagName
* @param description * @param description
*/ */
public void registerTag(String tagName, boolean multiWord, String description){ public void registerTag(String tagName, boolean multiWord, String description) {
this.registerTag(tagName, multiWord); this.registerTag(tagName, multiWord);
} }
public void registerTag(String tagName, boolean multiWord){ public void registerTag(String tagName, boolean multiWord) {
} }