diff --git a/src/main/java/cactusServer/entities/Character.java b/src/main/java/cactusServer/entities/Character.java index 2661bc2..d4328f7 100644 --- a/src/main/java/cactusServer/entities/Character.java +++ b/src/main/java/cactusServer/entities/Character.java @@ -77,7 +77,7 @@ } public Map createItem(String name, int amount) { - String id = createUniqueId(UNIQUE_ID_LENGTH, itemMap.keySet()); + String id = new RandomStringGenerator().createUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, itemMap.keySet()); Item item = new Item(name, amount); itemMap.put(id, item); return new HashMap() { @@ -92,24 +92,4 @@ public Item destroyItem(String itemId) { return itemMap.remove(itemId); } - - private String createUniqueId(int length, Set idSet) { - String id; - do { - id = createRandomId(length); - } while (checkId(id, idSet)); - return id; - } - - private boolean checkId(String id, Set idSet) { - return idSet.contains(id); - } - - private String createRandomId(int length) { - StringBuilder id = new StringBuilder(""); - do { - id.append(UUID.randomUUID().toString()); - } while (id.length() < length); - return id.substring(0, length); - } }