|
39 | 39 | import com.laytonsmith.abstraction.events.MCEntityRegainHealthEvent; |
40 | 40 | import com.laytonsmith.abstraction.events.MCEntityTargetEvent; |
41 | 41 | import com.laytonsmith.abstraction.events.MCEntityToggleGlideEvent; |
| 42 | +import com.laytonsmith.abstraction.events.MCEntityToggleSwimEvent; |
42 | 43 | import com.laytonsmith.abstraction.events.MCEntityUnleashEvent; |
43 | 44 | import com.laytonsmith.abstraction.events.MCEntityPotionEffectEvent; |
44 | 45 | import com.laytonsmith.abstraction.events.MCFireworkExplodeEvent; |
|
68 | 69 | import com.laytonsmith.core.constructs.Target; |
69 | 70 | import com.laytonsmith.core.environments.Environment; |
70 | 71 | import com.laytonsmith.core.events.AbstractEvent; |
| 72 | +import com.laytonsmith.core.events.AbstractGenericEvent; |
71 | 73 | import com.laytonsmith.core.events.BindableEvent; |
72 | 74 | import com.laytonsmith.core.events.BoundEvent; |
73 | 75 | import com.laytonsmith.core.events.BoundEvent.ActiveEvent; |
74 | 76 | import com.laytonsmith.core.events.Driver; |
75 | 77 | import com.laytonsmith.core.events.EventBuilder; |
76 | 78 | import com.laytonsmith.core.events.Prefilters; |
77 | 79 | import com.laytonsmith.core.events.Prefilters.PrefilterType; |
| 80 | +import com.laytonsmith.core.events.prefilters.OptionalPlayerPrefilterMatcher; |
| 81 | +import com.laytonsmith.core.events.prefilters.PrefilterBuilder; |
| 82 | +import com.laytonsmith.core.events.prefilters.StringICPrefilterMatcher; |
78 | 83 | import com.laytonsmith.core.exceptions.CRE.CREBadEntityException; |
79 | 84 | import com.laytonsmith.core.exceptions.CRE.CREBindException; |
80 | 85 | import com.laytonsmith.core.exceptions.CRE.CRECastException; |
@@ -2053,6 +2058,99 @@ public Driver driver() { |
2053 | 2058 | } |
2054 | 2059 | } |
2055 | 2060 |
|
| 2061 | + @api |
| 2062 | + public static class entity_toggle_swim extends AbstractGenericEvent<MCEntityToggleSwimEvent> { |
| 2063 | + |
| 2064 | + @Override |
| 2065 | + public String getName() { |
| 2066 | + return "entity_toggle_swim"; |
| 2067 | + } |
| 2068 | + |
| 2069 | + @Override |
| 2070 | + public String docs() { |
| 2071 | + return "{type: <macro> The entity type of the entity | id: <macro> The entity id of the entity" |
| 2072 | + + " | player: <macro> The player triggering the event}" |
| 2073 | + + " This event is called when an entity's swimming status is toggled" |
| 2074 | + + " {id: The entityID of the entity | type: The entity type of the entity |" |
| 2075 | + + " swimming: true if the entity is entering swimming mode, false if the entity is leaving it |" |
| 2076 | + + " player: If the entity is a player, this will contain their name, otherwise null}" + " {}" |
| 2077 | + + " {}"; |
| 2078 | + } |
| 2079 | + |
| 2080 | + |
| 2081 | + @Override |
| 2082 | + protected PrefilterBuilder getPrefilterBuilder() { |
| 2083 | + return new PrefilterBuilder<MCEntityToggleSwimEvent>() |
| 2084 | + .set("player", "The player that toggled swimming", new OptionalPlayerPrefilterMatcher<>()) |
| 2085 | + .set("type", "The entity type of the entity that toggled swimming", new StringICPrefilterMatcher<>() { |
| 2086 | + @Override |
| 2087 | + protected String getProperty(MCEntityToggleSwimEvent event) { |
| 2088 | + return event.getEntityType().name(); |
| 2089 | + } |
| 2090 | + }) |
| 2091 | + .set("id", "The ID of the entity that toggled swimming", new StringICPrefilterMatcher<>() { |
| 2092 | + @Override |
| 2093 | + protected String getProperty(MCEntityToggleSwimEvent event) { |
| 2094 | + return event.getEntity().getUniqueId().toString(); |
| 2095 | + } |
| 2096 | + }); |
| 2097 | + } |
| 2098 | + |
| 2099 | + @Override |
| 2100 | + public MCEntityToggleSwimEvent convert(CArray manualObject, Target t) { |
| 2101 | + return null; |
| 2102 | + } |
| 2103 | + |
| 2104 | + @Override |
| 2105 | + public Map<String, Mixed> evaluate(MCEntityToggleSwimEvent e) throws EventException { |
| 2106 | + Map<String, Mixed> ret = evaluate_helper(e); |
| 2107 | + Target t = Target.UNKNOWN; |
| 2108 | + |
| 2109 | + ret.put("swimming", CBoolean.GenerateCBoolean(e.isSwimming(), t)); |
| 2110 | + ret.put("id", new CString(e.getEntity().getUniqueId().toString(), t)); |
| 2111 | + ret.put("type", new CString(e.getEntityType().name(), t)); |
| 2112 | + |
| 2113 | + if(e.getEntity() instanceof MCPlayer) { |
| 2114 | + ret.put("player", new CString(((MCPlayer) e.getEntity()).getName(), t)); |
| 2115 | + } else { |
| 2116 | + ret.put("player", CNull.NULL); |
| 2117 | + } |
| 2118 | + |
| 2119 | + return ret; |
| 2120 | + } |
| 2121 | + |
| 2122 | + @Override |
| 2123 | + public boolean modifyEvent(String key, Mixed value, MCEntityToggleSwimEvent event) throws ConfigRuntimeException { |
| 2124 | + return false; |
| 2125 | + } |
| 2126 | + |
| 2127 | + @Override |
| 2128 | + public Version since() { |
| 2129 | + return MSVersion.V3_3_5; |
| 2130 | + } |
| 2131 | + |
| 2132 | + @Override |
| 2133 | + public Driver driver() { |
| 2134 | + return Driver.ENTITY_TOGGLE_SWIM; |
| 2135 | + } |
| 2136 | + |
| 2137 | + @Override |
| 2138 | + public void cancel(MCEntityToggleSwimEvent o, boolean state) { |
| 2139 | + } |
| 2140 | + |
| 2141 | + @Override |
| 2142 | + public boolean isCancellable(MCEntityToggleSwimEvent o) { |
| 2143 | + // Deprecated |
| 2144 | + // https://jd.papermc.io/paper/1.21.5/org/bukkit/event/entity/EntityToggleSwimEvent.html#setCancelled(boolean) |
| 2145 | + return false; |
| 2146 | + } |
| 2147 | + |
| 2148 | + @Override |
| 2149 | + public boolean isCancelled(MCEntityToggleSwimEvent o) { |
| 2150 | + return false; |
| 2151 | + } |
| 2152 | + } |
| 2153 | + |
2056 | 2154 | @api |
2057 | 2155 | public static class firework_explode extends AbstractEvent { |
2058 | 2156 |
|
|
0 commit comments