Fixed spelling error and added more to remove command

This commit is contained in:
sekwah41 2018-02-01 19:14:58 +00:00 committed by Sekwah
parent 72ff68fc2a
commit aa5dc09f23
9 changed files with 123 additions and 40 deletions

View File

@ -42,6 +42,9 @@ command.create.detailedhelp=List tags after create in the format tag:value, if y
command.remove.noname= You need to give the name of the portal you want to remove.
command.remove.error= Removing the portal was blocked:
command.remove.noname=No portal by that name was found
command.remove.invalidselection=The portal selection you had is no longer valid
command.remove.noselection=You don't have a portal selected
portal.invalidselection=You must have both pos1 and pos2 selected to create a portal.
portal.noname=No name for the portal has been given.

View File

@ -15,7 +15,7 @@ public class CoreListeners {
}
public void playerJoin(PlayerContainer player) {
AdvancedPortalsCore.getPortalManager().playerJoin(player);
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
if(player.isOp()) {
if(!Lang.translate("translatedata.lastchange").equals(AdvancedPortalsCore.lastTranslationUpdate)) {
player.sendMessage(Lang.translateColor("messageprefix.negative")
@ -26,10 +26,28 @@ public class CoreListeners {
}
}
public void teleportEvent(PlayerContainer player) {
AdvancedPortalsCore.getPortalManager().activateCooldown(player);
}
public void playerLeave(PlayerContainer player) {
AdvancedPortalsCore.getPortalManager().playerLeave(player);
}
/**
* @param loc where the entity spawns
* @return if the entity is allowed to spawn
*/
public boolean mobSpawn(PlayerLocation loc) {
return !AdvancedPortalsCore.getPortalManager().inPortalRegion(loc);
}
/**
* @param player
* @param fromLoc
* @param toLoc
* @return if the player is allowed to move
*/
public boolean playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
return AdvancedPortalsCore.getPortalManager().playerMove(player, fromLoc, toLoc);
}

View File

@ -4,7 +4,7 @@ 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.portal.PortalException;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
@ -27,10 +27,11 @@ public class PortalManager {
* Store data of when the player last entered the portal
*/
private HashMap<String, Long> lastAttempt = new HashMap();
/**
* Tracks what portal a player has selected
* Tracks the name of portal a player has selected
*/
private HashMap<String, AdvancedPortal> selectedPortal = new HashMap();
private HashMap<String, String> selectedPortal = new HashMap();
private HashMap<String, PortalLocation> portalSelectorLeftClick = new HashMap();
private HashMap<String, PortalLocation> portalSelectorRightClick = new HashMap();
@ -73,17 +74,7 @@ public class PortalManager {
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) {
public void activateCooldown(PlayerContainer player) {
this.lastAttempt.put(player.getUUID().toString(), System.currentTimeMillis());
}
@ -95,13 +86,13 @@ public class PortalManager {
return false;
}
public void createPortal(PlayerContainer player, ArrayList<PortalTag> tags) throws PortalTagExeption {
public void createPortal(PlayerContainer player, ArrayList<PortalTag> tags) throws PortalException {
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"));
throw new PortalException(Lang.translate("portal.invalidselection"));
}
}
@ -111,9 +102,9 @@ public class PortalManager {
* @param loc2
* @param tags
* @return
* @throws PortalTagExeption
* @throws PortalException
*/
public boolean createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalTagExeption {
public boolean createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalException {
return createPortal(null, loc1, loc2, tags);
}
@ -127,9 +118,9 @@ public class PortalManager {
* @param loc2
* @param tags
* @return
* @throws PortalTagExeption
* @throws PortalException
*/
public boolean createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalTagExeption {
public boolean createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalException {
int maxX = Math.max(loc1.posX, loc2.posX);
int maxY = Math.max(loc1.posY, loc2.posY);
int maxZ = Math.max(loc1.posZ, loc2.posZ);
@ -150,10 +141,10 @@ public class PortalManager {
}
String portalName = portal.getArg("name");
if(portalName == null || portalName.equals("")) {
throw new PortalTagExeption(Lang.translate("portal.noname"));
throw new PortalException(Lang.translate("portal.noname"));
}
else if(this.portalHashMap.containsKey(portalName)) {
throw new PortalTagExeption(Lang.translate("portal.takenname"));
throw new PortalException(Lang.translate("portal.takenname"));
}
portal.removeArg("name");
this.portalHashMap.put(portalName, portal);
@ -166,12 +157,40 @@ public class PortalManager {
this.portals = portalValues.toArray(new AdvancedPortal[0]);
}
public void removePlayerSelection(PlayerContainer player) throws PortalTagExeption {
public void removePlayerSelection(PlayerContainer player) throws PortalException {
String portal = this.selectedPortal.get(player.getUUID());
if(portal != null) {
try {
this.removePortal(player, portal);
}
catch(PortalException e) {
if(e.getMessage().equals(Lang.translate("command.remove.noname"))) {
this.selectedPortal.remove(player.getUUID());
throw new PortalException(Lang.translate("command.remove.invalidselection"));
}
else {
throw e;
}
}
}
throw new PortalException(Lang.translate("command.remove.noselection"));
}
/**
* @param player null if a player didnt send it
* @param portalName
* @throws PortalException
*/
public void removePortal(PlayerContainer player, String portalName) throws PortalException {
AdvancedPortal portal = this.getPortal(portalName);
if(portal == null) {
throw new PortalException(Lang.translate("command.remove.noname"));
}
}
public void removePortal(PlayerContainer player, String portalName) throws PortalTagExeption {
private AdvancedPortal getPortal(String portalName) {
return this.portalHashMap.get(portalName);
}
/**
@ -181,4 +200,13 @@ public class PortalManager {
public Set<Map.Entry<String, AdvancedPortal>> getPortals() {
return this.portalHashMap.entrySet();
}
public boolean inPortalRegion(PlayerLocation loc) {
return this.inPortalRegion(loc, 0);
}
private boolean inPortalRegion(PlayerLocation loc, int additionalArea) {
return true;
}
}

View File

@ -3,8 +3,8 @@ 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) {
public class PortalException extends Exception {
public PortalException(String reason) {
super(reason);
}
}

View File

@ -25,9 +25,9 @@ public class TagHandler {
* @param player if null the portal has been created by the server or a plugin
* @param argData
* @return if the portal can be created.
* @throws PortalTagExeption message given is the reason the portal cant be made
* @throws PortalException message given is the reason the portal cant be made
*/
void portalCreated(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalTagExeption;
void portalCreated(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException;
/**
* Example if the player does not have access to remove the portal.
@ -35,9 +35,9 @@ public class TagHandler {
* @param player if null the portal has been destroyed by the server or a plugin
* @param argData
* @return if the portal can be destroyed.
* @throws PortalTagExeption message given is the reason the portal cant be removed
* @throws PortalException message given is the reason the portal cant be removed
*/
void portalDestroyed(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalTagExeption;
void portalDestroyed(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException;
}

View File

@ -3,7 +3,7 @@ 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.PortalTag;
import com.sekwah.advancedportals.core.api.portal.PortalTagExeption;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
@ -38,7 +38,7 @@ public class CreateSubCommand implements SubCommand {
}
else {
String detectedTag = this.getTag(args[i].toLowerCase());
if(args[i].toLowerCase().startsWith(detectedTag + ":")) {
if(detectedTag != null) {
String arg = args[i].substring(detectedTag.length());
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
@ -52,7 +52,7 @@ public class CreateSubCommand implements SubCommand {
}
try {
AdvancedPortalsCore.getPortalManager().createPortal(player, portalTags);
} catch (PortalTagExeption portalTagExeption) {
} catch (PortalException portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
+ portalTagExeption.getMessage());
}

View File

@ -3,8 +3,7 @@ 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.api.portal.PortalException;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
@ -19,8 +18,12 @@ public class RemoveSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
try {
AdvancedPortalsCore.getPortalManager().removePortal(sender.getPlayerContainer(), args[1]);
} catch (PortalException portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative")
+ Lang.translateColor("command.remove.error") + " " + portalTagExeption.getMessage());
}
}
else {
PlayerContainer player = sender.getPlayerContainer();
@ -30,7 +33,7 @@ public class RemoveSubCommand implements SubCommand {
else {
try {
AdvancedPortalsCore.getPortalManager().removePlayerSelection(player);
} catch (PortalTagExeption portalTagExeption) {
} catch (PortalException portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative")
+ Lang.translateColor("command.remove.error") + " " + portalTagExeption.getMessage());
}

View File

@ -0,0 +1,9 @@
package com.sekwah.advancedportals.coreconnector;
public class ConnectorDataCollector {
public boolean materialExists(String materialName) {
return false;
}
}

View File

@ -31,11 +31,33 @@ public class PlayerContainer {
return null;
}
public double getEyeHeight() {
return 0;
}
public void teleport(PlayerLocation location) {}
public boolean hasPermission(String permission) {
return false;
}
/**
* @param blockPos
* @param material
*/
public void sendFakeBlock(PortalLocation blockPos, String material) {
}
/**
* Only 1.12 and below supported
* @param blockPos
* @param material
* @param data
*/
public void sendFakeBlockWithData(PortalLocation blockPos, String material, byte data) {
}
public void giveItem(String material, String itemName, String... itemDescription) {}
}