mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-11-18 06:24:17 +01:00
Note-block block type for custom mining
This commit is contained in:
parent
de18990f37
commit
677637a7a3
@ -0,0 +1,89 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
|
||||
import org.bukkit.Instrument;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.NoteBlock;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NoteBlockType implements BlockType {
|
||||
private final Instrument instrument;
|
||||
private final Note note;
|
||||
|
||||
public NoteBlockType(MMOLineConfig config) {
|
||||
config.validateKeys("note");
|
||||
|
||||
instrument = config.contains("instrument")
|
||||
? UtilityMethods.prettyValueOf(Instrument::valueOf, config.getString("instrument"), "No instrument with ID '%s'")
|
||||
: Instrument.PIANO;
|
||||
note = new Note(config.getInt("note"));
|
||||
}
|
||||
|
||||
public NoteBlockType(@NotNull Block block) {
|
||||
final var state = (NoteBlock) block.getBlockData();
|
||||
this.instrument = state.getInstrument();
|
||||
this.note = state.getNote();
|
||||
}
|
||||
|
||||
public Instrument getInstrument() {
|
||||
return instrument;
|
||||
}
|
||||
|
||||
public Note getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakRestrictions(@NotNull Block block) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(RegeneratingBlock block) {
|
||||
Location loc = block.getLocation();
|
||||
block.getLocation().getBlock().setType(Material.NOTE_BLOCK);
|
||||
|
||||
NoteBlock state = (NoteBlock) loc.getBlock().getBlockData();
|
||||
state.setInstrument(instrument);
|
||||
state.setNote(note);
|
||||
loc.getBlock().setBlockData(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regenerate(RegeneratingBlock block) {
|
||||
Location loc = block.getLocation();
|
||||
loc.getBlock().setType(Material.NOTE_BLOCK);
|
||||
// Sets the original blocks old data (only when regenerating)
|
||||
loc.getBlock().setBlockData(block.getBlockData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String display() {
|
||||
return "NoteBlock{instrument=" + instrument.name() + ", note=" + note + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{note="+note.getId()+",instr="+instrument.name()+"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) return true;
|
||||
if (object == null || getClass() != object.getClass()) return false;
|
||||
NoteBlockType that = (NoteBlockType) object;
|
||||
return instrument == that.instrument && Objects.equals(note, that.note);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(instrument, note);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -49,7 +50,7 @@ public class SkullBlockType implements BlockType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String display() {
|
||||
public @NotNull String display() {
|
||||
return "Skull{" + value + "}";
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -43,8 +44,8 @@ public class VanillaBlockType implements BlockType {
|
||||
Location loc = block.getLocation();
|
||||
block.getLocation().getBlock().setType(type);
|
||||
|
||||
BlockData state = block.getLocation().getBlock().getBlockData();
|
||||
if (age > 0 && state instanceof Ageable) {
|
||||
BlockData state;
|
||||
if (age > 0 && (state = block.getLocation().getBlock().getBlockData()) instanceof Ageable) {
|
||||
((Ageable) state).setAge(age);
|
||||
loc.getBlock().setBlockData(state);
|
||||
}
|
||||
@ -59,7 +60,7 @@ public class VanillaBlockType implements BlockType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String display() {
|
||||
public @NotNull String display() {
|
||||
return "Vanilla{" + type.name() + "}";
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.block.NoteBlockType;
|
||||
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.quest.objective.*;
|
||||
@ -199,6 +200,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
if (config.getKey().equalsIgnoreCase("vanilla"))
|
||||
return new VanillaBlockType(config);
|
||||
|
||||
if (config.getKey().equalsIgnoreCase("note_block"))
|
||||
return new NoteBlockType(config);
|
||||
|
||||
if (config.getKey().equalsIgnoreCase("skull") || config.getKey().equals("head") || config.getKey().equals("playerhead"))
|
||||
return new SkullBlockType(config);
|
||||
|
||||
|
||||
@ -3,15 +3,13 @@ package net.Indyuce.mmocore.manager.profession;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.block.*;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.loot.chest.condition.Condition;
|
||||
import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -53,6 +51,7 @@ public class CustomBlockManager extends SpecificProfessionManager {
|
||||
super("on-mine");
|
||||
|
||||
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty());
|
||||
registerBlockType(block -> block.getType()== Material.NOTE_BLOCK ? Optional.of(new NoteBlockType(block)) : Optional.empty());
|
||||
}
|
||||
|
||||
public void registerBlockType(Function<Block, Optional<BlockType>> function) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user