Refactor Destinations

This commit is contained in:
Max Qian 2016-08-01 18:53:56 -07:00
parent 920e3952d7
commit db76bc6ef2
6 changed files with 45 additions and 126 deletions

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals;
import com.sekwah.advancedportals.DataCollector.DataCollector;
import com.sekwah.advancedportals.compat.bukkit.NMS;
import com.sekwah.advancedportals.destinations.Destination;
import com.sekwah.advancedportals.destinations.*;
import com.sekwah.advancedportals.effects.WarpEffects;
import com.sekwah.advancedportals.listeners.*;
import com.sekwah.advancedportals.metrics.Metrics;

View File

@ -24,12 +24,14 @@ public class Destination {
private static AdvancedPortalsPlugin plugin;
private static boolean TeleportRiding = false;
public static int PortalMessagesDisplay = 0;
public Destination(AdvancedPortalsPlugin plugin) {
Destination.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
TeleportRiding = config.getConfig().getBoolean("WarpRiddenEntity");
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
}
// TODO add permissions for destinations.
@ -104,7 +106,7 @@ public class Destination {
config.saveConfig();
}
public static boolean warp(Player player, String name, boolean senderror) {
public static boolean warp(Player player, String name) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
if (config.getConfig().getString(name + ".world") != null) {
Location loc = player.getLocation();
@ -137,65 +139,30 @@ public class Destination {
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
if (PortalMessagesDisplay == 1) {
player.sendMessage("");
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.");
player.sendMessage("");
} else if (PortalMessagesDisplay == 2) {
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**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);*/
}
return true;
} else {
if (senderror) {
player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
}
return false;
}
} else {
if (senderror) {
player.sendMessage(plugin.customPrefixFail + "\u00A7c There has been a problem warping you to the selected destination!");
player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
}
return false;
}
}
/**
* Same as other warp but changes sender to player for you.
*
* @param player the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(Player player, String name) {
return warp(player, name, true);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name, boolean senderror) {
Player player = (Player) sender;
return warp(player, name, senderror);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender the player being warped
* @param name name of the warp
* @return returns if the player has warped
*/
public static boolean warp(CommandSender sender, String name) {
Player player = (Player) sender;
return warp(player, name, true);
}
public static List<String> destiList() {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");

View File

@ -1,6 +1,8 @@
package com.sekwah.advancedportals;
package com.sekwah.advancedportals.destinations;
import com.sekwah.advancedportals.destinations.Destination;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.PluginMessages;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -14,30 +16,22 @@ import java.util.List;
public class DestinationCommand implements CommandExecutor, TabCompleter {
public static int PortalMessagesDisplay = 0;
private AdvancedPortalsPlugin plugin;
public DestinationCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
plugin.getCommand("destination").setExecutor(this);
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay");
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if (args.length > 0) {
if (args[0].toLowerCase().equals("create")) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
if (args.length > 0) { switch (args[0].toLowerCase()) {
case "create":
if (sender.hasPermission("advancedportals.desti.create")) {
if (args.length > 1) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X");
if (posX == null) {
sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!");
@ -52,7 +46,8 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
} 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")) {
break;
case "remove":
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml");
if (args.length > 1) {
String posX = portalConfig.getConfig().getString(args[1] + ".pos.X");
@ -65,29 +60,16 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
} 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")) {
break;
case "goto":
case "warp":
if (args.length > 1) {
//System.out.println(args[1]);
ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml");
if (configDesti.getConfig().getString(args[1] + ".world") != null) {
Destination.warp(sender, args[1]);
if (PortalMessagesDisplay == 1) {
sender.sendMessage("");
sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
} else if (PortalMessagesDisplay == 2) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
Destination.warp((Player) sender, args[1]);
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to warp to.");
}
} 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")) {
break;
case "list":
List<String> destiList = Destination.destiList();
if (destiList.size() >= 1) {
if (args.length > 1) {
@ -128,9 +110,10 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
} else {
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations.");
}
break;
}
} 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");
PluginMessages.UnknownCommand(sender, command);
}
return true;
}

View File

@ -1,6 +1,8 @@
package com.sekwah.advancedportals;
package com.sekwah.advancedportals.destinations;
import com.sekwah.advancedportals.destinations.Destination;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.PluginMessages;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -29,26 +31,9 @@ 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) {
sender.sendMessage("");
sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.");
sender.sendMessage("");
} else if (DestinationCommand.PortalMessagesDisplay == 2) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
Destination.warp((Player) sender, args[0]);
} else {
sender.sendMessage("");
sender.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you tried to warp to does not exist!");
sender.sendMessage("");
}
} else {
sender.sendMessage("");
sender.sendMessage(plugin.customPrefixFail + "\u00A7c You need to type a destination after /" + command + "!");
sender.sendMessage("");
PluginMessages.UnknownCommand(sender, command);
}
return true;
}

View File

@ -86,19 +86,7 @@ public class Listeners implements Listener {
WarpEvent warpEvent = new WarpEvent(player, portal);
plugin.getServer().getPluginManager().callEvent(warpEvent);
if (portal.inPortal.contains(player)) return;
if (!event.isCancelled()) {
boolean warped = Portal.activate(player, portal);
if (PortalMessagesDisplay == 1 && warped) {
player.sendMessage("");
player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7.");
player.sendMessage("");
} else if (PortalMessagesDisplay == 2 && warped) {
ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml");
plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
}
if (!event.isCancelled()) Portal.activate(player, portal);
if (portal.trigger.equals(Material.PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true));

View File

@ -439,10 +439,6 @@ public class Portal {
if (configDesti.getConfig().getString(portal.destiation + ".world") != null) {
boolean warped = Destination.warp(player, portal.destiation);
return warped;
} else {
player.sendMessage(plugin.customPrefix + "\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!");
}
} else {
if (showFailMessage) {