Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some helpful changes #981

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 44 additions & 0 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,12 @@ public boolean chat(String message) {
this.resetCraftingGridType();
this.craftingType = CRAFTING_SMALL;

// adding command execution like in Nukkit-DOC -> see above
if(message.startsWith("/")) {
Copy link
Member

Choose a reason for hiding this comment

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

But why?

Copy link
Author

Choose a reason for hiding this comment

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

i just think player.chat("/say hi"); is better and faster written then player.getServer().dispatchCommand(player, "say hi"); and its written in the javadoc if a message starts with / in player.chat method it would be dispatched as command... :)

Copy link
Member

@SupremeMortal SupremeMortal Nov 28, 2019

Choose a reason for hiding this comment

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

That doc comment looks like a mistake when commands were given their own packet in 1.2

this.server.dispatchCommand(this, message.substring(1));
return true;
}

if (this.removeFormat) {
message = TextFormat.clean(message, true);
}
Expand Down Expand Up @@ -3385,6 +3391,44 @@ public void setViewDistance(int distance) {
this.dataPacket(pk);
}

/**
* Get an Array with nearby Players in a defined radius around the Player
* @param radiusX
* @param radiusY
* @param radiusZ
* @return nearByPlayers
*/
public Player[] getNearByPlayers(int radiusX, int radiusY, int radiusZ) {
AxisAlignedBB axisalignedbb = new SimpleAxisAlignedBB(this.x - radiusX, this.y - radiusY, this.z - radiusZ, this.x + radiusX, this.y + radiusY, this.z + radiusZ);
Entity[] nearByEntities = this.level.getNearbyEntities(axisalignedbb, this);
int i = 0;
for(Entity entity : nearByEntities) {
if(!(entity instanceof Player)) continue;
i++;
}
Player[] nearByPlayers = new Player[(i+1)];
int x = 0;
for(Entity entity : nearByEntities) {
if(!(entity instanceof Player)) continue;
nearByPlayers[x] = (Player)entity;
x++;
}
return nearByPlayers;
}

/**
* Get an Array with nearby Entities in a defined radius around the Player
* @param radiusX
* @param radiusY
* @param radiusZ
* @return nearbyEntities
*/
public Entity[] getNearByEntities(int radiusX, int radiusY, int radiusZ) {
AxisAlignedBB axisalignedbb = new SimpleAxisAlignedBB(this.x - radiusX, this.y - radiusY, this.z - radiusZ, this.x + radiusX, this.y + radiusY, this.z + radiusZ);
return this.level.getNearbyEntities(axisalignedbb, this);
}


public int getViewDistance() {
return this.chunkRadius;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/cn/nukkit/permission/PermissibleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public boolean isPermissionSet(Permission permission) {

@Override
public boolean hasPermission(String name) {

// Adding * permission support and negative permissions for * user to remove some perms
if(this.isPermissionSet("*") && ((PermissionAttachmentInfo)this.permissions.get("*")).getValue()){
if(this.isPermissionSet("-" + name) && ((PermissionAttachmentInfo)this.permissions.get("-" + name)).getValue()){
return false;
}else{
return true;
}
}

if (this.isPermissionSet(name)) {
return this.permissions.get(name).getValue();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang
Submodule lang updated from e39cda to c63baf