Skip to content

Commit

Permalink
Version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Asleeepp committed Feb 25, 2024
1 parent 71fece5 commit 5458036
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 75 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compileJava {
}

group = 'me.Asleepp'
version = '1.3'
version = '1.4'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.asleepp.SkriptItemsAdder.elements.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
import org.bukkit.event.block.Action;

import javax.annotation.Nullable;
@Name("Is Action")
@Description({"This condition checks if the player has interacted with a custom block with either a left or a right click."})
@Examples({"on interact with custom block: /tif interact action is right click: /t/tkill event-player "})
@Since("1.4")
public class CondGetAction extends Condition {

static {
Skript.registerCondition(CondGetAction.class, "[custom|ia|itemsadder] [interact] action is (:right|:left) click");
}

private boolean isLeft;

@Override
public boolean check(Event e) {
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
if (isLeft) {
return event.getAction() == Action.LEFT_CLICK_BLOCK;
} else {
return event.getAction() == Action.RIGHT_CLICK_BLOCK;
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "interact action is " + (isLeft ? "left" : "right") + " click";
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
isLeft = parseResult.hasTag("left");
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.asleepp.SkriptItemsAdder.elements.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;

import javax.annotation.Nullable;
@Name("Is Block Clicked")
@Description({"This condition checks what block the player clicked."})
@Examples({"on interact with custom block: /tif clicked block is \"diamond_tiles\" /t/tsend \"That's quite valuable.\" "})
@Since("1.4")
public class CondGetBlockClicked extends Condition {

private Expression<String> block;

static {
Skript.registerCondition(CondGetBlockClicked.class, "[the] block clicked is %strings%");
}

@Override
public boolean check(Event e) {
if (e instanceof CustomBlockInteractEvent) {
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
String clickedBlock = event.getBlockClicked().getType().toString();
return clickedBlock.equals(block.getSingle(e));
}
return false;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "[the] block clicked is " + block.toString(e, debug);
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
block = (Expression<String>) exprs[0];
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.asleepp.SkriptItemsAdder.elements.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
import org.bukkit.block.BlockFace;
import org.bukkit.event.Event;

import javax.annotation.Nullable;
@Name("Is Block Face")
@Description({"This condition checks what face of a block the player has interacted with."})
@Examples({"on interact with custom block: /tif clicked block face is south: /t/tsend \"Why are you doing that?\" "})
@Since("1.4")
public class CondGetBlockFace extends Condition {

static {
Skript.registerCondition(CondGetBlockFace.class, "[clicked] block face is (:down|:north|:south|:east|:west|:up)");
}

private BlockFace face;

@Override
public boolean check(Event e) {
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
return event.getBlockFace() == face;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "clicked block face is " + face.toString();
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
if (parseResult.hasTag("north")) {
face = BlockFace.NORTH;
} else if (parseResult.hasTag("south")) {
face = BlockFace.SOUTH;
} else if (parseResult.hasTag("east")) {
face = BlockFace.EAST;
} else if (parseResult.hasTag("west")) {
face = BlockFace.WEST;
} else if (parseResult.hasTag("up")) {
face = BlockFace.UP;
} else if (parseResult.hasTag("down")) {
face = BlockFace.DOWN;
}
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@ public class EffPlayBreakSound extends Effect {
@Override
protected void execute(Event e) {
String customBlockId = this.customBlockId.getSingle(e);
Player[] players = this.players.getArray(e);
Player[] players = this.players.getAll(e);

if (customBlockId != null) {
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
if (customBlock != null) {
Block bukkitBlock = customBlock.getBlock();
if (bukkitBlock != null) {
for (Player player : players) {
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) { // probably not 5 blocks but whatever
CustomBlock.playBreakSound(bukkitBlock);
CustomBlock.playBreakSound(bukkitBlock);
}
}
}
}
}
}


@Override
public String toString(@Nullable Event e, boolean debug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,21 @@ public class EffPlayPlaceSound extends Effect {
@Override
protected void execute(Event e) {
String customBlockId = this.customBlockId.getSingle(e);
Player[] players = this.players.getArray(e);
Player[] players = this.players.getAll(e);

if (customBlockId != null) {
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
if (customBlock != null) {
Block bukkitBlock = customBlock.getBlock();
if (bukkitBlock != null) {
for (Player player : players) {
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) {
CustomBlock.playPlaceSound(bukkitBlock);
CustomBlock.playPlaceSound(bukkitBlock);
}
}
}
}
}
}


@Override
public String toString(@Nullable Event e, boolean debug) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.asleepp.SkriptItemsAdder.elements.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.CustomFurniture;
import org.bukkit.Location;
import org.bukkit.event.Event;

import javax.annotation.Nullable;
@Name("Remove Custom Furniture")
@Description({"If there is furniture at a location, this effect will remove it."})
@Examples({"remove custom furniture at player's location"})
@Since("1.4")
public class EffRemoveCustomFurniture extends Effect {

static {
Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) (custom|ia|itemsadder) furniture [%string%] at %locations%");
}

private Expression<String> furnitureId;
private Expression<Location> locations;

@Override
protected void execute(Event e) {
Location[] locs = locations.getAll(e);
String id = furnitureId != null ? furnitureId.getSingle(e) : null;

for (Location loc : locs) {
if (id != null && loc != null) {
CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock());

if (existingFurniture != null) {
existingFurniture.remove(false);
}
}
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "remove custom furniture " + (furnitureId != null ? furnitureId.toString(e, debug) : "") + " at " + locations.toString(e, debug);
}

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
furnitureId = (Expression<String>) exprs[0];
locations = (Expression<Location>) exprs[1];
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import javax.annotation.Nullable;

@Name("Replace Custom Furniture")
@Description({"Replace a custom furniture at a location."})
@Description({"If there is furniture at a location, this effect will remove it and place the one you specify."})
@Examples({"replace custom furniture \"comfy_chair\" at player's location"})
@Since("1.4")
public class EffReplaceCustomFurniture extends Effect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
Expand All @@ -26,6 +27,12 @@ public class EvtCustomBlockBreak extends SkriptEvent {

static {
Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of (custom|ia|itemsadder) block [%string%]");
EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter<CustomBlock, CustomBlockBreakEvent>() {
@Override
public CustomBlock get(CustomBlockBreakEvent event) {
return CustomBlock.byAlreadyPlaced(event.getBlock());
}
}, 0);
}

@SuppressWarnings("unchecked")
Expand All @@ -41,19 +48,19 @@ public boolean check(Event event) {
return false;
}

CustomBlockBreakEvent customBlockBreakEvent = (CustomBlockBreakEvent) event;
if (customBlockBreakEvent.isCancelled()) {
CustomBlockBreakEvent customEvent = (CustomBlockBreakEvent) event;
if (customEvent.isCancelled()) {
return false;
}

// check block
if (blockName != null) {
String specifiedBlockName = blockName.getSingle(event);
Block block = customBlockBreakEvent.getBlock();
Block block = customEvent.getBlock();
if (block == null) {
return false;
}
String actualBlockName = customBlockBreakEvent.getNamespacedID();
String actualBlockName = customEvent.getNamespacedID();
if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) {
return false;
}
Expand All @@ -62,6 +69,7 @@ public boolean check(Event event) {
return true;
}


@Override
public String toString(@Nullable Event e, boolean debug) {
return "Custom Block Break event";
Expand Down
Loading

0 comments on commit 5458036

Please sign in to comment.