diff options
author | Maximusbarcz <maxim.baranek@gmail.com> | 2023-01-16 19:23:35 +0100 |
---|---|---|
committer | Maximusbarcz <maxim.baranek@gmail.com> | 2023-01-16 19:23:35 +0100 |
commit | c940f1261b74e83c135703fa0c35d3f8e5605761 (patch) | |
tree | 6b2fd4e91488da45a76807dc86d097f8fa3f9d8f /src/main/java | |
parent | dfad85d18a2a7fa55cd8adf85216e92519aa47ba (diff) | |
download | ygasi-c940f1261b74e83c135703fa0c35d3f8e5605761.tar.gz ygasi-c940f1261b74e83c135703fa0c35d3f8e5605761.tar.bz2 ygasi-c940f1261b74e83c135703fa0c35d3f8e5605761.zip |
Some small changes now, mainly a config button in the main branch gui for moderators
Diffstat (limited to 'src/main/java')
4 files changed, 28 insertions, 15 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java index 8c1fa4b..728f976 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.Ygasi; import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.*; @@ -9,6 +10,7 @@ import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.stat.Stats; import net.minecraft.text.Text; @@ -157,6 +159,19 @@ public class BranchGui { .setCallback((index, clickType, actionType) -> ResetGui.gui(player)) ); + //config button for admins + if (player.hasPermissionLevel(4)) { + gui.setSlot(0, new GuiElementBuilder() + .setItem(Items.COMPARATOR) + .setName(Text.translatable("gui.ygasi.branch.config.title")) + .addLoreLine(Text.translatable("gui.ygasi.branch.config.lore")) + .setCallback((index, clickType, actionType) -> { + ConfigGui.gui(player, true); + player.playSound(SoundEvent.of(Ygasi.click), SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + } + //grant the player the root advancement of ygasi AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/root"), "opened_skill_menu"); @@ -191,21 +206,14 @@ public class BranchGui { put("druidry", DruidryGui.class); }}; - final Map<String, String> BRANCH_TO_ADVANCEMENT = new HashMap<>() {{ - put("mercenary", "unlocked_mercenary"); - put("wizardry", "unlocked_wizardry"); - put("druidry", "unlocked_druidry"); - }}; - Identifier advancementId = new Identifier("minecraft", "ygasi/" + branch); - String advancementCriterion = BRANCH_TO_ADVANCEMENT.get(branch); Class<?> guiClass = BRANCH_TO_GUI.get(branch); if (hasMercenary || hasWizadry || hasDrudiry) { player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F); player.closeHandledScreen(); } else { - AdvUtils.grantAdvancementCriterion(player, advancementId, advancementCriterion); + AdvUtils.grantAdvancementCriterion(player, advancementId, "unlocked_" + branch); unlockSuccess(player, branchName); try { Method guiMethod = guiClass.getMethod("gui", ServerPlayerEntity.class); diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java index 21934a8..bfd3e23 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.Ygasi; import dev.mayaqq.ygasi.registry.ConfigRegistry; import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.gui.SignGui; @@ -17,12 +18,16 @@ import static dev.mayaqq.ygasi.Ygasi.click; public class ConfigGui { - public static void gui(ServerPlayerEntity player) { + public static void gui(ServerPlayerEntity player, Boolean fromBranch) { SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) { @Override public void onClose() { - ConfigRegistry.save(); super.onClose(); + ConfigRegistry.save(); + if (fromBranch) { + BranchGui.gui(player); + player.playSound(SoundEvent.of(Ygasi.click), SoundCategory.PLAYERS, 1.0F, 1.0F); + } } }; @@ -54,7 +59,7 @@ public class ConfigGui { ConfigRegistry.CONFIG.enableSkillBook = !ConfigRegistry.CONFIG.enableSkillBook; player.playSound(SoundEvent.of(click), SoundCategory.PLAYERS, 1.0F, 1.0F); gui.close(); - gui(player); + gui(player, false); }) ); @@ -112,7 +117,7 @@ public class ConfigGui { } catch (Exception e) { player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); } - gui(player); + gui(player, false); } }; gui.open(); diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java index c74280f..2f79874 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java @@ -63,6 +63,7 @@ public class ResetGui { public static void reset(ServerPlayerEntity player) { //check if player experience level is greater than 10 //revoke the abilities first + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/root"); if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) { AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/mercenary"); String[] subBranches = {"mercenary.Offence", "mercenary.Ninja", "mercenary.Defence"}; @@ -75,9 +76,8 @@ public class ResetGui { private static void resetBranch (String[] subBranches, ServerPlayerEntity player) { for (String subBranch : subBranches) { for (int i = 1; i < 4; i++) { - String branch = subBranch + i; try { - Class<?> branchClass = Class.forName("dev.mayaqq.ygasi.abilities." + branch); + Class<?> branchClass = Class.forName("dev.mayaqq.ygasi.abilities." + subBranch + i); branchClass.getMethod("revoke", ServerPlayerEntity.class).invoke(null, player); } catch (Exception e) { diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java index f46de64..bdd93d6 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java @@ -83,7 +83,7 @@ public class CommandRegistry { })))) .then(literal("config") .executes(context -> { - ConfigGui.gui(context.getSource().getPlayer()); + ConfigGui.gui(context.getSource().getPlayer(), false); return 1; }) .then(literal("reload") |