From 019e73ead6d054ff713282944e69ba3d6abeb03b Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Tue, 28 Jul 2015 04:46:53 +0200 Subject: [PATCH] Changed the scripting language of Holocore to JavaScript. All scripts have been rewritten. --- scripts/commands/generic/addFriend.js | 18 +++ scripts/commands/generic/addFriend.py | 15 --- scripts/commands/generic/cmdBroadcast.js | 5 + scripts/commands/generic/cmdBroadcast.py | 7 -- scripts/commands/generic/cmdBroadcastArea.js | 5 + scripts/commands/generic/cmdBroadcastArea.py | 7 -- .../commands/generic/cmdBroadcastGalaxy.js | 5 + .../commands/generic/cmdBroadcastGalaxy.py | 7 -- .../commands/generic/cmdBroadcastPlanet.js | 5 + .../commands/generic/cmdBroadcastPlanet.py | 8 -- scripts/commands/generic/cmdSetSpeed.js | 16 +++ scripts/commands/generic/cmdSetSpeed.py | 16 --- scripts/commands/generic/cmdTip.js | 3 + scripts/commands/generic/cmdTip.py | 4 - scripts/commands/generic/debug.js | 3 + scripts/commands/generic/debug.py | 5 - scripts/commands/generic/getFriendList.js | 5 + scripts/commands/generic/getFriendList.py | 7 -- scripts/commands/generic/openContainer.js | 4 + scripts/commands/generic/openContainer.py | 6 - scripts/commands/generic/planetChat.js | 3 + scripts/commands/generic/planetChat.py | 3 - scripts/commands/generic/removeFriend.js | 25 ++++ scripts/commands/generic/removeFriend.py | 22 ---- scripts/commands/generic/setMoodInternal.js | 7 ++ scripts/commands/generic/setMoodInternal.py | 10 -- .../generic/setWaypointActiveStatus.js | 22 ++++ .../generic/setWaypointActiveStatus.py | 18 --- scripts/commands/generic/setWaypointName.js | 18 +++ scripts/commands/generic/setWaypointName.py | 15 --- .../commands/generic/spatialChatInternal.js | 5 + .../commands/generic/spatialChatInternal.py | 9 -- .../generic/toggleAwayFromKeyBoard.js | 4 + .../generic/toggleAwayFromKeyBoard.py | 6 - .../generic/toggleDisplayingFactionRank.js | 4 + .../generic/toggleDisplayingFactionRank.py | 6 - scripts/commands/generic/toggleHelper.js | 4 + scripts/commands/generic/toggleHelper.py | 6 - .../commands/generic/toggleLookingForGroup.js | 4 + .../commands/generic/toggleLookingForGroup.py | 6 - .../commands/generic/toggleLookingForWork.js | 4 + .../commands/generic/toggleLookingForWork.py | 6 - .../commands/generic/toggleOutOfCharacter.js | 4 + .../commands/generic/toggleOutOfCharacter.py | 6 - scripts/commands/generic/toggleRolePlay.js | 4 + scripts/commands/generic/toggleRolePlay.py | 6 - scripts/commands/generic/transferItemMisc.js | 22 ++++ scripts/commands/generic/transferItemMisc.py | 22 ---- .../commands/callbacks/ServerCmdCallback.java | 2 +- src/resources/sui/SuiWindow.java | 13 +- src/services/CoreManager.java | 3 - src/services/commands/CommandService.java | 4 +- src/services/sui/SuiService.java | 8 +- src/utilities/Scripts.java | 117 ++++-------------- 54 files changed, 237 insertions(+), 332 deletions(-) create mode 100644 scripts/commands/generic/addFriend.js delete mode 100644 scripts/commands/generic/addFriend.py create mode 100644 scripts/commands/generic/cmdBroadcast.js delete mode 100644 scripts/commands/generic/cmdBroadcast.py create mode 100644 scripts/commands/generic/cmdBroadcastArea.js delete mode 100644 scripts/commands/generic/cmdBroadcastArea.py create mode 100644 scripts/commands/generic/cmdBroadcastGalaxy.js delete mode 100644 scripts/commands/generic/cmdBroadcastGalaxy.py create mode 100644 scripts/commands/generic/cmdBroadcastPlanet.js delete mode 100644 scripts/commands/generic/cmdBroadcastPlanet.py create mode 100644 scripts/commands/generic/cmdSetSpeed.js delete mode 100644 scripts/commands/generic/cmdSetSpeed.py create mode 100644 scripts/commands/generic/cmdTip.js delete mode 100644 scripts/commands/generic/cmdTip.py create mode 100644 scripts/commands/generic/debug.js delete mode 100644 scripts/commands/generic/debug.py create mode 100644 scripts/commands/generic/getFriendList.js delete mode 100644 scripts/commands/generic/getFriendList.py create mode 100644 scripts/commands/generic/openContainer.js delete mode 100644 scripts/commands/generic/openContainer.py create mode 100644 scripts/commands/generic/planetChat.js delete mode 100644 scripts/commands/generic/planetChat.py create mode 100644 scripts/commands/generic/removeFriend.js delete mode 100644 scripts/commands/generic/removeFriend.py create mode 100644 scripts/commands/generic/setMoodInternal.js delete mode 100644 scripts/commands/generic/setMoodInternal.py create mode 100644 scripts/commands/generic/setWaypointActiveStatus.js delete mode 100644 scripts/commands/generic/setWaypointActiveStatus.py create mode 100644 scripts/commands/generic/setWaypointName.js delete mode 100644 scripts/commands/generic/setWaypointName.py create mode 100644 scripts/commands/generic/spatialChatInternal.js delete mode 100644 scripts/commands/generic/spatialChatInternal.py create mode 100644 scripts/commands/generic/toggleAwayFromKeyBoard.js delete mode 100644 scripts/commands/generic/toggleAwayFromKeyBoard.py create mode 100644 scripts/commands/generic/toggleDisplayingFactionRank.js delete mode 100644 scripts/commands/generic/toggleDisplayingFactionRank.py create mode 100644 scripts/commands/generic/toggleHelper.js delete mode 100644 scripts/commands/generic/toggleHelper.py create mode 100644 scripts/commands/generic/toggleLookingForGroup.js delete mode 100644 scripts/commands/generic/toggleLookingForGroup.py create mode 100644 scripts/commands/generic/toggleLookingForWork.js delete mode 100644 scripts/commands/generic/toggleLookingForWork.py create mode 100644 scripts/commands/generic/toggleOutOfCharacter.js delete mode 100644 scripts/commands/generic/toggleOutOfCharacter.py create mode 100644 scripts/commands/generic/toggleRolePlay.js delete mode 100644 scripts/commands/generic/toggleRolePlay.py create mode 100644 scripts/commands/generic/transferItemMisc.js delete mode 100644 scripts/commands/generic/transferItemMisc.py diff --git a/scripts/commands/generic/addFriend.js b/scripts/commands/generic/addFriend.js new file mode 100644 index 000000000..bd569c32a --- /dev/null +++ b/scripts/commands/generic/addFriend.js @@ -0,0 +1,18 @@ +var execute = function(objManager, player, target, args) { + var ChatAvatarRequestIntent = Java.type("intents.chat.ChatAvatarRequestIntent"); + var RequestType = Java.type("intents.chat.ChatAvatarRequestIntent.RequestType"); + var ghost = player.getPlayerObject(); + var name; + + if(ghost == null || args == null) { + return; + } + + name = args.split(" ")[0].toLowerCase(java.util.Locale.English); + + if(name == null) { + return; + } + + new ChatAvatarRequestIntent(player, name, RequestType.FRIEND_ADD_TARGET).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/addFriend.py b/scripts/commands/generic/addFriend.py deleted file mode 100644 index 140dec685..000000000 --- a/scripts/commands/generic/addFriend.py +++ /dev/null @@ -1,15 +0,0 @@ -from intents.chat import ChatAvatarRequestIntent -from intents.chat.ChatAvatarRequestIntent.RequestType import FRIEND_ADD_TARGET - -def execute(galacticManager, player, target, args): - ghost = player.getPlayerObject() - if ghost is None or args is None: - return - - name = str(args.split(" ")[0]).lower() - - if not name: - return - - ChatAvatarRequestIntent(player, name, FRIEND_ADD_TARGET).broadcast() - return diff --git a/scripts/commands/generic/cmdBroadcast.js b/scripts/commands/generic/cmdBroadcast.js new file mode 100644 index 000000000..4e510d3b6 --- /dev/null +++ b/scripts/commands/generic/cmdBroadcast.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var ChatBroadcastIntent = Java.type("intents.chat.ChatBroadcastIntent"); + var BroadcastType = Java.type("intents.chat.ChatBroadcastIntent.BroadcastType"); + new ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.PLANET).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcast.py b/scripts/commands/generic/cmdBroadcast.py deleted file mode 100644 index 8bb7eaa47..000000000 --- a/scripts/commands/generic/cmdBroadcast.py +++ /dev/null @@ -1,7 +0,0 @@ -from intents.chat import ChatBroadcastIntent -from intents.chat.ChatBroadcastIntent import BroadcastType -import sys - -def execute(objManager, player, target, args): - ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.PLANET).broadcast() - return \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastArea.js b/scripts/commands/generic/cmdBroadcastArea.js new file mode 100644 index 000000000..c4a58b542 --- /dev/null +++ b/scripts/commands/generic/cmdBroadcastArea.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var ChatBroadcastIntent = Java.type("intents.chat.ChatBroadcastIntent"); + var BroadcastType = Java.type("intents.chat.ChatBroadcastIntent.BroadcastType"); + new ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.AREA).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastArea.py b/scripts/commands/generic/cmdBroadcastArea.py deleted file mode 100644 index 2d7024e26..000000000 --- a/scripts/commands/generic/cmdBroadcastArea.py +++ /dev/null @@ -1,7 +0,0 @@ -from intents.chat import ChatBroadcastIntent -from intents.chat.ChatBroadcastIntent import BroadcastType -import sys - -def execute(objManager, player, target, args): - ChatBroadcastIntent(args, player, None, BroadcastType.AREA).broadcast() - return \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastGalaxy.js b/scripts/commands/generic/cmdBroadcastGalaxy.js new file mode 100644 index 000000000..fd9832e7f --- /dev/null +++ b/scripts/commands/generic/cmdBroadcastGalaxy.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var ChatBroadcastIntent = Java.type("intents.chat.ChatBroadcastIntent"); + var BroadcastType = Java.type("intents.chat.ChatBroadcastIntent.BroadcastType"); + new ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.GALAXY).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastGalaxy.py b/scripts/commands/generic/cmdBroadcastGalaxy.py deleted file mode 100644 index 03e1cd84e..000000000 --- a/scripts/commands/generic/cmdBroadcastGalaxy.py +++ /dev/null @@ -1,7 +0,0 @@ -from intents.chat import ChatBroadcastIntent -from intents.chat.ChatBroadcastIntent import BroadcastType -import sys - -def execute(objManager, player, target, args): - ChatBroadcastIntent(args, player, None, BroadcastType.GALAXY).broadcast() - return \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastPlanet.js b/scripts/commands/generic/cmdBroadcastPlanet.js new file mode 100644 index 000000000..4e510d3b6 --- /dev/null +++ b/scripts/commands/generic/cmdBroadcastPlanet.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var ChatBroadcastIntent = Java.type("intents.chat.ChatBroadcastIntent"); + var BroadcastType = Java.type("intents.chat.ChatBroadcastIntent.BroadcastType"); + new ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.PLANET).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/cmdBroadcastPlanet.py b/scripts/commands/generic/cmdBroadcastPlanet.py deleted file mode 100644 index 90a2d852f..000000000 --- a/scripts/commands/generic/cmdBroadcastPlanet.py +++ /dev/null @@ -1,8 +0,0 @@ -from intents.chat import ChatBroadcastIntent -from intents.chat.ChatBroadcastIntent import BroadcastType - -import sys - -def execute(objManager, player, target, args): - ChatBroadcastIntent(args, player, player.getCreatureObject().getLocation().getTerrain(), BroadcastType.PLANET).broadcast() - return \ No newline at end of file diff --git a/scripts/commands/generic/cmdSetSpeed.js b/scripts/commands/generic/cmdSetSpeed.js new file mode 100644 index 000000000..243dc2b0e --- /dev/null +++ b/scripts/commands/generic/cmdSetSpeed.js @@ -0,0 +1,16 @@ +var execute = function(objManager, player, target, args) { + var creature = player.getCreatureObject(); + var AccessLevel = Java.type("resources.player.AccessLevel"); + + if(player.getAccessLevel() == AccessLevel.PLAYER) { + print("Error: Your Accesslevel is to low to use that command"); + return; + } + + if(creature == null) { + print("Error: No Player or CreatureObject"); + return; + } + + creature.setMovementScale(args); +} diff --git a/scripts/commands/generic/cmdSetSpeed.py b/scripts/commands/generic/cmdSetSpeed.py deleted file mode 100644 index f4d91c6ff..000000000 --- a/scripts/commands/generic/cmdSetSpeed.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -from resources.player import AccessLevel - -def execute(objManager, player, target, args): - ghost = player.getCreatureObject() - - if player.getAccessLevel() == AccessLevel.PLAYER: - print("Error: Your Accesslevel is to low to use that command") - return - - if ghost is None: - print("Error: No Player or CreatureObject") - return - - ghost.setMovementScale(float(args)) - return \ No newline at end of file diff --git a/scripts/commands/generic/cmdTip.js b/scripts/commands/generic/cmdTip.js new file mode 100644 index 000000000..f382222ea --- /dev/null +++ b/scripts/commands/generic/cmdTip.js @@ -0,0 +1,3 @@ +var execute = function(objManager, player, target, args) { + +} \ No newline at end of file diff --git a/scripts/commands/generic/cmdTip.py b/scripts/commands/generic/cmdTip.py deleted file mode 100644 index 25353f4bc..000000000 --- a/scripts/commands/generic/cmdTip.py +++ /dev/null @@ -1,4 +0,0 @@ -import sys - -def execute(objManager, player, target, args): - return \ No newline at end of file diff --git a/scripts/commands/generic/debug.js b/scripts/commands/generic/debug.js new file mode 100644 index 000000000..d59a07a09 --- /dev/null +++ b/scripts/commands/generic/debug.js @@ -0,0 +1,3 @@ +var execute = function(objManager, player, target, args) { + print("Hello"); +} \ No newline at end of file diff --git a/scripts/commands/generic/debug.py b/scripts/commands/generic/debug.py deleted file mode 100644 index 56fd367a0..000000000 --- a/scripts/commands/generic/debug.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys - -def execute(objManager, player, target, args): - print "Hello" - return \ No newline at end of file diff --git a/scripts/commands/generic/getFriendList.js b/scripts/commands/generic/getFriendList.js new file mode 100644 index 000000000..74da90866 --- /dev/null +++ b/scripts/commands/generic/getFriendList.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var ChatAvatarRequestIntent = Java.type("intents.chat.ChatAvatarRequestIntent"); + var RequestType = Java.type("intents.chat.ChatAvatarRequestIntent.RequestType"); + new ChatAvatarRequestIntent(player, null, RequestType.FRIEND_LIST).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/getFriendList.py b/scripts/commands/generic/getFriendList.py deleted file mode 100644 index c75dd1c4b..000000000 --- a/scripts/commands/generic/getFriendList.py +++ /dev/null @@ -1,7 +0,0 @@ -from intents.chat import ChatAvatarRequestIntent -from intents.chat.ChatAvatarRequestIntent.RequestType import FRIEND_LIST - - -def execute(galacticManager, player, target, args): - ChatAvatarRequestIntent(player, None, FRIEND_LIST).broadcast() - return diff --git a/scripts/commands/generic/openContainer.js b/scripts/commands/generic/openContainer.js new file mode 100644 index 000000000..a272a1425 --- /dev/null +++ b/scripts/commands/generic/openContainer.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var ClientOpenContainerMessage = Java.type("network.packets.swg.zone.ClientOpenContainerMessage"); + player.sendPacket(new ClientOpenContainerMessage(target.getObjectId())); +} \ No newline at end of file diff --git a/scripts/commands/generic/openContainer.py b/scripts/commands/generic/openContainer.py deleted file mode 100644 index e32c03c98..000000000 --- a/scripts/commands/generic/openContainer.py +++ /dev/null @@ -1,6 +0,0 @@ -from network.packets.swg.zone import ClientOpenContainerMessage - -def execute(objManager, player, target, args): - player.sendPacket(ClientOpenContainerMessage(target.getObjectId())) - return - \ No newline at end of file diff --git a/scripts/commands/generic/planetChat.js b/scripts/commands/generic/planetChat.js new file mode 100644 index 000000000..f382222ea --- /dev/null +++ b/scripts/commands/generic/planetChat.js @@ -0,0 +1,3 @@ +var execute = function(objManager, player, target, args) { + +} \ No newline at end of file diff --git a/scripts/commands/generic/planetChat.py b/scripts/commands/generic/planetChat.py deleted file mode 100644 index e25c9b15a..000000000 --- a/scripts/commands/generic/planetChat.py +++ /dev/null @@ -1,3 +0,0 @@ - -def execute(galacticManager, player, target, args): - return diff --git a/scripts/commands/generic/removeFriend.js b/scripts/commands/generic/removeFriend.js new file mode 100644 index 000000000..5438d052d --- /dev/null +++ b/scripts/commands/generic/removeFriend.js @@ -0,0 +1,25 @@ +var execute = function(objManager, player, target, args) { + var ChatAvatarRequestIntent = Java.type("intents.chat.ChatAvatarRequestIntent"); + var RequestType = Java.type("intents.chat.ChatAvatarRequestIntent.RequestType"); + var ProsePackage = Java.type("resources.encodables.ProsePackage"); + var ChatBroadcastIntent = Java.type("intents.chat.ChatBroadcastIntent"); + var ghost = player.getPlayerObject(); + var name; + + if(ghost == null || args == null) { + return; + } + + name = args.split(" ")[0].toLowerCase(java.util.Locale.English); + + if(name == null) { + return; + } + + if(!ghost.getFriendsList().contains(name)) { + new ChatBroadcastIntent(player, new ProsePackage("@cmnty:friend_not_found", "TT", name)).broadcast(); + return; + } + + new ChatAvatarRequestIntent(player, name, RequestType.FRIEND_REMOVE_TARGET).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/removeFriend.py b/scripts/commands/generic/removeFriend.py deleted file mode 100644 index 6871aacd4..000000000 --- a/scripts/commands/generic/removeFriend.py +++ /dev/null @@ -1,22 +0,0 @@ -from intents.chat import ChatBroadcastIntent -from resources.encodables import ProsePackage -from intents.chat import ChatAvatarRequestIntent -from intents.chat.ChatAvatarRequestIntent.RequestType import FRIEND_REMOVE_TARGET - -def execute(galacticManager, player, target, args): - ghost = player.getPlayerObject() - - if ghost is None or not args: - return - - name = str(args.split(" ")[0]).lower() - - if not name: - return - - if ghost.getFriendsList().contains(name) is False: - ChatBroadcastIntent(player, ProsePackage("@cmnty:friend_not_found", "TT", name)).broadcast() - return - - ChatAvatarRequestIntent(player, name, FRIEND_REMOVE_TARGET).broadcast() - return diff --git a/scripts/commands/generic/setMoodInternal.js b/scripts/commands/generic/setMoodInternal.js new file mode 100644 index 000000000..ac6f88d36 --- /dev/null +++ b/scripts/commands/generic/setMoodInternal.js @@ -0,0 +1,7 @@ +var execute = function(objManager, player, target, args) { + if(args.contains(" ")) { + return; + } + + player.getCreatureObject().setMoodId(args); +} \ No newline at end of file diff --git a/scripts/commands/generic/setMoodInternal.py b/scripts/commands/generic/setMoodInternal.py deleted file mode 100644 index 2589b0f88..000000000 --- a/scripts/commands/generic/setMoodInternal.py +++ /dev/null @@ -1,10 +0,0 @@ -from intents.chat import SpatialChatIntent -import sys - -#Args: moodId -def execute(objManager, player, target, args): - if " " in args: - return - - player.getCreatureObject().setMoodId(int(args)) - return \ No newline at end of file diff --git a/scripts/commands/generic/setWaypointActiveStatus.js b/scripts/commands/generic/setWaypointActiveStatus.js new file mode 100644 index 000000000..63fc3a88b --- /dev/null +++ b/scripts/commands/generic/setWaypointActiveStatus.js @@ -0,0 +1,22 @@ +var execute = function(objManager, player, target, args) { + var ghost = player.getPlayerObject(); + var waypoint; + + if(ghost == null || target == null) { + return; + } + + waypoint = ghost.getWaypoint(target.getObjectId()); + + if(waypoint == null) { + return; + } + + if(waypoint.isActive()) { + waypoint.setActive(false); + } else { + waypoint.setActive(true); + } + + ghost.updateWaypoint(waypoint); +} \ No newline at end of file diff --git a/scripts/commands/generic/setWaypointActiveStatus.py b/scripts/commands/generic/setWaypointActiveStatus.py deleted file mode 100644 index d79f89439..000000000 --- a/scripts/commands/generic/setWaypointActiveStatus.py +++ /dev/null @@ -1,18 +0,0 @@ -import sys - -def execute(objManager, player, target, args): - ghost = player.getPlayerObject() - if ghost is None or target is None: - return - - waypoint = ghost.getWaypoint(target.getObjectId()) - if waypoint is None: - return - - if waypoint.isActive(): - waypoint.setActive(False) - else: - waypoint.setActive(True) - - ghost.updateWaypoint(waypoint) - return \ No newline at end of file diff --git a/scripts/commands/generic/setWaypointName.js b/scripts/commands/generic/setWaypointName.js new file mode 100644 index 000000000..8aadc78a0 --- /dev/null +++ b/scripts/commands/generic/setWaypointName.js @@ -0,0 +1,18 @@ +var execute = function(objManager, player, target, args) { + var ghost = player.getPlayerObject(); + var waypoint; + + if(ghost == null || target == null) { + return; + } + + waypoint = ghost.getWaypoint(target.getObjectId()); + + if(waypoint == null) { + return; + } + + waypoint.setName(args); + + ghost.updateWaypoint(waypoint); +} \ No newline at end of file diff --git a/scripts/commands/generic/setWaypointName.py b/scripts/commands/generic/setWaypointName.py deleted file mode 100644 index f8a1e44e8..000000000 --- a/scripts/commands/generic/setWaypointName.py +++ /dev/null @@ -1,15 +0,0 @@ -import sys - -#Args: name -def execute(objManager, player, target, args): - ghost = player.getPlayerObject() - if ghost is None or target is None: - return - - waypoint = ghost.getWaypoint(target.getObjectId()) - if waypoint is None: - return - - waypoint.setName(args) - ghost.updateWaypoint(waypoint) - return \ No newline at end of file diff --git a/scripts/commands/generic/spatialChatInternal.js b/scripts/commands/generic/spatialChatInternal.js new file mode 100644 index 000000000..1920d1ce6 --- /dev/null +++ b/scripts/commands/generic/spatialChatInternal.js @@ -0,0 +1,5 @@ +var execute = function(objManager, player, target, args) { + var cmdArgs = args.split(' ', 5); + var SpatialChatIntent = Java.type("intents.chat.SpatialChatIntent"); + new SpatialChatIntent(player, cmdArgs[1], args.substring(10), cmdArgs[2]).broadcast(); +} \ No newline at end of file diff --git a/scripts/commands/generic/spatialChatInternal.py b/scripts/commands/generic/spatialChatInternal.py deleted file mode 100644 index 763c72be3..000000000 --- a/scripts/commands/generic/spatialChatInternal.py +++ /dev/null @@ -1,9 +0,0 @@ -from intents.chat import SpatialChatIntent -import sys - -#Args: unkInt chatType moodId unkInt2 langId message -def execute(objManager, player, target, args): - cmdArgs = args.split(' ', 5) - #print ('unkInt=' + cmdArgs[0] + ' chatType=' + cmdArgs[1] + ' moodId=' + cmdArgs[2] + ' unkInt2=' + cmdArgs[3] + ' langId=' + cmdArgs[4]) - SpatialChatIntent(player, int(cmdArgs[1]), cmdArgs[5], int(cmdArgs[2])).broadcast() - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleAwayFromKeyBoard.js b/scripts/commands/generic/toggleAwayFromKeyBoard.js new file mode 100644 index 000000000..84e9fc8de --- /dev/null +++ b/scripts/commands/generic/toggleAwayFromKeyBoard.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.AFK); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleAwayFromKeyBoard.py b/scripts/commands/generic/toggleAwayFromKeyBoard.py deleted file mode 100644 index cd360a155..000000000 --- a/scripts/commands/generic/toggleAwayFromKeyBoard.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import AFK - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(AFK) - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleDisplayingFactionRank.js b/scripts/commands/generic/toggleDisplayingFactionRank.js new file mode 100644 index 000000000..4c30635cd --- /dev/null +++ b/scripts/commands/generic/toggleDisplayingFactionRank.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.FACTIONRANK); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleDisplayingFactionRank.py b/scripts/commands/generic/toggleDisplayingFactionRank.py deleted file mode 100644 index 091e3bd80..000000000 --- a/scripts/commands/generic/toggleDisplayingFactionRank.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import FACTIONRANK - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(FACTIONRANK); - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleHelper.js b/scripts/commands/generic/toggleHelper.js new file mode 100644 index 000000000..a6d9aa8bc --- /dev/null +++ b/scripts/commands/generic/toggleHelper.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.HELPER); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleHelper.py b/scripts/commands/generic/toggleHelper.py deleted file mode 100644 index 4f84f168b..000000000 --- a/scripts/commands/generic/toggleHelper.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import HELPER - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(HELPER); - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleLookingForGroup.js b/scripts/commands/generic/toggleLookingForGroup.js new file mode 100644 index 000000000..8b487d2a9 --- /dev/null +++ b/scripts/commands/generic/toggleLookingForGroup.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.LFG); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleLookingForGroup.py b/scripts/commands/generic/toggleLookingForGroup.py deleted file mode 100644 index 8dd12fca9..000000000 --- a/scripts/commands/generic/toggleLookingForGroup.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import LFG - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(LFG); - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleLookingForWork.js b/scripts/commands/generic/toggleLookingForWork.js new file mode 100644 index 000000000..804424c6c --- /dev/null +++ b/scripts/commands/generic/toggleLookingForWork.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.LFW); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleLookingForWork.py b/scripts/commands/generic/toggleLookingForWork.py deleted file mode 100644 index 70ac2a61c..000000000 --- a/scripts/commands/generic/toggleLookingForWork.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import LFW - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(LFW); - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleOutOfCharacter.js b/scripts/commands/generic/toggleOutOfCharacter.js new file mode 100644 index 000000000..0f2f2bfc6 --- /dev/null +++ b/scripts/commands/generic/toggleOutOfCharacter.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.OOC); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleOutOfCharacter.py b/scripts/commands/generic/toggleOutOfCharacter.py deleted file mode 100644 index 104a2c30d..000000000 --- a/scripts/commands/generic/toggleOutOfCharacter.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import OOC - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(OOC); - return \ No newline at end of file diff --git a/scripts/commands/generic/toggleRolePlay.js b/scripts/commands/generic/toggleRolePlay.js new file mode 100644 index 000000000..fb1bd5322 --- /dev/null +++ b/scripts/commands/generic/toggleRolePlay.js @@ -0,0 +1,4 @@ +var execute = function(objManager, player, target, args) { + var PlayerFlags = Java.type("resources.player.PlayerFlags"); + player.getPlayerObject().toggleFlag(PlayerFlags.ROLEPLAYER); +} \ No newline at end of file diff --git a/scripts/commands/generic/toggleRolePlay.py b/scripts/commands/generic/toggleRolePlay.py deleted file mode 100644 index 33cf585af..000000000 --- a/scripts/commands/generic/toggleRolePlay.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys -from resources.player.PlayerFlags import ROLEPLAYER - -def execute(objManager, player, target, args): - player.getPlayerObject().toggleFlag(ROLEPLAYER); - return \ No newline at end of file diff --git a/scripts/commands/generic/transferItemMisc.js b/scripts/commands/generic/transferItemMisc.js new file mode 100644 index 000000000..d8457a3d3 --- /dev/null +++ b/scripts/commands/generic/transferItemMisc.js @@ -0,0 +1,22 @@ +var execute = function(objManager, player, target, args) { + var actor = player.getCreatureObject(); + var inventory; + + if(actor == null || target == null) { + return; + } + + inventory = actor.getSlottedObject("inventory"); + + if(inventory == null) { + return; + } + + if(target.getParent() == actor) { + result = target.moveToContainer(actor, inventory) + actor.removeEquipment(target) + } else { + result = target.moveToContainer(actor, actor) + actor.addEquipment(target) + } +} \ No newline at end of file diff --git a/scripts/commands/generic/transferItemMisc.py b/scripts/commands/generic/transferItemMisc.py deleted file mode 100644 index 6efa0f714..000000000 --- a/scripts/commands/generic/transferItemMisc.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys - -def execute(galacticManager, player, target, args): - actor = player.getCreatureObject() - if actor is None or target is None: - return - - inventory = actor.getSlottedObject("inventory") - - if inventory is None: - return - - if target.getParent() == actor: - result = target.moveToContainer(actor, inventory) - actor.removeEquipment(target) - return - else: - result = target.moveToContainer(actor, actor) - actor.addEquipment(target) - return - - return \ No newline at end of file diff --git a/src/resources/commands/callbacks/ServerCmdCallback.java b/src/resources/commands/callbacks/ServerCmdCallback.java index fb03e62fa..3e413e1bc 100644 --- a/src/resources/commands/callbacks/ServerCmdCallback.java +++ b/src/resources/commands/callbacks/ServerCmdCallback.java @@ -68,7 +68,7 @@ public class ServerCmdCallback implements ICmdCallback { } private void debug(GalacticManager galacticManager, Player player, SWGObject target, String args) { - Scripts.execute("commands/generic/debug.py", "execute", galacticManager, player, target, args); + Scripts.invoke("commands/generic/debug", "execute", galacticManager, player, target, args); } private static class ServerSuiCallback implements ISuiCallback { diff --git a/src/resources/sui/SuiWindow.java b/src/resources/sui/SuiWindow.java index c69248c7c..35d5884fb 100644 --- a/src/resources/sui/SuiWindow.java +++ b/src/resources/sui/SuiWindow.java @@ -35,9 +35,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - -import org.python.core.PyObject; - import resources.player.Player; import network.packets.swg.zone.server_ui.SuiCreatePageMessage.SuiWindowComponent; @@ -49,7 +46,7 @@ public class SuiWindow { private long rangeObjId; private float maxDistance = 0; private List components = new ArrayList(); - private Map scriptCallbacks; + private Map scriptCallbacks; private Map javaCallbacks; public SuiWindow(String script, Player owner) { @@ -139,12 +136,12 @@ public class SuiWindow { javaCallbacks.put(eventId, callback); } - public final void addCallback(int eventId, String source, Trigger trigger, List returnParams, PyObject callback) { + public final void addCallback(int eventId, String source, Trigger trigger, List returnParams, String callbackScript) { addCallbackComponent(source, trigger, returnParams); if (scriptCallbacks == null) - scriptCallbacks = new HashMap(); - scriptCallbacks.put(eventId, callback); + scriptCallbacks = new HashMap(); + scriptCallbacks.put(eventId, callbackScript); } private SuiWindowComponent createComponent(byte type) { @@ -173,7 +170,7 @@ public class SuiWindow { public final void setMaxDistance(float maxDistance) { this.maxDistance = maxDistance; } public final List getComponents() { return components; } public final ISuiCallback getJavaCallback(int eventType) { return ((javaCallbacks == null) ? null : javaCallbacks.get(eventType)); } - public final PyObject getScriptCallback(int eventType) { return ((scriptCallbacks == null) ? null : scriptCallbacks.get(eventType)); } + public final String getScriptCallback(int eventType) { return ((scriptCallbacks == null) ? null : scriptCallbacks.get(eventType)); } public enum Trigger { UPDATE ((byte) 4), diff --git a/src/services/CoreManager.java b/src/services/CoreManager.java index 4b130bfaf..755901dcf 100644 --- a/src/services/CoreManager.java +++ b/src/services/CoreManager.java @@ -56,7 +56,6 @@ import resources.control.Manager; import resources.control.ServerStatus; import resources.server_info.Config; import services.galaxy.GalacticManager; -import utilities.Scripts; public class CoreManager extends Manager { @@ -111,7 +110,6 @@ public class CoreManager extends Manager { @Override public boolean stop() { galaxy.setStatus(GalaxyStatus.LOCKED); - Scripts.cleanup(); return super.stop(); } @@ -155,7 +153,6 @@ public class CoreManager extends Manager { } System.out.println("CoreManager: Initializing scripts..."); long start = System.nanoTime(); - Scripts.initialize(getConfig(ConfigFile.PRIMARY)); long end = System.nanoTime(); System.out.println("CoreManager: Initialized scripts. Took " + (end-start)/1E6 + "ms"); } diff --git a/src/services/commands/CommandService.java b/src/services/commands/CommandService.java index c585ceb92..95937b0cf 100644 --- a/src/services/commands/CommandService.java +++ b/src/services/commands/CommandService.java @@ -123,7 +123,7 @@ public class CommandService extends Service { if (command.hasJavaCallback()) command.getJavaCallback().execute(galacticManager, player, target, args); else - Scripts.execute("commands/generic/" + command.getScriptCallback(), "execute", galacticManager, player, target, args); + Scripts.invoke("commands/generic/" + command.getScriptCallback(), "execute", galacticManager, player, target, args); } private void loadBaseCommands() { @@ -146,7 +146,7 @@ public class CommandService extends Service { Command command = new Command((String) cmdRow[0]); command.setCrc(CRC.getCrc(command.getName().toLowerCase(Locale.ENGLISH))); - command.setScriptCallback(callback + ".py"); + command.setScriptCallback(callback); command.setDefaultTime((float) cmdRow[6]); command.setCharacterAbility((String) cmdRow[7]); diff --git a/src/services/sui/SuiService.java b/src/services/sui/SuiService.java index 61cee76cf..24b2b8754 100644 --- a/src/services/sui/SuiService.java +++ b/src/services/sui/SuiService.java @@ -31,9 +31,6 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -import org.python.core.Py; -import org.python.core.PyObject; - import network.packets.Packet; import network.packets.swg.SWGPacket; import network.packets.swg.zone.object_controller.ObjectController; @@ -50,6 +47,7 @@ import resources.player.Player; import resources.sui.ISuiCallback; import resources.sui.SuiWindow; import services.player.PlayerManager; +import utilities.Scripts; public class SuiService extends Service { @@ -132,8 +130,8 @@ public class SuiService extends Service { ISuiCallback callback = window.getJavaCallback(eventId); callback.handleEvent(player, player.getCreatureObject(), eventId, r.getDataStrings()); } else if (window.getScriptCallback(eventId) != null) { - PyObject callback = window.getScriptCallback(eventId); - callback.__call__(Py.java2py(player), Py.java2py(player.getCreatureObject()), Py.java2py(eventId), Py.java2py(r.getDataStrings())); + String callbackScript = window.getScriptCallback(eventId); + Scripts.invoke(callbackScript, "callback", player, player.getCreatureObject(), eventId, r.getDataStrings()); } } diff --git a/src/utilities/Scripts.java b/src/utilities/Scripts.java index 645595b90..41155a946 100644 --- a/src/utilities/Scripts.java +++ b/src/utilities/Scripts.java @@ -1,100 +1,37 @@ -/******************************************************************************* - * Copyright (c) 2015 /// Project SWG /// www.projectswg.com - * - * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on - * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. - * Our goal is to create an emulator which will provide a server for players to - * continue playing a game similar to the one they used to play. We are basing - * it on the final publish of the game prior to end-game events. - * - * This file is part of Holocore. - * - * -------------------------------------------------------------------------------- - * - * Holocore is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Holocore is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Holocore. If not, see - ******************************************************************************/ - package utilities; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PySystemState; -import org.python.util.PythonInterpreter; -import resources.server_info.Config; +import java.io.FileReader; -import java.io.File; -import java.io.IOException; -import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; public class Scripts { - private static Scripts instance = new Scripts(); + private static final String SCRIPTS = "scripts/"; - private final PythonInterpreter interpreter; - - private Scripts() { - interpreter = new PythonInterpreter(); - } - - public static PyObject execute(String script, String method, Object ... args) { - if (!exists(script)) - return null; - - instance.interpreter.execfile(SCRIPTS + script); - return instance.interpreter.get(method).__call__(Py.javas2pys(args)); - } - - public static boolean exists(String script) { - return (new File(SCRIPTS + script).exists()); - } - - public static void initialize(Config config) { - PySystemState systemState = instance.interpreter.getSystemState(); - systemState.setCurrentWorkingDir(systemState.getCurrentWorkingDir() + "/"); - Scripts.initScripts(systemState); - } - - private static void initScripts(PySystemState systemState) { - File scripts = new File(systemState.getCurrentWorkingDir()); - final int length = scripts.getAbsolutePath().length(); - final PythonInterpreter interpreter = instance.interpreter; - + private static final String EXTENSION = ".js"; + private static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName("nashorn"); + private static final Invocable INVOCABLE = (Invocable) ENGINE; + + // Prevents instantiation. + private Scripts() {} + + /** + * @param script name of the script, relative to the scripts folder. + * @param function name of the specific function within the script. + * @param args to pass to the function. + * @return whatever the function returns. If the function doesn't have a return statement, this method returns {@code null}. + * If an exception occurs, {@code null} is returned. + */ + @SuppressWarnings("unchecked") + public static T invoke(String script, String function, Object... args) { try { - Files.walkFileTree(scripts.toPath(), new FileVisitor() { - public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException { - return FileVisitResult.CONTINUE; - } - - public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { - String name = path.toFile().getAbsolutePath(); - if (name.endsWith(".py")) - interpreter.execfile(name.substring(length + 1)); - return FileVisitResult.CONTINUE; - } - public FileVisitResult visitFileFailed(Path path, IOException e) throws IOException { - return FileVisitResult.CONTINUE; - } - public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - e.printStackTrace(); + ENGINE.eval(new FileReader(SCRIPTS + script + EXTENSION)); + return (T) INVOCABLE.invokeFunction(function, args); + } catch(Throwable t) { + t.printStackTrace(); + return null; } } - - public static void cleanup() { - instance.interpreter.cleanup(); - } + }