Notify player how much they earned
Set owner of dropped items so no one else can pick them up
This commit is contained in:
parent
12f37d471e
commit
f7ee3841f7
|
|
@ -0,0 +1,48 @@
|
|||
package com.alttd.fishingevent.commands.fish_subcommands;
|
||||
|
||||
import com.alttd.fishingevent.commands.SubCommand;
|
||||
import com.alttd.fishingevent.points.PointsManagement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Points extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
Component playerName;
|
||||
int points;
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (args.length == 1) {
|
||||
playerName = player.displayName();
|
||||
points = PointsManagement.getInstance().getPoints(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "points";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
if (commandSender.hasPermission(getPermission() + ".others")) {
|
||||
return commandSender.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ import com.alttd.fishingevent.gui.GUI;
|
|||
import com.alttd.fishingevent.points.PointsManagement;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
|
@ -48,9 +50,11 @@ public class SellWindow extends GUI {
|
|||
}
|
||||
|
||||
PointsManagement pointsManagement = PointsManagement.getInstance();
|
||||
UUID uuid = player.getUniqueId();
|
||||
NamespacedKey namespacedKey = optionalNamespacedKey.get();
|
||||
List<ItemStack> itemsToMoveBack = new ArrayList<>();
|
||||
|
||||
int pointsEarned = 0;
|
||||
for (ItemStack content : getInventory().getContents()) {
|
||||
if (content == null) {
|
||||
continue;
|
||||
|
|
@ -59,11 +63,15 @@ public class SellWindow extends GUI {
|
|||
if (points == -1) {
|
||||
itemsToMoveBack.add(content);
|
||||
} else {
|
||||
pointsManagement.addPoints(player.getUniqueId(), points);
|
||||
pointsEarned += points;
|
||||
pointsManagement.addPoints(uuid, points);
|
||||
}
|
||||
}
|
||||
player.sendMiniMessage(Messages.GUI.EARNED_POINTS, TagResolver.resolver(
|
||||
Placeholder.parsed("earned_points", String.valueOf(pointsEarned)),
|
||||
Placeholder.parsed("total_points", String.valueOf(pointsManagement.getPoints(uuid)))));
|
||||
player.getInventory().addItem(itemsToMoveBack.toArray(ItemStack[]::new)).values()
|
||||
.forEach(item -> player.getWorld().dropItem(player.getLocation(), item));
|
||||
.forEach(item -> player.getWorld().dropItem(player.getLocation(), item).setOwner(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user