mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-28 12:07:38 +01:00
Completed changing powertool config from tokenized string to lists
This commit is contained in:
parent
812a357361
commit
e10675dfdc
@ -196,24 +196,15 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
return (List<String>)powertools.get(stack.getTypeId());
|
return (List<String>)powertools.get(stack.getTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPowertoolList(ItemStack stack)
|
public void setPowertool(ItemStack stack, List<String> commandList)
|
||||||
{
|
{
|
||||||
Map<String, Object> tools = (Map<String, Object>)config.getProperty("powertools");
|
if (commandList == null || commandList.isEmpty())
|
||||||
List<String> commands;
|
|
||||||
|
|
||||||
commands = (List<String>)tools.get(stack.getTypeId());
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPowertool(ItemStack stack, String command)
|
|
||||||
{
|
|
||||||
if (command == null || command.isEmpty())
|
|
||||||
{
|
{
|
||||||
powertools.remove(stack.getTypeId());
|
powertools.remove(stack.getTypeId());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
powertools.put(stack.getTypeId(), command);
|
powertools.put(stack.getTypeId(), commandList);
|
||||||
}
|
}
|
||||||
config.setProperty("powertools", powertools);
|
config.setProperty("powertools", powertools);
|
||||||
config.save();
|
config.save();
|
||||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
|||||||
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -19,6 +20,7 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||||
{
|
{
|
||||||
ItemStack is = user.getItemInHand();
|
ItemStack is = user.getItemInHand();
|
||||||
|
List<String> powertools = user.getPowertool(is);
|
||||||
if (is == null || is.getType() == Material.AIR)
|
if (is == null || is.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
user.sendMessage(Util.i18n("powerToolAir"));
|
user.sendMessage(Util.i18n("powerToolAir"));
|
||||||
@ -31,7 +33,6 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (command.equalsIgnoreCase("list"))
|
if (command.equalsIgnoreCase("list"))
|
||||||
{
|
{
|
||||||
List<String> powertools = user.getPowertool(is);
|
|
||||||
if (powertools == null || powertools.isEmpty())
|
if (powertools == null || powertools.isEmpty())
|
||||||
{
|
{
|
||||||
user.sendMessage(Util.format("powerToolListEmpty", itemName));
|
user.sendMessage(Util.format("powerToolListEmpty", itemName));
|
||||||
@ -46,9 +47,15 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String removedCommand = command.substring(2);
|
command = command.substring(2);
|
||||||
command = removePowerTool(user, removedCommand, is, itemName);
|
if (!powertools.contains(command))
|
||||||
user.sendMessage(Util.format("powerToolRemove", removedCommand, itemName));
|
{
|
||||||
|
user.sendMessage(Util.format("powerToolNoSuchCommandAssigned", command, itemName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
powertools.remove(command);
|
||||||
|
user.sendMessage(Util.format("powerToolRemove", command, itemName));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -60,18 +67,25 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (command.startsWith("a:"))
|
if (command.startsWith("a:"))
|
||||||
{
|
{
|
||||||
try
|
command = command.substring(2);
|
||||||
|
if(powertools.contains(command))
|
||||||
{
|
{
|
||||||
command = appendPowerTool(user, command, is, itemName);
|
user.sendMessage(Util.format("powerToolAlreadySet", command, itemName));
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
user.sendMessage(e.getMessage());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (powertools != null && !powertools.isEmpty())
|
||||||
|
{
|
||||||
|
// Replace all commands with this one
|
||||||
|
powertools.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
powertools = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
user.sendMessage(Util.format("powerToolAttach", command.replace("|", ", "), itemName));
|
powertools.add(command);
|
||||||
|
user.sendMessage(Util.format("powerToolAttach", powertools.toString(), itemName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -80,7 +94,7 @@ public class Commandpowertool extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
charge(user);
|
charge(user);
|
||||||
user.setPowertool(is, command);
|
user.setPowertool(is, powertools);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception
|
private String appendPowerTool(User user, String command, ItemStack is, String itemName) throws Exception
|
||||||
|
Loading…
Reference in New Issue
Block a user