use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.
the class ChestShopMod method suggestSell.
private CompletableFuture<Suggestions> suggestSell(CommandContext<ClientCommandSource> context, SuggestionsBuilder suggestionsBuilder) {
ChestShopItemNames itemNameMap = EdenClient.getMod(DataFetcher.class).getChestShopItemNames();
shops.values().forEach(s -> s.stream().filter(ChestShopEntry::canSell).map(entry -> itemNameMap.getLongName(entry.getItem())).filter(Objects::nonNull).forEach(suggestionsBuilder::suggest));
return suggestionsBuilder.buildFuture();
}
use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.
the class WorldEditReplaceHelper method registerCommand.
private void registerCommand(String command) {
LiteralArgumentBuilder<ClientCommandSource> node = literal(command);
node.then(literal("replace").then(argument("from", StringArgumentType.word()).suggests(this::suggestValidBlocks).then(argument("to", StringArgumentType.word()).suggests(this::suggestValidBlocks).executes(c -> {
Optional<Block> fromBlockOpt = Registry.BLOCK.getOrEmpty(new Identifier(c.getArgument("from", String.class)));
Optional<Block> toBlockOpt = Registry.BLOCK.getOrEmpty(new Identifier(c.getArgument("to", String.class)));
if (fromBlockOpt.isEmpty() || toBlockOpt.isEmpty()) {
sendModMessage("One of your block-inputs doesn't exist.");
return 0;
}
Block fromBlock = fromBlockOpt.get();
Block toBlock = toBlockOpt.get();
if (fromBlock.equals(toBlock)) {
sendModMessage("Both input-blocks can't be the same!");
return 0;
}
String[] currentOperation = new String[] { getBlockIDFromBlock(toBlock), getBlockIDFromBlock(fromBlock) };
undoCommandStack.add(currentOperation);
return replaceCommandRequest(fromBlock, toBlock, delay, true);
}))));
node.then(literal("undo").executes(c -> {
if (undoCommandStack.size() == 0) {
sendModMessage("Nothing left to undo.");
return 0;
}
replaceUndoRequest(Registry.BLOCK.get(new Identifier(undoCommandStack.peek()[0])), Registry.BLOCK.get(new Identifier(undoCommandStack.peek()[1])), delay);
redoCommandStack.add(new String[] { undoCommandStack.peek()[1], undoCommandStack.peek()[0] });
undoCommandStack.pop();
return 1;
}));
node.then(literal("redo").executes(c -> {
if (redoCommandStack.size() == 0) {
sendModMessage("Nothing left to redo.");
return 0;
}
replaceRedoRequest(Registry.BLOCK.get(new Identifier(redoCommandStack.peek()[0])), Registry.BLOCK.get(new Identifier(redoCommandStack.peek()[1])), delay);
undoCommandStack.add(new String[] { redoCommandStack.peek()[1], redoCommandStack.peek()[0] });
redoCommandStack.pop();
return 1;
}));
node.then(literal("delay").then(argument("delay", IntegerArgumentType.integer(0, 40)).executes(c -> {
this.delay = c.getArgument("delay", Integer.class);
sendModMessage(ChatColor.GOLD + "Set delay to " + ChatColor.AQUA + delay + ChatColor.GOLD + " ticks.");
return 1;
})));
node.then(literal("togglemessages").executes(c -> {
ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
entityPlayer.sendChatMessage("/eignoremessage predefined worldedit");
return 1;
}));
register(node, "The WorldEditReplaceHelper helps you replace blocks that have specific properties which normal WorldEdit doesn't take into consideration when replacing blocks.", "Blocks like stairs, slabs, panes, walls, trapdoors, etc. can be replaced by other blocks of their type with their properties (waterlogged, shape, direction, etc.) unaffected.");
}
use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.
the class ClientPlayerMixin method sendMessage.
@Inject(at = @At("HEAD"), method = "sendChatMessage", cancellable = true)
void sendMessage(String message, CallbackInfo ci) {
SendChatMessageCallback.EVENT.invoker().sendMessage(message);
if (message.length() < 2 || !message.startsWith("/"))
return;
if (!CommandManager.isClientSideCommand(message.substring(1).split(" ")[0]))
return;
CommandManager.execute(message.substring(1), new ClientCommandSource(networkHandler, client));
ci.cancel();
}
use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.
the class ChestShopMod method suggestBuy.
private CompletableFuture<Suggestions> suggestBuy(CommandContext<ClientCommandSource> context, SuggestionsBuilder suggestionsBuilder) {
ChestShopItemNames itemNameMap = EdenClient.getMod(DataFetcher.class).getChestShopItemNames();
shops.values().forEach(s -> s.stream().filter(ChestShopEntry::canBuy).map(entry -> itemNameMap.getLongName(entry.getItem())).filter(Objects::nonNull).forEach(suggestionsBuilder::suggest));
return suggestionsBuilder.buildFuture();
}
use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.
the class ChestShopMod method registerCommand.
private void registerCommand(String name) {
LiteralArgumentBuilder<ClientCommandSource> node = literal(name);
node.then(literal("clear").executes(c -> {
shops.clear();
sendModMessage("Cleared ChestShop entries.");
return 1;
}));
node.then(literal("updateshops").executes(c -> {
var shops = EdenClient.getMod(DataFetcher.class).getPlayerWarps().getShops();
TaskManager tm = new TaskManager((shops.size() + 2) * 120);
sendModMessage(ChatColor.GOLD + "Teleporting to all player warps, this will take about " + ChatColor.AQUA + (shops.size() * 6) + ChatColor.GOLD + " seconds.");
int count = shops.size();
AtomicInteger i = new AtomicInteger(1);
for (String shop : shops.keySet()) {
tm.then(new RunnableTask(() -> PlayerUtils.messageC2S("/pw " + shop)));
// wait for chunks to load
tm.then(new WaitForTicksTask(120));
tm.then(new RunnableTask(() -> sendModMessage(ChatColor.GOLD + "Shop " + ChatColor.AQUA + i.getAndIncrement() + ChatColor.GOLD + "/" + ChatColor.AQUA + count + ChatColor.GOLD + " | " + ChatColor.AQUA + ((count - i.get() + 1) * 5) + ChatColor.GOLD + " seconds left")));
tm.then(new RunnableTask(() -> checkForShops(PlayerUtils.getPlayer(), 8)));
}
tm.start();
return 1;
}));
node.then(literal("list").executes(c -> {
int sum = shops.values().stream().mapToInt(Set::size).sum();
if (sum < 20)
shops.values().forEach(sl -> sl.stream().map(cs -> cs.getItem() + " B" + cs.getBuyPricePerItem() + ":" + cs.getSellPricePerItem() + "S").forEach(PlayerUtils::sendModMessage));
sendModMessage(String.format("There are %s ChestShops stored.", sum));
return 1;
}));
node.then(literal("toggle").executes(c -> {
searchEnabled = !searchEnabled;
sendModMessage("ChestShop search " + (searchEnabled ? "enabled" : "disabled"));
return 1;
}));
node.then(literal("sell").then(argument("item", StringArgumentType.greedyString()).suggests(this::suggestSell).executes(c -> {
sendModMessage("Sell: ");
String item = EdenClient.getMod(DataFetcher.class).getChestShopItemNames().getShortName(c.getArgument("item", String.class));
List<ChestShopEntry> matching = new ArrayList<>();
shops.values().forEach(m -> m.stream().filter(ChestShopEntry::canSell).filter(e -> e.getItem().equals(item)).forEach(matching::add));
matching.stream().sorted(Comparator.comparingDouble(ChestShopEntry::getSellPricePerItem).reversed()).limit(10).map(cs -> {
Optional<Map.Entry<String, Vec3i>> opw = getNearestPlayerWarp(cs.getPos());
Style style = Style.EMPTY.withColor(Formatting.GOLD);
Vec3i pos = cs.getPos();
String cmd = EdenClient.getMod(GetTo.class).getCommandTo(pos);
Text hoverText = new LiteralText(opw.isPresent() ? opw.get().getKey() : "click me!").formatted(Formatting.GOLD);
style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
style = style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd));
return new LiteralText(cs.formattedString(false)).setStyle(style);
}).forEach(PlayerUtils::sendModMessage);
return 1;
})));
node.then(literal("buy").then(argument("item", StringArgumentType.greedyString()).suggests(this::suggestBuy).executes(c -> {
String item = EdenClient.getMod(DataFetcher.class).getChestShopItemNames().getShortName(c.getArgument("item", String.class));
sendModMessage("Buy: ");
List<ChestShopEntry> matching = new ArrayList<>();
shops.values().forEach(m -> m.stream().filter(ChestShopEntry::canBuy).filter(e -> e.getItem().equals(item)).forEach(matching::add));
matching.stream().sorted(Comparator.comparingDouble(ChestShopEntry::getBuyPricePerItem)).limit(10).map(cs -> {
Optional<Map.Entry<String, Vec3i>> opw = getNearestPlayerWarp(cs.getPos());
Style style = Style.EMPTY.withColor(Formatting.GOLD);
Vec3i pos = cs.getPos();
String cmd = EdenClient.getMod(GetTo.class).getCommandTo(pos);
Text hoverText = new LiteralText(opw.isPresent() ? opw.get().getKey() : "click me!").formatted(Formatting.GOLD);
style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
style = style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd));
return new LiteralText(cs.formattedString(true)).setStyle(style);
}).forEach(PlayerUtils::sendModMessage);
return 1;
})));
node.then(literal("exploitable").executes(c -> {
List<String> exploitableItems = getExploitableShopsText();
File folder = new File(EdenClient.getDataFolder(), "ChestShop_Exploitable");
if (!folder.exists())
folder.mkdirs();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
File file = new File(folder, formatter.format(new Date()) + ".txt");
try {
if (!file.exists())
if (!file.createNewFile())
return -1;
} catch (IOException e) {
e.printStackTrace();
}
try (FileWriter writer = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(writer)) {
for (String foundDisparity : exploitableItems) {
bw.write(foundDisparity);
bw.newLine();
}
sendModMessage(new LiteralText("Wrote file without errors. Saved at ").formatted(Formatting.GOLD).append(new LiteralText(file.getAbsolutePath()).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, file.getAbsolutePath())))));
} catch (IOException e) {
sendModMessage("Error while writing file. See console for more info.");
e.printStackTrace();
}
return 1;
}));
node.then(literal("writeshopstofile").executes(c -> {
Map<String, List<ChestShopEntry>> buyEntries = getBuyShops();
Map<String, List<ChestShopEntry>> sellEntries = getSellShops();
List<String> lines = new ArrayList<>();
List<String> keys = new ArrayList<>();
keys.addAll(buyEntries.keySet());
keys.addAll(sellEntries.keySet());
keys = keys.stream().sorted(Comparator.comparing(s -> s)).collect(Collectors.toList());
ChestShopItemNames itemNameMap = EdenClient.getMod(DataFetcher.class).getChestShopItemNames();
for (String key : keys) {
List<ChestShopEntry> currentBuyEntries = buyEntries.get(key);
if (currentBuyEntries != null)
currentBuyEntries = currentBuyEntries.stream().sorted(Comparator.comparingDouble(ChestShopEntry::getBuyPricePerItem)).collect(Collectors.toList());
else
currentBuyEntries = new ArrayList<>();
List<ChestShopEntry> currentSellEntries = sellEntries.get(key);
if (currentSellEntries != null)
currentSellEntries = currentSellEntries.stream().sorted(Comparator.comparingDouble(ChestShopEntry::getSellPricePerItem).reversed()).collect(Collectors.toList());
else
currentSellEntries = new ArrayList<>();
String originalName = itemNameMap.getLongName(key);
if (originalName == null)
originalName = key;
lines.add(originalName + ":");
if (currentBuyEntries.size() > 0) {
lines.add("Buy:");
currentBuyEntries.forEach(e -> lines.add(String.format("%-15s [%6d, %3d, %6d] for %.2f$/item", e.getOwner(), e.getPos().getX(), e.getPos().getY(), e.getPos().getZ(), e.getBuyPricePerItem())));
}
if (currentSellEntries.size() > 0) {
lines.add("Sell:");
currentSellEntries.forEach(e -> lines.add(String.format("%-15s [%6d, %3d, %6d] for %.2f$/item", e.getOwner(), e.getPos().getX(), e.getPos().getY(), e.getPos().getZ(), e.getSellPricePerItem())));
}
lines.add("");
}
File folder = new File(EdenClient.getDataFolder(), "ChestShopModEntries");
if (!folder.exists())
folder.mkdirs();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
Date date = new Date();
File file = new File(folder, formatter.format(date) + ".txt");
try {
if (!file.exists())
if (!file.createNewFile())
return -1;
} catch (IOException e) {
e.printStackTrace();
}
try (FileWriter writer = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(writer)) {
for (String line : lines) {
if (line == null) {
bw.write("null:");
continue;
}
bw.write(line);
bw.newLine();
}
sendModMessage(new LiteralText("Wrote file without errors. Saved at ").formatted(Formatting.GOLD).append(new LiteralText(file.getAbsolutePath()).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to copy path"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, file.getAbsolutePath())))));
} catch (IOException e) {
sendModMessage("Error while writing file. See console for more info.");
e.printStackTrace();
}
return 1;
}));
node.executes(c -> {
sendModMessage("/chestshop sell itemtype");
sendModMessage("/chestshop buy itemtype");
sendModMessage("/chestshop toggle");
sendModMessage("/chestshop clear");
sendModMessage("/chestshop list");
return 1;
});
register(node, "ChestShop item find/sell/buy helper.", "Automatically stores all ChestShops in all chunks you load. You can search specific items to get their buy/sell options. Other features include automatic searching for shops which sell items cheaper than other shops buy them, writing all shops to a file and automatically updating all shops via their playerwarps.");
}
Aggregations