Skip to content

Commit

Permalink
Added SearchModule, SearchCommand, heavily optimized configs and clie…
Browse files Browse the repository at this point in the history
…nt overall
  • Loading branch information
uoil committed Dec 10, 2020
1 parent 54cb544 commit 8c28704
Show file tree
Hide file tree
Showing 25 changed files with 508 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public void onSave() {
}

protected void saveJsonObjectToFile(JsonObject object) {
File newFile = FileUtil.recreateFile(this.getFile());
FileUtil.saveJsonFile(newFile, object);
FileUtil.saveJsonFile(FileUtil.recreateFile(this.getFile()), object);
}

protected JsonObject convertJsonObjectFromFile() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.rigamortis.seppuku.api.event.module;

import me.rigamortis.seppuku.api.module.Module;

/**
* Author Seth
* 6/10/2019 @ 2:36 PM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class BlockPlacementRequest {
private final EnumFacing placeDirection;

public BlockPlacementRequest(final BlockPos structurePosition,
final EnumFacing placeDirection) {
final EnumFacing placeDirection) {
this.structurePosition = structurePosition;
this.placeDirection = placeDirection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public int getNewSlot() {
}

public void handleHandSwap(final boolean restore,
final Minecraft minecraft) {
final Minecraft minecraft) {
minecraft.player.inventory.currentItem =
restore ? this.getOldSlot() : this.getNewSlot();
minecraft.playerController.updateController();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/me/rigamortis/seppuku/api/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static File createDirectory(String dir) {
* Creates a json file in a directory
*/
public static File createJsonFile(File dir, String name) {
File file = new File(dir, name + ".json");
return file;
return new File(dir, name + ".json");
}

/**
Expand All @@ -80,7 +79,7 @@ public static File recreateFile(File file) {
*/
public static void saveJsonFile(File file, JsonObject jsonObject) {
try {
file.createNewFile();
//file.createNewFile();
FileWriter writer = new FileWriter(file);
Throwable throwable = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void exec(String input) {
@Listener
public void render(EventRender2D event) {
final InfEnderChestModule mod = (InfEnderChestModule) Seppuku.INSTANCE.getModuleManager().find(InfEnderChestModule.class);
if(mod != null) {
if(mod.getScreen() != null) {
if (mod != null) {
if (mod.getScreen() != null) {
Minecraft.getMinecraft().displayGuiScreen(mod.getScreen());
Seppuku.INSTANCE.logChat("Opening the last inventory.");
} else {
Expand Down
179 changes: 179 additions & 0 deletions src/main/java/me/rigamortis/seppuku/impl/command/SearchCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package me.rigamortis.seppuku.impl.command;

import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.command.Command;
import me.rigamortis.seppuku.api.util.StringUtil;
import me.rigamortis.seppuku.impl.module.render.SearchModule;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.event.HoverEvent;

/**
* @author noil
*/
public final class SearchCommand extends Command {

private final String[] addAlias = new String[]{"Add"};
private final String[] removeAlias = new String[]{"Remove", "Rem", "Delete", "Del"};
private final String[] listAlias = new String[]{"List", "Lst"};
private final String[] clearAlias = new String[]{"Clear", "clr"};

public SearchCommand() {
super("Search", new String[]{"find", "locate"}, "Allows you to change what blocks are visible on search",
"Search Add <Block_Name>\n" +
"Search Add <ID>\n" +
"Search Remove <Block_Name>\n" +
"Search Remove <ID>\n" +
"Search List\n" +
"Search Clear");
}

@Override
public void exec(String input) {
if (!this.clamp(input, 2, 3)) {
this.printUsage();
return;
}

final String[] split = input.split(" ");

final SearchModule searchModule = (SearchModule) Seppuku.INSTANCE.getModuleManager().find(SearchModule.class);

if (searchModule != null) {
if (equals(addAlias, split[1])) {
if (!this.clamp(input, 3, 3)) {
this.printUsage();
return;
}

if (StringUtil.isInt(split[2])) {
final int id = Integer.parseInt(split[2]);

if (id > 0) {
final Block block = Block.getBlockById(id);

if (searchModule.contains(Block.getIdFromBlock(block))) {
Seppuku.INSTANCE.logChat("Search already contains " + block.getLocalizedName());
} else {
searchModule.add(Block.getIdFromBlock(block));
if (searchModule.isEnabled()) {
searchModule.updateRenders();
}
Seppuku.INSTANCE.getConfigManager().saveAll();
Seppuku.INSTANCE.logChat("Added " + block.getLocalizedName() + " to search");
}
} else {
Seppuku.INSTANCE.errorChat("Cannot add Air to search");
}
} else {
final Block block = Block.getBlockFromName(split[2].toLowerCase());

if (block != null) {
if (block == Blocks.AIR) {
Seppuku.INSTANCE.errorChat("Cannot add Air to search");
} else {
if (searchModule.contains(Block.getIdFromBlock(block))) {
Seppuku.INSTANCE.logChat("Search already contains " + block.getLocalizedName());
} else {
searchModule.add(Block.getIdFromBlock(block));
if (searchModule.isEnabled()) {
searchModule.updateRenders();
}
Seppuku.INSTANCE.getConfigManager().saveAll();
Seppuku.INSTANCE.logChat("Added " + block.getLocalizedName() + " to search");
}
}
} else {
Seppuku.INSTANCE.logChat("\247c" + split[2] + "\247f is not a valid block");
}
}
} else if (equals(removeAlias, split[1])) {
if (!this.clamp(input, 3, 3)) {
this.printUsage();
return;
}

if (StringUtil.isInt(split[2])) {
final int id = Integer.parseInt(split[2]);

if (id > 0) {
final Block block = Block.getBlockById(id);

if (searchModule.contains(Block.getIdFromBlock(block))) {
searchModule.remove(Block.getIdFromBlock(block));
if (searchModule.isEnabled()) {
searchModule.updateRenders();
}
Seppuku.INSTANCE.getConfigManager().saveAll();
Seppuku.INSTANCE.logChat("Removed " + block.getLocalizedName() + " from search");
} else {
Seppuku.INSTANCE.logChat("Search doesn't contain " + block.getLocalizedName());
}
} else {
Seppuku.INSTANCE.errorChat("Cannot remove Air from search");
}
} else {
final Block block = Block.getBlockFromName(split[2].toLowerCase());

if (block != null) {
if (block == Blocks.AIR) {
Seppuku.INSTANCE.errorChat("Cannot remove Air from search");
} else {
if (searchModule.contains(Block.getIdFromBlock(block))) {
searchModule.remove(Block.getIdFromBlock(block));
if (searchModule.isEnabled()) {
searchModule.updateRenders();
}
Seppuku.INSTANCE.getConfigManager().saveAll();
Seppuku.INSTANCE.logChat("Removed " + block.getLocalizedName() + " from search");
} else {
Seppuku.INSTANCE.logChat("Search doesn't contain " + block.getLocalizedName());
}
}
} else {
Seppuku.INSTANCE.logChat("\247c" + split[2] + "\247f is not a valid block");
}
}
} else if (equals(listAlias, split[1])) {
if (!this.clamp(input, 2, 2)) {
this.printUsage();
return;
}

if (searchModule.getIds().size() > 0) {
final TextComponentString msg = new TextComponentString("\2477Search IDs: ");

for (int i : searchModule.getIds()) {
msg.appendSibling(new TextComponentString("\2477[\247a" + i + "\2477] ")
.setStyle(new Style()
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(Block.getBlockById(i).getLocalizedName())))));
}

Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(msg);
} else {
Seppuku.INSTANCE.logChat("You don't have any search ids");
}
} else if (equals(clearAlias, split[1])) {
if (!this.clamp(input, 2, 2)) {
this.printUsage();
return;
}
searchModule.clear();
if (searchModule.isEnabled()) {
searchModule.updateRenders();
}
Seppuku.INSTANCE.getConfigManager().saveAll();
Seppuku.INSTANCE.logChat("Cleared all blocks from search");
} else {
Seppuku.INSTANCE.errorChat("Unknown input " + "\247f\"" + input + "\"");
this.printUsage();
}
} else {
Seppuku.INSTANCE.errorChat("Search not present");
}
}
}

31 changes: 28 additions & 3 deletions src/main/java/me/rigamortis/seppuku/impl/command/XrayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
import me.rigamortis.seppuku.api.util.StringUtil;
import me.rigamortis.seppuku.impl.module.render.XrayModule;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.event.HoverEvent;

/**
* Author Seth
* 4/16/2019 @ 10:42 PM.
*/
public final class XrayCommand extends Command {

private String[] addAlias = new String[]{"Add", "A"};
private String[] removeAlias = new String[]{"Remove", "Rem", "R", "Delete", "Del", "D"};
private String[] clearAlias = new String[]{"Clear", "C"};
private final String[] addAlias = new String[]{"Add", "A"};
private final String[] removeAlias = new String[]{"Remove", "Rem", "R", "Delete", "Del", "D"};
private final String[] listAlias = new String[]{"List", "Lst"};
private final String[] clearAlias = new String[]{"Clear", "C"};

public XrayCommand() {
super("Xray", new String[]{"JadeVision", "Jade"}, "Allows you to change what blocks are visible on xray",
"Xray Add <Block_Name>\n" +
"Xray Add <ID>\n" +
"Xray Remove <Block_Name>\n" +
"Xray Remove <ID>\n" +
"Xray List\n" +
"Xray Clear");
}

Expand Down Expand Up @@ -140,6 +146,25 @@ public void exec(String input) {
Seppuku.INSTANCE.logChat("\247c" + split[2] + "\247f is not a valid block");
}
}
} else if (equals(listAlias, split[1])) {
if (!this.clamp(input, 2, 2)) {
this.printUsage();
return;
}

if (xray.getIds().size() > 0) {
final TextComponentString msg = new TextComponentString("\247Xray IDs: ");

for (int i : xray.getIds()) {
msg.appendSibling(new TextComponentString("\2477[\247a" + i + "\2477] ")
.setStyle(new Style()
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(Block.getBlockById(i).getLocalizedName())))));
}

Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(msg);
} else {
Seppuku.INSTANCE.logChat("You don't have any search ids");
}
} else if (equals(clearAlias, split[1])) {
if (!this.clamp(input, 2, 2)) {
this.printUsage();
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/me/rigamortis/seppuku/impl/config/SearchConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package me.rigamortis.seppuku.impl.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.module.render.SearchModule;

import java.io.File;
import java.util.Objects;

/**
* @author noil
*/
public final class SearchConfig extends Configurable {

private final SearchModule searchModule;

public SearchConfig(File dir) {
super(FileUtil.createJsonFile(dir, "SearchIds"));
this.searchModule = (SearchModule) Seppuku.INSTANCE.getModuleManager().find("Search");
}

@Override
public void onLoad() {
super.onLoad();

if (this.searchModule == null)
return;

JsonArray searchIdsJsonArray = null;

final JsonElement blockIds = this.getJsonObject().get("SearchBlockIds");
if (blockIds != null)
searchIdsJsonArray = blockIds.getAsJsonArray();

if (searchIdsJsonArray != null) {
for (JsonElement jsonElement : searchIdsJsonArray) {
((SearchModule) Objects.requireNonNull(Seppuku.INSTANCE.getModuleManager().find("Search"))).add(jsonElement.getAsInt());
}
}
}

@Override
public void onSave() {
if (this.searchModule == null)
return;

JsonObject save = new JsonObject();

JsonArray searchIdsJsonArray = new JsonArray();
for (Integer i : this.searchModule.getIds())
searchIdsJsonArray.add(i);

save.add("SearchBlockIds", searchIdsJsonArray);

this.saveJsonObjectToFile(save);
}
}
Loading

0 comments on commit 8c28704

Please sign in to comment.