Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Sep 26, 2023
1 parent c329abc commit f977dd4
Show file tree
Hide file tree
Showing 43 changed files with 800 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

public enum BlockType {
NOTE_BLOCK(Material.NOTE_BLOCK),
STRING(Material.TRIPWIRE)
STRING(Material.TRIPWIRE),
CHORUS_PLANT(Material.CHORUS_PLANT),
RED_MUSHROOM_BLOCK(Material.RED_MUSHROOM_BLOCK),
BROWN_MUSHROOM_BLOCK(Material.BROWN_MUSHROOM_BLOCK),
MUSHROOM_STEM(Material.MUSHROOM_STEM),
FIRE(Material.FIRE)
;
private final Material material;
BlockType(Material material) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package kor.toxicity.questadder.api.event;

import kor.toxicity.questadder.api.mechanic.IActualNPC;
import kor.toxicity.questadder.api.mechanic.DialogSender;
import kor.toxicity.questadder.api.mechanic.IDialog;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class DialogStartEvent extends QuestAdderPlayerEvent implements DialogEvent, NPCEvent, Cancellable {
public class DialogStartEvent extends QuestAdderPlayerEvent implements DialogEvent, Cancellable {

private final IActualNPC npc;
private final DialogSender sender;
private final IDialog dialog;
private boolean cancelled;
public DialogStartEvent(Player who, IActualNPC npc, IDialog dialog) {
public DialogStartEvent(Player who, DialogSender sender, IDialog dialog) {
super(who);
this.npc = npc;
this.sender = sender;
this.dialog = dialog;
}

Expand All @@ -26,8 +26,8 @@ public static HandlerList getHandlerList() {
return dialog;
}

public @NotNull IActualNPC getNpc() {
return npc;
public @NotNull DialogSender getSender() {
return sender;
}

@Override
Expand Down
45 changes: 45 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/gui/GuiData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package kor.toxicity.questadder.api.gui;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class GuiData {
private final IGui gui;
private final Inventory inventory;
private GuiExecutor executor;
private final Player player;

public GuiData(@NotNull IGui gui, @NotNull Inventory inventory, @NotNull GuiExecutor executor, @NotNull Player player) {
this.gui = gui;
this.inventory = inventory;
this.executor = executor;
this.player = player;
}

public @NotNull GuiExecutor getExecutor() {
return executor;
}

public @NotNull IGui getGui() {
return gui;
}

public @NotNull Inventory getInventory() {
return inventory;
}

public @NotNull Player getPlayer() {
return player;
}

public void setExecutor(@NotNull GuiExecutor executor) {
this.executor = Objects.requireNonNull(executor);
}

public void reopen() {
gui.open(player,executor);
}
}
10 changes: 10 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/gui/GuiExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kor.toxicity.questadder.api.gui;

import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public interface GuiExecutor {
void initialize(@NotNull GuiData data);
void click(@NotNull GuiData data, @NotNull ItemStack clickedItem, int clickedSlot, boolean isPlayerInventory, @NotNull MouseButton button);
void end(@NotNull GuiData data);
}
37 changes: 37 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/gui/GuiHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package kor.toxicity.questadder.api.gui;

import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class GuiHolder implements InventoryHolder {
private final Inventory inventory;
private final GuiData data;
private final GuiExecutor executor;
public GuiHolder(@NotNull IGui gui, int size, @NotNull Component name, @NotNull Player player, @NotNull GuiExecutor executor, @NotNull Map<Integer, ItemStack> map) {
inventory = Bukkit.createInventory(this, size, name);
map.forEach(inventory::setItem);
data = new GuiData(gui, inventory, executor, player);
this.executor = executor;
executor.initialize(data);
}

public @NotNull GuiExecutor getExecutor() {
return executor;
}

public @NotNull GuiData getData() {
return data;
}

@Override
public @NotNull Inventory getInventory() {
return inventory;
}
}
16 changes: 16 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/gui/IGui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kor.toxicity.questadder.api.gui;

import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public interface IGui {
@NotNull GuiHolder open(@NotNull Player player, @NotNull GuiExecutor executor);
@NotNull
Component getGuiName();
@NotNull
Map<Integer, ItemStack> getInnerItems();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kor.toxicity.questadder.api.gui;

public enum MouseButton {
LEFT,
RIGHT,
SHIFT_LEFT,
SHIFT_RIGHT,
OTHER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kor.toxicity.questadder.api.mechanic;

import kor.toxicity.questadder.api.gui.IGui;
import kor.toxicity.questadder.api.util.SoundData;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface DialogSender {
@Nullable
Entity getEntity();
@NotNull
SoundData getSoundData();
@NotNull
String getTalkerName();
long getTypingSpeed();
@Nullable
IGui getGui();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package kor.toxicity.questadder.api.mechanic;

import net.citizensnpcs.api.npc.NPC;
import org.jetbrains.annotations.NotNull;

public interface IActualNPC {
NPC toCitizensNPC();
IQuestNPC toQuestNPC();
public interface IActualNPC extends DialogSender {
@NotNull NPC toCitizensNPC();
@NotNull IQuestNPC toQuestNPC();
}
21 changes: 21 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/util/SoundData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kor.toxicity.questadder.api.util;

import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public record SoundData(@NotNull String name, float volume, float pitch) {
public static @Nullable SoundData fromString(@NotNull String string) {
var split = string.split(" ");
if (split.length < 3) return null;
try {
return new SoundData(split[0], Float.parseFloat(split[1]), Float.parseFloat(split[2]));
} catch (Exception e) {
return null;
}
}

public void play(@NotNull Player player) {
player.playSound(player.getLocation(), name, volume, pitch);
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

def questAdderGroup = 'kor.toxicity'
def questAdderVersion = '1.1.0-SNAPSHOT'
def questAdderVersion = '1.1.1-SNAPSHOT'

allprojects {
apply plugin: 'java'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 5 additions & 5 deletions plugin/src/main/java/kor/toxicity/questadder/QuestAdderBukkit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import kor.toxicity.questadder.manager.*
import kor.toxicity.questadder.mechanic.quest.QuestRecord
import kor.toxicity.questadder.nms.NMS
import kor.toxicity.questadder.util.ComponentReader
import kor.toxicity.questadder.util.SoundData
import kor.toxicity.questadder.util.TimeFormat
import kor.toxicity.questadder.util.action.ActCast
import kor.toxicity.questadder.util.action.ActSkill
import kor.toxicity.questadder.util.builder.ActionBuilder
import kor.toxicity.questadder.util.database.StandardDatabaseSupplier
import kor.toxicity.questadder.api.mechanic.AbstractEvent
import kor.toxicity.questadder.api.util.SoundData
import kor.toxicity.questadder.util.event.*
import kor.toxicity.questadder.util.event.itemsadder.EventCustomBlockBreak
import kor.toxicity.questadder.util.event.itemsadder.EventCustomBlockClick
Expand Down Expand Up @@ -90,7 +90,7 @@ import java.util.concurrent.ThreadLocalRandom
class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
companion object: QuestAdder {

const val VERSION = "1.1.0"
const val VERSION = "1.1.1"

private val listener = object : Listener {
}
Expand Down Expand Up @@ -513,12 +513,12 @@ class QuestAdderBukkit: JavaPlugin(), QuestAdderPlugin {
loadFile("suffix")?.let { suffix ->
Suffix.reload(suffix)
}
managerList.forEach {
it.reload(this)
}
loadFile("config")?.let { config ->
Config.reload(config)
}
managerList.forEach {
it.reload(this)
}
var task: (() -> Unit)?
do {
task = lazyTaskCache.poll()?.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package kor.toxicity.questadder.block

import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.block.data.BlockData
import org.bukkit.block.data.MultipleFacing

data class BrownMushroomBlockData(
val west: Boolean,
val up: Boolean,
val south: Boolean,
val north: Boolean,
val east: Boolean,
val down: Boolean
): QuestBlockData {
companion object {
fun fromHash(hash: Int): BrownMushroomBlockData {
val bit = hash and ((1 shl 6) - 1)

return BrownMushroomBlockData(
(bit and 1) == 1,
((bit ushr 1) and 1) == 1,
((bit ushr 2) and 1) == 1,
((bit ushr 3) and 1) == 1,
((bit ushr 4) and 1) == 1,
((bit ushr 5) and 1) == 1,
)
}
fun fromBlock(blockData: MultipleFacing): BrownMushroomBlockData {
val direction = blockData.faces
return BrownMushroomBlockData(
direction.contains(BlockFace.WEST),
direction.contains(BlockFace.UP),
direction.contains(BlockFace.SOUTH),
direction.contains(BlockFace.NORTH),
direction.contains(BlockFace.EAST),
direction.contains(BlockFace.DOWN)
)
}
}

override fun toKey(): String = "west=$west,up=$up,south=$south,north=$north,east=$east,down=$down"

override fun createBlockData(): BlockData = (Material.BROWN_MUSHROOM_BLOCK.createBlockData() as MultipleFacing).also {
it.setFace(BlockFace.WEST, west)
it.setFace(BlockFace.UP, up)
it.setFace(BlockFace.SOUTH, south)
it.setFace(BlockFace.NORTH, north)
it.setFace(BlockFace.EAST, east)
it.setFace(BlockFace.DOWN, down)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package kor.toxicity.questadder.block

import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.block.data.BlockData
import org.bukkit.block.data.MultipleFacing

data class ChorusPlantBlockData(
val west: Boolean,
val up: Boolean,
val south: Boolean,
val north: Boolean,
val east: Boolean,
val down: Boolean
): QuestBlockData {
companion object {
fun fromHash(hash: Int): ChorusPlantBlockData {
val bit = hash and ((1 shl 6) - 1)

return ChorusPlantBlockData(
(bit and 1) == 1,
((bit ushr 1) and 1) == 1,
((bit ushr 2) and 1) == 1,
((bit ushr 3) and 1) == 1,
((bit ushr 4) and 1) == 1,
((bit ushr 5) and 1) == 1,
)
}
fun fromBlock(blockData: MultipleFacing): ChorusPlantBlockData {
val direction = blockData.faces
return ChorusPlantBlockData(
direction.contains(BlockFace.WEST),
direction.contains(BlockFace.UP),
direction.contains(BlockFace.SOUTH),
direction.contains(BlockFace.NORTH),
direction.contains(BlockFace.EAST),
direction.contains(BlockFace.DOWN)
)
}
}

override fun toKey(): String = "west=$west,up=$up,south=$south,north=$north,east=$east,down=$down"

override fun createBlockData(): BlockData = (Material.CHORUS_PLANT.createBlockData() as MultipleFacing).also {
it.setFace(BlockFace.WEST, west)
it.setFace(BlockFace.UP, up)
it.setFace(BlockFace.SOUTH, south)
it.setFace(BlockFace.NORTH, north)
it.setFace(BlockFace.EAST, east)
it.setFace(BlockFace.DOWN, down)
}
}
Loading

0 comments on commit f977dd4

Please sign in to comment.