Skip to content

Commit

Permalink
patch receives message event determinations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 19, 2020
1 parent b853102 commit 0ea65f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
Expand Up @@ -8,6 +8,8 @@
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;

import java.util.function.Consumer;

public class PlayerReceivesMessageScriptEvent extends BukkitScriptEvent {

// <--[event]
Expand Down Expand Up @@ -44,11 +46,16 @@ public PlayerReceivesMessageScriptEvent() {
public ElementTag rawJson;
public ElementTag system;
public PlayerTag player;
public boolean loaded;

public boolean messageModified;
public boolean rawJsonModified;
public Consumer<String> modifyMessage;
public Consumer<String> modifyRawJson;
public Consumer<Boolean> modifyCancellation;

public boolean loaded;
@Override
public void cancellationChanged() {
modifyCancellation.accept(cancelled);
}

@Override
public boolean couldMatch(ScriptPath path) {
Expand Down Expand Up @@ -77,12 +84,12 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("message:")) {
message = new ElementTag(determination.substring("message:".length()));
messageModified = true;
modifyMessage.accept(message.asString());
return true;
}
if (lower.startsWith("raw_json:")) {
rawJson = new ElementTag(determination.substring("raw_json:".length()));
rawJsonModified = true;
modifyRawJson.accept(rawJson.asString());
return true;
}
}
Expand Down
Expand Up @@ -8,6 +8,8 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;

import java.util.function.Consumer;

public class PlayerSteersEntityScriptEvent extends BukkitScriptEvent {

// <--[event]
Expand Down Expand Up @@ -47,6 +49,13 @@ public PlayerSteersEntityScriptEvent() {
public ElementTag jump;
public ElementTag dismount;

public Consumer<Boolean> modifyCancellation;

@Override
public void cancellationChanged() {
modifyCancellation.accept(cancelled);
}

@Override
public boolean couldMatch(ScriptPath path) {
return path.eventArgLowerAt(1).startsWith("steers");
Expand Down
Expand Up @@ -1181,6 +1181,7 @@ public static void registerTags() {
// @description
// Returns what items the block at the location would drop if broken naturally.
// Optionally specifier a breaker item.
// Not guaranteed to contain exactly correct or contain all possible drops (for things like plants that drop only when grown, ores that drop random amounts, etc).
// -->
registerTag("drops", (attribute, object) -> {
ItemStack inputItem = null;
Expand Down
Expand Up @@ -53,6 +53,7 @@ public Boolean call() throws Exception {
event.jump = new ElementTag(steerVehicle.getJumpInput());
event.dismount = new ElementTag(steerVehicle.getDismountInput());
event.cancelled = false;
event.modifyCancellation = (c) -> event.cancelled = c;
event.fire();
return event.cancelled;
}
Expand Down Expand Up @@ -106,17 +107,12 @@ public Boolean call() throws Exception {
event.message = new ElementTag(chat.getMessage());
event.rawJson = new ElementTag(chat.getRawJson());
event.system = new ElementTag(pos == 1);
event.messageModified = false;
event.rawJsonModified = false;
event.player = PlayerTag.mirrorBukkitPlayer(player);
event.modifyMessage = chat::setMessage;
event.modifyRawJson = chat::setRawJson;
event.cancelled = false;
event.modifyCancellation = (c) -> event.cancelled = c;
event.fire();
if (event.messageModified) {
chat.setMessage(event.message.asString());
}
else if (event.rawJsonModified) {
chat.setRawJson(event.rawJson.asString());
}
return event.cancelled;
}
return false;
Expand Down

0 comments on commit 0ea65f2

Please sign in to comment.