Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 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 Down
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,14 @@
package com.laytonsmith.abstraction.events;

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

public interface MCEntityToggleSwimEvent extends BindableEvent {

boolean isSwimming();

MCEntity getEntity();

MCEntityType getEntityType();
}
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,6 +69,7 @@
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;
Expand Down Expand Up @@ -2053,6 +2055,91 @@ 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
public boolean matches(Map<String, Mixed> filter, MCEntityToggleSwimEvent e) throws PrefilterNonMatchException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of matches(), override the getPrefilterBuilder() method. This new method is much faster at runtime, and offers additional benefits such as better documentation. There are several examples of this, just search for "getPrefilterBuilder" to see some examples you can learn from (player_chat for instance has been converted), or see the PrefilterBuilder class. Once you implement that method, the matches() method goes away.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it, but for a player that may not exist and the id of the entity didn't appear to have any examples (or I didn't notice). For the new filter I used the documentation from a similar one, as I don't quite understand how their tags work.

MCEntity entity = e.getEntity();
Prefilters.match(filter, "type", entity.getType().name(), Prefilters.PrefilterType.MACRO);
Prefilters.match(filter, "id", entity.getUniqueId().toString(), Prefilters.PrefilterType.MACRO);

if(entity instanceof MCPlayer) {
Prefilters.match(filter, "player", ((MCPlayer) entity).getName(), Prefilters.PrefilterType.MACRO);
}
return true;
}

@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