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

View File

@ -38,9 +38,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
if(sender.hasPermission("advancedportals.portal")){
if(args.length > 0){
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
if (sender.hasPermission("advancedportals.portal")) {
if (args.length > 0) {
if (args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")) {
Player player = (Player) sender;
PlayerInventory inventory = player.getInventory();
@ -49,7 +49,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Material WandMaterial = Material.getMaterial(ItemID);
if(WandMaterial == null){
if (WandMaterial == null) {
WandMaterial = Material.IRON_AXE;
}
@ -62,9 +62,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
inventory.addItem(regionselector);
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!");
}
else if(args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")){
Player player = (Player)sender;
} else if (args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")) {
Player player = (Player) sender;
PlayerInventory inventory = player.getInventory();
ItemStack portalBlock = new ItemStack(Material.PORTAL, 1);
@ -72,12 +71,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
inventory.addItem(portalBlock);
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!");
}
else if(args[0].toLowerCase().equals("create")) {
Player player = (Player)sender;
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
if(args.length >= 2){ // may make this next piece of code more efficient, maybe check against a list of available variables or something
} else if (args[0].toLowerCase().equals("create")) {
Player player = (Player) sender;
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something
// TODO change system to use arrays and hashmaps
boolean hasName = false;
boolean hasTriggerBlock = false;
@ -94,49 +92,41 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ArrayList<PortalArg> extraData = new ArrayList<>();
for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
for (int i = 1; i < args.length; i++) {
if (args[i].toLowerCase().startsWith("name:") && args[i].length() > 5) {
hasName = true;
portalName = args[i].replaceFirst("name:", "");
}
else if(args[i].toLowerCase().startsWith("name:")) {
} else if (args[i].toLowerCase().startsWith("name:")) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that isnt nothing!");
return true;
}
else if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
} else if (args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12) {
hasDestination = true;
destination = args[i].toLowerCase().replaceFirst("destination:", "");
}
else if(args[i].toLowerCase().startsWith("desti:") && args[i].length() > 6){
} else if (args[i].toLowerCase().startsWith("desti:") && args[i].length() > 6) {
hasDestination = true;
destination = args[i].toLowerCase().replaceFirst("desti:", "");
}
else if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
} else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) {
hasTriggerBlock = true;
triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", "");
}
else if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
} else if (args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13) {
hasTriggerBlock = true;
triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", "");
}
else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){ // not completely implemented
} else if (args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7) { // not completely implemented
isBungeePortal = true;
serverName = args[i].toLowerCase().replaceFirst("bungee:", "");
//extraData.add(new PortalArgs("bungee", serverName));
}
else if(args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11){ // not completely implemented
} else if (args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11) { // not completely implemented
needsPermission = true;
permission = args[i].toLowerCase().replaceFirst("permission:", "");
extraData.add(new PortalArg("permission", permission));
}
else if(args[i].toLowerCase().startsWith("command:") && args[i].length() > 8){ // not completely implemented
} else if (args[i].toLowerCase().startsWith("command:") && args[i].length() > 8) { // not completely implemented
executesCommand = true;
portalCommand = parseArgVariable(args,i,"command:");
portalCommand = parseArgVariable(args, i, "command:");
i += this.portalArgsStringLength - 1;
extraData.add(new PortalArg("command.1", portalCommand));
}
}
if(!hasName){
if (!hasName) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!");
return true;
}
@ -148,46 +138,42 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml");
String destiPosX = desticonfig.getConfig().getString(destination + ".pos1.X");
if(!Portal.portalExists(portalName)){
if (!Portal.portalExists(portalName)) {
player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a]\u00A7e You have created a new portal with the following details:");
player.sendMessage("\u00A7aname: \u00A7e" + portalName);
if(hasDestination){
if (hasDestination) {
player.sendMessage("\u00A7adestination: \u00A7e" + destination);
}
else if(destiPosX == null){
} else if (destiPosX == null) {
player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)");
}
else{
} else {
player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not work)");
}
if(isBungeePortal){
if (isBungeePortal) {
player.sendMessage("\u00A7abungee: \u00A7e" + serverName);
}
if(needsPermission){
if (needsPermission) {
player.sendMessage("\u00A7apermission: \u00A7e" + permission);
}
else{
} else {
player.sendMessage("\u00A7apermission: \u00A7e(none needed)");
}
if(executesCommand){
if (executesCommand) {
player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand);
}
Material triggerBlockMat = Material.getMaterial(0);
if(hasTriggerBlock){
if (hasTriggerBlock) {
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
if(triggerBlockMat != null){
if (triggerBlockMat != null) {
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, portalArgs));
}
else{
} else {
hasTriggerBlock = false;
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
@ -197,69 +183,58 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs));
}
}
else{
} else {
ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml");
player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
PortalArg[] portalArgs = new PortalArg[extraData.size()];
portalArgs = extraData.toArray(portalArgs);
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs));
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A portal by that name already exists!");
}
// add code to save the portal to the portal config and reload the portals
player.sendMessage("");
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c"
+ " for a full list of currently available variables and an example command!");
}
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!");
}
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have two points selected to make a portal!");
}
}
else if(args[0].toLowerCase().equals("variables")) {
} else if (args[0].toLowerCase().equals("variables")) {
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination");
sender.sendMessage("");
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
}
else if(args[0].toLowerCase().equals("select")) {
} else if (args[0].toLowerCase().equals("select")) {
// TODO finish the select command and the hit block to replace!
Player player = (Player)sender;
if(!player.hasMetadata("selectingPortal")){
if(args.length > 1){
if(Portal.portalExists(args[1])){
Player player = (Player) sender;
if (!player.hasMetadata("selectingPortal")) {
if (args.length > 1) {
if (Portal.portalExists(args[1])) {
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!");
}
}
else{
} else {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Hit a block inside the portal region to select the portal!");
player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true));
}
}
else{
} else {
player.removeMetadata("selectingPortal", plugin);
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!");
}
}
else if(args[0].toLowerCase().equals("gui")){
Player player = (Player)sender;
if(args.length > 1){
if(args[1].toLowerCase().equals("remove") && args.length > 2){
} else if (args[0].toLowerCase().equals("gui")) {
Player player = (Player) sender;
if (args.length > 1) {
if (args[1].toLowerCase().equals("remove") && args.length > 2) {
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?");
sender.sendMessage("");
@ -268,199 +243,163 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage("");
}
}
}
else if(args[0].toLowerCase().equals("edit")) {
} else if (args[0].toLowerCase().equals("edit")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
if(args.length > 1){
if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
if (posX != null) {
portalEditMenu(sender, portalConfig, args[1]);
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists!");
}
}
else{
Player player = (Player)sender;
if(player.hasMetadata("selectedPortal")){
} else {
Player player = (Player) sender;
if (player.hasMetadata("selectedPortal")) {
String portalName = player.getMetadata("selectedPortal").get(0).asString();
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
if(posX != null){
if (posX != null) {
portalEditMenu(sender, portalConfig, portalName);
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin);
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!");
}
}
}
else if(args[0].toLowerCase().equals("rename")) {
} else if (args[0].toLowerCase().equals("rename")) {
// not finished yet /
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
if(args.length > 1){
Player player = (Player)sender;
if(player.hasMetadata("selectedPortal")){
if (args.length > 1) {
Player player = (Player) sender;
if (player.hasMetadata("selectedPortal")) {
String portalName = player.getMetadata("selectedPortal").get(0).asString();
if(portalName.toLowerCase() != args[1].toLowerCase()){
if (portalName.toLowerCase() != args[1].toLowerCase()) {
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null && newPortalPosX == null){
if (posX != null && newPortalPosX == null) {
Portal.rename(portalName, args[1]);
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a.");
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
}
else if(newPortalPosX != null){
} else if (newPortalPosX != null) {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!");
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin);
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you have selected is already called that!");
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!");
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!");
}
}
else if(args[0].toLowerCase().equals("command")) {
Player player = (Player)sender;
if(player.hasMetadata("selectedPortal")) {
} else if (args[0].toLowerCase().equals("command")) {
Player player = (Player) sender;
if (player.hasMetadata("selectedPortal")) {
String portalName = player.getMetadata("selectedPortal").get(0).asString();
if(args.length > 1){
if (args.length > 1) {
// TODO add the command autocompletes, add, remove and show
if(args[1].toLowerCase().equals("add")) {
if(args.length > 2){
if (args[1].toLowerCase().equals("add")) {
if (args.length > 2) {
String portalCommand = args[2];
for(int i = 3; i < args.length; i++){
for (int i = 3; i < args.length; i++) {
portalCommand += args[i];
}
if(Portal.addCommand(portalName, portalCommand)){
if (Portal.addCommand(portalName, portalCommand)) {
sender.sendMessage("\u00A77a[\u00A77eAdvancedPortals\u00A77a] Command added to portal!");
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Failed to add command to portal!");
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must actually specify a command to execute!");
}
}
else if(args[1].toLowerCase().equals("remove")) {
} else if (args[1].toLowerCase().equals("remove")) {
// Specify what line to remove
}
else if(args[1].toLowerCase().equals("show")) {
} else if (args[1].toLowerCase().equals("show")) {
// Show all the commands the portal executes
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!");
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!");
}
}
else{
} else {
}
}
else if(args[0].toLowerCase().equals("remove")) {
} else if (args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
if(args.length > 1){
if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
if (posX != null) {
Portal.remove(args[1]);
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A7e" + args[1] + "\u00A7c has been removed!");
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!");
}
}
else{
Player player = (Player)sender;
if(player.hasMetadata("selectedPortal")){
} else {
Player player = (Player) sender;
if (player.hasMetadata("selectedPortal")) {
String portalName = player.getMetadata("selectedPortal").get(0).asString();
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
if(posX != null){
if (posX != null) {
Portal.remove(portalName);
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A77" + portalName + "\u00A7c has been removed!");
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin);
}
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!");
}
}
}
else if(args[0].toLowerCase().equals("help")) {
} else if (args[0].toLowerCase().equals("help")) {
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Still designing in game help page :(");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] For now please use the wiki http://bit.ly/portals-help");
}
else if(args[0].toLowerCase().equals("bukkitpage")) {
} else if (args[0].toLowerCase().equals("bukkitpage")) {
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!");
}
else if(args[0].toLowerCase().equals("helppage")) {
} else if (args[0].toLowerCase().equals("helppage")) {
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: http://bit.ly/portals-help!");
}
else if(args[0].toLowerCase().equals("show")){
} else if (args[0].toLowerCase().equals("show")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml");
Player player = (Player) sender;
if(args.length > 1){
if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
if (posX != null) {
Selection.Show(player, this.plugin, args[1]);
}
else{
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!");
}
}
else{
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
} else {
if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) {
if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!");
Selection.Show(player, this.plugin);
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!");
}
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!");
}
}
}
else if(args[0].toLowerCase().equals("reload")) {
} else if (args[0].toLowerCase().equals("reload")) {
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!");
Listeners.reloadValues(plugin);
Portal.loadPortals();
}
else{
} else {
PluginMessages.UnknownCommand(sender, command);
}
}
else{
} else {
PluginMessages.UnknownCommand(sender, command);
}
}
else{
} else {
PluginMessages.NoPermission(sender, command);
}
@ -468,23 +407,22 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
private String parseArgVariable(String[] args, int currentArg, String argStarter) {
String variableString = args[currentArg].replaceFirst(argStarter,"");
String variableString = args[currentArg].replaceFirst(argStarter, "");
this.portalArgsStringLength = 1;
if(variableString.charAt(0) == '"'){
variableString = variableString.substring(1,variableString.length());
if(variableString.charAt(variableString.length()-1) != '"'){
if (variableString.charAt(0) == '"') {
variableString = variableString.substring(1, variableString.length());
if (variableString.charAt(variableString.length() - 1) != '"') {
currentArg++;
for( ; currentArg < args.length; currentArg++){
for (; currentArg < args.length; currentArg++) {
variableString += " " + args[currentArg];
this.portalArgsStringLength += 1;
if(variableString.charAt(variableString.length() - 1) == '"'){
variableString = variableString.substring(0,variableString.length() - 1);
if (variableString.charAt(variableString.length() - 1) == '"') {
variableString = variableString.substring(0, variableString.length() - 1);
break;
}
}
}
else{
variableString = variableString.substring(0,variableString.length() - 1);
} else {
variableString = variableString.substring(0, variableString.length() - 1);
}
}
@ -505,41 +443,37 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z"));
String destination = portalConfig.getConfig().getString(portalName + ".destination");
if(destination != null){
if (destination != null) {
sender.sendMessage(" \u00A7adestination\u00A7e: " + destination);
}
else{
} else {
sender.sendMessage(" \u00A7cdestination\u00A7e: null");
}
String trigger = portalConfig.getConfig().getString(portalName + ".triggerblock");
if(trigger != null){
if (trigger != null) {
sender.sendMessage(" \u00A7atriggerBlock\u00A7e: " + trigger);
}
else{
} else {
sender.sendMessage(" \u00A7ctriggerBlock\u00A7e: null");
}
if(portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null){
if (portalConfig.getConfig().getString(portalName + ".portalArgs.command.1") != null) {
int commands = 0;
String command = portalConfig.getConfig().getString(portalName + ".portalArgs.command.1");
// TODO possibly change code so it counds number of subvalues rather than a loop.
while(command != null){
while (command != null) {
command = portalConfig.getConfig().getString(portalName + ".portalArgs.command." + ++commands);
}
if(--commands > 1){
if (--commands > 1) {
sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " commands");
}
else{
} else {
sender.sendMessage(" \u00A7acommands\u00A7e: " + commands + " command");
}
}
else{
} else {
sender.sendMessage(" \u00A7ccommands\u00A7e: none");
}
sender.sendMessage("");
Player player = (Player)sender;
Player player = (Player) sender;
plugin.nmsAccess.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal show " + portalName + "\"}}"
@ -553,12 +487,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){
if (sender.hasPermission("AdvancedPortals.CreatePortal")) {
if (args.length == 1) {
autoComplete.addAll(Arrays.asList("create", "portal", "portalblock", "select", "selector"
, "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage"));
}
else if(args[0].toLowerCase().equals("create")){
} else if (args[0].toLowerCase().equals("create")) {
boolean hasName = false;
boolean hasTriggerBlock = false;
@ -570,10 +503,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
// TODO change auto complete when quotes are opened and closed. Such as autocomplete @Player and stuff when specifying commands
for(int i = 1; i < args.length; i++){
for (int i = 1; i < args.length; i++) {
String argTag = getTag(args[i].toLowerCase());
if(argTag.length() + 1 < args[i].length()){
switch(argTag){
if (argTag.length() + 1 < args[i].length()) {
switch (argTag) {
case "name":
hasName = true;
break;
@ -600,17 +533,30 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
}
if(!hasName){autoComplete.add("name:");}
if(!hasTriggerBlock){autoComplete.add("triggerblock:");}
if(!hasDestination){autoComplete.add("destination:");autoComplete.add("desti:");}
if(!isBungeePortal){autoComplete.add("bungee:");}
if(!needsPermission){autoComplete.add("permission:");}
if(!hasCommand){autoComplete.add("command:");}
if (!hasName) {
autoComplete.add("name:");
}
if (!hasTriggerBlock) {
autoComplete.add("triggerblock:");
}
if (!hasDestination) {
autoComplete.add("destination:");
autoComplete.add("desti:");
}
if (!isBungeePortal) {
autoComplete.add("bungee:");
}
if (!needsPermission) {
autoComplete.add("permission:");
}
if (!hasCommand) {
autoComplete.add("command:");
}
}
}
Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){
for (Object result : autoComplete.toArray()) {
if (!result.toString().startsWith(args[args.length - 1])) {
autoComplete.remove(result);
}
}
@ -619,8 +565,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
private String getTag(String arg) {
int indexOfSplitter = arg.indexOf(':');
if(indexOfSplitter > 0){
return arg.substring(0,indexOfSplitter);
if (indexOfSplitter > 0) {
return arg.substring(0, indexOfSplitter);
}
return "";
}

View File

@ -37,10 +37,9 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
try {
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();
}else
{
} else {
System.out.println("Something went wrong, please notify the author and tell them this version v:" + version);
this.setEnabled(false);
}
@ -59,7 +58,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix");
if(useCustomPrefix){
if (useCustomPrefix) {
this.customPrefix = config.getConfig().getString("CustomPrefix");
}

View File

@ -21,26 +21,27 @@ public class DataCollector {
*
*/
/**public static void playerWarped() {
try {
Metrics metrics = new Metrics(plugin);
Graph TotalWarps = metrics.createGraph("Total Warps");
TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") {
@Override
public int getValue() {
return 1; // number of warps
}
});
metrics.start();
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
}
}*/
/**
* public static void playerWarped() {
* try {
* Metrics metrics = new Metrics(plugin);
* <p>
* Graph TotalWarps = metrics.createGraph("Total Warps");
* <p>
* TotalWarps.addPlotter(new Metrics.Plotter("Internal Warps") {
*
* @Override public int getValue() {
* return 1; // number of warps
* }
* <p>
* });
* <p>
* metrics.start();
* } catch (IOException e) {
* plugin.getLogger().log(Level.SEVERE, "Could not submit data", e);
* }
* }
*/
public static void setupMetrics() {
@ -55,8 +56,7 @@ public class DataCollector {
/**TotalWarps.addPlotter(new Metrics.Plotter(triggerName) {
@Override
public int getValue() {
@Override public int getValue() {
return 1; // number of portals created
}

View File

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

View File

@ -18,16 +18,13 @@ public class Selection {
timeout = config.getConfig().getInt("ShowSelectionShowDuration");
String BlockID = config.getConfig().getString("ShowSelectionBlockID");
try
{
try {
blockType = Material.getMaterial(Integer.parseInt(BlockID));
}
catch(Exception e)
{
} catch (Exception e) {
blockType = Material.getMaterial(BlockID);
}
if(blockType == null){
if (blockType == null) {
blockType = Material.STAINED_GLASS;
}
@ -55,58 +52,58 @@ public class Selection {
* 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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
player.sendBlockChange(loc, blockType, metadata);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
@ -124,27 +121,24 @@ public class Selection {
int HighY = 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();
HighX = player.getMetadata("Pos1X").get(0).asInt();
}
else{
} else {
LowX = player.getMetadata("Pos1X").get(0).asInt();
HighX = player.getMetadata("Pos2X").get(0).asInt();
}
if(player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()){
if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) {
LowY = player.getMetadata("Pos2Y").get(0).asInt();
HighY = player.getMetadata("Pos1Y").get(0).asInt();
}
else{
} else {
LowY = player.getMetadata("Pos1Y").get(0).asInt();
HighY = player.getMetadata("Pos2Y").get(0).asInt();
}
if(player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()){
if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) {
LowZ = player.getMetadata("Pos2Z").get(0).asInt();
HighZ = player.getMetadata("Pos1Z").get(0).asInt();
}
else{
} else {
LowZ = player.getMetadata("Pos1Z").get(0).asInt();
HighZ = player.getMetadata("Pos2Z").get(0).asInt();
}
@ -157,58 +151,58 @@ public class Selection {
* 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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
player.sendBlockChange(loc, blockType, metadata);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Selection.Hide(player, plugin, pos1, pos2);
}
}, timeout * 20);
@ -226,51 +220,51 @@ public class Selection {
int HighY = pos2.getBlockY();
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
player.sendBlockChange(loc, loc.getBlock().getType(), loc.getBlock().getData());
}

View File

@ -28,27 +28,24 @@ public class WarpCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){
if(Destination.warp(sender, args[0], false)){
if(DestinationCommand.PortalMessagesDisplay == 1){
if (args.length > 0) {
if (Destination.warp(sender, args[0], false)) {
if (DestinationCommand.PortalMessagesDisplay == 1) {
sender.sendMessage("");
sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
}
else if(DestinationCommand.PortalMessagesDisplay == 2){
} else if (DestinationCommand.PortalMessagesDisplay == 2) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
}
else{
} else {
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you tried to warp to does not exist!");
sender.sendMessage("");
}
}
else{
} else {
sender.sendMessage("");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type a destination after /" + command + "!");
sender.sendMessage("");

View File

@ -27,7 +27,7 @@ public class Destination {
// 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");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
@ -42,7 +42,7 @@ public class Destination {
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");
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
@ -57,7 +57,7 @@ public class Destination {
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");
config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world"));
@ -74,7 +74,7 @@ public class Destination {
config.saveConfig();
}
public static void remove(String name){
public static void remove(String name) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
config.getConfig().set(name.toLowerCase() + ".world", null);
@ -93,11 +93,11 @@ public class Destination {
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");
if(config.getConfig().getString(name + ".world") != null){
if (config.getConfig().getString(name + ".world") != null) {
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.setX(config.getConfig().getDouble(name + ".pos.X"));
@ -112,13 +112,12 @@ public class Destination {
Chunk c = loc.getChunk();
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
if(player.getVehicle() != null){
if (player.getVehicle() != null) {
riding.eject();
riding.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
riding.setPassenger(player);
}
else{
} else {
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
WarpEffects.activateParticles(player);
@ -126,18 +125,16 @@ public class Destination {
return true;
}
else{
if(senderror){
} else {
if (senderror) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
}
return false;
}
}
else{
if(senderror){
} else {
if (senderror) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
@ -167,7 +164,7 @@ public class Destination {
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name, boolean senderror) {
Player player = (Player)sender;
Player player = (Player) sender;
return warp(player, name, senderror);
}
@ -180,20 +177,20 @@ public class Destination {
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name) {
Player player = (Player)sender;
Player player = (Player) sender;
return warp(player, name, true);
}
public static List<String> destiList(){
public static List<String> destiList() {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
LinkedList<String> destiList = new LinkedList<>();
Set<String> destiSet = config.getConfig().getKeys(false);
if(destiSet.size() > 0){
for(Object desti: destiSet.toArray()){
if (destiSet.size() > 0) {
for (Object desti : destiSet.toArray()) {
destiSet.add(desti.toString());
}
}

View File

@ -10,11 +10,9 @@ import org.bukkit.entity.Player;
public class WarpEffects {
public boolean oldSoundLoc = true;
public static Sound[] sounds = new Sound[1];
public static boolean soundError = false;
public boolean oldSoundLoc = true;
public WarpEffects(AdvancedPortalsPlugin plugin) {
try {
@ -34,28 +32,30 @@ public class WarpEffects {
public static void activateParticles(Player player) {
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles){
switch (Assets.currentWarpParticles) {
case 1:
for(int i = 0; i < 10; i++){
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++){
for (int i = 0; i < 10; i++) {
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
}
default: break;
default:
break;
}
}
public static void activateSound(Player player) {
if(!soundError){
if (!soundError) {
Location loc = player.getLocation();
World world = player.getWorld();
switch (Assets.currentWarpParticles){
switch (Assets.currentWarpParticles) {
case 1:
world.playSound(loc, sounds[0], 1F, 1F);
default: break;
default:
break;
}
}
}

View File

@ -30,6 +30,9 @@ public final class WarpEvent extends Event implements Cancellable {
this.portalData = portalData;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Returns if the event has been cancelled
@ -44,16 +47,8 @@ public final class WarpEvent extends Event implements Cancellable {
cancelled = cancel;
}
public AdvancedPortal getPortalData(){return portalData;}
/**
* If the
*
* @param warped
*/
@SuppressWarnings("unused")
public void setHasWarped(boolean warped){
this.hasWarped = warped;
public AdvancedPortal getPortalData() {
return portalData;
}
/**
@ -61,20 +56,25 @@ public final class WarpEvent extends Event implements Cancellable {
*
* @return hasWarped
*/
public boolean getHasWarped(){
public boolean getHasWarped() {
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() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -25,7 +25,7 @@ public class FlowStopper implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
if(WaterFlow){
if (WaterFlow) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@ -36,16 +36,16 @@ public class FlowStopper implements Listener {
Block blockTo = event.getToBlock();
Block block = event.getBlock();
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){
if ((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()) {
if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){
if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) {
event.setCancelled(true);
@ -54,11 +54,11 @@ public class FlowStopper implements Listener {
}
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);

View File

@ -25,17 +25,13 @@ import org.bukkit.metadata.FixedMetadataValue;
public class Listeners implements Listener {
private final AdvancedPortalsPlugin plugin;
private int PortalMessagesDisplay = 2;
// 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;
@SuppressWarnings("deprecation")
public Listeners(AdvancedPortalsPlugin plugin) {
@ -48,12 +44,9 @@ public class Listeners implements Listener {
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
try
{
try {
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
}
catch(Exception e)
{
} catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
@ -70,12 +63,9 @@ public class Listeners implements Listener {
String ItemID = config.getConfig().getString("AxeItemId");
try
{
try {
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
}
catch(Exception e)
{
} catch (Exception e) {
WandMaterial = Material.getMaterial(ItemID);
}
}
@ -83,7 +73,7 @@ public class Listeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onMoveEvent(PlayerMoveEvent event) {
// will check if the player is in the portal or not.
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
@ -98,12 +88,12 @@ public class Listeners implements Listener {
// 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()){
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);
@ -111,46 +101,43 @@ public class Listeners implements Listener {
if (!event.isCancelled()) {
boolean warped = Portal.activate(player, portal);
if(PortalMessagesDisplay == 1 && warped){
if (PortalMessagesDisplay == 1 && warped) {
player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
player.sendMessage("");
}
else if(PortalMessagesDisplay == 2 && warped){
} else if (PortalMessagesDisplay == 2 && warped) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
if(warped){
if (warped) {
//event.setFrom(player.getLocation());
//event.setTo(player.getLocation());
//event.setCancelled(true);
}
else{
} else {
player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN);
event.setCancelled(true);
}
}
if(portal.trigger.equals(Material.PORTAL)){
if(player.getGameMode().equals(GameMode.CREATIVE)){
if (portal.trigger.equals(Material.PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
if(player != null && player.isOnline()){
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
if (player != null && player.isOnline()) {
player.removeMetadata("hasWarped", plugin);
}
}
}, 10);
}
}
else if(portal.trigger.equals(Material.LAVA)){
} else if (portal.trigger.equals(Material.LAVA)) {
player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
player.removeMetadata("lavaWarped", plugin);
player.setFireTicks(0);
}
@ -168,16 +155,16 @@ public class Listeners implements Listener {
@EventHandler
public void onCombustEntityEvent(EntityCombustEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
Location loc = event.getEntity().getLocation();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(loc.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(loc.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true);
return;
}
@ -189,22 +176,22 @@ public class Listeners implements Listener {
@EventHandler
public void onDamEvent(EntityDamageEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
//System.out.println(event.getCause());
if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){
if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) {
Location loc = event.getEntity().getLocation();
if(event.getEntity().hasMetadata("lavaWarped")){
if (event.getEntity().hasMetadata("lavaWarped")) {
event.setCancelled(true);
return;
}
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(loc.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(loc.getWorld().getName())) {
if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){
if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) {
if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){
if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) {
event.setCancelled(true);
return;
@ -221,24 +208,24 @@ public class Listeners implements Listener {
@SuppressWarnings("deprecation")
@EventHandler
public void onPortalEvent(PlayerPortalEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
Player player = event.getPlayer();
if(player.hasMetadata("hasWarped")){
if (player.hasMetadata("hasWarped")) {
event.setCancelled(true);
return;
}
Location loc = player.getLocation();
Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(player.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(player.getWorld().getName())) {
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) {
event.setCancelled(true);
@ -258,20 +245,20 @@ public class Listeners implements Listener {
// also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer();
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
if(!Portal.portalsActive){
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
if (!Portal.portalsActive) {
player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled.");
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
}
Block block = event.getClickedBlock();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){
if ((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()) {
if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){
if ((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()) {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
event.setCancelled(true);
@ -288,7 +275,7 @@ public class Listeners implements Listener {
return;
}
if(player.hasPermission("AdvancedPortals.CreatePortal")){
if (player.hasPermission("AdvancedPortals.CreatePortal")) {
// UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally,
// by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used
@ -300,11 +287,11 @@ public class Listeners implements Listener {
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")))) {
// 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();
// 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.
@ -318,8 +305,7 @@ public class Listeners implements Listener {
event.setCancelled(true);
// Returns the event so no more code is executed(stops unnecessary code being executed)
}
else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location blockloc = event.getClickedBlock().getLocation();
player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX()));
player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY()));
@ -340,5 +326,4 @@ public class Listeners implements Listener {
}
}

View File

@ -30,7 +30,7 @@ public class PortalPlacer implements Listener {
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalPlace){
if (PortalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@ -39,14 +39,13 @@ public class PortalPlacer implements Listener {
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
Material material = block.getType();
if (material == Material.PORTAL)
{
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if (material == Material.PORTAL) {
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;

View File

@ -33,28 +33,28 @@ public class PortalProtect implements Listener {
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalProtect){
if (PortalProtect) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event){
public void onBlockBreak(BlockBreakEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
if(!event.getPlayer().hasPermission("advancedportals.build")){
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
@ -68,21 +68,21 @@ public class PortalProtect implements Listener {
@SuppressWarnings("unused")
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event){
public void onBlockPlace(BlockPlaceEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
if(!event.getPlayer().hasPermission("advancedportals.build")){
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()){
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
@ -95,9 +95,9 @@ public class PortalProtect implements Listener {
}
@EventHandler(priority = EventPriority.HIGH)
public void onExplosion(EntityExplodeEvent event){
public void onExplosion(EntityExplodeEvent event) {
if(!Portal.portalsActive){
if (!Portal.portalsActive) {
return;
}
@ -105,12 +105,12 @@ public class PortalProtect implements Listener {
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
Object[] portals = Portal.Portals;
for(AdvancedPortal portal : Portal.Portals){ // change for format for(int i = 0; i < portals.length; i++){
if(portal.worldName.equals(block.getWorld().getName())){
for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){
if (portal.worldName.equals(block.getWorld().getName())) {
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if ((portal.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);
i--;

View File

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

View File

@ -25,21 +25,21 @@ public class AdvancedPortal {
public PortalArg[] portalArgs = null;
// TODO think of relaying out the data input to a more logical format.
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs){
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs){
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
}
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this(portalName, trigger, pos1, pos2, worldName, portalArgs);
this.destiation = destination;
}
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) {
this.portalName = portalName;
this.trigger = trigger;
this.pos1 = pos1;
@ -48,9 +48,9 @@ public class AdvancedPortal {
this.portalArgs = portalArgs;
}
public String getArg(String arg){
for(PortalArg portalArg : portalArgs){
if(arg.equals(portalArg.argName)){
public String getArg(String arg) {
for (PortalArg portalArg : portalArgs) {
if (arg.equals(portalArg.argName)) {
return portalArg.value;
}
}

View File

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

View File

@ -19,15 +19,11 @@ import java.util.logging.Level;
public class Portal {
private static AdvancedPortalsPlugin plugin;
public static boolean portalsActive = false;
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
private static boolean ShowBungeeMessage;
private static AdvancedPortalsPlugin plugin;
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
private static boolean ShowBungeeMessage;
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
@ -39,17 +35,16 @@ public class Portal {
/**
* This can be used to move the get keys to different sections
*
* <p>
* ConfigurationSection section = portalData.getSection("sectionname");
*
* <p>
* section.getKeys(false);
*
*/
public static void loadPortals(){
public static void loadPortals() {
portalData = new ConfigAccessor(plugin, "portals.yml");
Set<String> PortalSet = portalData.getConfig().getKeys(false);
if(PortalSet.size() > 0){
if (PortalSet.size() > 0) {
Portals = new AdvancedPortal[PortalSet.toArray().length];
/*for(int i = 0; i <= PortalSet.toArray().length - 1; i++){
@ -57,24 +52,21 @@ public class Portal {
}*/
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
{
try {
Integer.parseInt(BlockID);
System.out.println("Block names must be given not IDs");
}
catch(NumberFormatException e)
{
} catch (NumberFormatException e) {
blockType = Material.getMaterial(BlockID);
}
if(blockType == null){
if (blockType == null) {
blockType = Material.PORTAL;
}
@ -85,15 +77,14 @@ public class Portal {
if (portalArgsConf != null) {
Set<String> argsSet = portalArgsConf.getKeys(true);
for(Object argName : argsSet.toArray()){
if(portalArgsConf.isString(argName.toString())){
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);
@ -112,20 +103,19 @@ public class Portal {
portalId++;
}
portalsActive = true;
}
else{
} else {
portalsActive = false;
}
}
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArg... extraData) {
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, PortalArg... extraData) {
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) {
if(!pos1.getWorld().equals(pos2.getWorld())){
if (!pos1.getWorld().equals(pos2.getWorld())) {
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
return "\u00A7cPortal creation error, pos1 and pos2 must be in the same world!";
}
@ -138,27 +128,24 @@ public class Portal {
int HighY = 0;
int HighZ = 0;
if(pos1.getX() > pos2.getX()){
if (pos1.getX() > pos2.getX()) {
LowX = (int) pos2.getX();
HighX = (int) pos1.getX();
}
else{
} else {
LowX = (int) pos1.getX();
HighX = (int) pos2.getX();
}
if(pos1.getY() > pos2.getY()){
if (pos1.getY() > pos2.getY()) {
LowY = (int) pos2.getY();
HighY = (int) pos1.getY();
}
else{
} else {
LowY = (int) pos1.getY();
HighY = (int) pos2.getY();
}
if(pos1.getZ() > pos2.getZ()){
if (pos1.getZ() > pos2.getZ()) {
LowZ = (int) pos2.getZ();
HighZ = (int) pos1.getZ();
}
else{
} else {
LowZ = (int) pos1.getZ();
HighZ = (int) pos2.getZ();
}
@ -166,7 +153,7 @@ public class Portal {
Location checkpos1 = new Location(pos1.getWorld(), HighX, HighY, HighZ);
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
if(checkPortalOverlap(checkpos1, checkpos2)){
if (checkPortalOverlap(checkpos1, checkpos2)) {
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
return "\u00A7cPortal creation error, portals must not overlap!";
}
@ -187,7 +174,7 @@ public class Portal {
portalData.getConfig().set(name + ".pos2.Y", LowY);
portalData.getConfig().set(name + ".pos2.Z", LowZ);
for(PortalArg arg: portalArgs){
for (PortalArg arg : portalArgs) {
portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
}
@ -201,25 +188,41 @@ public class Portal {
// make this actually work!
private static boolean checkPortalOverlap(Location pos1, Location pos2) {
if(portalsActive){
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;}
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].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].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].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].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].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].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;}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
return true;
}
}
portalId++;
}
@ -228,8 +231,8 @@ public class Portal {
}
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){
if (pos1.getX() >= posX && pos1.getY() >= posX && pos1.getZ() >= posZ) {
if ((pos2.getX()) <= posX && pos2.getY() <= posY && pos2.getZ() <= posZ) {
return true;
}
@ -238,10 +241,9 @@ public class Portal {
}
private static String checkMaterial(Material triggerBlock) {
if(triggerBlock.equals(Material.WATER)){
if (triggerBlock.equals(Material.WATER)) {
return "STATIONARY_WATER";
}
else if(triggerBlock.equals(Material.LAVA)){
} else if (triggerBlock.equals(Material.LAVA)) {
return "STATIONARY_LAVA";
}
return triggerBlock.toString();
@ -253,16 +255,13 @@ public class Portal {
Material triggerBlockType;
String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock");
try
{
try {
triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID));
}
catch(Exception e)
{
} catch (Exception e) {
triggerBlockType = Material.getMaterial(BlockID);
}
if(triggerBlockType == null){
if (triggerBlockType == null) {
triggerBlockType = Material.PORTAL;
}
@ -273,7 +272,7 @@ public class Portal {
return result;
}
public static void redefine(Location pos1, Location pos2, String name){
public static void redefine(Location pos1, Location pos2, String name) {
portalData.getConfig().set(name + ".pos1.X", pos1.getX());
portalData.getConfig().set(name + ".pos1.Y", pos1.getY());
@ -289,16 +288,16 @@ public class Portal {
}
public static String getDestination(String portalName){
public static String getDestination(String portalName) {
return portalData.getConfig().getString(portalName + ".destination");
}
public static void remove(String name){
public static void remove(String name) {
Object[] keys = portalData.getConfig().getKeys(true).toArray();
for(int i = keys.length - 1; i >= 0; i--){
for (int i = keys.length - 1; i >= 0; i--) {
String key = keys[i].toString();
if(key.startsWith(name + ".")){
if (key.startsWith(name + ".")) {
portalData.getConfig().set(key, null);
}
}
@ -335,21 +334,16 @@ public class Portal {
loadPortals();
}
public static boolean portalExists(String portalName){
public static boolean portalExists(String portalName) {
String posX = portalData.getConfig().getString(portalName + ".pos1.X");
if(posX == null){
return false;
}
else{
return true;
}
return posX != null;
}
public static boolean activate(Player player, String portalName) {
for(AdvancedPortal portal : Portal.Portals){
if(portal.portalName.equals(portalName)) return activate(player, portal);
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;
@ -361,13 +355,13 @@ public class Portal {
String permission = portal.getArg("permission");
/*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!");
return false;
}
if(portal.bungee != null){
if(ShowBungeeMessage){
if (portal.bungee != null) {
if (ShowBungeeMessage) {
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
@ -376,67 +370,59 @@ public class Portal {
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return false;
}
else{
} else {
boolean showFailMessage = true;
if(portal.getArg("command.1") != null){
if (portal.getArg("command.1") != null) {
showFailMessage = false;
int commandLine = 1;
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do{
do {
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
if(command.startsWith("#")){
if (command.startsWith("#")) {
command = command.substring(1);
plugin.getLogger().log(Level.SEVERE, "Portal command: " + command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
else if(command.startsWith("!")){
} else if (command.startsWith("!")) {
command = command.substring(1);
boolean wasOp = player.isOp();
try{
try {
player.setOp(true);
player.performCommand(command);
}
finally {
} finally {
player.setOp(wasOp);
}
}
else if(command.startsWith("^")){
} else if (command.startsWith("^")) {
command = command.substring(1);
PermissionAttachment permissionAttachment = null;
try{
try {
permissionAttachment = player.addAttachment(plugin, "*", true);
player.performCommand(command);
}
finally {
} finally {
player.removeAttachment(permissionAttachment);
}
}
else{
} else {
player.performCommand(command);
}
command = portal.getArg("command." + ++commandLine);
}while(command != null);
} while (command != null);
}
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if(portal.destiation != null){
if (portal.destiation != null) {
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if(configDesti.getConfig().getString(portal.destiation + ".world") != null){
if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
boolean warped = Destination.warp(player, portal.destiation);
return warped;
}
else{
} else {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
}
else{
if(showFailMessage) {
} 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!");
@ -465,23 +451,20 @@ public class Portal {
}
}
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
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
Set<String> keys = config.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(oldName + ".")){
if(config.getConfig().getString(key) != null){
try
{
for (String key : keys) {
if (key.startsWith(oldName + ".")) {
if (config.getConfig().getString(key) != null) {
try {
int intData = Integer.parseInt(config.getConfig().getString(key));
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
}
catch(Exception e)
{
} catch (Exception e) {
config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key));
}
@ -498,15 +481,15 @@ public class Portal {
public static boolean addCommand(String portalName, String portalCommand) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
if(portalExists(portalName)){
if (portalExists(portalName)) {
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)
; //Loops increasing commandLine till 1 is null
config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand);
config.saveConfig();
loadPortals();
return true;
}
else{
} else {
return false;
}
}

View File

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

View File

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