Skip to content

Commit

Permalink
Add functions to hide entities from players
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Feb 28, 2024
1 parent 170ebbb commit 7c64252
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye

void setVanished(boolean set, MCPlayer to);

void hideEntity(MCEntity entity);

void showEntity(MCEntity entity);

boolean canSeeEntity(MCEntity entity);

boolean isNewPlayer();

String getHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,34 @@ public void setVanished(boolean set, MCPlayer to) {
}
}

@Override
public void hideEntity(MCEntity entity) {
try {
p.hideEntity(CommandHelperPlugin.self, (Entity) entity.getHandle());
} catch(NoSuchMethodError ex) {
// probably before 1.18
}
}

@Override
public void showEntity(MCEntity entity) {
try {
p.showEntity(CommandHelperPlugin.self, (Entity) entity.getHandle());
} catch(NoSuchMethodError ex) {
// probably before 1.18
}
}

@Override
public boolean canSeeEntity(MCEntity entity) {
try {
return p.canSee((Entity) entity.getHandle());
} catch(NoSuchMethodError ex) {
// probably before 1.18
return true;
}
}

@Override
public void setWhitelisted(boolean value) {
p.setWhitelisted(value);
Expand Down
167 changes: 167 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6888,4 +6888,171 @@ public Boolean runAsync() {
return false;
}
}

@api
public static class phide_entity extends AbstractFunction {

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

@Override
public String docs() {
return "void {[player], entityUUID} Sets an entity to no longer be seen or tracked by the player's client."
+ " Resets to default on player rejoin."
+ " (MC 1.18+)";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1, 2};
}

@Override
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
MCPlayer p;
MCEntity e;
if(args.length == 1) {
p = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
Static.AssertPlayerNonNull(p, t);
e = Static.getEntity(args[0], t);
} else {
p = Static.GetPlayer(args[0], t);
e = Static.getEntity(args[1], t);
}
p.hideEntity(e);
return CVoid.VOID;
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREBadEntityException.class};
}

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

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}
}

@api
public static class pshow_entity extends AbstractFunction {

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

@Override
public String docs() {
return "void {[player], entityUUID} Sets an entity to be sent to the player's client again. (MC 1.18+)";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1, 2};
}

@Override
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
MCPlayer p;
MCEntity e;
if(args.length == 1) {
p = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
Static.AssertPlayerNonNull(p, t);
e = Static.getEntity(args[0], t);
} else {
p = Static.GetPlayer(args[0], t);
e = Static.getEntity(args[1], t);
}
p.showEntity(e);
return CVoid.VOID;
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREBadEntityException.class};
}

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

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}
}

@api
public static class pcan_see_entity extends AbstractFunction {

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

@Override
public String docs() {
return "boolean {[player], entityUUID} Gets whether the entity is known by the player's client or"
+ " hidden by a plugin. (MC 1.18+)";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1, 2};
}

@Override
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
MCPlayer p;
MCEntity e;
if(args.length == 1) {
p = env.getEnv(CommandHelperEnvironment.class).GetPlayer();
Static.AssertPlayerNonNull(p, t);
e = Static.getEntity(args[0], t);
} else {
p = Static.GetPlayer(args[0], t);
e = Static.getEntity(args[1], t);
}
return CBoolean.get(p.canSeeEntity(e));
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREBadEntityException.class};
}

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

@Override
public boolean isRestricted() {
return true;
}

@Override
public Boolean runAsync() {
return false;
}
}
}

0 comments on commit 7c64252

Please sign in to comment.