Skip to content

Commit 9db7721

Browse files
committed
Add get|set_entity_killer()
1 parent f0f9d62 commit 9db7721

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {
4343

4444
MCPlayer getKiller();
4545

46+
void setKiller(MCPlayer killer);
47+
4648
double getLastDamage();
4749

4850
MCEntity getLeashHolder();

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCLivingEntity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ public MCPlayer getKiller() {
135135
return new BukkitMCPlayer(killer);
136136
}
137137

138+
@Override
139+
public void setKiller(MCPlayer killer) {
140+
try {
141+
if(killer == null) {
142+
le.setKiller(null);
143+
} else {
144+
le.setKiller((Player) killer.getHandle());
145+
}
146+
} catch(NoSuchMethodError ignore) {
147+
// probably not Paper
148+
}
149+
}
150+
138151
@Override
139152
public double getLastDamage() {
140153
return le.getLastDamage();

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5698,4 +5698,108 @@ public Version since() {
56985698
}
56995699

57005700
}
5701+
5702+
@api
5703+
public static class get_entity_killer extends AbstractFunction {
5704+
5705+
@Override
5706+
public Class<? extends CREThrowable>[] thrown() {
5707+
return new Class[]{CREFormatException.class, CRELengthException.class, CREBadEntityException.class};
5708+
}
5709+
5710+
@Override
5711+
public boolean isRestricted() {
5712+
return true;
5713+
}
5714+
5715+
@Override
5716+
public Boolean runAsync() {
5717+
return false;
5718+
}
5719+
5720+
@Override
5721+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
5722+
MCLivingEntity entity = Static.getLivingEntity(args[0], t);
5723+
MCPlayer killer = entity.getKiller();
5724+
if(killer == null) {
5725+
return CNull.NULL;
5726+
} else {
5727+
return new CString(killer.getName(), t);
5728+
}
5729+
}
5730+
5731+
@Override
5732+
public String getName() {
5733+
return "get_entity_killer";
5734+
}
5735+
5736+
@Override
5737+
public Integer[] numArgs() {
5738+
return new Integer[]{1};
5739+
}
5740+
5741+
@Override
5742+
public String docs() {
5743+
return "string {entityUUID} Gets the player killer of a living entity. Can be null."
5744+
+ " Usually indicates the last player that damaged the entity within the last five seconds.";
5745+
}
5746+
5747+
@Override
5748+
public Version since() {
5749+
return MSVersion.V3_3_5;
5750+
}
5751+
}
5752+
5753+
@api
5754+
public static class set_entity_killer extends AbstractFunction {
5755+
5756+
@Override
5757+
public Class<? extends CREThrowable>[] thrown() {
5758+
return new Class[]{CREFormatException.class, CRELengthException.class, CREBadEntityException.class};
5759+
}
5760+
5761+
@Override
5762+
public boolean isRestricted() {
5763+
return true;
5764+
}
5765+
5766+
@Override
5767+
public Boolean runAsync() {
5768+
return false;
5769+
}
5770+
5771+
@Override
5772+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
5773+
MCLivingEntity entity = Static.getLivingEntity(args[0], t);
5774+
if(args[1] instanceof CNull) {
5775+
entity.setKiller(null);
5776+
} else {
5777+
MCPlayer killer = Static.GetPlayer(args[1], t);
5778+
entity.setKiller(killer);
5779+
}
5780+
return CVoid.VOID;
5781+
}
5782+
5783+
@Override
5784+
public String getName() {
5785+
return "set_entity_killer";
5786+
}
5787+
5788+
@Override
5789+
public Integer[] numArgs() {
5790+
return new Integer[]{2};
5791+
}
5792+
5793+
@Override
5794+
public String docs() {
5795+
return "void {entityUUID, player} Sets the player killer of a living entity. (Paper only)"
5796+
+ " Can be set at any time before the entity dies to change kill attribution for the next five"
5797+
+ " seconds or until it's changed again. Can be set to null.";
5798+
}
5799+
5800+
@Override
5801+
public Version since() {
5802+
return MSVersion.V3_3_5;
5803+
}
5804+
}
57015805
}

0 commit comments

Comments
 (0)