diff --git a/src/main/java/com/syncleus/aethermud/command/commands/admin/ManifestCommand.java b/src/main/java/com/syncleus/aethermud/command/commands/admin/ManifestCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..80437d50b6d60b090b2a3011d635cab2c46e6599 --- /dev/null +++ b/src/main/java/com/syncleus/aethermud/command/commands/admin/ManifestCommand.java @@ -0,0 +1,87 @@ +/** + * Copyright 2017 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.syncleus.aethermud.command.commands.admin; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.syncleus.aethermud.command.commands.Command; +import com.syncleus.aethermud.core.GameManager; +import com.syncleus.aethermud.items.ItemBuilder; +import com.syncleus.aethermud.items.ItemInstance; +import com.syncleus.aethermud.items.Loot; +import com.syncleus.aethermud.npc.NpcBuilder; +import com.syncleus.aethermud.npc.NpcSpawn; +import com.syncleus.aethermud.player.PlayerRole; +import com.syncleus.aethermud.server.communication.Color; +import com.syncleus.aethermud.storage.graphdb.GraphStorageFactory; +import com.syncleus.aethermud.storage.graphdb.model.ItemData; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.MessageEvent; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +public class ManifestCommand extends Command { + + final static List<String> validTriggers = Arrays.asList("manifest"); + final static String description = "Manifest an item."; + final static String correctUsage = "manifest <item id> | spawn"; + final static Set<PlayerRole> roles = Sets.newHashSet(PlayerRole.ADMIN); + + public ManifestCommand(GameManager gameManager) { + super(gameManager, validTriggers, description, correctUsage, roles); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { + execCommand(ctx, e, () -> { + try( GraphStorageFactory.AetherMudTx tx = this.gameManager.getGraphStorageFactory().beginTransaction() ) { + List<? extends ItemData> itemsFromDb = tx.getStorage().getAllItems(); + if (originalMessageParts.size() == 1) { + write(getHeader()); + for (ItemData itemData : itemsFromDb) { + write( itemData.getInternalItemName() +": " + itemData.getItemName() + "\r\n"); + } + } else { + originalMessageParts.remove(0); + String itemName = Joiner.on(" ").join(originalMessageParts); + + Optional<ItemData> optionalItemData = tx.getStorage().getItem(itemName); + if(!optionalItemData.isPresent()) { + write("Item " + itemName + " not found.\r\n"); + return; + } + + ItemData itemData = optionalItemData.get(); + ItemInstance item = new ItemBuilder().from(ItemData.copyItem(itemData)).create(); + gameManager.getEntityManager().saveItem(item); + gameManager.placeItemInRoom(currentRoom.getRoomId(), item.getItemId()); + write("Item " + itemName + " manifested.\r\n"); + } + } + }); + } + + public String getHeader() { + StringBuilder sb = new StringBuilder(); + sb.append(Color.MAGENTA + "-+=[ " + Color.RESET).append("Item").append(Color.MAGENTA + " ]=+- " + Color.RESET).append("\r\n"); + sb.append(Color.MAGENTA + "AvailableItems-----------------------" + Color.RESET).append("\r\n"); + return sb.toString(); + } +} diff --git a/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java b/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java index 587510ab28dcc7347cbd60f803a25d4e62cdf995..2c2b8aee96bcbbb0a83ddfa321b1ddef6c328431 100644 --- a/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java +++ b/src/main/java/com/syncleus/aethermud/configuration/ConfigureCommands.java @@ -123,5 +123,6 @@ public class ConfigureCommands { commandRegistry.addCommand(new RestartCommand(gameManager)); commandRegistry.addCommand(new GiveHealthCommand(gameManager)); commandRegistry.addCommand(new GraphStatusCommand(gameManager)); + commandRegistry.addCommand(new ManifestCommand(gameManager)); } } diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/ItemData.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/ItemData.java index c666982e6b22167d4f8f994583fd677b2f48651f..7f3ebcf68e0d71114e5fd014b42e82fee774ca0c 100644 --- a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/ItemData.java +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/ItemData.java @@ -274,8 +274,9 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame { for(SpawnRuleData data : dest.getSpawnRuleDatas()) data.remove(); - for(SpawnRule spawnRule : src.getSpawnRules()) - SpawnRuleData.copySpawnRule(dest.createSpawnRuleData(), spawnRule); + if( src.getSpawnRules() != null ) + for(SpawnRule spawnRule : src.getSpawnRules()) + SpawnRuleData.copySpawnRule(dest.createSpawnRuleData(), spawnRule); if( src.getItemApplyStats() != null ) StatData.copyStats((dest.getItemApplyStatData() != null ? dest.getItemApplyStatData() : dest.createItemApplyStatData()), src.getItemApplyStats()); diff --git a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/MerchantData.java b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/MerchantData.java index fe721c1b7773c55cb6901b2291ccd5336629a847..7f41c4f2cc28173582b8f11a087d0ab0fea9d5cc 100644 --- a/src/main/java/com/syncleus/aethermud/storage/graphdb/model/MerchantData.java +++ b/src/main/java/com/syncleus/aethermud/storage/graphdb/model/MerchantData.java @@ -55,7 +55,7 @@ public abstract class MerchantData extends AbstractInterceptingVertexFrame { @Property("name") public abstract void setName(String name); - + public String getColorName() { return ColorizedTextTemplate.renderFromTemplateLanguage(this.getProperty("colorName")); }