Add TransferShopsCommand
This commit is contained in:
parent
75c0899298
commit
f12b80b280
|
|
@ -71,7 +71,9 @@ publishing {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly("com.alttd:Galaxy-API:1.20.1-R0.1-SNAPSHOT") {
|
||||
isChanging = true
|
||||
}
|
||||
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
||||
exclude("org.bukkit","bukkit")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.alttd.playershops.commands;
|
|||
import com.alttd.playershops.commands.subcommands.CheckStockCommand;
|
||||
import com.alttd.playershops.commands.subcommands.OpenCommand;
|
||||
import com.alttd.playershops.commands.subcommands.ReloadCommand;
|
||||
import com.alttd.playershops.commands.subcommands.TransferShopsCommand;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
|
@ -34,6 +35,7 @@ public class PlayerShopCommand extends Command {
|
|||
commands.put(Set.of("reload"), new ReloadCommand());
|
||||
commands.put(Set.of("checkstock"), new CheckStockCommand());
|
||||
commands.put(Set.of("open"), new OpenCommand());
|
||||
commands.put(Set.of("transfershops"), new TransferShopsCommand());
|
||||
|
||||
return commands.entrySet().stream()
|
||||
.flatMap(entry -> entry.getKey().stream().map(s -> Map.entry(s, entry.getValue())))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package com.alttd.playershops.commands.subcommands;
|
||||
|
||||
import com.alttd.playershops.PlayerShops;
|
||||
import com.alttd.playershops.commands.PlayerShopCommand;
|
||||
import com.alttd.playershops.commands.PlayerShopCommands;
|
||||
import com.alttd.playershops.commands.Subcommand;
|
||||
import com.alttd.playershops.shop.PlayerShop;
|
||||
import com.alttd.playershops.utils.ShopUtil;
|
||||
import com.alttd.playershops.utils.Util;
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class TransferShopsCommand implements Subcommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String subCommand, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMiniMessage("<red>Only players can use this command.", null);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1 && args.length != 2) {
|
||||
player.sendMiniMessage("<red>Invalid command syntax, use /transfershops <uuid> <newplayer>", null);
|
||||
return false;
|
||||
}
|
||||
UUID oldUUID = UUID.fromString(args[0]);
|
||||
Player newShopOwner = Bukkit.getPlayer(args[1]);
|
||||
if (newShopOwner == null) {
|
||||
player.sendMiniMessage("<red>" + args[1] + " is not online and has to be online for this process.", null);
|
||||
return false;
|
||||
}
|
||||
List<PlayerShop> playerShops = PlayerShops.getInstance().getShopHandler().getShops(oldUUID);
|
||||
sender.sendMiniMessage("<red>Starting the transfer process now, this might lag the server.", null);
|
||||
for (PlayerShop playerShop : playerShops) {
|
||||
playerShop.setOwner(newShopOwner);
|
||||
}
|
||||
newShopOwner.sendMiniMessage(playerShops.size() + " have been transferred to you.", null);
|
||||
sender.sendMiniMessage(playerShops.size() + " have been transferred to " + args[1] + ".", null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(final CommandSender sender, final String subCommand, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
return PlayerShops.getInstance().getShopHandler().getShopOwners().stream().map(uuid -> toString()).toList();
|
||||
} else if (args.length == 2) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -140,6 +140,7 @@ public class PlayerShop {
|
|||
public void setOwner(Player player) {
|
||||
ownerUUID = player.getUniqueId();
|
||||
ownerName = player.getName();
|
||||
update();
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user