fix 'seeInvisiblePlayers' friendly flag (#491)

This commit is contained in:
Andre Roldan 2021-10-17 01:21:38 -05:00 committed by GitHub
parent 06189ee783
commit fb39fa59f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 4 deletions

View File

@ -28,6 +28,9 @@ public class Team implements PacketGroupingAudience {
private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
private static final byte ALLOW_FRIENDLY_FIRE_BIT = 0x01;
private static final byte SEE_INVISIBLE_PLAYERS_BIT = 0x02;
/**
* A collection of all registered entities who are on the team.
*/
@ -296,6 +299,44 @@ public class Team implements PacketGroupingAudience {
this.sendUpdatePacket();
}
private boolean getFriendlyFlagBit(byte index) {
return (this.friendlyFlags & index) == index;
}
private void setFriendlyFlagBit(byte index, boolean value) {
if (value) {
this.friendlyFlags |= index;
} else {
this.friendlyFlags &= ~index;
}
}
public void setAllowFriendlyFire(boolean value) {
this.setFriendlyFlagBit(ALLOW_FRIENDLY_FIRE_BIT, value);
}
public void updateAllowFriendlyFire(boolean value) {
this.setAllowFriendlyFire(value);
this.sendUpdatePacket();
}
public boolean isAllowFriendlyFire() {
return this.getFriendlyFlagBit(ALLOW_FRIENDLY_FIRE_BIT);
}
public void setSeeInvisiblePlayers(boolean value) {
this.setFriendlyFlagBit(SEE_INVISIBLE_PLAYERS_BIT, value);
}
public void updateSeeInvisiblePlayers(boolean value) {
this.setSeeInvisiblePlayers(value);
this.sendUpdatePacket();
}
public boolean isSeeInvisiblePlayers() {
return this.getFriendlyFlagBit(SEE_INVISIBLE_PLAYERS_BIT);
}
/**
* Gets the registry name of the team.
*

View File

@ -128,7 +128,8 @@ public class TeamBuilder {
* @return this builder, for chaining
*/
public TeamBuilder updateAllowFriendlyFire() {
return this.updateFriendlyFlags((byte) 0x01);
this.team.updateAllowFriendlyFire(true);
return this;
}
/**
@ -137,7 +138,8 @@ public class TeamBuilder {
* @return this builder, for chaining
*/
public TeamBuilder updateSeeInvisiblePlayers() {
return this.updateFriendlyFlags((byte) 0x01);
this.team.updateSeeInvisiblePlayers(true);
return this;
}
/**
@ -239,7 +241,8 @@ public class TeamBuilder {
* @return this builder, for chaining
*/
public TeamBuilder allowFriendlyFire() {
return this.friendlyFlags((byte) 0x01);
this.team.setAllowFriendlyFire(true);
return this;
}
/**
@ -250,7 +253,8 @@ public class TeamBuilder {
* @return this builder, for chaining
*/
public TeamBuilder seeInvisiblePlayers() {
return this.friendlyFlags((byte) 0x01);
this.team.setSeeInvisiblePlayers(true);
return this;
}
/**