Skip to content
This repository was archived by the owner on Jun 22, 2022. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs = -Xmx1G
#Fabric properties
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.2
loader_version=0.13.3

#Mod properties
mod_version = 2.2.2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.codeutilities.mod;

import io.github.codeutilities.mod.config.Config;
import io.github.codeutilities.sys.SimplePlot;
import io.github.codeutilities.sys.file.FileUtil;
import io.github.codeutilities.sys.networking.State;
import net.fabricmc.loader.api.FabricLoader;

import java.nio.file.Path;
import java.util.ArrayList;

public class PlotHistoryRecorder {
private static final Path FILE_PATH = FabricLoader.getInstance().getGameDir().resolve("CodeUtilities/history.sff"); // sff means stupid file format

private static String lastPlot = null;
public static void record(State.Plot statePlot) {
if(statePlot == null) return;
if(!Config.getBoolean("plotHistory")) return;
if(lastPlot != null && lastPlot.equals(statePlot.getId())) return;

SimplePlot plot = SimplePlot.fromStatePlot(statePlot);
lastPlot = plot.getId();

String fileContents = FileUtil.readFirstLine(FILE_PATH);

ArrayList<SimplePlot> plots = SimplePlot.toPlotList(fileContents);
while(plots.size() > Config.getInteger("plotHistoryLength")) {
plots.remove(0);
}
plots.add(0, plot);
FileUtil.writeStringToFile(FILE_PATH, SimplePlot.serializePlots(plots));
}

public static ArrayList<SimplePlot> getHistory() {
return SimplePlot.toPlotList(FileUtil.readFirstLine(FILE_PATH));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@
import io.github.codeutilities.mod.commands.impl.item.UnpackCommand;
import io.github.codeutilities.mod.commands.impl.item.template.SendTemplateCommand;
import io.github.codeutilities.mod.commands.impl.item.template.WebviewCommand;
import io.github.codeutilities.mod.commands.impl.other.CalcCommand;
import io.github.codeutilities.mod.commands.impl.other.CodeUtilitiesCommand;
import io.github.codeutilities.mod.commands.impl.other.NBSCommand;
import io.github.codeutilities.mod.commands.impl.other.NBSSearchCommand;
import io.github.codeutilities.mod.commands.impl.other.NodeCommand;
import io.github.codeutilities.mod.commands.impl.other.PJoinCommand;
import io.github.codeutilities.mod.commands.impl.other.PartnerBracketCommand;
import io.github.codeutilities.mod.commands.impl.other.PlotsCommand;
import io.github.codeutilities.mod.commands.impl.other.QueueCommand;
import io.github.codeutilities.mod.commands.impl.other.SchemCommand;
import io.github.codeutilities.mod.commands.impl.other.SearchCommand;
import io.github.codeutilities.mod.commands.impl.other.*;
import io.github.codeutilities.mod.commands.impl.text.ActionbarCommand;
import io.github.codeutilities.mod.commands.impl.text.ColorCommand;
import io.github.codeutilities.mod.commands.impl.text.ColorsCommand;
Expand Down Expand Up @@ -69,7 +59,8 @@ public void load() {
new SubTitleCommand(),
new ActionbarCommand(),
new CalcCommand(),
new CustomTextureCommand()
new CustomTextureCommand(),
new HistoryCommand()
);

if (Config.getBoolean("dfCommands")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package io.github.codeutilities.mod.commands.impl.other;


import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.github.codeutilities.mod.PlotHistoryRecorder;
import io.github.codeutilities.mod.commands.Command;
import io.github.codeutilities.mod.commands.arguments.ArgBuilder;
import io.github.codeutilities.mod.config.Config;
import io.github.codeutilities.sys.SimplePlot;
import io.github.codeutilities.sys.player.chat.ChatType;
import io.github.codeutilities.sys.player.chat.ChatUtil;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.*;

import java.util.ArrayList;

public class HistoryCommand extends Command {

@Override
public void register(MinecraftClient mc, CommandDispatcher<FabricClientCommandSource> cd) {
LiteralArgumentBuilder<FabricClientCommandSource> cmd = ArgBuilder.literal("history")
.executes(ctx -> {
if(!Config.getBoolean("plotHistory")) {
ChatUtil.sendMessage(new LiteralText("Plot history is not enabled in the settings."), ChatType.FAIL);
return 1;
}

ArrayList<SimplePlot> plots = PlotHistoryRecorder.getHistory();
if(plots.size() == 0) {
ChatUtil.sendMessage(new LiteralText("no plots in the history."), ChatType.FAIL);
return 1;
}

ChatUtil.sendMessage(
new LiteralText("\n⏪")
.styled(style -> style.withColor(TextColor.fromRgb(0x1f9947))).append(
new LiteralText(" CodeUtilities Plot History ")
.styled(style -> style.withColor(TextColor.fromRgb(0x33ffa7))).append(
new LiteralText("⏩")
.styled(style -> style.withColor(TextColor.fromRgb(0x1f9947)))
)), null);

for (SimplePlot entry : plots) {
MutableText entrymsg = new LiteralText(entry.getName())
.styled(style -> style.withColor(TextColor.fromRgb(0x00bbff)
).withClickEvent(
new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
"/join " + entry.getId()
))
.withHoverEvent(
new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new LiteralText("Click to join!").styled(style2 -> style2.withColor(TextColor.fromRgb(0xaaaaaa)))
)
)
).append(
new LiteralText(" - ").styled(style -> style.withColor(TextColor.fromRgb(0x555555))).append(
new LiteralText(entry.getId()).styled(style -> style.withColor(TextColor.fromRgb(0xaaaaaa)))
.append(
new LiteralText(" by " + entry.getOwner()).styled(style -> style.withColor(TextColor.fromRgb(0x555555))))));
ChatUtil.sendMessage(entrymsg, null);
}

return 1;
});
cd.register(cmd);
}

@Override
public String getDescription() {
return "[blue]/history[reset]\n"
+ "\n"
+ "lists your recently joined plots.";
}

@Override
public String getName() {
return "/history";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void initialize() {
quickNum.register(new DoubleSetting("quicknumTertiaryAmount", 0.1));
this.register(quickNum);

// Plot History
ConfigSubGroup plotHistory = new ConfigSubGroup("plotHistory");
plotHistory.register(new BooleanSetting("plotHistory", true));
plotHistory.register(new IntegerSetting("plotHistoryLength", 20));
this.register(plotHistory);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.codeutilities.mod.features.social.chat.message.checks;

import io.github.codeutilities.mod.PlotHistoryRecorder;
import io.github.codeutilities.mod.features.social.chat.message.Message;
import io.github.codeutilities.mod.features.social.chat.message.MessageCheck;
import io.github.codeutilities.mod.features.social.chat.message.MessageType;
Expand All @@ -22,6 +23,8 @@ public boolean check(Message message, String stripped) {

@Override
public void onReceive(Message message) {
DFInfo.setCurrentState(State.fromLocate(message));
State state = State.fromLocate(message);
DFInfo.setCurrentState(state);
PlotHistoryRecorder.record(state.getPlot());
}
}
59 changes: 59 additions & 0 deletions src/main/java/io/github/codeutilities/sys/SimplePlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.codeutilities.sys;

import io.github.codeutilities.sys.networking.State;

import java.util.ArrayList;

public class SimplePlot {
private final String id;
private final String name;
private final String owner;

public SimplePlot(String id, String name, String owner) {
this.id = id;
this.name = name;
this.owner = owner;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getOwner() {
return owner;
}

public static SimplePlot fromStatePlot(State.Plot plot) {
return new SimplePlot(plot.getId(), plot.getName().replaceAll("[,;]", "?"), plot.getOwner());
}

@Override
public String toString() {
return id + ";" + name + ";" + owner;
}

public static ArrayList<SimplePlot> toPlotList(String serialized) {
String[] serializedPlots = serialized.length() == 0 ? null : serialized.split(",");
ArrayList<SimplePlot> plots = new ArrayList<>();
if(serializedPlots == null)
return plots;

for(String serializedPlot : serializedPlots) {
String[] props = serializedPlot.split(";");
plots.add(new SimplePlot(props[0], props[1], props[2]));
}
return plots;
}

public static String serializePlots(ArrayList<SimplePlot> plots) {
StringBuilder builder = new StringBuilder();
for(SimplePlot plot : plots) {
builder.append(",").append(plot.toString());
}
return builder.toString().replaceAll("^,", "");
}
}
39 changes: 38 additions & 1 deletion src/main/java/io/github/codeutilities/sys/file/FileUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.github.codeutilities.sys.file;

import java.io.IOException;
import io.github.codeutilities.CodeUtilities;
import org.apache.logging.log4j.Level;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileUtil {
Expand All @@ -11,4 +15,37 @@ public static String readFile(String path, Charset encoding)
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}


public static String readFirstLine(Path path) {
File file = path.toFile();

try {
if(!file.exists()) {
boolean result = file.createNewFile();
CodeUtilities.log(Level.INFO, path + " does not exist. creating it.");
if(!result)
CodeUtilities.log(Level.INFO, "failed creating " + path);

}

String contents = Files.readString(path);

return contents == null ? "" : contents;
} catch(IOException exception) {
CodeUtilities.log(Level.WARN, "Failed to read " + path);
exception.printStackTrace();
return "";
}
}

public static void writeStringToFile(Path path, String content) {
try {
Files.writeString(path, content);
} catch (IOException e) {
CodeUtilities.log(Level.WARN, "Failed writing to " + path);
e.printStackTrace();
}
}

}
11 changes: 9 additions & 2 deletions src/main/resources/assets/codeutilities/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,12 @@
"key.codeutilities.node3": "Node 3",
"key.codeutilities.node4": "Node 4",
"key.codeutilities.node5": "Node 5",
"key.codeutilities.node_beta": "Node Beta"
}
"key.codeutilities.node_beta": "Node Beta",

"config.codeutilities.subcategory.misc_plotHistory": "Plot Verlauf",
"config.codeutilities.subcategory.misc_plotHistory.tooltip": "Verlauf von kürzlich betretenen plots.",
"config.codeutilities.option.plotHistory.tooltip": "dieses feature aktivieren.",
"config.codeutilities.option.plotHistory": "Aktiviert",
"config.codeutilities.option.plotHistoryLength": "Maximale Plots",
"config.codeutilities.option.plotHistoryLength.tooltip": "Maximale anzahl an plots im Plot Verlauf."
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/codeutilities/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@
"config.codeutilities.option.quicknumTertiaryAmount": "Secondary Amount",
"config.codeutilities.option.quicknumTertiaryAmount.tooltip": "Change how much a scroll changes the number. (When holding SHIFT)",

"config.codeutilities.subcategory.misc_plotHistory": "Recent Plots History",
"config.codeutilities.subcategory.misc_plotHistory.tooltip": "History of recent plots you joined.",
"config.codeutilities.option.plotHistory.tooltip": "Enable this feature.",
"config.codeutilities.option.plotHistory": "Enabled",
"config.codeutilities.option.plotHistoryLength": "Maximum Plots",
"config.codeutilities.option.plotHistoryLength.tooltip": "How many plots can be in the history at a time.",

"config.codeutilities.option.chestToolTip": "Chest Tooltip",
"config.codeutilities.option.chestToolTip.tooltip": "Display chest params when you are in dev",
"config.codeutilities.option.chestToolTipType": "Chest Tooltip Style",
Expand Down