Skip to content
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 @@ -11,6 +11,7 @@

import com.cubefury.vendingmachine.command.vending.IVendingSubcommand;
import com.cubefury.vendingmachine.command.vending.SubCmdAdd;
import com.cubefury.vendingmachine.command.vending.SubCmdReload;
import com.cubefury.vendingmachine.command.vending.SubCmdReset;
import com.cubefury.vendingmachine.command.vending.SubCmdSet;

Expand All @@ -22,6 +23,7 @@ public class CommandVending extends CommandBase {
register(new SubCmdAdd());
register(new SubCmdSet());
register(new SubCmdReset());
register(new SubCmdReload());
}

private static void register(IVendingSubcommand cmd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;

import com.cubefury.vendingmachine.VendingMachine;
import com.cubefury.vendingmachine.command.Utils;
import com.cubefury.vendingmachine.storage.NameCache;
import com.cubefury.vendingmachine.trade.CurrencyType;
Expand All @@ -36,7 +35,6 @@ public void execute(ICommandSender sender, String[] args) throws CommandExceptio
boolean allCurrency = false;
CurrencyType type = null;
int amount = 0;
VendingMachine.LOG.info(args.length);

switch (args.length) {
case 2: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.cubefury.vendingmachine.command.vending;

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

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;

import com.cubefury.vendingmachine.handlers.SaveLoadHandler;
import com.cubefury.vendingmachine.network.handlers.NetTradeDbSync;

public class SubCmdReload implements IVendingSubcommand {

@Override
public String getName() {
return "reload";
}

@Override
public String getUsage(ICommandSender sender) {
return "/vending reload database";
}

@Override
public void execute(ICommandSender sender, String[] args) throws CommandException {
if (args.length != 1 || args[0].compareTo("database") != 0) {
sender.addChatMessage(new ChatComponentText("Usage: " + getUsage(sender)));
return;
}

SaveLoadHandler.INSTANCE.reloadDatabase();
NetTradeDbSync.sendDatabase(null, false);

sender.addChatMessage(new ChatComponentText("Reloaded Trade Database"));
}

@Override
public List<String> tabComplete(ICommandSender sender, String[] args) {
switch (args.length) {
case 1: {
return CommandBase
.getListOfStringsFromIterableMatchingLastWord(args, Collections.singletonList("database"));
}
default: {
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,12 @@ public void unloadAll() {
TradeManager.INSTANCE.clearTradeState(null);
}

public void reloadDatabase() {
TradeDatabase.INSTANCE.clear();
TradeManager.INSTANCE.clearTradeState(null);

loadDatabase();
loadTradeState();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void clearTradeState(@Nullable UUID player) {
tradeGroupStates.forEach((uuid, tgs) -> tgs.clearTradeState(player));
clearCurrency(player);
clearNotificationQueue(player);
if (player == null) {
availableTrades.clear();
} else {
availableTrades.remove(player);
}
}

public TradeHistory getTradeState(@Nonnull UUID player, TradeGroup tg) {
Expand Down