Skip to content

Commit

Permalink
random fixes before v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed May 28, 2021
1 parent d1eeca8 commit 3d4fe47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public static void load() throws IOException {

public static void save() throws IOException {
String[] intermediary = new String[username.length];
StringBuilder toSave = new StringBuilder();
String toSave = "";
for (int i = 0; i < username.length; i++) {
intermediary[i] = username[i] + ":" + nickname[i];
toSave.append(intermediary[i]).append("\n");
toSave += intermediary[i] + "\n";
}
loadFile.save("nick.txt",toSave.toString());
loadFile.save("nick.txt",toSave);
}

public static String getName(PlayerEntity user) {
Expand All @@ -78,14 +78,12 @@ public static String getName(PlayerEntity user) {

public static void registerCommand() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
dispatcher.register(literal("nick").then(argument("nickname", StringArgumentType.string()).executes(context -> {
var ctx = argument("nickname", StringArgumentType.string()).executes(context -> {
addName(context.getSource().getPlayer(),StringArgumentType.getString(context,"nickname"));
return 1;
})));
dispatcher.register(literal("nickname").then(argument("nickname", StringArgumentType.string()).executes(context -> {
addName(context.getSource().getPlayer(),StringArgumentType.getString(context,"nickname"));
return 1;
})));
});
dispatcher.register(literal("nick").then(ctx));
dispatcher.register(literal("nickname").then(ctx));
});
}
}
22 changes: 8 additions & 14 deletions src/main/java/com/github/olivermakescode/extension/swapRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@

public class swapRow {
public static void swap(int row, PlayerEntity player) {
int startIdx = row*9;

for (int i = startIdx; i<startIdx+9; i++) {
int currSlot = i-startIdx;
for (int i = row*9; i<row*9+9; i++) {
int currSlot = i-row*9;
ItemStack currItem = player.getInventory().getStack(i);
ItemStack currHotbar = player.getInventory().getStack(currSlot);
player.getInventory().setStack(currSlot,currItem);
player.getInventory().setStack(i,currHotbar);
}
player.getInventory().selectedSlot = 0;
}

public static void register() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
dispatcher.register(literal("hb").then(argument("slot", IntegerArgumentType.integer(1,3)).executes(context -> {
swap(IntegerArgumentType.getInteger(context,"slot"), context.getSource().getPlayer());
var ctx = argument("slot", IntegerArgumentType.integer(1, 3)).executes(context -> {
swap(IntegerArgumentType.getInteger(context, "slot"), context.getSource().getPlayer());
return 1;
})));
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
dispatcher.register(literal("hotbar").then(argument("slot", IntegerArgumentType.integer(1,3)).executes(context -> {
swap(IntegerArgumentType.getInteger(context,"slot"), context.getSource().getPlayer());
return 1;
})));
});

dispatcher.register(literal("hotbar").then(ctx));
dispatcher.register(literal("hb").then(ctx));
});
}
}

0 comments on commit 3d4fe47

Please sign in to comment.