Skip to content

Commit

Permalink
* Updated dependencies.
Browse files Browse the repository at this point in the history
* Fixed issues with portal delays executing commands before the delay was complete.
* Fixed the delay command and tab completion.
* Fixed the cooldown command.
  • Loading branch information
XZot1K committed Oct 8, 2023
1 parent c43c1f5 commit 307b0ee
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>xzot1k.plugins.sp</groupId>
<artifactId>SimplePortals</artifactId>
<version>1.7.3</version>
<version>1.7.4</version>
<packaging>jar</packaging>

<name>SimplePortals</name>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/xzot1k/plugins/sp/SimplePortals.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

Expand Down Expand Up @@ -52,11 +53,16 @@ public void onEnable() {
setPrismaInstalled(getServer().getPluginManager().getPlugin("Prisma") != null);
manager = new Manager(this);

PluginCommand command = getCommand("simpleportals");
if (command != null) {
command.setTabCompleter(new TabCompleter(this));
command.setExecutor(new Commands(this));
TabCompleter tabCompleter = new TabCompleter(this);
Commands commands = new Commands(this);
for (Map.Entry<String, Map<String, Object>> entry : getDescription().getCommands().entrySet()) {
PluginCommand command = getCommand(entry.getKey());
if (command == null) continue;

command.setTabCompleter(tabCompleter);
command.setExecutor(commands);
}

getServer().getPluginManager().registerEvents(new Listeners(this), this);
getManager().convertFromPortalsFile();

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/xzot1k/plugins/sp/api/objects/Portal.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public void invokeCommands(Player player, Location locationForCoords) {
* @param entity The entity to perform actions on.
*/
public void performAction(@NotNull Entity entity) {

final boolean isPlayer = (entity instanceof Player);

if (isPlayer) {
Expand Down Expand Up @@ -285,6 +284,10 @@ public void performAction(@NotNull Entity entity) {
if (!teleportTask.isCancelled()) teleportTask.cancel();
}, (getDelay() * 20L + 1));
} else {

invokeCommands((Player) entity, location);
if (isCommandsOnly()) return;

getPluginInstance().getManager().playTeleportEffect(entity.getLocation());
getPluginInstance().getManager().teleportWithEntity(entity, location);
getPluginInstance().getManager().getPortalLinkMap().put(entity.getUniqueId(), getPortalId());
Expand Down Expand Up @@ -339,6 +342,10 @@ && getPluginInstance().getManager().getSmartTransferMap().containsKey(entity.get
}, (getDelay() * 20L + 1));
} else {
final Location loc = serializableLocation.asBukkitLocation();

invokeCommands((Player) entity, loc);
if (isCommandsOnly()) return;

getPluginInstance().getManager().playTeleportEffect(entity.getLocation());
getPluginInstance().getManager().teleportWithEntity(player, loc);
getPluginInstance().getManager().getPortalLinkMap().put(player.getUniqueId(), getPortalId());
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/xzot1k/plugins/sp/core/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

if (args.length >= 3) {

boolean isAddCmd = (args[0].equalsIgnoreCase("addcommand") || args[0].equalsIgnoreCase("addcmd")),
isMessageCmd = args[0].equalsIgnoreCase("message"),
isSetLocationCmd = (args[0].equalsIgnoreCase("setlocation") || args[0].equalsIgnoreCase("sl")),
isCooldownCmd = args[0].equalsIgnoreCase("cooldown"),
isDelayCmd = args[0].equalsIgnoreCase("delay");

if (isAddCmd || isMessageCmd || isCooldownCmd || isSetLocationCmd) {
if (isAddCmd || isMessageCmd || isCooldownCmd || isDelayCmd || isSetLocationCmd) {

Portal prevPortal = null, currentPortal = null;
StringBuilder nameBuilder = new StringBuilder(),
Expand Down Expand Up @@ -599,7 +598,7 @@ private void initiatePortalCooldown(CommandSender sender, String portalName, Str
}

Portal portal = getPluginInstance().getManager().getPortal(portalName);
if (portal != null) {
if (portal == null) {
sender.sendMessage(getPluginInstance().getManager().colorText(getPluginInstance().getLangConfig().getString("prefix")
+ Objects.requireNonNull(getPluginInstance().getLangConfig().getString("portal-invalid-message"))
.replace("{name}", portalName)));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/xzot1k/plugins/sp/core/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ private void initiatePortalStuff(Location toLocation, Location fromLocation, Ent
if (portal != null && !portal.isDisabled()) {
if (isPlayer) {
final Player player = (Player) entity;

TeleportTask teleportTask = pluginInstance.getManager().getTeleportTasks().getOrDefault(player.getUniqueId(), null);
if (teleportTask != null && !teleportTask.isCancelled()) return;

if (pluginInstance.getManager().getPortalLinkMap().containsKey(player.getUniqueId())
&& pluginInstance.getManager().getPortalLinkMap().get(player.getUniqueId()).equalsIgnoreCase(portal.getPortalId()))
return;
Expand Down Expand Up @@ -296,8 +300,7 @@ private void initiatePortalStuff(Location toLocation, Location fromLocation, Ent
if (!canBypassCooldown) pluginInstance.getManager().updatePlayerPortalCooldown((Player) entity, "normal");
}

if (isPlayer) portal.invokeCommands((Player) entity, toLocation);
if (!portal.isCommandsOnly() || portal.getTeleportLocation() == null) {
if (portal.getTeleportLocation() != null) {
if (isPlayer) {
final Player player = (Player) entity;
if (portal.getMessage() != null && !portal.getMessage().isEmpty())
Expand Down Expand Up @@ -334,7 +337,8 @@ else if (portal.getSubTitle() != null && !portal.getSubTitle().isEmpty())
final Player player = (Player) entity;

pluginInstance.getManager().getPortalLinkMap().remove(player.getUniqueId());
if (!pluginInstance.getManager().getSmartTransferMap().isEmpty() && pluginInstance.getManager().getSmartTransferMap().containsKey(player.getUniqueId())) {
if (!pluginInstance.getManager().getSmartTransferMap().isEmpty()
&& pluginInstance.getManager().getSmartTransferMap().containsKey(player.getUniqueId())) {
SerializableLocation serializableLocation = pluginInstance.getManager().getSmartTransferMap().get(player.getUniqueId());
if (serializableLocation != null) {
Location location = player.getLocation();
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/xzot1k/plugins/sp/core/TabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import xzot1k.plugins.sp.api.enums.PortalCommandType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TabCompleter implements org.bukkit.command.TabCompleter {
Expand All @@ -30,7 +29,7 @@ public TabCompleter(SimplePortals pluginInstance) {
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
//removed command.getName().equalsIgnoreCase("simpleportals") && because not necessary
if ( commandSender.hasPermission("simpleportals.use") ) {
if (commandSender.hasPermission("simpleportals.use")) {
values.clear();
partialValues.clear();
if (args.length == 1) {
Expand All @@ -55,34 +54,37 @@ public List<String> onTabComplete(CommandSender commandSender, Command command,
values.add("disablemessages");
values.add("list");
values.add("cooldown");
values.add("delay");


} else if (args.length == 2 || (args.length == 3 && (args[0].equalsIgnoreCase("setlocation") || args[0].equalsIgnoreCase("sl"))) ){
} else if (args.length == 2 || (args.length == 3 && (args[0].equalsIgnoreCase("setlocation")
|| args[0].equalsIgnoreCase("sl")))) {
//The portal name should not be completed for every argument
if( !args[0].equalsIgnoreCase("selectionmode") && !args[0].equalsIgnoreCase("sm") && !args[0].equalsIgnoreCase("create") && !args[0].equalsIgnoreCase("list") ){
if (!args[0].equalsIgnoreCase("selectionmode") && !args[0].equalsIgnoreCase("sm")
&& !args[0].equalsIgnoreCase("create") && !args[0].equalsIgnoreCase("list")) {
values.addAll(getPluginInstance().getManager().getPortalNames(false));
}
} else if (args.length == 3) {
if(args[0].equalsIgnoreCase("cooldown")){
for(int i=0; i<=12; i++){
values.add(""+i);
if (args[0].equalsIgnoreCase("cooldown") || args[0].equalsIgnoreCase("delay")) {
for (int i = 0; i <= 12; i++) {
values.add("" + i);
}
}else{
} else {
int colonCount = 0;
for (char character : args[2].toCharArray()){
if (character == ':'){
for (char character : args[2].toCharArray()) {
if (character == ':') {
colonCount++;
}
}

if (colonCount == 1){
for (PortalCommandType portalCommandType : PortalCommandType.values()){
if (colonCount == 1) {
for (PortalCommandType portalCommandType : PortalCommandType.values()) {
values.add(portalCommandType.name());
}
//Return immediately, because copyPartialMatches breaks this for some reason
return values;
}else if (colonCount == 2){
for (int i = 0; ++i < 100; ){
} else if (colonCount == 2) {
for (int i = 0; ++i < 100; ) {
values.add(String.valueOf(i));
}
//Return immediately, because copyPartialMatches breaks this for some reason
Expand Down Expand Up @@ -111,7 +113,6 @@ public List<String> onTabComplete(CommandSender commandSender, Command command,
StringUtil.copyPartialMatches(args[args.length - 1], values, partialValues);



//if (values.size() > 0) Collections.sort(values);
return partialValues;
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/xzot1k/plugins/sp/core/tasks/TeleportTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TeleportTask extends BukkitRunnable {
private final Location location;
private long ticksPassed = 0;
private boolean done = false;

public TeleportTask(Entity entity, Portal portal, Location location) {
this.INSTANCE = SimplePortals.getPluginInstance();
this.entity = entity;
Expand Down Expand Up @@ -50,7 +51,6 @@ public void run() {
if (rem <= 0 && !done) {
done = true;

INSTANCE.getManager().teleportWithEntity(entity, location);
if (entity instanceof Player) {
final Player player = ((Player) entity);

Expand All @@ -60,9 +60,17 @@ public void run() {
player.sendTitle(INSTANCE.getManager().colorText(title), INSTANCE.getManager().colorText(subTitle
.replace("{rem}", String.valueOf(rem))), 0, 40, 0);
}
}

INSTANCE.getManager().getPortalLinkMap().put(player.getUniqueId(), portal.getPortalId());
INSTANCE.getManager().getEntitiesInTeleportationAndPortals().remove(player.getUniqueId());
portal.invokeCommands((Player) entity, location);

if (!portal.isCommandsOnly()) {
INSTANCE.getManager().teleportWithEntity(entity, location);
if (entity instanceof Player) {
final Player player = ((Player) entity);
INSTANCE.getManager().getPortalLinkMap().put(player.getUniqueId(), portal.getPortalId());
INSTANCE.getManager().getEntitiesInTeleportationAndPortals().remove(player.getUniqueId());
}
}

cancel();
Expand Down

0 comments on commit 307b0ee

Please sign in to comment.