├── .github ├── dependabot.yml └── workflows │ ├── publish-javadoc.yml │ └── stale.yml ├── AdvancedCore ├── .factorypath ├── .gitignore ├── .project ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bencodez │ │ │ └── advancedcore │ │ │ ├── AdvancedCoreConfigOptions.java │ │ │ ├── AdvancedCorePlugin.java │ │ │ ├── VaultHandler.java │ │ │ ├── api │ │ │ ├── backup │ │ │ │ ├── BackupHandle.java │ │ │ │ └── ZipCreator.java │ │ │ ├── bookgui │ │ │ │ ├── BookWrapper.java │ │ │ │ └── Layout.java │ │ │ ├── cmi │ │ │ │ └── CMIHandler.java │ │ │ ├── command │ │ │ │ ├── AdvancedCoreTabCompleteHandler.java │ │ │ │ ├── CommandHandler.java │ │ │ │ └── PlayerCommandHandler.java │ │ │ ├── exceptions │ │ │ │ └── FileDirectoryException.java │ │ │ ├── geyser │ │ │ │ └── GeyserHandle.java │ │ │ ├── gui │ │ │ │ ├── GUIHandler.java │ │ │ │ └── GUIMethod.java │ │ │ ├── hologram │ │ │ │ ├── Hologram.java │ │ │ │ └── HologramHandler.java │ │ │ ├── inventory │ │ │ │ ├── BInventory.java │ │ │ │ ├── BInventoryButton.java │ │ │ │ ├── BInventoryListener.java │ │ │ │ ├── GUISession.java │ │ │ │ ├── UpdatingBInventoryButton.java │ │ │ │ └── editgui │ │ │ │ │ ├── EditGUI.java │ │ │ │ │ ├── EditGUIButton.java │ │ │ │ │ ├── EditGUIValueType.java │ │ │ │ │ └── valuetypes │ │ │ │ │ ├── EditGUIValue.java │ │ │ │ │ ├── EditGUIValueBoolean.java │ │ │ │ │ ├── EditGUIValueInventory.java │ │ │ │ │ ├── EditGUIValueList.java │ │ │ │ │ ├── EditGUIValueNumber.java │ │ │ │ │ └── EditGUIValueString.java │ │ │ ├── item │ │ │ │ ├── FullInventoryHandler.java │ │ │ │ ├── ItemBuilder.java │ │ │ │ ├── ItemsAdderHandle.java │ │ │ │ ├── NexoItemHandle.java │ │ │ │ └── ReflectionModelUtil.java │ │ │ ├── javascript │ │ │ │ ├── JavascriptEngine.java │ │ │ │ ├── JavascriptEngineHandler.java │ │ │ │ └── JavascriptPlaceholderRequest.java │ │ │ ├── messages │ │ │ │ ├── MessageBuilder.java │ │ │ │ └── PlaceholderUtils.java │ │ │ ├── misc │ │ │ │ ├── CompatibleCacheBuilder.java │ │ │ │ ├── MiscUtils.java │ │ │ │ ├── PlayerManager.java │ │ │ │ ├── animation │ │ │ │ │ └── AnimationAPI.java │ │ │ │ ├── effects │ │ │ │ │ ├── ActionBar.java │ │ │ │ │ ├── BossBar.java │ │ │ │ │ ├── FireworkHandler.java │ │ │ │ │ ├── ItemMessage.java │ │ │ │ │ └── Title.java │ │ │ │ ├── files │ │ │ │ │ └── FilesManager.java │ │ │ │ └── scoreboards │ │ │ │ │ └── SimpleScoreboard.java │ │ │ ├── permissions │ │ │ │ ├── LuckPermsHandle.java │ │ │ │ ├── PermissionHandler.java │ │ │ │ └── PlayerPermissionHandler.java │ │ │ ├── placeholder │ │ │ │ ├── CalculatingPlaceholder.java │ │ │ │ ├── NonPlayerPlaceHolder.java │ │ │ │ └── PlaceHolder.java │ │ │ ├── rewards │ │ │ │ ├── DefinedReward.java │ │ │ │ ├── DirectlyDefinedReward.java │ │ │ │ ├── Inject.java │ │ │ │ ├── RepeatHandle.java │ │ │ │ ├── Reward.java │ │ │ │ ├── RewardBuilder.java │ │ │ │ ├── RewardEditData.java │ │ │ │ ├── RewardFileData.java │ │ │ │ ├── RewardFileDefinedReward.java │ │ │ │ ├── RewardHandler.java │ │ │ │ ├── RewardOptions.java │ │ │ │ ├── RewardPlaceholderHandle.java │ │ │ │ ├── SubDirectlyDefinedReward.java │ │ │ │ ├── editbuttons │ │ │ │ │ ├── RewardEdit.java │ │ │ │ │ ├── RewardEditActionBar.java │ │ │ │ │ ├── RewardEditAdvancedPriority.java │ │ │ │ │ ├── RewardEditAdvancedRandomReward.java │ │ │ │ │ ├── RewardEditAdvancedWorld.java │ │ │ │ │ ├── RewardEditBossBar.java │ │ │ │ │ ├── RewardEditChoices.java │ │ │ │ │ ├── RewardEditDate.java │ │ │ │ │ ├── RewardEditDelayed.java │ │ │ │ │ ├── RewardEditEXP.java │ │ │ │ │ ├── RewardEditEXPLevels.java │ │ │ │ │ ├── RewardEditEffect.java │ │ │ │ │ ├── RewardEditFirework.java │ │ │ │ │ ├── RewardEditItems.java │ │ │ │ │ ├── RewardEditJavascript.java │ │ │ │ │ ├── RewardEditLocationDistance.java │ │ │ │ │ ├── RewardEditLucky.java │ │ │ │ │ ├── RewardEditMessages.java │ │ │ │ │ ├── RewardEditMoney.java │ │ │ │ │ ├── RewardEditPotions.java │ │ │ │ │ ├── RewardEditSound.java │ │ │ │ │ ├── RewardEditSpecialChance.java │ │ │ │ │ ├── RewardEditTempPermission.java │ │ │ │ │ ├── RewardEditTimed.java │ │ │ │ │ └── RewardEditTitle.java │ │ │ │ ├── injected │ │ │ │ │ ├── RewardInject.java │ │ │ │ │ ├── RewardInjectBoolean.java │ │ │ │ │ ├── RewardInjectConfigurationSection.java │ │ │ │ │ ├── RewardInjectDouble.java │ │ │ │ │ ├── RewardInjectInt.java │ │ │ │ │ ├── RewardInjectKeys.java │ │ │ │ │ ├── RewardInjectString.java │ │ │ │ │ ├── RewardInjectStringList.java │ │ │ │ │ └── RewardInjectValidator.java │ │ │ │ └── injectedrequirement │ │ │ │ │ ├── RequirementInject.java │ │ │ │ │ ├── RequirementInjectBoolean.java │ │ │ │ │ ├── RequirementInjectConfigurationSection.java │ │ │ │ │ ├── RequirementInjectDouble.java │ │ │ │ │ ├── RequirementInjectInt.java │ │ │ │ │ ├── RequirementInjectKeys.java │ │ │ │ │ ├── RequirementInjectString.java │ │ │ │ │ ├── RequirementInjectStringList.java │ │ │ │ │ └── RequirementInjectValidator.java │ │ │ ├── time │ │ │ │ ├── TimeChecker.java │ │ │ │ ├── TimeType.java │ │ │ │ └── events │ │ │ │ │ ├── DateChangedEvent.java │ │ │ │ │ ├── DayChangeEvent.java │ │ │ │ │ ├── MonthChangeEvent.java │ │ │ │ │ ├── PreDateChangedEvent.java │ │ │ │ │ └── WeekChangeEvent.java │ │ │ ├── updater │ │ │ │ └── UpdateDownloader.java │ │ │ ├── user │ │ │ │ ├── AdvancedCoreUser.java │ │ │ │ ├── UserData.java │ │ │ │ ├── UserDataChanged.java │ │ │ │ ├── UserManager.java │ │ │ │ ├── UserStartup.java │ │ │ │ ├── UserStorage.java │ │ │ │ ├── usercache │ │ │ │ │ ├── UserDataCache.java │ │ │ │ │ ├── UserDataManager.java │ │ │ │ │ ├── change │ │ │ │ │ │ ├── UserDataChange.java │ │ │ │ │ │ ├── UserDataChangeBoolean.java │ │ │ │ │ │ ├── UserDataChangeInt.java │ │ │ │ │ │ └── UserDataChangeString.java │ │ │ │ │ └── keys │ │ │ │ │ │ ├── UserDataKey.java │ │ │ │ │ │ ├── UserDataKeyBoolean.java │ │ │ │ │ │ ├── UserDataKeyInt.java │ │ │ │ │ │ └── UserDataKeyString.java │ │ │ │ └── userstorage │ │ │ │ │ ├── mysql │ │ │ │ │ └── MySQL.java │ │ │ │ │ └── sql │ │ │ │ │ └── UserTable.java │ │ │ ├── valuerequest │ │ │ │ ├── InputMethod.java │ │ │ │ ├── ValueRequest.java │ │ │ │ ├── ValueRequestBuilder.java │ │ │ │ ├── book │ │ │ │ │ ├── BookManager.java │ │ │ │ │ └── BookSign.java │ │ │ │ ├── listeners │ │ │ │ │ ├── BooleanListener.java │ │ │ │ │ ├── Listener.java │ │ │ │ │ ├── NumberListener.java │ │ │ │ │ └── StringListener.java │ │ │ │ ├── prompt │ │ │ │ │ ├── PromptManager.java │ │ │ │ │ └── PromptReturnString.java │ │ │ │ ├── requesters │ │ │ │ │ ├── BooleanRequester.java │ │ │ │ │ ├── NumberRequester.java │ │ │ │ │ └── StringRequester.java │ │ │ │ └── sign │ │ │ │ │ └── SignMenu.java │ │ │ └── yml │ │ │ │ └── editor │ │ │ │ └── ConfigEditor.java │ │ │ ├── bungeeapi │ │ │ ├── globaldata │ │ │ │ ├── GlobalDataHandler.java │ │ │ │ ├── GlobalDataHandlerProxy.java │ │ │ │ └── GlobalMySQL.java │ │ │ └── time │ │ │ │ └── BungeeTimeChecker.java │ │ │ ├── command │ │ │ ├── CommandLoader.java │ │ │ ├── executor │ │ │ │ └── ValueRequestInputCommand.java │ │ │ └── gui │ │ │ │ ├── AdminGUI.java │ │ │ │ ├── ChoiceGUI.java │ │ │ │ ├── RewardEditGUI.java │ │ │ │ ├── RewardGUIConfirmation.java │ │ │ │ └── UserGUI.java │ │ │ ├── data │ │ │ └── ServerData.java │ │ │ ├── listeners │ │ │ ├── AdvancedCoreLoginEvent.java │ │ │ ├── AuthMeLogin.java │ │ │ ├── LoginSecurityLogin.java │ │ │ ├── PlayerJoinEvent.java │ │ │ ├── PlayerRewardEvent.java │ │ │ ├── PlayerShowListener.java │ │ │ ├── PluginUpdateVersionEvent.java │ │ │ └── WorldChangeEvent.java │ │ │ ├── logger │ │ │ └── Logger.java │ │ │ ├── nms │ │ │ ├── NMSManager.java │ │ │ └── ReflectionUtils.java │ │ │ └── thread │ │ │ ├── FileThread.java │ │ │ └── Thread.java │ └── resources │ │ ├── Rewards │ │ ├── ExampleAdvanced.yml │ │ └── ExampleBasic.yml │ │ └── advancedcoreversion.yml │ └── test │ └── java │ └── com │ └── bencodez │ └── advancedcore │ └── tests │ ├── AdvancedCoreUserTest.java │ ├── BackupHandleTest.java │ ├── BaseTest.java │ ├── BungeeTimeCheckerTest.java │ ├── TimeCheckerTest.java │ └── ZipCreatorTest.java ├── LICENSE └── README.md /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/AdvancedCore/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/publish-javadoc.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Javadoc 2 | 3 | on: 4 | release: 5 | types: [published] 6 | branches: 7 | - master 8 | - main 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Deploy JavaDoc 🚀 15 | uses: MathieuSoysal/Javadoc-publisher.yml@main 16 | with: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | javadoc-branch: gh-pages 19 | java-version: 17 20 | target-folder: '' 21 | project: maven # or gradle 22 | # subdirectories: moduleA moduleB #for subdirectories support, needs to be run with custom command 23 | custom-command: mvn -f AdvancedCore/pom.xml deploy -P javadoc javadoc:aggregate 24 | javadoc-source-folder: 'AdvancedCore/target/apidocs' 25 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | - cron: '32 18 * * *' 11 | 12 | jobs: 13 | stale: 14 | 15 | runs-on: ubuntu-latest 16 | permissions: 17 | issues: write 18 | pull-requests: write 19 | 20 | steps: 21 | - uses: actions/stale@v5 22 | with: 23 | repo-token: ${{ secrets.GITHUB_TOKEN }} 24 | stale-issue-message: 'Stale issue message' 25 | stale-pr-message: 'Stale pull request message' 26 | stale-issue-label: 'no-issue-activity' 27 | stale-pr-label: 'no-pr-activity' 28 | -------------------------------------------------------------------------------- /AdvancedCore/.factorypath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /AdvancedCore/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /target/ 3 | /.idea/ 4 | /*.iml 5 | /.settings/ 6 | /.classpath 7 | /.apt_generated/ 8 | /.apt_generated_tests/ 9 | -------------------------------------------------------------------------------- /AdvancedCore/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AdvancedCore 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/VaultHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.plugin.RegisteredServiceProvider; 6 | 7 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton; 8 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString; 9 | import com.bencodez.advancedcore.api.item.ItemBuilder; 10 | import com.bencodez.advancedcore.api.rewards.Reward; 11 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 12 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 13 | import com.bencodez.advancedcore.api.rewards.injectedrequirement.RequirementInjectString; 14 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 15 | 16 | import lombok.Getter; 17 | import net.milkbowl.vault.economy.Economy; 18 | import net.milkbowl.vault.permission.Permission; 19 | 20 | public class VaultHandler { 21 | public void loadVault(AdvancedCorePlugin plugin) { 22 | if (plugin.isLoadVault()) { 23 | plugin.getBukkitScheduler().runTaskLater(plugin, new Runnable() { 24 | 25 | @Override 26 | public void run() { 27 | if (setupEconomy(plugin)) { 28 | plugin.getLogger().info("Successfully hooked into vault economy!"); 29 | } else { 30 | plugin.getLogger().warning("Failed to hook into vault economy"); 31 | } 32 | 33 | if (setupPermissions(plugin)) { 34 | plugin.getLogger().info("Hooked into vault permissions"); 35 | 36 | plugin.getRewardHandler() 37 | .addInjectedRequirements(new RequirementInjectString("VaultGroup", "") { 38 | 39 | @Override 40 | public boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, 41 | String type, RewardOptions rewardOptions) { 42 | if (type.equals("")) { 43 | return true; 44 | } 45 | String group = ""; 46 | if (!rewardOptions.isGiveOffline() && user.isOnline()) { 47 | group = getPerms().getPrimaryGroup(user.getPlayer()); 48 | } else { 49 | group = getPerms().getPrimaryGroup(null, user.getOfflinePlayer()); 50 | } 51 | if (group.equalsIgnoreCase(type)) { 52 | return true; 53 | } 54 | return false; 55 | } 56 | }.priority(100).addEditButton(new EditGUIButton(new ItemBuilder(Material.PAPER), 57 | new EditGUIValueString("VaultGroup", null) { 58 | 59 | @Override 60 | public void setValue(Player player, String value) { 61 | RewardEditData reward = (RewardEditData) getInv().getData("Reward"); 62 | reward.setValue(getKey(), value); 63 | plugin.reloadAdvancedCore(false); 64 | } 65 | }.addOptions(getPerms().getGroups())))); 66 | } else { 67 | plugin.getLogger().warning("Failed to hook into vault permissions"); 68 | } 69 | } 70 | }, 5); 71 | } else { 72 | plugin.debug("Vault hook disabled"); 73 | } 74 | } 75 | 76 | private boolean setupEconomy(AdvancedCorePlugin plugin) { 77 | if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) { 78 | return false; 79 | } 80 | RegisteredServiceProvider rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); 81 | if (rsp == null) { 82 | return false; 83 | } 84 | econ = rsp.getProvider(); 85 | return econ != null; 86 | } 87 | 88 | @Getter 89 | private Economy econ = null; 90 | 91 | private boolean setupPermissions(AdvancedCorePlugin plugin) { 92 | if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) { 93 | return false; 94 | } 95 | RegisteredServiceProvider rsp = plugin.getServer().getServicesManager() 96 | .getRegistration(Permission.class); 97 | if (rsp == null) { 98 | return false; 99 | } 100 | perms = rsp.getProvider(); 101 | return perms != null; 102 | } 103 | 104 | @Getter 105 | private Permission perms; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/backup/BackupHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.backup; 2 | 3 | import java.io.File; 4 | import java.time.LocalDateTime; 5 | 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.advancedcore.api.misc.MiscUtils; 11 | import com.bencodez.advancedcore.api.time.TimeType; 12 | import com.bencodez.advancedcore.api.time.events.DateChangedEvent; 13 | 14 | public class BackupHandle implements Listener { 15 | private static BackupHandle instance = new BackupHandle(); 16 | 17 | public static BackupHandle getInstance() { 18 | return instance; 19 | } 20 | 21 | private BackupHandle() { 22 | } 23 | 24 | public void checkOldBackups() { 25 | for (File file : new File(AdvancedCorePlugin.getInstance().getDataFolder(), "Backups").listFiles()) { 26 | long lastModified = file.lastModified(); 27 | if (LocalDateTime.now().minusDays(5).isAfter(MiscUtils.getInstance().getTime(lastModified))) { 28 | file.delete(); 29 | AdvancedCorePlugin.getInstance().debug("Deleting old backup: " + file.getName()); 30 | } 31 | } 32 | } 33 | 34 | @EventHandler 35 | public void onPostDateChange(DateChangedEvent e) { 36 | if (!e.getTimeType().equals(TimeType.DAY) || !AdvancedCorePlugin.getInstance().getOptions().isCreateBackups()) { 37 | return; 38 | } 39 | 40 | LocalDateTime now = AdvancedCorePlugin.getInstance().getTimeChecker().getTime(); 41 | ZipCreator.getInstance().create(AdvancedCorePlugin.getInstance().getDataFolder(), 42 | new File(AdvancedCorePlugin.getInstance().getDataFolder(), "Backups" + File.separator + "Backup-" 43 | + now.getYear() + "_" + now.getMonth() + "_" + now.getDayOfMonth() + ".zip")); 44 | 45 | checkOldBackups(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/BookWrapper.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.bookgui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.simpleapi.messages.MessageAPI; 11 | 12 | import lombok.Getter; 13 | import lombok.Setter; 14 | import net.md_5.bungee.api.chat.BaseComponent; 15 | import xyz.upperlevel.spigot.book.BookUtil; 16 | 17 | public class BookWrapper { 18 | @Getter 19 | private ItemStack book; 20 | @Getter 21 | private ArrayList builder = new ArrayList<>(); 22 | @Getter 23 | private BookUtil.PageBuilder currentPage; 24 | @Getter 25 | @Setter 26 | private int currentPageLines = 0; 27 | @Getter 28 | private HashMap placeholders = new HashMap<>(); 29 | @Getter 30 | @Setter 31 | private String title; 32 | 33 | public BookWrapper(String title) { 34 | this.title = title; 35 | currentPage = new BookUtil.PageBuilder(); 36 | } 37 | 38 | public BookWrapper addLayout(Layout layout) { 39 | addToCurrentPage(layout.getLayout(getPlaceholders())); 40 | return this; 41 | } 42 | 43 | public BookWrapper addLine() { 44 | currentPageLines += 1; 45 | if (currentPageLines > 14) { 46 | nextPage(0); 47 | } 48 | currentPage.newLine(); 49 | return this; 50 | } 51 | 52 | public BookWrapper addPlaceholder(String toReplace, String replaceWith) { 53 | placeholders.put(toReplace, replaceWith); 54 | return this; 55 | } 56 | 57 | public BookWrapper addToCurrentPage(BaseComponent... baseComponents) { 58 | currentPageLines += baseComponents.length; 59 | if (currentPageLines > 14) { 60 | nextPage(baseComponents.length); 61 | } 62 | for (BaseComponent comp : baseComponents) { 63 | currentPage.add(comp); 64 | currentPage.newLine(); 65 | } 66 | return this; 67 | } 68 | 69 | public String colorize(String s) { 70 | return MessageAPI.colorize(s); 71 | } 72 | 73 | public BookWrapper nextPage(int newSize) { 74 | builder.add(currentPage.build()); 75 | currentPage = new BookUtil.PageBuilder(); 76 | currentPageLines = newSize; 77 | return this; 78 | } 79 | 80 | public void open(Player player) { 81 | builder.add(currentPage.build()); 82 | book = BookUtil.writtenBook().author(player.getName()).title(colorize(title)).pages(builder).build(); 83 | AdvancedCorePlugin.getInstance().getBukkitScheduler().runTask(AdvancedCorePlugin.getInstance(), new Runnable() { 84 | 85 | @Override 86 | public void run() { 87 | BookUtil.openPlayer(player, book); 88 | } 89 | }, player); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/Layout.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.bookgui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.regex.Pattern; 6 | 7 | import com.bencodez.advancedcore.api.messages.PlaceholderUtils; 8 | import com.bencodez.simpleapi.messages.MessageAPI; 9 | 10 | import lombok.Getter; 11 | import net.md_5.bungee.api.ChatColor; 12 | import net.md_5.bungee.api.chat.BaseComponent; 13 | import net.md_5.bungee.api.chat.TextComponent; 14 | 15 | public class Layout { 16 | private BaseComponent compToAdd; 17 | 18 | private HashMap placeholders = new HashMap<>(); 19 | @Getter 20 | private ArrayList stringLayout; 21 | private String text; 22 | 23 | public Layout(ArrayList layout) { 24 | this.stringLayout = layout; 25 | } 26 | 27 | public Layout addPlaceholder(String toReplace, String replaceWith) { 28 | placeholders.put(toReplace, replaceWith); 29 | return this; 30 | } 31 | 32 | private String colorize(String s) { 33 | return ChatColor.translateAlternateColorCodes('&', s); 34 | } 35 | 36 | public BaseComponent[] getLayout(HashMap placeholders) { 37 | stringLayout = PlaceholderUtils.replacePlaceHolder(stringLayout, placeholders); 38 | stringLayout = PlaceholderUtils.replacePlaceHolder(stringLayout, this.placeholders); 39 | ArrayList layout = new ArrayList<>(); 40 | for (int i = 0; i < stringLayout.size(); i++) { 41 | String str = stringLayout.get(i); 42 | 43 | if (text != null && !text.equals("") && MessageAPI.containsIgnorecase(str, text)) { 44 | String[] split = str.split(Pattern.quote(text)); 45 | 46 | String first = ""; 47 | String last = ""; 48 | if (split.length > 0) { 49 | first = split[0]; 50 | if (split.length > 1) { 51 | last = split[1]; 52 | } 53 | } 54 | BaseComponent comp = new TextComponent(colorize(first)); 55 | comp.addExtra(compToAdd); 56 | comp.addExtra(colorize(last)); 57 | layout.add(comp); 58 | 59 | } else { 60 | layout.add(new TextComponent(colorize(str))); 61 | } 62 | } 63 | BaseComponent[] comps = new BaseComponent[layout.size()]; 64 | for (int i = 0; i < layout.size(); i++) { 65 | comps[i] = layout.get(i); 66 | } 67 | return comps; 68 | } 69 | 70 | public Layout replaceTextComponent(String text, BaseComponent compToAdd) { 71 | this.text = text; 72 | this.compToAdd = compToAdd; 73 | return this; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/cmi/CMIHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.cmi; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.Zrips.CMI.CMI; 6 | 7 | public class CMIHandler { 8 | public boolean isVanished(Player p) { 9 | return CMI.getInstance().getPlayerManager().getUser(p).isVanished(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/AdvancedCoreTabCompleteHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.command; 2 | 3 | import java.util.ArrayList; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import org.bukkit.command.CommandSender; 7 | 8 | import com.bencodez.simpleapi.command.TabCompleteHandler; 9 | 10 | public class AdvancedCoreTabCompleteHandler { 11 | static AdvancedCoreTabCompleteHandler instance = new AdvancedCoreTabCompleteHandler(); 12 | 13 | public static AdvancedCoreTabCompleteHandler getInstance() { 14 | return instance; 15 | } 16 | 17 | public ArrayList getTabCompleteOptions(ArrayList handles, CommandSender sender, 18 | String[] args, int argNum) { 19 | ArrayList tabComplete = new ArrayList<>(); 20 | ConcurrentHashMap> options = TabCompleteHandler.getInstance().getTabCompleteOptions(); 21 | for (CommandHandler h : handles) { 22 | tabComplete.addAll(h.getTabCompleteOptions(sender, args, argNum, options)); 23 | } 24 | return tabComplete; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/PlayerCommandHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | 7 | public abstract class PlayerCommandHandler extends CommandHandler { 8 | 9 | private int playerArg = -1; 10 | 11 | public PlayerCommandHandler(AdvancedCorePlugin plugin) { 12 | super(plugin); 13 | figureOutPlayerArg(); 14 | } 15 | 16 | public PlayerCommandHandler(AdvancedCorePlugin plugin, String[] args, String perm) { 17 | super(plugin, args, perm); 18 | figureOutPlayerArg(); 19 | } 20 | 21 | public PlayerCommandHandler(AdvancedCorePlugin plugin, String[] args, String perm, String helpMessage) { 22 | super(plugin, args, perm, helpMessage); 23 | figureOutPlayerArg(); 24 | } 25 | 26 | public PlayerCommandHandler(AdvancedCorePlugin plugin, String[] args, String perm, String helpMessage, 27 | boolean allowConsole) { 28 | super(plugin, args, perm, helpMessage, allowConsole); 29 | figureOutPlayerArg(); 30 | } 31 | 32 | public PlayerCommandHandler(AdvancedCorePlugin plugin, String[] args, String perm, String helpMessage, 33 | boolean allowConsole, boolean forceConsole) { 34 | super(plugin, args, perm, helpMessage, allowConsole); 35 | figureOutPlayerArg(); 36 | } 37 | 38 | @Override 39 | public void execute(CommandSender sender, String[] args) { 40 | if (playerArg >= 0) { 41 | if (args[playerArg].equalsIgnoreCase("all")) { 42 | executeAll(sender, args); 43 | } 44 | } 45 | executeSinglePlayer(sender, args); 46 | } 47 | 48 | public abstract void executeAll(CommandSender sender, String[] args); 49 | 50 | public abstract void executeSinglePlayer(CommandSender sender, String[] args); 51 | 52 | private void figureOutPlayerArg() { 53 | for (int i = 0; i < getArgs().length; i++) { 54 | if (getArgs()[i].equalsIgnoreCase("(player)")) { 55 | playerArg = i; 56 | return; 57 | } 58 | } 59 | getPlugin().devDebug("Failed to figure out player arg number for: " + getArgs()); 60 | } 61 | 62 | @Override 63 | public void setArgs(String[] args) { 64 | super.setArgs(args); 65 | figureOutPlayerArg(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/exceptions/FileDirectoryException.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.exceptions; 2 | 3 | public class FileDirectoryException extends Exception { 4 | private static final long serialVersionUID = 3691439344307857655L; 5 | 6 | public FileDirectoryException() { 7 | 8 | } 9 | 10 | public FileDirectoryException(String message) { 11 | super(message); 12 | } 13 | 14 | public FileDirectoryException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public FileDirectoryException(Throwable cause) { 19 | super(cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/geyser/GeyserHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.geyser; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.util.UUID; 6 | 7 | public class GeyserHandle { 8 | private Class geyserClass; 9 | private Object geyserAPI; 10 | private Method method; 11 | private boolean geyserExists = false; 12 | 13 | public boolean isGeyserPlayer(UUID player) { 14 | if (geyserExists) { 15 | Object value; 16 | try { 17 | value = method.invoke(geyserAPI, player); 18 | 19 | if (value instanceof Boolean) { 20 | return (boolean) value; 21 | } 22 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 23 | // e.printStackTrace(); 24 | } 25 | } 26 | return false; 27 | } 28 | 29 | public void load() { 30 | try { 31 | geyserClass = Class.forName("org.geysermc.geyser.api.GeyserApi"); 32 | 33 | geyserAPI = geyserClass.getMethod("api", new Class[] {}).invoke(geyserClass, new Object[] {}); 34 | 35 | method = geyserAPI.getClass().getMethod("isBedrockPlayer", UUID.class); 36 | geyserExists = true; 37 | } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException 38 | | InvocationTargetException | ClassNotFoundException e) { 39 | // e.printStackTrace(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIHandler.java: -------------------------------------------------------------------------------- 1 | 2 | package com.bencodez.advancedcore.api.gui; 3 | 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | import com.bencodez.advancedcore.AdvancedCorePlugin; 11 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 12 | import com.bencodez.simpleapi.array.ArrayUtils; 13 | import com.bencodez.simpleapi.messages.MessageAPI; 14 | 15 | import lombok.Getter; 16 | import net.md_5.bungee.api.chat.TextComponent; 17 | 18 | public abstract class GUIHandler { 19 | @Getter 20 | private HashMap data = new HashMap<>(); 21 | 22 | @Getter 23 | private CommandSender player; 24 | 25 | @Getter 26 | private AdvancedCorePlugin plugin; 27 | 28 | public GUIHandler(AdvancedCorePlugin plugin, CommandSender player) { 29 | this.plugin = plugin; 30 | this.player = player; 31 | } 32 | 33 | public String colorize(String str) { 34 | return MessageAPI.colorize(str); 35 | } 36 | 37 | public abstract ArrayList getChat(CommandSender sender); 38 | 39 | public abstract void onBook(Player player); 40 | 41 | public abstract void onChat(CommandSender player); 42 | 43 | public abstract void onChest(Player player); 44 | 45 | public abstract void open(); 46 | 47 | public void open(GUIMethod method) { 48 | if (player instanceof Player) { 49 | switch (method) { 50 | case BOOK: 51 | onBook((Player) player); 52 | return; 53 | case CHAT: 54 | onChat(player); 55 | return; 56 | case CHEST: 57 | onChest((Player) player); 58 | return; 59 | default: 60 | break; 61 | 62 | } 63 | } else { 64 | onChat(player); 65 | } 66 | } 67 | 68 | public void sendMessage(ArrayList message) { 69 | if (player instanceof Player) { 70 | AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); 71 | user.sendMessage(message); 72 | } else { 73 | player.sendMessage(ArrayUtils.convert(message)); 74 | } 75 | } 76 | 77 | public void sendMessage(String... message) { 78 | if (player instanceof Player) { 79 | AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); 80 | user.sendMessage(message); 81 | } else { 82 | player.sendMessage(message); 83 | } 84 | } 85 | 86 | public void sendMessageJson(ArrayList text) { 87 | if (player instanceof Player) { 88 | AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); 89 | user.sendJson(text); 90 | } else { 91 | player.sendMessage(ArrayUtils.convert(ArrayUtils.comptoString(text))); 92 | } 93 | } 94 | 95 | public void setData(String str, Object value) { 96 | data.put(str, value); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIMethod.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.gui; 2 | 3 | public enum GUIMethod { 4 | BOOK, CHAT, CHEST; 5 | } 6 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/HologramHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.hologram; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | 7 | public class HologramHandler { 8 | private ArrayList list; 9 | @SuppressWarnings("unused") 10 | private AdvancedCorePlugin plugin; 11 | 12 | public HologramHandler(AdvancedCorePlugin plugin) { 13 | this.plugin = plugin; 14 | list = new ArrayList<>(); 15 | } 16 | 17 | public void add(Hologram hologram) { 18 | list.add(hologram); 19 | } 20 | 21 | public void onShutDown() { 22 | for (Hologram hologram : list) { 23 | hologram.kill(); 24 | } 25 | list = new ArrayList<>(); 26 | } 27 | 28 | public void remove(Hologram hologram) { 29 | remove(hologram, true); 30 | } 31 | 32 | public void remove(Hologram hologram, boolean kill) { 33 | if (kill) { 34 | hologram.kill(); 35 | } 36 | list.remove(hologram); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/GUISession.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.inventory.Inventory; 5 | import org.bukkit.inventory.InventoryHolder; 6 | import org.bukkit.inventory.InventoryView; 7 | 8 | import com.bencodez.simpleapi.player.PlayerUtils; 9 | 10 | public class GUISession implements InventoryHolder { 11 | /** 12 | * Get the GUISession for a given inventory, or null if none exists for this 13 | * inventory 14 | * 15 | * @param inventory The inventory to get the GUISession from 16 | * @return The GUISession or null if none exists 17 | */ 18 | public static GUISession extractSession(Inventory inventory) { 19 | if (inventory == null) { 20 | return null; 21 | } 22 | InventoryHolder ih = inventory.getHolder(); 23 | if (ih != null && ih instanceof GUISession) { 24 | return (GUISession) ih; 25 | } 26 | return null; 27 | } 28 | 29 | /** 30 | * Extract the GUISession from the inventory currently being viewed by a player, 31 | * or null if none exists 32 | * 33 | * @param player The player who's open inventory to extract the GUISession from 34 | * @return The GUISession or null if none exists 35 | */ 36 | public static GUISession extractSession(Player player) { 37 | if (player == null) { 38 | return null; 39 | } 40 | InventoryView oInv = player.getOpenInventory(); 41 | if (oInv == null) { 42 | return null; 43 | } 44 | Inventory inv = PlayerUtils.getTopInventory(player); 45 | if (inv != null) { 46 | return extractSession(inv); 47 | } 48 | return extractSession(oInv.getTopInventory()); 49 | 50 | } 51 | 52 | private BInventory inventoryGUI; // GUI Being viewed 53 | private int page = 1; // Currently displayed page number 54 | 55 | /** 56 | * Construct a new GUISession 57 | * 58 | * @param inventoryGUI The inventory that this a session to view 59 | * @param page The page currently being viewed 60 | */ 61 | public GUISession(BInventory inventoryGUI, int page) { 62 | if (inventoryGUI == null) { 63 | throw new IllegalArgumentException("InventoryGUI must not be null"); 64 | } 65 | 66 | this.inventoryGUI = inventoryGUI; 67 | this.page = page; 68 | } 69 | 70 | /** 71 | * Method inherited from Bukkit's InventoryHolder. Will always return null 72 | * 73 | * @return Null 74 | */ 75 | @Override 76 | public Inventory getInventory() { // Part of InventoryHolder from bukkit 77 | return null; // doesn't matter at all if null returned 78 | } 79 | 80 | /** 81 | * Get the InventoryGUI being viewed 82 | * 83 | * @return The InventoryGUI being viewed 84 | */ 85 | public BInventory getInventoryGUI() { 86 | return inventoryGUI; 87 | } 88 | 89 | /** 90 | * Get the page currently being viewed 91 | * 92 | * @return The page 93 | */ 94 | public int getPage() { 95 | return page; 96 | } 97 | 98 | /** 99 | * Set the page currently being viewed 100 | * 101 | * @param page The page 102 | */ 103 | public void setPage(int page) { 104 | if (page < 1) { 105 | throw new IllegalArgumentException("Page must be >= 1"); 106 | } 107 | this.page = page; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUI.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | import java.util.HashMap; 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | import com.bencodez.advancedcore.api.inventory.BInventory; 10 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 11 | 12 | public class EditGUI extends BInventory { 13 | 14 | public EditGUI(String name) { 15 | super(name); 16 | } 17 | 18 | public void sort() { 19 | Map map = getButtons(); 20 | setButtons(new HashMap<>()); 21 | LinkedHashMap buttons = new LinkedHashMap<>(); 22 | ArrayList sortedList = new ArrayList<>(); 23 | for (BInventoryButton button : map.values()) { 24 | if (button instanceof EditGUIButton) { 25 | EditGUIButton b = (EditGUIButton) button; 26 | String key = b.getEditor().getKey(); 27 | sortedList.add(key); 28 | b.setSlot(-1); 29 | buttons.put(key, b); 30 | } else { 31 | addButton(button); 32 | } 33 | } 34 | sortedList.sort(Comparator.naturalOrder()); 35 | 36 | for (String key : sortedList) { 37 | addButton(buttons.get(key)); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIButton.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.bukkit.Material; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 11 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 12 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValue; 13 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory; 14 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList; 15 | import com.bencodez.advancedcore.api.item.ItemBuilder; 16 | import com.bencodez.simpleapi.array.ArrayUtils; 17 | 18 | import lombok.Getter; 19 | import lombok.Setter; 20 | 21 | public class EditGUIButton extends BInventoryButton { 22 | 23 | @Getter 24 | @Setter 25 | private EditGUIValue editor; 26 | 27 | public EditGUIButton(EditGUIValue editer) { 28 | super(new ItemBuilder(Material.PAPER)); 29 | this.editor = editer; 30 | } 31 | 32 | public EditGUIButton(ItemBuilder item, EditGUIValue editer) { 33 | super(item); 34 | this.editor = editer; 35 | } 36 | 37 | public EditGUIButton addLore(String lore) { 38 | getEditor().addLore(lore); 39 | return this; 40 | } 41 | 42 | public EditGUIButton addOptions(String... str) { 43 | getEditor().addOptions(str); 44 | return this; 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | @Override 49 | public ItemStack getItem(Player player, HashMap placeholders) { 50 | ItemBuilder builder = getBuilder(); 51 | builder.addPlaceholder(placeholders); 52 | if ((getEditor() instanceof EditGUIValueInventory)) { 53 | if (!builder.hasCustomDisplayName()) { 54 | builder.setName("&cSet " + getEditor().getKey()); 55 | } 56 | builder.setLore("&cClick to open"); 57 | } else if (!(getEditor() instanceof EditGUIValueList)) { 58 | if (!builder.hasCustomDisplayName()) { 59 | builder.setName("&cSet " + getEditor().getType() + " for " + getEditor().getKey()); 60 | } 61 | builder.setLore("&cCurrent value: " + getEditor().getCurrentValue()); 62 | } else { 63 | if (!builder.hasCustomDisplayName()) { 64 | builder.setName("&cEdit list for " + getEditor().getKey()); 65 | } 66 | if (getEditor().getCurrentValue() instanceof ArrayList) { 67 | builder.setLore(ArrayUtils.makeStringList((ArrayList) getEditor().getCurrentValue())); 68 | } else { 69 | builder.setLore("&cCurrent value: null"); 70 | } 71 | } 72 | ArrayList lores = getEditor().getLores(); 73 | if (lores != null) { 74 | for (String t : lores) { 75 | builder.addLoreLine("&3" + t); 76 | } 77 | } 78 | return builder.toItemStack(player); 79 | } 80 | 81 | @Override 82 | public void onClick(ClickEvent clickEvent) { 83 | getEditor().setInv(getInv()); 84 | getEditor().onClick(clickEvent); 85 | } 86 | 87 | public EditGUIButton setName(String name) { 88 | this.getBuilder().setName(name); 89 | return this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIValueType.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui; 2 | 3 | public enum EditGUIValueType { 4 | BOOLEAN, CONFIGURATIONSECTION, DOUBLE, INT, LIST, NUMBER, STRING; 5 | } 6 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValue.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory; 6 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 7 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 8 | import com.bencodez.advancedcore.api.valuerequest.InputMethod; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public abstract class EditGUIValue { 14 | @Getter 15 | @Setter 16 | private boolean canGetValue = true; 17 | 18 | @Getter 19 | @Setter 20 | private Object currentValue; 21 | 22 | @Getter 23 | @Setter 24 | private InputMethod inputMethod; 25 | 26 | @Getter 27 | @Setter 28 | private BInventory inv; 29 | 30 | @Getter 31 | @Setter 32 | private String key; 33 | 34 | @Getter 35 | @Setter 36 | private ArrayList lores; 37 | 38 | @Getter 39 | private ArrayList options = new ArrayList<>(); 40 | 41 | public EditGUIValue addLore(ArrayList lore) { 42 | if (lores == null) { 43 | lores = new ArrayList<>(); 44 | } 45 | lores.addAll(lore); 46 | return this; 47 | } 48 | 49 | public EditGUIValue addLore(String lore) { 50 | if (lores == null) { 51 | lores = new ArrayList<>(); 52 | } 53 | lores.add(lore); 54 | return this; 55 | } 56 | 57 | public EditGUIValue addOptions(String... str) { 58 | for (String s : str) { 59 | options.add(s); 60 | } 61 | return this; 62 | } 63 | 64 | public boolean containsKey(RewardEditData rewardEditData) { 65 | return rewardEditData.hasPath(getKey()); 66 | } 67 | 68 | public abstract String getType(); 69 | 70 | public EditGUIValue inputMethod(InputMethod inputMethod) { 71 | this.inputMethod = inputMethod; 72 | return this; 73 | } 74 | 75 | public abstract void onClick(ClickEvent event); 76 | } 77 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueBoolean.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 6 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder; 7 | import com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener; 8 | import com.bencodez.simpleapi.messages.MessageAPI; 9 | 10 | public abstract class EditGUIValueBoolean extends EditGUIValue { 11 | public EditGUIValueBoolean(String key, Object value) { 12 | setKey(key); 13 | setCurrentValue(value); 14 | } 15 | 16 | @Override 17 | public String getType() { 18 | return "boolean"; 19 | } 20 | 21 | @Override 22 | public void onClick(ClickEvent clickEvent) { 23 | if (getCurrentValue() == null) { 24 | setCurrentValue("false"); 25 | } 26 | new ValueRequestBuilder(new BooleanListener() { 27 | 28 | @Override 29 | public void onInput(Player player, boolean value) { 30 | setValue(player, value); 31 | player.sendMessage(MessageAPI.colorize("&cSetting " + getKey() + " to " + value)); 32 | } 33 | }).currentValue(getCurrentValue().toString()).usingMethod(getInputMethod()).request(clickEvent.getPlayer()); 34 | } 35 | 36 | public abstract void setValue(Player player, boolean value); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueInventory.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 6 | 7 | public abstract class EditGUIValueInventory extends EditGUIValue { 8 | private ArrayList keys = new ArrayList<>(); 9 | 10 | public EditGUIValueInventory(String key) { 11 | setKey(key); 12 | setCanGetValue(false); 13 | keys.add(key); 14 | } 15 | 16 | public EditGUIValueInventory addCheckKey(String key) { 17 | keys.add(key); 18 | return this; 19 | } 20 | 21 | @Override 22 | public String getType() { 23 | return "unkown"; 24 | } 25 | 26 | @Override 27 | public void onClick(ClickEvent clickEvent) { 28 | openInventory(clickEvent); 29 | } 30 | 31 | public abstract void openInventory(ClickEvent clickEvent); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueList.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.Player; 7 | 8 | import com.bencodez.advancedcore.api.inventory.BInventory; 9 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 10 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 11 | import com.bencodez.advancedcore.api.item.ItemBuilder; 12 | import com.bencodez.advancedcore.api.valuerequest.InputMethod; 13 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder; 14 | import com.bencodez.advancedcore.api.valuerequest.listeners.Listener; 15 | import com.bencodez.simpleapi.array.ArrayUtils; 16 | 17 | public abstract class EditGUIValueList extends EditGUIValue { 18 | public EditGUIValueList(String key, Object value) { 19 | setKey(key); 20 | setCurrentValue(value); 21 | } 22 | 23 | @Override 24 | public String getType() { 25 | return "list"; 26 | } 27 | 28 | @Override 29 | public void onClick(ClickEvent clickEvent) { 30 | if (getCurrentValue() == null) { 31 | setCurrentValue(new ArrayList<>()); 32 | } 33 | BInventory inv = new BInventory("Edit list: " + getKey()); 34 | inv.setMeta(clickEvent.getPlayer(), "Value", getCurrentValue()); 35 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&cAdd value")) { 36 | 37 | @Override 38 | public void onClick(ClickEvent clickEvent) { 39 | new ValueRequestBuilder(new Listener() { 40 | @Override 41 | public void onInput(Player player, String add) { 42 | @SuppressWarnings("unchecked") 43 | ArrayList list = (ArrayList) getMeta(player, "Value"); 44 | if (list == null) { 45 | list = new ArrayList<>(); 46 | } 47 | list.add(add); 48 | setValue(player, list); 49 | sendMessage(player, "&cAdded " + add + " to " + getKey()); 50 | } 51 | }, new String[] {}).request(clickEvent.getPlayer()); 52 | } 53 | }); 54 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.BARRIER).setName("&cRemove value")) { 55 | 56 | @SuppressWarnings("unchecked") 57 | @Override 58 | public void onClick(ClickEvent clickEvent) { 59 | ArrayList list = (ArrayList) getMeta(clickEvent.getPlayer(), "Value"); 60 | if (!list.isEmpty()) { 61 | new ValueRequestBuilder(new Listener() { 62 | @Override 63 | public void onInput(Player player, String add) { 64 | ArrayList list = (ArrayList) getMeta(player, "Value"); 65 | list.remove(add); 66 | setValue(player, list); 67 | sendMessage(player, "&cRemoved " + add + " from " + getKey()); 68 | } 69 | }, ArrayUtils.convert((ArrayList) getMeta(clickEvent.getPlayer(), "Value"))) 70 | .usingMethod(InputMethod.INVENTORY).allowCustomOption(false) 71 | .request(clickEvent.getPlayer()); 72 | } else { 73 | clickEvent.getPlayer().sendMessage("No values to remove"); 74 | } 75 | } 76 | }); 77 | inv.openInventory(clickEvent.getPlayer()); 78 | } 79 | 80 | public abstract void setValue(Player player, ArrayList value); 81 | } 82 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueNumber.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 6 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder; 7 | import com.bencodez.advancedcore.api.valuerequest.listeners.Listener; 8 | import com.bencodez.simpleapi.messages.MessageAPI; 9 | 10 | public abstract class EditGUIValueNumber extends EditGUIValue { 11 | 12 | public EditGUIValueNumber(String key, Object value) { 13 | setKey(key); 14 | setCurrentValue(value); 15 | } 16 | 17 | @Override 18 | public String getType() { 19 | return "number"; 20 | } 21 | 22 | @Override 23 | public void onClick(ClickEvent clickEvent) { 24 | if (getCurrentValue() == null) { 25 | setCurrentValue(0); 26 | } 27 | new ValueRequestBuilder(new Listener() { 28 | 29 | @Override 30 | public void onInput(Player player, Number number) { 31 | setValue(player, number); 32 | player.sendMessage(MessageAPI.colorize("&cSetting " + getKey() + " to " + number.doubleValue())); 33 | } 34 | }, new Number[] { 0, 10, 25, 50, 100, 500, 1000, (Number) getCurrentValue() }) 35 | .currentValue(getCurrentValue().toString()).allowCustomOption(true).usingMethod(getInputMethod()) 36 | .request(clickEvent.getPlayer()); 37 | } 38 | 39 | public abstract void setValue(Player player, Number num); 40 | } 41 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.inventory.editgui.valuetypes; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 6 | import com.bencodez.advancedcore.api.valuerequest.ValueRequestBuilder; 7 | import com.bencodez.advancedcore.api.valuerequest.listeners.Listener; 8 | import com.bencodez.simpleapi.array.ArrayUtils; 9 | import com.bencodez.simpleapi.messages.MessageAPI; 10 | 11 | public abstract class EditGUIValueString extends EditGUIValue { 12 | 13 | public EditGUIValueString(String key, Object value) { 14 | setKey(key); 15 | setCurrentValue(value); 16 | } 17 | 18 | @Override 19 | public String getType() { 20 | return "string"; 21 | } 22 | 23 | @Override 24 | public void onClick(ClickEvent clickEvent) { 25 | if (getCurrentValue() == null) { 26 | setCurrentValue(""); 27 | } 28 | new ValueRequestBuilder(new Listener() { 29 | @Override 30 | public void onInput(Player player, String value) { 31 | setValue(player, value); 32 | player.sendMessage(MessageAPI.colorize("&cSetting " + getKey() + " to " + value)); 33 | } 34 | }, ArrayUtils.convert(getOptions())).currentValue(getCurrentValue().toString()).allowCustomOption(true) 35 | .usingMethod(getInputMethod()).request(clickEvent.getPlayer()); 36 | } 37 | 38 | public abstract void setValue(Player player, String value); 39 | } 40 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemsAdderHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.item; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import dev.lone.itemsadder.api.CustomStack; 6 | 7 | public class ItemsAdderHandle { 8 | public ItemsAdderHandle() { 9 | 10 | } 11 | 12 | public ItemStack getItem(String item) { 13 | CustomStack stack = CustomStack.getInstance(item); 14 | if (stack != null) { 15 | return stack.getItemStack(); 16 | } 17 | // no custom item found with that id 18 | return null; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/NexoItemHandle.java: -------------------------------------------------------------------------------- 1 | 2 | package com.bencodez.advancedcore.api.item; 3 | 4 | import java.lang.reflect.Method; 5 | 6 | import org.bukkit.inventory.ItemStack; 7 | 8 | public class NexoItemHandle { 9 | public NexoItemHandle() { 10 | } 11 | 12 | public ItemStack getItem(String item) { 13 | try { 14 | Class nexoItemsClass = Class.forName("com.nexomc.nexo.api.NexoItems"); 15 | Method itemFromIdMethod = nexoItemsClass.getMethod("itemFromId", String.class); 16 | Object itemBuilder = itemFromIdMethod.invoke(null, item); 17 | if (itemBuilder != null) { 18 | Class itemBuilderClass = Class.forName("com.nexomc.nexo.items.ItemBuilder"); 19 | Method buildMethod = itemBuilderClass.getMethod("build"); 20 | Object builtItem = buildMethod.invoke(itemBuilder); 21 | return (ItemStack) builtItem; 22 | } 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | return null; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.javascript; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | 6 | import javax.script.ScriptEngine; 7 | import javax.script.ScriptEngineManager; 8 | 9 | import com.bencodez.simpleapi.nms.ReflectionUtils; 10 | 11 | public class JavascriptEngineHandler { 12 | 13 | private static JavascriptEngineHandler instance = new JavascriptEngineHandler(); 14 | 15 | public static JavascriptEngineHandler getInstance() { 16 | return instance; 17 | } 18 | 19 | private boolean builtIn = false; 20 | 21 | private Class factory; 22 | 23 | private Method methodToUse; 24 | 25 | public JavascriptEngineHandler() { 26 | if (Double.parseDouble(System.getProperty("java.specification.version")) < 15) { 27 | builtIn = true; 28 | } else { 29 | try { 30 | builtIn = false; 31 | factory = ReflectionUtils 32 | .getClassForName("org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory"); 33 | for (Method m : factory.getDeclaredMethods()) { 34 | if (m.getParameterCount() == 0) { 35 | if (m.getName().equals("getScriptEngine")) { 36 | methodToUse = m; 37 | } 38 | } 39 | } 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | } 46 | 47 | public ScriptEngine getJSScriptEngine() { 48 | if (builtIn) { 49 | return new ScriptEngineManager().getEngineByName("js"); 50 | } 51 | if (factory != null) { 52 | try { 53 | return (ScriptEngine) methodToUse.invoke(factory.newInstance(), new Object[] {}); 54 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException 55 | | InstantiationException e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptPlaceholderRequest.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.javascript; 2 | 3 | import org.bukkit.OfflinePlayer; 4 | 5 | public abstract class JavascriptPlaceholderRequest { 6 | 7 | private String str; 8 | 9 | public JavascriptPlaceholderRequest(String str) { 10 | this.str = str; 11 | } 12 | 13 | public abstract Object getObject(OfflinePlayer player); 14 | 15 | /** 16 | * @return the str 17 | */ 18 | public String getStr() { 19 | return str; 20 | } 21 | 22 | /** 23 | * @param str the str to set 24 | */ 25 | public void setStr(String str) { 26 | this.str = str; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/messages/MessageBuilder.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.messages; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.OfflinePlayer; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import com.bencodez.advancedcore.api.javascript.JavascriptEngine; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | import com.bencodez.simpleapi.messages.MessageAPI; 12 | 13 | import lombok.Getter; 14 | import lombok.Setter; 15 | import net.md_5.bungee.api.chat.TextComponent; 16 | 17 | public class MessageBuilder { 18 | @Getter 19 | @Setter 20 | private String text; 21 | 22 | public MessageBuilder(String text) { 23 | this.text = text; 24 | } 25 | 26 | public MessageBuilder colorize() { 27 | setText(MessageAPI.colorize(getText())); 28 | return this; 29 | } 30 | 31 | public MessageBuilder parseText() { 32 | replaceJavascript(); 33 | colorize(); 34 | return this; 35 | } 36 | 37 | public MessageBuilder parseText(HashMap placeholders) { 38 | if (placeholders != null) { 39 | replacePlaceholder(placeholders); 40 | } 41 | replaceJavascript(); 42 | colorize(); 43 | return this; 44 | } 45 | 46 | public MessageBuilder parseText(OfflinePlayer player) { 47 | parseText(player, null); 48 | return this; 49 | } 50 | 51 | public MessageBuilder parseText(OfflinePlayer player, HashMap placeholders) { 52 | if (placeholders != null) { 53 | replacePlaceholder(placeholders); 54 | } 55 | replaceJavascript(player); 56 | colorize(); 57 | return this; 58 | } 59 | 60 | public MessageBuilder parseText(Player player) { 61 | parseText(player, null); 62 | return this; 63 | } 64 | 65 | public MessageBuilder parseText(Player player, HashMap placeholders) { 66 | if (placeholders != null) { 67 | replacePlaceholder(placeholders); 68 | } 69 | replaceJavascript((OfflinePlayer) player); 70 | replacePlaceHolders(player); 71 | colorize(); 72 | return this; 73 | } 74 | 75 | public MessageBuilder replaceJavascript() { 76 | setText(PlaceholderUtils.replaceJavascript(getText())); 77 | return this; 78 | } 79 | 80 | public MessageBuilder replaceJavascript(AdvancedCoreUser user) { 81 | setText(PlaceholderUtils.replaceJavascript(user, getText())); 82 | return this; 83 | } 84 | 85 | public MessageBuilder replaceJavascript(CommandSender sender) { 86 | setText(PlaceholderUtils.replaceJavascript(sender, getText())); 87 | return this; 88 | } 89 | 90 | public MessageBuilder replaceJavascript(JavascriptEngine engine) { 91 | setText(PlaceholderUtils.replaceJavascript(getText(), engine)); 92 | return this; 93 | } 94 | 95 | public MessageBuilder replaceJavascript(OfflinePlayer player) { 96 | setText(PlaceholderUtils.replaceJavascript(player, getText())); 97 | return this; 98 | } 99 | 100 | public MessageBuilder replacePlaceholder(HashMap placeholders) { 101 | setText(PlaceholderUtils.replacePlaceHolder(text, placeholders)); 102 | return this; 103 | } 104 | 105 | public MessageBuilder replacePlaceholder(HashMap placeholders, boolean ignoreCase) { 106 | setText(PlaceholderUtils.replacePlaceHolder(text, placeholders, ignoreCase)); 107 | return this; 108 | } 109 | 110 | public MessageBuilder replacePlaceholder(String toReplace, String replaceWith) { 111 | setText(PlaceholderUtils.replacePlaceHolder(text, toReplace, replaceWith)); 112 | return this; 113 | } 114 | 115 | public MessageBuilder replacePlaceholder(String toReplace, String replaceWith, boolean ignoreCase) { 116 | setText(PlaceholderUtils.replacePlaceHolder(text, toReplace, replaceWith, ignoreCase)); 117 | return this; 118 | } 119 | 120 | /** 121 | * Replace placeholderapi placeholders 122 | * 123 | * @param player the player 124 | * @return the string 125 | */ 126 | public MessageBuilder replacePlaceHolders(Player player) { 127 | setText(PlaceholderUtils.replacePlaceHolders(player, getText())); 128 | return this; 129 | } 130 | 131 | @Override 132 | public String toString() { 133 | return getText(); 134 | } 135 | 136 | public TextComponent toTextComponent() { 137 | return PlaceholderUtils.parseJson(getText()); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/animation/AnimationAPI.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.misc.animation; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.Timer; 6 | import java.util.TimerTask; 7 | 8 | public class AnimationAPI { 9 | public interface Animation { 10 | public void onAnimate(String text); 11 | } 12 | 13 | private static AnimationAPI instance = new AnimationAPI(); 14 | 15 | public static AnimationAPI getInstance() { 16 | return instance; 17 | } 18 | 19 | private AnimationAPI() { 20 | } 21 | 22 | /** 23 | * Run an animation 24 | * 25 | * @param texts Text for animation 26 | * @param timeBetween Time between text updates 27 | * @param animation Method to run to display text 28 | */ 29 | public void runAnimation(ArrayList texts, long timeBetween, final Animation animation) { 30 | Iterator it = texts.iterator(); 31 | new Timer().schedule(new TimerTask() { 32 | 33 | @Override 34 | public void run() { 35 | if (it.hasNext()) { 36 | animation.onAnimate(it.next()); 37 | } else { 38 | cancel(); 39 | } 40 | 41 | } 42 | }, 0, timeBetween); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/ActionBar.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.misc.effects; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.scheduler.BukkitRunnable; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.simpleapi.messages.MessageAPI; 9 | import com.bencodez.simpleapi.nms.NMSManager; 10 | 11 | import net.md_5.bungee.api.ChatMessageType; 12 | import net.md_5.bungee.api.chat.TextComponent; 13 | 14 | /** 15 | * The Class ActionBar. 16 | */ 17 | public class ActionBar { 18 | 19 | /** The duration. */ 20 | private int duration; 21 | 22 | /** The msg. */ 23 | private String msg; 24 | 25 | AdvancedCorePlugin plugin = AdvancedCorePlugin.getInstance(); 26 | 27 | /** 28 | * Instantiates a new action bar. 29 | * 30 | * @param msg the msg 31 | * @param duration the duration 32 | */ 33 | public ActionBar(String msg, int duration) { 34 | setMsg(MessageAPI.colorize(msg)); 35 | setDuration(duration); 36 | } 37 | 38 | /** 39 | * Gets the duration. 40 | * 41 | * @return the duration 42 | */ 43 | public int getDuration() { 44 | return duration; 45 | } 46 | 47 | /** 48 | * Gets the msg. 49 | * 50 | * @return the msg 51 | */ 52 | public String getMsg() { 53 | return msg; 54 | } 55 | 56 | /** 57 | * Send. 58 | * 59 | * @param players the players 60 | */ 61 | public void send(Player... players) { 62 | for (Player player : players) { 63 | sendActionBar(player, getMsg(), getDuration()); 64 | } 65 | } 66 | 67 | /** 68 | * Send action bar. 69 | * 70 | * @param player the player 71 | * @param message the message 72 | */ 73 | @SuppressWarnings("deprecation") 74 | public void sendActionBar(Player player, String message) { 75 | if (!NMSManager.getInstance().isVersion("1.7", "1.8", "1.9", "1.10", "1.11", "1.12")) { 76 | player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); 77 | } 78 | } 79 | 80 | /** 81 | * Send action bar. 82 | * 83 | * @param player the player 84 | * @param message the message 85 | * @param duration the duration 86 | */ 87 | public void sendActionBar(final Player player, final String message, int duration) { 88 | sendActionBar(player, message); 89 | 90 | if (duration >= 0) { 91 | // Sends empty message at the end of the duration. Allows messages 92 | // shorter than 3 seconds, ensures precision. 93 | new BukkitRunnable() { 94 | @Override 95 | public void run() { 96 | sendActionBar(player, ""); 97 | } 98 | }.runTaskLater(plugin, duration + 1); 99 | } 100 | 101 | // Re-sends the messages every 3 seconds so it doesn't go away from the 102 | // player's screen. 103 | for (int i = 30; i < duration; i += 30) { 104 | new BukkitRunnable() { 105 | @Override 106 | public void run() { 107 | sendActionBar(player, message); 108 | } 109 | }.runTaskLater(plugin, i); 110 | } 111 | } 112 | 113 | /** 114 | * Send action bar to all players. 115 | * 116 | * @param message the message 117 | */ 118 | public void sendActionBarToAllPlayers(String message) { 119 | sendActionBarToAllPlayers(message, -1); 120 | } 121 | 122 | /** 123 | * Send action bar to all players. 124 | * 125 | * @param message the message 126 | * @param duration the duration 127 | */ 128 | public void sendActionBarToAllPlayers(String message, int duration) { 129 | for (Player p : Bukkit.getOnlinePlayers()) { 130 | sendActionBar(p, message, duration); 131 | } 132 | } 133 | 134 | /** 135 | * Sets the duration. 136 | * 137 | * @param duration the new duration 138 | */ 139 | public void setDuration(int duration) { 140 | this.duration = duration; 141 | } 142 | 143 | /** 144 | * Sets the msg. 145 | * 146 | * @param msg the new msg 147 | */ 148 | public void setMsg(String msg) { 149 | this.msg = msg; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/BossBar.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.misc.effects; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.boss.BarColor; 8 | import org.bukkit.boss.BarStyle; 9 | import org.bukkit.entity.Player; 10 | 11 | import com.bencodez.advancedcore.AdvancedCorePlugin; 12 | import com.bencodez.simpleapi.messages.MessageAPI; 13 | 14 | import lombok.Getter; 15 | 16 | // TODO: Auto-generated Javadoc 17 | /** 18 | * The Class BossBar. 19 | */ 20 | public class BossBar { 21 | 22 | @Getter 23 | private org.bukkit.boss.BossBar bossBar; 24 | 25 | /** 26 | * Instantiates a new boss bar. 27 | * 28 | * @param msg the msg 29 | * @param barColor the bar color 30 | * @param barStyle the bar style 31 | * @param progress the progress 32 | */ 33 | public BossBar(String msg, String barColor, String barStyle, double progress) { 34 | bossBar = Bukkit.createBossBar(MessageAPI.colorize(msg), BarColor.valueOf(barColor), 35 | BarStyle.valueOf(barStyle)); 36 | bossBar.setProgress(progress); 37 | } 38 | 39 | public void addPlayer(Player player) { 40 | bossBar.addPlayer(player); 41 | } 42 | 43 | public void addPlayer(final Player player, int delay) { 44 | try { 45 | if (player == null) { 46 | return; 47 | } 48 | bossBar.addPlayer(player); 49 | 50 | if (delay > 0) { 51 | AdvancedCorePlugin.getInstance().getBukkitScheduler().runTaskLater(AdvancedCorePlugin.getInstance(), 52 | new Runnable() { 53 | 54 | @Override 55 | public void run() { 56 | if (bossBar != null && player != null) { 57 | bossBar.removePlayer(player); 58 | } 59 | } 60 | }, delay * 50 + 60, TimeUnit.MILLISECONDS); 61 | } 62 | } catch (Exception e) { 63 | AdvancedCorePlugin.getInstance().debug(e); 64 | } 65 | } 66 | 67 | public List getPlayers() { 68 | return bossBar.getPlayers(); 69 | } 70 | 71 | public void hide() { 72 | if (bossBar != null) { 73 | bossBar.setVisible(false); 74 | bossBar.removeAll(); 75 | } 76 | } 77 | 78 | private void hideInDelay(int delay) { 79 | AdvancedCorePlugin.getInstance().getBukkitScheduler().runTaskLater(AdvancedCorePlugin.getInstance(), 80 | new Runnable() { 81 | 82 | @Override 83 | public void run() { 84 | hide(); 85 | } 86 | }, delay * 50, TimeUnit.MILLISECONDS); 87 | } 88 | 89 | public void removePlayer(Player player) { 90 | bossBar.removePlayer(player); 91 | } 92 | 93 | public void send() { 94 | bossBar.setVisible(true); 95 | } 96 | 97 | public void send(int delay) { 98 | bossBar.setVisible(true); 99 | 100 | hideInDelay(delay); 101 | } 102 | 103 | /** 104 | * Send. 105 | * 106 | * @param player the player 107 | * @param delay the delay 108 | */ 109 | public void send(Player player, int delay) { 110 | bossBar.addPlayer(player); 111 | bossBar.setVisible(true); 112 | hideInDelay(delay); 113 | } 114 | 115 | public void setColor(String barColor) { 116 | if (barColor != null) { 117 | bossBar.setColor(BarColor.valueOf(barColor)); 118 | } 119 | } 120 | 121 | public void setProgress(double progress) { 122 | if (progress > 1) { 123 | progress = 1; 124 | } 125 | if (progress < 0) { 126 | progress = 0; 127 | } 128 | bossBar.setProgress(progress); 129 | } 130 | 131 | public void setStyle(String barStyle) { 132 | if (barStyle != null) { 133 | bossBar.setStyle(BarStyle.valueOf(barStyle)); 134 | } 135 | } 136 | 137 | public void setTitle(String title) { 138 | if (title != null) { 139 | bossBar.setTitle(MessageAPI.colorize(title)); 140 | } 141 | 142 | } 143 | 144 | public void setVisible(boolean visible) { 145 | bossBar.setVisible(visible); 146 | } 147 | } -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/files/FilesManager.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.misc.files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.configuration.file.FileConfiguration; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.advancedcore.thread.FileThread; 11 | 12 | import net.md_5.bungee.api.ChatColor; 13 | 14 | // TODO: Auto-generated Javadoc 15 | /** 16 | * The Class FilesManager. 17 | */ 18 | public class FilesManager { 19 | 20 | /** The instance. */ 21 | static FilesManager instance = new FilesManager(); 22 | 23 | /** 24 | * Gets the single instance of FilesManager. 25 | * 26 | * @return single instance of FilesManager 27 | */ 28 | public static FilesManager getInstance() { 29 | return instance; 30 | } 31 | 32 | /** The plugin. */ 33 | AdvancedCorePlugin plugin = AdvancedCorePlugin.getInstance(); 34 | 35 | /** 36 | * Instantiates a new files manager. 37 | */ 38 | private FilesManager() { 39 | } 40 | 41 | /** 42 | * Edits the file. 43 | * 44 | * @param file the file 45 | * @param data the data 46 | */ 47 | public void editFile(File file, FileConfiguration data) { 48 | FileThread.getInstance().run(new Runnable() { 49 | 50 | @Override 51 | public void run() { 52 | try { 53 | data.save(file); 54 | } catch (IOException e) { 55 | Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save " + file.getName()); 56 | } 57 | 58 | } 59 | }); 60 | } 61 | } -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/scoreboards/SimpleScoreboard.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenCodez/AdvancedCore/eaaa15eb779ae7f63884572e8ef8a2a6991124d9/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/scoreboards/SimpleScoreboard.java -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/permissions/LuckPermsHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.permissions; 2 | 3 | import java.util.UUID; 4 | import java.util.concurrent.CompletableFuture; 5 | import java.util.concurrent.ExecutionException; 6 | import java.util.concurrent.TimeUnit; 7 | import java.util.concurrent.TimeoutException; 8 | 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.plugin.RegisteredServiceProvider; 11 | 12 | import com.bencodez.advancedcore.AdvancedCorePlugin; 13 | 14 | import lombok.Getter; 15 | import net.luckperms.api.LuckPerms; 16 | import net.luckperms.api.model.user.User; 17 | 18 | public class LuckPermsHandle { 19 | @Getter 20 | LuckPerms api = null; 21 | 22 | public boolean hasPermission(UUID uuid, String permission) { 23 | User user = api.getUserManager().getUser(uuid); 24 | if (user == null) { 25 | CompletableFuture loadedUser = api.getUserManager().loadUser(uuid); 26 | try { 27 | user = loadedUser.get(10, TimeUnit.SECONDS); 28 | } catch (InterruptedException | ExecutionException | TimeoutException e) { 29 | e.printStackTrace(); 30 | return false; 31 | } 32 | } 33 | return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean(); 34 | } 35 | 36 | public void load(AdvancedCorePlugin plugin) { 37 | RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); 38 | if (provider != null) { 39 | api = provider.getProvider(); 40 | plugin.getLogger().info("Loaded LuckPerms hook!"); 41 | } 42 | } 43 | 44 | public boolean luckpermsApiLoaded() { 45 | return api != null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/permissions/PlayerPermissionHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.permissions; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map.Entry; 5 | import java.util.UUID; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.permissions.PermissionAttachment; 10 | 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | public class PlayerPermissionHandler { 15 | @Getter 16 | private UUID uuid; 17 | @Getter 18 | @Setter 19 | private PermissionAttachment attachment; 20 | 21 | private PermissionHandler handler; 22 | 23 | @Getter 24 | private HashMap timedPermissions; 25 | 26 | private HashMap permsToAdd; 27 | 28 | public PlayerPermissionHandler(UUID uuid, PermissionAttachment attachment, PermissionHandler handler) { 29 | this.uuid = uuid; 30 | this.attachment = attachment; 31 | this.handler = handler; 32 | } 33 | 34 | public PlayerPermissionHandler addExpiration(String perm, long delay) { 35 | if (timedPermissions == null) { 36 | timedPermissions = new HashMap<>(); 37 | } 38 | timedPermissions.put(perm, System.currentTimeMillis() + (delay * 1000)); 39 | getAttachment().setPermission(perm, true); 40 | handler.getTimer().schedule(new Runnable() { 41 | 42 | @Override 43 | public void run() { 44 | removePermission(perm); 45 | } 46 | }, delay, TimeUnit.SECONDS); 47 | handler.getPlugin().debug("Giving temp permission " + perm + " to " + uuid.toString() + " for " + delay); 48 | return this; 49 | } 50 | 51 | public PlayerPermissionHandler addOfflinePerm(String perm, long delay) { 52 | if (permsToAdd == null) { 53 | permsToAdd = new HashMap<>(); 54 | } 55 | permsToAdd.put(perm, delay); 56 | return this; 57 | } 58 | 59 | public PlayerPermissionHandler addPerm(String perm) { 60 | if (getAttachment() != null) { 61 | getAttachment().setPermission(perm, true); 62 | handler.getPlugin().debug("Giving permission " + perm + " to " + uuid.toString()); 63 | } 64 | return this; 65 | } 66 | 67 | public void onLogin(Player player) { 68 | if ((player == null) || (permsToAdd == null)) { 69 | return; 70 | } 71 | for (Entry entry : permsToAdd.entrySet()) { 72 | if (entry.getValue().longValue() > 0) { 73 | addExpiration(entry.getKey(), entry.getValue().longValue() / 1000); 74 | } else { 75 | addPerm(entry.getKey()); 76 | } 77 | } 78 | } 79 | 80 | public void remove() { 81 | getAttachment().remove(); 82 | handler.removePermission(uuid); 83 | } 84 | 85 | public void removePermission(String perm) { 86 | getAttachment().setPermission(perm, false); 87 | getAttachment().getPermissions().remove(perm); 88 | if (timedPermissions != null) { 89 | timedPermissions.remove(perm); 90 | } 91 | handler.getPlugin().debug("Removing permission " + perm + " to " + uuid.toString()); 92 | if (getAttachment().getPermissions().size() == 0) { 93 | remove(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/CalculatingPlaceholder.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.placeholder; 2 | 3 | import java.util.UUID; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import lombok.Getter; 7 | 8 | public abstract class CalculatingPlaceholder extends PlaceHolder { 9 | 10 | @Getter 11 | private ConcurrentHashMap cacheData = new ConcurrentHashMap<>(); 12 | 13 | public CalculatingPlaceholder(String identifier) { 14 | super(identifier); 15 | } 16 | 17 | public CalculatingPlaceholder(String identifier, boolean useStartsWith) { 18 | super(identifier, useStartsWith); 19 | } 20 | 21 | public CalculatingPlaceholder(String identifier, String noValueReturn) { 22 | super(identifier, noValueReturn); 23 | } 24 | 25 | public CalculatingPlaceholder(String identifier, String noValueReturn, boolean useStartsWith) { 26 | super(identifier, noValueReturn, useStartsWith); 27 | } 28 | 29 | @Override 30 | public void clearCachePlayer(UUID javaUUID) { 31 | for (String ident : getCache().keySet()) { 32 | if (getCache().get(ident).containsKey(javaUUID)) { 33 | getCache().get(ident).remove(javaUUID); 34 | } 35 | } 36 | cacheData.remove(javaUUID); 37 | } 38 | 39 | public abstract String placeholderDataRequest(T user, String identifier); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/NonPlayerPlaceHolder.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.placeholder; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | import com.bencodez.simpleapi.messages.MessageAPI; 6 | 7 | import lombok.Getter; 8 | 9 | public abstract class NonPlayerPlaceHolder { 10 | @Getter 11 | private String description; 12 | @Getter 13 | private String identifier; 14 | @Getter 15 | private boolean useStartsWith = false; 16 | 17 | @Getter 18 | private ConcurrentHashMap cache; 19 | 20 | @Getter 21 | private boolean usesCache = false; 22 | 23 | @Getter 24 | private String noValueReturn = "0"; 25 | 26 | public NonPlayerPlaceHolder(String identifier) { 27 | this.identifier = identifier; 28 | } 29 | 30 | public NonPlayerPlaceHolder(String identifier, boolean useStartsWith) { 31 | this.identifier = identifier; 32 | this.useStartsWith = useStartsWith; 33 | } 34 | 35 | public NonPlayerPlaceHolder(String identifier, String noValueReturn) { 36 | this.identifier = identifier; 37 | this.noValueReturn = noValueReturn; 38 | } 39 | 40 | public NonPlayerPlaceHolder(String identifier, String noValueReturn, boolean useStartsWith) { 41 | this.identifier = identifier; 42 | this.useStartsWith = useStartsWith; 43 | this.noValueReturn = noValueReturn; 44 | } 45 | 46 | public boolean hasDescription() { 47 | return description != null; 48 | } 49 | 50 | public boolean isCached(String identifier) { 51 | return cache.containsKey(identifier); 52 | } 53 | 54 | public boolean matches(String identifier) { 55 | if (isUseStartsWith()) { 56 | if (MessageAPI.startsWithIgnoreCase(identifier, getIdentifier())) { 57 | return true; 58 | } 59 | } else { 60 | if (getIdentifier().equalsIgnoreCase(identifier)) { 61 | return true; 62 | } 63 | } 64 | return false; 65 | } 66 | 67 | public abstract String placeholderRequest(String identifier); 68 | 69 | public NonPlayerPlaceHolder setUseCache(boolean usesCache, String identifier) { 70 | this.usesCache = usesCache; 71 | if (cache == null) { 72 | cache = new ConcurrentHashMap<>(); 73 | } 74 | cache.put(identifier, ""); 75 | return this; 76 | } 77 | 78 | public NonPlayerPlaceHolder useStartsWith() { 79 | useStartsWith = true; 80 | return this; 81 | } 82 | 83 | public NonPlayerPlaceHolder withDescription(String desc) { 84 | description = desc; 85 | return this; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/PlaceHolder.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.placeholder; 2 | 3 | import java.util.UUID; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import com.bencodez.simpleapi.messages.MessageAPI; 7 | 8 | import lombok.Getter; 9 | 10 | public abstract class PlaceHolder { 11 | @Getter 12 | private String description; 13 | @Getter 14 | private String identifier; 15 | @Getter 16 | private boolean useStartsWith = false; 17 | 18 | @Getter 19 | private String noValueReturn = "0"; 20 | 21 | @Getter 22 | private ConcurrentHashMap> cache; 23 | 24 | @Getter 25 | private String updateDataKey = ""; 26 | 27 | @Getter 28 | private boolean usesCache = false; 29 | 30 | public PlaceHolder(String identifier) { 31 | this.identifier = identifier; 32 | } 33 | 34 | public PlaceHolder(String identifier, boolean useStartsWith) { 35 | this.identifier = identifier; 36 | this.useStartsWith = useStartsWith; 37 | } 38 | 39 | public PlaceHolder(String identifier, String noValueReturn) { 40 | this.identifier = identifier; 41 | this.noValueReturn = noValueReturn; 42 | } 43 | 44 | public PlaceHolder(String identifier, String noValueReturn, boolean useStartsWith) { 45 | this.identifier = identifier; 46 | this.useStartsWith = useStartsWith; 47 | this.noValueReturn = noValueReturn; 48 | } 49 | 50 | public void clearCachePlayer(UUID javaUUID) { 51 | for (String ident : cache.keySet()) { 52 | if (cache.get(ident).containsKey(javaUUID)) { 53 | cache.get(ident).remove(javaUUID); 54 | } 55 | 56 | } 57 | } 58 | 59 | public boolean hasDescription() { 60 | return description != null; 61 | } 62 | 63 | public boolean isCached(String identifier) { 64 | return cache.containsKey(identifier); 65 | } 66 | 67 | public boolean isCached(String identifier, UUID uuid) { 68 | if (isCached(identifier)) { 69 | if (cache.get(identifier).containsKey(uuid)) { 70 | return true; 71 | } 72 | } 73 | return false; 74 | } 75 | 76 | public boolean matches(String identifier) { 77 | if (isUseStartsWith()) { 78 | if (MessageAPI.startsWithIgnoreCase(identifier, getIdentifier())) { 79 | return true; 80 | } 81 | } else { 82 | if (getIdentifier().equalsIgnoreCase(identifier)) { 83 | return true; 84 | } 85 | } 86 | return false; 87 | } 88 | 89 | public abstract String placeholderRequest(T user, String identifier); 90 | 91 | public PlaceHolder setUseCache(boolean usesCache, String identifier) { 92 | this.usesCache = usesCache; 93 | if (cache == null) { 94 | cache = new ConcurrentHashMap<>(); 95 | } 96 | cache.put(identifier, new ConcurrentHashMap<>()); 97 | return this; 98 | } 99 | 100 | public PlaceHolder updateDataKey(String key) { 101 | this.updateDataKey = key; 102 | return this; 103 | } 104 | 105 | public PlaceHolder useStartsWith() { 106 | useStartsWith = true; 107 | return this; 108 | } 109 | 110 | public PlaceHolder withDescription(String desc) { 111 | description = desc; 112 | return this; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DefinedReward.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | public interface DefinedReward { 6 | public void createSection(String key); 7 | 8 | public ConfigurationSection getFileData(); 9 | 10 | public String getFullPath(); 11 | 12 | public String getPath(); 13 | 14 | public String needsDot(); 15 | 16 | public void save(); 17 | 18 | public void setData(String str, Object value); 19 | } 20 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DirectlyDefinedReward.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | public abstract class DirectlyDefinedReward implements DefinedReward { 9 | @Getter 10 | @Setter 11 | private String path; 12 | 13 | public DirectlyDefinedReward(String path) { 14 | this.path = path; 15 | } 16 | 17 | public abstract void createSection(String key); 18 | 19 | public void createSectionLocal(String key) { 20 | createSection(getPath() + "." + key); 21 | } 22 | 23 | public abstract ConfigurationSection getFileData(); 24 | 25 | public String getFullPath() { 26 | return path; 27 | } 28 | 29 | public Reward getReward() { 30 | if (isDirectlyDefined()) { 31 | return new Reward(getPath().replace(".", "_"), getFileData().getConfigurationSection(getPath())) 32 | .needsRewardFile(false); 33 | } 34 | return null; 35 | } 36 | 37 | public Object getValue(String path) { 38 | return getFileData().get(getPath() + "." + path); 39 | } 40 | 41 | public boolean isDirectlyDefined() { 42 | return getFileData().isConfigurationSection(getPath()); 43 | } 44 | 45 | public String needsDot() { 46 | return "."; 47 | } 48 | 49 | public abstract void save(); 50 | 51 | public abstract void setData(String path, Object value); 52 | 53 | public void setParentValue(Object value) { 54 | setData(getPath(), value); 55 | } 56 | 57 | public void setValue(String path, Object value) { 58 | setData(getPath() + "." + path, value); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/Inject.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 6 | 7 | import lombok.Getter; 8 | import lombok.Setter; 9 | 10 | public class Inject { 11 | @Getter 12 | @Setter 13 | private ArrayList editButtons = new ArrayList<>(); 14 | 15 | @Getter 16 | @Setter 17 | private boolean internalReward = false; 18 | 19 | @Getter 20 | @Setter 21 | private String path; 22 | 23 | @Getter 24 | @Setter 25 | private int priority = 50; 26 | 27 | public Inject(String path) { 28 | this.path = path; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/RepeatHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import java.util.TimerTask; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.configuration.ConfigurationSection; 7 | import org.bukkit.entity.Player; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | 12 | import lombok.Getter; 13 | import lombok.Setter; 14 | 15 | public class RepeatHandle { 16 | @Getter 17 | @Setter 18 | private int amount = -1; 19 | 20 | @Getter 21 | @Setter 22 | private boolean autoStop = false; 23 | @Getter 24 | @Setter 25 | private boolean enabled = false; 26 | private int globalAmount = 0; 27 | @Getter 28 | @Setter 29 | private boolean repeatOnStartup = false; 30 | @Getter 31 | private Reward reward; 32 | @Getter 33 | @Setter 34 | private long timeBetween = 0; 35 | 36 | public RepeatHandle(Reward reward) { 37 | this.reward = reward; 38 | ConfigurationSection data = reward.getConfig().getConfigData().getConfigurationSection("Repeat"); 39 | if (data != null) { 40 | enabled = data.getBoolean("Enabled", false); 41 | timeBetween = data.getLong("TimeBetween", 0); 42 | amount = data.getInt("Amount", -1); 43 | repeatOnStartup = data.getBoolean("RepeatOnStartup", false); 44 | autoStop = data.getBoolean("AutoStop", true); 45 | } 46 | } 47 | 48 | public void giveRepeat(AdvancedCorePlugin plugin, AdvancedCoreUser user) { 49 | if (repeatOnStartup) { 50 | return; 51 | } 52 | plugin.debug("Giving repeat reward in " + timeBetween); 53 | plugin.getRewardHandler().getRepeatTimer().schedule(new TimerTask() { 54 | 55 | @Override 56 | public void run() { 57 | if (amount > 0) { 58 | int cAmount = user.getRepeatAmount(reward); 59 | if (cAmount >= amount) { 60 | user.setRepeatAmount(reward, 0); 61 | cancel(); 62 | return; 63 | } 64 | // add amount 65 | user.setRepeatAmount(reward, cAmount + 1); 66 | if (autoStop) { 67 | if (!reward.canGiveReward(user, new RewardOptions())) { 68 | user.setRepeatAmount(reward, 0); 69 | cancel(); 70 | return; 71 | } else { 72 | giveReward(plugin, user, true); 73 | cancel(); 74 | return; 75 | } 76 | } else { 77 | giveReward(plugin, user, false); 78 | cancel(); 79 | return; 80 | } 81 | 82 | } 83 | if (autoStop) { 84 | if (!reward.canGiveReward(user, new RewardOptions())) { 85 | cancel(); 86 | return; 87 | } else { 88 | giveReward(plugin, user, true); 89 | cancel(); 90 | return; 91 | } 92 | } else { 93 | giveReward(plugin, user, false); 94 | cancel(); 95 | return; 96 | } 97 | } 98 | }, timeBetween); 99 | } 100 | 101 | public void giveRepeatAll(AdvancedCorePlugin plugin) { 102 | plugin.getRewardHandler().getRepeatTimer().schedule(new TimerTask() { 103 | 104 | @Override 105 | public void run() { 106 | if (amount > 0) { 107 | if (globalAmount >= amount) { 108 | cancel(); 109 | return; 110 | } 111 | globalAmount++; 112 | } 113 | for (Player p : Bukkit.getOnlinePlayers()) { 114 | AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(p); 115 | giveReward(plugin, user, false); 116 | cancel(); 117 | return; 118 | } 119 | } 120 | }, timeBetween); 121 | 122 | } 123 | 124 | public void giveReward(AdvancedCorePlugin plugin, AdvancedCoreUser user, boolean bypassRequirement) { 125 | AdvancedCorePlugin.getInstance() 126 | .debug("Giving repeat reward " + reward.getName() + " for " + user.getPlayerName()); 127 | if (bypassRequirement) { 128 | reward.giveReward(user, new RewardOptions().setIgnoreRequirements(false).setIgnoreChance(false) 129 | .setCheckRepeat(false).forceOffline()); 130 | } else { 131 | reward.giveReward(user, new RewardOptions().setCheckRepeat(false).forceOffline()); 132 | } 133 | giveRepeat(plugin, user); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/RewardEditData.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | import org.bukkit.entity.Player; 5 | 6 | import com.bencodez.advancedcore.command.gui.RewardEditGUI; 7 | 8 | import lombok.Getter; 9 | 10 | public class RewardEditData { 11 | private DirectlyDefinedReward directlyDefinedReward; 12 | @Getter 13 | private RewardEditData parent; 14 | 15 | private Reward reward; 16 | 17 | public RewardEditData(DirectlyDefinedReward directlyDefinedReward) { 18 | this.directlyDefinedReward = directlyDefinedReward; 19 | } 20 | 21 | public RewardEditData(DirectlyDefinedReward directlyDefinedReward, RewardEditData parent) { 22 | this.directlyDefinedReward = directlyDefinedReward; 23 | this.parent = parent; 24 | } 25 | 26 | public RewardEditData(Reward reward) { 27 | this.reward = reward; 28 | } 29 | 30 | public void createSection(String path) { 31 | if (reward != null) { 32 | reward.getConfig().createSection(path); 33 | } else if (directlyDefinedReward != null) { 34 | directlyDefinedReward.createSectionLocal(path); 35 | } 36 | } 37 | 38 | public ConfigurationSection getData() { 39 | if (reward != null) { 40 | return reward.getConfig().getConfigData(); 41 | } 42 | if (directlyDefinedReward != null) { 43 | return directlyDefinedReward.getFileData().getConfigurationSection(directlyDefinedReward.getPath()); 44 | } 45 | return null; 46 | } 47 | 48 | public String getName() { 49 | if (reward != null) { 50 | return reward.getName(); 51 | } 52 | return directlyDefinedReward.getPath(); 53 | } 54 | 55 | public Object getValue(String key) { 56 | if (reward != null) { 57 | return reward.getConfig().getConfigData().get(key); 58 | } 59 | if (directlyDefinedReward != null) { 60 | return directlyDefinedReward.getValue(key); 61 | } 62 | return null; 63 | } 64 | 65 | public boolean hasPath(String path) { 66 | if (reward != null) { 67 | return reward.getConfig().getConfigData().contains(path, false); 68 | } 69 | return directlyDefinedReward.getFileData().contains(directlyDefinedReward.getPath() + "." + path, false); 70 | } 71 | 72 | public void reOpenEditGUI(Player player) { 73 | RewardEditGUI.getInstance().openRewardGUI(player, this, getName()); 74 | } 75 | 76 | public void save() { 77 | if (reward != null) { 78 | reward.getConfig().save(reward.getConfig().getFileData()); 79 | } else if (directlyDefinedReward != null) { 80 | directlyDefinedReward.save(); 81 | } 82 | } 83 | 84 | public void setValue(String path, Object value) { 85 | if (reward != null) { 86 | reward.getConfig().set(path, value); 87 | } else if (directlyDefinedReward != null) { 88 | directlyDefinedReward.setValue(path, value); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/RewardFileDefinedReward.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | public class RewardFileDefinedReward implements DefinedReward { 9 | @Getter 10 | @Setter 11 | private String path; 12 | 13 | @Getter 14 | @Setter 15 | private Reward master; 16 | 17 | public RewardFileDefinedReward(Reward master) { 18 | this.master = master; 19 | path = ""; 20 | } 21 | 22 | public RewardFileDefinedReward(Reward master, String path) { 23 | this.master = master; 24 | this.path = path; 25 | } 26 | 27 | public void createSection(String key) { 28 | master.getConfig().createSection(key); 29 | } 30 | 31 | public void createSectionLocal(String key) { 32 | if (getPath().isEmpty()) { 33 | createSection(key); 34 | } else { 35 | createSection(getPath() + "." + key); 36 | } 37 | } 38 | 39 | public ConfigurationSection getFileData() { 40 | return master.getConfig().getConfigData(); 41 | } 42 | 43 | public String getFullPath() { 44 | return master.getName() + "." + path; 45 | } 46 | 47 | public Reward getReward() { 48 | if (getPath().isEmpty()) { 49 | return master; 50 | } 51 | if (isDirectlyDefined()) { 52 | return new Reward((getPath()).replace(".", "_"), getFileData().getConfigurationSection(getPath())) 53 | .needsRewardFile(false); 54 | } 55 | return null; 56 | } 57 | 58 | public Object getValue(String path) { 59 | if (getPath().isEmpty()) { 60 | return getFileData().get(path); 61 | } 62 | return getFileData().get(getPath() + "." + path); 63 | } 64 | 65 | public boolean isDirectlyDefined() { 66 | if (path.isEmpty()) { 67 | return true; 68 | } 69 | return getFileData().isConfigurationSection(getPath()); 70 | } 71 | 72 | @Override 73 | public String needsDot() { 74 | if (getPath().isEmpty()) { 75 | return ""; 76 | } 77 | return "."; 78 | } 79 | 80 | public void save() { 81 | master.getConfig().save(); 82 | } 83 | 84 | public void setData(String path, Object value) { 85 | master.getConfig().set(path, value); 86 | } 87 | 88 | public void setParentValue(Object value) { 89 | setData(getPath(), value); 90 | } 91 | 92 | public void setValue(String path, Object value) { 93 | if (getPath().isEmpty()) { 94 | setData(path, value); 95 | } else { 96 | setData(getPath() + "." + path, value); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/RewardPlaceholderHandle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 4 | 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | public abstract class RewardPlaceholderHandle { 9 | @Getter 10 | @Setter 11 | private String key; 12 | 13 | @Getter 14 | @Setter 15 | private boolean preProcess = false; 16 | 17 | public RewardPlaceholderHandle(String key) { 18 | this.key = key; 19 | } 20 | 21 | public abstract String getValue(Reward reward, AdvancedCoreUser user); 22 | 23 | public RewardPlaceholderHandle preProcess() { 24 | preProcess = true; 25 | return this; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/SubDirectlyDefinedReward.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | public class SubDirectlyDefinedReward implements DefinedReward { 9 | @Getter 10 | @Setter 11 | private String path; 12 | 13 | @Getter 14 | @Setter 15 | private DefinedReward master; 16 | 17 | public SubDirectlyDefinedReward(DefinedReward master, String path) { 18 | this.master = master; 19 | this.path = path; 20 | } 21 | 22 | public void createSection(String key) { 23 | master.createSection(master.getPath() + master.needsDot() + key); 24 | } 25 | 26 | public void createSectionLocal(String key) { 27 | createSection(getPath() + "." + key); 28 | } 29 | 30 | public ConfigurationSection getFileData() { 31 | return master.getFileData().getConfigurationSection(master.getPath()); 32 | } 33 | 34 | public String getFullPath() { 35 | return master.getFullPath() + master.needsDot() + path; 36 | } 37 | 38 | public Reward getReward() { 39 | if (isDirectlyDefined()) { 40 | return new Reward((master.getFullPath() + master.needsDot() + getPath()).replace(".", "_"), 41 | getFileData().getConfigurationSection(getPath())).needsRewardFile(false); 42 | } 43 | return null; 44 | } 45 | 46 | public Object getValue(String path) { 47 | return getFileData().get(getPath() + "." + path); 48 | } 49 | 50 | public boolean isDirectlyDefined() { 51 | return getFileData().isConfigurationSection(getPath()); 52 | } 53 | 54 | @Override 55 | public String needsDot() { 56 | return "."; 57 | } 58 | 59 | public void save() { 60 | master.save(); 61 | } 62 | 63 | public void setData(String path, Object value) { 64 | master.setData(master.getPath() + master.needsDot() + path, value); 65 | } 66 | 67 | public void setParentValue(Object value) { 68 | setData(getPath(), value); 69 | } 70 | 71 | public void setValue(String path, Object value) { 72 | setData(getPath() + "." + path, value); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEdit.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 9 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton; 10 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueBoolean; 11 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory; 12 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueList; 13 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueNumber; 14 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueString; 15 | import com.bencodez.advancedcore.api.item.ItemBuilder; 16 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 17 | import com.bencodez.advancedcore.api.valuerequest.InputMethod; 18 | 19 | public abstract class RewardEdit { 20 | 21 | public EditGUIButton getBackButton(RewardEditData reward) { 22 | EditGUIButton b = new EditGUIButton(new ItemBuilder("BARRIER").setName("&cGo back"), 23 | new EditGUIValueInventory("") { 24 | 25 | @Override 26 | public void openInventory(ClickEvent clickEvent) { 27 | reward.reOpenEditGUI(clickEvent.getPlayer()); 28 | } 29 | }); 30 | b.setSlot(-2); 31 | return b; 32 | } 33 | 34 | public EditGUIButton getBackButtonCustom(RewardEditData reward, EditGUIValueInventory edit) { 35 | EditGUIButton b = new EditGUIButton(new ItemBuilder("BARRIER").setName("&cGo back"), edit); 36 | b.setSlot(-2); 37 | return b; 38 | } 39 | 40 | public EditGUIButton getBooleanButton(String key, RewardEditData reward) { 41 | return new EditGUIButton(new EditGUIValueBoolean(key, reward.getValue(key)) { 42 | 43 | @Override 44 | public void setValue(Player player, boolean value) { 45 | setVal(key, value); 46 | open(player, reward); 47 | } 48 | }); 49 | } 50 | 51 | public EditGUIButton getDoubleButton(String key, RewardEditData reward) { 52 | return new EditGUIButton(new EditGUIValueNumber(key, reward.getValue(key)) { 53 | 54 | @Override 55 | public void setValue(Player player, Number num) { 56 | setVal(key, num.doubleValue()); 57 | open(player, reward); 58 | } 59 | }); 60 | } 61 | 62 | public EditGUIButton getIntButton(String key, RewardEditData reward) { 63 | return new EditGUIButton(new EditGUIValueNumber(key, reward.getValue(key)) { 64 | 65 | @Override 66 | public void setValue(Player player, Number num) { 67 | setVal(key, num.intValue()); 68 | open(player, reward); 69 | } 70 | }); 71 | } 72 | 73 | public EditGUIButton getStringButton(String key, RewardEditData reward) { 74 | return new EditGUIButton(new EditGUIValueString(key, reward.getValue(key)) { 75 | 76 | @Override 77 | public void setValue(Player player, String str) { 78 | setVal(key, str); 79 | open(player, reward); 80 | } 81 | }); 82 | } 83 | 84 | public EditGUIButton getStringButton(String key, RewardEditData reward, String... options) { 85 | return new EditGUIButton(new EditGUIValueString(key, reward.getValue(key)) { 86 | 87 | @Override 88 | public void setValue(Player player, String str) { 89 | setVal(key, str); 90 | open(player, reward); 91 | } 92 | }.addOptions(options).inputMethod(InputMethod.INVENTORY)); 93 | } 94 | 95 | public EditGUIButton getStringListButton(String key, RewardEditData reward) { 96 | return new EditGUIButton(new EditGUIValueList(key, reward.getValue(key)) { 97 | 98 | @Override 99 | public void setValue(Player player, ArrayList value) { 100 | setVal(key, value); 101 | open(player, reward); 102 | } 103 | }); 104 | } 105 | 106 | public abstract void open(Player player, RewardEditData reward); 107 | 108 | public void openSubReward(Player player, String path, RewardEditData reward) { 109 | AdvancedCorePlugin.getInstance().getRewardHandler().openSubReward(player, path, reward); 110 | } 111 | 112 | public void reloadAdvancedCore() { 113 | AdvancedCorePlugin.getInstance().reloadAdvancedCore(false); 114 | } 115 | 116 | public abstract void setVal(String key, Object value); 117 | 118 | } 119 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditActionBar.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditActionBar extends RewardEdit { 9 | public RewardEditActionBar() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit ActionBar: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getStringButton("ActionBar.Message", reward)); 18 | inv.addButton(getIntButton("ActionBar.Delay", reward)); 19 | 20 | inv.addButton(getBackButton(reward)); 21 | 22 | inv.openInventory(player); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditBossBar.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditBossBar extends RewardEdit { 9 | public RewardEditBossBar() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit BossBar: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("BossBar.Enabled", reward)); 18 | inv.addButton(getStringButton("BossBar.Message", reward)); 19 | inv.addButton(getStringButton("BossBar.Color", reward)); 20 | inv.addButton(getStringButton("BossBar.Style", reward)); 21 | inv.addButton(getDoubleButton("BossBar.Progress", reward)); 22 | inv.addButton(getIntButton("BossBar.Delay", reward)); 23 | 24 | inv.addButton(getBackButton(reward)); 25 | 26 | inv.openInventory(player); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditDate.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditDate extends RewardEdit { 9 | public RewardEditDate() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Dzte: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getStringButton("Date.WeekDay", reward).addOptions("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", 18 | "FRIDAY", "SATURDAY", "SUNDAY")); 19 | inv.addButton(getIntButton("Date.DayOfMonth", reward)); 20 | inv.addButton(getStringButton("Date.Month", reward).addOptions("JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", 21 | "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER")); 22 | 23 | inv.addButton(getBackButton(reward)); 24 | 25 | inv.openInventory(player); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditDelayed.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditDelayed extends RewardEdit { 9 | public RewardEditDelayed() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Delayed: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("Delayed.Enabled", reward)); 18 | inv.addButton(getIntButton("Delayed.Hours", reward)); 19 | inv.addButton(getIntButton("Delayed.Minutes", reward)); 20 | inv.addButton(getIntButton("Delayed.Seconds", reward)); 21 | 22 | inv.addButton(getBackButton(reward)); 23 | 24 | inv.openInventory(player); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditEXP.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditEXP extends RewardEdit { 9 | public RewardEditEXP() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit EXP: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getIntButton("EXP", reward)); 18 | 19 | inv.addButton(getIntButton("EXP.Min", reward)); 20 | inv.addButton(getIntButton("EXP.Max", reward)); 21 | 22 | inv.addButton(getBackButton(reward)); 23 | 24 | inv.openInventory(player); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditEXPLevels.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditEXPLevels extends RewardEdit { 9 | public RewardEditEXPLevels() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit EXP: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getIntButton("EXPLevels", reward)); 18 | 19 | inv.addButton(getIntButton("EXPLevels.Min", reward)); 20 | inv.addButton(getIntButton("EXPLevels.Max", reward)); 21 | 22 | inv.addButton(getBackButton(reward)); 23 | 24 | inv.openInventory(player); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditEffect.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditEffect extends RewardEdit { 9 | public RewardEditEffect() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Effect: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("Effect.Enabled", reward)); 18 | inv.addButton(getStringButton("Effect.Effect", reward)); 19 | inv.addButton(getIntButton("Effect.Data", reward)); 20 | inv.addButton(getIntButton("Effect.Particles", reward)); 21 | inv.addButton(getIntButton("Effect.Radius", reward)); 22 | 23 | inv.addButton(getBackButton(reward)); 24 | 25 | inv.openInventory(player); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditFirework.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditFirework extends RewardEdit { 9 | public RewardEditFirework() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Firework: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("Firework.Enabled", reward)); 18 | inv.addButton(getStringListButton("Firework.Colors", reward)); 19 | inv.addButton(getStringListButton("Firework.FadeOutColor", reward)); 20 | inv.addButton(getBooleanButton("Firework.Trail", reward)); 21 | inv.addButton(getBooleanButton("Firework.Flicker", reward)); 22 | inv.addButton(getStringListButton("Firework.Types", reward)); 23 | 24 | inv.addButton(getBackButton(reward)); 25 | 26 | inv.openInventory(player); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditJavascript.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 6 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 7 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton; 8 | import com.bencodez.advancedcore.api.inventory.editgui.valuetypes.EditGUIValueInventory; 9 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 10 | 11 | public abstract class RewardEditJavascript extends RewardEdit { 12 | public RewardEditJavascript() { 13 | } 14 | 15 | @Override 16 | public void open(Player player, RewardEditData reward) { 17 | EditGUI inv = new EditGUI("Edit Javascript: " + reward.getName()); 18 | inv.addData("Reward", reward); 19 | 20 | inv.addButton(getBooleanButton("Javascript.Enabled", reward)); 21 | inv.addButton(getStringButton("Javascript.Expression", reward)); 22 | 23 | inv.addButton(new EditGUIButton(new EditGUIValueInventory("Javascript.TrueRewards") { 24 | 25 | @Override 26 | public void openInventory(ClickEvent clickEvent) { 27 | RewardEditData reward = (RewardEditData) getInv().getData("Reward"); 28 | if (reward.hasPath("AdvancedRandomReward")) { 29 | openSubReward(player, "Javascript.TrueRewards", reward); 30 | } 31 | } 32 | }).setName("&aEdit true rewards")); 33 | 34 | inv.addButton(new EditGUIButton(new EditGUIValueInventory("Javascript.FalseRewards") { 35 | 36 | @Override 37 | public void openInventory(ClickEvent clickEvent) { 38 | RewardEditData reward = (RewardEditData) getInv().getData("Reward"); 39 | if (reward.hasPath("AdvancedRandomReward")) { 40 | openSubReward(player, "Javascript.FalseRewards", reward); 41 | } 42 | } 43 | }).setName("&aEdit false rewards")); 44 | 45 | inv.addButton(getBackButton(reward)); 46 | 47 | inv.openInventory(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditLocationDistance.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditLocationDistance extends RewardEdit { 9 | public RewardEditLocationDistance() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit LocationDistance: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getStringButton("LocationDistance.World", reward)); 18 | inv.addButton(getIntButton("LocationDistance.X", reward)); 19 | inv.addButton(getIntButton("LocationDistance.Y", reward)); 20 | inv.addButton(getIntButton("LocationDistance.Z", reward)); 21 | inv.addButton(getIntButton("LocationDistance.Distance", reward)); 22 | 23 | inv.addButton(getBackButton(reward)); 24 | 25 | inv.openInventory(player); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditMessages.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditMessages extends RewardEdit { 9 | public RewardEditMessages() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Messages: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | // message 18 | inv.addButton(getStringButton("Message", reward).addLore("Single line player message")); 19 | inv.addButton(getStringListButton("Message", reward).addLore("List of player messages")); 20 | 21 | // messages.player 22 | inv.addButton(getStringButton("Messages.Player", reward).addLore("Single line player message")); 23 | inv.addButton(getStringListButton("Messages.Player", reward).addLore("List of player messages")); 24 | 25 | // messages.broadcast 26 | inv.addButton(getStringButton("Messages.Broadcast", reward).addLore("Single line broadcast")); 27 | inv.addButton(getStringListButton("Messages.Broadcast", reward).addLore("List of broadcast messages")); 28 | 29 | inv.addButton(getBackButton(reward)); 30 | 31 | inv.openInventory(player); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditMoney.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditMoney extends RewardEdit { 9 | public RewardEditMoney() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Money: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getIntButton("Money", reward)); 18 | 19 | inv.addButton(getIntButton("Money.Min", reward)); 20 | inv.addButton(getIntButton("Money.Max", reward)); 21 | 22 | inv.addButton(getBackButton(reward)); 23 | 24 | inv.openInventory(player); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditSound.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.Registry; 6 | import org.bukkit.entity.Player; 7 | 8 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 9 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 10 | import com.bencodez.simpleapi.array.ArrayUtils; 11 | 12 | public abstract class RewardEditSound extends RewardEdit { 13 | public RewardEditSound() { 14 | } 15 | 16 | @Override 17 | public void open(Player player, RewardEditData reward) { 18 | EditGUI inv = new EditGUI("Edit Sound: " + reward.getName()); 19 | inv.addData("Reward", reward); 20 | 21 | inv.addButton(getBooleanButton("Sound.Enabled", reward)); 22 | 23 | ArrayList sounds = new ArrayList<>(); 24 | Registry.SOUNDS.forEach(sound -> sounds.add(sound.toString())); 25 | 26 | inv.addButton(getStringButton("Sound.Sound", reward, ArrayUtils.convert(sounds))); 27 | inv.addButton(getDoubleButton("Sound.Volume", reward)); 28 | inv.addButton(getDoubleButton("Sound.Pitch", reward)); 29 | 30 | inv.addButton(getBackButton(reward)); 31 | 32 | inv.openInventory(player); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditTempPermission.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditTempPermission extends RewardEdit { 9 | public RewardEditTempPermission() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit TempPermission: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getStringButton("TempPermission.Permission", reward)); 18 | inv.addButton(getIntButton("TempPermission.Expiration", reward)); 19 | 20 | inv.addButton(getBackButton(reward)); 21 | 22 | inv.openInventory(player); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditTimed.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditTimed extends RewardEdit { 9 | public RewardEditTimed() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Timed: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("Timed.Enabled", reward)); 18 | inv.addButton(getIntButton("Timed.Hour", reward)); 19 | inv.addButton(getIntButton("Timed.Minute", reward)); 20 | 21 | inv.addButton(getBackButton(reward)); 22 | 23 | inv.openInventory(player); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/editbuttons/RewardEditTitle.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.editbuttons; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUI; 6 | import com.bencodez.advancedcore.api.rewards.RewardEditData; 7 | 8 | public abstract class RewardEditTitle extends RewardEdit { 9 | public RewardEditTitle() { 10 | } 11 | 12 | @Override 13 | public void open(Player player, RewardEditData reward) { 14 | EditGUI inv = new EditGUI("Edit Title: " + reward.getName()); 15 | inv.addData("Reward", reward); 16 | 17 | inv.addButton(getBooleanButton("Title.Enabled", reward)); 18 | inv.addButton(getStringButton("Title.Title", reward)); 19 | inv.addButton(getStringButton("Title.SubTitle", reward)); 20 | inv.addButton(getIntButton("Title.FadeIn", reward)); 21 | inv.addButton(getIntButton("Title.ShowTime", reward)); 22 | inv.addButton(getIntButton("Title.FadeOut", reward)); 23 | 24 | inv.addButton(getBackButton(reward)); 25 | 26 | inv.openInventory(player); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInject.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.bukkit.configuration.ConfigurationSection; 7 | 8 | import com.bencodez.advancedcore.AdvancedCorePlugin; 9 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton; 10 | import com.bencodez.advancedcore.api.rewards.DefinedReward; 11 | import com.bencodez.advancedcore.api.rewards.Inject; 12 | import com.bencodez.advancedcore.api.rewards.Reward; 13 | import com.bencodez.advancedcore.api.rewards.SubDirectlyDefinedReward; 14 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 15 | 16 | import lombok.Getter; 17 | import lombok.Setter; 18 | 19 | public abstract class RewardInject extends Inject { 20 | 21 | @Getter 22 | private boolean addAsPlaceholder = false; 23 | 24 | @Getter 25 | private boolean alwaysForce = false; 26 | 27 | @Getter 28 | private boolean alwaysForceNoData = false; 29 | 30 | @Getter 31 | private Object object; 32 | 33 | @Getter 34 | private String placeholderName; 35 | 36 | @Getter 37 | private boolean postReward = false; 38 | 39 | @Getter 40 | @Setter 41 | private boolean synchronize = false; 42 | 43 | @Getter 44 | private boolean alwaysValid = false; 45 | 46 | @Getter 47 | private RewardInjectValidator validate; 48 | 49 | public RewardInject(String path) { 50 | super(path); 51 | } 52 | 53 | public RewardInject addEditButton(EditGUIButton button) { 54 | getEditButtons().add(button); 55 | return this; 56 | } 57 | 58 | public RewardInject alwaysForce() { 59 | this.alwaysForce = true; 60 | return this; 61 | } 62 | 63 | public RewardInject alwaysForceNoData() { 64 | this.alwaysForce = true; 65 | this.alwaysForceNoData = true; 66 | return this; 67 | } 68 | 69 | public RewardInject alwaysValid() { 70 | alwaysValid = true; 71 | return this; 72 | } 73 | 74 | public RewardInject asPlaceholder(String placeholderName) { 75 | addAsPlaceholder = true; 76 | this.placeholderName = placeholderName; 77 | return this; 78 | } 79 | 80 | public void debug(String str) { 81 | AdvancedCorePlugin.getInstance().debug(str); 82 | } 83 | 84 | public void extraDebug(String str) { 85 | AdvancedCorePlugin.getInstance().extraDebug(str); 86 | } 87 | 88 | public boolean hasValidator() { 89 | return getValidate() != null; 90 | } 91 | 92 | public boolean isEditable() { 93 | return !getEditButtons().isEmpty(); 94 | } 95 | 96 | public abstract Object onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 97 | HashMap placeholders); 98 | 99 | public RewardInject postReward() { 100 | postReward = true; 101 | return this; 102 | } 103 | 104 | public RewardInject priority(int priority) { 105 | setPriority(priority); 106 | return this; 107 | } 108 | 109 | public ArrayList subRewards(DefinedReward direct) { 110 | return new ArrayList<>(); 111 | } 112 | 113 | public RewardInject synchronize() { 114 | synchronize = true; 115 | object = new Object(); 116 | return this; 117 | } 118 | 119 | public void validate(Reward reward, ConfigurationSection data) { 120 | if (validate != null && data.contains(getPath())) { 121 | validate.onValidate(reward, this, data); 122 | } 123 | } 124 | 125 | public RewardInject validator(RewardInjectValidator validate) { 126 | this.validate = validate; 127 | return this; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectBoolean.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 10 | 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | public abstract class RewardInjectBoolean extends RewardInject { 15 | 16 | @Getter 17 | @Setter 18 | private boolean defaultValue = false; 19 | 20 | public RewardInjectBoolean(String path) { 21 | super(path); 22 | } 23 | 24 | public RewardInjectBoolean(String path, boolean defaultValue) { 25 | super(path); 26 | this.defaultValue = defaultValue; 27 | } 28 | 29 | public abstract String onRewardRequest(Reward reward, AdvancedCoreUser user, boolean num, 30 | HashMap placeholders); 31 | 32 | @Override 33 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 34 | HashMap placeholders) { 35 | if (data.isBoolean(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 36 | boolean value = data.getBoolean(getPath(), isDefaultValue()); 37 | AdvancedCorePlugin.getInstance() 38 | .extraDebug(reward.getRewardName() + ": Giving " + getPath() + ", value: " + value); 39 | String re = onRewardRequest(reward, user, value, placeholders); 40 | if (re == null) { 41 | return "" + value; 42 | } 43 | return re; 44 | } 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectConfigurationSection.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 10 | 11 | public abstract class RewardInjectConfigurationSection extends RewardInject { 12 | 13 | public RewardInjectConfigurationSection(String path) { 14 | super(path); 15 | } 16 | 17 | @Override 18 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 19 | HashMap placeholders) { 20 | if (data.isConfigurationSection(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 21 | || isAlwaysForceNoData()) { 22 | AdvancedCorePlugin.getInstance().extraDebug(reward.getRewardName() + ": Giving " + getPath()); 23 | return onRewardRequested(reward, user, data.getConfigurationSection(getPath()), placeholders); 24 | } 25 | return null; 26 | } 27 | 28 | public abstract String onRewardRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, 29 | HashMap placeholders); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectDouble.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 10 | 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | public abstract class RewardInjectDouble extends RewardInject { 15 | 16 | @Getter 17 | @Setter 18 | private double defaultValue = 0; 19 | 20 | public RewardInjectDouble(String path) { 21 | super(path); 22 | } 23 | 24 | public RewardInjectDouble(String path, double defaultValue) { 25 | super(path); 26 | this.defaultValue = defaultValue; 27 | } 28 | 29 | @Override 30 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 31 | HashMap placeholders) { 32 | if (data.isDouble(getPath()) || data.isInt(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 33 | || isAlwaysForceNoData()) { 34 | double value = data.getDouble(getPath(), getDefaultValue()); 35 | AdvancedCorePlugin.getInstance() 36 | .extraDebug(reward.getRewardName() + ": Giving " + getPath() + ", value: " + value); 37 | String d = onRewardRequest(reward, user, value, placeholders); 38 | if (d == null) { 39 | return "" + value; 40 | } 41 | return d; 42 | } 43 | return null; 44 | } 45 | 46 | public abstract String onRewardRequest(Reward reward, AdvancedCoreUser user, double num, 47 | HashMap placeholders); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectInt.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 10 | 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | public abstract class RewardInjectInt extends RewardInject { 15 | 16 | @Getter 17 | @Setter 18 | private int defaultValue = 0; 19 | 20 | public RewardInjectInt(String path) { 21 | super(path); 22 | } 23 | 24 | public RewardInjectInt(String path, int defaultValue) { 25 | super(path); 26 | this.defaultValue = defaultValue; 27 | } 28 | 29 | @Override 30 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 31 | HashMap placeholders) { 32 | if (data.isInt(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 33 | int value = data.getInt(getPath(), getDefaultValue()); 34 | AdvancedCorePlugin.getInstance() 35 | .extraDebug(reward.getRewardName() + ": Giving " + getPath() + ", value: " + value); 36 | String re = onRewardRequest(reward, user, value, placeholders); 37 | if (re == null) { 38 | return "" + value; 39 | } 40 | return re; 41 | } 42 | return null; 43 | } 44 | 45 | public abstract String onRewardRequest(Reward reward, AdvancedCoreUser user, int num, 46 | HashMap placeholders); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectKeys.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | import java.util.Set; 5 | 6 | import org.bukkit.configuration.ConfigurationSection; 7 | 8 | import com.bencodez.advancedcore.AdvancedCorePlugin; 9 | import com.bencodez.advancedcore.api.rewards.Reward; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | 12 | public abstract class RewardInjectKeys extends RewardInject { 13 | 14 | public RewardInjectKeys(String path) { 15 | super(path); 16 | } 17 | 18 | @Override 19 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 20 | HashMap placeholders) { 21 | if (data.isConfigurationSection(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 22 | || isAlwaysForceNoData()) { 23 | Set value = data.getConfigurationSection(getPath()).getKeys(false); 24 | AdvancedCorePlugin.getInstance().extraDebug(reward.getRewardName() + ": Giving " + getPath()); 25 | return onRewardRequested(reward, user, value, data.getConfigurationSection(getPath()), placeholders); 26 | } 27 | return null; 28 | } 29 | 30 | public abstract String onRewardRequested(Reward reward, AdvancedCoreUser user, Set section, 31 | ConfigurationSection data, HashMap placeholders); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 10 | 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | public abstract class RewardInjectString extends RewardInject { 15 | 16 | @Getter 17 | @Setter 18 | private String defaultValue; 19 | 20 | public RewardInjectString(String path) { 21 | super(path); 22 | } 23 | 24 | public RewardInjectString(String path, String defaultValue) { 25 | super(path); 26 | this.defaultValue = defaultValue; 27 | } 28 | 29 | @Override 30 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 31 | HashMap placeholders) { 32 | if ((data.isString(getPath()) && !data.getString(getPath(), "").isEmpty()) 33 | || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 34 | String value = data.getString(getPath(), getDefaultValue()); 35 | AdvancedCorePlugin.getInstance() 36 | .extraDebug(reward.getRewardName() + ": Giving " + getPath() + ", value: " + value); 37 | String re = onRewardRequest(reward, user, value, placeholders); 38 | if (re == null) { 39 | return value; 40 | } 41 | return re; 42 | } 43 | return null; 44 | } 45 | 46 | public abstract String onRewardRequest(Reward reward, AdvancedCoreUser user, String value, 47 | HashMap placeholders); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectStringList.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.bukkit.configuration.ConfigurationSection; 7 | 8 | import com.bencodez.advancedcore.AdvancedCorePlugin; 9 | import com.bencodez.advancedcore.api.rewards.Reward; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | import com.bencodez.simpleapi.array.ArrayUtils; 12 | 13 | import lombok.Getter; 14 | import lombok.Setter; 15 | 16 | public abstract class RewardInjectStringList extends RewardInject { 17 | 18 | @Getter 19 | @Setter 20 | private ArrayList defaultValue = new ArrayList<>(); 21 | 22 | public RewardInjectStringList(String path) { 23 | super(path); 24 | } 25 | 26 | public RewardInjectStringList(String path, ArrayList defaultValue) { 27 | super(path); 28 | this.defaultValue = defaultValue; 29 | } 30 | 31 | public abstract String onRewardRequest(Reward reward, AdvancedCoreUser user, ArrayList num, 32 | HashMap placeholders); 33 | 34 | @SuppressWarnings("unchecked") 35 | @Override 36 | public String onRewardRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 37 | HashMap placeholders) { 38 | if (data.isList(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 39 | ArrayList value = (ArrayList) data.getList(getPath(), getDefaultValue()); 40 | AdvancedCorePlugin.getInstance().extraDebug( 41 | reward.getRewardName() + ": Giving " + getPath() + ", value: " + ArrayUtils.makeStringList(value)); 42 | return onRewardRequest(reward, user, value, placeholders); 43 | 44 | } 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injected/RewardInjectValidator.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injected; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | 10 | import lombok.Getter; 11 | 12 | public abstract class RewardInjectValidator { 13 | @Getter 14 | private ArrayList paths = new ArrayList<>(); 15 | 16 | public RewardInjectValidator addPath(String path) { 17 | paths.add(path); 18 | return this; 19 | } 20 | 21 | public boolean isValid(RewardInject inject, String path) { 22 | return inject.getPath().startsWith(path) || paths.contains(path); 23 | } 24 | 25 | public abstract void onValidate(Reward reward, RewardInject inject, ConfigurationSection data); 26 | 27 | public void warning(Reward reward, RewardInject inject, String str) { 28 | AdvancedCorePlugin.getInstance().getLogger() 29 | .warning("RewardInject Validator: " + reward.getName() + ", Directly Defined: " 30 | + reward.getConfig().isDirectlyDefinedReward() + " Path: " + inject.getPath() + " : " + str); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInject.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.inventory.editgui.EditGUIButton; 7 | import com.bencodez.advancedcore.api.rewards.Inject; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | 12 | import lombok.Getter; 13 | 14 | public abstract class RequirementInject extends Inject { 15 | 16 | @Getter 17 | private boolean allowReattempt = false; 18 | 19 | @Getter 20 | private boolean alwaysForce = false; 21 | 22 | @Getter 23 | private boolean alwaysForceNoData = false; 24 | 25 | @Getter 26 | private RequirementInjectValidator validate; 27 | 28 | public RequirementInject(String path) { 29 | super(path); 30 | } 31 | 32 | public RequirementInject addEditButton(EditGUIButton button) { 33 | getEditButtons().add(button); 34 | return this; 35 | } 36 | 37 | public RequirementInject allowReattempt() { 38 | this.allowReattempt = true; 39 | return this; 40 | } 41 | 42 | public RequirementInject alwaysForce() { 43 | this.alwaysForce = true; 44 | return this; 45 | } 46 | 47 | public RequirementInject alwaysForceNoData() { 48 | this.alwaysForce = true; 49 | this.alwaysForceNoData = true; 50 | return this; 51 | } 52 | 53 | public void debug(String str) { 54 | AdvancedCorePlugin.getInstance().debug(str); 55 | } 56 | 57 | public void extraDebug(String str) { 58 | AdvancedCorePlugin.getInstance().extraDebug(str); 59 | } 60 | 61 | public boolean hasValidator() { 62 | return getValidate() != null; 63 | } 64 | 65 | public boolean isEditable() { 66 | return !getEditButtons().isEmpty(); 67 | } 68 | 69 | public abstract boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 70 | RewardOptions rewardOptions); 71 | 72 | public RequirementInject priority(int priority) { 73 | setPriority(priority); 74 | return this; 75 | } 76 | 77 | public void validate(Reward reward, ConfigurationSection data) { 78 | if (validate != null && data.contains(getPath())) { 79 | validate.onValidate(reward, this, data); 80 | } 81 | } 82 | 83 | public RequirementInject validator(RequirementInjectValidator validate) { 84 | this.validate = validate; 85 | return this; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectBoolean.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public abstract class RequirementInjectBoolean extends RequirementInject { 14 | 15 | @Getter 16 | @Setter 17 | private boolean defaultValue = false; 18 | 19 | public RequirementInjectBoolean(String path) { 20 | super(path); 21 | } 22 | 23 | public RequirementInjectBoolean(String path, boolean defaultValue) { 24 | super(path); 25 | this.defaultValue = defaultValue; 26 | } 27 | 28 | @Override 29 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 30 | RewardOptions rewardOptions) { 31 | if (data.isBoolean(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 32 | boolean value = data.getBoolean(getPath(), isDefaultValue()); 33 | AdvancedCorePlugin.getInstance() 34 | .extraDebug(reward.getRewardName() + ": Checking " + getPath() + ", value: " + value); 35 | return onRequirementsRequest(reward, user, value, rewardOptions); 36 | 37 | } 38 | return true; 39 | } 40 | 41 | public abstract boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, boolean num, 42 | RewardOptions rewardOptions); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectConfigurationSection.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | public abstract class RequirementInjectConfigurationSection extends RequirementInject { 11 | 12 | public RequirementInjectConfigurationSection(String path) { 13 | super(path); 14 | } 15 | 16 | @Override 17 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 18 | RewardOptions rewardOptions) { 19 | if (data.isConfigurationSection(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 20 | || isAlwaysForceNoData()) { 21 | AdvancedCorePlugin.getInstance().extraDebug(reward.getRewardName() + ": Checking " + getPath()); 22 | return onRequirementsRequested(reward, user, data.getConfigurationSection(getPath()), rewardOptions); 23 | } 24 | return true; 25 | } 26 | 27 | public abstract boolean onRequirementsRequested(Reward reward, AdvancedCoreUser user, ConfigurationSection section, 28 | RewardOptions rewardOptions); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectDouble.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public abstract class RequirementInjectDouble extends RequirementInject { 14 | 15 | @Getter 16 | @Setter 17 | private double defaultValue = 0; 18 | 19 | public RequirementInjectDouble(String path) { 20 | super(path); 21 | } 22 | 23 | public RequirementInjectDouble(String path, double defaultValue) { 24 | super(path); 25 | this.defaultValue = defaultValue; 26 | } 27 | 28 | @Override 29 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 30 | RewardOptions rewardOptions) { 31 | if (data.isDouble(getPath()) || data.isInt(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 32 | || isAlwaysForceNoData()) { 33 | double value = data.getDouble(getPath(), getDefaultValue()); 34 | AdvancedCorePlugin.getInstance() 35 | .extraDebug(reward.getRewardName() + ": Checking " + getPath() + ", value: " + value); 36 | return onRequirementsRequest(reward, user, value, rewardOptions); 37 | } 38 | return true; 39 | } 40 | 41 | public abstract boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, double num, 42 | RewardOptions rewardOptions); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectInt.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public abstract class RequirementInjectInt extends RequirementInject { 14 | 15 | @Getter 16 | @Setter 17 | private int defaultValue = 0; 18 | 19 | public RequirementInjectInt(String path) { 20 | super(path); 21 | } 22 | 23 | public RequirementInjectInt(String path, int defaultValue) { 24 | super(path); 25 | this.defaultValue = defaultValue; 26 | } 27 | 28 | @Override 29 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 30 | RewardOptions rewardOptions) { 31 | if (data.isInt(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 32 | int value = data.getInt(getPath(), getDefaultValue()); 33 | AdvancedCorePlugin.getInstance() 34 | .extraDebug(reward.getRewardName() + ": Checking " + getPath() + ", value: " + value); 35 | return onRequirementsRequest(reward, user, value, rewardOptions); 36 | } 37 | return true; 38 | } 39 | 40 | public abstract boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, int num, 41 | RewardOptions rewardOptions); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectKeys.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import java.util.Set; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | 12 | public abstract class RequirementInjectKeys extends RequirementInject { 13 | 14 | public RequirementInjectKeys(String path) { 15 | super(path); 16 | } 17 | 18 | @Override 19 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 20 | RewardOptions rewardOptions) { 21 | if (data.isConfigurationSection(getPath()) || (isAlwaysForce() && data.contains(getPath(), true)) 22 | || isAlwaysForceNoData()) { 23 | Set value = data.getConfigurationSection(getPath()).getKeys(false); 24 | AdvancedCorePlugin.getInstance().extraDebug(reward.getRewardName() + ": Checking " + getPath()); 25 | return onRequirementsRequested(reward, user, value, data.getConfigurationSection(getPath()), rewardOptions); 26 | } 27 | return true; 28 | } 29 | 30 | public abstract boolean onRequirementsRequested(Reward reward, AdvancedCoreUser user, Set section, 31 | ConfigurationSection data, RewardOptions rewardOptions); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import org.bukkit.configuration.ConfigurationSection; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public abstract class RequirementInjectString extends RequirementInject { 14 | 15 | @Getter 16 | @Setter 17 | private String defaultValue; 18 | 19 | public RequirementInjectString(String path) { 20 | super(path); 21 | } 22 | 23 | public RequirementInjectString(String path, String defaultValue) { 24 | super(path); 25 | this.defaultValue = defaultValue; 26 | } 27 | 28 | @Override 29 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 30 | RewardOptions rewardOptions) { 31 | if ((data.isString(getPath()) && !data.getString(getPath(), "").isEmpty()) 32 | || (isAlwaysForce() && data.contains(getPath(), true)) || isAlwaysForceNoData()) { 33 | String value = data.getString(getPath(), getDefaultValue()); 34 | AdvancedCorePlugin.getInstance() 35 | .extraDebug(reward.getRewardName() + ": Checking " + getPath() + ", value: " + value); 36 | return onRequirementsRequest(reward, user, value, rewardOptions); 37 | 38 | } 39 | return true; 40 | } 41 | 42 | public abstract boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, String value, 43 | RewardOptions rewardOptions); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectStringList.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | import com.bencodez.simpleapi.array.ArrayUtils; 12 | 13 | import lombok.Getter; 14 | import lombok.Setter; 15 | 16 | public abstract class RequirementInjectStringList extends RequirementInject { 17 | 18 | @Getter 19 | @Setter 20 | private ArrayList defaultValue = new ArrayList<>(); 21 | 22 | public RequirementInjectStringList(String path) { 23 | super(path); 24 | } 25 | 26 | public RequirementInjectStringList(String path, ArrayList defaultValue) { 27 | super(path); 28 | this.defaultValue = defaultValue; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | @Override 33 | public boolean onRequirementRequest(Reward reward, AdvancedCoreUser user, ConfigurationSection data, 34 | RewardOptions rewardOptions) { 35 | if (data.isList(getPath()) || (isAlwaysForce() && data.contains(getPath(), true) || isAlwaysForceNoData())) { 36 | ArrayList value = (ArrayList) data.getList(getPath(), getDefaultValue()); 37 | AdvancedCorePlugin.getInstance().extraDebug(reward.getRewardName() + ": Checking " + getPath() + ", value: " 38 | + ArrayUtils.makeStringList(value)); 39 | return onRequirementsRequest(reward, user, value, rewardOptions); 40 | 41 | } 42 | return true; 43 | } 44 | 45 | public abstract boolean onRequirementsRequest(Reward reward, AdvancedCoreUser user, ArrayList num, 46 | RewardOptions rewardOptions); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/injectedrequirement/RequirementInjectValidator.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.rewards.injectedrequirement; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.configuration.ConfigurationSection; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.rewards.Reward; 9 | 10 | import lombok.Getter; 11 | 12 | public abstract class RequirementInjectValidator { 13 | 14 | @Getter 15 | private ArrayList paths = new ArrayList<>(); 16 | 17 | public RequirementInjectValidator addPath(String path) { 18 | paths.add(path); 19 | return this; 20 | } 21 | 22 | public boolean isValid(RequirementInject inject, String path) { 23 | return inject.getPath().startsWith(path) || paths.contains(path); 24 | } 25 | 26 | public abstract void onValidate(Reward reward, RequirementInject inject, ConfigurationSection data); 27 | 28 | public void warning(Reward reward, RequirementInject inject, String str) { 29 | AdvancedCorePlugin.getInstance().getLogger() 30 | .warning("RequirementInject Validator: " + reward.getName() + ", Directly Defined: " 31 | + reward.getConfig().isDirectlyDefinedReward() + " Path: " + inject.getPath() + " : " + str); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/TimeType.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time; 2 | 3 | public enum TimeType { 4 | DAY, MONTH, WEEK; 5 | 6 | public static TimeType getTimeType(String str) { 7 | for (TimeType time : TimeType.values()) { 8 | if (time.toString().equalsIgnoreCase(str)) { 9 | return time; 10 | } 11 | } 12 | return null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DateChangedEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time.events; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import com.bencodez.advancedcore.api.time.TimeType; 7 | 8 | // TODO: Auto-generated Javadoc 9 | /** 10 | * The Class DayChangeEvent. 11 | */ 12 | public class DateChangedEvent extends Event { 13 | 14 | /** The Constant handlers. */ 15 | private static final HandlerList handlers = new HandlerList(); 16 | 17 | /** 18 | * Gets the handler list. 19 | * 20 | * @return the handler list 21 | */ 22 | public static HandlerList getHandlerList() { 23 | return handlers; 24 | } 25 | 26 | private boolean fake = false; 27 | 28 | private TimeType timeType; 29 | 30 | public DateChangedEvent(TimeType time) { 31 | super(true); 32 | this.timeType = time; 33 | } 34 | 35 | /* 36 | * (non-Javadoc) 37 | * 38 | * @see org.bukkit.event.Event#getHandlers() 39 | */ 40 | @Override 41 | public HandlerList getHandlers() { 42 | return handlers; 43 | } 44 | 45 | /** 46 | * @return the timeType 47 | */ 48 | public TimeType getTimeType() { 49 | return timeType; 50 | } 51 | 52 | public boolean isFake() { 53 | return fake; 54 | } 55 | 56 | public void setFake(boolean fake) { 57 | this.fake = fake; 58 | } 59 | 60 | /** 61 | * @param timeType the timeType to set 62 | */ 63 | public void setTimeType(TimeType timeType) { 64 | this.timeType = timeType; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DayChangeEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time.events; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | // TODO: Auto-generated Javadoc 7 | /** 8 | * The Class DayChangeEvent. 9 | */ 10 | public class DayChangeEvent extends Event { 11 | 12 | /** The Constant handlers. */ 13 | private static final HandlerList handlers = new HandlerList(); 14 | 15 | /** 16 | * Gets the handler list. 17 | * 18 | * @return the handler list 19 | */ 20 | public static HandlerList getHandlerList() { 21 | return handlers; 22 | } 23 | 24 | private boolean fake = false; 25 | 26 | /** 27 | * Instantiates a new day change event. 28 | */ 29 | public DayChangeEvent() { 30 | super(true); 31 | } 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see org.bukkit.event.Event#getHandlers() 37 | */ 38 | @Override 39 | public HandlerList getHandlers() { 40 | return handlers; 41 | } 42 | 43 | public boolean isFake() { 44 | return fake; 45 | } 46 | 47 | public void setFake(boolean fake) { 48 | this.fake = fake; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/MonthChangeEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time.events; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | // TODO: Auto-generated Javadoc 7 | /** 8 | * The Class MonthChangeEvent. 9 | */ 10 | public class MonthChangeEvent extends Event { 11 | 12 | /** The Constant handlers. */ 13 | private static final HandlerList handlers = new HandlerList(); 14 | 15 | /** 16 | * Gets the handler list. 17 | * 18 | * @return the handler list 19 | */ 20 | public static HandlerList getHandlerList() { 21 | return handlers; 22 | } 23 | 24 | private boolean fake = false; 25 | 26 | /** 27 | * Instantiates a new month change event. 28 | */ 29 | public MonthChangeEvent() { 30 | super(true); 31 | } 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see org.bukkit.event.Event#getHandlers() 37 | */ 38 | @Override 39 | public HandlerList getHandlers() { 40 | return handlers; 41 | } 42 | 43 | public boolean isFake() { 44 | return fake; 45 | } 46 | 47 | public void setFake(boolean fake) { 48 | this.fake = fake; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/PreDateChangedEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time.events; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import com.bencodez.advancedcore.api.time.TimeType; 7 | 8 | // TODO: Auto-generated Javadoc 9 | /** 10 | * The Class DayChangeEvent. 11 | */ 12 | public class PreDateChangedEvent extends Event { 13 | 14 | /** The Constant handlers. */ 15 | private static final HandlerList handlers = new HandlerList(); 16 | 17 | /** 18 | * Gets the handler list. 19 | * 20 | * @return the handler list 21 | */ 22 | public static HandlerList getHandlerList() { 23 | return handlers; 24 | } 25 | 26 | private boolean fake = false; 27 | 28 | private TimeType timeType; 29 | 30 | public PreDateChangedEvent(TimeType time) { 31 | super(true); 32 | this.timeType = time; 33 | } 34 | 35 | /* 36 | * (non-Javadoc) 37 | * 38 | * @see org.bukkit.event.Event#getHandlers() 39 | */ 40 | @Override 41 | public HandlerList getHandlers() { 42 | return handlers; 43 | } 44 | 45 | /** 46 | * @return the timeType 47 | */ 48 | public TimeType getTimeType() { 49 | return timeType; 50 | } 51 | 52 | public boolean isFake() { 53 | return fake; 54 | } 55 | 56 | public void setFake(boolean fake) { 57 | this.fake = fake; 58 | } 59 | 60 | /** 61 | * @param timeType the timeType to set 62 | */ 63 | public void setTimeType(TimeType timeType) { 64 | this.timeType = timeType; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/WeekChangeEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.time.events; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | // TODO: Auto-generated Javadoc 7 | /** 8 | * The Class WeekChangeEvent. 9 | */ 10 | public class WeekChangeEvent extends Event { 11 | 12 | /** The Constant handlers. */ 13 | private static final HandlerList handlers = new HandlerList(); 14 | 15 | /** 16 | * Gets the handler list. 17 | * 18 | * @return the handler list 19 | */ 20 | public static HandlerList getHandlerList() { 21 | return handlers; 22 | } 23 | 24 | private boolean fake = false; 25 | 26 | /** 27 | * Instantiates a new week change event. 28 | */ 29 | public WeekChangeEvent() { 30 | super(true); 31 | } 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see org.bukkit.event.Event#getHandlers() 37 | */ 38 | @Override 39 | public HandlerList getHandlers() { 40 | return handlers; 41 | } 42 | 43 | public boolean isFake() { 44 | return fake; 45 | } 46 | 47 | public void setFake(boolean fake) { 48 | this.fake = fake; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/updater/UpdateDownloader.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.updater; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.net.URL; 7 | import java.nio.channels.Channels; 8 | import java.nio.channels.ReadableByteChannel; 9 | 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.plugin.Plugin; 12 | import org.bukkit.plugin.java.JavaPlugin; 13 | 14 | import com.bencodez.advancedcore.AdvancedCorePlugin; 15 | import com.bencodez.simpleapi.updater.Updater; 16 | 17 | public class UpdateDownloader { 18 | 19 | private static UpdateDownloader instance = new UpdateDownloader(); 20 | 21 | public static UpdateDownloader getInstance() { 22 | return instance; 23 | } 24 | 25 | private UpdateDownloader() { 26 | } 27 | 28 | public void checkAutoDownload(JavaPlugin plugin, int resourceId) { 29 | Updater updater = new Updater(plugin, resourceId, 30 | !AdvancedCorePlugin.getInstance().getOptions().isAutoDownload()); 31 | switch (updater.getResult()) { 32 | case UPDATE_AVAILABLE: 33 | download(plugin, resourceId); 34 | plugin.getLogger() 35 | .info("Downloaded jar automaticly, restart to update. Note: Updates take 30-40 minutes to load"); 36 | break; 37 | default: 38 | break; 39 | } 40 | } 41 | 42 | public boolean download(Plugin plugin, int resourceId) { 43 | try { 44 | download(new URL("https://api.spiget.org/v2/resources/" + resourceId + "/download"), 45 | new File(Bukkit.getServer().getUpdateFolderFile(), plugin.getDescription().getName() + ".jar")); 46 | return true; 47 | } catch (IOException e) { // TODO Auto-generated catch block 48 | plugin.getLogger().warning("Unable to download jar"); 49 | e.printStackTrace(); 50 | return false; 51 | } 52 | } 53 | 54 | private void download(URL url, File target) throws IOException { 55 | target.getParentFile().mkdirs(); 56 | target.createNewFile(); 57 | ReadableByteChannel rbc = Channels.newChannel(url.openStream()); 58 | FileOutputStream fos = new FileOutputStream(target); 59 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 60 | fos.close(); 61 | rbc.close(); 62 | } 63 | 64 | public void downloadFromJenkins(String site, String projectName) { 65 | try { 66 | download( 67 | new URL("http://" + site + "/job/" + projectName + "/lastSuccessfulBuild/artifact/" + projectName 68 | + "/target/" + projectName + ".jar"), 69 | new File(Bukkit.getServer().getUpdateFolderFile(), 70 | AdvancedCorePlugin.getInstance().getDescription().getName() + ".jar")); 71 | } catch (IOException e) { 72 | e.printStackTrace(); 73 | } 74 | // String site = 75 | // "http://ben12345rocks.com/job/AylaChat/lastSuccessfulBuild/artifact/AylaChat/target/AylaChat.jar"; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/UserDataChanged.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user; 2 | 3 | public abstract class UserDataChanged { 4 | public abstract void onChange(AdvancedCoreUser user, String... key); 5 | } 6 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/UserStartup.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | public abstract class UserStartup { 7 | @Getter 8 | @Setter 9 | private boolean process = true; 10 | 11 | public abstract void onFinish(); 12 | 13 | public abstract void onStart(); 14 | 15 | public abstract void onStartUp(AdvancedCoreUser user); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/UserStorage.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user; 2 | 3 | public enum UserStorage { 4 | 5 | MYSQL, SQLITE, @Deprecated 6 | FLAT; 7 | 8 | public static UserStorage value(String str) { 9 | // if (str.equalsIgnoreCase("FLAT")) { 10 | // return SQLITE; 11 | // } 12 | for (UserStorage s : values()) { 13 | if (s.toString().equalsIgnoreCase(str)) { 14 | return s; 15 | } 16 | } 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/change/UserDataChange.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.change; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | public abstract class UserDataChange { 9 | @Getter 10 | @Setter 11 | private String key; 12 | 13 | public UserDataChange(String key) { 14 | this.key = key; 15 | } 16 | 17 | public abstract void dump(); 18 | 19 | public abstract DataValue toUserDataValue(); 20 | } 21 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/change/UserDataChangeBoolean.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.change; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueBoolean; 5 | 6 | import lombok.Getter; 7 | 8 | public class UserDataChangeBoolean extends UserDataChange { 9 | @Getter 10 | private boolean value; 11 | 12 | public UserDataChangeBoolean(String key, boolean value) { 13 | super(key); 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public void dump() { 19 | setKey(null); 20 | } 21 | 22 | @Override 23 | public DataValue toUserDataValue() { 24 | return new DataValueBoolean(value); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/change/UserDataChangeInt.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.change; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueInt; 5 | 6 | import lombok.Getter; 7 | 8 | public class UserDataChangeInt extends UserDataChange { 9 | @Getter 10 | private int value; 11 | 12 | public UserDataChangeInt(String key, int value) { 13 | super(key); 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public void dump() { 19 | setKey(null); 20 | } 21 | 22 | @Override 23 | public DataValue toUserDataValue() { 24 | return new DataValueInt(value); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/change/UserDataChangeString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.change; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueString; 5 | 6 | import lombok.Getter; 7 | 8 | public class UserDataChangeString extends UserDataChange { 9 | @Getter 10 | private String value; 11 | 12 | public UserDataChangeString(String key, String value) { 13 | super(key); 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public void dump() { 19 | setKey(null); 20 | value = null; 21 | } 22 | 23 | @Override 24 | public DataValue toUserDataValue() { 25 | return new DataValueString(value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/keys/UserDataKey.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.keys; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | 5 | import lombok.Getter; 6 | 7 | public abstract class UserDataKey { 8 | @Getter 9 | private String columnType; 10 | 11 | @Getter 12 | private String key; 13 | 14 | public UserDataKey(String key) { 15 | this.key = key; 16 | } 17 | 18 | public abstract DataValue getDefault(); 19 | 20 | public UserDataKey setColumnType(String columnType) { 21 | this.columnType = columnType; 22 | return this; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/keys/UserDataKeyBoolean.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.keys; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueBoolean; 5 | 6 | public class UserDataKeyBoolean extends UserDataKey { 7 | public UserDataKeyBoolean(String key) { 8 | super(key); 9 | setColumnType("VARCHAR(5)"); 10 | } 11 | 12 | public DataValue getDefault() { 13 | return new DataValueBoolean(false); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/keys/UserDataKeyInt.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.keys; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueInt; 5 | 6 | public class UserDataKeyInt extends UserDataKey { 7 | public UserDataKeyInt(String key) { 8 | super(key); 9 | setColumnType("INT DEFAULT '0'"); 10 | } 11 | 12 | public DataValue getDefault() { 13 | return new DataValueInt(0); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/keys/UserDataKeyString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.user.usercache.keys; 2 | 3 | import com.bencodez.simpleapi.sql.data.DataValue; 4 | import com.bencodez.simpleapi.sql.data.DataValueBoolean; 5 | import com.bencodez.simpleapi.sql.data.DataValueString; 6 | 7 | public class UserDataKeyString extends UserDataKey { 8 | public UserDataKeyString(String key) { 9 | super(key); 10 | setColumnType("TEXT"); 11 | } 12 | 13 | public DataValue getDefault() { 14 | if (getColumnType().equalsIgnoreCase("VARCHAR(5)")) { 15 | return new DataValueBoolean(false); 16 | } 17 | return new DataValueString(""); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/InputMethod.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest; 2 | 3 | import com.bencodez.advancedcore.AdvancedCorePlugin; 4 | 5 | /** 6 | * The Enum InputMethod. 7 | */ 8 | public enum InputMethod { 9 | 10 | BOOK, 11 | 12 | CHAT, 13 | 14 | INVENTORY, 15 | 16 | SIGN; 17 | 18 | /** 19 | * Gets the method. 20 | * 21 | * @param method the method 22 | * @return the method 23 | */ 24 | public static InputMethod getMethod(String method) { 25 | for (InputMethod input : values()) { 26 | if (method.equalsIgnoreCase(input.toString())) { 27 | return input; 28 | } 29 | } 30 | try { 31 | return valueOf(AdvancedCorePlugin.getInstance().getOptions().getDefaultRequestMethod()); 32 | } catch (Exception ex) { 33 | return CHAT; 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/book/BookManager.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.book; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.Material; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.HandlerList; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.player.PlayerEditBookEvent; 10 | import org.bukkit.inventory.ItemStack; 11 | 12 | import com.bencodez.advancedcore.AdvancedCorePlugin; 13 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 14 | import com.bencodez.simpleapi.player.PlayerUtils; 15 | 16 | /** 17 | * The Class BookManager. 18 | */ 19 | public class BookManager implements Listener { 20 | 21 | /** The listener. */ 22 | public Listener listener; 23 | 24 | /** 25 | * Instantiates a new book manager. 26 | * 27 | * @param player the player 28 | * @param start the start 29 | * @param listener the listener 30 | */ 31 | public BookManager(Player player, String start, BookSign listener) { 32 | AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player); 33 | ItemStack item = new ItemStack(Material.WRITABLE_BOOK); 34 | PlayerUtils.setPlayerMeta(AdvancedCorePlugin.getInstance(), player, "BookManager", listener); 35 | 36 | user.giveItem(item); 37 | 38 | this.listener = new Listener() { 39 | @SuppressWarnings("deprecation") 40 | @EventHandler 41 | public void bookEdit(PlayerEditBookEvent event) { 42 | Player player = event.getPlayer(); 43 | boolean destory = false; 44 | 45 | String st = ""; 46 | for (String str : event.getNewBookMeta().getPages()) { 47 | st += str; 48 | } 49 | final String input = st; 50 | BookSign listener = (BookSign) PlayerUtils.getPlayerMeta(AdvancedCorePlugin.getInstance(), player, 51 | "BookManager"); 52 | Bukkit.getScheduler().runTaskAsynchronously(AdvancedCorePlugin.getInstance(), new Runnable() { 53 | 54 | @Override 55 | public void run() { 56 | listener.onBookSign(player, input); 57 | } 58 | }); 59 | 60 | player.getInventory().getItem(event.getSlot()).setType(Material.AIR); 61 | player.getInventory().setItem(event.getSlot(), new ItemStack(Material.AIR)); 62 | destory = true; 63 | 64 | if (destory) { 65 | destroy(); 66 | } 67 | 68 | } 69 | 70 | }; 71 | Bukkit.getPluginManager().registerEvents(this.listener, AdvancedCorePlugin.getInstance()); 72 | } 73 | 74 | /** 75 | * Destroy. 76 | */ 77 | public void destroy() { 78 | HandlerList.unregisterAll(listener); 79 | } 80 | } -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/book/BookSign.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.book; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | /** 6 | * The Class BookSign. 7 | */ 8 | public abstract class BookSign { 9 | 10 | /** 11 | * On book sign. 12 | * 13 | * @param player the player 14 | * @param input the input 15 | */ 16 | public abstract void onBookSign(Player player, String input); 17 | } -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/BooleanListener.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public abstract class BooleanListener { 6 | 7 | /** 8 | * On input. 9 | * 10 | * @param player the player 11 | * @param value the value 12 | */ 13 | public abstract void onInput(Player player, boolean value); 14 | } 15 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/Listener.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public abstract class Listener { 6 | 7 | public abstract void onInput(Player player, T value); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/NumberListener.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public abstract class NumberListener { 6 | 7 | /** 8 | * On input. 9 | * 10 | * @param player the player 11 | * @param value the value 12 | */ 13 | public abstract void onInput(Player player, Number value); 14 | } 15 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/StringListener.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public abstract class StringListener { 6 | 7 | /** 8 | * On input. 9 | * 10 | * @param player the player 11 | * @param value the value 12 | */ 13 | public abstract void onInput(Player player, String value); 14 | } 15 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/prompt/PromptManager.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.prompt; 2 | 3 | import org.bukkit.conversations.Conversable; 4 | import org.bukkit.conversations.ConversationFactory; 5 | 6 | /** 7 | * The Class PromptManager. 8 | */ 9 | public class PromptManager { 10 | 11 | /** The conversation factory. */ 12 | ConversationFactory conversationFactory; 13 | 14 | /** The prompt text. */ 15 | String promptText; 16 | 17 | /** 18 | * Instantiates a new prompt manager. 19 | * 20 | * @param promptText the prompt text 21 | * @param convoFactory the convo factory 22 | */ 23 | public PromptManager(String promptText, ConversationFactory convoFactory) { 24 | this.promptText = promptText; 25 | conversationFactory = convoFactory; 26 | } 27 | 28 | /** 29 | * String prompt. 30 | * 31 | * @param conversable the conversable 32 | * @param prompt the prompt 33 | */ 34 | public void stringPrompt(Conversable conversable, PromptReturnString prompt) { 35 | prompt.promptText = promptText; 36 | conversationFactory.withFirstPrompt(prompt).buildConversation(conversable).begin(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/prompt/PromptReturnString.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.prompt; 2 | 3 | import org.bukkit.conversations.Conversable; 4 | import org.bukkit.conversations.ConversationContext; 5 | import org.bukkit.conversations.Prompt; 6 | import org.bukkit.conversations.StringPrompt; 7 | 8 | /** 9 | * The Class PromptReturnString. 10 | */ 11 | public abstract class PromptReturnString extends StringPrompt { 12 | 13 | /** The prompt text. */ 14 | public String promptText; 15 | 16 | /* 17 | * (non-Javadoc) 18 | * 19 | * @see org.bukkit.conversations.Prompt#acceptInput(org.bukkit.conversations. 20 | * ConversationContext, java.lang.String) 21 | */ 22 | @Override 23 | public Prompt acceptInput(ConversationContext context, String input) { 24 | 25 | context.setSessionData("Input", input); 26 | onInput(context, context.getForWhom(), input); 27 | return Prompt.END_OF_CONVERSATION; 28 | } 29 | 30 | /* 31 | * (non-Javadoc) 32 | * 33 | * @see org.bukkit.conversations.Prompt#getPromptText(org.bukkit.conversations 34 | * .ConversationContext) 35 | */ 36 | @Override 37 | public String getPromptText(ConversationContext context) { 38 | return promptText; 39 | } 40 | 41 | /** 42 | * On input. 43 | * 44 | * @param context the context 45 | * @param conversable the conversable 46 | * @param input the input 47 | */ 48 | public abstract void onInput(ConversationContext context, Conversable conversable, String input); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/requesters/BooleanRequester.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.api.valuerequest.requesters; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.inventory.BInventory; 9 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 10 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 11 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 12 | import com.bencodez.advancedcore.api.valuerequest.InputMethod; 13 | import com.bencodez.advancedcore.api.valuerequest.book.BookManager; 14 | import com.bencodez.advancedcore.api.valuerequest.book.BookSign; 15 | import com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener; 16 | import com.bencodez.simpleapi.player.PlayerUtils; 17 | 18 | import net.md_5.bungee.api.chat.ClickEvent.Action; 19 | import net.md_5.bungee.api.chat.TextComponent; 20 | 21 | /** 22 | * The Class BooleanRequester. 23 | */ 24 | public class BooleanRequester { 25 | 26 | /** 27 | * Instantiates a new boolean requester. 28 | */ 29 | public BooleanRequester() { 30 | 31 | } 32 | 33 | /** 34 | * Request. 35 | * 36 | * @param player the player 37 | * @param method the method 38 | * @param currentValue the current value 39 | * @param promptText the prompt text 40 | * @param listener the listener 41 | */ 42 | public void request(Player player, InputMethod method, String currentValue, String promptText, 43 | BooleanListener listener) { 44 | if (AdvancedCorePlugin.getInstance().getOptions().getDisabledRequestMethods().contains(method.toString())) { 45 | player.sendMessage("Disabled method: " + method.toString()); 46 | } 47 | if (method.equals(InputMethod.SIGN)) { 48 | method = InputMethod.INVENTORY; 49 | } 50 | if (method.equals(InputMethod.INVENTORY)) { 51 | 52 | BInventory inv = new BInventory("Click one of the following:"); 53 | 54 | inv.addButton(inv.getNextSlot(), 55 | new BInventoryButton("True", new String[] {}, new ItemStack(Material.REDSTONE_BLOCK)) { 56 | 57 | @Override 58 | public void onClick(ClickEvent clickEvent) { 59 | listener.onInput(clickEvent.getPlayer(), 60 | Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName())); 61 | 62 | } 63 | }); 64 | inv.addButton(inv.getNextSlot(), 65 | new BInventoryButton("False", new String[] {}, new ItemStack(Material.IRON_BLOCK)) { 66 | 67 | @Override 68 | public void onClick(ClickEvent clickEvent) { 69 | listener.onInput(clickEvent.getPlayer(), 70 | Boolean.valueOf(clickEvent.getClickedItem().getItemMeta().getDisplayName())); 71 | 72 | } 73 | }); 74 | 75 | inv.openInventory(player); 76 | 77 | } else if (method.equals(InputMethod.CHAT)) { 78 | 79 | AdvancedCoreUser user = AdvancedCorePlugin.getInstance().getUserManager().getUser(player); 80 | user.sendMessage("&cClick one of the following options below:"); 81 | String option = "True"; 82 | TextComponent comp = new TextComponent(option); 83 | PlayerUtils.setPlayerMeta(AdvancedCorePlugin.getInstance(), player, "ValueRequestBoolean", listener); 84 | comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, 85 | "/" + AdvancedCorePlugin.getInstance().getName().toLowerCase() + "valuerequestinput Boolean " 86 | + option)); 87 | user.sendJson(comp); 88 | option = "False"; 89 | comp = new TextComponent(option); 90 | comp.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(Action.RUN_COMMAND, 91 | "/" + AdvancedCorePlugin.getInstance().getName().toLowerCase() + "valuerequestinput Boolean " 92 | + option)); 93 | user.sendJson(comp); 94 | } else if (method.equals(InputMethod.BOOK)) { 95 | 96 | new BookManager(player, currentValue, new BookSign() { 97 | 98 | @Override 99 | public void onBookSign(Player player, String input) { 100 | listener.onInput(player, Boolean.valueOf(input)); 101 | 102 | } 103 | }); 104 | } else { 105 | player.sendMessage("Invalid method/disabled method, change your request method"); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandler.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.bungeeapi.globaldata; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Map.Entry; 6 | 7 | import com.bencodez.simpleapi.sql.Column; 8 | import com.bencodez.simpleapi.sql.data.DataValue; 9 | import com.bencodez.simpleapi.sql.data.DataValueBoolean; 10 | import com.bencodez.simpleapi.sql.data.DataValueInt; 11 | import com.bencodez.simpleapi.sql.data.DataValueString; 12 | 13 | import lombok.Getter; 14 | 15 | public class GlobalDataHandler { 16 | @Getter 17 | private GlobalMySQL globalMysql; 18 | 19 | public GlobalDataHandler(GlobalMySQL globalMysql) { 20 | this.globalMysql = globalMysql; 21 | } 22 | 23 | public boolean getBoolean(String server, String key) { 24 | HashMap data = getExact(server); 25 | if (data.containsKey(key)) { 26 | DataValue value = data.get(key); 27 | if (value.isBoolean()) { 28 | return value.getBoolean(); 29 | } 30 | return Boolean.valueOf(value.getString()).booleanValue(); 31 | } 32 | return false; 33 | } 34 | 35 | public HashMap getExact(String server) { 36 | HashMap data = new HashMap<>(); 37 | for (Column entry : globalMysql.getExact(server)) { 38 | data.put(entry.getName(), entry.getValue()); 39 | } 40 | return data; 41 | } 42 | 43 | public int getInt(String server, String key) { 44 | HashMap data = getExact(server); 45 | if (data.containsKey(key)) { 46 | DataValue value = data.get(key); 47 | if (value.isInt()) { 48 | return value.getInt(); 49 | } 50 | } 51 | return 0; 52 | } 53 | 54 | public String getString(String server, String key) { 55 | HashMap data = getExact(server); 56 | if (data.containsKey(key)) { 57 | DataValue value = data.get(key); 58 | if (value.isString()) { 59 | return value.getString(); 60 | } 61 | } 62 | return ""; 63 | } 64 | 65 | public void setBoolean(String server, String key, boolean data) { 66 | globalMysql.update(server, key, new DataValueBoolean(data)); 67 | } 68 | 69 | public void setData(String server, HashMap data) { 70 | ArrayList cols = new ArrayList<>(); 71 | for (Entry entry : data.entrySet()) { 72 | cols.add(new Column(entry.getKey(), entry.getValue())); 73 | } 74 | globalMysql.update(server, cols, false); 75 | } 76 | 77 | public void setInt(String server, String key, int data) { 78 | globalMysql.update(server, key, new DataValueInt(data)); 79 | } 80 | 81 | public void setString(String server, String key, String data) { 82 | globalMysql.update(server, key, new DataValueString(data)); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/command/executor/ValueRequestInputCommand.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.command.executor; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.command.PluginIdentifiableCommand; 8 | import org.bukkit.plugin.Plugin; 9 | 10 | import com.bencodez.advancedcore.AdvancedCorePlugin; 11 | import com.bencodez.advancedcore.api.command.CommandHandler; 12 | 13 | public class ValueRequestInputCommand extends Command implements PluginIdentifiableCommand { 14 | private final AdvancedCorePlugin plugin; 15 | 16 | public ValueRequestInputCommand(AdvancedCorePlugin plugin, String name) { 17 | super(name); 18 | this.plugin = plugin; 19 | description = "ValueRequestInput"; 20 | setAliases(new ArrayList<>()); 21 | } 22 | 23 | @Override 24 | public boolean execute(CommandSender sender, String alias, String[] args) { 25 | for (CommandHandler cmd : plugin.getAdvancedCoreCommandLoader().getValueRequestCommands()) { 26 | if (cmd.runCommand(sender, args)) { 27 | return true; 28 | } 29 | } 30 | 31 | return true; 32 | } 33 | 34 | @Override 35 | public Plugin getPlugin() { 36 | return plugin; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/AdminGUI.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.command.gui; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.inventory.ClickType; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import com.bencodez.advancedcore.AdvancedCorePlugin; 11 | import com.bencodez.advancedcore.api.inventory.BInventory; 12 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 13 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 14 | import com.bencodez.advancedcore.api.item.ItemBuilder; 15 | import com.bencodez.advancedcore.api.rewards.Reward; 16 | import com.bencodez.advancedcore.api.valuerequest.ValueRequest; 17 | import com.bencodez.advancedcore.api.valuerequest.listeners.StringListener; 18 | 19 | /** 20 | * The Class AdminGUI. 21 | */ 22 | public class AdminGUI { 23 | 24 | /** The instance. */ 25 | static AdminGUI instance = new AdminGUI(); 26 | 27 | /** 28 | * Gets the single instance of AdminGUI. 29 | * 30 | * @return single instance of AdminGUI 31 | */ 32 | public static AdminGUI getInstance() { 33 | return instance; 34 | } 35 | 36 | AdvancedCorePlugin plugin = AdvancedCorePlugin.getInstance(); 37 | 38 | /** The plugin GU is. */ 39 | private ArrayList pluginGUIs; 40 | 41 | /** 42 | * Instantiates a new admin GUI. 43 | */ 44 | private AdminGUI() { 45 | } 46 | 47 | /** 48 | * Adds the button. 49 | * 50 | * @param b the b 51 | */ 52 | public void addButton(BInventoryButton b) { 53 | if (pluginGUIs == null) { 54 | pluginGUIs = new ArrayList<>(); 55 | } 56 | pluginGUIs.add(b); 57 | } 58 | 59 | /** 60 | * Open GUI. 61 | * 62 | * @param player the player 63 | */ 64 | public void openGUI(Player player) { 65 | if (!player.hasPermission(AdvancedCorePlugin.getInstance().getOptions().getPermPrefix() + ".Admin")) { 66 | player.sendMessage("Not enough permissions"); 67 | return; 68 | } 69 | BInventory inv = new BInventory("AdminGUI"); 70 | inv.addButton(inv.getNextSlot(), new BInventoryButton("&cRewards", new String[] { "&cMiddle click to create" }, 71 | new ItemStack(Material.DIAMOND)) { 72 | 73 | @Override 74 | public void onClick(ClickEvent event) { 75 | Player player = event.getWhoClicked(); 76 | if (event.getClick().equals(ClickType.MIDDLE)) { 77 | new ValueRequest().requestString(player, new StringListener() { 78 | 79 | @Override 80 | public void onInput(Player player, String value) { 81 | Reward reward = plugin.getRewardHandler().getReward(value); 82 | player.sendMessage("Reward file created"); 83 | plugin.reloadAdvancedCore(false); 84 | RewardEditGUI.getInstance().openRewardGUI(player, reward); 85 | 86 | } 87 | }); 88 | } else { 89 | RewardEditGUI.getInstance().openRewardsGUI(player); 90 | } 91 | } 92 | }); 93 | 94 | inv.addButton(inv.getNextSlot(), new BInventoryButton(new ItemBuilder("PLAYER_HEAD").setName("&cUsers")) { 95 | 96 | @Override 97 | public void onClick(ClickEvent event) { 98 | Player player = event.getWhoClicked(); 99 | UserGUI.getInstance().openUsersGUI(player); 100 | 101 | } 102 | 103 | }); 104 | 105 | if (pluginGUIs != null) { 106 | for (BInventoryButton b : pluginGUIs) { 107 | inv.addButton(inv.getNextSlot(), b); 108 | } 109 | } 110 | 111 | inv.openInventory(player); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/RewardGUIConfirmation.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.command.gui; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.advancedcore.api.gui.GUIHandler; 11 | import com.bencodez.advancedcore.api.gui.GUIMethod; 12 | import com.bencodez.advancedcore.api.inventory.BInventory; 13 | import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; 14 | import com.bencodez.advancedcore.api.inventory.BInventoryButton; 15 | import com.bencodez.advancedcore.api.item.ItemBuilder; 16 | 17 | public abstract class RewardGUIConfirmation extends GUIHandler { 18 | 19 | @SuppressWarnings("unused") 20 | private AdvancedCorePlugin plugin; 21 | private String title; 22 | 23 | public RewardGUIConfirmation(AdvancedCorePlugin plugin, CommandSender player, String title) { 24 | super(plugin, player); 25 | this.plugin = plugin; 26 | this.title = title; 27 | } 28 | 29 | @Override 30 | public ArrayList getChat(CommandSender sender) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void onBook(Player player) { 36 | } 37 | 38 | @Override 39 | public void onChat(CommandSender sender) { 40 | 41 | } 42 | 43 | @Override 44 | public void onChest(Player player) { 45 | BInventory inv = new BInventory(title); 46 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.EMERALD_BLOCK).setName("&aConfirm")) { 47 | 48 | @Override 49 | public void onClick(ClickEvent clickEvent) { 50 | onConfirm(clickEvent.getPlayer()); 51 | } 52 | }); 53 | inv.addButton(new BInventoryButton(new ItemBuilder(Material.REDSTONE_BLOCK).setName("&aCancel")) { 54 | 55 | @Override 56 | public void onClick(ClickEvent clickEvent) { 57 | onDeny(clickEvent.getPlayer()); 58 | } 59 | }); 60 | inv.openInventory(player); 61 | } 62 | 63 | public abstract void onConfirm(Player p); 64 | 65 | public abstract void onDeny(Player p); 66 | 67 | @Override 68 | public void open() { 69 | open(GUIMethod.CHEST); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/data/ServerData.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.data; 2 | 3 | import java.io.File; 4 | 5 | import org.bukkit.plugin.Plugin; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.simpleapi.file.YMLFile; 9 | 10 | // TODO: Auto-generated Javadoc 11 | /** 12 | * The Class ServerData. 13 | */ 14 | public class ServerData extends YMLFile { 15 | public ServerData(AdvancedCorePlugin plugin) { 16 | super(plugin, new File(plugin.getDataFolder(), "ServerData.yml")); 17 | } 18 | 19 | public long getLastUpdated() { 20 | return getData().getLong("LastUpdated", -1); 21 | } 22 | 23 | /** 24 | * Gets the plugin version. 25 | * 26 | * @param plugin the plugin 27 | * @return the plugin version 28 | */ 29 | public String getPluginVersion(Plugin plugin) { 30 | return getData().getString("PluginVersions." + plugin.getName(), ""); 31 | } 32 | 33 | /** 34 | * Gets the prev day. 35 | * 36 | * @return the prev day 37 | */ 38 | public int getPrevDay() { 39 | return getData().getInt("PrevDay", -1); 40 | } 41 | 42 | /** 43 | * Gets the prev month. 44 | * 45 | * @return the prev month 46 | */ 47 | public String getPrevMonth() { 48 | return getData().getString("Month", ""); 49 | } 50 | 51 | /** 52 | * Gets the prev week day. 53 | * 54 | * @return the prev week day 55 | */ 56 | public int getPrevWeekDay() { 57 | return getData().getInt("PrevWeek", -1); 58 | } 59 | 60 | public boolean isIgnoreTime() { 61 | return getData().getBoolean("IgnoreTime", false); 62 | } 63 | 64 | @Override 65 | public void onFileCreation() { 66 | } 67 | 68 | public void setData(String path, Object value) { 69 | getData().set(path, value); 70 | saveData(); 71 | } 72 | 73 | public void setIgnoreTime(boolean value) { 74 | getData().set("IgnoreTime", value); 75 | saveData(); 76 | } 77 | 78 | public void setLastUpdated() { 79 | getData().set("LastUpdated", System.currentTimeMillis()); 80 | saveData(); 81 | } 82 | 83 | /** 84 | * Sets the plugin version. 85 | * 86 | * @param plugin the new plugin version 87 | */ 88 | public void setPluginVersion(Plugin plugin) { 89 | getData().set("PluginVersions." + plugin.getName(), plugin.getDescription().getVersion()); 90 | saveData(); 91 | } 92 | 93 | /** 94 | * Sets the prev day. 95 | * 96 | * @param day the new prev day 97 | */ 98 | public void setPrevDay(int day) { 99 | getData().set("PrevDay", day); 100 | saveData(); 101 | } 102 | 103 | /** 104 | * Sets the prev month. 105 | * 106 | * @param month the new prev month 107 | */ 108 | public void setPrevMonth(String month) { 109 | getData().set("Month", month); 110 | saveData(); 111 | } 112 | 113 | /** 114 | * Sets the prev week day. 115 | * 116 | * @param week the new prev week day 117 | */ 118 | public void setPrevWeekDay(int week) { 119 | getData().set("PrevWeek", week); 120 | saveData(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AdvancedCoreLoginEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | 9 | import lombok.Getter; 10 | import lombok.Setter; 11 | 12 | // TODO: Auto-generated Javadoc 13 | /** 14 | * The Class PlayerRewardEvent. 15 | */ 16 | public class AdvancedCoreLoginEvent extends Event { 17 | 18 | /** The Constant handlers. */ 19 | private static final HandlerList handlers = new HandlerList(); 20 | 21 | /** 22 | * Gets the handler list. 23 | * 24 | * @return the handler list 25 | */ 26 | public static HandlerList getHandlerList() { 27 | return handlers; 28 | } 29 | 30 | /** The cancelled. */ 31 | private boolean cancelled; 32 | 33 | @Getter 34 | @Setter 35 | private Player player; 36 | 37 | public AdvancedCoreLoginEvent(Player player) { 38 | super(true); 39 | setPlayer(player); 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * 45 | * @see org.bukkit.event.Event#getHandlers() 46 | */ 47 | @Override 48 | public HandlerList getHandlers() { 49 | return handlers; 50 | } 51 | 52 | /** 53 | * Checks if is cancelled. 54 | * 55 | * @return true, if is cancelled 56 | */ 57 | public boolean isCancelled() { 58 | return cancelled; 59 | } 60 | 61 | public boolean isUserInStorage() { 62 | return AdvancedCorePlugin.getInstance().getUserManager().getAllUUIDs() 63 | .contains(player.getUniqueId().toString()); 64 | } 65 | 66 | /** 67 | * Sets the cancelled. 68 | * 69 | * @param bln the new cancelled 70 | */ 71 | public void setCancelled(boolean bln) { 72 | cancelled = bln; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AuthMeLogin.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.bencodez.advancedcore.api.misc.PlayerManager; 9 | 10 | import fr.xephi.authme.api.v3.AuthMeApi; 11 | import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; 12 | 13 | public class AuthMeLogin implements Listener { 14 | private AdvancedCorePlugin plugin; 15 | 16 | public AuthMeLogin(AdvancedCorePlugin plugin) { 17 | this.plugin = plugin; 18 | } 19 | 20 | @EventHandler 21 | public void authmeLogin(AuthMeAsyncPreLoginEvent event) { 22 | plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { 23 | 24 | @Override 25 | public void run() { 26 | if (event.getPlayer() != null) { 27 | if (AuthMeApi.getInstance().isAuthenticated(event.getPlayer()) 28 | && plugin.getOptions().isWaitUntilLoggedIn()) { 29 | plugin.debug("Authme Login: " + event.getPlayer().getName() + " (" 30 | + PlayerManager.getInstance().getUUID(event.getPlayer().getName()) + ")"); 31 | AdvancedCoreLoginEvent login = new AdvancedCoreLoginEvent(event.getPlayer()); 32 | Bukkit.getPluginManager().callEvent(login); 33 | } 34 | } 35 | } 36 | }, 2); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/LoginSecurityLogin.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | 7 | import com.bencodez.advancedcore.AdvancedCorePlugin; 8 | import com.lenis0012.bukkit.loginsecurity.events.AuthActionEvent; 9 | import com.lenis0012.bukkit.loginsecurity.session.AuthActionType; 10 | 11 | public class LoginSecurityLogin implements Listener { 12 | private AdvancedCorePlugin plugin; 13 | 14 | public LoginSecurityLogin(AdvancedCorePlugin plugin) { 15 | this.plugin = plugin; 16 | } 17 | 18 | @EventHandler 19 | public void loginSecurityLogin(AuthActionEvent event) { 20 | if (event.getType().equals(AuthActionType.LOGIN)) { 21 | plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { 22 | 23 | @Override 24 | public void run() { 25 | if (event.getPlayer() != null) { 26 | if (plugin.getOptions().isWaitUntilLoggedIn()) { 27 | plugin.debug("LoginSecurity Login: " + event.getPlayer().getName() + " (" 28 | + event.getPlayer().getUniqueId() + ")"); 29 | AdvancedCoreLoginEvent login = new AdvancedCoreLoginEvent(event.getPlayer()); 30 | Bukkit.getPluginManager().callEvent(login); 31 | } 32 | } 33 | } 34 | }, 2); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/PlayerRewardEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import com.bencodez.advancedcore.api.rewards.Reward; 7 | import com.bencodez.advancedcore.api.rewards.RewardOptions; 8 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 9 | 10 | // TODO: Auto-generated Javadoc 11 | /** 12 | * The Class PlayerRewardEvent. 13 | */ 14 | public class PlayerRewardEvent extends Event { 15 | 16 | /** The Constant handlers. */ 17 | private static final HandlerList handlers = new HandlerList(); 18 | 19 | /** 20 | * Gets the handler list. 21 | * 22 | * @return the handler list 23 | */ 24 | public static HandlerList getHandlerList() { 25 | return handlers; 26 | } 27 | 28 | /** The cancelled. */ 29 | private boolean cancelled; 30 | 31 | /** The player. */ 32 | private AdvancedCoreUser player; 33 | /** The reward. */ 34 | private Reward reward; 35 | 36 | private RewardOptions rewardOptions; 37 | 38 | /** 39 | * Instantiates a new player reward event. 40 | * 41 | * @param reward the reward 42 | * @param player the player 43 | * @param rewardOptions rewardOptions 44 | */ 45 | public PlayerRewardEvent(Reward reward, AdvancedCoreUser player, RewardOptions rewardOptions) { 46 | super(true); 47 | setPlayer(player); 48 | setReward(reward); 49 | setRewardOptions(rewardOptions); 50 | } 51 | 52 | /* 53 | * (non-Javadoc) 54 | * 55 | * @see org.bukkit.event.Event#getHandlers() 56 | */ 57 | @Override 58 | public HandlerList getHandlers() { 59 | return handlers; 60 | } 61 | 62 | /** 63 | * Gets the player. 64 | * 65 | * @return the player 66 | */ 67 | public AdvancedCoreUser getPlayer() { 68 | return player; 69 | } 70 | 71 | /** 72 | * Gets the reward. 73 | * 74 | * @return the reward 75 | */ 76 | public Reward getReward() { 77 | return reward; 78 | } 79 | 80 | /** 81 | * @return the rewardOptions 82 | */ 83 | public RewardOptions getRewardOptions() { 84 | return rewardOptions; 85 | } 86 | 87 | /** 88 | * Checks if is cancelled. 89 | * 90 | * @return true, if is cancelled 91 | */ 92 | public boolean isCancelled() { 93 | return cancelled; 94 | } 95 | 96 | /** 97 | * Sets the cancelled. 98 | * 99 | * @param bln the new cancelled 100 | */ 101 | public void setCancelled(boolean bln) { 102 | cancelled = bln; 103 | } 104 | 105 | /** 106 | * Sets the player. 107 | * 108 | * @param player the new player 109 | */ 110 | public void setPlayer(AdvancedCoreUser player) { 111 | this.player = player; 112 | } 113 | 114 | /** 115 | * Sets the reward. 116 | * 117 | * @param reward the new reward 118 | */ 119 | public void setReward(Reward reward) { 120 | this.reward = reward; 121 | } 122 | 123 | /** 124 | * @param rewardOptions the rewardOptions to set 125 | */ 126 | public void setRewardOptions(RewardOptions rewardOptions) { 127 | this.rewardOptions = rewardOptions; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/PlayerShowListener.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.Listener; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | 11 | import de.myzelyam.api.vanish.PlayerShowEvent; 12 | 13 | // TODO: Auto-generated Javadoc 14 | /** 15 | * The Class PlayerJoinEvent. 16 | */ 17 | public class PlayerShowListener implements Listener { 18 | 19 | /** The plugin. */ 20 | private AdvancedCorePlugin plugin; 21 | 22 | /** 23 | * Instantiates a new player join event. 24 | * 25 | * @param plugin the plugin 26 | */ 27 | public PlayerShowListener(AdvancedCorePlugin plugin) { 28 | this.plugin = plugin; 29 | } 30 | 31 | @EventHandler(priority = EventPriority.MONITOR) 32 | public void onJoin(PlayerShowEvent event) { 33 | if (plugin != null && plugin.isEnabled()) { 34 | plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { 35 | 36 | @Override 37 | public void run() { 38 | if (plugin != null && plugin.isEnabled()) { 39 | if (plugin.isAuthMeLoaded() && plugin.getOptions().isWaitUntilLoggedIn()) { 40 | return; 41 | } 42 | 43 | Player player = event.getPlayer(); 44 | 45 | if (player != null) { 46 | plugin.debug("Vanish Login: " + event.getPlayer().getName() + " (" 47 | + event.getPlayer().getUniqueId() + ")"); 48 | if (plugin.getPermissionHandler() != null) { 49 | plugin.getPermissionHandler().login(player); 50 | } 51 | 52 | AdvancedCoreLoginEvent login = new AdvancedCoreLoginEvent(player); 53 | Bukkit.getPluginManager().callEvent(login); 54 | 55 | if (login.isCancelled()) { 56 | return; 57 | } 58 | } 59 | 60 | } 61 | 62 | } 63 | }, 2); 64 | } 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/PluginUpdateVersionEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | import org.bukkit.plugin.Plugin; 6 | 7 | /** 8 | * The Class PluginUpdateVersionEvent. 9 | */ 10 | public class PluginUpdateVersionEvent extends Event { 11 | 12 | /** The Constant handlers. */ 13 | private static final HandlerList handlers = new HandlerList(); 14 | 15 | /** 16 | * Gets the handler list. 17 | * 18 | * @return the handler list 19 | */ 20 | public static HandlerList getHandlerList() { 21 | return handlers; 22 | } 23 | 24 | /** The old version. */ 25 | private String oldVersion; 26 | 27 | /** The plugin. */ 28 | private Plugin plugin; 29 | 30 | /** 31 | * Instantiates a new plugin update version event. 32 | * 33 | * @param plugin the plugin 34 | * @param oldVersion the old version 35 | */ 36 | public PluginUpdateVersionEvent(Plugin plugin, String oldVersion) { 37 | super(true); 38 | this.plugin = plugin; 39 | this.oldVersion = oldVersion; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * 45 | * @see org.bukkit.event.Event#getHandlers() 46 | */ 47 | @Override 48 | public HandlerList getHandlers() { 49 | return handlers; 50 | } 51 | 52 | /** 53 | * Gets the old version. 54 | * 55 | * @return the old version 56 | */ 57 | public String getOldVersion() { 58 | return oldVersion; 59 | } 60 | 61 | /** 62 | * Gets the plugin. 63 | * 64 | * @return the plugin 65 | */ 66 | public Plugin getPlugin() { 67 | return plugin; 68 | } 69 | 70 | /** 71 | * Sets the old version. 72 | * 73 | * @param oldVersion the new old version 74 | */ 75 | public void setOldVersion(String oldVersion) { 76 | this.oldVersion = oldVersion; 77 | } 78 | 79 | /** 80 | * Sets the plugin. 81 | * 82 | * @param plugin the new plugin 83 | */ 84 | public void setPlugin(Plugin plugin) { 85 | this.plugin = plugin; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/WorldChangeEvent.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.listeners; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerChangedWorldEvent; 8 | 9 | import com.bencodez.advancedcore.AdvancedCorePlugin; 10 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 11 | 12 | /** 13 | * The Class WorldChangeEvent. 14 | */ 15 | public class WorldChangeEvent implements Listener { 16 | 17 | /** The plugin. */ 18 | private AdvancedCorePlugin plugin; 19 | 20 | /** 21 | * Instantiates a new world change event. 22 | * 23 | * @param plugin Plugin 24 | */ 25 | public WorldChangeEvent(AdvancedCorePlugin plugin) { 26 | this.plugin = plugin; 27 | } 28 | 29 | /** 30 | * On world change. 31 | * 32 | * @param event the event 33 | */ 34 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) 35 | public void onWorldChange(PlayerChangedWorldEvent event) { 36 | if (plugin != null && plugin.isEnabled() && plugin.isLoadUserData()) { 37 | final Player player = event.getPlayer(); 38 | plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { 39 | 40 | @Override 41 | public void run() { 42 | if (plugin.getOptions().isDisableCheckOnWorldChange() || player == null 43 | || !plugin.isLoadUserData()) { 44 | return; 45 | } 46 | 47 | AdvancedCoreUser user = plugin.getUserManager().getUser(player); 48 | if (user.isCheckWorld()) { 49 | user.checkOfflineRewards(); 50 | } 51 | } 52 | }, 10); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/logger/Logger.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.logger; 2 | 3 | import java.io.File; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | import java.io.PrintWriter; 7 | 8 | import org.bukkit.plugin.Plugin; 9 | 10 | /** 11 | * The Class Logger. 12 | */ 13 | public class Logger { 14 | 15 | /** The location. */ 16 | File location; 17 | 18 | /** The plugin. */ 19 | Plugin plugin; 20 | 21 | /** 22 | * Instantiates a new logger. 23 | * 24 | * @param plugin the plugin 25 | * @param location the location 26 | */ 27 | public Logger(Plugin plugin, File location) { 28 | this.plugin = plugin; 29 | this.location = location; 30 | } 31 | 32 | /** 33 | * Log to file. 34 | * 35 | * @param message the message 36 | */ 37 | public void logToFile(String message) { 38 | try { 39 | if (!location.getParentFile().exists()) { 40 | location.getParentFile().mkdirs(); 41 | } 42 | 43 | File saveTo = location; 44 | if (!saveTo.exists()) { 45 | saveTo.createNewFile(); 46 | } 47 | 48 | FileWriter fw = new FileWriter(saveTo, true); 49 | 50 | PrintWriter pw = new PrintWriter(fw); 51 | 52 | pw.println(message); 53 | 54 | pw.flush(); 55 | 56 | pw.close(); 57 | 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/java/com/bencodez/advancedcore/thread/Thread.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.thread; 2 | 3 | import java.util.Arrays; 4 | 5 | import com.bencodez.advancedcore.AdvancedCorePlugin; 6 | import com.bencodez.simpleapi.player.NameFetcher; 7 | 8 | /** 9 | * The Class Thread. 10 | */ 11 | @Deprecated 12 | public class Thread { 13 | 14 | /** 15 | * The Class ReadThread. 16 | */ 17 | public class ReadThread extends java.lang.Thread { 18 | 19 | public String getName(java.util.UUID uuid) { 20 | plugin.debug("Looking up player name: " + uuid); 21 | NameFetcher fet = new NameFetcher(Arrays.asList(uuid)); 22 | try { 23 | return fet.call().get(uuid); 24 | } catch (Exception e) { 25 | // AdvancedCorePlugin.getInstance().debug(e); 26 | return ""; 27 | } 28 | } 29 | 30 | @Override 31 | public void run() { 32 | while (!thread.isInterrupted()) { 33 | try { 34 | sleep(50); 35 | } catch (InterruptedException e) { 36 | e.printStackTrace(); 37 | System.exit(0); 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * Run. 44 | * 45 | * @param run the run 46 | */ 47 | public void run(Runnable run) { 48 | synchronized (Thread.getInstance()) { 49 | run.run(); 50 | } 51 | } 52 | } 53 | 54 | /** The instance. */ 55 | static Thread instance = new Thread(); 56 | 57 | /** 58 | * Gets the single instance of Thread. 59 | * 60 | * @return single instance of Thread 61 | */ 62 | public static Thread getInstance() { 63 | return instance; 64 | } 65 | 66 | /** The plugin. */ 67 | AdvancedCorePlugin plugin = AdvancedCorePlugin.getInstance(); 68 | 69 | /** The thread. */ 70 | private ReadThread thread; 71 | 72 | /** 73 | * Instantiates a new thread. 74 | */ 75 | private Thread() { 76 | } 77 | 78 | /** 79 | * @return the thread 80 | */ 81 | public ReadThread getThread() { 82 | if (thread == null || !thread.isAlive()) { 83 | loadThread(); 84 | } 85 | return thread; 86 | } 87 | 88 | /** 89 | * Load thread. 90 | */ 91 | public void loadThread() { 92 | thread = new ReadThread(); 93 | thread.start(); 94 | } 95 | 96 | /** 97 | * Run. 98 | * 99 | * @param run the run 100 | */ 101 | public void run(Runnable run) { 102 | getThread().run(run); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /AdvancedCore/src/main/resources/advancedcoreversion.yml: -------------------------------------------------------------------------------- 1 | version: '${project.version}' 2 | time: '${timestamp}' 3 | buildnumber: '${build.number}' -------------------------------------------------------------------------------- /AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/AdvancedCoreUserTest.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.tests; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | import static org.mockito.Mockito.mock; 5 | import static org.mockito.Mockito.verify; 6 | import static org.mockito.Mockito.when; 7 | 8 | import java.util.ArrayList; 9 | import java.util.UUID; 10 | 11 | import org.junit.jupiter.api.BeforeEach; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import com.bencodez.advancedcore.AdvancedCoreConfigOptions; 15 | import com.bencodez.advancedcore.AdvancedCorePlugin; 16 | import com.bencodez.advancedcore.api.user.AdvancedCoreUser; 17 | import com.bencodez.advancedcore.api.user.UserData; 18 | import com.bencodez.advancedcore.api.user.UserManager; 19 | import com.bencodez.advancedcore.api.user.UserStorage; 20 | import com.bencodez.advancedcore.api.user.usercache.UserDataManager; 21 | import com.bencodez.advancedcore.api.user.userstorage.mysql.MySQL; 22 | 23 | public class AdvancedCoreUserTest { 24 | private AdvancedCorePlugin plugin; 25 | private UserManager userManager; 26 | private UserDataManager dataManager; 27 | private UserData data; 28 | private AdvancedCoreUser user; 29 | 30 | @BeforeEach 31 | public void setUp() { 32 | plugin = mock(AdvancedCorePlugin.class); 33 | userManager = mock(UserManager.class); 34 | dataManager = mock(UserDataManager.class); 35 | data = mock(UserData.class); 36 | MySQL mysql = mock(MySQL.class); 37 | 38 | AdvancedCoreConfigOptions configOptions = mock(AdvancedCoreConfigOptions.class); 39 | when(plugin.getOptions()).thenReturn(configOptions); 40 | when(configOptions.isOnlineMode()).thenReturn(true); // Stub the required method 41 | when(plugin.getMysql()).thenReturn(mysql); 42 | when(userManager.getDataManager()).thenReturn(dataManager); 43 | when(plugin.getUserManager()).thenReturn(userManager); 44 | when(plugin.getStorageType()).thenReturn(UserStorage.MYSQL); 45 | when(userManager.getOfflineRewardsPath()).thenReturn("offlineRewardsPath"); 46 | 47 | user = new AdvancedCoreUser(plugin, UUID.randomUUID(),"Test"); 48 | user.setData(data); // Inject the mocked UserData object 49 | } 50 | 51 | @Test 52 | void setOfflineRewards_emptyList() { 53 | ArrayList rewards = new ArrayList<>(); 54 | user.setOfflineRewards(rewards); 55 | verify(data).setStringList("offlineRewardsPath", rewards); 56 | } 57 | 58 | @Test 59 | void setOfflineRewards_exceedsLimit() { 60 | ArrayList rewards = new ArrayList<>(); 61 | for (int i = 0; i < 5000; i++) { 62 | rewards.add("reward123456789a123456789a" + i); 63 | } 64 | int initialSize = rewards.size(); 65 | user.setOfflineRewards(rewards); 66 | 67 | // Verify the method call 68 | verify(data).setStringList("offlineRewardsPath", rewards); 69 | 70 | // Ensure the data is within limits 71 | String result = String.join("%line%", rewards); 72 | int maxLength = 65535; 73 | assertTrue(result.getBytes().length <= maxLength, "The resulting string exceeds the maximum length"); 74 | 75 | // Verify that not everything got deleted 76 | assertTrue(rewards.size() > 0, "All rewards were deleted"); 77 | assertTrue(rewards.size() < initialSize, "No rewards were deleted"); 78 | } 79 | 80 | @Test 81 | void setOfflineRewards_singleLargeReward() { 82 | ArrayList rewards = new ArrayList<>(); 83 | rewards.add("largeReward"); 84 | user.setOfflineRewards(rewards); 85 | verify(data).setStringList("offlineRewardsPath", rewards); 86 | } 87 | 88 | @Test 89 | void setOfflineRewards_withinLimit() { 90 | ArrayList rewards = new ArrayList<>(); 91 | rewards.add("reward1"); 92 | rewards.add("reward2"); 93 | user.setOfflineRewards(rewards); 94 | verify(data).setStringList("offlineRewardsPath", rewards); 95 | } 96 | } -------------------------------------------------------------------------------- /AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/BackupHandleTest.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.tests; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertFalse; 4 | import static org.junit.jupiter.api.Assertions.assertTrue; 5 | import static org.mockito.ArgumentMatchers.anyLong; 6 | import static org.mockito.Mockito.mock; 7 | import static org.mockito.Mockito.when; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.nio.file.Path; 13 | import java.nio.file.attribute.FileTime; 14 | import java.time.LocalDateTime; 15 | import java.time.ZoneId; 16 | 17 | import org.junit.jupiter.api.AfterAll; 18 | import org.junit.jupiter.api.Test; 19 | import org.junit.jupiter.api.TestInstance; 20 | import org.junit.jupiter.api.TestInstance.Lifecycle; 21 | import org.mockito.MockedStatic; 22 | import org.mockito.Mockito; 23 | 24 | import com.bencodez.advancedcore.api.backup.BackupHandle; 25 | import com.bencodez.advancedcore.api.misc.MiscUtils; 26 | 27 | @TestInstance(Lifecycle.PER_CLASS) 28 | public class BackupHandleTest { 29 | 30 | private Path tempDir; 31 | private BackupHandle backupHandle; 32 | private MiscUtils mockMiscUtils; 33 | private MockedStatic backupHandleMockedStatic; 34 | private MockedStatic miscUtilsMockedStatic; 35 | private BaseTest baseTest; 36 | 37 | @AfterAll 38 | public void tearDown() throws IOException { 39 | if (backupHandleMockedStatic != null && !backupHandleMockedStatic.isClosed()) { 40 | backupHandleMockedStatic.close(); 41 | backupHandleMockedStatic = null; 42 | } 43 | if (miscUtilsMockedStatic != null && !miscUtilsMockedStatic.isClosed()) { 44 | miscUtilsMockedStatic.close(); 45 | miscUtilsMockedStatic = null; 46 | } 47 | 48 | // Delete the temporary directory and its contents 49 | if (tempDir != null) { 50 | Files.walk(tempDir).map(Path::toFile).forEach(File::delete); 51 | } 52 | } 53 | 54 | @Test 55 | public void testCheckOldBackups() throws IOException { 56 | baseTest = BaseTest.getInstance(); 57 | 58 | // Create a temporary directory 59 | tempDir = Files.createTempDirectory("testBackups"); 60 | 61 | // Mock the MiscUtils instance 62 | mockMiscUtils = mock(MiscUtils.class); 63 | when(mockMiscUtils.getTime(anyLong())).thenAnswer(invocation -> { 64 | long millis = invocation.getArgument(0); 65 | return LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(millis), ZoneId.systemDefault()); 66 | }); 67 | 68 | // Mock the BackupHandle instance 69 | backupHandleMockedStatic = Mockito.mockStatic(BackupHandle.class); 70 | miscUtilsMockedStatic = Mockito.mockStatic(MiscUtils.class); 71 | backupHandleMockedStatic.when(BackupHandle::getInstance).thenReturn(mock(BackupHandle.class)); 72 | miscUtilsMockedStatic.when(MiscUtils::getInstance).thenReturn(mockMiscUtils); 73 | 74 | // Mock the dataFolder location 75 | File dataFolder = new File(tempDir.toFile(), "dataFolder"); 76 | dataFolder.mkdir(); 77 | when(baseTest.plugin.getDataFolder()).thenReturn(dataFolder); 78 | 79 | // Create a backup directory in the mocked dataFolder 80 | File backupDir = new File(dataFolder, "Backups"); 81 | backupDir.mkdir(); 82 | 83 | // Create a file older than 5 days 84 | File oldBackup = new File(backupDir, "oldBackup.zip"); 85 | oldBackup.createNewFile(); 86 | LocalDateTime oldTime = LocalDateTime.now().minusDays(6); 87 | Files.setLastModifiedTime(oldBackup.toPath(), 88 | FileTime.fromMillis(oldTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); 89 | 90 | // Create a file newer than 5 days 91 | File newBackup = new File(backupDir, "newBackup.zip"); 92 | newBackup.createNewFile(); 93 | LocalDateTime newTime = LocalDateTime.now().minusDays(3); 94 | Files.setLastModifiedTime(newBackup.toPath(), 95 | FileTime.fromMillis(newTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); 96 | 97 | // Ensure the backupHandle is not a mock and call the actual method 98 | backupHandleMockedStatic.close(); 99 | backupHandle = BackupHandle.getInstance(); 100 | backupHandle.checkOldBackups(); 101 | 102 | // Verify that the old backup was deleted and the new one was not 103 | assertFalse(oldBackup.exists(), "Old backup should be deleted"); 104 | assertTrue(newBackup.exists(), "New backup should not be deleted"); 105 | } 106 | } -------------------------------------------------------------------------------- /AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.tests; 2 | 3 | import static org.mockito.Mockito.mock; 4 | import static org.mockito.Mockito.mockStatic; 5 | import static org.mockito.Mockito.when; 6 | 7 | import java.util.logging.Logger; 8 | 9 | import org.junit.jupiter.api.AfterAll; 10 | import org.mockito.MockedStatic; 11 | 12 | import com.bencodez.advancedcore.AdvancedCoreConfigOptions; 13 | import com.bencodez.advancedcore.AdvancedCorePlugin; 14 | import com.bencodez.advancedcore.data.ServerData; 15 | 16 | public class BaseTest { 17 | private static BaseTest instance; 18 | private MockedStatic advancedCorePluginMockedStatic; 19 | 20 | public AdvancedCorePlugin plugin; 21 | public AdvancedCoreConfigOptions options; 22 | public ServerData serverDataFile; 23 | public Logger logger; 24 | 25 | private BaseTest() { 26 | plugin = mock(AdvancedCorePlugin.class); 27 | options = mock(AdvancedCoreConfigOptions.class); 28 | serverDataFile = mock(ServerData.class); 29 | logger = mock(Logger.class); 30 | 31 | advancedCorePluginMockedStatic = mockStatic(AdvancedCorePlugin.class); 32 | advancedCorePluginMockedStatic.when(AdvancedCorePlugin::getInstance).thenReturn(plugin); 33 | when(plugin.getOptions()).thenReturn(options); 34 | when(plugin.getServerDataFile()).thenReturn(serverDataFile); 35 | when(plugin.getLogger()).thenReturn(logger); 36 | } 37 | 38 | public static BaseTest getInstance() { 39 | if (instance == null) { 40 | instance = new BaseTest(); 41 | } 42 | return instance; 43 | } 44 | 45 | @AfterAll 46 | public void close() { 47 | if (advancedCorePluginMockedStatic != null) { 48 | advancedCorePluginMockedStatic.close(); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/TimeCheckerTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenCodez/AdvancedCore/eaaa15eb779ae7f63884572e8ef8a2a6991124d9/AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/TimeCheckerTest.java -------------------------------------------------------------------------------- /AdvancedCore/src/test/java/com/bencodez/advancedcore/tests/ZipCreatorTest.java: -------------------------------------------------------------------------------- 1 | package com.bencodez.advancedcore.tests; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | import static org.mockito.Mockito.mock; 5 | import static org.mockito.Mockito.when; 6 | 7 | import java.io.File; 8 | import java.io.IOException; 9 | import java.nio.file.Files; 10 | import java.util.List; 11 | 12 | import org.junit.jupiter.api.AfterEach; 13 | import org.junit.jupiter.api.BeforeEach; 14 | import org.junit.jupiter.api.Test; 15 | 16 | import com.bencodez.advancedcore.AdvancedCorePlugin; 17 | import com.bencodez.advancedcore.api.backup.ZipCreator; 18 | 19 | public class ZipCreatorTest { 20 | 21 | private ZipCreator zipCreator; 22 | private AdvancedCorePlugin mockPlugin; 23 | private File tempDir; 24 | private File tempFile; 25 | 26 | @BeforeEach 27 | public void setUp() throws IOException { 28 | // Mock the plugin instance 29 | mockPlugin = mock(AdvancedCorePlugin.class); 30 | when(mockPlugin.getDataFolder()).thenReturn(new File("target/mockDataFolder")); 31 | when(mockPlugin.getName()).thenReturn("AdvancedCore"); 32 | 33 | // Mock the logger 34 | java.util.logging.Logger mockLogger = mock(java.util.logging.Logger.class); 35 | when(mockPlugin.getLogger()).thenReturn(mockLogger); 36 | 37 | // Set the plugin instance in ZipCreator 38 | zipCreator = ZipCreator.getInstance(); 39 | zipCreator.plugin = mockPlugin; 40 | 41 | // Create a temporary directory and file for testing within the target folder 42 | tempDir = new File("target/testDir"); 43 | tempDir.mkdirs(); 44 | tempFile = new File(tempDir, "testFile.txt"); 45 | Files.write(tempFile.toPath(), "Sample content".getBytes()); 46 | } 47 | 48 | @AfterEach 49 | public void tearDown() { 50 | // Clean up temporary files and directories 51 | tempFile.delete(); 52 | tempDir.delete(); 53 | } 54 | 55 | @Test 56 | public void testAddAllFiles() { 57 | List fileList = new java.util.ArrayList<>(); 58 | zipCreator.addAllFiles(tempDir, fileList); 59 | assertTrue(fileList.contains(tempFile), "File list should contain the test file"); 60 | } 61 | 62 | @Test 63 | public void testCreate() throws IOException { 64 | File zipFile = new File(tempDir, "testArchive.zip"); 65 | zipCreator.create(tempDir, zipFile); 66 | assertTrue(zipFile.exists(), "Zip file should be created"); 67 | assertTrue(zipFile.length() > 0, "Zip file should not be empty"); 68 | } 69 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AdvancedCore 2 | API used in the plugins developed by BenCodez, can be used in any project. 3 | 4 | [Download](https://www.spigotmc.org/resources/advancedcore.28295/) 5 | 6 | ## License 7 | ### This project is licensed under the Creative Commons Attribution 3.0 Unported license. 8 | [Read it here](https://creativecommons.org/licenses/by/3.0/) 9 | 10 | ## How to use 11 | ### Use the following code in Maven: 12 | 13 | BenCodez Repo 14 | https://nexus.bencodez.com/repository/maven-public/ 15 | 16 | 17 | 18 | com.bencodez 19 | advancedcore 20 | LATEST 21 | provided 22 | 23 | 24 | ### In Gradle: 25 | repositories { 26 | maven { url "https://nexus.bencodez.com/repository/maven-public/" } 27 | } 28 | dependencies { 29 | compile "com.bencodez:advancedcore:LATEST" 30 | } 31 | 32 | Versions: 33 | LATEST - latest stable release 34 | Check out all tags [on the releases tab](https://github.com/BenCodez/AdvancedCore/tags). 35 | --------------------------------------------------------------------------------