Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
优化记忆功能 完善API和修改操作
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhangup committed Mar 6, 2022
1 parent 65cf6d9 commit 8553075
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<groupId>me.xiaozhangup.natunology</groupId>
<artifactId>Natunology</artifactId>
<name>Natunology</name>
<version>1.1.3</version>
<version>1.1.4</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.xiaozhangup.natunology.Main;
import me.xiaozhangup.natunology.api.Message;
import me.xiaozhangup.natunology.techcore.api.ItemHash;
import me.xiaozhangup.natunology.techcore.items.Items;
import me.xiaozhangup.natunology.techcore.views.MainTap;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -56,6 +57,13 @@ public static void regCommands() {
}
} else if (inside[0].equals("guide")) {
MainTap.openMainTap(p);
} else if (inside[0].equals("getitem")) {
try {
p.getInventory().addItem(ItemHash.getItem(Integer.valueOf(inside[1])));
Message.send(p, "&f[&7科技&f] &a物品已经发送到您的背包!");
} catch (Exception e) {
Message.send(p, "&f[&7科技&f] &c没有这个物品!");
}
} else {
Message.send(p, "&f[&7科技&f] &c没有这个命令!", "&f[&7科技&f] 输入/ntg help 查看帮助");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ public class Datahash {

public static HashMap<Player, String> lastgroup = new HashMap<>();

public static HashMap<Integer, List<ItemStack>> crafttable = new HashMap<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.xiaozhangup.natunology.techcore.Datahash;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class ItemHash {

Expand All @@ -19,6 +20,9 @@ public static String getGroupId(ItemStack itemStack) {
}

public static void addItem(ItemStack itemStack, Integer integer, String group) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setCustomModelData(integer);
itemStack.setItemMeta(itemMeta);
Datahash.items.put(integer, itemStack);
Datahash.itemgroupd.put(integer, group);
}
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/me/xiaozhangup/natunology/techcore/api/Test.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package me.xiaozhangup.natunology.techcore.api;

import me.xiaozhangup.natunology.techcore.items.Items;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class Test {

public static void runTest() {
ItemHash.addGroup(new ItemStack(Material.CHEST), "test1");
ItemHash.addGroup(new ItemStack(Material.GLASS), "test2");
ItemHash.addGroup(new ItemStack(Material.GRASS), "test3");
ItemHash.addItem(Items.addId(new ItemStack(Material.LAVA_BUCKET), 42), 42, "misc");
ItemHash.addItem(Items.addId(new ItemStack(Material.TORCH), 43), 43, "test1");
ItemHash.addItem(Items.addId(new ItemStack(Material.ACACIA_BOAT), 44), 44, "test2");
ItemHash.addItem(Items.addId(new ItemStack(Material.EGG), 45), 45, "test3");
// ItemHash.addGroup(new ItemStack(Material.CHEST), "test1");
// ItemHash.addGroup(new ItemStack(Material.GLASS), "test2");
// ItemHash.addGroup(new ItemStack(Material.GRASS), "test3");
// ItemHash.addItem(new ItemStack(Material.LAVA_BUCKET), 42, "misc");
// ItemHash.addItem(new ItemStack(Material.TORCH), 43, "test1");
// ItemHash.addItem(new ItemStack(Material.ACACIA_BOAT), 44, "test2");
// ItemHash.addItem(new ItemStack(Material.EGG), 45, "test3");
}

}
25 changes: 21 additions & 4 deletions src/main/java/me/xiaozhangup/natunology/techcore/events/Books.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.xiaozhangup.natunology.techcore.events;

import me.xiaozhangup.natunology.techcore.Datahash;
import me.xiaozhangup.natunology.techcore.api.ItemHash;
import me.xiaozhangup.natunology.techcore.views.InfoMenu;
import me.xiaozhangup.natunology.techcore.views.MainTap;
Expand All @@ -13,6 +12,9 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import static me.xiaozhangup.natunology.techcore.Datahash.itemgroupd;
import static me.xiaozhangup.natunology.techcore.Datahash.lastgroup;

public class Books implements Listener {

@EventHandler
Expand All @@ -22,7 +24,20 @@ public void onItemClick(PlayerInteractEvent e) {
e.getItem().getItemMeta().hasCustomModelData() &&
e.getItem().getItemMeta().getCustomModelData() == 1) {
Player p = e.getPlayer();
String key = lastgroup.get(p);
e.setCancelled(true);
if (p.isSneaking()) {
InfoMenu.openInfoMenu(p);
return;
} else if (key != null) {
if (key.startsWith("g")) {
MainTap.openGroup(p, key.replace("g", ""));
return;
} else {
MainTap.openCraft(p, Integer.valueOf(key.replace("id", "")));
return;
}
}
MainTap.openMainTap(p);
}
}
Expand All @@ -41,18 +56,20 @@ public void onInvClick(InventoryClickEvent e) {
InfoMenu.openInfoMenu(player);
} else if (itemStack.getItemMeta().getCustomModelData() == 3) {
MainTap.openMainTap(player);
lastgroup.remove(player);
} else if (itemStack.getItemMeta().getCustomModelData() == 4) {
MainTap.openGroup(player, Datahash.lastgroup.get(player));
MainTap.openGroup(player, itemgroupd.get(Integer.valueOf(lastgroup.get(player).replace("id", ""))));
lastgroup.put(player, "g" + itemgroupd.get(Integer.valueOf(lastgroup.get(player).replace("id", ""))));
} else if (itemStack.getItemMeta().getCustomModelData() == 5) {
MainTap.openGroup(player, "misc");
Datahash.lastgroup.put(player, "misc");
lastgroup.put(player, "gmisc");
} else {
MainTap.openCraft(player, itemStack.getItemMeta().getCustomModelData());
}
} else if (itemStack != null) {
if (ItemHash.getGroupId(itemStack) != null) {
MainTap.openGroup(player, ItemHash.getGroupId(itemStack));
Datahash.lastgroup.put(player, ItemHash.getGroupId(itemStack));
lastgroup.put(player, "g" + ItemHash.getGroupId(itemStack));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static ItemStack guide() {
ItemStack itemStack = new ItemStack(Material.BOOK);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setCustomModelData(1);
itemMeta.setDisplayName(Message.color("&7Natunology 指导书"));
itemMeta.setLore(NString.toStringlist(" ", "&f右键单击打开书本", "&e技术 物品 工具"));
itemMeta.setDisplayName(Message.color("&7 Natunology 指导书"));
itemMeta.setLore(NString.toStringlist(" ", "&f右键单击打开指导书", "&fShift + 右键打开关于"));
itemStack.setItemMeta(itemMeta);
return itemStack;
}
Expand Down Expand Up @@ -121,11 +121,4 @@ public static ItemStack itemBuilder(Material material, String name, String... lo
return itemStack;
}

public static ItemStack addId(ItemStack itemStack, Integer integer) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setCustomModelData(integer);
itemStack.setItemMeta(itemMeta);
return itemStack;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.xiaozhangup.natunology.techcore.views;

import me.xiaozhangup.natunology.api.Message;
import me.xiaozhangup.natunology.api.NString;
import me.xiaozhangup.natunology.techcore.Datahash;
import me.xiaozhangup.natunology.techcore.items.Items;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -28,7 +29,8 @@ public static void openInfoMenu(Player p) {
inventory.setItem(11, Items.itemBuilder(Material.PAPER, "&fItemGroupD", " ", "&7T: " + Datahash.itemgroupd.size()));
inventory.setItem(12, Items.itemBuilder(Material.PAPER, "&fGroupID", " ", "&7T: " + Datahash.groupid.size()));
inventory.setItem(13, Items.itemBuilder(Material.PAPER, "&fLastGroup", " ", "&7T: " + Datahash.lastgroup.size()));
inventory.setItem(14, Items.itemBuilder(Material.PAPER, "&fCraftTable", " ", "&7T: " + Datahash.crafttable.size()));

inventory.setItem(17, Items.getSkull("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDU2Yzk0NjE5MDMxMjMxNjhjZTY2N2VhZDdlYTU2YTUxNjEzMDk3MDQ5YmE2NDc4MzJiMzcyMmFmZmJlYjYzNiJ9fX0=", "&f服务器运行", NString.toStringlist("", "&7Bukkit " + Bukkit.getBukkitVersion(), "&7Minecraft " + Bukkit.getMinecraftVersion(), "&7Version " + Bukkit.getVersion())));

p.openInventory(inventory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ public static void openCraft(Player p, Integer id) {
for (int i = 36; i <= 44; i++) {
inventory.setItem(i, Items.board());
}
Datahash.lastgroup.put(p, "id" + id);

inventory.setItem(4, Items.getHome());
inventory.setItem(0, Items.getBack());

inventory.setItem(19, Datahash.items.get(id));

//todo callevent

p.openInventory(inventory);
} catch (Exception ignored) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Natunology
main: me.xiaozhangup.natunology.Main
version: 1.1.3
version: 1.1.4
api-version: 1.13
authors:
- xiaozhangup
Expand Down

0 comments on commit 8553075

Please sign in to comment.