Skip to content

Commit

Permalink
partial event cleanup related to last core commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 16, 2021
1 parent 5d7c49e commit 5660498
Show file tree
Hide file tree
Showing 46 changed files with 225 additions and 338 deletions.
Expand Up @@ -92,12 +92,9 @@ public String getName() {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (!isDefaultDetermination(determinationObj)) {
String determination = determinationObj.toString();
if (LocationTag.matches(determination)) {
event.getAcceleration().copy((LocationTag.valueOf(determination, getTagContext(path))).toVector());
return true;
}
if (determinationObj.canBeType(LocationTag.class)) {
event.getAcceleration().copy(determinationObj.asType(LocationTag.class, getTagContext(path)).toVector());
return true;
}
return super.applyDetermination(path, determinationObj);
}
Expand Down
Expand Up @@ -86,7 +86,7 @@ public ScriptEntryData getScriptEntryData() {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && !isDefaultDetermination(determinationObj)) {
if (determinationObj instanceof ElementTag) {
String lower = CoreUtilities.toLowerCase(determinationObj.toString());
if (lower.equals("keep_item")) {
event.setConsumeItem(false);
Expand Down
Expand Up @@ -71,15 +71,13 @@ public String getName() {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (!isDefaultDetermination(determinationObj)) {
try {
event.setEffect(ItemPotion.parseEffect(determinationObj.toString(), getTagContext(path)));
}
catch (Exception e) {
Debug.echoError(e);
}
try {
event.setEffect(ItemPotion.parseEffect(determinationObj.toString(), getTagContext(path)));
return true;
}
catch (Exception e) {
Debug.echoError(e);
}
return super.applyDetermination(path, determinationObj);
}

Expand Down
Expand Up @@ -21,30 +21,28 @@ public class ServerListPingScriptEventPaperImpl extends ListPingScriptEvent {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (!isDefaultDetermination(determinationObj)) {
String determination = determinationObj.toString();
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("protocol_version:") && ArgumentHelper.matchesInteger(determination.substring("protocol_version:".length()))) {
((PaperServerListPingEvent) event).setProtocolVersion(Integer.parseInt(determination.substring("protocol_version:".length())));
return true;
}
else if (lower.startsWith("version_name:")) {
((PaperServerListPingEvent) event).setVersion(determination.substring("version_name:".length()));
return true;
String determination = determinationObj.toString();
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("protocol_version:") && ArgumentHelper.matchesInteger(determination.substring("protocol_version:".length()))) {
((PaperServerListPingEvent) event).setProtocolVersion(Integer.parseInt(determination.substring("protocol_version:".length())));
return true;
}
else if (lower.startsWith("version_name:")) {
((PaperServerListPingEvent) event).setVersion(determination.substring("version_name:".length()));
return true;
}
else if (lower.startsWith("exclude_players:")) {
HashSet<UUID> exclusions = new HashSet<>();
for (PlayerTag player : ListTag.valueOf(determination.substring("exclude_players:".length()), getTagContext(path)).filter(PlayerTag.class, getTagContext(path))) {
exclusions.add(player.getUUID());
}
else if (lower.startsWith("exclude_players:")) {
HashSet<UUID> exclusions = new HashSet<>();
for (PlayerTag player : ListTag.valueOf(determination.substring("exclude_players:".length()), getTagContext(path)).filter(PlayerTag.class, getTagContext(path))) {
exclusions.add(player.getUUID());
}
Iterator<Player> players = ((PaperServerListPingEvent) event).iterator();
while (players.hasNext()) {
if (exclusions.contains(players.next().getUniqueId())) {
players.remove();
}
Iterator<Player> players = ((PaperServerListPingEvent) event).iterator();
while (players.hasNext()) {
if (exclusions.contains(players.next().getUniqueId())) {
players.remove();
}
return true;
}
return true;
}
return super.applyDetermination(path, determinationObj);
}
Expand Down
Expand Up @@ -60,11 +60,9 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {

if (!runInCheck(path, location)) {
return false;
}

String mat2 = path.eventArgLowerAt(4);
if (mat2.length() > 0 && !tryMaterial(old_material, mat2)) {
return false;
Expand All @@ -87,8 +85,8 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String lower = CoreUtilities.toLowerCase(determination);
if (lower.equals("buildable")) {
cancelled = false;
return true;
}
return true;
}
return super.applyDetermination(path, determinationObj);
}
Expand All @@ -102,12 +100,9 @@ public void cancellationChanged() {
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "location":
return location;
case "new_material":
return new_material;
case "old_material":
return old_material;
case "location": return location;
case "new_material": return new_material;
case "old_material": return old_material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -53,16 +53,13 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {

if (!runInCheck(path, location)) {
return false;
}

if (!tryMaterial(material, path.eventArgLowerAt(0))) {
return false;
}
return super.matches(path);

}

@Override
Expand All @@ -72,11 +69,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
switch (name) {
case "location": return location;
case "material": return material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -3,7 +3,6 @@
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down Expand Up @@ -89,31 +88,24 @@ public String getName() {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (ArgumentHelper.matchesDouble(determination)) {
Deprecations.blockDispensesItemDetermination.warn();
event.setVelocity(event.getVelocity().multiply(Double.parseDouble(determination)));
return true;
}
else if (LocationTag.matches(determination)) {
LocationTag vel = LocationTag.valueOf(determination, getTagContext(path));
if (vel == null) {
Debug.echoError("[" + getName() + "] Invalid velocity '" + determination + "'!");
}
else {
if (determinationObj.canBeType(LocationTag.class)) {
LocationTag vel = determinationObj.asType(LocationTag.class, getTagContext(path));
if (vel != null) {
event.setVelocity(vel.toVector());
return true;
}
return true;
}
else if (ItemTag.matches(determination)) {
ItemTag it = ItemTag.valueOf(determination, path.container);
if (it == null) {
Debug.echoError("[" + getName() + "] Invalid item '" + determination + "'!");
}
else {
if (determinationObj.canBeType(ItemTag.class)) {
ItemTag it = determinationObj.asType(ItemTag.class, getTagContext(path));
if (it != null) {
item = it;
event.setItem(item.getItemStack());
return true;
}
}
if (ArgumentHelper.matchesDouble(determinationObj.toString())) {
Deprecations.blockDispensesItemDetermination.warn();
event.setVelocity(event.getVelocity().multiply(Double.parseDouble(determinationObj.toString())));
return true;
}
return super.applyDetermination(path, determinationObj);
Expand All @@ -122,12 +114,9 @@ else if (ItemTag.matches(determination)) {
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "location":
return location;
case "item":
return item;
case "velocity":
return new LocationTag(event.getVelocity());
case "location": return location;
case "item": return item;
case "velocity": return new LocationTag(event.getVelocity());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -102,18 +102,16 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {

@Override
public ObjectTag getContext(String name) {
if (name.equals("block")) {
return new LocationTag(event.getBlock().getLocation());
}
if (name.equals("blocks")) {
ListTag blocks = new ListTag();
for (Block block : this.blocks) {
blocks.addObject(new LocationTag(block.getLocation()));
switch (name) {
case "block": return new LocationTag(event.getBlock().getLocation());
case "blocks": {
ListTag blocks = new ListTag();
for (Block block : this.blocks) {
blocks.addObject(new LocationTag(block.getLocation()));
}
return blocks;
}
return blocks;
}
else if (name.equals("strength")) {
return new ElementTag(event.getYield());
case "strength": return new ElementTag(event.getYield());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -70,11 +70,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
switch (name) {
case "location": return location;
case "material": return material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -72,11 +72,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("entity")) {
return new EntityTag(event.getEntity());
switch (name) {
case "location": return location;
case "entity": return new EntityTag(event.getEntity());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -70,11 +70,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
switch (name) {
case "location": return location;
case "material": return material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -95,11 +95,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
switch (name) {
case "location": return location;
case "material": return material;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -74,20 +74,20 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return new MaterialTag(event.getBlock());
}
else if (name.equals("entity") && event.getIgnitingEntity() != null) {
return new EntityTag(event.getIgnitingEntity());
}
else if (name.equals("origin_location") && event.getIgnitingBlock() != null) {
return new LocationTag(event.getIgnitingBlock().getLocation());
}
else if (name.equals("cause")) {
return cause;
switch (name) {
case "location": return location;
case "material": return new MaterialTag(event.getBlock());
case "cause": return cause;
case "entity":
if (event.getIgnitingEntity() != null) {
return new EntityTag(event.getIgnitingEntity()).getDenizenObject();
}
break;
case "origin_location":
if (event.getIgnitingBlock() != null) {
return new LocationTag(event.getIgnitingBlock().getLocation());
}
break;
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -73,11 +73,9 @@ public String getName() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("new_material")) {
return new MaterialTag(event.getChangedType());
switch (name) {
case "location": return location;
case "new_material": return new MaterialTag(event.getChangedType());
}
return super.getContext(name);
}
Expand Down
Expand Up @@ -80,12 +80,9 @@ public String getName() {
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "location":
return location;
case "material":
return material;
case "source_location":
return new LocationTag(event.getBlock().getLocation());
case "location": return location;
case "material": return material;
case "source_location": return new LocationTag(event.getBlock().getLocation());
}
return super.getContext(name);
}
Expand Down

0 comments on commit 5660498

Please sign in to comment.