From dc91fdcac98253a845d6182c3310809459fec7fb Mon Sep 17 00:00:00 2001 From: Iosnowore Date: Thu, 6 Apr 2017 17:15:08 -0700 Subject: [PATCH 1/4] Fixed JIRA bug NGE-563 https://projectswg.atlassian.net/browse/NGE-563 --- .../callbacks/TransferItemCallback.java | 102 +++++++++--------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/src/resources/commands/callbacks/TransferItemCallback.java b/src/resources/commands/callbacks/TransferItemCallback.java index e0243af2e..edc2a9c6d 100644 --- a/src/resources/commands/callbacks/TransferItemCallback.java +++ b/src/resources/commands/callbacks/TransferItemCallback.java @@ -52,11 +52,11 @@ public class TransferItemCallback implements ICmdCallback { new ChatBroadcastIntent(player, "@container_error_message:container29").broadcast(); return; } - + CreatureObject actor = player.getCreatureObject(); - + // You can't transfer your own creature - if(actor.equals(target)) { + if (actor.equals(target)) { new ChatBroadcastIntent(player, "@container_error_message:container17").broadcast(); return; } @@ -69,87 +69,89 @@ public class TransferItemCallback implements ICmdCallback { SWGObject newContainer = galacticManager.getObjectManager().getObjectById(Long.valueOf(args.split(" ")[1])); // Lookup failed, their client gave us an object ID that isn't mapped to an object - if(newContainer == null) { + if (newContainer == null) { new ChatBroadcastIntent(player, "@container_error_message:container15").broadcast(); return; } - + // You can't add something to itself if (target.equals(newContainer)) { new ChatBroadcastIntent(player, "@container_error_message:container02").broadcast(); return; } - + // You can't move an object to a container that it's already inside if (oldContainer.equals(newContainer)) { new ChatBroadcastIntent(player, "@container_error_message:container11").broadcast(); return; } - - SWGObject appearanceInventory = actor.getSlottedObject("appearance_inventory"); - - Assert.notNull(appearanceInventory); - - // TODO move check to CommandService. There's an in-combat boolean column in the command table! - // You can't equip or unequip non-weapon equipment whilst in combat - if (!weapon && actor.isInCombat() && ((newContainer.equals(actor) || oldContainer.equals(actor)) || (newContainer.equals(appearanceInventory) || oldContainer.equals(appearanceInventory)))) { - new ChatBroadcastIntent(player, "@base_player:not_while_in_combat").broadcast(); - return; - } - // A container can only be the child of another container if the other container has a larger volume - if (newContainer.getContainerType() == 2 && target.getContainerType() == 2 && target.getMaxContainerSize()>= newContainer.getMaxContainerSize()) { + SWGObject appearanceInventory = actor.getSlottedObject("appearance_inventory"); + + Assert.notNull(appearanceInventory); + + // A container can only be the child of another container if the + // other container has a larger volume + if (newContainer.getContainerType() == 2 && target.getContainerType() == 2 + && target.getMaxContainerSize() >= newContainer.getMaxContainerSize()) { new ChatBroadcastIntent(player, "@container_error_message:container12").broadcast(); return; } - + // We can't transfer an item into an appearance-equipped container! SWGObject containerParent = newContainer.getParent(); - + if (containerParent != null && containerParent.equals(appearanceInventory)) { // Don't be fooled - the message below contains no prose keys new ChatBroadcastIntent(player, "@container_error_message:container34_prose").broadcast(); return; } - // If armour, they must have the "wear_all_armor" ability - if (target.getAttribute("armor_category") != null && !actor.hasAbility("wear_all_armor")) { - new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); - return; + // Check if item is being equipped + if (newContainer.equals(actor)) { + // If armor, they must have the "wear_all_armor" ability + if (target.getAttribute("armor_category") != null && !actor.hasAbility("wear_all_armor")) { + new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); + return; + } + + // Check the players level, if they're too low of a level, don't allow them to wear it + String reqLevelStr = target.getAttribute("required_combat_level"); + + if (reqLevelStr != null) { + short reqLevel = Short.parseShort(reqLevelStr); + if (actor.getLevel() < reqLevel) { + new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); + return; + } + } + + // Make sure the player can wear it based on their species + if (newContainer.equals(actor) && !checkSpeciesRestriction(actor, target)) + return; + + // If the character doesn't have the right profession, reject it + if (newContainer.equals(actor) && target.hasAttribute("class_required") + && !target.getAttribute("class_required").equals("None")) { + String profession = cleanProfessionString(actor.getPlayerObject().getProfession()); + if (!target.getAttribute("class_required").contains(profession)) { + new ChatBroadcastIntent(player, "@base_player:cannot_use_item").broadcast(); + return; + } + } } // Only empty containers can be Appearance Equipped if (newContainer.equals(appearanceInventory)) { - if(targetGameObjectType == GameObjectType.GOT_MISC_CONTAINER_WEARABLE && !target.getContainedObjects().isEmpty()) { - // Don't be fooled - the message below contains no prose keys + if (targetGameObjectType == GameObjectType.GOT_MISC_CONTAINER_WEARABLE + && !target.getContainedObjects().isEmpty()) { + // Don't be fooled - the message below contains no prose + // keys new ChatBroadcastIntent(player, "@container_error_message:container33_prose").broadcast(); return; } } - // Check the players level, if they're too low of a level, don't allow them to wear it - String reqLevelStr = target.getAttribute("required_combat_level"); - - if (reqLevelStr != null) { - short reqLevel = Short.parseShort(reqLevelStr); - if (actor.getLevel() < reqLevel) { - new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); - return; - } - } - - // Make sure the player can wear it based on their species - if (!checkSpeciesRestriction(actor, target)) - return; - - // If the character doesn't have the right profession, reject it - if (target.hasAttribute("class_required") && !target.getAttribute("class_required").equals("None")) { - String profession = cleanProfessionString(actor.getPlayerObject().getProfession()); - if (!target.getAttribute("class_required").contains(profession)) { - new ChatBroadcastIntent(player, "@base_player:cannot_use_item").broadcast(); - return; - } - } switch (target.moveToContainer(actor, newContainer)) { case SUCCESS: if (weapon) { From 52dda3b2c602f3876317ccf345a8e43e76341b1d Mon Sep 17 00:00:00 2001 From: Iosnowore Date: Thu, 6 Apr 2017 17:22:41 -0700 Subject: [PATCH 2/4] Reverted Eclipse auto indent --- src/resources/commands/callbacks/TransferItemCallback.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/resources/commands/callbacks/TransferItemCallback.java b/src/resources/commands/callbacks/TransferItemCallback.java index edc2a9c6d..9fb66d7f3 100644 --- a/src/resources/commands/callbacks/TransferItemCallback.java +++ b/src/resources/commands/callbacks/TransferItemCallback.java @@ -90,10 +90,8 @@ public class TransferItemCallback implements ICmdCallback { Assert.notNull(appearanceInventory); - // A container can only be the child of another container if the - // other container has a larger volume - if (newContainer.getContainerType() == 2 && target.getContainerType() == 2 - && target.getMaxContainerSize() >= newContainer.getMaxContainerSize()) { + // A container can only be the child of another container if the other container has a larger volume + if (newContainer.getContainerType() == 2 && target.getContainerType() == 2 && target.getMaxContainerSize() >= newContainer.getMaxContainerSize()) { new ChatBroadcastIntent(player, "@container_error_message:container12").broadcast(); return; } From da999be3307fecfef14f87be5773b10eb62cd151 Mon Sep 17 00:00:00 2001 From: Iosnowore Date: Thu, 6 Apr 2017 17:27:27 -0700 Subject: [PATCH 3/4] Minor cleanup --- .../commands/callbacks/TransferItemCallback.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/resources/commands/callbacks/TransferItemCallback.java b/src/resources/commands/callbacks/TransferItemCallback.java index 9fb66d7f3..bbd2493e8 100644 --- a/src/resources/commands/callbacks/TransferItemCallback.java +++ b/src/resources/commands/callbacks/TransferItemCallback.java @@ -116,21 +116,17 @@ public class TransferItemCallback implements ICmdCallback { // Check the players level, if they're too low of a level, don't allow them to wear it String reqLevelStr = target.getAttribute("required_combat_level"); - if (reqLevelStr != null) { - short reqLevel = Short.parseShort(reqLevelStr); - if (actor.getLevel() < reqLevel) { - new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); - return; - } + if (reqLevelStr != null && actor.getLevel() < Short.parseShort(reqLevelStr)) { + new ChatBroadcastIntent(player, "@base_player:level_too_low").broadcast(); + return; } // Make sure the player can wear it based on their species - if (newContainer.equals(actor) && !checkSpeciesRestriction(actor, target)) + if (!checkSpeciesRestriction(actor, target)) return; // If the character doesn't have the right profession, reject it - if (newContainer.equals(actor) && target.hasAttribute("class_required") - && !target.getAttribute("class_required").equals("None")) { + if (target.hasAttribute("class_required") && !target.getAttribute("class_required").equals("None")) { String profession = cleanProfessionString(actor.getPlayerObject().getProfession()); if (!target.getAttribute("class_required").contains(profession)) { new ChatBroadcastIntent(player, "@base_player:cannot_use_item").broadcast(); From 8751f6f8e505bc253b14d588c0402d79d49ed6b2 Mon Sep 17 00:00:00 2001 From: Iosnowore Date: Thu, 6 Apr 2017 17:28:07 -0700 Subject: [PATCH 4/4] Autoindent fix --- src/resources/commands/callbacks/TransferItemCallback.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/resources/commands/callbacks/TransferItemCallback.java b/src/resources/commands/callbacks/TransferItemCallback.java index bbd2493e8..6155cc9bf 100644 --- a/src/resources/commands/callbacks/TransferItemCallback.java +++ b/src/resources/commands/callbacks/TransferItemCallback.java @@ -137,10 +137,8 @@ public class TransferItemCallback implements ICmdCallback { // Only empty containers can be Appearance Equipped if (newContainer.equals(appearanceInventory)) { - if (targetGameObjectType == GameObjectType.GOT_MISC_CONTAINER_WEARABLE - && !target.getContainedObjects().isEmpty()) { - // Don't be fooled - the message below contains no prose - // keys + if (targetGameObjectType == GameObjectType.GOT_MISC_CONTAINER_WEARABLE && !target.getContainedObjects().isEmpty()) { + // Don't be fooled - the message below contains no prose keys new ChatBroadcastIntent(player, "@container_error_message:container33_prose").broadcast(); return; }