mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-17 07:02:54 -04:00
Merged in M4SS/holocore/permissions_fix (pull request #205)
Fixed issues where any in-game object could be picked up and being able to exceed container volume limits
This commit is contained in:
@@ -1,24 +1,33 @@
|
||||
function executeCommand(galacticManager, player, target, args) {
|
||||
var actor = player.getCreatureObject();
|
||||
var inventory;
|
||||
var oldContainer = target.getParent();
|
||||
|
||||
if(actor === null || target === null || actor === target) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newContainer = galacticManager.getObjectManager().getObjectById(args.split(" ")[1]);
|
||||
|
||||
if(actor == null || target == null) {
|
||||
return;
|
||||
}
|
||||
var ContainerResult = Java.type("resources.containers.ContainerResult");
|
||||
|
||||
inventory = actor.getSlottedObject("inventory");
|
||||
var containerResult = target.moveToContainer(actor, newContainer);
|
||||
|
||||
if(inventory == null) {
|
||||
return;
|
||||
switch (containerResult) {
|
||||
case ContainerResult.SUCCESS:
|
||||
if (actor.getEquipmentList().contains(target)) {
|
||||
actor.removeEquipment(target);
|
||||
} else if (newContainer === actor) {
|
||||
actor.addEquipment(target);
|
||||
}
|
||||
break;
|
||||
case ContainerResult.CONTAINER_FULL:
|
||||
// TODO container03_prose if container is named
|
||||
intentFactory.sendSystemMessage(player, "@container_error_message:container03");
|
||||
break;
|
||||
case ContainerResult.NO_PERMISSION:
|
||||
// TODO container08_prose if container is named
|
||||
intentFactory.sendSystemMessage(player, "@container_error_message:container08");
|
||||
break;
|
||||
default:
|
||||
print("Unhandled ContainerResult " + containerResult + " in transferItemMisc!");
|
||||
break;
|
||||
}
|
||||
|
||||
result = target.moveToContainer(actor, newContainer); // Move item from the old container to the new container
|
||||
if (actor.getEquipmentList().contains(target)) {
|
||||
actor.removeEquipment(target);
|
||||
} else if (newContainer == actor) {
|
||||
actor.addEquipment(target);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +1,33 @@
|
||||
function executeCommand(galacticManager, player, target, args) {
|
||||
var actor = player.getCreatureObject();
|
||||
var inventory;
|
||||
var oldContainer = target.getParent();
|
||||
|
||||
if(actor === null || target === null || actor === target) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newContainer = galacticManager.getObjectManager().getObjectById(args.split(" ")[1]);
|
||||
|
||||
if(actor == null || target == null) {
|
||||
return;
|
||||
}
|
||||
var ContainerResult = Java.type("resources.containers.ContainerResult");
|
||||
|
||||
inventory = actor.getSlottedObject("inventory");
|
||||
var containerResult = target.moveToContainer(actor, newContainer);
|
||||
|
||||
if(inventory == null) {
|
||||
return;
|
||||
switch (containerResult) {
|
||||
case ContainerResult.SUCCESS:
|
||||
if (actor.getEquipmentList().contains(target)) {
|
||||
actor.removeEquipment(target);
|
||||
} else if (newContainer === actor) {
|
||||
actor.addEquipment(target);
|
||||
}
|
||||
break;
|
||||
case ContainerResult.CONTAINER_FULL:
|
||||
// TODO container03_prose if container is named
|
||||
intentFactory.sendSystemMessage(player, "@container_error_message:container03");
|
||||
break;
|
||||
case ContainerResult.NO_PERMISSION:
|
||||
// TODO container08_prose if container is named
|
||||
intentFactory.sendSystemMessage(player, "@container_error_message:container08");
|
||||
break;
|
||||
default:
|
||||
print("Unhandled ContainerResult " + containerResult + " in transferItemMisc!");
|
||||
break;
|
||||
}
|
||||
|
||||
result = target.moveToContainer(actor, newContainer); // Move item from the old container to the new container
|
||||
if (actor.getEquipmentList().contains(target)) {
|
||||
actor.removeEquipment(target);
|
||||
} else if (newContainer == actor) {
|
||||
actor.addEquipment(target);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -181,11 +181,17 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
* @return {@link ContainerResult}
|
||||
*/
|
||||
public ContainerResult moveToContainer(SWGObject requester, SWGObject container) {
|
||||
// Check if the requester has MOVE permissions for the current container of the object
|
||||
if(!hasPermission(requester, ContainerPermissions.Permission.MOVE)) {
|
||||
return ContainerResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
// Check if the requester has MOVE permissions to the destination container
|
||||
if (!container.hasPermission(requester, ContainerPermissions.Permission.MOVE)) {
|
||||
Log.w("SWGObject", "No permission 'MOVE' for requestor %s with object %s", requester, this);
|
||||
return ContainerResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
|
||||
// Check if object can fit into container or slots
|
||||
int arrangementId = container.getArrangementId(this);
|
||||
if (arrangementId == -1) {
|
||||
@@ -254,7 +260,7 @@ public abstract class SWGObject extends BaselineObject implements Comparable<SWG
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPermission(SWGObject object, ContainerPermissions.Permission... permissions) {
|
||||
if (object == null || object == this || object.getOwner() == getOwner())
|
||||
if (object == null)
|
||||
return true;
|
||||
for (ContainerPermissions.Permission permission : permissions) {
|
||||
switch(permission) {
|
||||
|
||||
Reference in New Issue
Block a user