Done major work on create command and remove command

This commit is contained in:
sekwah41 2018-01-31 18:06:02 +00:00 committed by Sekwah
parent 4c1dae79e3
commit 64b2d88658
13 changed files with 329 additions and 37 deletions

View File

@ -36,9 +36,18 @@ command.reload.reloaded= All Advanced Portals data reloaded
command.create.help=Creates portals
command.create.noargs= You need to actually list args for portal creation.
command.create.noname= You need to at least give a name to the portal no matter how many other tags you give it.
command.create.error= There was an error making the portal:
command.create.console= You cannot create a portal using the console.
command.create.detailedhelp=List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces"
command.remove.noname= You need to give the name of the portal you want to remove.
command.remove.error= Removing the portal was blocked:
portal.invalidselection=You must have both pos1 and pos2 selected to create a portal.
portal.noname=No name for the portal has been given.
portal.takenname=The name given for the portal is already taken.
command.trans.help=Copy translation new default translation file
command.version.help=Returns the current version of the plugin

View File

@ -121,7 +121,7 @@ public class AdvancedPortalsCore {
this.portalCommand = new CommandWithSubCommands();
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand());
this.portalCommand.registerSubCommand("transupdate", new TransUpdateSubCommand(this));
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand(this));
this.commandRegister.registerCommand("portal", this.portalCommand);
@ -156,9 +156,9 @@ public class AdvancedPortalsCore {
this.infoLogger.log(Lang.translate("logger.plugindisable"));
}
/*public static AdvancedPortalsCore getInstance() {
public static AdvancedPortalsCore getInstance() {
return instance;
}*/
}
public Config getConfig() {
return this.config;

View File

@ -34,6 +34,36 @@ public class CoreListeners {
return AdvancedPortalsCore.getPortalManager().playerMove(player, fromLoc, toLoc);
}
/**
*
* @param fromPos
* @param toPos
* @return if movement is allowed
*/
public boolean liquidFlow(PortalLocation fromPos, PortalLocation toPos) {
return true;
}
/**
* @player player causing the event (or null if not a player)
* @param blockPos
* @param blockMaterial
* @return if the block is allowed to break
*/
public boolean blockBreak(PlayerContainer player, PortalLocation blockPos, String blockMaterial) {
return true;
}
/**
* If the block is allowed to be interacted with e.g. a lever
* @player player causing the event (or null if not a player)
* @param blockPos
* @return
*/
public boolean blockInteract(PlayerContainer player, PortalLocation blockPos) {
return true;
}
/**
*
* @param player

View File

@ -3,13 +3,16 @@ package com.sekwah.advancedportals.core.api.managers;
import com.google.gson.reflect.TypeToken;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.api.portal.PortalTag;
import com.sekwah.advancedportals.core.api.portal.PortalTagExeption;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* When a player leaves the server any data stored on them is removed to free memory.
@ -56,17 +59,28 @@ public class PortalManager {
}
/**
* Load the default data into the portals.
*/
public void loadPortals() {
Type type = new TypeToken<Map<String, AdvancedPortal>>(){}.getType();
this.portalHashMap = this.portalsCore.getDataStorage().loadJson(type ,"portals.json");
if(this.portalHashMap == null) {
Type type = new TypeToken<Map<String, AdvancedPortal>>() {
}.getType();
this.portalHashMap = this.portalsCore.getDataStorage().loadJson(type, "portals.json");
if (this.portalHashMap == null) {
this.portalHashMap = new HashMap<>();
}
this.portalsCore.getDataStorage().storeJson(this.portalHashMap, "config.json");
this.updatePortalArray();
}
public boolean removePortal(String portalName) {
if (this.portalHashMap.containsKey(portalName)) {
this.portalHashMap.remove(portalName);
this.updatePortalArray();
return true;
} else {
return false;
}
}
public void playerJoin(PlayerContainer player) {
@ -80,4 +94,91 @@ public class PortalManager {
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
return false;
}
public void createPortal(PlayerContainer player, ArrayList<PortalTag> tags) throws PortalTagExeption {
if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString())
&& this.portalSelectorRightClick.containsKey(player.getUUID().toString())) {
this.createPortal(player, this.portalSelectorLeftClick.get(player.getUUID().toString()),
this.portalSelectorRightClick.get(player.getUUID().toString()), tags);
} else {
throw new PortalTagExeption(Lang.translate("portal.invalidselection"));
}
}
/**
*
* @param loc1
* @param loc2
* @param tags
* @return
* @throws PortalTagExeption
*/
public boolean createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalTagExeption {
return createPortal(null, loc1, loc2, tags);
}
/**
* Maybe add detection for overlapping however thats not a major issue for now and portals may overlap inside
* solid blocks
*
* @param player null if no player
* @param loc1
* @param loc2
* @param tags
* @return
* @throws PortalTagExeption
*/
public boolean createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalTagExeption {
int maxX = Math.max(loc1.posX, loc2.posX);
int maxY = Math.max(loc1.posY, loc2.posY);
int maxZ = Math.max(loc1.posZ, loc2.posZ);
int minX = Math.min(loc1.posX, loc2.posX);
int minY = Math.min(loc1.posY, loc2.posY);
int minZ = Math.min(loc1.posZ, loc2.posZ);
PortalLocation maxLoc = new PortalLocation(maxX, maxY, maxZ);
PortalLocation minLoc = new PortalLocation(minX, minY, minZ);
AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc);
for(PortalTag portalTag : tags) {
portal.setArg(portalTag);
}
for(PortalTag portalTag : tags) {
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
creation.portalCreated(portal, player, portalTag.VALUE);
}
String portalName = portal.getArg("name");
if(portalName == null || portalName.equals("")) {
throw new PortalTagExeption(Lang.translate("portal.noname"));
}
else if(this.portalHashMap.containsKey(portalName)) {
throw new PortalTagExeption(Lang.translate("portal.takenname"));
}
portal.removeArg("name");
this.portalHashMap.put(portalName, portal);
this.updatePortalArray();
return true;
}
private void updatePortalArray() {
Collection<AdvancedPortal> portalValues = this.portalHashMap.values();
this.portals = portalValues.toArray(new AdvancedPortal[0]);
}
public void removePlayerSelection(PlayerContainer player) throws PortalTagExeption {
}
public void removePortal(PlayerContainer player, String portalName) throws PortalTagExeption {
}
/**
* Get an array of portals without a reference to the main array
* @return
*/
public Set<Map.Entry<String, AdvancedPortal>> getPortals() {
return this.portalHashMap.entrySet();
}
}

View File

@ -20,6 +20,8 @@ public class AdvancedPortal {
private PortalLocation minLoc;
private String triggerBlock;
private HashMap<String, String> args = new HashMap<>();
private transient Set<String> argsCol;
@ -64,16 +66,20 @@ public class AdvancedPortal {
}
for(PortalTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalPreActivated(player, data, this.getArg(portalTag.NAME));
activationHandler.portalPreActivated(this, player, data, this.getArg(portalTag.NAME));
}
for(PortalTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalActivated(player, data, this.getArg(portalTag.NAME));
activationHandler.portalActivated(this, player, data, this.getArg(portalTag.NAME));
}
for(PortalTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalPostActivated(player, data, this.getArg(portalTag.NAME));
activationHandler.portalPostActivated(this, player, data, this.getArg(portalTag.NAME));
}
return true;
}
public void setArg(PortalTag portalTag) {
this.setArg(portalTag.NAME, portalTag.VALUE);
}
}

View File

@ -0,0 +1,10 @@
package com.sekwah.advancedportals.core.api.portal;
/**
* Returns a message saying what went wrong with the portal tag.
*/
public class PortalTagExeption extends Exception {
public PortalTagExeption(String reason) {
super(reason);
}
}

View File

@ -108,6 +108,16 @@ public class TagRegistry {
return false;
}
/**
* Returns a non referenced copy of the array list.
* @return
*/
public ArrayList<String> getTags() {
ArrayList<String> newArrayList = new ArrayList<>();
newArrayList.addAll(this.tags);
return newArrayList;
}
public boolean isTagRegistered(String tag){
return this.tagDesc.containsKey(tag);
}

View File

@ -23,21 +23,21 @@ public class TagHandler {
* Example if the player does not have access to use a tag on the portal.
*
* @param player if null the portal has been created by the server or a plugin
* @param activeData
* @param argData
* @return if the portal can be created.
* @throws PortalTagExeption message given is the reason the portal cant be made
*/
boolean portalCreated(PlayerContainer player, ActivationData activeData, String argData);
void portalCreated(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalTagExeption;
/**
* Example if the player does not have access to remove the portal.
*
* @param player if null the portal has been destroyed by the server or a plugin
* @param activeData
* @param argData
* @return if the portal can be destroyed.
* @throws PortalTagExeption message given is the reason the portal cant be removed
*/
boolean portalDestroyed(PlayerContainer player, ActivationData activeData, String argData);
void portalDestroyed(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalTagExeption;
}
@ -50,7 +50,7 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalPreActivated(PlayerContainer player, ActivationData activeData, String argData);
void portalPreActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
/**
* Activates after portal activation
@ -59,7 +59,7 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalPostActivated(PlayerContainer player, ActivationData activeData, String argData);
void portalPostActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
/**
* Activates if the portal is allowed from pre
@ -68,27 +68,25 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalActivated(PlayerContainer player, ActivationData activeData, String argData);
void portalActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
}
public interface TagStatus {
/**
* If the user has access to add the tag
* If the user has access to add the tag (this does not include being added on creation)
*
* @param player
* @param activeData
* @param argData
* @return if the tag will be added.
*/
boolean tagAdded(PlayerContainer player, ActivationData activeData, String argData);
boolean tagAdded(AdvancedPortal portal, PlayerContainer player, String argData);
/**
* If the user has access to remove the tag
* If the user has access to remove the tag (this does not include being added on destruction)
*
* @param player
* @param activeData
* @param argData
* @return if the tag will be removed.
*/

View File

@ -1,28 +1,80 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.api.portal.PortalTag;
import com.sekwah.advancedportals.core.api.portal.PortalTagExeption;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.ArrayList;
import java.util.List;
public class CreateSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
//AdvancedPortal newPortal = new AdvancedPortal();
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<PortalTag> portalTags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
for (int i = 1; i < args.length; i++) {
if(partingValueWithSpaces) {
if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1);
partingValueWithSpaces = false;
portalTags.add(new PortalTag(argBeingParsed, currentParsedValue));
}
else {
sender.sendMessage(Lang.translate(""));
currentParsedValue += " " + args[i];
}
}
else {
String detectedTag = this.getTag(args[i].toLowerCase());
if(args[i].toLowerCase().startsWith(detectedTag + ":")) {
String arg = args[i].substring(detectedTag.length());
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
currentParsedValue = arg;
}
else {
portalTags.add(new PortalTag(detectedTag, arg));
}
}
}
}
try {
AdvancedPortalsCore.getPortalManager().createPortal(player, portalTags);
} catch (PortalTagExeption portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
+ portalTagExeption.getMessage());
}
}
else {
sender.sendMessage(Lang.translate("command.create.noargs"));
}
}
private String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getTagRegistry().getTags();
for(String tag : tags) {
if(arg.startsWith(tag + ":")) {
return tag;
}
}
return null;
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp();
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override

View File

@ -25,7 +25,7 @@ public class ReloadSubCommand implements SubCommand {
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp();
return sender.isOp() || sender.hasPermission("advancedportals.reload");
}
@Override

View File

@ -0,0 +1,65 @@
package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.api.portal.PortalTag;
import com.sekwah.advancedportals.core.api.portal.PortalTagExeption;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class RemoveSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
}
else {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translate("command.remove.noname"));
}
else {
try {
AdvancedPortalsCore.getPortalManager().removePlayerSelection(player);
} catch (PortalTagExeption portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative")
+ Lang.translateColor("command.remove.error") + " " + portalTagExeption.getMessage());
}
}
}
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
List<String> portalNames = new ArrayList<>();
for(Map.Entry<String, AdvancedPortal> portal : AdvancedPortalsCore.getPortalManager().getPortals()) {
portalNames.add(portal.getKey());
}
Collections.sort(portalNames);
return portalNames;
}
@Override
public String getBasicHelpText() {
return Lang.translate("command.create.help");
}
@Override
public String getDetailedHelpText() {
return Lang.translate("command.create.detailedhelp");
}
}

View File

@ -8,15 +8,22 @@ import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer
import java.util.List;
public class TransUpdateSubCommand implements SubCommand {
private final AdvancedPortalsCore portalsCore;
public TransUpdateSubCommand(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
AdvancedPortalsCore.getInstance().getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("translatedata.replaced"));
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp();
return sender.isOp() || sender.hasPermission("advancedportals.transupdate");
}
@Override
@ -26,11 +33,11 @@ public class TransUpdateSubCommand implements SubCommand {
@Override
public String getBasicHelpText() {
return "This is basic help text";
return Lang.translate("command.trans.help");
}
@Override
public String getDetailedHelpText() {
return "This help text is a lot more detailed than the basic one";
return Lang.translate("command.trans.help");
}
}

View File

@ -19,6 +19,10 @@ public class Config {
private int portalCooldown = 5;
private String warpParticles = "ENDER";
private String warpSound = "ENDER";
private String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
private String selectionBlock = "RED_STAINED_GLASS";