Skip to content

Commit

Permalink
Support Ledger 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vacla committed Jun 21, 2024
1 parent e8449e2 commit d6df221
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.15.5+1.20.4] - 2024-06-21

### Added

- Support Ledger 1.3.0

## [1.15.4+1.20.4] - 2024-04-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ project_slug = watson
modrinth_debug = false

#Current and version
mod_version = 1.15.4
mod_version = 1.15.5

#Required malilib version
malilib_version = 0.18.1
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/minemania/watson/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class Reference
public static final String MOD_ID = "watson";
public static final String MOD_NAME = "Watson";
public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID);
public static final int LEDGER_PROTOCOL = 2;
public static final int LEDGER_PROTOCOL = 3;
}
21 changes: 20 additions & 1 deletion src/main/java/eu/minemania/watson/data/LedgerSearch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.minemania.watson.data;

import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;
import java.util.List;

public class LedgerSearch
Expand All @@ -14,8 +15,9 @@ public class LedgerSearch
private final String sources;
private final String timeBefore;
private final String timeAfter;
private final String rolledBack;

public LedgerSearch(List<String> actions, List<String> dimension, List<String> block, List<String> entityType, List<String> item, List<String> tag, int range, String source, String timeBefore, String timeAfter)
public LedgerSearch(List<String> actions, List<String> dimension, List<String> block, List<String> entityType, List<String> item, List<String> tag, int range, String source, String timeBefore, String timeAfter, RolledbackMode rolledBack)
{
this.actions = setTypeList("action",actions);
this.dimensions = setTypeList("world", dimension);
Expand All @@ -27,6 +29,14 @@ public LedgerSearch(List<String> actions, List<String> dimension, List<String> b
this.sources = setTypeString("source", source);
this.timeBefore = setTypeString("before", timeBefore);
this.timeAfter = setTypeString("after", timeAfter);
if (rolledBack == RolledbackMode.IGNORED)
{
this.rolledBack = "";
}
else
{
this.rolledBack = setTypeString("rolledback", rolledBack == RolledbackMode.ON ? "true" : "false");
}
}

private String setTypeString(String type, String parameterContent)
Expand Down Expand Up @@ -120,6 +130,11 @@ public String getTimeBefore()
return timeBefore;
}

public String getRolledBack()
{
return rolledBack;
}

public String getSearchData()
{
StringBuilder search = new StringBuilder();
Expand Down Expand Up @@ -173,6 +188,10 @@ public String getSearchData()
search.append(timeBefore);
search.append(" ");
}
if (!rolledBack.isEmpty())
{
search.append(rolledBack);
}
return search.toString().strip();
}
}
15 changes: 14 additions & 1 deletion src/main/java/eu/minemania/watson/db/LedgerInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.minemania.watson.db;

import eu.minemania.watson.gui.GuiLedger.ButtonListenerCycleTypePacket.LedgerMode;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;

import java.util.List;

Expand All @@ -21,8 +22,9 @@ public class LedgerInfo
private int z;
private LedgerMode ledgerMode;
private int pages;
private RolledbackMode rolledBack;

public LedgerInfo(List<String> actions, List<String> blocks, List<String> dimensions, List<String> entityTypes, List<String> items, List<String> tags, String sources, String timeBefore, String timeAfter, int range, int x, int y, int z, LedgerMode ledgerMode, int pages)
public LedgerInfo(List<String> actions, List<String> blocks, List<String> dimensions, List<String> entityTypes, List<String> items, List<String> tags, String sources, String timeBefore, String timeAfter, int range, int x, int y, int z, LedgerMode ledgerMode, int pages, RolledbackMode rolledBack)
{
this.actions = actions;
this.blocks = blocks;
Expand All @@ -39,6 +41,7 @@ public LedgerInfo(List<String> actions, List<String> blocks, List<String> dimens
this.z = z;
this.ledgerMode = ledgerMode;
this.pages = pages;
this.rolledBack = rolledBack;
}

public List<String> getActions()
Expand Down Expand Up @@ -190,4 +193,14 @@ public void setPages(int pages)
{
this.pages = pages;
}

public RolledbackMode getRolledBack()
{
return rolledBack;
}

public void setRolledBack(RolledbackMode rolledBack)
{
this.rolledBack = rolledBack;
}
}
89 changes: 85 additions & 4 deletions src/main/java/eu/minemania/watson/gui/GuiLedger.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.minemania.watson.data.DataManager;
import eu.minemania.watson.db.LedgerInfo;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerCycleTypePacket.LedgerMode;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;
import eu.minemania.watson.network.ledger.PluginInspectPacketHandler;
import eu.minemania.watson.network.ledger.PluginPurgePacketHandler;
import eu.minemania.watson.network.ledger.PluginRollbackPacketHandler;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class GuiLedger extends GuiBase
protected GuiTextFieldInteger textFieldY;
protected GuiTextFieldInteger textFieldZ;
protected GuiTextFieldInteger textFieldPages;
protected LedgerInfo ledgerInfo = new LedgerInfo(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), "", "", "", 0, 0, 0, 0, LedgerMode.INSPECT, 10);
protected LedgerInfo ledgerInfo = new LedgerInfo(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), "", "", "", 0, 0, 0, 0, LedgerMode.INSPECT, 10, RolledbackMode.IGNORED);

protected GuiLedger()
{
Expand Down Expand Up @@ -192,6 +193,20 @@ public void initGui()
this.addTextField(this.textFieldPages, new PagesTextFieldListener(this));
}

if (ledgerInfo.getLedgerMode() == LedgerMode.SEARCH)
{
y += 30;

label = StringUtils.translate("watson.gui.label.ledger.title.rolledback"); //Rolledback
this.addLabel(x, y, width, 20, 0xFFFFFFFF, label);
offset = this.getStringWidth(label) + 4;
this.addWidget(new WidgetInfoIcon(x + offset, y + 4, Icons.INFO_11, "watson.gui.label.ledger.info.rolledback"));

label = StringUtils.translate("watson.gui.button.ledger.rolledback", ledgerInfo.getRolledBack().getDisplayName());
button = new ButtonGeneric(x + offset + 20, y, buttonWidth, 20, label);
this.addButton(button, new ButtonListenerRolledback(this));
}

y = this.height - 50;

label = StringUtils.translate("watson.gui.button.ledger.ledgermode", ledgerInfo.getLedgerMode().getDisplayName());
Expand Down Expand Up @@ -471,14 +486,15 @@ private void setLedgerInfo()
int z = this.ledgerInfo.getZ();
LedgerMode ledgerMode = this.ledgerInfo.getLedgerMode();
int pages = this.ledgerInfo.getPages();
RolledbackMode rolledBack = this.ledgerInfo.getRolledBack();

LedgerInfo ledgerInfo = new LedgerInfo(actions, blocks, dimension, entityTypes, items, tags, source, timeBefore, timeAfter, range, x, y, z, ledgerMode, pages);
LedgerInfo ledgerInfo = new LedgerInfo(actions, blocks, dimension, entityTypes, items, tags, source, timeBefore, timeAfter, range, x, y, z, ledgerMode, pages, rolledBack);
DataManager.setLedgerInfo(ledgerInfo);
}

private void clearLedgerInfo()
{
LedgerInfo ledgerInfo = new LedgerInfo(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), "", "", "", 0, 0, 0, 0, LedgerMode.INSPECT, 10);
LedgerInfo ledgerInfo = new LedgerInfo(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), "", "", "", 0, 0, 0, 0, LedgerMode.INSPECT, 10, RolledbackMode.IGNORED);
this.ledgerInfo = ledgerInfo;
DataManager.setLedgerInfo(ledgerInfo);
}
Expand Down Expand Up @@ -938,6 +954,7 @@ public void actionPerformedWithButton(ButtonBase button, int mouseButton)
int y = ledgerInfo.getY();
int z = ledgerInfo.getZ();
int pages = ledgerInfo.getPages();
RolledbackMode rolledBack = ledgerInfo.getRolledBack();
MinecraftClient mc = parent.mc;

switch (ledgerInfo.getLedgerMode())
Expand All @@ -946,7 +963,7 @@ public void actionPerformedWithButton(ButtonBase button, int mouseButton)
case PURGE -> new PluginPurgePacketHandler().sendPacket(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, mc);
case ROLLBACK -> new PluginRollbackPacketHandler().sendPacket(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, false, mc);
case RESTORE -> new PluginRollbackPacketHandler().sendPacket(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, true, mc);
case SEARCH -> new PluginSearchPacketHandler().sendPacket(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, pages, mc);
case SEARCH -> new PluginSearchPacketHandler().sendPacket(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, pages, rolledBack, mc);
}
}
}
Expand Down Expand Up @@ -1041,4 +1058,68 @@ public LedgerMode cycle(boolean forward)
}
}
}

public static class ButtonListenerRolledback implements IButtonActionListener
{
private final GuiLedger parent;

public ButtonListenerRolledback(GuiLedger parent)
{
this.parent = parent;
}

@Override
public void actionPerformedWithButton(ButtonBase button, int mouseButton)
{
RolledbackMode mode = parent.ledgerInfo.getRolledBack().cycle(mouseButton == 0);
parent.ledgerInfo.setRolledBack(mode);
parent.initGui();
}

public enum RolledbackMode
{
ON("watson.gui.button.ledger.rolledback.on"),
OFF("watson.gui.button.ledger.rolledback.off"),
IGNORED("watson.gui.button.ledger.rolledback.ignored");

private final String labelKey;

RolledbackMode(String labelKey)
{
this.labelKey = labelKey;
}

public String getLabelKey()
{
return this.labelKey;
}

public String getDisplayName()
{
return StringUtils.translate(this.getLabelKey());
}

public RolledbackMode cycle(boolean forward)
{
int id = this.ordinal();

if (forward)
{
if (++id >= values().length)
{
id = 0;
}
}
else
{
if (--id < 0)
{
id = values().length - 1;
}
}

return values()[id % values().length];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.minemania.watson.Watson;
import eu.minemania.watson.config.Configs;
import eu.minemania.watson.data.LedgerSearch;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
Expand All @@ -28,7 +29,7 @@ public void sendPacket(List<String> action, List<String> dimension, List<String>
{
return;
}
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter);
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, RolledbackMode.IGNORED);
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeString(ledgerSearch.getSearchData());
if(Configs.Generic.DEBUG.getBooleanValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.minemania.watson.Watson;
import eu.minemania.watson.config.Configs;
import eu.minemania.watson.data.LedgerSearch;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
Expand All @@ -28,7 +29,7 @@ public void sendPacket(List<String> action, List<String> dimension, List<String>
{
return;
}
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter);
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, RolledbackMode.IGNORED);
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeBoolean(restore);
packetByteBuf.writeString(ledgerSearch.getSearchData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.minemania.watson.Watson;
import eu.minemania.watson.config.Configs;
import eu.minemania.watson.data.LedgerSearch;
import eu.minemania.watson.gui.GuiLedger.ButtonListenerRolledback.RolledbackMode;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
Expand All @@ -19,11 +20,11 @@ public class PluginSearchPacketHandler

public static final PluginSearchPacketHandler INSTANCE = new PluginSearchPacketHandler();

public void sendPacket(List<String> action, List<String> dimension, List<String> block, List<String> entityType, List<String> item, List<String> tag, int range, String source, String timeBefore, String timeAfter, int pages, MinecraftClient mc)
public void sendPacket(List<String> action, List<String> dimension, List<String> block, List<String> entityType, List<String> item, List<String> tag, int range, String source, String timeBefore, String timeAfter, int pages, RolledbackMode rolledBack, MinecraftClient mc)
{
try
{
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter);
LedgerSearch ledgerSearch = new LedgerSearch(action, dimension, block, entityType, item, tag, range, source, timeBefore, timeAfter, rolledBack);
ClientPlayNetworkHandler packetHandler = mc.getNetworkHandler();
if (packetHandler == null)
{
Expand All @@ -47,6 +48,7 @@ public void sendPacket(List<String> action, List<String> dimension, List<String>
Watson.logger.info("timeAfter: "+ledgerSearch.getTimeAfter());
Watson.logger.info("search: "+ledgerSearch.getSearchData());
Watson.logger.info("pages: "+ pages);
Watson.logger.info("rolledBack: "+ ledgerSearch.getRolledBack());
Watson.logger.info(CHANNEL);
}
ClientPlayNetworking.send(CHANNEL, packetByteBuf);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/watson/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
"watson.gui.button.ledger.purge": "Purge",
"watson.gui.button.ledger.restore": "Restore",
"watson.gui.button.ledger.rollback": "Rollback",
"watson.gui.button.ledger.rolledback": "%s",
"watson.gui.button.ledger.rolledback.on": "On",
"watson.gui.button.ledger.rolledback.off": "Off",
"watson.gui.button.ledger.rolledback.ignored": "Ignored",
"watson.gui.button.ledger.search": "Search",
"watson.gui.button.ledger.submit": "Submit",
"watson.gui.button.ledger.tag": "Tags",
Expand Down Expand Up @@ -147,6 +151,7 @@
"watson.gui.label.ledger.info.coords": "Only used for Inspect.",
"watson.gui.label.ledger.info.pages": "Amount of pages that Ledger will send.",
"watson.gui.label.ledger.info.range": "Range needs to bigger than 1.",
"watson.gui.label.ledger.info.rolledback": "Will only show edits that are rolledback or not or ignored.",
"watson.gui.label.ledger.info.source": "Sources are comma seperated.\nTo invert a source put '!' before the source.\nExamples for a source are 'Annevdl29' and '@tnt'.",
"watson.gui.label.ledger.info.time": "You can specify durations with 's' seconds, 'm' minute, 'h' hour, 'd' day and 'w' week.\nFor example '7w4d31m42s'.",
"watson.gui.label.ledger.title.action": "Action",
Expand All @@ -156,6 +161,7 @@
"watson.gui.label.ledger.title.item": "Item",
"watson.gui.label.ledger.title.pages": "Pages",
"watson.gui.label.ledger.title.range": "Range",
"watson.gui.label.ledger.title.rolledback": "Rolledback",
"watson.gui.label.ledger.title.source": "Source",
"watson.gui.label.ledger.title.tag": "Tag",
"watson.gui.label.ledger.title.time.before": "Time before",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/watson/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
"watson.gui.button.ledger.purge": "Очистить",
"watson.gui.button.ledger.restore": "Восстановить",
"watson.gui.button.ledger.rollback": "Откатить",
"watson.gui.button.ledger.rolledback": "%s",
"watson.gui.button.ledger.rolledback.on": "Вкл",
"watson.gui.button.ledger.rolledback.off": "Выкл",
"watson.gui.button.ledger.rolledback.ignored": "Игнорируется",
"watson.gui.button.ledger.search": "Поиск",
"watson.gui.button.ledger.submit": "Подтвердить",
"watson.gui.button.ledger.tag": "Теги",
Expand Down Expand Up @@ -147,6 +151,7 @@
"watson.gui.label.ledger.info.coords": "Использовать только для проверки",
"watson.gui.label.ledger.info.pages": "Количество страниц, который Ledger будет отправлять",
"watson.gui.label.ledger.info.range": "Диапазон должен быть больше 1",
"watson.gui.label.ledger.info.rolledback": "Будут показаны только те правки, которые были откачены, не откачены или проигнорированы.",
"watson.gui.label.ledger.info.source": "Источники разделяются запятыми.\nЧтобы инвертировать источник, поставьте '!' перед источником.\nПримеры для источника: 'Annevdl29' и '@tnt'",
"watson.gui.label.ledger.info.time": "Вы можете указать продолжительность с помощью 's' секунды, 'm' минут, 'h' час, 'd' день и 'w' неделя.\nНапример: '7w4d31m42s'",
"watson.gui.label.ledger.title.action": "Действие",
Expand All @@ -156,6 +161,7 @@
"watson.gui.label.ledger.title.item": "Предмет",
"watson.gui.label.ledger.title.pages": "Страниц",
"watson.gui.label.ledger.title.range": "Диапазон",
"watson.gui.label.ledger.title.rolledback": "Откат",
"watson.gui.label.ledger.title.source": "Источник",
"watson.gui.label.ledger.title.tag": "Тэг",
"watson.gui.label.ledger.title.time.before": "Время до",
Expand Down

0 comments on commit d6df221

Please sign in to comment.