Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double chest issues #35

Merged
merged 10 commits into from
Jun 4, 2024
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 @@ -119,7 +119,10 @@ public void onRightClick(Sign sign, Player player, PlayerCraft craft) {
(int) Math.ceil(e.getRemaining().get(blob))));
}
return;
} catch (ProtoRepair.ProtoRepairExpiredException | ProtoRepair.ProtoRepairLocationException | ProtoRepair.ItemRemovalException e) {
} catch (ProtoRepair.ItemRemovalException e) {
player.sendMessage(I18nSupport.getInternationalisedString("Repair - Removal exception"));
return;
} catch (ProtoRepair.ProtoRepairExpiredException | ProtoRepair.ProtoRepairLocationException e) {
// Expired or wrong location, go back to first click
// ItemRemovalException shouldn't happen, but go back to first click regardless
createProtoRepair(sign, uuid, player, craft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

Expand All @@ -28,7 +30,8 @@

public class RepairInventoryCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s,
@NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(
MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Repair - Must Be Player"));
Expand Down Expand Up @@ -63,18 +66,24 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
List<RepairBlob> keys = new LinkedList<>(inventory.getKeySet());
keys.sort((key1, key2) -> ((int) (inventory.get(key2) - inventory.get(key1))));

TopicPaginator paginator = new TopicPaginator(I18nSupport.getInternationalisedString("Inventory - Inventory Header"), false);
TopicPaginator paginator = new TopicPaginator(
I18nSupport.getInternationalisedString("Inventory - Inventory Header"), false);
for (RepairBlob key : keys) {
paginator.addLine(buildLine(key, inventory.get(key)));
}

if (paginator.isEmpty()) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Inventory - Empty Craft"));
player.sendMessage(
MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Inventory - Empty Craft"));
return true;
}

if (!paginator.isInBounds(page)) {
player.sendMessage(MOVECRAFT_COMMAND_PREFIX + net.countercraft.movecraft.localisation.I18nSupport.getInternationalisedString("Paginator - Page Number") + " " + page + " " + net.countercraft.movecraft.localisation.I18nSupport.getInternationalisedString("Paginator - Exceeds Bounds"));
player.sendMessage(MOVECRAFT_COMMAND_PREFIX
+ net.countercraft.movecraft.localisation.I18nSupport
.getInternationalisedString("Paginator - Page Number")
+ " " + page + " " + net.countercraft.movecraft.localisation.I18nSupport
.getInternationalisedString("Paginator - Exceeds Bounds"));
return true;
}

Expand All @@ -100,7 +109,10 @@ private RepairCounter sumInventory(Craft craft) {
if (!(state instanceof Container))
continue;

for (ItemStack item : ((Container) state).getInventory().getContents()) {
Inventory inventory = ((Container) state).getInventory();
if (inventory instanceof DoubleChestInventory)
continue; // Don't take from double chests
for (ItemStack item : inventory.getContents()) {
if (item == null)
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.Sign;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -168,6 +169,8 @@ public Pair<RepairCounter, Map<MovecraftLocation, Counter<Material>>> checkMater

private Counter<Material> sumInventory(Inventory inventory) {
Counter<Material> result = new Counter<>();
if (inventory instanceof DoubleChestInventory)
return result; // Don't take from double chests
for (ItemStack item : inventory.getContents()) {
if (item == null)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Repair\ -\ Saved\ States=Saved States
Repair\ -\ Ongoing\ Repairs=Ongoing repairs
Repair\ -\ No\ Repairs=None found
Repair\ -\ Must\ Be\ Player=You must be a player to check the list of saved states.
Repair\ -\ Removal\ exception=ERROR TAKING MATERAILS - Check that you don't have any double chests.
Command\ -\ Bar\ Set=Repair Bar now set to
Economy\ -\ Not\ Enough\ Money=You do not have enough money
Inventory\ -\ Inventory\ Header=Inventory
Expand Down
Loading