Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ClientBin/
*.publishsettings
orleans.codegen.cs

# Including strong name files can present a security risk
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

Expand Down Expand Up @@ -324,7 +324,7 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
Expand All @@ -343,4 +343,4 @@ persistence.json
src/main/resources/apps.methodscript.com/tsp-output

# VSCode
.vscode
.vscode/*
14 changes: 14 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"recommendations": [
"redhat.java",
"shengchen.vscode-checkstyle",
"vscjava.vscode-java-debug",
"vscjava.vscode-java-dependency",
"vscjava.vscode-java-pack",
"vscjava.vscode-java-test",
"vscjava.vscode-maven",
],
"unwantedRecommendations": [

]
}
382 changes: 382 additions & 0 deletions .vscode/java-formatter.xml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.checkstyle.configuration": "${workspaceFolder}/checkstyle.xml",
"java.checkstyle.properties": {
"config_loc": "${workspaceFolder}",
},
"java.checkstyle.autocheck": true,
"java.format.settings.url": ".vscode/java-formatter.xml",
"[java]": {
"editor.insertSpaces": false
},
"files.trimTrailingWhitespace": true,
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.laytonsmith.abstraction.events.MCEntityRegainHealthEvent;
import com.laytonsmith.abstraction.events.MCEntityTargetEvent;
import com.laytonsmith.abstraction.events.MCEntityToggleGlideEvent;
import com.laytonsmith.abstraction.events.MCEntityToggleSwimEvent;
import com.laytonsmith.abstraction.events.MCEntityUnleashEvent;
import com.laytonsmith.abstraction.events.MCEntityPotionEffectEvent;
import com.laytonsmith.abstraction.events.MCFireworkExplodeEvent;
Expand Down Expand Up @@ -102,6 +103,7 @@
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.entity.EntityToggleSwimEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
Expand Down Expand Up @@ -917,6 +919,36 @@ public MCEntityType getEntityType() {
}
}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCEntityToggleSwimEvent implements MCEntityToggleSwimEvent {

EntityToggleSwimEvent e;

public BukkitMCEntityToggleSwimEvent(Event e) {
this.e = (EntityToggleSwimEvent) e;
}

@Override
public Object _GetObject() {
return e;
}

@Override
public boolean isSwimming() {
return e.isSwimming();
}

@Override
public MCEntity getEntity() {
return BukkitConvertor.BukkitGetCorrectEntity(e.getEntity());
}

@Override
public MCEntityType getEntityType() {
return BukkitConvertor.BukkitGetCorrectEntity(e.getEntity()).getType();
}
}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCFireworkExplodeEvent implements MCFireworkExplodeEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCEntityPortalEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCEntityRegainHealthEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCEntityToggleGlideEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCEntityToggleSwimEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCEntityUnleashEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCFireworkExplodeEvent;
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents.BukkitMCHangingBreakEvent;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.entity.EntityToggleSwimEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
Expand Down Expand Up @@ -200,6 +202,12 @@ public void onEntityToggleGlide(EntityToggleGlideEvent event) {
EventUtils.TriggerListener(Driver.ENTITY_TOGGLE_GLIDE, "entity_toggle_glide", etge);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityToggleSwim(EntityToggleSwimEvent event) {
BukkitMCEntityToggleSwimEvent etse = new BukkitMCEntityToggleSwimEvent(event);
EventUtils.TriggerListener(Driver.ENTITY_TOGGLE_SWIM, "entity_toggle_swim", etse);
}

@EventHandler(priority = EventPriority.LOWEST)
public void onFireworkExplode(FireworkExplodeEvent event) {
BukkitMCFireworkExplodeEvent fee = new BukkitMCFireworkExplodeEvent(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.core.events.BindableEvent;

public interface MCEntityEvent extends BindableEvent {

MCEntity getEntity();

MCEntityType getEntityType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.laytonsmith.abstraction.events;


public interface MCEntityToggleSwimEvent extends MCEntityEvent {

boolean isSwimming();
}
1 change: 1 addition & 0 deletions src/main/java/com/laytonsmith/core/events/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum Driver {
PROJECTILE_LAUNCH,
TARGET_ENTITY,
ENTITY_TOGGLE_GLIDE,
ENTITY_TOGGLE_SWIM,
FIREWORK_EXPLODE,
/**
* Inventory events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.laytonsmith.abstraction.events.MCEntityRegainHealthEvent;
import com.laytonsmith.abstraction.events.MCEntityTargetEvent;
import com.laytonsmith.abstraction.events.MCEntityToggleGlideEvent;
import com.laytonsmith.abstraction.events.MCEntityToggleSwimEvent;
import com.laytonsmith.abstraction.events.MCEntityUnleashEvent;
import com.laytonsmith.abstraction.events.MCEntityPotionEffectEvent;
import com.laytonsmith.abstraction.events.MCFireworkExplodeEvent;
Expand Down Expand Up @@ -68,13 +69,17 @@
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.events.AbstractEvent;
import com.laytonsmith.core.events.AbstractGenericEvent;
import com.laytonsmith.core.events.BindableEvent;
import com.laytonsmith.core.events.BoundEvent;
import com.laytonsmith.core.events.BoundEvent.ActiveEvent;
import com.laytonsmith.core.events.Driver;
import com.laytonsmith.core.events.EventBuilder;
import com.laytonsmith.core.events.Prefilters;
import com.laytonsmith.core.events.Prefilters.PrefilterType;
import com.laytonsmith.core.events.prefilters.OptionalPlayerPrefilterMatcher;
import com.laytonsmith.core.events.prefilters.PrefilterBuilder;
import com.laytonsmith.core.events.prefilters.StringICPrefilterMatcher;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
import com.laytonsmith.core.exceptions.CRE.CREBindException;
import com.laytonsmith.core.exceptions.CRE.CRECastException;
Expand Down Expand Up @@ -2053,6 +2058,99 @@ public Driver driver() {
}
}

@api
public static class entity_toggle_swim extends AbstractGenericEvent<MCEntityToggleSwimEvent> {

@Override
public String getName() {
return "entity_toggle_swim";
}

@Override
public String docs() {
return "{type: <macro> The entity type of the entity | id: <macro> The entity id of the entity"
+ " | player: <macro> The player triggering the event}"
+ " This event is called when an entity's swimming status is toggled"
+ " {id: The entityID of the entity | type: The entity type of the entity |"
+ " swimming: true if the entity is entering swimming mode, false if the entity is leaving it |"
+ " player: If the entity is a player, this will contain their name, otherwise null}" + " {}"
+ " {}";
}


@Override
protected PrefilterBuilder getPrefilterBuilder() {
return new PrefilterBuilder<MCEntityToggleSwimEvent>()
.set("player", "The player that toggled swimming", new OptionalPlayerPrefilterMatcher<>())
.set("type", "The entity type of the entity that toggled swimming", new StringICPrefilterMatcher<>() {
@Override
protected String getProperty(MCEntityToggleSwimEvent event) {
return event.getEntityType().name();
}
})
.set("id", "The ID of the entity that toggled swimming", new StringICPrefilterMatcher<>() {
@Override
protected String getProperty(MCEntityToggleSwimEvent event) {
return event.getEntity().getUniqueId().toString();
}
});
}

@Override
public MCEntityToggleSwimEvent convert(CArray manualObject, Target t) {
return null;
}

@Override
public Map<String, Mixed> evaluate(MCEntityToggleSwimEvent e) throws EventException {
Map<String, Mixed> ret = evaluate_helper(e);
Target t = Target.UNKNOWN;

ret.put("swimming", CBoolean.GenerateCBoolean(e.isSwimming(), t));
ret.put("id", new CString(e.getEntity().getUniqueId().toString(), t));
ret.put("type", new CString(e.getEntityType().name(), t));

if(e.getEntity() instanceof MCPlayer) {
ret.put("player", new CString(((MCPlayer) e.getEntity()).getName(), t));
} else {
ret.put("player", CNull.NULL);
}

return ret;
}

@Override
public boolean modifyEvent(String key, Mixed value, MCEntityToggleSwimEvent event) throws ConfigRuntimeException {
return false;
}

@Override
public Version since() {
return MSVersion.V3_3_5;
}

@Override
public Driver driver() {
return Driver.ENTITY_TOGGLE_SWIM;
}

@Override
public void cancel(MCEntityToggleSwimEvent o, boolean state) {
}

@Override
public boolean isCancellable(MCEntityToggleSwimEvent o) {
// Deprecated
// https://jd.papermc.io/paper/1.21.5/org/bukkit/event/entity/EntityToggleSwimEvent.html#setCancelled(boolean)
return false;
}

@Override
public boolean isCancelled(MCEntityToggleSwimEvent o) {
return false;
}
}

@api
public static class firework_explode extends AbstractEvent {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.laytonsmith.core.events.prefilters;

import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.events.MCEntityEvent;
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.compiler.CompilerEnvironment;
import com.laytonsmith.core.compiler.CompilerWarning;
import com.laytonsmith.core.constructs.CClassType;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.events.prefilters.PlayerPrefilterMatcher.PlayerPrefilterDocs;
import com.laytonsmith.core.exceptions.ConfigCompileException;
import com.laytonsmith.core.exceptions.ConfigCompileGroupException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.natives.interfaces.Mixed;

/**
* A OptionalPlayerPrefilterMatcher is a relatively specialized PrefilterMatcher which only works with MCEntityEvent subtypes.
* It simply checks that entity is a player and matches the player name against the specified input.
*
* @param <T>
*/
public class OptionalPlayerPrefilterMatcher<T extends MCEntityEvent> extends MacroICPrefilterMatcher<T> {

@Override
public PrefilterDocs getDocsObject() {
return new PlayerPrefilterDocs();
}

@Override
public void validate(ParseTree node, CClassType nodeType, Environment env)
throws ConfigCompileException, ConfigCompileGroupException, ConfigRuntimeException {
if(!nodeType.doesExtend(CString.TYPE)) {
env.getEnv(CompilerEnvironment.class).addCompilerWarning(node.getFileOptions(),
new CompilerWarning("Expected a string (player) here, this may not perform as expected.",
node.getTarget(), null));
}
}

@Override
public boolean matches(String key, Mixed value, T event, Target t) {
Object prop = getProperty(event);
if(prop == null) {
return CNull.NULL.equals(value);
}

return super.matches(key, value, event, t);
}

@Override
protected Object getProperty(T event) {
MCEntity entity = event.getEntity();
if(entity instanceof MCPlayer player) {
return player.getName();
}

return null;
}
}