9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2026-01-04 15:41:35 +00:00
This commit is contained in:
XiaoMoMi
2024-07-28 16:14:25 +08:00
parent f555ca6010
commit 84290eacff
7 changed files with 21 additions and 17 deletions

View File

@@ -244,7 +244,7 @@ public class BukkitActionManager implements ActionManager<Player> {
for (String text : replaced) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), text);
}
}, context.arg(ContextKeys.LOCATION));
}, null);
};
});
registerAction("player-command", (args, chance) -> {

View File

@@ -66,7 +66,7 @@ public class GetItemCommand extends BukkitCommandFeature<CommandSender> {
final String id = context.get("id");
final Player player = context.sender();
try {
ItemStack itemStack = BukkitCustomFishingPlugin.getInstance().getItemManager().buildInternal(Context.player(player), id);
ItemStack itemStack = BukkitCustomFishingPlugin.getInstance().getItemManager().buildInternal(Context.player(player).arg(ContextKeys.ID, id), id);
if (itemStack == null) {
throw new RuntimeException("Unrecognized item id: " + id);
}

View File

@@ -67,7 +67,7 @@ public class GiveItemCommand extends BukkitCommandFeature<CommandSender> {
final String id = context.get("id");
boolean toInv = context.flags().hasFlag("to-inventory");
try {
ItemStack itemStack = BukkitCustomFishingPlugin.getInstance().getItemManager().buildInternal(Context.player(player), id);
ItemStack itemStack = BukkitCustomFishingPlugin.getInstance().getItemManager().buildInternal(Context.player(player).arg(ContextKeys.ID, id), id);
if (itemStack == null) {
throw new RuntimeException("Unrecognized item id: " + id);
}

View File

@@ -414,7 +414,7 @@ public class BukkitConfigManager extends ConfigManager {
this.registerItemParser(arg -> {
String base64 = (String) arg;
return (item, context) -> item.skull(base64);
}, 5200, "head");
}, 5200, "head64");
this.registerItemParser(arg -> {
List<String> args = ListUtils.toList(arg);
return (item, context) -> item.itemFlags(args);
@@ -461,6 +461,10 @@ public class BukkitConfigManager extends ConfigManager {
item.setTag(UUID.randomUUID(), "CustomFishing", "uuid");
};
}, 2_222, "stackable");
this.registerItemParser(arg -> {
boolean enable = (boolean) arg;
return (item, context) -> item.setTag(enable ? 1 : 0, "CustomFishing", "placeable");
}, 2_335, "placeable");
this.registerItemParser(arg -> {
String sizePair = (String) arg;
String[] split = sizePair.split("~", 2);

View File

@@ -36,10 +36,7 @@ import net.momirealms.customfishing.bukkit.util.ItemStackUtils;
import net.momirealms.customfishing.bukkit.util.LocationUtils;
import net.momirealms.customfishing.common.item.Item;
import net.momirealms.sparrow.heart.SparrowHeart;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.Skull;
import org.bukkit.enchantments.Enchantment;
@@ -131,7 +128,7 @@ public class BukkitItemManager implements ItemManager, Listener {
// CustomFishingItem item = requireNonNull(items.get(id), () -> "No item found for " + id);
CustomFishingItem item = items.get(id);
if (item == null) return null;
return build(context.arg(ContextKeys.ID, id), item);
return build(context, item);
}
@NotNull
@@ -417,13 +414,17 @@ public class BukkitItemManager implements ItemManager, Listener {
@EventHandler (ignoreCancelled = true)
public void onBreakBlock(BlockBreakEvent event) {
final Block block = event.getBlock();
if (event.getPlayer().getGameMode() == GameMode.CREATIVE)
return;
if (block.getState() instanceof Skull) {
PersistentDataContainer pdc = block.getChunk().getPersistentDataContainer();
String base64 = pdc.get(new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation())), PersistentDataType.STRING);
NamespacedKey key = new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation()));
String base64 = pdc.get(key, PersistentDataType.STRING);
if (base64 != null) {
ItemStack itemStack = ItemStackUtils.fromBase64(base64);
event.setDropItems(false);
block.getLocation().getWorld().dropItemNaturally(block.getLocation(), itemStack);
pdc.remove(key);
}
}
}