Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified gradlew
100644 → 100755
Empty file.
20 changes: 6 additions & 14 deletions src/main/java/net/levelz/data/LevelLists.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.levelz.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class LevelLists {
Expand Down Expand Up @@ -60,26 +61,17 @@ public class LevelLists {
public static final ArrayList<Object> compassList = new ArrayList<Object>();
// Misc
public static final List<ArrayList<Object>> listOfAllLists = new ArrayList<>();
// Player
public static final List<List<Integer>> miningBlockList = new ArrayList<List<Integer>>();
public static final List<Integer> miningLevelList = new ArrayList<Integer>();

public static final List<List<Integer>> brewingItemList = new ArrayList<List<Integer>>();
public static final List<Integer> brewingLevelList = new ArrayList<Integer>();
public static final List<Object> potionList = new ArrayList<Object>();

public static final List<List<Integer>> smithingItemList = new ArrayList<List<Integer>>();
public static final List<Integer> smithingLevelList = new ArrayList<Integer>();

public static final List<List<Integer>> craftingItemList = new ArrayList<List<Integer>>();
public static final List<Integer> craftingLevelList = new ArrayList<Integer>();
public static final List<String> craftingSkillList = new ArrayList<String>();

// Custom
public static final ArrayList<Object> customBlockList = new ArrayList<Object>();
public static final ArrayList<Object> customItemList = new ArrayList<Object>();
public static final ArrayList<Object> customEntityList = new ArrayList<Object>();

public static final HashMap<String, List<Integer>> levelLists = new HashMap<>();
public static final HashMap<String, List<List<Integer>>> levelObjectsLists = new HashMap<>();
public static final HashMap<String, List<Object>> levelExtraDataLists = new HashMap<>();
public static final HashMap<String, Boolean> levelHasExtraData = new HashMap<>();

public static ArrayList<Object> getList(String string) {
switch (string) {
// Item
Expand Down
87 changes: 51 additions & 36 deletions src/main/java/net/levelz/data/LevelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -418,41 +419,61 @@ private void fillLists(JsonObject data, boolean addToExisting, int type, int ind
}
}


private static final HashMap<Integer, String> skillReferenceMap = new HashMap<Integer, String>() {{
put(1, "mining");
put(2, "alchemy");
put(3, "smithing");
put(4, "crafting");
}};

public static void addSkillReference(int id, String skill) {
if(skillReferenceMap.get(id) != null){
throw new IllegalArgumentException("Skill reference already exists");
}
skillReferenceMap.put(id, skill);
}

public static String getReferencedSkillName(int reference){
return skillReferenceMap.get(reference);
}

// type: 1 = mining; 2 = brewing; 3 = smithing; 4 = crafting
private void sortAndFillLists(List<Integer> levelList, List<List<Integer>> objectList, int type) {
// clear replace list for next usage
replaceList.clear();

if (type != 0) {
if (type == 1) {
LevelLists.miningLevelList.addAll(levelList);
LevelLists.miningLevelList.sort(Comparator.naturalOrder());
for (int i = 0; i < levelList.size(); i++)
LevelLists.miningBlockList.add(i, objectList.get(levelList.indexOf(LevelLists.miningLevelList.get(i))));

} else if (type == 2) {
LevelLists.brewingLevelList.addAll(levelList);
LevelLists.brewingLevelList.sort(Comparator.naturalOrder());
for (int i = 0; i < levelList.size(); i++)
LevelLists.brewingItemList.add(i, objectList.get(levelList.indexOf(LevelLists.brewingLevelList.get(i))));

} else if (type == 3) {
LevelLists.smithingLevelList.addAll(levelList);
LevelLists.smithingLevelList.sort(Comparator.naturalOrder());
for (int i = 0; i < levelList.size(); i++)
LevelLists.smithingItemList.add(i, objectList.get(levelList.indexOf(LevelLists.smithingLevelList.get(i))));

} else if (type == 4) {
LevelLists.craftingLevelList.addAll(levelList);
LevelLists.craftingSkillList.addAll(skillList);
LevelLists.craftingItemList.addAll(objectList);
SortList.concurrentSort(LevelLists.craftingLevelList, LevelLists.craftingLevelList, LevelLists.craftingSkillList, LevelLists.craftingItemList);
this.skillList.clear();
String skill = getReferencedSkillName(type);
if(skill == null) {
return;
}

var levelListCopy = LevelLists.levelLists.getOrDefault(skill, new ArrayList<>());
var objListCopy = LevelLists.levelObjectsLists.getOrDefault(skill, new ArrayList<>());
levelListCopy.addAll(levelList);

if(skillList.isEmpty()){
levelListCopy.sort(Comparator.naturalOrder());
for (int i = 0; i < levelList.size(); i++) {
objListCopy.add(i, objectList.get(levelList.indexOf(levelListCopy.get(i))));
}
this.objectList.clear();
this.levelList.clear();
}else{
var extraList = LevelLists.levelExtraDataLists.getOrDefault(skill, new ArrayList<>());
extraList.addAll(skillList);
objListCopy.addAll(objectList);

SortList.concurrentSort(levelListCopy, levelListCopy, extraList, objListCopy);

LevelLists.levelExtraDataLists.put(skill, extraList);
this.skillList.clear();
}

LevelLists.levelLists.put(skill, levelListCopy);
LevelLists.levelObjectsLists.put(skill, objListCopy);

this.objectList.clear();
this.levelList.clear();

}

public static void addAllInOneList() {
Expand Down Expand Up @@ -568,15 +589,9 @@ public static void clearEveryList() {
LevelLists.customItemList.clear();
LevelLists.customEntityList.clear();

LevelLists.miningBlockList.clear();
LevelLists.miningLevelList.clear();
LevelLists.brewingItemList.clear();
LevelLists.brewingLevelList.clear();
LevelLists.smithingItemList.clear();
LevelLists.smithingLevelList.clear();
LevelLists.craftingItemList.clear();
LevelLists.craftingLevelList.clear();
LevelLists.craftingSkillList.clear();
LevelLists.levelLists.clear();
LevelLists.levelObjectsLists.clear();
LevelLists.levelExtraDataLists.clear();
// Potion list isn't filled via levelz datapacks
// LevelLists.potionList.clear();
}
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/net/levelz/data/SkillArgumentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.levelz.data;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.levelz.stats.Skill;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class SkillArgumentType implements ArgumentType<String> {

public static SkillArgumentType skill() {
return new SkillArgumentType();
}

public static List<String> skillStrings() {
List<String> skillStrings = new ArrayList<>();
for(var skill: Skill.values()){
skillStrings.add(skill.getName().toLowerCase());
}
skillStrings.add("level");
skillStrings.add("points");
skillStrings.add("experience");
return skillStrings;
}

@Override
public String parse(StringReader reader) throws CommandSyntaxException {
int argBeginning = reader.getCursor(); // The starting position of the cursor is at the beginning of the argument.
if (!reader.canRead()) {
reader.skip();
}

// Now we check the contents of the argument till either we hit the end of the
// command line (when ''canRead'' becomes false)
// Otherwise we go till reach reach a space, which signifies the next argument
while (reader.canRead() && reader.peek() != ' ') { // peek provides the character at the current cursor position.
reader.skip(); // Tells the StringReader to move it's cursor to the next position.
}

// Now we substring the specific part we want to see using the starting cursor
// position and the ends where the next argument starts.
String skillRawString = reader.getString().substring(argBeginning, reader.getCursor());
try {
if(skillStrings().contains(skillRawString.toLowerCase())){
return skillRawString.toLowerCase();
}
// And we return our type, in this case the parser will consider this
// argument to have parsed properly and then move on.
} catch (Exception ex) {
// UUIDs can throw an exception when made by a string, so we catch the exception
// and repackage it into a CommandSyntaxException type.
// Create with context tells Brigadier to supply some context to tell the user
// where the command failed at.
// Though normal create method could be used.
throw new SimpleCommandExceptionType(Text.literal(ex.getMessage())).createWithContext(reader);
}
throw new SimpleCommandExceptionType(Text.literal("Invalid skill")).createWithContext(reader);
}

@Override
public Collection<String> getExamples() {
return skillStrings();
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
for(var skillString: skillStrings()){
if(skillString.startsWith(builder.getRemaining().toLowerCase())){
builder.suggest(skillString);
}
}
return builder.buildFuture();
}

}
Loading