Skip to content

Commit

Permalink
Sync back to main after looking up offline player async
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 committed Aug 3, 2024
1 parent b556cb1 commit 399b166
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void handleCommand(CommandContext<PlayerCommandSource> context) {
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_FRIEND))
.whenComplete((offlinePlayer, exception) -> {
.whenCompleteAsync((offlinePlayer, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -93,7 +93,7 @@ private void handleCommand(CommandContext<PlayerCommandSource> context) {
return;
}
processWithFriend(sender, region, offlinePlayer);
});
}, this.executor);
}

private void processWithFriend(@Nonnull Player sender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -39,16 +40,19 @@ public class DelFriendCommand extends AreashopCommandBean {
private final MessageBridge messageBridge;
private final CommandFlag<GeneralRegion> regionFlag;
private final OfflinePlayerHelper offlinePlayerHelper;
private final BukkitSchedulerExecutor executor;

@Inject
public DelFriendCommand(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager,
@Nonnull OfflinePlayerHelper offlinePlayerHelper
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
@Nonnull BukkitSchedulerExecutor executor
) {
this.messageBridge = messageBridge;
this.regionFlag = RegionParseUtil.createDefault(fileManager);
this.offlinePlayerHelper = offlinePlayerHelper;
this.executor = executor;
}

/**
Expand Down Expand Up @@ -101,7 +105,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
.whenComplete((offlinePlayer, exception) -> {
.whenCompleteAsync((offlinePlayer, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -112,7 +116,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
return;
}
processWithSender(sender, region, offlinePlayer);
});
}, this.executor);
}

private void processWithSender(@Nonnull CommandSender sender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import me.wiefferink.areashop.commands.util.RegionInfoUtil;
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.bukkit.command.CommandSender;
import org.incendo.cloud.Command;
import org.incendo.cloud.bean.CommandProperties;
Expand All @@ -25,16 +26,19 @@ public class InfoPlayerCommand extends AreashopCommandBean {
private final MessageBridge messageBridge;
private final IFileManager fileManager;
private final OfflinePlayerHelper offlinePlayerHelper;
private final BukkitSchedulerExecutor executor;

@Inject
public InfoPlayerCommand(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager,
@Nonnull OfflinePlayerHelper offlinePlayerHelper
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
@Nonnull BukkitSchedulerExecutor executor
) {
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.offlinePlayerHelper = offlinePlayerHelper;
this.executor = executor;
}

@Override
Expand Down Expand Up @@ -66,7 +70,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
.whenComplete((offlinePlayer, exception) -> {
.whenCompleteAsync((offlinePlayer, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -77,7 +81,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
return;
}
RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer);
});
}, this.executor);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.commands.util.commandsource.PlayerCommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -29,16 +30,19 @@ public class MeCommand extends AreashopCommandBean {
private final IFileManager fileManager;
private final MessageBridge messageBridge;
private final OfflinePlayerHelper offlinePlayerHelper;
private final BukkitSchedulerExecutor executor;

@Inject
public MeCommand(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager,
@Nonnull OfflinePlayerHelper offlinePlayerHelper
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
@Nonnull BukkitSchedulerExecutor executor
) {
this.messageBridge = messageBridge;
this.fileManager = fileManager;
this.offlinePlayerHelper = offlinePlayerHelper;
this.executor = executor;
}

@Override
Expand Down Expand Up @@ -73,7 +77,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
throw new AreaShopCommandException("me-noPermission");
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
.whenComplete((offlinePlayer, exception) -> {
.whenCompleteAsync((offlinePlayer, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -84,7 +88,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
return;
}
RegionInfoUtil.showRegionInfo(this.messageBridge, this.fileManager, sender, offlinePlayer);
});
}, this.executor);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
}
double price = context.get(KEY_PRICE);
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_LANDLORD))
.whenComplete((landlord, exception) -> {
.whenCompleteAsync((landlord, exception) -> {
if (exception != null) {
player.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -118,8 +118,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
buyRegion.setLandlord(landlord.getUniqueId(), landlord.getName());
this.fileManager.addRegion(buyRegion);
this.messageBridge.message(player, "add-success", "buy", regionName);
});

}, this.executor);
}, this.executor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
DurationInput duration = context.get(KEY_DURATION);

this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_LANDLORD))
.whenComplete((landlord, exception) -> {
.whenCompleteAsync((landlord, exception) -> {
if (exception != null) {
player.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -126,8 +126,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
rentRegion.setDuration(duration.toTinySpacedString());
this.fileManager.addRegion(rentRegion);
this.messageBridge.message(player, "add-success", "rent", regionName);
});

}, this.executor);
}, this.executor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
import me.wiefferink.areashop.managers.IFileManager;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command;
Expand All @@ -30,16 +31,19 @@ public class SetLandlordCommand extends AreashopCommandBean {
private final MessageBridge messageBridge;
private final CommandFlag<GeneralRegion> regionFlag;
private final OfflinePlayerHelper offlinePlayerHelper;
private final BukkitSchedulerExecutor executor;

@Inject
public SetLandlordCommand(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager,
@Nonnull OfflinePlayerHelper offlinePlayerHelper
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
@Nonnull BukkitSchedulerExecutor executor
) {
this.messageBridge = messageBridge;
this.regionFlag = RegionParseUtil.createDefault(fileManager);
this.offlinePlayerHelper = offlinePlayerHelper;
this.executor = executor;
}


Expand Down Expand Up @@ -76,7 +80,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
}
GeneralRegion region = RegionParseUtil.getOrParseRegion(context, sender, this.regionFlag);
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
.whenComplete((landlord, exception) -> {
.whenCompleteAsync((landlord, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -90,7 +94,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
region.setLandlord(landlord.getUniqueId(), playerName);
region.update();
this.messageBridge.message(sender, "setlandlord-success", playerName, region);
});
}, this.executor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.wiefferink.areashop.regions.BuyRegion;
import me.wiefferink.areashop.regions.GeneralRegion;
import me.wiefferink.areashop.regions.RentRegion;
import me.wiefferink.areashop.tools.BukkitSchedulerExecutor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -34,16 +35,19 @@ public class SetOwnerCommand extends AreashopCommandBean {

private final MessageBridge messageBridge;
private final OfflinePlayerHelper offlinePlayerHelper;
private final BukkitSchedulerExecutor executor;

@Inject
public SetOwnerCommand(
@Nonnull MessageBridge messageBridge,
@Nonnull IFileManager fileManager,
@Nonnull OfflinePlayerHelper offlinePlayerHelper
) {
@Nonnull OfflinePlayerHelper offlinePlayerHelper,
@Nonnull BukkitSchedulerExecutor executor
) {
this.messageBridge = messageBridge;
this.regionFlag = RegionParseUtil.createDefault(fileManager);
this.offlinePlayerHelper = offlinePlayerHelper;
this.executor = executor;
}

@Override
Expand Down Expand Up @@ -88,7 +92,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
return;
}
this.offlinePlayerHelper.lookupOfflinePlayerAsync(context.get(KEY_PLAYER))
.whenComplete((offlinePlayer, exception) -> {
.whenCompleteAsync((offlinePlayer, exception) -> {
if (exception != null) {
sender.sendMessage("failed to lookup offline player!");
exception.printStackTrace();
Expand All @@ -99,7 +103,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
return;
}
setOwner(sender, offlinePlayer, region);
});
}, this.executor);
}

private void setOwner(@Nonnull CommandSender sender, @Nonnull OfflinePlayer player, GeneralRegion region) {
Expand Down

0 comments on commit 399b166

Please sign in to comment.