package net.sourceforge.pain.logic.event.console.command.builder; import net.sourceforge.pain.*; import net.sourceforge.pain.network.console.*; import net.sourceforge.pain.data.*; import net.sourceforge.pain.data.prototype.*; import net.sourceforge.pain.data.type.*; import net.sourceforge.pain.logic.fn.*; import net.sourceforge.pain.logic.fn.factory.*; import java.util.*; /** * PAiN Date: 05.06.2003 Time: 1:40:02 */ public final class BC_Del extends BuilderCommand { public void processBuilderCommand(BuilderShell p, String args) throws Exception { if (args == null) { showUsage(p.console); return; } Prototype r = p.builder.getEditedRole(); if (r == null) { MessageOutFn.outln(p.console, "No active prototype found"); return; } PrototypeInfo pi = (PrototypeInfo) r.getRole(PrototypeInfo.class); if (!args.equals(pi.getVnum())) { MessageOutFn.outln(p.console, "Invalid vnum specified: '" + args + "'"); MessageOutFn.outln(p.console, "Active prototype vnum: '" + pi.getVnum() + "' name:" + pi.getName()); return; } // ok removal: ResetGroupRegistry rgr = Core.getWorld().getResetGroupRegistry(); ArrayList resetsToDelete = new ArrayList(); int totalRemoved = 0; for (Iterator it = rgr.getResetGroups().iterator(); it.hasNext();) { ResetGroup rg = (ResetGroup) it.next(); resetsToDelete.clear(); final Set resets = rg.getResets(); for (Iterator it2 = resets.iterator(); it2.hasNext();) { Reset reset = (Reset) it2.next(); if (reset.getResettedPrototype() == pi) { resetsToDelete.add(pi); SpaceReset sr = (SpaceReset) reset.getRole(SpaceReset.class); if (sr != null) { MessageOutFn.outln(p.console, "Removing reset from group:" + rg.getGroupId() + " space:" + sr.getLocation().getName()); } else { MessageOutFn.outln(p.console, "Removing reset from group:" + rg.getGroupId()); } } } totalRemoved += resetsToDelete.size(); resets.removeAll(resetsToDelete); } String name = pi.getName(); String vnum = pi.getVnum(); GlobalFactory.destroyObject(pi); MessageOutFn.outln(p.console, "Total resets removed: " + totalRemoved); MessageOutFn.outln(p.console, "Prototype: " + vnum + "/" + name + " removed"); } public void showUsage(Console console) { MessageOutFn.outln(console, "DEL:Command syntax <VNUM>\n"); } public void showHelp(Console console) { MessageOutFn.outln(console, "Builder command DEL removes the prototype and all it's resets"); MessageOutFn.outln(console, "To avoid accidental prototype removal this command removes only"); MessageOutFn.outln(console, "active prototype (command 'USE' makes prototype active and VNUM used as confirmation"); MessageOutFn.outln(console, "Usage: del <VNUM>"); } }