Skip to content

Commit

Permalink
sync config and alert disallowed remove/modify
Browse files Browse the repository at this point in the history
  • Loading branch information
topi-banana committed Jan 10, 2025
1 parent a64917f commit 3f3b813
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/vulpeus/kyoyu/KyoyuConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class KyoyuConfig {

public static KyoyuConfig fromJson(String json) {
Gson gson = new Gson();
Kyoyu.LOGGER.info("{}", json);
return gson.fromJson(json, KyoyuConfig.class);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vulpeus/kyoyu/client/KyoyuClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public KyoyuClient(String serverVersion, KyoyuConfig serverConfig) {
this.serverVersion = serverVersion;
this.serverConfig = serverConfig;
}
private String serverVersion() {
public String serverVersion() {
return serverVersion;
}
private KyoyuConfig serverConfig() {
public KyoyuConfig serverConfig() {
return serverConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import fi.dy.masa.malilib.util.GuiUtils;
import fi.dy.masa.malilib.util.InfoUtils;
import fi.dy.masa.malilib.util.StringUtils;
import net.minecraft.client.Minecraft;

//? if >=1.20 {
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -58,7 +59,7 @@ public Explorer_WidgetListEntry(int x, int y, int width, int height, KyoyuPlacem
textWidth = getStringWidth(text) + 10;
endX -= textWidth + 2;
button = new ButtonGeneric(endX, buttonY, textWidth, buttonHeight, text);
button.setEnabled(true);
button.setEnabled(kyoyuClient.serverConfig().isAllowedRemove(Minecraft.getInstance().player.getName().getString()));
listener = new ButtonListener(ButtonListener.Type.REMOVE, this);
addButton(button, listener);

Expand Down Expand Up @@ -141,15 +142,14 @@ public void actionPerformedWithButton(ButtonBase button, int arg1) {
if (type == null) {
return;
}
button.setEnabled(false);
button.setEnabled(!this.type.onAction(entry));
Kyoyu.LOGGER.info("{} on click {}", entry.kyoyuPlacement.getName(), type.name());
this.type.onAction(entry);
}

public enum Type {
MATERIAL_LIST() {
@Override
void onAction(Explorer_WidgetListEntry entry) {
boolean onAction(Explorer_WidgetListEntry entry) {
LitematicaSchematic schematic = SchematicHolder.getInstance().getOrLoad(entry.kyoyuPlacement.getFile());
Set<String> regionNames= schematic.getAreas().keySet();
MaterialListSchematic materialList = new MaterialListSchematic(schematic, regionNames, true);
Expand All @@ -159,11 +159,12 @@ void onAction(Explorer_WidgetListEntry entry) {
gui.setTitle(StringUtils.translate("litematica.gui.title.material_list.select_schematic_regions", schematic.getMetadata().getName()));
gui.setParent(GuiUtils.getCurrentScreen());
GuiBase.openGui(gui);
return true;
}
},
LOAD() {
@Override
void onAction(Explorer_WidgetListEntry entry) {
boolean onAction(Explorer_WidgetListEntry entry) {

SchematicPlacement placement = SchematicPlacement.createFor(
SchematicHolder.getInstance().getOrLoad(entry.kyoyuPlacement.getFile()),
Expand All @@ -175,28 +176,31 @@ void onAction(Explorer_WidgetListEntry entry) {
((ISchematicPlacement) placement).kyoyu$updateFromKyoyuPlacement(entry.kyoyuPlacement);
((ISchematicPlacement) placement).kyoyu$setKyoyuId(entry.kyoyuPlacement.getUuid());
DataManager.getSchematicPlacementManager().addSchematicPlacement(placement, true);
return true;
}
},
DOWNLOAD() {
@Override
void onAction(Explorer_WidgetListEntry entry) {
boolean onAction(Explorer_WidgetListEntry entry) {
FileRequestPacket fileRequestPacket = new FileRequestPacket(entry.kyoyuPlacement.getUuid());
KyoyuPacketManager.sendC2S(fileRequestPacket);
return true;
}
},
REMOVE() {
@Override
void onAction(Explorer_WidgetListEntry entry) {
boolean onAction(Explorer_WidgetListEntry entry) {
if (!GuiBase.isShiftDown()) {
InfoUtils.showGuiOrInGameMessage(Message.MessageType.ERROR, "kyoyu.error.remove_without_shift");
return;
return false;
}
RemovePlacementPacket removePlacementPacket = new RemovePlacementPacket(entry.kyoyuPlacement.getUuid());
KyoyuPacketManager.sendC2S(removePlacementPacket);
return true;
}
};

abstract void onAction(Explorer_WidgetListEntry entry);
abstract boolean onAction(Explorer_WidgetListEntry entry);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ClientPacketListenerMixin {
@Inject(method = "handleLogin", at = @At("RETURN"))
private void onJoin(ClientboundLoginPacket clientboundLoginPacket, CallbackInfo ci) {
Kyoyu.LOGGER.info("Login to Server");
KyoyuPacketManager.sendC2S(new HandshakePacket(Kyoyu.MOD_VERSION));
KyoyuPacketManager.sendC2S(new HandshakePacket(Kyoyu.MOD_VERSION, Kyoyu.CONFIG));
}
}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement;
import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager;
import fi.dy.masa.litematica.schematic.placement.SubRegionPlacement;
import fi.dy.masa.malilib.gui.Message;
import fi.dy.masa.malilib.util.InfoUtils;
import fi.dy.masa.malilib.util.JsonUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -127,7 +130,14 @@ public class SchematicPlacementMixin implements ISchematicPlacement {
@Unique
private void onModified() {
if (this.ignore_update) return;
if (KyoyuClient.getInstance() == null) return;
KyoyuClient instance = KyoyuClient.getInstance();
if (instance == null) return;
LocalPlayer localPlayer = Minecraft.getInstance().player;
if (localPlayer == null) return;
if (!instance.serverConfig().isAllowedModify(localPlayer.getName().getString())) {
InfoUtils.showGuiOrInGameMessage(Message.MessageType.ERROR, "kyoyu.error.disallowed_modify");
return;
}
KyoyuPlacement kyoyuPlacement = this.kyoyu$toKyoyuPlacement();
if (kyoyuPlacement == null) return;
PlacementMetaPacket placementMetaPacket = new PlacementMetaPacket(kyoyuPlacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public class HandshakePacket extends IKyoyuPacket {
private final String version;
private final KyoyuConfig config;

public HandshakePacket(String version) {
this.version = version;
this.config = null;
}

public HandshakePacket(String version, KyoyuConfig config) {
this.version = version;
this.config = config;
Expand Down

0 comments on commit 3f3b813

Please sign in to comment.