Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #660 from book000/feat/collect-creative-items
Browse files Browse the repository at this point in the history
feat: creative-items.tsv作成処理追加
  • Loading branch information
book000 authored Jan 24, 2022
2 parents c0ae59b + eba0471 commit 5bf9e14
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/com/jaoafa/mymaid4/event/Event_AntiToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class Event_AntiToolbar extends MyMaidLibrary implements Listener, EventPremise {
final Pattern damagePattern = Pattern.compile("\\{Damage:[0-9]+}");
final Map<UUID, ItemStack> pickupItems = new HashMap<>();
final boolean isCollectCreativeItems = false;

@Override
public String description() {
Expand All @@ -54,6 +55,44 @@ public void onInventoryCreative(InventoryCreativeEvent event) {
return;
}

// マイクラバージョン変更時用、クリエイティブアイテム集積処理
if (isCollectCreativeItems) {
Path path = Path.of("creative-items.tsv");
Path path_all = Path.of("creative-all-items.tsv");
try {
String prevString = "";
if (Files.exists(path)) {
prevString = Files.readString(path);
}
String allString = "";
if (Files.exists(path_all)) {
allString = Files.readString(path_all);
}
ItemStack is = event.getCursor();
Material material = is.getType();
String nbt = NMSManager.getNBT(is);
if (nbt == null) {
return;
}
if (allString.contains(material + "\t" + nbt)) {
return;
}
if (!nbt.equals("{}")) {
prevString += material + "\t" + nbt + "\n";
player.sendMessage(Component.text(material + " " + nbt, NamedTextColor.YELLOW));
} else {
player.sendMessage(Component.text(material + " " + nbt, NamedTextColor.GREEN));
}
allString += material + "\t" + nbt + "\n";
Files.writeString(path, prevString);
Files.writeString(path_all, allString);

} catch (IOException e) {
e.printStackTrace();
}
return;
}

if (MyMaidData.getCreativeInventoryWithNBTs().isEmpty()) {
return;
}
Expand Down

0 comments on commit 5bf9e14

Please sign in to comment.