Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.mvplugins.multiverse.core.MultiverseCoreApi;
import org.mvplugins.multiverse.core.config.node.ConfigNode;
import org.mvplugins.multiverse.core.config.node.Node;
import org.mvplugins.multiverse.core.config.node.NodeGroup;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.exceptions.MultiverseException;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.external.vavr.control.Try;
import org.mvplugins.multiverse.portals.action.ActionHandler;
import org.mvplugins.multiverse.portals.action.ActionHandlerProvider;
import org.mvplugins.multiverse.portals.locale.MVPi18n;
import org.mvplugins.multiverse.portals.utils.MultiverseRegion;

import java.util.Collections;
Expand Down Expand Up @@ -74,17 +74,20 @@ private <N extends Node> N node(N node) {
.stringParser((sender, input, type) -> {
if (input.equals("@selected-region")) {
if (!(sender instanceof Player player)) {
return Try.failure(new MultiverseException("You can only use '@selected-region' as a player."));
return Try.failure(new MultiverseException(
Message.of(MVPi18n.PORTALCONFIG_LOCATION_PLAYERSONLY)));
}
MultiverseRegion region = plugin.getPortalSession(player).getSelectedRegion();
if (region == null) {
return Try.failure(new MultiverseException("You must select a region first. See `/mvp wand` for more info."));
return Try.failure(new MultiverseException(
Message.of(MVPi18n.PORTALCONFIG_LOCATION_SELECTIONREQUIRED)));
}
return Try.success(region.toString());
}
PortalLocation portalLocation = PortalLocation.parseLocation(input);
if (!portalLocation.isValidLocation()) {
return Try.failure(new MultiverseException("Invalid location format. The portal location must be in the format `WORLD:X,Y,Z:X,Y,Z`."));
return Try.failure(new MultiverseException(
Message.of(MVPi18n.PORTALCONFIG_LOCATION_INVALID)));
}
return Try.success(portalLocation.toString());
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public void onEnable() {

Logging.setDebugLevel(coreConfig.get().getGlobalDebug());

this.setUpLocales();

// Register our commands
this.registerCommands();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.entity.LivingEntity;
import org.mvplugins.multiverse.core.economy.MVEconomist;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
import org.mvplugins.multiverse.core.command.MVCommandManager;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.locale.message.MessageReplacement.Replace;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
import org.mvplugins.multiverse.portals.config.PortalsConfig;
import org.mvplugins.multiverse.portals.enums.MoveType;
import org.mvplugins.multiverse.portals.locale.MVPi18n;
import org.mvplugins.multiverse.portals.utils.DisplayUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import org.mvplugins.multiverse.portals.utils.MultiverseRegion;
import org.mvplugins.multiverse.portals.utils.PortalManager;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

public class PortalPlayerSession {
private final MultiversePortals plugin;
private final PortalsConfig portalsConfig;
private final PortalManager portalManager;
private final WorldManager worldManager;
private final DisplayUtils displayUtils;
private final Player player;
private final MVCommandIssuer issuer;

private MVPortal portalSelection = null;
private MVPortal standingIn = null;
Expand All @@ -52,6 +58,7 @@
this.worldManager = plugin.getServiceLocator().getService(WorldManager.class);
this.displayUtils = plugin.getServiceLocator().getService(DisplayUtils.class);
this.player = p;
this.issuer = plugin.getServiceLocator().getService(MVCommandManager.class).getCommandIssuer(p);
this.setLocation(p.getLocation());
this.lastTeleportTime = new Date(new Date().getTime() - this.portalsConfig.getPortalCooldown());
}
Expand All @@ -68,10 +75,9 @@
public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
if (this.debugMode) {
this.player.sendMessage("Portal debug mode " + ChatColor.GREEN + "ENABLED");
this.player.sendMessage("Use " + ChatColor.DARK_AQUA + "/mvp debug" + ChatColor.WHITE + " to disable.");
this.issuer.sendInfo(MVPi18n.DEBUG_ENABLED);
} else {
this.player.sendMessage("Portal debug mode " + ChatColor.RED + "DISABLED");
this.issuer.sendInfo(MVPi18n.DEBUG_DISABLED);
}
}

Expand Down Expand Up @@ -145,12 +151,16 @@
}
this.leftClick = v;
this.leftClickWorld = world;
String message = ChatColor.AQUA + "First position set to: (" + v.getBlockX() + ", " + v.getBlockY() + ", " + v.getBlockZ() + ")";
String position = "(" + v.getBlockX() + ", " + v.getBlockY() + ", " + v.getBlockZ() + ")";
if (this.leftClickWorld == this.rightClickWorld && this.rightClick != null) {
MultiverseRegion tempReg = new MultiverseRegion(this.leftClick, this.rightClick, this.leftClickWorld);
message += ChatColor.GOLD + " (" + tempReg.getArea() + " blocks)";
this.issuer.sendInfo(MVPi18n.SELECTION_FIRST_AREA,
replace("{position}").with(position),

Check failure on line 158 in src/main/java/org/mvplugins/multiverse/portals/PortalPlayerSession.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "{position}" 4 times.

See more on https://sonarcloud.io/project/issues?id=Multiverse_Multiverse-Portals&issues=AZ-E5m7dNV3sao26_IHn&open=AZ-E5m7dNV3sao26_IHn&pullRequest=719
Replace.COUNT.with(tempReg.getArea()));
} else {
this.issuer.sendInfo(MVPi18n.SELECTION_FIRST,
replace("{position}").with(position));
}
this.player.sendMessage(message);
return true;
}

Expand All @@ -160,12 +170,16 @@
}
this.rightClick = v;
this.rightClickWorld = world;
String message = ChatColor.AQUA + "Second position set to: (" + v.getBlockX() + ", " + v.getBlockY() + ", " + v.getBlockZ() + ")";
String position = "(" + v.getBlockX() + ", " + v.getBlockY() + ", " + v.getBlockZ() + ")";
if (this.leftClickWorld == this.rightClickWorld && this.leftClick != null) {
MultiverseRegion tempReg = new MultiverseRegion(this.leftClick, this.rightClick, this.leftClickWorld);
message += ChatColor.GOLD + " (" + tempReg.getArea() + " blocks)";
this.issuer.sendInfo(MVPi18n.SELECTION_SECOND_AREA,
replace("{position}").with(position),
Replace.COUNT.with(tempReg.getArea()));
} else {
this.issuer.sendInfo(MVPi18n.SELECTION_SECOND,
replace("{position}").with(position));
}
this.player.sendMessage(message);
return true;

}
Expand All @@ -180,27 +194,27 @@
return new MultiverseRegion(minPoint, maxPoint,
this.worldManager.getLoadedWorld(minPoint.getWorld().getName()).getOrNull());
} else {
this.player.sendMessage("You haven't finished your selection.");
this.issuer.sendError(MVPi18n.SELECTION_WORLDEDIT_INCOMPLETE);
return null;
}
} else {
this.player.sendMessage("You must have a WorldEdit selection to do this.");
this.issuer.sendError(MVPi18n.SELECTION_WORLDEDIT_REQUIRED);
return null;
}
}
// They're using our crappy selection:
if (this.leftClick == null) {
this.player.sendMessage("You need to LEFT click on a block with your wand!");
this.issuer.sendError(MVPi18n.SELECTION_LEFT_REQUIRED);
return null;
}
if (this.rightClick == null) {
this.player.sendMessage("You need to RIGHT click on a block with your wand!");
this.issuer.sendError(MVPi18n.SELECTION_RIGHT_REQUIRED);
return null;
}
if (!this.leftClickWorld.equals(this.rightClickWorld)) {
this.player.sendMessage("You need to select both coords in the same world!");
this.player.sendMessage("Left Click Position was in:" + this.leftClickWorld.getAlias());
this.player.sendMessage("Right Click Position was in:" + this.rightClickWorld.getAlias());
this.issuer.sendError(MVPi18n.SELECTION_SAMEWORLD_REQUIRED,
replace("{leftWorld}").with(this.leftClickWorld.getAlias()),
replace("{rightWorld}").with(this.rightClickWorld.getAlias()));
return null;
}
return new MultiverseRegion(this.leftClick, this.rightClick, this.leftClickWorld);
Expand Down Expand Up @@ -251,13 +265,13 @@
return false;
}

displayUtils.showStaticInfo(this.player, this.standingIn, "You are currently standing in ");
displayUtils.showStaticInfo(this.player, this.standingIn, MVPi18n.PORTALINFO_DEBUGHEADER);
return true;
}

public boolean showDebugInfo(MVPortal portal) {
if (portal.playerCanEnterPortal(this.player)) {
displayUtils.showStaticInfo(this.player, portal, "Portal Info ");
displayUtils.showStaticInfo(this.player, portal, MVPi18n.PORTALINFO_HEADER);
}
Logging.info("Player " + this.player.getName() + " walked through" + portal.getName() + " with debug on.");
return true;
Expand All @@ -276,7 +290,7 @@
public boolean checkAndSendCooldownMessage() {
long cooldownMs = this.getRemainingTeleportCooldown();
if (cooldownMs > 0) {
this.player.sendMessage(this.getCooldownMessage(cooldownMs));
this.issuer.sendError(this.getCooldownMessage(cooldownMs));
return true;
}

Expand All @@ -303,11 +317,9 @@
* @param cooldownMs The cooldown time in milliseconds.
* @return A message to be sent to a player, informing them about the remaining cooldown time.
*/
private String getCooldownMessage(long cooldownMs) {
return "There is a portal " + ChatColor.AQUA + "cooldown "
+ ChatColor.WHITE + "in effect. Please try again in "
+ ChatColor.GOLD + this.formatCooldownTime(cooldownMs)
+ ChatColor.WHITE + ".";
private Message getCooldownMessage(long cooldownMs) {
return Message.of(MVPi18n.PORTAL_COOLDOWN,
replace("{cooldown}").with(formatCooldownTime(cooldownMs)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import org.bukkit.command.CommandSender;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.locale.message.MessageReplacement.Replace;
import org.mvplugins.multiverse.core.utils.result.Attempt;
import org.mvplugins.multiverse.external.jetbrains.annotations.ApiStatus;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.vavr.control.Option;
import org.mvplugins.multiverse.portals.locale.MVPi18n;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

/**
* Provides various actions that can be performed when a portal is used. This extends to more than just teleporting.
* <br/>
Expand Down Expand Up @@ -68,8 +72,9 @@ public void registerHandlerType(@NotNull ActionHandlerType<?, ?> handlerType) {
return Option.of(handlerTypeMap.get(name))
.map(Attempt::<ActionHandlerType<?, ?>, ActionFailureReason>success)
.getOrElse(() -> Attempt.failure(ActionFailureReason.INSTANCE,
Message.of("Unknown action type '" + name + "'. Supported types are: "
+ String.join(", ", handlerTypeMap.keySet()))));
Message.of(MVPi18n.ACTION_UNKNOWN_TYPE,
Replace.NAME.with(name),
replace("{types}").with(String.join(", ", handlerTypeMap.keySet())))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mvplugins.multiverse.portals.action.types;

import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.utils.result.Attempt;
Expand All @@ -26,8 +25,7 @@ final class CommandActionHandler extends ActionHandler<CommandActionHandlerType,

@Override
public @NotNull Message actionDescription(Entity entity) {
return Message.of(ChatColor.AQUA + "Runs command " + commandRunner.cmdType + " " + ChatColor.GOLD + "/"
+ commandRunner.parseCmdStrPlaceholders(entity));
return commandRunner.actionDescription(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.portals.action.ActionFailureReason;
import org.mvplugins.multiverse.portals.action.ActionHandlerType;
import org.mvplugins.multiverse.portals.locale.MVPi18n;

import java.util.Collection;
import java.util.List;
Expand All @@ -25,7 +26,7 @@ final class CommandActionHandlerType extends ActionHandlerType<CommandActionHand
@NotNull String action) {
if (action.isEmpty()) {
return Attempt.failure(ActionFailureReason.INSTANCE,
Message.of("Please specific a valid command to run as the portal's action."));
Message.of(MVPi18n.ACTION_COMMAND_INVALID));
}
return Attempt.success(new CommandActionHandler(this, CommandRunner.fromString(action)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.mvplugins.multiverse.core.utils.REPatterns;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.external.acf.locales.MessageKeyProvider;
import org.mvplugins.multiverse.portals.locale.MVPi18n;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

abstract class CommandRunner {

Expand All @@ -20,12 +25,12 @@ static CommandRunner fromString(String command) {

final String rawCmd;
private final String cmdStr;
final String cmdType;
private final MessageKeyProvider descriptionKey;

private CommandRunner(String rawCmd, String cmdStr, String cmdType) {
private CommandRunner(String rawCmd, String cmdStr, MessageKeyProvider descriptionKey) {
this.rawCmd = rawCmd;
this.cmdStr = cmdStr;
this.cmdType = cmdType;
this.descriptionKey = descriptionKey;
}

void runCommand(CommandSender sender) {
Expand All @@ -46,12 +51,17 @@ String parseCmdStrPlaceholders(CommandSender sender) {
return parsedCmd;
}

Message actionDescription(CommandSender sender) {
return Message.of(descriptionKey,
replace("{command}").with(parseCmdStrPlaceholders(sender)));
}

protected abstract void runCommand(CommandSender sender, String cmd);

private static class Self extends CommandRunner {

private Self(String rawCmd, String cmdStr) {
super(rawCmd, cmdStr, "myself");
super(rawCmd, cmdStr, MVPi18n.ACTION_COMMAND_SELF);
}

@Override
Expand All @@ -63,7 +73,7 @@ protected void runCommand(CommandSender sender, String cmd) {
private static class Op extends CommandRunner {

private Op(String rawCmd, String cmdStr) {
super(rawCmd, cmdStr, "as operator");
super(rawCmd, cmdStr, MVPi18n.ACTION_COMMAND_OPERATOR);
}

@Override
Expand All @@ -83,7 +93,7 @@ protected void runCommand(CommandSender sender, String cmd) {
private static class Console extends CommandRunner {

private Console(String rawCmd, String cmdStr) {
super(rawCmd, cmdStr, "from console");
super(rawCmd, cmdStr, MVPi18n.ACTION_COMMAND_CONSOLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.mvplugins.multiverse.portals.action.types;

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Vehicle;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.locale.message.MessageReplacement.Replace;
import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter;
import org.mvplugins.multiverse.core.teleportation.PassengerMode;
import org.mvplugins.multiverse.core.teleportation.PassengerModes;
Expand All @@ -14,6 +14,8 @@
import org.mvplugins.multiverse.portals.MVPortal;
import org.mvplugins.multiverse.portals.action.ActionFailureReason;
import org.mvplugins.multiverse.portals.action.ActionHandler;
import org.mvplugins.multiverse.portals.locale.MVPi18n;


final class MultiverseDestinationActionHandler extends ActionHandler<MultiverseDestinationActionHandlerType, MultiverseDestinationActionHandler> {

Expand Down Expand Up @@ -43,8 +45,8 @@ final class MultiverseDestinationActionHandler extends ActionHandler<MultiverseD

@Override
public @NotNull Message actionDescription(Entity entity) {
//todo use v5.4's DestinationInstance#getDisplayMessage method
return Message.of(ChatColor.AQUA + "Teleports to " + ChatColor.GOLD + destinationInstance.toString());
return Message.of(MVPi18n.ACTION_MULTIVERSEDESTINATION_DESCRIPTION,
Replace.DESTINATION.with(destinationInstance.toString()));
}

private PassengerMode passengerModeFor(MVPortal portal, Entity entity) {
Expand Down
Loading
Loading