Skip to content

Commit

Permalink
Merge pull request #817 from TonytheMacaroni/main
Browse files Browse the repository at this point in the history
Magic Item Adjustments, Bugfixes
  • Loading branch information
Chronoken authored Dec 13, 2023
2 parents bbe4ab7 + 9e266b2 commit 4dfee12
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 714 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: echo "sha_short=$(git rev-parse --short ${{github.sha}})" >> $GITHUB_OUTPUT
- name: Get version
id: version
run: echo "version=$(grep version gradle.properties | cut -d"=" -f2)" >> $GITHUB_OUTPUT
run: echo "version=$(grep version gradle.properties | cut -d"=" -f2 | xargs)" >> $GITHUB_OUTPUT
- name: Setup Java
uses: actions/setup-java@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public static void onMagicItem(CommandIssuer issuer, String[] args) {
if (player == null) player = getPlayerFromIssuer(issuer);
if (player == null) return;

ItemStack item = magicItem.getItemStack();
ItemStack item = magicItem.getItemStack().clone();
item.setAmount(amount);
player.getInventory().addItem(item);
issuer.sendMessage(MagicSpells.getTextColor() + player.getName() + " received a magic item (" + args[0] + " x" + amount + ").");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}

addUseAndChargeCost(player);
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && airBlock.getType().isAir()) {
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && airBlock.isReplaceable()) {
// Place
ItemStack item = player.getInventory().getItemInMainHand();
if (item.isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public CastResult cast(SpellData data) {
}

ConfigurationSection section = AlternativeReaderManager.serialize(serializerKey.get(data), item);
if (section == null) {
sendMessage("Unable to serialize item.", caster);
return new CastResult(PostCastAction.ALREADY_HANDLED, data);
}

YamlConfiguration config = new YamlConfiguration();
config.set("magic-items." + System.currentTimeMillis(), section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.RayTraceResult;
import org.bukkit.block.data.BlockData;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.MagicSpells;
Expand Down Expand Up @@ -110,8 +111,13 @@ private boolean isDenied(Material mat) {
}

private boolean build(Player player, Block block, Block against, ItemStack item, int slot, SpellData data) {
if (!block.isReplaceable()) return false;

BlockData blockData = item.getType().createBlockData();
if (!block.canPlace(blockData)) return false;

BlockState previousState = block.getState();
block.setType(item.getType());
block.setBlockData(blockData);

if (checkPlugins.get(data)) {
MagicSpellsBlockPlaceEvent event = new MagicSpellsBlockPlaceEvent(block, previousState, against, player.getEquipment().getItemInMainHand(), player, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ public CastResult cast(SpellData data) {

int yOffset = this.yOffset.get(data);
if (yOffset != 0) block = block.getRelative(0, yOffset, 0);
if (!block.isPassable()) {

BlockData blockType = this.blockType.get(data);

if (!block.canPlace(blockType) || !block.isReplaceable()) {
if (checkFace.get(data)) {
Block upper = block.getRelative(BlockFace.UP);
if (!upper.isPassable()) return noTarget(data);
if (!upper.canPlace(blockType) || !block.isReplaceable()) return noTarget(data);
block = upper;
} else return noTarget(data);
}
Expand All @@ -136,8 +139,11 @@ public CastResult cast(SpellData data) {
block = event.getTargetLocation().getBlock();
data = event.getSpellData();

createPulser(block, data);
block.setBlockData(blockType);
pulsers.put(block, new Pulser(block, blockType.getMaterial(), data));
ticker.start();

playSpellEffects(data);
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

Expand All @@ -159,10 +165,12 @@ public CastResult castAtLocation(SpellData data) {
int yOffset = this.yOffset.get(data);
if (yOffset != 0) block = block.getRelative(0, yOffset, 0);

if (!block.isPassable()) {
BlockData blockType = this.blockType.get(data);

if (!block.canPlace(blockType) || !block.isReplaceable()) {
if (checkFace.get(data)) {
Block upper = block.getRelative(BlockFace.UP);
if (!upper.isPassable()) return noTarget(data);
if (!upper.canPlace(blockType) || !block.isReplaceable()) return noTarget(data);
block = upper;
} else return noTarget(data);
}
Expand All @@ -171,21 +179,14 @@ public CastResult castAtLocation(SpellData data) {
location = block.getLocation().toCenterLocation();
location.setPitch(pitch);
location.setYaw(yaw);

data = data.location(location);
createPulser(block, data);

return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

private void createPulser(Block block, SpellData data) {
BlockData blockType = this.blockType.get(data);
block.setBlockData(blockType);

pulsers.put(block, new Pulser(block, blockType.getMaterial(), data));
ticker.start();

playSpellEffects(data);
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
Expand Down
Loading

0 comments on commit 4dfee12

Please sign in to comment.