├── src ├── config.yml ├── me │ └── mrCookieSlime │ │ ├── CSCoreLibPlugin │ │ ├── java │ │ │ ├── EncodingType.java │ │ │ ├── Characters.java │ │ │ └── Converter.java │ │ ├── general │ │ │ ├── Particles │ │ │ │ ├── MC_1_13 │ │ │ │ │ ├── Axis.java │ │ │ │ │ ├── ParticleType.java │ │ │ │ │ └── ParticleEffect.java │ │ │ │ └── FireworkShow.java │ │ │ ├── Reflection │ │ │ │ ├── CraftObject.java │ │ │ │ ├── PackageName.java │ │ │ │ └── ReflectionUtils.java │ │ │ ├── Player │ │ │ │ ├── Players.java │ │ │ │ ├── PlayerManager.java │ │ │ │ ├── PlayerStats.java │ │ │ │ └── PlayerInventory.java │ │ │ ├── World │ │ │ │ ├── MenuSounds.java │ │ │ │ ├── ActionBarBuilder.java │ │ │ │ ├── TabMessage.java │ │ │ │ ├── ArmorStandFactory.java │ │ │ │ └── CustomSkull.java │ │ │ ├── Inventory │ │ │ │ ├── Item │ │ │ │ │ ├── ItemFlagComparator.java │ │ │ │ │ ├── CustomArmor.java │ │ │ │ │ ├── CustomBanner.java │ │ │ │ │ ├── MenuItem.java │ │ │ │ │ ├── CustomPotion.java │ │ │ │ │ ├── SkullItem.java │ │ │ │ │ ├── CustomItemSerializer.java │ │ │ │ │ └── CustomItem.java │ │ │ │ ├── ClickAction.java │ │ │ │ ├── Maps.java │ │ │ │ ├── InvUtils.java │ │ │ │ ├── MenuHelper.java │ │ │ │ ├── CustomBookOverlay.java │ │ │ │ ├── Menu.java │ │ │ │ └── ChestMenu.java │ │ │ ├── String │ │ │ │ ├── Christmas.java │ │ │ │ └── StringUtils.java │ │ │ ├── Chat │ │ │ │ ├── Colors.java │ │ │ │ ├── TellRawString.java │ │ │ │ ├── CommandHelp.java │ │ │ │ └── TellRawMessage.java │ │ │ ├── Math │ │ │ │ ├── Calculator.java │ │ │ │ └── DoubleHandler.java │ │ │ ├── Block │ │ │ │ ├── TreeCalculator.java │ │ │ │ └── Vein.java │ │ │ ├── Recipe │ │ │ │ ├── RecipeManager.java │ │ │ │ └── RecipeCalculator.java │ │ │ └── ListUtils.java │ │ ├── compatibility │ │ │ ├── MaterialHook.java │ │ │ └── MaterialHelper.java │ │ ├── events │ │ │ ├── Listeners │ │ │ │ ├── CustomBookOverlayListener.java │ │ │ │ ├── ItemUseListener.java │ │ │ │ ├── MapListener.java │ │ │ │ ├── StatisticListener.java │ │ │ │ └── MenuClickListener.java │ │ │ ├── ItemUseEvent.java │ │ │ └── MenuClickEvent.java │ │ ├── Configuration │ │ │ ├── Variable.java │ │ │ ├── Localization.java │ │ │ └── Config.java │ │ ├── PlayerRunnable.java │ │ ├── protection │ │ │ └── ProtectionManager.java │ │ ├── PluginUtils.java │ │ ├── CSCoreLib.java │ │ └── updater │ │ │ └── Updater.java │ │ └── CSCoreLibSetup │ │ ├── CSCoreLibExample.java │ │ └── CSCoreLibLoader.java ├── plugin.yml └── Classes to edit when a new Minecraft Version comes out.md ├── renovate.json ├── lib ├── Factions.jar └── MassiveCore.jar ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ └── bug-report.md ├── README.md └── pom.xml /src/config.yml: -------------------------------------------------------------------------------- 1 | options: 2 | auto-update: true -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /lib/Factions.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBusyBiscuit/CS-CoreLib/HEAD/lib/Factions.jar -------------------------------------------------------------------------------- /lib/MassiveCore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBusyBiscuit/CS-CoreLib/HEAD/lib/MassiveCore.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /.settings/ 3 | .classpath 4 | .project 5 | .idea 6 | /target 7 | *.iml 8 | dependency-reduced-pom.xml -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/java/EncodingType.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.java; 2 | 3 | @Deprecated 4 | public enum EncodingType { 5 | 6 | BASE64, 7 | BINARY; 8 | } 9 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Particles/MC_1_13/Axis.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Particles.MC_1_13; 2 | 3 | @Deprecated 4 | public enum Axis { 5 | 6 | X, 7 | Y, 8 | Z; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Particles/MC_1_13/ParticleType.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Particles.MC_1_13; 2 | 3 | @Deprecated 4 | public enum ParticleType { 5 | 6 | NORMAL, 7 | CRACK, 8 | COLORED; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Reflection/CraftObject.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Reflection; 2 | 3 | @Deprecated 4 | public enum CraftObject { 5 | 6 | PLAYER, 7 | WORLD, 8 | ENTITY, 9 | ANIMALS; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Player/Players.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Player; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | @Deprecated 6 | public class Players { 7 | 8 | public static boolean isOnline(String name) { 9 | return Bukkit.getPlayer(name) != null; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: CS-CoreLib 2 | version: ${project.version} 3 | author: A lot of awesome people 4 | website: http://thebusybiscuit.github.io/ 5 | 6 | main: me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib 7 | 8 | api-version: 1.13 9 | 10 | commands: 11 | cs_triggerinterface: 12 | description: Background Command 13 | usage: Dont use it 14 | -------------------------------------------------------------------------------- /src/Classes to edit when a new Minecraft Version comes out.md: -------------------------------------------------------------------------------- 1 | * me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay 2 | * me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage 3 | * me.mrCookieSlime.CSCoreLibPlugin.general.World.Animals 4 | * me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils 5 | 6 | Add more as you add version-dependent Features -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Reflection/PackageName.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Reflection; 2 | 3 | @Deprecated 4 | public enum PackageName { 5 | 6 | NMS("net.minecraft.server."), 7 | OBC("org.bukkit.craftbukkit."); 8 | 9 | private String path; 10 | 11 | private PackageName(String path) { 12 | this.path = path; 13 | } 14 | 15 | public String toPackage() { 16 | return path; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/World/MenuSounds.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.World; 2 | 3 | import org.bukkit.Sound; 4 | 5 | @Deprecated 6 | public class MenuSounds { 7 | 8 | Sound open, close; 9 | 10 | public MenuSounds(Sound open, Sound close) { 11 | this.open = open; 12 | this.close = close; 13 | } 14 | 15 | public Sound getOpeningSound() { 16 | return open; 17 | } 18 | 19 | public Sound getClosingSound() { 20 | return close; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/ItemFlagComparator.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import java.util.Comparator; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItemSerializer.ItemFlag; 6 | 7 | @Deprecated 8 | public class ItemFlagComparator implements Comparator { 9 | 10 | @Override 11 | public int compare(ItemFlag flag1, ItemFlag flag2) { 12 | return flag1.getWeight() - flag2.getWeight(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ClickAction.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | public class ClickAction { 4 | 5 | private boolean right; 6 | private boolean shift; 7 | 8 | public ClickAction(boolean rightClicked, boolean shiftClicked) { 9 | this.right = rightClicked; 10 | this.shift = shiftClicked; 11 | } 12 | 13 | public boolean isRightClicked() { 14 | return right; 15 | } 16 | 17 | public boolean isShiftClicked() { 18 | return shift; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/compatibility/MaterialHook.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.compatibility; 2 | 3 | import org.bukkit.Material; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 6 | 7 | @Deprecated 8 | public class MaterialHook { 9 | 10 | public static Material parse(String name, String legacy) { 11 | if (ReflectionUtils.isVersion("v1_12_", "v1_11_", "v1_10_", "v1_9_")) { 12 | return Material.valueOf(legacy); 13 | } 14 | else { 15 | return Material.valueOf(name); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/String/Christmas.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.String; 2 | 3 | import org.bukkit.ChatColor; 4 | 5 | @Deprecated 6 | public final class Christmas { 7 | 8 | private Christmas() {} 9 | 10 | public static String color(String string) { 11 | StringBuilder xmas = new StringBuilder(""); 12 | for (int i = 0; i < string.length(); i++) { 13 | xmas.append((i % 2 == 0 ? "&a": "&c")); 14 | xmas.append(string.charAt(i)); 15 | } 16 | return ChatColor.translateAlternateColorCodes('&', xmas.toString()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/CustomArmor.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import org.bukkit.Color; 4 | import org.bukkit.inventory.ItemStack; 5 | import org.bukkit.inventory.meta.ItemMeta; 6 | import org.bukkit.inventory.meta.LeatherArmorMeta; 7 | 8 | @Deprecated 9 | public class CustomArmor extends ItemStack { 10 | 11 | public CustomArmor(ItemStack item, Color color) { 12 | super(item.clone()); 13 | ItemMeta im = getItemMeta(); 14 | ((LeatherArmorMeta) im).setColor(color); 15 | setItemMeta(im); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/Listeners/CustomBookOverlayListener.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events.Listeners; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay; 4 | 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerSwapHandItemsEvent; 8 | 9 | @Deprecated 10 | public class CustomBookOverlayListener implements Listener { 11 | 12 | @EventHandler 13 | public void onDrop(PlayerSwapHandItemsEvent e) { 14 | if (CustomBookOverlay.opening.contains(e.getPlayer().getUniqueId())) e.setCancelled(true); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Maps.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.UUID; 6 | 7 | import me.mrCookieSlime.CSCoreLibPlugin.general.World.MenuSounds; 8 | 9 | @Deprecated 10 | public class Maps { 11 | 12 | public Map inv; 13 | public Map menus; 14 | public Map sounds; 15 | 16 | public static Maps instance; 17 | 18 | public Maps() { 19 | inv = new HashMap<>(); 20 | sounds = new HashMap<>(); 21 | menus = new HashMap<>(); 22 | instance = this; 23 | } 24 | 25 | public static Maps getInstance() { 26 | return instance; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Chat/Colors.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Chat; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 4 | 5 | import org.bukkit.ChatColor; 6 | 7 | @Deprecated 8 | public enum Colors { 9 | 10 | YELLOW(ChatColor.YELLOW), 11 | GREEN(ChatColor.GREEN), 12 | GOLD(ChatColor.GOLD), 13 | AQUA(ChatColor.AQUA), 14 | DARK_AQUA(ChatColor.DARK_AQUA), 15 | DARK_BLUE(ChatColor.DARK_BLUE); 16 | 17 | ChatColor color; 18 | 19 | Colors(ChatColor color) { 20 | this.color = color; 21 | } 22 | 23 | public static ChatColor getRandom() { 24 | return values()[CSCoreLib.randomizer().nextInt(values().length)].toChatColor(); 25 | } 26 | 27 | public ChatColor toChatColor() { 28 | return color; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Chat/TellRawString.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Chat; 2 | 3 | @Deprecated 4 | public class TellRawString extends TellRawMessage { 5 | 6 | private String json; 7 | 8 | /** 9 | * Creates a new Instance based on the 10 | * specified JSON String 11 | * 12 | * @param json The JSON Message you want to send 13 | */ 14 | public TellRawString(String json) { 15 | this.json = json; 16 | } 17 | 18 | /** 19 | * Overridden Method to ensure it uses 20 | * the previously defined JSON String 21 | * instead of building a new One 22 | * 23 | * @return The previously defined JSON String 24 | */ 25 | @Override 26 | public String build() { 27 | return this.json; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/CustomBanner.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import org.bukkit.DyeColor; 4 | import org.bukkit.block.banner.Pattern; 5 | import org.bukkit.inventory.ItemStack; 6 | import org.bukkit.inventory.meta.BannerMeta; 7 | 8 | import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHook; 9 | 10 | @Deprecated 11 | public class CustomBanner extends ItemStack { 12 | 13 | public CustomBanner(DyeColor color, Pattern... patterns) { 14 | super(MaterialHook.parse("WHITE_BANNER", "BANNER")); 15 | 16 | BannerMeta meta = (BannerMeta) getItemMeta(); 17 | 18 | meta.setBaseColor(color); 19 | 20 | for (Pattern pattern: patterns) { 21 | meta.addPattern(pattern); 22 | } 23 | 24 | setItemMeta(meta); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Variable.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.Configuration; 2 | 3 | @Deprecated 4 | public class Variable { 5 | 6 | protected String placeholder; 7 | private String string; 8 | 9 | /** 10 | * Creates a new Variable Object with the specified Placeholder and string 11 | * 12 | * @param placeholder The String which will get replaced by the Variable 13 | * @param string The String which will replace the placeholder 14 | */ 15 | public Variable(String placeholder, String string) { 16 | this.placeholder = placeholder; 17 | this.string = string; 18 | } 19 | 20 | /** 21 | * Returns the specified String with this Variable appplied to it 22 | * 23 | * @param string The String which this Variable will be applied to 24 | * @return The applied String 25 | */ 26 | public String apply(String string) { 27 | return string.replace(this.placeholder, this.string); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Math/Calculator.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Math; 2 | 3 | import org.bukkit.Location; 4 | 5 | @Deprecated 6 | public final class Calculator { 7 | 8 | private Calculator() {} 9 | 10 | public static int formToLine(int i) { 11 | int lines = 1; 12 | 13 | if (i > 9) lines++; 14 | if (i > 9*2) lines++; 15 | if (i > 9*3) lines++; 16 | if (i > 9*4) lines++; 17 | if (i > 9*5) lines++; 18 | if (i > 9*6) lines++; 19 | 20 | return lines; 21 | } 22 | 23 | public static Location centerPosition(Location l ) { 24 | 25 | double x = l.getX(); 26 | double z = l.getZ(); 27 | 28 | String[] rawX = String.valueOf(x).split("."); 29 | String[] rawZ = String.valueOf(z).split("."); 30 | 31 | String newX = rawX[0] + ".5"; 32 | String newZ = rawZ[0] + ".5"; 33 | 34 | l.setX(Double.parseDouble(newX)); 35 | l.setZ(Double.parseDouble(newZ)); 36 | 37 | return l; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/java/Characters.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.java; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 4 | 5 | @Deprecated 6 | public class Characters { 7 | 8 | private static final char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); 9 | 10 | /** 11 | * Returns a random Character 12 | * 13 | * @return A Random Character 14 | */ 15 | public static char getRandomCharacter() { 16 | return chars[CSCoreLib.randomizer().nextInt(chars.length)]; 17 | } 18 | 19 | /** 20 | * Generates a random String 21 | * 22 | * @param length The Length of your desired String 23 | * @return A randomly generated String 24 | */ 25 | public static String getRandomString(int length) { 26 | StringBuilder builder = new StringBuilder(); 27 | for (int i = 0; i < length; i++) { 28 | builder.append(getRandomCharacter()); 29 | } 30 | return builder.toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a Bug or an Issue with CS-CoreLib 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Description (Required) 11 | 12 | 13 | ## Steps to reproduce the Issue (Required) 14 | 15 | 16 | ## Expected behavior (Required) 17 | 18 | 19 | ## Server Log / Error Report 20 | 21 | 22 | 23 | ## Environment (Required) 24 | 25 | 26 | 27 | - Minecraft Version: 28 | - CS-CoreLib Version: 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CS-CoreLib 2 | CS-CoreLib is a very old library for some of my older plugins.
3 | It isn't updated anymore but still required for running [Slimefun4](https://github.com/Slimefun/Slimefun4) as of now. 4 | 5 | ## New version 6 | **You were probably looking for this:** 7 | https://github.com/TheBusyBiscuit/CS-CoreLib2 8 | 9 | ## Development Builds 10 | Click on the badge below to go to our "development" build page, where you can download the latest versions before they are released to the public. 11 | But keep in mind: These builds are still in development and not guaranteed to work or to be stable. 12 | 13 |

14 | 15 | Build Server 16 | 17 |

18 | 19 | ## License 20 | This project is licensed under 21 | [GNU GPLv3](https://github.com/TheBusyBiscuit/CS-CoreLib/blob/master/LICENSE) 22 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Block/TreeCalculator.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Block; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.block.BlockFace; 8 | 9 | @Deprecated 10 | public class TreeCalculator { 11 | 12 | private static final BlockFace[] faces = new BlockFace[] {BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST}; 13 | 14 | public static void getTree(Location origin, Location anchor, List list) { 15 | int max = 200; 16 | if (list.size() > max) return; 17 | 18 | for (BlockFace face: faces) { 19 | Block next = anchor.getBlock().getRelative(face); 20 | if (next.getType() == anchor.getBlock().getType() && !list.contains(next.getLocation())) { 21 | list.add(next.getLocation()); 22 | getTree(origin, next.getLocation(), list); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Player/PlayerManager.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Player; 2 | 3 | import org.bukkit.GameMode; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.potion.PotionEffect; 6 | 7 | @Deprecated 8 | public class PlayerManager { 9 | 10 | public static void reset(Player p) { 11 | p.setGameMode(GameMode.SURVIVAL); 12 | p.setHealth(20); 13 | p.setFoodLevel(20); 14 | 15 | clearEffects(p); 16 | p.setExp(0); 17 | p.setLevel(0); 18 | 19 | p.getInventory().clear(); 20 | p.getInventory().setArmorContents(null); 21 | 22 | PlayerInventory.update(p); 23 | } 24 | 25 | public static void clearEffects(Player p) { 26 | for (PotionEffect e : p.getActivePotionEffects()) { 27 | p.removePotionEffect(e.getType()); 28 | } 29 | } 30 | 31 | public static void loseHunger(Player p, int amount) { 32 | if (p.getGameMode() != GameMode.CREATIVE) { 33 | int starve = p.getFoodLevel() - amount; 34 | if (starve < 0) starve = 0; 35 | p.setFoodLevel(starve); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/Listeners/ItemUseListener.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events.Listeners; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.Action; 9 | import org.bukkit.event.player.PlayerInteractEvent; 10 | import org.bukkit.plugin.Plugin; 11 | 12 | @Deprecated 13 | public class ItemUseListener implements Listener { 14 | 15 | public ItemUseListener(Plugin plugin) { 16 | plugin.getServer().getPluginManager().registerEvents(this, plugin); 17 | } 18 | 19 | @EventHandler 20 | public void onRightClick(PlayerInteractEvent e) throws Exception { 21 | if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { 22 | ItemUseEvent event = new ItemUseEvent(e, e.getAction() == Action.RIGHT_CLICK_BLOCK ? e.getClickedBlock(): null); 23 | Bukkit.getPluginManager().callEvent(event); 24 | if (!e.isCancelled()) e.setCancelled(event.isCancelled()); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Block/Vein.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Block; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.block.BlockFace; 8 | 9 | @Deprecated 10 | public class Vein { 11 | 12 | private static final BlockFace[] faces = new BlockFace[] {BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST}; 13 | 14 | public static void calculate(Location origin, Location anchor, List list, int max) { 15 | if (list.size() > max) return; 16 | 17 | for (BlockFace face: faces) { 18 | Block next = anchor.getBlock().getRelative(face); 19 | if ((next.getType() == anchor.getBlock().getType() || (next.getType().toString().endsWith("REDSTONE_ORE") && anchor.getBlock().getType().toString().endsWith("REDSTONE_ORE"))) && !list.contains(next.getLocation())) { 20 | list.add(next.getLocation()); 21 | calculate(origin, next.getLocation(), list, max); 22 | } 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Chat/CommandHelp.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Chat; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.plugin.Plugin; 8 | 9 | @Deprecated 10 | public class CommandHelp { 11 | 12 | @Deprecated 13 | public static void sendCommandHelp(CommandSender p, Plugin plugin, List commands, List descriptions) { 14 | ChatColor label = Colors.getRandom(); 15 | ChatColor info = Colors.getRandom(); 16 | 17 | String authors = ""; 18 | for (int i = 0; i < plugin.getDescription().getAuthors().size(); i++) { 19 | if (i > 0) authors = authors + ", " + plugin.getDescription().getAuthors().get(i); 20 | else authors = plugin.getDescription().getAuthors().get(i); 21 | } 22 | 23 | p.sendMessage(""); 24 | p.sendMessage(label + plugin.getDescription().getName() + " v" + plugin.getDescription().getVersion() + " by " + authors); 25 | p.sendMessage(""); 26 | for (int i = 0; i < commands.size(); i++) { 27 | p.sendMessage(label + commands.get(i) + " " + info + descriptions.get(i)); 28 | } 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/java/Converter.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.java; 2 | 3 | import java.util.Base64; 4 | 5 | @Deprecated 6 | public class Converter { 7 | 8 | public static String encode(EncodingType type, String string) { 9 | switch (type) { 10 | case BASE64: { 11 | return Base64.getEncoder().encodeToString(string.getBytes()); 12 | } 13 | case BINARY: { 14 | StringBuilder binary = new StringBuilder(); 15 | for (byte b: string.getBytes()) { 16 | int value = b; 17 | for (int i = 0; i < 8; i++) { 18 | binary.append((value & 128) == 0 ? 0: 1); 19 | value <<= 1; 20 | } 21 | binary.append(" "); 22 | } 23 | return binary.toString(); 24 | } 25 | default: 26 | return ""; 27 | } 28 | } 29 | 30 | public static String decode(EncodingType type, String string) { 31 | switch (type) { 32 | case BASE64: { 33 | return new String(Base64.getDecoder().decode(string)); 34 | } 35 | case BINARY: { 36 | StringBuilder text = new StringBuilder(); 37 | for (String segment: string.split(" ")) { 38 | text.append(new Character((char) Integer.parseInt(segment, 2)).toString()); 39 | } 40 | return text.toString(); 41 | } 42 | default: 43 | return ""; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/MenuItem.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.Material; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.inventory.meta.ItemMeta; 10 | 11 | @Deprecated 12 | public class MenuItem extends ItemStack { 13 | 14 | public MenuItem(Material type, String name, int amount, int durability, String action) { 15 | super(type, amount); 16 | ItemMeta im = getItemMeta(); 17 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 18 | List lore = new ArrayList(); 19 | lore.add(""); 20 | lore.add(ChatColor.GREEN + "> Click to " + action); 21 | im.setLore(lore); 22 | setItemMeta(im); 23 | setDurability((short) durability); 24 | } 25 | 26 | public MenuItem(Material type, String name, int durability, String action) { 27 | super(type); 28 | ItemMeta im = getItemMeta(); 29 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 30 | List lore = new ArrayList(); 31 | lore.add(""); 32 | lore.add(ChatColor.GREEN + "> Click to " + action); 33 | im.setLore(lore); 34 | setItemMeta(im); 35 | setDurability((short) durability); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/World/ActionBarBuilder.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.World; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage; 6 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 7 | 8 | import org.bukkit.entity.Player; 9 | 10 | @Deprecated 11 | public class ActionBarBuilder extends TellRawMessage { 12 | 13 | private static Constructor constructor; 14 | 15 | static { 16 | try { 17 | constructor = ReflectionUtils.getClass("PacketPlayOutChat").getConstructor(ReflectionUtils.getClass("IChatBaseComponent"), byte.class); 18 | } catch (SecurityException e) { 19 | e.printStackTrace(); 20 | } catch (NoSuchMethodException e) { 21 | e.printStackTrace(); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | 27 | /** 28 | * Sends the ActionBar Message to the specified 29 | * Players 30 | * 31 | * @param players All Players who should receive the ActionBar Message 32 | * @throws Exception 33 | */ 34 | @Override 35 | public void send(Player... players) throws Exception { 36 | Object packet = constructor.newInstance(getSerializedString(), (byte) 2); 37 | for (Player p: players) { 38 | ReflectionUtils.sendPacket(p, packet); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/PlayerRunnable.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import me.mrCookieSlime.CSCoreLibPlugin.java.Converter; 7 | import me.mrCookieSlime.CSCoreLibPlugin.java.EncodingType; 8 | 9 | import org.bukkit.entity.Player; 10 | 11 | @Deprecated 12 | public abstract class PlayerRunnable { 13 | 14 | public static Map map = new HashMap<>(); 15 | 16 | private long timestamp; 17 | private String id; 18 | 19 | public abstract void run(Player p); 20 | 21 | public PlayerRunnable() { 22 | this(-1); 23 | } 24 | 25 | public PlayerRunnable(int expire_in_minutes) { 26 | this.timestamp = System.nanoTime(); 27 | 28 | id = Converter.encode(EncodingType.BASE64, String.valueOf(timestamp)); 29 | map.put(id, this); 30 | 31 | if (expire_in_minutes >= 0) { 32 | CSCoreLib.getLib().getServer().getScheduler().scheduleSyncDelayedTask(CSCoreLib.getLib(), new Runnable() { 33 | 34 | @Override 35 | public void run() { 36 | map.remove(id); 37 | } 38 | }, expire_in_minutes * 60L * 20L); 39 | } 40 | } 41 | 42 | public static void run(String id, Player p) { 43 | if (!map.containsKey(id)) { 44 | return; 45 | } 46 | 47 | map.get(id).run(p); 48 | } 49 | 50 | public String getID() { 51 | return id; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/Listeners/MapListener.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events.Listeners; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Maps; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.inventory.InventoryCloseEvent; 9 | import org.bukkit.plugin.Plugin; 10 | 11 | @Deprecated 12 | public class MapListener implements Listener { 13 | 14 | public MapListener(Plugin plugin) { 15 | plugin.getServer().getPluginManager().registerEvents(this, plugin); 16 | } 17 | 18 | @EventHandler 19 | public void onClose(InventoryCloseEvent e) { 20 | if (Maps.getInstance().menus.containsKey(e.getPlayer().getUniqueId())) { 21 | Maps.getInstance().menus.get(e.getPlayer().getUniqueId()).getMenuCloseHandler().onClose((Player) e.getPlayer()); 22 | Maps.getInstance().menus.remove(e.getPlayer().getUniqueId()); 23 | } 24 | if (Maps.getInstance().inv.containsKey(e.getPlayer().getUniqueId())) Maps.getInstance().inv.remove(e.getPlayer().getUniqueId()); 25 | if (Maps.getInstance().sounds.containsKey(e.getPlayer().getUniqueId())) { 26 | ((Player) e.getPlayer()).playSound(e.getPlayer().getLocation(), Maps.getInstance().sounds.get(e.getPlayer().getUniqueId()).getClosingSound(), 1F, 1F); 27 | Maps.getInstance().sounds.remove(e.getPlayer().getUniqueId()); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Recipe/RecipeManager.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Recipe; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.Material; 7 | import org.bukkit.inventory.ItemStack; 8 | import org.bukkit.inventory.Recipe; 9 | 10 | @Deprecated 11 | public class RecipeManager { 12 | 13 | public static void removeRecipe(Material type) { 14 | Iterator recipes = Bukkit.recipeIterator(); 15 | Recipe recipe; 16 | while (recipes.hasNext()) { 17 | recipe = recipes.next(); 18 | if (recipe != null && recipe.getResult().getType() == type) { 19 | recipes.remove(); 20 | } 21 | } 22 | } 23 | 24 | public static void removeVanillaRecipe(Material type) { 25 | Iterator recipes = Bukkit.recipeIterator(); 26 | Recipe recipe; 27 | while (recipes.hasNext()) { 28 | recipe = recipes.next(); 29 | if (recipe != null && recipe.getResult().isSimilar(new ItemStack(type))) { 30 | recipes.remove(); 31 | } 32 | } 33 | } 34 | 35 | public static void removeRecipe(Material type, short durability) { 36 | Iterator recipes = Bukkit.recipeIterator(); 37 | Recipe recipe; 38 | while (recipes.hasNext()) { 39 | recipe = recipes.next(); 40 | if (recipe != null && recipe.getResult().getType() == type && recipe.getResult().getDurability() == durability) { 41 | recipes.remove(); 42 | } 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/World/TabMessage.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.World; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage; 6 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 7 | 8 | import org.bukkit.entity.Player; 9 | 10 | @Deprecated 11 | public class TabMessage extends TellRawMessage { 12 | 13 | private static Constructor constructor; 14 | 15 | static { 16 | try { 17 | constructor = ReflectionUtils.getClass("PacketPlayOutPlayerListHeaderFooter").getConstructor(ReflectionUtils.getClass("IChatBaseComponent")); 18 | } catch (NoSuchMethodException e) { 19 | e.printStackTrace(); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | /** 26 | * Sends Title to the specified 27 | * Players 28 | * 29 | * @param players All Players who should receive the Title 30 | * @throws Exception 31 | */ 32 | public void send(TabMessage footer, Player... players) throws Exception { 33 | Object packet = constructor.newInstance(getSerializedString()); 34 | if (footer != null) ReflectionUtils.setFieldValue(packet, "b", footer.getSerializedString()); 35 | for (Player p: players) { 36 | ReflectionUtils.sendPacket(p, packet); 37 | } 38 | } 39 | 40 | public enum TabType { 41 | HEADER, 42 | FOOTER; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/protection/ProtectionManager.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.protection; 2 | 3 | import java.util.UUID; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.block.Block; 7 | 8 | import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; 9 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 10 | 11 | @Deprecated 12 | public class ProtectionManager { 13 | 14 | private io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager manager; 15 | 16 | public ProtectionManager() {} 17 | 18 | public ProtectionManager(CSCoreLib plugin) { 19 | manager = new io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager(plugin.getServer()); 20 | } 21 | 22 | public boolean canBuild(UUID uuid, Block b) { 23 | return this.canBuild(uuid, b, false); 24 | } 25 | 26 | public boolean canAccessChest(UUID uuid, Block b) { 27 | return this.canAccessChest(uuid, b, false); 28 | } 29 | 30 | public boolean canBuild(UUID uuid, Block b, boolean message) { 31 | if (manager == null) return false; 32 | 33 | return manager.hasPermission(Bukkit.getOfflinePlayer(uuid), b.getLocation(), ProtectableAction.PLACE_BLOCK); 34 | } 35 | 36 | public boolean canAccessChest(UUID uuid, Block b, boolean message) { 37 | if (manager == null) return false; 38 | 39 | return manager.hasPermission(Bukkit.getOfflinePlayer(uuid), b.getLocation(), ProtectableAction.ACCESS_INVENTORIES); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Math/DoubleHandler.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Math; 2 | 3 | import java.text.DecimalFormat; 4 | 5 | @Deprecated 6 | public final class DoubleHandler { 7 | 8 | private DoubleHandler() {} 9 | 10 | public static String getFancyDouble(double d) { 11 | DecimalFormat format = new DecimalFormat("##.##"); 12 | 13 | double d2 = d / 1000000000000000d; 14 | if (d2 > 1) return format.format(d2).replace(",", ".") + "Q"; 15 | 16 | d2 = d / 1000000000000d; 17 | if (d2 > 1) return format.format(d2).replace(",", ".") + "T"; 18 | 19 | d2 = d / 1000000000d; 20 | if (d2 > 1) return format.format(d2).replace(",", ".") + "B"; 21 | 22 | d2 = d / 1000000d; 23 | if (d2 > 1) return format.format(d2).replace(",", ".") + "M"; 24 | 25 | d2 = d / 1000d; 26 | if (d2 > 1) return format.format(d2).replace(",", ".") + "K"; 27 | 28 | return format.format(d).replace(",", "."); 29 | } 30 | 31 | public static double fixDouble(double amount, int digits) { 32 | if (digits == 0) return (int) amount; 33 | StringBuilder format = new StringBuilder("##"); 34 | for (int i = 0; i < digits; i++) { 35 | if (i == 0) format.append("."); 36 | format.append("#"); 37 | } 38 | return Double.valueOf(new DecimalFormat(format.toString()).format(amount).replace(",", ".")); 39 | } 40 | 41 | public static double fixDouble(double amount) { 42 | return fixDouble(amount, 2); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/CustomPotion.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 4 | 5 | import org.bukkit.Color; 6 | import org.bukkit.Material; 7 | import org.bukkit.inventory.meta.PotionMeta; 8 | import org.bukkit.potion.PotionData; 9 | import org.bukkit.potion.PotionEffect; 10 | import org.bukkit.potion.PotionEffectType; 11 | import org.bukkit.potion.PotionType; 12 | 13 | @Deprecated 14 | public class CustomPotion extends CustomItem { 15 | 16 | @Deprecated 17 | public CustomPotion(String name, int durability, String[] lore, PotionEffect effect) { 18 | super(Material.POTION, name, (ReflectionUtils.getVersion().startsWith("v1_8_")) ? durability: 0, lore); 19 | PotionMeta meta = (PotionMeta) getItemMeta(); 20 | if (ReflectionUtils.getVersion().startsWith("v1_8_")) meta.setMainEffect(PotionEffectType.SATURATION); 21 | else meta.setMainEffect(effect.getType()); 22 | meta.addCustomEffect(effect, true); 23 | setItemMeta(meta); 24 | } 25 | 26 | public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) { 27 | super(Material.POTION, name, lore); 28 | PotionMeta meta = (PotionMeta) getItemMeta(); 29 | meta.setBasePotionData(new PotionData(type)); 30 | meta.addCustomEffect(effect, true); 31 | setItemMeta(meta); 32 | } 33 | 34 | public CustomPotion(String name, Color color, PotionEffect effect, String... lore) { 35 | super(Material.POTION, name, lore); 36 | PotionMeta meta = (PotionMeta) getItemMeta(); 37 | meta.setColor(color); 38 | meta.addCustomEffect(effect, true); 39 | setItemMeta(meta); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/Listeners/StatisticListener.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events.Listeners; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerStats; 4 | import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerStats.PlayerStat; 5 | 6 | import org.bukkit.GameMode; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.EventPriority; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.block.BlockBreakEvent; 11 | import org.bukkit.event.entity.PlayerDeathEvent; 12 | import org.bukkit.event.player.PlayerQuitEvent; 13 | import org.bukkit.plugin.Plugin; 14 | 15 | @Deprecated 16 | public class StatisticListener implements Listener { 17 | 18 | public StatisticListener(Plugin plugin) { 19 | plugin.getServer().getPluginManager().registerEvents(this, plugin); 20 | } 21 | 22 | @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) 23 | public void onDie(PlayerDeathEvent e) { 24 | if (e.getEntity().getKiller() != null) { 25 | PlayerStats.getStats(e.getEntity().getKiller()).addStatistic(PlayerStat.PLAYERS_KILLED, 1); 26 | PlayerStats.getStats(e.getEntity().getKiller()).addStatistic(PlayerStat.PLAYER_KILLSTREAK, 1); 27 | } 28 | PlayerStats.getStats(e.getEntity()).addStatistic(PlayerStat.DEATHS, 1); 29 | PlayerStats.getStats(e.getEntity()).setStatistic(PlayerStat.PLAYER_KILLSTREAK, 0); 30 | } 31 | 32 | @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) 33 | public void onBreak(BlockBreakEvent e) { 34 | if (e.getPlayer().getGameMode() != GameMode.CREATIVE) PlayerStats.getStats(e.getPlayer()).addStatistic(PlayerStat.BLOCKS_BROKEN, 1); 35 | } 36 | 37 | @EventHandler 38 | public void onQuit(PlayerQuitEvent e) { 39 | PlayerStats.unregister(e.getPlayer()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/ItemUseEvent.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.Cancellable; 6 | import org.bukkit.event.Event; 7 | import org.bukkit.event.HandlerList; 8 | import org.bukkit.event.player.PlayerInteractEvent; 9 | import org.bukkit.inventory.ItemStack; 10 | 11 | @Deprecated 12 | public class ItemUseEvent extends Event implements Cancellable { 13 | 14 | private static final HandlerList handlers = new HandlerList(); 15 | 16 | PlayerInteractEvent e; 17 | Player p; 18 | ItemStack i; 19 | Block b; 20 | boolean cancelled; 21 | 22 | public HandlerList getHandlers() { 23 | return handlers; 24 | } 25 | 26 | public static HandlerList getHandlerList() { 27 | return handlers; 28 | } 29 | 30 | @Deprecated 31 | public ItemUseEvent(Player p, ItemStack item, Block clicked) { 32 | this.p = p; 33 | this.i = item; 34 | this.b = clicked; 35 | this.e = null; 36 | } 37 | 38 | public ItemUseEvent(PlayerInteractEvent e, Block clicked) { 39 | this.p = e.getPlayer(); 40 | this.i = e.getItem(); 41 | this.b = clicked; 42 | this.e = e; 43 | } 44 | public ItemUseEvent(PlayerInteractEvent e, ItemStack item, Block clicked) { 45 | this.p = e.getPlayer(); 46 | this.i = item; 47 | this.b = clicked; 48 | this.e = e; 49 | } 50 | 51 | public Player getPlayer() { 52 | return this.p; 53 | } 54 | 55 | public ItemStack getItem() { 56 | return this.i; 57 | } 58 | 59 | public Block getClickedBlock() { 60 | return this.b; 61 | } 62 | 63 | public PlayerInteractEvent getParentEvent() { 64 | return this.e; 65 | } 66 | 67 | @Override 68 | public boolean isCancelled() { 69 | return this.cancelled; 70 | } 71 | 72 | @Override 73 | public void setCancelled(boolean cancel) { 74 | this.cancelled = cancel; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/MenuClickEvent.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; 4 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Maps; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.Event; 8 | import org.bukkit.event.HandlerList; 9 | import org.bukkit.inventory.Inventory; 10 | import org.bukkit.inventory.ItemStack; 11 | 12 | @Deprecated 13 | public class MenuClickEvent extends Event { 14 | 15 | private static final HandlerList handlers = new HandlerList(); 16 | 17 | Inventory inventory; 18 | int index; 19 | Player player; 20 | ItemStack item; 21 | int raw; 22 | ClickAction action; 23 | 24 | public HandlerList getHandlers() { 25 | return handlers; 26 | } 27 | 28 | public static HandlerList getHandlerList() { 29 | return handlers; 30 | } 31 | 32 | public MenuClickEvent(Player player, Inventory inv, ClickAction action, int index, ItemStack item, int rawSlot) { 33 | this.inventory = inv; 34 | this.index = index; 35 | this.player = player; 36 | this.item = item; 37 | this.raw = rawSlot; 38 | this.action = action; 39 | } 40 | 41 | public boolean hasKey() { 42 | return Maps.getInstance().inv.containsKey(player.getUniqueId()); 43 | } 44 | 45 | public String getKey() { 46 | if (hasKey()) { 47 | return Maps.getInstance().inv.get(player.getUniqueId()); 48 | } 49 | else { 50 | return null; 51 | } 52 | } 53 | 54 | public ItemStack getItem() { 55 | return this.item; 56 | } 57 | 58 | public Inventory getInventory() { 59 | return this.inventory; 60 | } 61 | 62 | public int getIndex() { 63 | return this.index; 64 | } 65 | 66 | public int getRawSlot() { 67 | return this.raw; 68 | } 69 | 70 | public Player getWhoClicked() { 71 | return this.player; 72 | } 73 | 74 | public ClickAction getAction() { 75 | return this.action; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/World/ArmorStandFactory.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.World; 2 | 3 | 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.ArmorStand; 6 | import org.bukkit.entity.EntityType; 7 | import org.bukkit.inventory.ItemStack; 8 | import org.bukkit.util.EulerAngle; 9 | 10 | @Deprecated 11 | public class ArmorStandFactory { 12 | 13 | public static ArmorStand createHidden(Location l) { 14 | ArmorStand armorStand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); 15 | armorStand.setVisible(false); 16 | armorStand.setSilent(true); 17 | armorStand.setMarker(true); 18 | armorStand.setGravity(false); 19 | armorStand.setBasePlate(false); 20 | armorStand.setCustomNameVisible(true); 21 | armorStand.setRemoveWhenFarAway(false); 22 | 23 | return armorStand; 24 | } 25 | 26 | public static ArmorStand createSmall(Location l, ItemStack item, EulerAngle arm, float yaw) { 27 | l.setYaw(yaw); 28 | ArmorStand armorStand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); 29 | armorStand.getEquipment().setItemInMainHand(item); 30 | armorStand.setVisible(false); 31 | armorStand.setSilent(true); 32 | armorStand.setMarker(true); 33 | armorStand.setGravity(false); 34 | armorStand.setSmall(true); 35 | armorStand.setArms(true); 36 | armorStand.setRightArmPose(arm); 37 | armorStand.setBasePlate(false); 38 | armorStand.setRemoveWhenFarAway(false); 39 | 40 | return armorStand; 41 | } 42 | 43 | public static ArmorStand createSmall(Location l, ItemStack head, float yaw) { 44 | l.setYaw(yaw); 45 | ArmorStand armorStand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); 46 | armorStand.getEquipment().setHelmet(head); 47 | armorStand.setVisible(false); 48 | armorStand.setSilent(true); 49 | armorStand.setMarker(true); 50 | armorStand.setGravity(false); 51 | armorStand.setSmall(true); 52 | armorStand.setBasePlate(false); 53 | armorStand.setRemoveWhenFarAway(false); 54 | 55 | return armorStand; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/ListUtils.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general; 2 | 3 | import java.util.List; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 6 | 7 | @Deprecated 8 | public final class ListUtils { 9 | 10 | private ListUtils() {} 11 | 12 | /** 13 | * Returns an amount of random Entries from 14 | * a List without returning any Entries more 15 | * than once 16 | * 17 | * @param list The List you want the entries to be taken from 18 | * @param random How many Entries should be returned 19 | * @return List of random Entries from the List 20 | */ 21 | public static List getRandomEntries(List list, int random) { 22 | final int size = list.size(); 23 | for (int i = 0; i < (size - random); i++) { 24 | list.remove(CSCoreLib.randomizer().nextInt(list.size())); 25 | } 26 | return list; 27 | } 28 | 29 | /** 30 | * Forms the StringList into a normal sentence with Spaces 31 | * 32 | * @param list The List you want to convert 33 | * @return Converted String 34 | */ 35 | public static String toString(List list) { 36 | return toString(list.toArray(new String[list.size()])); 37 | } 38 | 39 | /** 40 | * Forms the String Array into a normal sentence with Spaces 41 | * 42 | * @param list The List you want to convert 43 | * @return Converted String 44 | */ 45 | public static String toString(String... list) { 46 | return toString(0, list); 47 | } 48 | 49 | /** 50 | * Forms the String Array into a normal sentence with Spaces 51 | * and excludes the first X entries 52 | * 53 | * @param list The List you want to convert 54 | * @param excluded The Start Index for the String Array 55 | * @return Converted String 56 | */ 57 | public static String toString(int excluded, String... list) { 58 | StringBuilder builder = new StringBuilder(); 59 | 60 | for (int i = excluded; i < list.length; i++) { 61 | if (i > excluded) builder.append(" "); 62 | builder.append(list[i]); 63 | } 64 | 65 | return builder.toString(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/SkullItem.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.Material; 8 | import org.bukkit.OfflinePlayer; 9 | import org.bukkit.inventory.ItemStack; 10 | import org.bukkit.inventory.meta.ItemMeta; 11 | import org.bukkit.inventory.meta.SkullMeta; 12 | 13 | import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHook; 14 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 15 | 16 | @Deprecated 17 | public class SkullItem extends ItemStack { 18 | 19 | String owner; 20 | 21 | public SkullItem(OfflinePlayer player) { 22 | super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM"))); 23 | this.owner = player.getName(); 24 | SkullMeta meta = (SkullMeta) getItemMeta(); 25 | meta.setOwningPlayer(player); 26 | setItemMeta(meta); 27 | } 28 | 29 | @Deprecated 30 | public SkullItem(String name, String owner) { 31 | super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM"))); 32 | 33 | if (ReflectionUtils.isVersion("v1_10_", "v1_11_", "v1_12_")) { 34 | setDurability((short) 3); 35 | } 36 | 37 | ItemMeta im = getItemMeta(); 38 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 39 | 40 | ((SkullMeta) im).setOwner(owner); 41 | 42 | setItemMeta(im); 43 | this.owner = owner; 44 | } 45 | 46 | @Deprecated 47 | public SkullItem(String owner) { 48 | super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM"))); 49 | 50 | if (ReflectionUtils.isVersion("v1_10_", "v1_11_", "v1_12_")) { 51 | setDurability((short) 3); 52 | } 53 | 54 | ItemMeta im = getItemMeta(); 55 | ((SkullMeta) im).setOwner(owner); 56 | setItemMeta(im); 57 | this.owner = owner; 58 | } 59 | 60 | @Deprecated 61 | public SkullItem(String name, String owner, String... lore) { 62 | super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM"))); 63 | 64 | if (ReflectionUtils.isVersion("v1_10_", "v1_11_", "v1_12_")) { 65 | setDurability((short) 3); 66 | } 67 | 68 | ItemMeta im = getItemMeta(); 69 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 70 | List lines = new ArrayList<>(); 71 | for (String line: lore) { 72 | lines.add(ChatColor.translateAlternateColorCodes('&', line)); 73 | } 74 | im.setLore(lines); 75 | ((SkullMeta) im).setOwner(owner); 76 | setItemMeta(im); 77 | this.owner = owner; 78 | } 79 | 80 | public String getOwner() { 81 | return this.owner; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/events/Listeners/MenuClickListener.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.events.Listeners; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.events.MenuClickEvent; 4 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler; 6 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHandler; 7 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; 8 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Maps; 9 | 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.Material; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.event.EventHandler; 14 | import org.bukkit.event.Listener; 15 | import org.bukkit.event.inventory.InventoryClickEvent; 16 | import org.bukkit.plugin.Plugin; 17 | 18 | @Deprecated 19 | public class MenuClickListener implements Listener { 20 | 21 | public MenuClickListener(Plugin plugin) { 22 | plugin.getServer().getPluginManager().registerEvents(this, plugin); 23 | } 24 | 25 | @EventHandler 26 | public void onClick(InventoryClickEvent e) { 27 | if (Maps.getInstance().menus.containsKey(e.getWhoClicked().getUniqueId())) { 28 | ChestMenu menu = Maps.getInstance().menus.get(e.getWhoClicked().getUniqueId()); 29 | if (e.getRawSlot() < e.getInventory().getSize()) { 30 | MenuClickHandler handler = menu.getMenuClickHandler(e.getSlot()); 31 | if(handler == null) { 32 | e.setCancelled(!menu.isEmptySlotsClickable() && (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)); 33 | } else { 34 | if (handler instanceof AdvancedMenuClickHandler) { 35 | e.setCancelled(!((AdvancedMenuClickHandler) handler).onClick(e, (Player) e.getWhoClicked(), e.getSlot(), e.getCursor(), new ClickAction(e.isRightClick(), e.isShiftClick()))); 36 | } 37 | else e.setCancelled(!handler.onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick()))); 38 | } 39 | } 40 | else e.setCancelled(!menu.getPlayerInventoryClickHandler().onClick((Player) e.getWhoClicked(), e.getSlot(), e.getCurrentItem(), new ClickAction(e.isRightClick(), e.isShiftClick()))); 41 | } 42 | else if (Maps.getInstance().inv.containsKey(e.getWhoClicked().getUniqueId())) { 43 | e.setCancelled(true); 44 | if (e.getCurrentItem() != null) { 45 | Bukkit.getPluginManager().callEvent(new MenuClickEvent((Player) e.getWhoClicked(), e.getInventory(), new ClickAction(e.isRightClick(), e.isShiftClick()), e.getSlot(), e.getCurrentItem(), e.getRawSlot())); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/String/StringUtils.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.String; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.PackageName; 6 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 7 | 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | @Deprecated 11 | public class StringUtils { 12 | 13 | private static Method copy, getName, toString; 14 | 15 | static { 16 | try { 17 | copy = ReflectionUtils.getClass(PackageName.OBC, "inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class); 18 | getName = ReflectionUtils.getMethod(ReflectionUtils.getClass(PackageName.NMS, "ItemStack"), "getName"); 19 | 20 | if (ReflectionUtils.isVersion("v1_13_", "v1_14_", "v1_15_")) { 21 | toString = ReflectionUtils.getMethod(ReflectionUtils.getClass(PackageName.NMS, "IChatBaseComponent"), "getString"); 22 | } 23 | } 24 | catch(Exception x) { 25 | x.printStackTrace(); 26 | } 27 | } 28 | 29 | public static String formatItemName(ItemStack item, boolean includePlural) { 30 | String name = item.getType().toString(); 31 | try { 32 | Object instance = copy.invoke(null, item); 33 | 34 | if (toString == null) { 35 | name = (String) getName.invoke(instance); 36 | } 37 | else { 38 | name = (String) toString.invoke(getName.invoke(instance)); 39 | } 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) name = item.getItemMeta().getDisplayName(); 44 | if (includePlural) name = item.getAmount() + " " + name + "/s"; 45 | return name; 46 | } 47 | 48 | public static String format(String string) { 49 | string = string.toLowerCase(); 50 | StringBuilder builder = new StringBuilder(); 51 | int i = 0; 52 | for (String s: string.split("_")) { 53 | if (i == 0) builder.append(Character.toUpperCase(s.charAt(0)) + s.substring(1)); 54 | else builder.append(" " + Character.toUpperCase(s.charAt(0)) + s.substring(1)); 55 | i++; 56 | } 57 | return builder.toString(); 58 | } 59 | 60 | public static boolean contains(String string, String... contain) { 61 | for (String s: contain) { 62 | if (string.contains(s)) return true; 63 | } 64 | return false; 65 | } 66 | 67 | public static boolean equals(String string, String... equal) { 68 | for (String s: equal) { 69 | if (string.equals(s)) return true; 70 | } 71 | return false; 72 | } 73 | 74 | public static boolean endsWith(String string, String... end) { 75 | for (String s: end) { 76 | if (string.endsWith(s)) return true; 77 | } 78 | return false; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/InvUtils.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.inventory.Inventory; 6 | import org.bukkit.inventory.ItemStack; 7 | import org.bukkit.inventory.PlayerInventory; 8 | 9 | @Deprecated 10 | public class InvUtils { 11 | 12 | public static boolean fits(Inventory inv, ItemStack item) { 13 | Inventory inv2 = null; 14 | int size = inv.getSize(); 15 | if (inv instanceof PlayerInventory) { 16 | size = 36; 17 | inv2 = Bukkit.createInventory(null, size); 18 | } 19 | else if (inv.getSize() % 9 == 0) { 20 | inv2 = Bukkit.createInventory(null, size); 21 | } 22 | else { 23 | inv2 = Bukkit.createInventory(null, inv.getType()); 24 | } 25 | for (int i = 0; i < size; i++) { 26 | inv2.setItem(i, inv.getItem(i)); 27 | } 28 | return inv2.addItem(item).isEmpty(); 29 | } 30 | 31 | public static boolean fits(Inventory inv, ItemStack item, int slot) { 32 | if (inv.getContents()[slot] == null) return true; 33 | else { 34 | ItemStack clone = inv.getContents()[slot].clone(); 35 | int fits = (clone.getType().getMaxStackSize() - inv.getContents()[slot].getAmount()); 36 | if (clone.getType() == item.getType() && clone.getDurability() == item.getDurability()) { 37 | if (clone.getItemMeta().toString().equalsIgnoreCase(item.getItemMeta().toString())) { 38 | if (fits >= item.getAmount()) return true; 39 | else return false; 40 | } 41 | else return false; 42 | } 43 | else return false; 44 | } 45 | } 46 | 47 | /** 48 | * @since 1.5.16 49 | */ 50 | public static boolean hasEmptySlot(Inventory inv) { 51 | return inv.firstEmpty() != 1; 52 | } 53 | 54 | public static ItemStack decreaseItem(ItemStack item, int amount) { 55 | if (item == null) return null; 56 | ItemStack clone = item.clone(); 57 | if (amount < clone.getAmount()) clone.setAmount(clone.getAmount() - amount); 58 | else return null; 59 | return clone; 60 | } 61 | 62 | public static ItemStack setAmount(ItemStack item, int amount) { 63 | return new CustomItem(item, amount); 64 | } 65 | 66 | public static void removeItem(Inventory inv, ItemStack item, int Amount) { 67 | ItemStack[] contents = inv.getContents(); 68 | 69 | for (int i = 0; i < Amount; i++) { 70 | for (int j = 0; j < contents.length; j++) { 71 | if (contents[j] != null) { 72 | if (contents[j].getType() == item.getType() && contents[j].getDurability() == item.getDurability()) { 73 | if (contents[j].getAmount() > 1) { 74 | contents[j].setAmount(contents[j].getAmount() - 1); 75 | } 76 | else { 77 | inv.removeItem(contents[j]); 78 | } 79 | break; 80 | } 81 | } 82 | } 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/MenuHelper.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.UUID; 6 | 7 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 8 | 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.event.EventHandler; 12 | import org.bukkit.event.EventPriority; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.player.AsyncPlayerChatEvent; 15 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 16 | 17 | @Deprecated 18 | public class MenuHelper implements Listener { 19 | 20 | public static Map map = new HashMap<>(); 21 | public static Map map2 = new HashMap<>(); 22 | 23 | @EventHandler(priority=EventPriority.LOWEST) 24 | public void onChat(final AsyncPlayerChatEvent e) { 25 | final Player p = e.getPlayer(); 26 | final String message = e.getMessage().replaceAll("\\u00a7", "&"); 27 | if (map.containsKey(p.getUniqueId())) { 28 | final ChatHandler handler = map.get(p.getUniqueId()); 29 | map.remove(p.getUniqueId()); 30 | 31 | Bukkit.getScheduler().scheduleSyncDelayedTask(CSCoreLib.getLib(), new Runnable() { 32 | 33 | @Override 34 | public void run() { 35 | handler.onChat(p, message); 36 | } 37 | }, 0L); 38 | 39 | e.setCancelled(true); 40 | } 41 | else if (map2.containsKey(p.getUniqueId())) { 42 | final ChatHandler handler = map2.get(p.getUniqueId()); 43 | map2.remove(p.getUniqueId()); 44 | 45 | Bukkit.getScheduler().scheduleSyncDelayedTask(CSCoreLib.getLib(), new Runnable() { 46 | 47 | @Override 48 | public void run() { 49 | handler.onChat(p, message); 50 | } 51 | }, 0L); 52 | 53 | e.setCancelled(true); 54 | } 55 | } 56 | 57 | @EventHandler(priority=EventPriority.LOWEST) 58 | public void onComamnd(PlayerCommandPreprocessEvent e) { 59 | Player p = e.getPlayer(); 60 | if (map.containsKey(p.getUniqueId())) { 61 | ChatHandler handler = map.get(p.getUniqueId()); 62 | map.remove(p.getUniqueId()); 63 | handler.onChat(p, e.getMessage()); 64 | 65 | e.setCancelled(true); 66 | } 67 | else if (map2.containsKey(p.getUniqueId())) { 68 | ChatHandler handler = map2.get(p.getUniqueId()); 69 | map2.remove(p.getUniqueId()); 70 | handler.onChat(p, e.getMessage()); 71 | 72 | e.setCancelled(true); 73 | } 74 | } 75 | 76 | public interface ChatHandler { 77 | 78 | boolean onChat(Player p, String input); 79 | } 80 | 81 | public static void awaitChatInput(Player p, ChatHandler handler) { 82 | map.put(p.getUniqueId(), handler); 83 | } 84 | 85 | public static void awaitChatInput(Player p, boolean command, ChatHandler handler) { 86 | if (command) map2.put(p.getUniqueId(), handler); 87 | else map.put(p.getUniqueId(), handler); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Recipe/RecipeCalculator.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Recipe; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.Material; 9 | import org.bukkit.inventory.FurnaceRecipe; 10 | import org.bukkit.inventory.ItemStack; 11 | import org.bukkit.inventory.Recipe; 12 | import org.bukkit.inventory.ShapedRecipe; 13 | import org.bukkit.inventory.ShapelessRecipe; 14 | 15 | @Deprecated 16 | public class RecipeCalculator { 17 | 18 | public static List getIngredients(Recipe recipe) { 19 | List ingredients = new ArrayList<>(); 20 | if ((recipe instanceof ShapedRecipe)) { 21 | ShapedRecipe sr = (ShapedRecipe)recipe; 22 | String[] shape = sr.getShape(); 23 | 24 | for (String row : shape) { 25 | for (int i = 0; i < row.length(); i++) { 26 | ItemStack stack = (ItemStack)sr.getIngredientMap().get(Character.valueOf(row.charAt(i))); 27 | for (ItemStack ing : ingredients) { 28 | int mss = ing.getType().getMaxStackSize(); 29 | if ((ing.isSimilar(stack)) && (ing.getAmount() < mss)) { 30 | int canAdd = mss - ing.getAmount(); 31 | int add = Math.min(canAdd, stack.getAmount()); 32 | ing.setAmount(ing.getAmount() + add); 33 | int remaining = stack.getAmount() - add; 34 | if (remaining >= 1) { 35 | stack.setAmount(remaining); 36 | } else { 37 | stack = null; 38 | break; 39 | } 40 | } 41 | } 42 | if ((stack != null) && (stack.getAmount() > 0)) 43 | ingredients.add(stack); 44 | } 45 | } 46 | } 47 | else if ((recipe instanceof ShapelessRecipe)) { 48 | for (ItemStack i : ((ShapelessRecipe)recipe).getIngredientList()) { 49 | for (ItemStack ing : ingredients) { 50 | int mss = ing.getType().getMaxStackSize(); 51 | if ((ing.isSimilar(i)) && (ing.getAmount() < mss)) { 52 | int canAdd = mss - ing.getAmount(); 53 | ing.setAmount(ing.getAmount() + Math.min(canAdd, i.getAmount())); 54 | int remaining = i.getAmount() - Math.min(canAdd, i.getAmount()); 55 | if (remaining < 1) break; 56 | i.setAmount(remaining); 57 | } 58 | 59 | } 60 | 61 | if (i.getAmount() > 0) { 62 | ingredients.add(i); 63 | } 64 | } 65 | } 66 | return ingredients; 67 | } 68 | 69 | public static ItemStack getSmeltedOutput(Material type) { 70 | ItemStack result = null; 71 | Iterator iter = Bukkit.recipeIterator(); 72 | while (iter.hasNext()) { 73 | Recipe recipe = iter.next(); 74 | if (!(recipe instanceof FurnaceRecipe)) continue; 75 | if (((FurnaceRecipe) recipe).getInput().getType() != type) continue; 76 | result = recipe.getResult(); 77 | break; 78 | } 79 | 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/CustomItemSerializer.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import org.bukkit.enchantments.Enchantment; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | @Deprecated 11 | public class CustomItemSerializer { 12 | 13 | public enum ItemFlag { 14 | 15 | MATERIAL(0), 16 | DATA(1), 17 | AMOUNT(2), 18 | DURABILITY(3), 19 | ENCHANTMENTS(4), 20 | ITEMMETA_DISPLAY_NAME(5), 21 | ITEMMETA_LORE(6); 22 | 23 | private int weight; 24 | 25 | ItemFlag(int weight) { 26 | this.weight = weight; 27 | } 28 | 29 | public int getWeight() { 30 | return this.weight; 31 | } 32 | 33 | } 34 | 35 | private static ItemFlagComparator comparator = new ItemFlagComparator(); 36 | 37 | @SuppressWarnings("deprecation") 38 | public static String serialize(ItemStack item, ItemFlag... flags) { 39 | if (item == null) return "NULL"; 40 | List flaglist = Arrays.asList(flags); 41 | 42 | Collections.sort(flaglist, comparator); 43 | 44 | StringBuilder builder = new StringBuilder(); 45 | 46 | int i = 0; 47 | for (ItemFlag flag: flags) { 48 | if (i > 0) builder.append(" "); 49 | builder.append(flag.toString() + "="); 50 | 51 | switch (flag) { 52 | case AMOUNT: { 53 | builder.append(item.getAmount()); 54 | break; 55 | } 56 | case DATA: { 57 | builder.append((int) item.getData().getData()); 58 | break; 59 | } 60 | case DURABILITY: { 61 | builder.append((int) item.getDurability()); 62 | break; 63 | } 64 | case ENCHANTMENTS: 65 | for (Enchantment enchantment: Enchantment.values()) { 66 | if (item.getEnchantments().containsKey(enchantment)) { 67 | builder.append(enchantment.getName() + ":" + item.getEnchantmentLevel(enchantment)); 68 | } 69 | else { 70 | builder.append(enchantment.getName() + ":0"); 71 | } 72 | } 73 | break; 74 | case ITEMMETA_DISPLAY_NAME: { 75 | if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) { 76 | builder.append(item.getItemMeta().getDisplayName().replaceAll("\\u00a7", "&")); 77 | } 78 | else { 79 | builder.append("NONE"); 80 | } 81 | break; 82 | } 83 | case ITEMMETA_LORE: { 84 | if (item.hasItemMeta() && item.getItemMeta().hasLore()) { 85 | builder.append(item.getItemMeta().getLore().toString().replaceAll("\\u00a7", "&")); 86 | } 87 | else { 88 | builder.append("NONE"); 89 | } 90 | break; 91 | } 92 | case MATERIAL: { 93 | builder.append(item.getType().toString()); 94 | break; 95 | } 96 | default: 97 | break; 98 | } 99 | 100 | i++; 101 | } 102 | 103 | return builder.toString(); 104 | } 105 | 106 | public static boolean equals(ItemStack stack1, ItemStack stack2, ItemFlag... flags) { 107 | return serialize(stack1, flags).equals(serialize(stack2, flags)); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Player/PlayerStats.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Player; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.HashSet; 6 | import java.util.Map; 7 | import java.util.Set; 8 | import java.util.UUID; 9 | 10 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; 11 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 12 | 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.Statistic; 15 | import org.bukkit.entity.Player; 16 | 17 | @Deprecated 18 | public class PlayerStats { 19 | 20 | private static Set stats = new HashSet(); 21 | private static Map map = new HashMap(); 22 | 23 | UUID uuid; 24 | Config cfg; 25 | Map statistics; 26 | 27 | public PlayerStats(UUID uuid) { 28 | this.uuid = uuid; 29 | File file = new File("data-storage/CS-CoreLib/PlayerStats/" + uuid + ".stats"); 30 | cfg = new Config(file); 31 | statistics = new HashMap(); 32 | 33 | if (cfg.contains("stat.LOGIN")) cfg.setValue("stat.LOGIN", String.valueOf(cfg.getLong("stat.LOGIN") + 1)); 34 | else cfg.setValue("stat.LOGIN", "1"); 35 | 36 | if (file.exists()) { 37 | for (String key: cfg.getKeys("stat")) { 38 | statistics.put(PlayerStat.valueOf(key), cfg.getLong("stat." + key)); 39 | } 40 | } 41 | 42 | stats.add(this); 43 | map.put(uuid, this); 44 | } 45 | 46 | public static PlayerStats getStats(Player p) { 47 | if (map.containsKey(p.getUniqueId())) return map.get(p.getUniqueId()); 48 | else return new PlayerStats(p.getUniqueId()); 49 | } 50 | 51 | public long getStatistic(PlayerStat stat) { 52 | switch (stat) { 53 | case PLAY_TIME_MS: { 54 | if (ReflectionUtils.isVersion("v1_12_", "v1_11_", "v1_10_", "v1_9_")) { 55 | return Long.valueOf(String.valueOf(Bukkit.getPlayer(uuid).getStatistic(Statistic.valueOf("PLAY_ONE_TICK")) * 50)); 56 | } 57 | else { 58 | return Long.valueOf(String.valueOf(Bukkit.getPlayer(uuid).getStatistic(Statistic.valueOf("PLAY_ONE_MINUTE")) * 1000L)); 59 | } 60 | } 61 | default: { 62 | if (statistics.containsKey(stat)) return statistics.get(stat); 63 | else return 0; 64 | } 65 | } 66 | } 67 | 68 | public void setStatistic(PlayerStat stat, long value) { 69 | statistics.put(stat, value); 70 | } 71 | 72 | public void addStatistic(PlayerStat stat, long addition) { 73 | setStatistic(stat, getStatistic(stat) + addition); 74 | } 75 | 76 | private void save() { 77 | for (PlayerStat stat: statistics.keySet()) { 78 | cfg.setValue("stat." + stat.toString(), String.valueOf(getStatistic(stat))); 79 | } 80 | cfg.save(); 81 | } 82 | 83 | public enum PlayerStat { 84 | 85 | LOGIN, 86 | BLOCKS_BROKEN, 87 | PLAYERS_KILLED, 88 | DEATHS, 89 | PLAYER_KILLSTREAK, 90 | PLAY_TIME_MS; 91 | 92 | } 93 | 94 | public static void unregister(Player p) { 95 | if (map.containsKey(p.getUniqueId())) { 96 | PlayerStats ps = map.get(p.getUniqueId()); 97 | ps.save(); 98 | 99 | stats.remove(ps); 100 | map.remove(p.getUniqueId()); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Particles/FireworkShow.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Particles; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | 5 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 6 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 7 | 8 | import org.bukkit.Color; 9 | import org.bukkit.FireworkEffect; 10 | import org.bukkit.FireworkEffect.Type; 11 | import org.bukkit.Location; 12 | import org.bukkit.entity.EntityType; 13 | import org.bukkit.entity.Firework; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.inventory.meta.FireworkMeta; 16 | 17 | @Deprecated 18 | public class FireworkShow { 19 | 20 | public static void launchFirework(Location l, Color color) { 21 | Firework fw = (Firework)l.getWorld().spawnEntity(l, EntityType.FIREWORK); 22 | FireworkMeta meta = fw.getFireworkMeta(); 23 | FireworkEffect effect = FireworkEffect.builder().flicker(CSCoreLib.randomizer().nextBoolean()).withColor(color).with(CSCoreLib.randomizer().nextInt(3) + 1 == 1 ? Type.BALL: Type.BALL_LARGE).trail(CSCoreLib.randomizer().nextBoolean()).build(); 24 | meta.addEffect(effect); 25 | meta.setPower(CSCoreLib.randomizer().nextInt(2) + 1); 26 | fw.setFireworkMeta(meta); 27 | } 28 | 29 | public static Firework createFirework(Location l, Color color) { 30 | Firework fw = (Firework)l.getWorld().spawnEntity(l, EntityType.FIREWORK); 31 | FireworkMeta meta = fw.getFireworkMeta(); 32 | FireworkEffect effect = FireworkEffect.builder().flicker(CSCoreLib.randomizer().nextBoolean()).withColor(color).with(CSCoreLib.randomizer().nextInt(3) + 1 == 1 ? Type.BALL: Type.BALL_LARGE).trail(CSCoreLib.randomizer().nextBoolean()).build(); 33 | meta.addEffect(effect); 34 | meta.setPower(CSCoreLib.randomizer().nextInt(2) + 1); 35 | fw.setFireworkMeta(meta); 36 | return fw; 37 | } 38 | 39 | public static void launchRandom(Player p, int amount) { 40 | for (int i = 0; i < amount; i++) { 41 | Location l = p.getLocation().clone(); 42 | l.setX(l.getX() + CSCoreLib.randomizer().nextInt(amount)); 43 | l.setX(l.getX() - CSCoreLib.randomizer().nextInt(amount)); 44 | l.setZ(l.getZ() + CSCoreLib.randomizer().nextInt(amount)); 45 | l.setZ(l.getZ() - CSCoreLib.randomizer().nextInt(amount)); 46 | 47 | launchFirework(l, getColors()[CSCoreLib.randomizer().nextInt(getColors().length)]); 48 | } 49 | } 50 | 51 | public static Color[] getColors() { 52 | return new Color[] {Color.AQUA, Color.BLACK, Color.BLUE, Color.FUCHSIA, Color.GRAY, Color.GREEN, Color.LIME, Color.MAROON, Color.NAVY, Color.OLIVE, Color.ORANGE, Color.PURPLE, Color.RED, Color.SILVER, Color.TEAL, Color.WHITE, Color.YELLOW}; 53 | } 54 | 55 | public static void playEffect(Location l, Color color) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { 56 | Firework fw = l.getWorld().spawn(l, Firework.class); 57 | Object worldObject = ReflectionUtils.getMethod(l.getWorld().getClass(), "getHandle").invoke(l.getWorld(),(Object[]) null); 58 | 59 | FireworkMeta meta = fw.getFireworkMeta(); 60 | meta.addEffect(FireworkEffect.builder().with(Type.BURST).flicker(false).trail(false).withColor(color).withFade(Color.WHITE).build()); 61 | fw.setFireworkMeta(meta); 62 | 63 | ReflectionUtils.getMethod(worldObject.getClass(), "broadcastEntityEffect").invoke(worldObject, new Object[] {ReflectionUtils.getMethod(fw.getClass(), "getHandle").invoke(fw, (Object[]) null), (byte) 17}); 64 | fw.remove(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Localization.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.Configuration; 2 | 3 | import java.io.File; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.command.CommandSender; 10 | import org.bukkit.plugin.Plugin; 11 | 12 | @Deprecated 13 | public class Localization { 14 | 15 | private File file; 16 | private Config config; 17 | 18 | /** 19 | * Creates a new Localization Object for the specified Plugin 20 | * 21 | * @param plugin The Plugin this Localization is made for 22 | */ 23 | public Localization(Plugin plugin) { 24 | this.file = new File("plugins/" + plugin.getDescription().getName().replace(" ", "_") + "/messages.yml"); 25 | this.config = new Config(file); 26 | } 27 | 28 | /** 29 | * Sets the Default Message/s for the specified Key 30 | * 31 | * @param key The Key of those Messages 32 | * @param messages The Messages which this key will refer to by default 33 | */ 34 | public void setDefault(String key, String... messages) { 35 | if (!config.contains(key)) config.setValue(key, Arrays.asList(messages)); 36 | } 37 | 38 | /** 39 | * Sets the default Message Prefix 40 | * 41 | * @param prefix The Prefix by default 42 | */ 43 | public void setPrefix(String prefix) { 44 | setDefault("prefix", prefix); 45 | } 46 | 47 | /** 48 | * Returns the Strings referring to the specified Key 49 | * 50 | * @param key The Key of those Messages 51 | * @return The List this key is referring to 52 | */ 53 | public List getTranslation(String key) { 54 | return config.getValue(key) instanceof String ? Arrays.asList(config.getString(key)): config.getStringList(key); 55 | } 56 | 57 | /** 58 | * Sends all Messages the key is referring to 59 | * including the Prefix and specified Variables 60 | * 61 | * @param sender The Player/Console who should receive these Messages 62 | * @param key The Key of those Messages 63 | * @param addPrefix Specify whether the Prefix will get added or not 64 | * @param variables All Variables which should be applied to the sent messages 65 | */ 66 | public void sendTranslation(CommandSender sender, String key, boolean addPrefix, Variable... variables) { 67 | String prefix = addPrefix && config.contains("prefix") ? getTranslation("prefix").get(0): ""; 68 | for (String translation: getTranslation(key)) { 69 | for (Variable variable: variables) { 70 | translation = variable.apply(translation); 71 | } 72 | sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + translation)); 73 | } 74 | } 75 | 76 | /** 77 | * Sends all Messages the key is referring to 78 | * including the Prefix and specified Variables 79 | * 80 | * @param key The Key of those Messages 81 | * @param addPrefix Specify whether the Prefix will get added or not 82 | * @param variables All Variables which should be applied to the sent messages 83 | */ 84 | public void broadcastTranslation(String key, boolean addPrefix, Variable... variables) { 85 | String prefix = addPrefix && config.contains("prefix") ? getTranslation("prefix").get(0): ""; 86 | for (String translation: getTranslation(key)) { 87 | for (Variable variable: variables) { 88 | translation = variable.apply(translation); 89 | } 90 | Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', prefix + translation)); 91 | } 92 | } 93 | 94 | /** 95 | * Reloads the messages.yml File 96 | */ 97 | public void reload() { 98 | config.reload(); 99 | } 100 | 101 | /** 102 | * Saves this Localization to its File 103 | */ 104 | public void save() { 105 | config.save(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/compatibility/MaterialHelper.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.compatibility; 2 | 3 | import org.bukkit.Material; 4 | 5 | import java.util.Arrays; 6 | 7 | @Deprecated 8 | public class MaterialHelper { 9 | 10 | public static final Material[] WoolColours; 11 | public static final Material[] StainedGlassColours; 12 | public static final Material[] StainedGlassPaneColours; 13 | public static final Material[] TerracottaColours; 14 | public static final Material[] GlazedTerracottaColours; 15 | 16 | static { 17 | WoolColours = Arrays.stream(Material.values()).filter(MaterialHelper::isWool) 18 | .toArray(Material[]::new); 19 | 20 | StainedGlassColours = Arrays.stream(Material.values()).filter(MaterialHelper::isStainedGlass) 21 | .toArray(Material[]::new); 22 | 23 | StainedGlassPaneColours = Arrays.stream(Material.values()).filter(MaterialHelper::isStainedGlassPane) 24 | .toArray(Material[]::new); 25 | 26 | TerracottaColours = Arrays.stream(Material.values()).filter(MaterialHelper::isTerracotta) 27 | .toArray(Material[]::new); 28 | 29 | GlazedTerracottaColours = Arrays.stream(Material.values()).filter(MaterialHelper::isGlazedTerracotta) 30 | .toArray(Material[]::new); 31 | } 32 | 33 | public static Material getSaplingFromLog(Material log) { 34 | if (!isLog(log)) 35 | return Material.AIR; 36 | 37 | String type = log.name().substring(0, log.name().lastIndexOf('_')); 38 | type = type.replace("STRIPPED_", ""); 39 | try { 40 | return Material.valueOf(type + "_SAPLING"); 41 | }catch (IllegalArgumentException ignored) { 42 | return Material.AIR; 43 | } 44 | } 45 | 46 | public static Material getWoodFromLog(Material log) { 47 | if (!isLog(log)) 48 | return Material.AIR; 49 | 50 | String type = log.name().substring(0, log.name().lastIndexOf('_')); 51 | type = type.replace("STRIPPED_", ""); 52 | try { 53 | return Material.valueOf(type + "_PLANKS"); 54 | } catch (IllegalArgumentException ignored) { 55 | return Material.AIR; 56 | } 57 | } 58 | 59 | public static boolean isLog(Material log) { 60 | return log.name().endsWith("_LOG") || log.name().endsWith("_WOOD"); 61 | } 62 | 63 | public static boolean isLeavesBlock(Material leaves) { 64 | return leaves.name().endsWith("_LEAVES"); 65 | } 66 | 67 | public static boolean isWool(Material material) { 68 | return material.name().endsWith("_WOOL"); 69 | } 70 | 71 | public static boolean isStainedGlass(Material material) { 72 | return material.name().endsWith("_STAINED_GLASS"); 73 | } 74 | 75 | public static boolean isStainedGlassPane(Material material) { 76 | return material.name().endsWith("_STAINED_GLASS_PANE"); 77 | } 78 | 79 | public static boolean isTerracotta(Material material) { 80 | return material.name().endsWith("_TERRACOTTA"); 81 | } 82 | 83 | public static boolean isGlazedTerracotta(Material material) { 84 | return material.name().endsWith("_GLAZED_TERRACOTTA"); 85 | } 86 | 87 | public static boolean isDiggable(Material material) { 88 | return material.name().endsWith("_DIRT") || material.name().equals("DIRT") 89 | || material.name().endsWith("_SAND") || material.name().equals("SAND") 90 | || material.name().startsWith("SNOW_") || material.name().equals("SNOW") 91 | || material.name().equals("PODZOL") || material.name().equals("GRAVEL") 92 | || material.name().equals("MYCELIUM") || material.name().startsWith("GRASS_") 93 | || material.name().equals("FARMLAND") || material.name().equals("CLAY"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/PluginUtils.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin; 2 | 3 | import java.io.File; 4 | 5 | import org.bstats.bukkit.Metrics; 6 | import org.bukkit.configuration.file.FileConfiguration; 7 | import org.bukkit.plugin.Plugin; 8 | 9 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; 10 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Localization; 11 | import me.mrCookieSlime.CSCoreLibPlugin.updater.Updater; 12 | 13 | @Deprecated 14 | public class PluginUtils { 15 | 16 | private Plugin plugin; 17 | private int id; 18 | private Config cfg; 19 | private Localization local; 20 | private Metrics metrics; 21 | 22 | /** 23 | * Creates a new PluginUtils Instance for 24 | * the specified Plugin 25 | * 26 | * @param plugin The Plugin for which this PluginUtils Instance is made for 27 | */ 28 | public PluginUtils(Plugin plugin) { 29 | this.plugin = plugin; 30 | } 31 | 32 | /** 33 | * Creates a new PluginUtils Instance for 34 | * the specified Plugin 35 | * 36 | * @param plugin The Plugin for which this PluginUtils Instance is made for 37 | */ 38 | public PluginUtils(Plugin plugin, int id) { 39 | this(plugin); 40 | this.id = id; 41 | } 42 | 43 | /** 44 | * Returns the specified ID from Curse 45 | * 46 | * @return Plugin ID 47 | */ 48 | public int getPluginID() { 49 | return this.id; 50 | } 51 | 52 | /** 53 | * Automatically sets up an Updater Service for you 54 | * 55 | * @param id The ID of your Project 56 | * @param file The file of your Plugin (obtained by plugin.getFile() ) 57 | */ 58 | public void setupUpdater(int id, File file) { 59 | this.id = id; 60 | if (plugin.getConfig().getBoolean("options.auto-update")) { 61 | new Updater(plugin, file, id); 62 | } 63 | } 64 | 65 | /** 66 | * Automatically sets up an Updater Service for you 67 | * 68 | * @param file The file of your Plugin (obtained by plugin.getFile() ) 69 | */ 70 | public void setupUpdater(File file) { 71 | if (plugin.getConfig().getBoolean("options.auto-update")) { 72 | new Updater(plugin, file, id); 73 | } 74 | } 75 | 76 | /** 77 | * Automatically sets up MC-Stats Metrics for you 78 | */ 79 | public void setupMetrics() { 80 | 81 | } 82 | 83 | /** 84 | * Returns the previously setup Metrics 85 | * which can be used to setup custom charts 86 | * 87 | * @return Metrics of this Plugin 88 | */ 89 | public Metrics getMetrics() { 90 | return metrics; 91 | } 92 | 93 | /** 94 | * Automatically sets up the messages.yml for you 95 | */ 96 | public void setupLocalization() { 97 | local = new Localization(plugin); 98 | } 99 | 100 | /** 101 | * Automatically sets up the config.yml for you 102 | */ 103 | public void setupConfig() { 104 | FileConfiguration config = plugin.getConfig(); 105 | config.options().copyDefaults(true); 106 | config.options().header("\nName: " + plugin.getName() + "\nAuthor: " + plugin.getDescription().getAuthors().get(0) + "\n\nDo not modify the Config while the Server is running\notherwise bad things might happen!\n\nThis Plugin also requires CS-CoreLib to run!\nIf you don't have it installed already, its going to be\nautomatically installed for you\n\nThis Plugin utilises an Auto-Updater. If you want to turn that off,\nsimply set options -> auto-update to false"); 107 | plugin.saveConfig(); 108 | 109 | cfg = new Config(plugin); 110 | } 111 | 112 | /** 113 | * Returns the previously setup Config 114 | * 115 | * @return Config of this Plugin 116 | */ 117 | public Config getConfig() { 118 | return cfg; 119 | } 120 | 121 | /** 122 | * Returns the previously setup Localization 123 | * 124 | * @return Localization for this Plugin 125 | */ 126 | public Localization getLocalization() { 127 | return local; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibExample.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibSetup; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.PluginUtils; 4 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; 5 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Localization; 6 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Variable; 7 | 8 | import org.bukkit.plugin.java.JavaPlugin; 9 | 10 | // Before you continue reading this 11 | // make sure you have added the CSCoreLibLoader.class to your package 12 | // CSCoreLibLoader.class (https://dl.dropbox.com/s/vqlu8ogh0cgszpx/CSCoreLibLoader.java?dl=0) 13 | // and CS-CoreLib to your Build Path 14 | 15 | // Your standard Plugin Setup 16 | public class CSCoreLibExample extends JavaPlugin { 17 | 18 | // Your generic onEnable() method 19 | @Override 20 | public void onEnable() { 21 | // Now to make sure your Plugin auto-installs CS-CoreLib if it was not found, create a new Instance of your CSCoreLibLoader 22 | // You need to specify an Instance of your main class for that, but as you do this in your onEnable() method, simply specify this 23 | CSCoreLibLoader loader = new CSCoreLibLoader(this); 24 | // Now to check whether CS-CoreLib was properly installed, do the following statement: 25 | if (loader.load()) { 26 | // Now you can start enabling your Plugin right here as CSCoreLib was properly installed. 27 | // The first thing you will most likely do is setting up the basics of your Plugin like a Config 28 | // To do that you will need an Instance of PluginUtils for your Plugin 29 | PluginUtils utils = new PluginUtils(this); 30 | // Now setting up the config is as easy as the following 31 | // This will take care of copying your default config.yml in your src folder and loading it 32 | utils.setupConfig(); 33 | // To access your Config at any time, you can do this 34 | Config cfg = utils.getConfig(); 35 | // This Config Object also has some useful methods which come along with it, you can play around with those for yourself 36 | cfg.getLocation("path"); 37 | cfg.setDefaultValue("path", "value"); 38 | cfg.getRandomStringfromList("path"); 39 | cfg.getFloat("path"); 40 | cfg.save(); 41 | cfg.reload(); 42 | cfg.getString("path"); 43 | // And a lot more... 44 | 45 | // Now your PluginUtils can do way more than that though 46 | // For example you can setup your own Auto-Updater 47 | int id = 0; 48 | utils.setupUpdater(id, getFile()); 49 | // You can find your id here https://api.curseforge.com/servermods/projects?search= 50 | // But there is also Metrics embedded if you want to monitor the Usage of your Plugins 51 | utils.setupMetrics(); 52 | // And since a lot of people nowadays want more customization, there is also a Localization provided 53 | utils.setupLocalization(); 54 | // And to access it: 55 | Localization local = utils.getLocalization(); 56 | // And this Localization Object is a stripped down Version of the Config Object and has some of its Methods 57 | local.setDefault("key", "You", "can", "specify", "multiple", "messages", "if", "you", "want"); 58 | // This will return the List of strings that are found under this key 59 | local.getTranslation("key"); 60 | // You can also specify a Prefix if you want, also Color Codes are supported in all of these methods 61 | local.setDefault("prefix", "&7[Awesome Plugin]"); 62 | // The following will send the Messages to the specified Player (null in this case) 63 | // The boolean at the end represents whether a Prefix will be attached or not. 64 | // Note here that you need to specify a Prefix first 65 | local.sendTranslation(null, "path.to.message", true); 66 | // Now if your localized Messages contains placeholders like %player% 67 | // No problem, you can make use of those as well 68 | local.sendTranslation(null, "path.to.message", true, new Variable("%player%", "replaced text")); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Player/PlayerInventory.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Player; 2 | 3 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils; 4 | 5 | import org.bukkit.GameMode; 6 | import org.bukkit.Material; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | @Deprecated 11 | public class PlayerInventory { 12 | 13 | @SuppressWarnings("deprecation") 14 | public static void consumeItemInHand(Player p) { 15 | if (p.getGameMode() != GameMode.CREATIVE) { 16 | ItemStack item = p.getItemInHand().clone(); 17 | item.setAmount(item.getAmount() - 1); 18 | p.setItemInHand(item.getAmount() > 0 ? item: null); 19 | } 20 | } 21 | 22 | public static void removeItemIgnoringMetaAndDamage(Player p, Material Item, int Amount) { 23 | ItemStack[] contents = p.getInventory().getContents(); 24 | 25 | for (int i = 0; i < Amount; i++) { 26 | for (int j = 0; j < contents.length; j++) { 27 | if (contents[j] != null) { 28 | if (contents[j].getType() == Item) { 29 | if (contents[j].getAmount() > 1) contents[j].setAmount(contents[j].getAmount() - 1); 30 | else p.getInventory().removeItem(contents[j]); 31 | break; 32 | } 33 | } 34 | } 35 | } 36 | } 37 | 38 | public static void removeItemIgnoringMeta(Player p, Material Item, int Amount) { 39 | ItemStack[] contents = p.getInventory().getContents(); 40 | 41 | for (int i = 0; i < Amount; i++) { 42 | for (int j = 0; j < contents.length; j++) { 43 | if (contents[j] != null) { 44 | if (contents[j].getType() == Item && contents[j].getDurability() == 0) { 45 | if (contents[j].getAmount() > 1) contents[j].setAmount(contents[j].getAmount() - 1); 46 | else p.getInventory().removeItem(contents[j]); 47 | break; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | 54 | public static void removeItemIgnoringMeta(Player p, Material Item, int Amount, int durability) { 55 | ItemStack[] contents = p.getInventory().getContents(); 56 | 57 | for (int i = 0; i < Amount; i++) { 58 | for (int j = 0; j < contents.length; j++) { 59 | if (contents[j] != null) { 60 | if (contents[j].getType() == Item && contents[j].getDurability() == durability) { 61 | if (contents[j].getAmount() > 1) contents[j].setAmount(contents[j].getAmount() - 1); 62 | else p.getInventory().removeItem(contents[j]); 63 | break; 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | public static void removeItem(Player p, ItemStack item, int Amount) { 71 | ItemStack[] contents = p.getInventory().getContents(); 72 | 73 | for (int i = 0; i < Amount; i++) { 74 | for (int j = 0; j < contents.length; j++) { 75 | if (contents[j] != null) { 76 | if (contents[j].getType() == item.getType() && contents[j].getDurability() == item.getDurability()) { 77 | if (contents[j].getAmount() > 1) contents[j].setAmount(contents[j].getAmount() - 1); 78 | else p.getInventory().removeItem(contents[j]); 79 | break; 80 | } 81 | } 82 | } 83 | } 84 | } 85 | 86 | @SuppressWarnings("deprecation") 87 | public static void update(Player p) { 88 | p.updateInventory(); 89 | // TODO: Switch to new updateInventory Method once implemented 90 | } 91 | 92 | @SuppressWarnings("deprecation") 93 | public static void damageItemInHand(Player p) { 94 | if (p.getGameMode() != GameMode.CREATIVE) { 95 | ItemStack item = p.getItemInHand().clone(); 96 | 97 | item.setDurability((short) (item.getDurability() + 1)); 98 | p.setItemInHand(item.getDurability() < item.getType().getMaxDurability() ? item: null); 99 | } 100 | } 101 | 102 | public static void giveItem(Player p, ItemStack item) { 103 | if (InvUtils.fits(p.getInventory(), item)) p.getInventory().addItem(item); 104 | else p.getWorld().dropItemNaturally(p.getLocation(), item); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/CustomBookOverlay.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Method; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.UUID; 9 | 10 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 11 | import me.mrCookieSlime.CSCoreLibPlugin.events.Listeners.CustomBookOverlayListener; 12 | import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage; 13 | import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerInventory; 14 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.CraftObject; 15 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.PackageName; 16 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 17 | 18 | import org.bukkit.Bukkit; 19 | import org.bukkit.Material; 20 | import org.bukkit.entity.Player; 21 | import org.bukkit.event.EventHandler; 22 | import org.bukkit.event.Listener; 23 | import org.bukkit.event.player.PlayerDropItemEvent; 24 | import org.bukkit.inventory.ItemStack; 25 | import org.bukkit.inventory.meta.BookMeta; 26 | 27 | @Deprecated 28 | public class CustomBookOverlay { 29 | 30 | public static Set opening = new HashSet<>(); 31 | private static Method openBook, copyBook; 32 | private static Object const_mainhand; 33 | 34 | static { 35 | try { 36 | Class enumhand = ReflectionUtils.getClass(PackageName.NMS, "EnumHand"); 37 | openBook = ReflectionUtils.getMethod(ReflectionUtils.getClass(PackageName.NMS, "EntityPlayer"), "a", ReflectionUtils.getClass(PackageName.NMS, "ItemStack"), enumhand); 38 | if (openBook == null) { 39 | openBook = ReflectionUtils.getMethod(ReflectionUtils.getClass(PackageName.NMS, "EntityPlayer"), "openBook", ReflectionUtils.getClass(PackageName.NMS, "ItemStack"), enumhand); 40 | } 41 | const_mainhand = ReflectionUtils.getEnumConstant(enumhand, "MAIN_HAND"); 42 | 43 | copyBook = ReflectionUtils.getMethod(ReflectionUtils.getClass(PackageName.OBC, "inventory.CraftItemStack"), "asNMSCopy", ItemStack.class); 44 | } catch (Exception x) { 45 | x.printStackTrace(); 46 | } 47 | } 48 | 49 | public static void load(CSCoreLib plugin) { 50 | plugin.getServer().getPluginManager().registerEvents(new CustomBookOverlayListener(), plugin); 51 | plugin.getServer().getPluginManager().registerEvents(new Listener() { 52 | 53 | @EventHandler 54 | public void onDrop(PlayerDropItemEvent e) { 55 | if (opening.contains(e.getPlayer().getUniqueId())) e.setCancelled(true); 56 | } 57 | 58 | }, plugin); 59 | } 60 | 61 | ItemStack book; 62 | 63 | public CustomBookOverlay(String title, String author, TellRawMessage... pages) { 64 | this.book = new ItemStack(Material.WRITTEN_BOOK); 65 | 66 | BookMeta meta = (BookMeta) this.book.getItemMeta(); 67 | meta.setTitle(title); 68 | meta.setAuthor(author); 69 | 70 | for (TellRawMessage page: pages) { 71 | try { 72 | addPage(meta, page); 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | 78 | this.book.setItemMeta(meta); 79 | } 80 | 81 | @SuppressWarnings({ "unchecked", "rawtypes" }) 82 | private void addPage(BookMeta meta, TellRawMessage page) throws Exception { 83 | Field field = ReflectionUtils.getField(ReflectionUtils.getClass(PackageName.OBC, "inventory.CraftMetaBook"), "pages"); 84 | field.setAccessible(true); 85 | 86 | List pages = (List) field.get(meta); 87 | 88 | pages.add(ReflectionUtils.getClass(PackageName.NMS, "IChatBaseComponent").cast(page.getSerializedString())); 89 | field.setAccessible(false); 90 | } 91 | 92 | public void open(final Player p) { 93 | if (opening.contains(p.getUniqueId())) return; 94 | 95 | final int slot = p.getInventory().getHeldItemSlot(); 96 | 97 | opening.add(p.getUniqueId()); 98 | final ItemStack item = p.getInventory().getItem(slot); 99 | p.getInventory().setItem(slot, this.book); 100 | 101 | Bukkit.getScheduler().scheduleSyncDelayedTask(CSCoreLib.getLib(), () -> { 102 | try { 103 | Object handle = ReflectionUtils.getHandle(CraftObject.PLAYER, p); 104 | Object copy = copyBook.invoke(null, book); 105 | 106 | openBook.invoke(handle, copy, const_mainhand); 107 | 108 | p.getInventory().setItem(slot, item); 109 | PlayerInventory.update(p); 110 | opening.remove(p.getUniqueId()); 111 | } catch (Exception e) { 112 | e.printStackTrace(); 113 | } 114 | }, 1L); 115 | } 116 | 117 | public ItemStack toItemStack() { 118 | return this.book.clone(); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | me.mrCookieSlime 6 | CS-CoreLib 7 | 1.7 8 | 9 | 10 | 1.8 11 | 1.8 12 | UTF-8 13 | 14 | 15 | 16 | 17 | papermc 18 | https://papermc.io/repo/repository/maven-public/ 19 | 20 | 21 | spigot-repo 22 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 23 | 24 | 25 | jitpack.io 26 | https://jitpack.io/ 27 | 28 | 29 | CodeMC 30 | https://repo.codemc.org/repository/maven-public 31 | 32 | 33 | 34 | 35 | ${project.basedir}/src 36 | ${project.basedir}/tests/java 37 | 38 | 39 | ${project.basedir}/tests/resources 40 | 41 | 42 | ${project.name} v${project.version} 43 | 44 | 45 | 46 | ${basedir}/src 47 | true 48 | 49 | plugin.yml 50 | config.yml 51 | 52 | 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-shade-plugin 58 | 3.2.4 59 | 60 | 61 | 62 | org.bstats 63 | me.mrCookieSlime.bstats 64 | 65 | 66 | io.github.thebusybiscuit.cscorelib2 67 | me.mrCookieSlime.CSCoreLibPlugin.cscorelib2 68 | 69 | 70 | 71 | 72 | com.github.thebusybiscuit:CS-CoreLib2 73 | 74 | **/cscorelib2/protection/** 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | package 83 | 84 | shade 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.spigotmc 95 | spigot-api 96 | 1.16.1-R0.1-SNAPSHOT 97 | provided 98 | 99 | 100 | org.apache.logging.log4j 101 | log4j-core 102 | 2.13.3 103 | provided 104 | 105 | 106 | com.github.TheBusyBiscuit 107 | CS-CoreLib2 108 | 0.27.4 109 | 110 | 111 | org.bstats 112 | bstats-bukkit 113 | 1.7 114 | compile 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Menu.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import me.mrCookieSlime.CSCoreLibPlugin.general.Math.Calculator; 9 | import me.mrCookieSlime.CSCoreLibPlugin.general.World.MenuSounds; 10 | 11 | import org.bukkit.Bukkit; 12 | import org.bukkit.ChatColor; 13 | import org.bukkit.Material; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.inventory.Inventory; 16 | import org.bukkit.inventory.ItemStack; 17 | 18 | @Deprecated 19 | public class Menu { 20 | 21 | Inventory inv; 22 | List contents; 23 | Map map; 24 | String name; 25 | MenuSounds sounds; 26 | 27 | public Menu(String name, List items) { 28 | this.name = name; 29 | this.inv = Bukkit.createInventory(null, Calculator.formToLine(items.size()) * 9, ChatColor.translateAlternateColorCodes('&', name)); 30 | this.contents = items; 31 | this.map = new HashMap(); 32 | for (int i = 0; i < this.inv.getSize(); i++) { 33 | if ((items.size() - 1) < i) { 34 | this.inv.setItem(i, new ItemStack(Material.AIR)); 35 | this.map.put(i, new ItemStack(Material.AIR)); 36 | } 37 | else { 38 | this.inv.setItem(i, items.get(i)); 39 | this.map.put(i, items.get(i)); 40 | } 41 | } 42 | } 43 | 44 | public Menu(String name, ItemStack[] items) { 45 | this.name = name; 46 | this.inv = Bukkit.createInventory(null, Calculator.formToLine(items.length) * 9, ChatColor.translateAlternateColorCodes('&', name)); 47 | List list = new ArrayList(); 48 | for (ItemStack item: items) { 49 | list.add(item); 50 | } 51 | this.contents = list; 52 | this.map = new HashMap(); 53 | for (int i = 0; i < this.inv.getSize(); i++) { 54 | if ((items.length - 1) < i) { 55 | this.inv.setItem(i, new ItemStack(Material.AIR)); 56 | this.map.put(i, new ItemStack(Material.AIR)); 57 | } 58 | else { 59 | this.inv.setItem(i, items[i]); 60 | this.map.put(i, items[i]); 61 | } 62 | } 63 | } 64 | 65 | public Menu(String name, int size) { 66 | this.name = name; 67 | this.inv = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', name)); 68 | this.contents = new ArrayList(); 69 | this.map = new HashMap(); 70 | for (int i = 0; i < this.inv.getSize(); i++) { 71 | this.inv.setItem(i, new ItemStack(Material.AIR)); 72 | this.map.put(i, new ItemStack(Material.AIR)); 73 | } 74 | } 75 | 76 | public boolean hasKey(Player p) { 77 | return Maps.getInstance().inv.containsKey(p.getUniqueId()); 78 | } 79 | 80 | public void setSize(int size) { 81 | this.inv = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', this.name)); 82 | for (int i = 0; i < size; i++) { 83 | if ((this.contents.size() - 1) < i) { 84 | this.inv.setItem(i, new ItemStack(Material.AIR)); 85 | this.map.put(i, new ItemStack(Material.AIR)); 86 | } 87 | } 88 | } 89 | 90 | public Inventory getInventory() { 91 | return this.inv; 92 | } 93 | 94 | public Map toHashMap() { 95 | return this.map; 96 | } 97 | 98 | public List getContents() { 99 | return this.contents; 100 | } 101 | 102 | public String getName() { 103 | return this.name; 104 | } 105 | 106 | public void addSounds(MenuSounds sounds) { 107 | this.sounds = sounds; 108 | } 109 | 110 | public void open(Player p) { 111 | p.openInventory(this.inv); 112 | if (sounds != null) { 113 | if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F); 114 | if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds); 115 | } 116 | } 117 | 118 | public void open(Player p, String key) { 119 | p.openInventory(this.inv); 120 | Maps.getInstance().inv.put(p.getUniqueId(), key); 121 | if (sounds != null) { 122 | if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F); 123 | if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds); 124 | } 125 | } 126 | 127 | public void openIndividually(Player p, List items) { 128 | Inventory inv = Bukkit.createInventory(null, Calculator.formToLine(items.size()) * 9, ChatColor.translateAlternateColorCodes('&', this.name)); 129 | for (int i = 0; i < items.size(); i++) { 130 | inv.setItem(i, items.get(i)); 131 | } 132 | p.openInventory(inv); 133 | if (sounds != null) { 134 | if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F); 135 | if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds); 136 | } 137 | } 138 | 139 | public void openIndividually(Player p, List items, String key) { 140 | openIndividually(p, items); 141 | Maps.getInstance().inv.put(p.getUniqueId(), key); 142 | if (sounds != null) { 143 | if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F); 144 | if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds); 145 | } 146 | } 147 | 148 | public void setItem(int slot, ItemStack item) { 149 | this.contents.set(slot, item); 150 | this.inv.setItem(slot, item); 151 | this.map.put(slot, item); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/Item/CustomItem.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.Material; 8 | import org.bukkit.enchantments.Enchantment; 9 | import org.bukkit.inventory.ItemStack; 10 | import org.bukkit.inventory.meta.ItemMeta; 11 | import org.bukkit.material.MaterialData; 12 | 13 | @Deprecated 14 | public class CustomItem extends ItemStack { 15 | 16 | public CustomItem(ItemStack item) { 17 | super(item); 18 | } 19 | 20 | @Deprecated 21 | public CustomItem(Material type, String name, int durability, List lore) { 22 | super(new ItemStack(type)); 23 | ItemMeta im = getItemMeta(); 24 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 25 | im.setLore(lore); 26 | setItemMeta(im); 27 | setDurability((short) durability); 28 | } 29 | 30 | @Deprecated 31 | public CustomItem(Material type, String name, int durability, String[] lore) { 32 | super(new ItemStack(type)); 33 | ItemMeta im = getItemMeta(); 34 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 35 | List lines = new ArrayList(); 36 | for (String line: lore) { 37 | lines.add(ChatColor.translateAlternateColorCodes('&', line)); 38 | } 39 | im.setLore(lines); 40 | setItemMeta(im); 41 | setDurability((short) durability); 42 | } 43 | 44 | @Deprecated 45 | public CustomItem(Material type, String name, int durability, String[] lore, String[] enchantments) { 46 | super(new ItemStack(type)); 47 | ItemMeta im = getItemMeta(); 48 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 49 | List lines = new ArrayList(); 50 | for (String line: lore) { 51 | lines.add(ChatColor.translateAlternateColorCodes('&', line)); 52 | } 53 | im.setLore(lines); 54 | setItemMeta(im); 55 | setDurability((short) durability); 56 | for (String ench: enchantments) { 57 | addUnsafeEnchantment(Enchantment.getByName(ench.split("-")[0]), Integer.parseInt(ench.split("-")[1])); 58 | } 59 | } 60 | 61 | @Deprecated 62 | public CustomItem(ItemStack item, String[] enchantments) { 63 | super(item); 64 | for (String ench: enchantments) { 65 | addUnsafeEnchantment(Enchantment.getByName(ench.split("-")[0]), Integer.parseInt(ench.split("-")[1])); 66 | } 67 | } 68 | 69 | @Deprecated 70 | public CustomItem(Material type, String name, String[] enchantments, int durability) { 71 | super(new ItemStack(type)); 72 | ItemMeta im = getItemMeta(); 73 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 74 | setItemMeta(im); 75 | setDurability((short) durability); 76 | for (String ench: enchantments) { 77 | addUnsafeEnchantment(Enchantment.getByName(ench.split("-")[0]), Integer.parseInt(ench.split("-")[1])); 78 | } 79 | } 80 | 81 | @Deprecated 82 | public CustomItem(Material type, String name, int durability) { 83 | super(new ItemStack(type)); 84 | ItemMeta im = getItemMeta(); 85 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 86 | setItemMeta(im); 87 | setDurability((short) durability); 88 | } 89 | 90 | public CustomItem(ItemStack item, String name) { 91 | super(item); 92 | ItemMeta im = getItemMeta(); 93 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 94 | setItemMeta(im); 95 | } 96 | 97 | public CustomItem(ItemStack item, String name, String... lore) { 98 | super(item); 99 | ItemMeta im = getItemMeta(); 100 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 101 | List lines = new ArrayList(); 102 | for (String line: lore) { 103 | lines.add(ChatColor.translateAlternateColorCodes('&', line)); 104 | } 105 | im.setLore(lines); 106 | setItemMeta(im); 107 | } 108 | 109 | @Deprecated 110 | public CustomItem(Material type, int durability) { 111 | super(new ItemStack(type)); 112 | setDurability((short) durability); 113 | } 114 | 115 | @Deprecated 116 | public CustomItem(Material type, int durability, int amount) { 117 | super(new ItemStack(type, amount)); 118 | setDurability((short) durability); 119 | } 120 | 121 | public CustomItem(ItemStack item, int amount) { 122 | super(item.clone()); 123 | setAmount(amount); 124 | } 125 | 126 | @Deprecated 127 | public CustomItem(Material type, String name, int durability, int amount, List lore) { 128 | super(new ItemStack(type, amount)); 129 | ItemMeta im = getItemMeta(); 130 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 131 | im.setLore(lore); 132 | setItemMeta(im); 133 | setDurability((short) durability); 134 | } 135 | 136 | public CustomItem(Material type, String name, String... lore) { 137 | this(new ItemStack(type), name, lore); 138 | } 139 | 140 | @Deprecated 141 | public CustomItem(MaterialData data, String name, String... lore) { 142 | super(data.toItemStack(1)); 143 | ItemMeta im = getItemMeta(); 144 | im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); 145 | List lines = new ArrayList(); 146 | for (String line: lore) { 147 | lines.add(ChatColor.translateAlternateColorCodes('&', line)); 148 | } 149 | im.setLore(lines); 150 | setItemMeta(im); 151 | } 152 | 153 | @Deprecated 154 | public CustomItem(MaterialData data, int amount) { 155 | super(data.toItemStack(amount)); 156 | } 157 | 158 | public List getLore() { 159 | if (!hasItemMeta()) return new ArrayList(); 160 | else if (!getItemMeta().hasLore()) return new ArrayList(); 161 | else return getItemMeta().getLore(); 162 | } 163 | 164 | public String getDisplayName() { 165 | if (!hasItemMeta()) return ""; 166 | else if (!getItemMeta().hasDisplayName()) return ""; 167 | else return getItemMeta().getDisplayName(); 168 | } 169 | 170 | public boolean hasEnchantment(Enchantment enchantment) { 171 | return getEnchantments().containsKey(enchantment); 172 | } 173 | 174 | public int getEnchantmentLevel(Enchantment enchantment){ 175 | return hasEnchantment(enchantment) ? getEnchantmentLevel(enchantment):0; 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/CSCoreLib.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin; 2 | 3 | import java.io.File; 4 | import java.util.HashSet; 5 | import java.util.Random; 6 | import java.util.Set; 7 | import java.util.UUID; 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | 11 | import org.apache.logging.log4j.Level; 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Marker; 14 | import org.apache.logging.log4j.core.Filter; 15 | import org.apache.logging.log4j.core.LogEvent; 16 | import org.apache.logging.log4j.core.Logger; 17 | import org.apache.logging.log4j.core.filter.AbstractFilter; 18 | import org.apache.logging.log4j.message.Message; 19 | import org.bstats.bukkit.Metrics; 20 | import org.bukkit.Bukkit; 21 | import org.bukkit.command.Command; 22 | import org.bukkit.command.CommandSender; 23 | import org.bukkit.entity.Player; 24 | import org.bukkit.plugin.java.JavaPlugin; 25 | 26 | import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; 27 | import me.mrCookieSlime.CSCoreLibPlugin.events.Listeners.ItemUseListener; 28 | import me.mrCookieSlime.CSCoreLibPlugin.events.Listeners.MapListener; 29 | import me.mrCookieSlime.CSCoreLibPlugin.events.Listeners.MenuClickListener; 30 | import me.mrCookieSlime.CSCoreLibPlugin.events.Listeners.StatisticListener; 31 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay; 32 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Maps; 33 | import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.MenuHelper; 34 | import me.mrCookieSlime.CSCoreLibPlugin.general.Player.PlayerStats; 35 | import me.mrCookieSlime.CSCoreLibPlugin.protection.ProtectionManager; 36 | 37 | @Deprecated 38 | public class CSCoreLib extends JavaPlugin { 39 | 40 | private static Random random; 41 | private PluginUtils utils; 42 | private static CSCoreLib instance; 43 | private Config cfg; 44 | 45 | private ProtectionManager manager; 46 | 47 | private Set log_patterns = new HashSet<>(); 48 | 49 | @Override 50 | public void onEnable() { 51 | 52 | if (!new File("data-storage/CS-CoreLib/PlayerStats").exists()) new File("data-storage/CS-CoreLib/PlayerStats").mkdirs(); 53 | 54 | new ItemUseListener(this); 55 | new MapListener(this); 56 | new MenuClickListener(this); 57 | new StatisticListener(this); 58 | getServer().getPluginManager().registerEvents(new MenuHelper(), this); 59 | 60 | random = new Random(); 61 | new Maps(); 62 | 63 | this.manager = new ProtectionManager(); 64 | 65 | utils = new PluginUtils(this); 66 | utils.setupConfig(); 67 | 68 | cfg = utils.getConfig(); 69 | cfg.setDefaultValue("skulls.uuid", UUID.randomUUID().toString()); 70 | cfg.save(); 71 | 72 | utils.setupUpdater(88802, getFile()); 73 | new Metrics(this, 4573); 74 | instance = this; 75 | 76 | ((Logger) LogManager.getRootLogger()).addFilter(new AbstractFilter() { 77 | 78 | public Filter.Result filter(final String logger, final String message, final Level level) { 79 | if (message == null) return Filter.Result.NEUTRAL; 80 | for (Pattern pattern: log_patterns) { 81 | final Matcher matcher = pattern.matcher(message); 82 | if (matcher.matches()) { 83 | return Filter.Result.DENY; 84 | } 85 | } 86 | return Filter.Result.NEUTRAL; 87 | } 88 | 89 | public Filter.Result filter(final LogEvent event) { 90 | return this.filter(event.getLoggerName(), event.getMessage().getFormattedMessage(), event.getLevel()); 91 | } 92 | 93 | public Filter.Result filter(final Logger logger, final Level level, final Marker marker, final String message, final Object... parameters) { 94 | return this.filter(logger.getName(), message, level); 95 | } 96 | 97 | public Filter.Result filter(final Logger logger, final Level level, final Marker marker, final Object message, final Throwable t) { 98 | return this.filter(logger.getName(), message.toString(), level); 99 | } 100 | 101 | public Filter.Result filter(final Logger logger, final Level level, final Marker marker, final Message message, final Throwable t) { 102 | return this.filter(logger.getName(), message.getFormattedMessage(), level); 103 | } 104 | 105 | }); 106 | 107 | filterLog("([A-Za-z0-9_]{3,16}) issued server command: /cs_triggerinterface (.{0,})"); 108 | 109 | getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> 110 | manager = new ProtectionManager(instance)); 111 | } 112 | 113 | public void filterLog(String pattern) { 114 | this.log_patterns.add(Pattern.compile(pattern)); 115 | } 116 | 117 | @Override 118 | public void onDisable() { 119 | for (Player p: Bukkit.getOnlinePlayers()) { 120 | PlayerStats.unregister(p); 121 | } 122 | 123 | random = null; 124 | Maps.instance = null; 125 | instance = null; 126 | MenuHelper.map = null; 127 | CustomBookOverlay.opening = null; 128 | PlayerRunnable.map = null; 129 | } 130 | 131 | /** 132 | * Returns a global Random Instance 133 | * 134 | * @return Random Instance 135 | */ 136 | @Deprecated 137 | public static Random randomizer() { 138 | return random; 139 | } 140 | 141 | /** 142 | * Returns the Instance of CS-CoreLibs main class 143 | * 144 | * @return CS-CoreLibs main class 145 | */ 146 | public static CSCoreLib getLib() { 147 | return instance; 148 | } 149 | 150 | /** 151 | * Returns CS-CoreLib's Config 152 | * 153 | * @return CS-CoreLibs Config 154 | */ 155 | public Config getCfg() { 156 | return cfg; 157 | } 158 | 159 | /** 160 | * Returns a ProtectionManager 161 | * 162 | * @return ProtectionManager 163 | */ 164 | @Deprecated 165 | public ProtectionManager getProtectionManager() { 166 | return this.manager; 167 | } 168 | 169 | @Override 170 | public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { 171 | if (sender instanceof Player && args.length == 1) { 172 | PlayerRunnable.run(args[0], (Player) sender); 173 | } 174 | return true; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibSetup/CSCoreLibLoader.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibSetup; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedReader; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.HttpURLConnection; 10 | import java.net.MalformedURLException; 11 | import java.net.URL; 12 | import java.net.URLConnection; 13 | 14 | import org.bukkit.plugin.Plugin; 15 | 16 | import com.google.gson.JsonArray; 17 | import com.google.gson.JsonObject; 18 | import com.google.gson.JsonParser; 19 | 20 | public class CSCoreLibLoader { 21 | 22 | Plugin plugin; 23 | URL url; 24 | URL download; 25 | File file; 26 | 27 | public CSCoreLibLoader(Plugin plugin) { 28 | this.plugin = plugin; 29 | try { 30 | this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=88802"); 31 | } catch (MalformedURLException e) { 32 | } 33 | } 34 | 35 | public boolean load() { 36 | if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) return true; 37 | else { 38 | System.err.println(" "); 39 | System.err.println("#################### - INFO - ####################"); 40 | System.err.println(" "); 41 | System.err.println(plugin.getName() + " could not be loaded."); 42 | System.err.println("It appears that you have not installed CS-CoreLib"); 43 | System.err.println("Your Server will now try to download and install"); 44 | System.err.println("CS-CoreLib for you."); 45 | System.err.println("You will be asked to restart your Server when it's finished."); 46 | System.err.println("If this somehow fails, please download and install CS-CoreLib manually:"); 47 | System.err.println("https://dev.bukkit.org/projects/cs-corelib"); 48 | System.err.println(" "); 49 | System.err.println("#################### - INFO - ####################"); 50 | System.err.println(" "); 51 | plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { 52 | if (connect()) install(); 53 | }, 10L); 54 | return false; 55 | } 56 | } 57 | 58 | private boolean connect() { 59 | try { 60 | final URLConnection connection = this.url.openConnection(); 61 | connection.setConnectTimeout(5000); 62 | connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)"); 63 | connection.setDoOutput(true); 64 | 65 | final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 66 | final JsonArray array = new JsonParser().parse(reader).getAsJsonArray(); 67 | final JsonObject json = array.get(array.size() - 1).getAsJsonObject(); 68 | 69 | download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:")); 70 | file = new File("plugins/" + json.get("name").getAsString() + ".jar"); 71 | 72 | return true; 73 | } catch (IOException e) { 74 | System.err.println(" "); 75 | System.err.println("#################### - WARNING - ####################"); 76 | System.err.println(" "); 77 | System.err.println("Could not connect to BukkitDev."); 78 | System.err.println("Please download & install CS-CoreLib manually:"); 79 | System.err.println("https://dev.bukkit.org/projects/cs-corelib"); 80 | System.err.println(" "); 81 | System.err.println("#################### - WARNING - ####################"); 82 | System.err.println(" "); 83 | return false; 84 | } 85 | } 86 | 87 | private URL traceURL(String location) throws IOException { 88 | HttpURLConnection connection = null; 89 | 90 | while (true) { 91 | URL url = new URL(location); 92 | connection = (HttpURLConnection) url.openConnection(); 93 | 94 | connection.setInstanceFollowRedirects(false); 95 | connection.setConnectTimeout(5000); 96 | connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); 97 | 98 | switch (connection.getResponseCode()) { 99 | case HttpURLConnection.HTTP_MOVED_PERM: 100 | case HttpURLConnection.HTTP_MOVED_TEMP: 101 | String loc = connection.getHeaderField("Location"); 102 | location = new URL(new URL(location), loc).toExternalForm(); 103 | continue; 104 | } 105 | break; 106 | } 107 | 108 | return new URL(connection.getURL().toString().replaceAll(" ", "%20")); 109 | } 110 | 111 | private void install() { 112 | BufferedInputStream input = null; 113 | FileOutputStream output = null; 114 | try { 115 | input = new BufferedInputStream(download.openStream()); 116 | output = new FileOutputStream(file); 117 | 118 | final byte[] data = new byte[1024]; 119 | int read; 120 | while ((read = input.read(data, 0, 1024)) != -1) { 121 | output.write(data, 0, read); 122 | } 123 | } catch (Exception ex) { 124 | System.err.println(" "); 125 | System.err.println("#################### - WARNING - ####################"); 126 | System.err.println(" "); 127 | System.err.println("Failed to download CS-CoreLib"); 128 | System.err.println("Please download & install CS-CoreLib manually:"); 129 | System.err.println("https://dev.bukkit.org/projects/cs-corelib"); 130 | System.err.println(" "); 131 | System.err.println("#################### - WARNING - ####################"); 132 | System.err.println(" "); 133 | } finally { 134 | try { 135 | if (input != null) input.close(); 136 | if (output != null) output.close(); 137 | System.err.println(" "); 138 | System.err.println("#################### - INFO - ####################"); 139 | System.err.println(" "); 140 | System.err.println("Please restart your Server to finish the Installation"); 141 | System.err.println("of " + plugin.getName() + " and CS-CoreLib"); 142 | System.err.println(" "); 143 | System.err.println("#################### - INFO - ####################"); 144 | System.err.println(" "); 145 | } catch (IOException e) { 146 | e.printStackTrace(); 147 | } 148 | } 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Chat/TellRawMessage.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Chat; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.lang.reflect.Method; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable; 10 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.PackageName; 11 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 12 | 13 | import org.bukkit.ChatColor; 14 | import org.bukkit.entity.Player; 15 | 16 | import com.google.gson.JsonObject; 17 | import com.google.gson.JsonPrimitive; 18 | 19 | @Deprecated 20 | public class TellRawMessage { 21 | 22 | private static final List special = Arrays.asList(ChatColor.ITALIC, ChatColor.MAGIC, ChatColor.BOLD, ChatColor.UNDERLINE, ChatColor.STRIKETHROUGH); 23 | private List text = new ArrayList<>(); 24 | 25 | private static Constructor constructor; 26 | private static Class serializer; 27 | private static Method method; 28 | 29 | static { 30 | try { 31 | constructor = ReflectionUtils.getClass("PacketPlayOutChat").getConstructor(ReflectionUtils.getClass("IChatBaseComponent")); 32 | serializer = ReflectionUtils.tryClass(PackageName.NMS, "ChatSerializer", "IChatBaseComponent$ChatSerializer"); 33 | 34 | method = ReflectionUtils.tryMethod(serializer, new String[] {"b", "a"}, String.class); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | public enum ClickAction { 41 | RUN_COMMAND, 42 | SUGGEST_COMMAND, 43 | OPEN_URL, 44 | CHANGE_PAGE; 45 | } 46 | 47 | public enum HoverAction { 48 | SHOW_TEXT, 49 | SHOW_ITEM, 50 | SHOW_ENTITY, 51 | SHOW_ACHIEVEMENT; 52 | } 53 | 54 | /** 55 | * Creates a new Instance 56 | */ 57 | public TellRawMessage() { 58 | } 59 | 60 | /** 61 | * Creates a new Instance and adds some Text 62 | * 63 | * @param text The Text you want to add 64 | */ 65 | public TellRawMessage(String text) { 66 | addText(text); 67 | } 68 | 69 | /** 70 | * Returns a String Object containing the previously 71 | * defined JSON fragments 72 | * 73 | * @return Converted JSON String 74 | */ 75 | public String build() { 76 | String extra = ""; 77 | if (text.size() > 0) { 78 | StringBuilder extras = new StringBuilder(); 79 | for (String msg: text) { 80 | extras.append(msg + ","); 81 | } 82 | extra = extras.toString().substring(0, extras.toString().length() - 1); 83 | } 84 | return "{text:\"\",extra:[" + extra + "]}"; 85 | } 86 | 87 | /** 88 | * Adds the specified Line of Text to your JSON Message 89 | * 90 | * @param text The Text you want to add 91 | * @return This Instance 92 | */ 93 | public TellRawMessage addText(String text) { 94 | this.text.add("{text:" + escape(text) + "}"); 95 | return this; 96 | } 97 | 98 | private String escape(String text) { 99 | String msg = ChatColor.translateAlternateColorCodes('&', text); 100 | return new JsonPrimitive(msg).toString(); 101 | } 102 | 103 | /** 104 | * Adds a Text to the Message depending on the Users 105 | * Language 106 | * 107 | * @param key The Key which is found in the .lang File 108 | * @return This Instance 109 | */ 110 | public TellRawMessage addTranslation(String key) { 111 | this.text.add("{translate:" + key + "}"); 112 | return this; 113 | } 114 | 115 | /** 116 | * Colors the previously added fragment 117 | * 118 | * @param color The Color you want to add 119 | * @return This Instance 120 | */ 121 | public TellRawMessage color(ChatColor color) { 122 | append(special.contains(color) ? color.name().toLowerCase() + ":true" : "color:" + color.name().toLowerCase()); 123 | return this; 124 | } 125 | 126 | /** 127 | * Adds a ClickEvent to the previously added 128 | * fragment 129 | * 130 | * @param action The Action that will be run 131 | * @param value The Value for that Action 132 | * @return This Instance 133 | */ 134 | public TellRawMessage addClickEvent(ClickAction action, String value) { 135 | append("clickEvent:{action:" + action.toString().toLowerCase() + ",value:" + escape(value) + "}"); 136 | return this; 137 | } 138 | 139 | /** 140 | * Adds a ClickEvent to the previously added 141 | * fragment 142 | * 143 | * @param runnable The Runnable that will be run 144 | * @return This Instance 145 | */ 146 | public TellRawMessage addClickEvent(PlayerRunnable runnable) { 147 | append("clickEvent:{action:run_command,value:\"" + "/cs_triggerinterface " + runnable.getID() + "\"}"); 148 | return this; 149 | } 150 | 151 | /** 152 | * Adds a HoverEvent to the previously added 153 | * fragment 154 | * 155 | * @param action The Action that will be run 156 | * @param value The Value for that Action 157 | * @return This Instance 158 | */ 159 | public TellRawMessage addHoverEvent(HoverAction action, String value) { 160 | append("hoverEvent:{action:" + action.toString().toLowerCase() + ",value:" + escape(value) + "}"); 161 | return this; 162 | } 163 | 164 | /** 165 | * Appends a Color or an Event to the previous fragment 166 | * 167 | * @param addition The Color or Event that will be appended to the previous fragment 168 | */ 169 | private void append(String addition) { 170 | String last = text.get(text.size() - 1); 171 | last = last.substring(0, last.length() - 1) + "," + addition + "}"; 172 | text.remove(text.size() - 1); 173 | text.add(last); 174 | } 175 | 176 | /** 177 | * Prepares the JSON Message to be sent 178 | * 179 | * @return The serialized String 180 | * @throws Exception 181 | */ 182 | public Object getSerializedString() throws Exception { 183 | String string = build(); 184 | try { 185 | Object obj = method.invoke(serializer, string); 186 | return obj; 187 | } catch(Exception x) { 188 | System.err.println(string); 189 | throw x; 190 | } 191 | } 192 | 193 | /** 194 | * Sends the JSON Message to the specified 195 | * Players 196 | * 197 | * @param players All Players who should receive the Message 198 | * @throws Exception 199 | */ 200 | public void send(Player... players) throws Exception { 201 | Object packet = constructor.newInstance(getSerializedString()); 202 | for (Player p: players) { 203 | ReflectionUtils.sendPacket(p, packet); 204 | } 205 | } 206 | 207 | } 208 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/World/CustomSkull.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.World; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.lang.reflect.Method; 6 | import java.util.Collection; 7 | import java.util.UUID; 8 | 9 | import org.bukkit.Material; 10 | import org.bukkit.block.Block; 11 | import org.bukkit.inventory.ItemStack; 12 | import org.bukkit.inventory.meta.ItemMeta; 13 | import org.bukkit.inventory.meta.SkullMeta; 14 | 15 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 16 | import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHook; 17 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.CraftObject; 18 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.PackageName; 19 | import me.mrCookieSlime.CSCoreLibPlugin.general.Reflection.ReflectionUtils; 20 | 21 | @Deprecated 22 | public class CustomSkull { 23 | 24 | private static Method tileentity, gameprofile, getgameprofile, property, insert_property, map_list, get_name, get_value, getOwner; 25 | private static Constructor position, profile_constructor, property_constructor; 26 | private static Class profile_class, property_class, map_class; 27 | 28 | static { 29 | try { 30 | profile_class = Class.forName("com.mojang.authlib.GameProfile"); 31 | property_class = Class.forName("com.mojang.authlib.properties.Property"); 32 | map_class = Class.forName("com.mojang.authlib.properties.PropertyMap"); 33 | 34 | profile_constructor = ReflectionUtils.getConstructor(profile_class, UUID.class, String.class); 35 | property = ReflectionUtils.getMethod(profile_class, "getProperties"); 36 | property_constructor = ReflectionUtils.getConstructor(property_class, String.class, String.class); 37 | insert_property = ReflectionUtils.getMethod(map_class, "put", String.class, property_class); 38 | map_list = ReflectionUtils.getMethod(map_class, "get", String.class); 39 | gameprofile = ReflectionUtils.getClass(PackageName.NMS, "TileEntitySkull").getMethod("setGameProfile", profile_class); 40 | 41 | // Removed from 1.14 42 | if (!ReflectionUtils.isVersion("v1_14_", "v1_15_")) 43 | getgameprofile = ReflectionUtils.getClass(PackageName.NMS, "TileEntitySkull").getMethod("getGameProfile"); 44 | 45 | getOwner = ReflectionUtils.getMethod(profile_class, "getName"); 46 | get_name = ReflectionUtils.getMethod(property_class, "getName"); 47 | get_value = ReflectionUtils.getMethod(property_class, "getValue"); 48 | 49 | position = ReflectionUtils.getConstructor(ReflectionUtils.getClass(PackageName.NMS, "BlockPosition"), int.class, int.class, int.class); 50 | tileentity = ReflectionUtils.getClass(PackageName.NMS, "WorldServer").getMethod("getTileEntity", ReflectionUtils.getClass(PackageName.NMS, "BlockPosition")); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | private static Object createProfile(String texture) throws Exception { 57 | if (!CSCoreLib.getLib().getCfg().contains("skulls.uuids." + texture)) { 58 | CSCoreLib.getLib().getCfg().setValue("skulls.uuids." + texture, UUID.randomUUID().toString()); 59 | CSCoreLib.getLib().getCfg().save(); 60 | } 61 | Object profile = profile_constructor.newInstance(UUID.fromString(CSCoreLib.getLib().getCfg().getString("skulls.uuids." + texture)), "CSCoreLib"); 62 | Object properties = property.invoke(profile); 63 | insert_property.invoke(properties, "textures", property_constructor.newInstance("textures", texture)); 64 | return profile; 65 | } 66 | 67 | /** 68 | * Sets the Skull at that Location to be the Skin of the specified Base64 String 69 | * 70 | * @param block The Block being set to that Skin 71 | * @param texture A Base64 String representing the Texture 72 | */ 73 | public static void setSkull(Block block, String texture) throws Exception { 74 | if (getTexture(block).equals(texture)) return; 75 | 76 | if (ReflectionUtils.isVersion("v1_12_")) { 77 | if (!block.getType().equals(Material.valueOf("SKULL"))) { 78 | throw new IllegalArgumentException("Block is not a Skull"); 79 | } 80 | } 81 | else { 82 | if (!(block.getType().equals(Material.valueOf("PLAYER_HEAD")) || block.getType().equals(Material.valueOf("PLAYER_WALL_HEAD")))) { 83 | throw new IllegalArgumentException("Block is not a Skull"); 84 | } 85 | } 86 | 87 | Object profile = createProfile(texture); 88 | Object world = ReflectionUtils.getHandle(CraftObject.WORLD, block.getWorld()); 89 | 90 | Object tile = tileentity.invoke(world, position.newInstance(block.getX(), block.getY(), block.getZ())); 91 | 92 | try { 93 | if (tile != null){ 94 | gameprofile.invoke(tile, profile); 95 | block.getState().update(true); 96 | } 97 | } catch(NullPointerException x) { 98 | System.err.println("Method: " + gameprofile); 99 | System.err.println("World: " + world); 100 | System.err.println("Tile Retriever: " + tileentity); 101 | System.err.println("Tile: " + tile); 102 | System.err.println("Profile Retriever: " + gameprofile); 103 | System.err.println("Profile: " + profile); 104 | x.printStackTrace(); 105 | } 106 | } 107 | 108 | /** 109 | * Returns a Skull Item with the specified Texture 110 | * 111 | * @param texture A Base64 String representing the Texture 112 | * @return The modified ItemStack 113 | */ 114 | public static ItemStack getItem(String texture) throws Exception { 115 | Object profile = createProfile(texture); 116 | ItemStack item = new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM")); 117 | 118 | ItemMeta im = item.getItemMeta(); 119 | ReflectionUtils.setFieldValue(im, "profile", profile); 120 | item.setItemMeta(im); 121 | return item; 122 | } 123 | 124 | /** 125 | * Sets the specified Skull to have the specified Texture 126 | * 127 | * @param item The ItemStack you want to modify 128 | * @param texture A Base64 String representing the Texture 129 | * @return The modified ItemStack 130 | */ 131 | public static ItemStack getItem(ItemStack item, String texture) throws Exception { 132 | if (texture == null) return item; 133 | Object profile = createProfile(texture); 134 | ItemMeta im = item.getItemMeta(); 135 | ReflectionUtils.setFieldValue(im, "profile", profile); 136 | item.setItemMeta(im); 137 | return item; 138 | } 139 | 140 | /** 141 | * Returns the Base64 String representing the Texture of the specified item 142 | * 143 | * @param item The ItemStack you want to retrieve the Data from 144 | * @return The found Base64 String representing the Texture 145 | * @throws InvocationTargetException 146 | * @throws IllegalAccessException 147 | * @throws IllegalArgumentException 148 | */ 149 | public static String getTexture(ItemStack item) { 150 | if (!(item.getItemMeta() instanceof SkullMeta)) return null; 151 | Object profile = null; 152 | try { 153 | profile = ReflectionUtils.getFieldValue(item.getItemMeta(), "profile"); 154 | Collection collection = (Collection) map_list.invoke(property.invoke(profile), "textures"); 155 | for (Object p: collection) { 156 | if (get_name.invoke(p).equals("textures")) return (String) get_value.invoke(p); 157 | } 158 | } catch (Exception e) { 159 | return null; 160 | } 161 | return null; 162 | } 163 | 164 | public static String getTexture(Block block) throws Exception { 165 | Object world = ReflectionUtils.getHandle(CraftObject.WORLD, block.getWorld()); 166 | 167 | Object tile = tileentity.invoke(world, position.newInstance(block.getX(), block.getY(), block.getZ())); 168 | if (tile == null) return ""; 169 | 170 | Object profile; 171 | 172 | if (ReflectionUtils.isVersion("v1_14_", "v1_15_")) 173 | profile = ReflectionUtils.getFieldValue(tile, "gameProfile"); 174 | else 175 | profile = getgameprofile.invoke(tile); 176 | 177 | if (profile != null) { 178 | Collection collection = (Collection) map_list.invoke(property.invoke(profile), "textures"); 179 | for (Object p: collection) { 180 | if (get_name.invoke(p).equals("textures")) return (String) get_value.invoke(p); 181 | } 182 | } 183 | 184 | return ""; 185 | } 186 | 187 | /** 188 | * Returns the Skull Owner of that Skull 189 | * 190 | * @param item The ItemStack you want to retrieve the Data from 191 | * @return The found Skull Owner 192 | * @throws InvocationTargetException 193 | * @throws IllegalAccessException 194 | * @throws IllegalArgumentException 195 | */ 196 | public static Object getName(ItemStack item) { 197 | if (!(item.getItemMeta() instanceof SkullMeta)) return "CSCoreLib"; 198 | try { 199 | return getOwner.invoke(ReflectionUtils.getFieldValue(item.getItemMeta(), "profile")); 200 | } catch (Exception e) { 201 | return "CSCoreLib"; 202 | } 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Particles/MC_1_13/ParticleEffect.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Particles.MC_1_13; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import org.bukkit.Color; 8 | import org.bukkit.Location; 9 | import org.bukkit.Material; 10 | import org.bukkit.Particle; 11 | import org.bukkit.Particle.DustOptions; 12 | import org.bukkit.entity.Player; 13 | 14 | @Deprecated 15 | public enum ParticleEffect { 16 | 17 | BARRIER(ParticleType.NORMAL), 18 | BLOCK_CRACK(ParticleType.CRACK), 19 | BLOCK_DUST(ParticleType.CRACK), 20 | CLOUD(ParticleType.NORMAL), 21 | CRIT(ParticleType.NORMAL), 22 | CRIT_MAGIC(ParticleType.NORMAL), 23 | DRIP_LAVA(ParticleType.NORMAL), 24 | DRIP_WATER(ParticleType.NORMAL), 25 | ENCHANTMENT_TABLE(ParticleType.NORMAL), 26 | EXPLOSION_HUGE(ParticleType.NORMAL), 27 | EXPLOSION_LARGE(ParticleType.NORMAL), 28 | EXPLOSION_NORMAL(ParticleType.NORMAL), 29 | FIREWORKS_SPARK(ParticleType.NORMAL), 30 | FLAME(ParticleType.NORMAL), 31 | FOOTSTEP(ParticleType.NORMAL), 32 | HEART(ParticleType.NORMAL), 33 | ITEM_CRACK(ParticleType.CRACK), 34 | ITEM_TAKE(ParticleType.NORMAL), 35 | LAVA(ParticleType.NORMAL), 36 | MOB_APPEARANCE(ParticleType.NORMAL), 37 | NOTE(ParticleType.NORMAL), 38 | PORTAL(ParticleType.NORMAL), 39 | REDSTONE(ParticleType.COLORED), 40 | SLIME(ParticleType.NORMAL), 41 | SMOKE_LARGE(ParticleType.NORMAL), 42 | SMOKE_NORMAL(ParticleType.NORMAL), 43 | SNOW_SHOVEL(ParticleType.NORMAL), 44 | SNOWBALL(ParticleType.NORMAL), 45 | SPELL(ParticleType.NORMAL), 46 | SPELL_INSTANT(ParticleType.NORMAL), 47 | SPELL_MOB(ParticleType.COLORED), 48 | SPELL_MOB_AMBIENT(ParticleType.COLORED), 49 | SPELL_WITCH(ParticleType.NORMAL), 50 | SUSPENDED(ParticleType.NORMAL), 51 | SUSPENDED_DEPTH(ParticleType.NORMAL), 52 | TOWN_AURA(ParticleType.NORMAL), 53 | VILLAGER_ANGRY(ParticleType.NORMAL), 54 | VILLAGER_HAPPY(ParticleType.NORMAL), 55 | WATER_BUBBLE(ParticleType.NORMAL), 56 | WATER_DROP(ParticleType.NORMAL), 57 | WATER_SPLASH(ParticleType.NORMAL), 58 | WATER_WAKE(ParticleType.NORMAL), 59 | DRAGON_BREATH(ParticleType.NORMAL), 60 | END_ROD(ParticleType.NORMAL), 61 | DAMAGE_INDICATOR(ParticleType.NORMAL), 62 | SWEEP_ATTACK(ParticleType.NORMAL); 63 | 64 | private ParticleType type; 65 | 66 | ParticleEffect(ParticleType type) { 67 | try { 68 | this.type = type; 69 | } catch (SecurityException e) { 70 | e.printStackTrace(); 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | 76 | /** 77 | * Displays a Particle assigned with the COLORED/NORMAL Type 78 | * 79 | * @param l The Location where the Particle should be displayed 80 | * @param offsetX The Offset on the X-Axis 81 | * @param offsetY The Offset on the Y-Axis 82 | * @param offsetZ The Offset on the Z-Axis 83 | * @param speed The Speed of the Particle 84 | * @param amount The Amount of Particles which should be displayed 85 | */ 86 | public void display(Location l, float offsetX, float offsetY, float offsetZ, float speed, int amount) throws Exception { 87 | this.display(l, offsetX, offsetY, offsetZ, speed, amount, getPlayers(l)); 88 | } 89 | 90 | /** 91 | * Displays a Particle assigned with the COLORED/NORMAL Type 92 | * 93 | * @param l The Location where the Particle should be displayed 94 | * @param offsetX The Offset on the X-Axis 95 | * @param offsetY The Offset on the Y-Axis 96 | * @param offsetZ The Offset on the Z-Axis 97 | * @param speed The Speed of the Particle 98 | * @param amount The Amount of Particles which should be displayed 99 | * @param players The Player who is supposed to see the Particle 100 | */ 101 | public void display(Location l, float offsetX, float offsetY, float offsetZ, float speed, int amount, List players) throws Exception { 102 | if (type == ParticleType.CRACK) { 103 | System.err.println("Effect \"" + toString() + "\" cannot be displayed as its Type mismatches: " + type.toString() + " != " + ParticleType.NORMAL.toString()); 104 | return; 105 | } 106 | 107 | if(toString().equals("REDSTONE")) { 108 | DustOptions dustOptions = new DustOptions(Color.RED, amount); 109 | for (Player p: players) { 110 | p.spawnParticle(Particle.valueOf(toString()), l, amount, offsetX, offsetY, offsetZ, speed, dustOptions); 111 | } 112 | } else { 113 | for (Player p: players) { 114 | p.spawnParticle(Particle.valueOf(toString()), l, amount, offsetX, offsetY, offsetZ, speed); 115 | } 116 | } 117 | } 118 | 119 | /** 120 | * Displays a Particle assigned with the CRACK type 121 | * 122 | * @param l The Location where the Particle should be displayed 123 | * @param data The Item/Block Data which should be used 124 | * @param offsetX The Offset on the X-Axis 125 | * @param offsetY The Offset on the Y-Axis 126 | * @param offsetZ The Offset on the Z-Axis 127 | * @param speed The Speed of the Particle 128 | * @param amount The Amount of Particles which should be displayed 129 | */ 130 | public void displayCrack(Location l, Material material, float offsetX, float offsetY, float offsetZ, float speed, int amount) throws Exception { 131 | if (type != ParticleType.CRACK) { 132 | System.err.println("Effect \"" + toString() + "\" cannot be displayed as its Type mismatches: " + type.toString() + " != " + ParticleType.CRACK.toString()); 133 | return; 134 | } 135 | 136 | for (Player p: getPlayers(l)) { 137 | p.spawnParticle(Particle.valueOf(toString()), l, amount,offsetX, offsetY, offsetZ, speed, material.createBlockData()); 138 | } 139 | } 140 | 141 | /** 142 | * Displays a Particle with a certain Color 143 | * Note: This only works with Particles assigned with the 144 | * COLORED type 145 | * 146 | * @param l The Location where the Particle should be displayed 147 | * @param color The Color your Particle should have 148 | */ 149 | public void displayColoredParticle(Location l, Color color) throws Exception { 150 | if (type != ParticleType.COLORED) { 151 | System.err.println("Effect \"" + toString() + "\" cannot be displayed as its Type mismatches: " + type.toString() + " != " + ParticleType.COLORED.toString()); 152 | return; 153 | } 154 | if(toString().equals("REDSTONE")) { 155 | DustOptions dustOptions = new DustOptions(color, 1); 156 | for (Player p: getPlayers(l)) { 157 | p.spawnParticle(Particle.valueOf(toString()), l, 1, 0, 0, 0, 1, dustOptions); 158 | } 159 | } else { 160 | display(l, color.getRed() / 255, color.getGreen() / 255, color.getBlue() / 255, 1, 0); 161 | } 162 | } 163 | 164 | /** 165 | * Returns a List of Players who are in Range of the Particle 166 | * 167 | * @return All Players in viewable Distance 168 | */ 169 | private List getPlayers(Location l) { 170 | return getPlayers(l, 300); 171 | } 172 | 173 | public static List getPlayers(Location l, int radius) { 174 | List players = new ArrayList(l.getWorld().getPlayers()); 175 | 176 | Iterator iterator = players.iterator(); 177 | while (iterator.hasNext()) { 178 | Player p = iterator.next(); 179 | if (!p.getWorld().getUID().equals(l.getWorld().getUID()) || p.getLocation().distanceSquared(l) > radius) { 180 | iterator.remove(); 181 | } 182 | } 183 | return players; 184 | } 185 | 186 | public void drawLine(Location l1, Location l2, List players) throws Exception { 187 | List error = new ArrayList(); 188 | 189 | if (l1.getBlockX() != l2.getBlockX()) error.add(Axis.X); 190 | if (l1.getBlockY() != l2.getBlockY()) error.add(Axis.Y); 191 | if (l1.getBlockZ() != l2.getBlockZ()) error.add(Axis.Z); 192 | 193 | if (error.size() > 1) { 194 | System.err.println("[CS-CoreLib - Particles] Could not display Particle Effect \"" + toString() + "\" in a Line as more than 1 Axis mismatched"); 195 | return; 196 | } 197 | 198 | switch (error.get(0)) { 199 | case X: { 200 | double deltaX = l2.getX() - l1.getX(); 201 | display(new Location(l1.getWorld(), l1.getX() + (deltaX / 2), l1.getY(), l1.getZ()), 0.25F * Math.abs((int) deltaX), 0F, 0F, 0F, Math.abs((int) deltaX) * 6, players); 202 | break; 203 | } 204 | case Y: { 205 | double deltaY = l2.getY() - l1.getY(); 206 | display(new Location(l1.getWorld(), l1.getX(), l1.getY() + (deltaY / 2), l1.getZ()), 0F, 0.25F * Math.abs((int) deltaY), 0F, 0F, Math.abs((int) deltaY) * 6, players); 207 | break; 208 | } 209 | case Z: { 210 | double deltaZ = l2.getZ() - l1.getZ(); 211 | display(new Location(l1.getWorld(), l1.getX(), l1.getY(), l1.getZ() + (deltaZ / 2)), 0F, 0F, 0.25F * Math.abs((int) deltaZ), 0F, Math.abs((int) deltaZ) * 6, players); 212 | break; 213 | } 214 | default: 215 | break; 216 | } 217 | } 218 | 219 | public void drawLine(Location l1, Location l2) throws Exception { 220 | this.drawLine(l1, l2, getPlayers(l1)); 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/updater/Updater.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.updater; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedReader; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.HttpURLConnection; 10 | import java.net.MalformedURLException; 11 | import java.net.URL; 12 | import java.net.URLConnection; 13 | 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.plugin.Plugin; 16 | 17 | import com.google.gson.JsonArray; 18 | import com.google.gson.JsonObject; 19 | import com.google.gson.JsonParser; 20 | 21 | @Deprecated 22 | public class Updater { 23 | 24 | private static final char[] blacklist = "abcdefghijklmnopqrstuvwxyz-+_ ()[]".toCharArray(); 25 | private static final String[] development_builds = {"DEV", "EXPERIMENTAL", "BETA", "ALPHA", "UNFINISHED"}; 26 | 27 | Plugin plugin; 28 | URL url; 29 | String localVersion; 30 | Thread thread; 31 | URL download; 32 | File file; 33 | String version; 34 | 35 | public Updater(Plugin plugin, File file, int id) { 36 | this.plugin = plugin; 37 | this.file = file; 38 | localVersion = plugin.getDescription().getVersion(); 39 | 40 | // Checking if current Version is a dev-build 41 | for (String dev: development_builds) { 42 | if (localVersion.contains(dev)) { 43 | System.err.println(" "); 44 | System.err.println("################## - DEVELOPMENT BUILD - ##################"); 45 | System.err.println("You appear to be using an experimental build of " + plugin.getName()); 46 | System.err.println("Version " + localVersion); 47 | System.err.println(" "); 48 | System.err.println("Auto-Updates have been disabled. Use at your own risk!"); 49 | System.err.println(" "); 50 | return; 51 | } 52 | } 53 | 54 | localVersion = localVersion.toLowerCase(); 55 | 56 | // Deleting all unwanted characters 57 | for (char blocked: blacklist) { 58 | localVersion = localVersion.replace(String.valueOf(blocked), ""); 59 | } 60 | 61 | // Starting download 62 | try { 63 | this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=" + id); 64 | plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { 65 | 66 | @Override 67 | public void run() { 68 | thread = new Thread(new UpdaterTask()); 69 | thread.start(); 70 | } 71 | }, 0l); 72 | } catch (MalformedURLException e) { 73 | e.printStackTrace(); 74 | } 75 | } 76 | 77 | public class UpdaterTask implements Runnable { 78 | 79 | @Override 80 | public void run() { 81 | if (connect()) { 82 | try { 83 | check(); 84 | } catch(NumberFormatException x) { 85 | System.err.println(" "); 86 | System.err.println("#################### - ERROR - ####################"); 87 | System.err.println("Could not auto-update " + plugin.getName()); 88 | System.err.println("Unrecognized Version: \"" + localVersion + "\""); 89 | System.err.println("#################### - ERROR - ####################"); 90 | System.err.println(" "); 91 | } 92 | } 93 | } 94 | 95 | private boolean connect() { 96 | try { 97 | final URLConnection connection = url.openConnection(); 98 | connection.setConnectTimeout(5000); 99 | connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); 100 | connection.setDoOutput(true); 101 | 102 | final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 103 | 104 | final JsonArray array = (JsonArray) new JsonParser().parse(reader.readLine()); 105 | if (array.size() == 0) { 106 | System.err.println("[CS-CoreLib - Updater] Could not connect to BukkitDev for Plugin \"" + plugin.getName() + "\", is it down?"); 107 | try { 108 | thread.join(); 109 | } catch (InterruptedException x) { 110 | x.printStackTrace(); 111 | } 112 | return false; 113 | } 114 | JsonObject latest = array.get(array.size() - 1).getAsJsonObject(); 115 | 116 | download = traceURL(latest.get("downloadUrl").getAsString().replace("https:", "http:")); 117 | version = latest.getAsJsonObject().get("name").getAsString(); 118 | version = version.toLowerCase(); 119 | 120 | for (char blocked: blacklist) { 121 | version = version.replace(String.valueOf(blocked), ""); 122 | } 123 | return true; 124 | } catch (IOException e) { 125 | System.err.println("[" + plugin.getName() + " - Updater] Could not connect to BukkitDev, is it down?"); 126 | try { 127 | thread.join(); 128 | } catch (InterruptedException x) { 129 | x.printStackTrace(); 130 | } 131 | return false; 132 | } 133 | } 134 | 135 | private void check() { 136 | String[] localSplit = localVersion.split("\\."); 137 | String[] remoteSplit = version.split("\\."); 138 | 139 | for (int i = 0; i < remoteSplit.length; i++) { 140 | if ((localSplit.length - 1) < i) { 141 | install(); 142 | return; 143 | } 144 | if (Integer.parseInt(localSplit[i]) > Integer.parseInt(remoteSplit[i])) { 145 | try { 146 | thread.join(); 147 | } catch (InterruptedException x) { 148 | x.printStackTrace(); 149 | } 150 | return; 151 | } 152 | if (Integer.parseInt(remoteSplit[i]) > Integer.parseInt(localSplit[i])) { 153 | install(); 154 | return; 155 | } 156 | } 157 | System.out.println("[CS-CoreLib - Updater] " + plugin.getName() + " is up to date!"); 158 | try { 159 | thread.join(); 160 | } catch (InterruptedException x) { 161 | x.printStackTrace(); 162 | } 163 | } 164 | 165 | 166 | private URL traceURL(String location) throws IOException { 167 | HttpURLConnection connection = null; 168 | 169 | while (true) { 170 | URL url = new URL(location); 171 | connection = (HttpURLConnection) url.openConnection(); 172 | 173 | connection.setInstanceFollowRedirects(false); 174 | connection.setConnectTimeout(5000); 175 | connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)"); 176 | 177 | switch (connection.getResponseCode()) { 178 | case HttpURLConnection.HTTP_MOVED_PERM: 179 | case HttpURLConnection.HTTP_MOVED_TEMP: 180 | String loc = connection.getHeaderField("Location"); 181 | location = new URL(new URL(location), loc).toExternalForm(); 182 | continue; 183 | } 184 | break; 185 | } 186 | 187 | return new URL(connection.getURL().toString().replaceAll(" ", "%20")); 188 | } 189 | 190 | private void install() { 191 | System.out.println("[CS-CoreLib - Updater] " + plugin.getName() + " is outdated!"); 192 | System.out.println("[CS-CoreLib - Updater] Downloading " + plugin.getName() + " v" + version); 193 | plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { 194 | 195 | @Override 196 | public void run() { 197 | BufferedInputStream input = null; 198 | FileOutputStream output = null; 199 | System.out.println(download.toString()); 200 | try { 201 | input = new BufferedInputStream(download.openStream()); 202 | output = new FileOutputStream(new File("plugins/" + Bukkit.getUpdateFolder(), file.getName())); 203 | 204 | final byte[] data = new byte[1024]; 205 | int read; 206 | while ((read = input.read(data, 0, 1024)) != -1) { 207 | output.write(data, 0, read); 208 | } 209 | } catch (Exception ex) { 210 | System.err.println(" "); 211 | System.err.println("#################### - ERROR - ####################"); 212 | System.err.println("Could not auto-update " + plugin.getName()); 213 | System.err.println("#################### - ERROR - ####################"); 214 | System.err.println(" "); 215 | ex.printStackTrace(); 216 | } finally { 217 | try { 218 | if (input != null) input.close(); 219 | if (output != null) output.close(); 220 | System.err.println(" "); 221 | System.err.println("#################### - UPDATE - ####################"); 222 | System.err.println(plugin.getName() + " was successfully updated (" + localVersion + " -> " + version + ")"); 223 | System.err.println("Please restart your Server in order to use the new Version"); 224 | System.err.println(" "); 225 | } catch (IOException e) { 226 | e.printStackTrace(); 227 | } 228 | try { 229 | thread.join(); 230 | } catch (InterruptedException x) { 231 | x.printStackTrace(); 232 | } 233 | } 234 | } 235 | }, 10L); 236 | } 237 | } 238 | 239 | } 240 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Inventory; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import me.mrCookieSlime.CSCoreLibPlugin.general.Math.Calculator; 9 | 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.ChatColor; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.event.inventory.InventoryClickEvent; 14 | import org.bukkit.inventory.Inventory; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | public class ChestMenu { 18 | 19 | /** 20 | * Checks whether the Config contains the specified Path 21 | * 22 | * @param path The path in the Config File 23 | * @return True/false 24 | */ 25 | 26 | boolean clickable; 27 | boolean emptyClickable; 28 | String title; 29 | Inventory inv; 30 | List items; 31 | Map handlers; 32 | MenuOpeningHandler open; 33 | MenuCloseHandler close; 34 | MenuClickHandler playerclick; 35 | 36 | /** 37 | * Creates a new ChestMenu with the specified 38 | * Title 39 | * 40 | * @param title The title of the Menu 41 | */ 42 | public ChestMenu(String title) { 43 | this.title = ChatColor.translateAlternateColorCodes('&', title); 44 | this.clickable = false; 45 | this.emptyClickable = true; 46 | this.items = new ArrayList(); 47 | this.handlers = new HashMap(); 48 | this.open = new MenuOpeningHandler() { 49 | 50 | @Override 51 | public void onOpen(Player p) { 52 | } 53 | }; 54 | this.close = new MenuCloseHandler() { 55 | 56 | @Override 57 | public void onClose(Player p) { 58 | } 59 | }; 60 | this.playerclick = new MenuClickHandler() { 61 | 62 | @Override 63 | public boolean onClick(Player p, int slot, ItemStack item, ClickAction action) { 64 | return isPlayerInventoryClickable(); 65 | } 66 | }; 67 | } 68 | 69 | /** 70 | * Toggles whether Players can access there 71 | * Inventory while viewing this Menu 72 | * 73 | * @param clickable Whether the Player can access his Inventory 74 | * @return The ChestMenu Instance 75 | */ 76 | public ChestMenu setPlayerInventoryClickable(boolean clickable) { 77 | this.clickable = clickable; 78 | return this; 79 | } 80 | 81 | /** 82 | * Returns whether the Player's Inventory is 83 | * accessible while viewing this Menu 84 | * 85 | * @return Whether the Player Inventory is clickable 86 | */ 87 | public boolean isPlayerInventoryClickable() { 88 | return clickable; 89 | } 90 | 91 | /** 92 | * Toggles whether Players can click the 93 | * empty menu slots while viewing this Menu 94 | * 95 | * @param emptyClickable Whether the Player can click empty slots 96 | * @return The ChestMenu Instance 97 | */ 98 | public ChestMenu setEmptySlotsClickable(boolean emptyClickable) { 99 | this.emptyClickable = emptyClickable; 100 | return this; 101 | } 102 | 103 | /** 104 | * Returns whether the empty menu slots are 105 | * clickable while viewing this Menu 106 | * 107 | * @return Whether the empty menu slots are clickable 108 | */ 109 | public boolean isEmptySlotsClickable() { 110 | return emptyClickable; 111 | } 112 | 113 | /** 114 | * Adds a ClickHandler to ALL Slots of the 115 | * Player's Inventory 116 | * 117 | * @param handler The MenuClickHandler 118 | * @return The ChestMenu Instance 119 | */ 120 | public ChestMenu addPlayerInventoryClickHandler(MenuClickHandler handler) { 121 | this.playerclick = handler; 122 | return this; 123 | } 124 | 125 | /** 126 | * Adds an Item to the Inventory in that Slot 127 | * 128 | * @param slot The Slot in the Inventory 129 | * @param item The Item for that Slot 130 | * @return The ChestMenu Instance 131 | */ 132 | public ChestMenu addItem(int slot, ItemStack item) { 133 | final int size = this.items.size(); 134 | if (size > slot) this.items.set(slot, item); 135 | else { 136 | for (int i = 0; i < slot - size; i++) { 137 | this.items.add(null); 138 | } 139 | this.items.add(item); 140 | } 141 | return this; 142 | } 143 | 144 | /** 145 | * Adds an Item to the Inventory in that Slot 146 | * as well as a Click Handler 147 | * 148 | * @param slot The Slot in the Inventory 149 | * @param item The Item for that Slot 150 | * @param handler The MenuClickHandler for that Slot 151 | * @return The ChestMenu Instance 152 | */ 153 | public ChestMenu addItem(int slot, ItemStack item, MenuClickHandler clickHandler) { 154 | addItem(slot, item); 155 | addMenuClickHandler(slot, clickHandler); 156 | return this; 157 | } 158 | 159 | /** 160 | * Returns the ItemStack in that Slot 161 | * 162 | * @param slot The Slot in the Inventory 163 | * @return The ItemStack in that Slot 164 | */ 165 | public ItemStack getItemInSlot(int slot) { 166 | setup(); 167 | return this.inv.getItem(slot); 168 | } 169 | 170 | /** 171 | * Executes a certain Action upon clicking an 172 | * Item in the Menu 173 | * 174 | * @param slot The Slot in the Inventory 175 | * @param handler The MenuClickHandler 176 | * @return The ChestMenu Instance 177 | */ 178 | public ChestMenu addMenuClickHandler(int slot, MenuClickHandler handler) { 179 | this.handlers.put(slot, handler); 180 | return this; 181 | } 182 | 183 | /** 184 | * Executes a certain Action upon opening 185 | * this Menu 186 | * 187 | * @param handler The MenuOpeningHandler 188 | * @return The ChestMenu Instance 189 | */ 190 | public ChestMenu addMenuOpeningHandler(MenuOpeningHandler handler) { 191 | this.open = handler; 192 | return this; 193 | } 194 | 195 | /** 196 | * Executes a certain Action upon closing 197 | * this Menu 198 | * 199 | * @param handler The MenuCloseHandler 200 | * @return The ChestMenu Instance 201 | */ 202 | public ChestMenu addMenuCloseHandler(MenuCloseHandler handler) { 203 | this.close = handler; 204 | return this; 205 | } 206 | 207 | /** 208 | * Finishes the Creation of the Menu 209 | * 210 | * @return The ChestMenu Instance 211 | */ 212 | @Deprecated 213 | public ChestMenu build() { 214 | return this; 215 | } 216 | 217 | /** 218 | * Returns an Array containing the Contents 219 | * of this Inventory 220 | * 221 | * @return The Contents of this Inventory 222 | */ 223 | public ItemStack[] getContents() { 224 | setup(); 225 | return this.inv.getContents(); 226 | } 227 | 228 | private void setup() { 229 | if (this.inv != null) return; 230 | this.inv = Bukkit.createInventory(null, Calculator.formToLine(this.items.size()) * 9, title); 231 | for (int i = 0; i < this.items.size(); i++) { 232 | this.inv.setItem(i, this.items.get(i)); 233 | } 234 | } 235 | 236 | /** 237 | * Resets this ChestMenu to a Point BEFORE the User interacted with it 238 | */ 239 | public void reset(boolean update) { 240 | if (update) this.inv.clear(); 241 | else this.inv = Bukkit.createInventory(null, Calculator.formToLine(this.items.size()) * 9, title); 242 | for (int i = 0; i < this.items.size(); i++) { 243 | this.inv.setItem(i, this.items.get(i)); 244 | } 245 | } 246 | 247 | /** 248 | * Modifies an ItemStack in an ALREADY OPENED ChestMenu 249 | * 250 | * @param slot The Slot of the Item which will be replaced 251 | * @param item The new Item 252 | */ 253 | public void replaceExistingItem(int slot, ItemStack item) { 254 | setup(); 255 | this.inv.setItem(slot, item); 256 | } 257 | 258 | /** 259 | * Opens this Menu for the specified Player/s 260 | * 261 | * @param players The Players who will see this Menu 262 | */ 263 | public void open(Player... players) { 264 | setup(); 265 | for (Player p: players) { 266 | p.openInventory(this.inv); 267 | Maps.getInstance().menus.put(p.getUniqueId(), this); 268 | if (open != null) open.onOpen(p); 269 | } 270 | } 271 | 272 | /** 273 | * Returns the MenuClickHandler which was registered for the specified Slot 274 | * 275 | * @param slot The Slot in the Inventory 276 | * @return The MenuClickHandler registered for the specified Slot 277 | */ 278 | public MenuClickHandler getMenuClickHandler(int slot) { 279 | return handlers.get(slot); 280 | } 281 | 282 | /** 283 | * Returns the registered MenuCloseHandler 284 | * 285 | * @return The registered MenuCloseHandler 286 | */ 287 | public MenuCloseHandler getMenuCloseHandler() { 288 | return close; 289 | } 290 | 291 | /** 292 | * Returns the registered MenuOpeningHandler 293 | * 294 | * @return The registered MenuOpeningHandler 295 | */ 296 | public MenuOpeningHandler getMenuOpeningHandler() { 297 | return open; 298 | } 299 | 300 | /** 301 | * Returns the registered MenuClickHandler 302 | * for Player Inventories 303 | * 304 | * @return The registered MenuClickHandler 305 | */ 306 | public MenuClickHandler getPlayerInventoryClickHandler() { 307 | return playerclick; 308 | } 309 | 310 | /** 311 | * Converts this ChestMenu Instance into a 312 | * normal Inventory 313 | * 314 | * @return The converted Inventory 315 | */ 316 | public Inventory toInventory() { 317 | return this.inv; 318 | } 319 | 320 | @FunctionalInterface 321 | public interface MenuClickHandler { 322 | public boolean onClick(Player p, int slot, ItemStack item, ClickAction action); 323 | } 324 | 325 | public interface AdvancedMenuClickHandler extends MenuClickHandler { 326 | public boolean onClick(InventoryClickEvent e, Player p, int slot, ItemStack cursor, ClickAction action); 327 | } 328 | 329 | @FunctionalInterface 330 | public interface MenuOpeningHandler { 331 | public void onOpen(Player p); 332 | } 333 | 334 | @FunctionalInterface 335 | public interface MenuCloseHandler { 336 | public void onClose(Player p); 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/general/Reflection/ReflectionUtils.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.general.Reflection; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.lang.reflect.Field; 5 | import java.lang.reflect.Method; 6 | import java.util.Arrays; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import me.mrCookieSlime.CSCoreLibPlugin.general.ListUtils; 12 | 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.entity.Player; 15 | 16 | @Deprecated 17 | public class ReflectionUtils { 18 | 19 | private static Method handle_player, handle_world, handle_entity, handle_animals, sendPacket; 20 | private static Field player_connection; 21 | private static final Map, Class> conversion = new HashMap, Class>(); 22 | private static String currentVersion; 23 | 24 | static { 25 | conversion.put(Byte.class, Byte.TYPE); 26 | conversion.put(Short.class, Short.TYPE); 27 | conversion.put(Integer.class, Integer.TYPE); 28 | conversion.put(Long.class, Long.TYPE); 29 | conversion.put(Character.class, Character.TYPE); 30 | conversion.put(Float.class, Float.TYPE); 31 | conversion.put(Double.class, Double.TYPE); 32 | conversion.put(Boolean.class, Boolean.TYPE); 33 | 34 | try { 35 | handle_world = getClass(PackageName.OBC, "CraftWorld").getMethod("getHandle"); 36 | handle_player = getClass(PackageName.OBC, "entity.CraftPlayer").getMethod("getHandle"); 37 | handle_entity = getClass(PackageName.OBC, "entity.CraftEntity").getMethod("getHandle"); 38 | handle_animals = getClass(PackageName.OBC, "entity.CraftAnimals").getMethod("getHandle"); 39 | player_connection = getClass(PackageName.NMS, "EntityPlayer").getField("playerConnection"); 40 | sendPacket = getMethod(getClass(PackageName.NMS, "PlayerConnection"), "sendPacket"); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | 46 | /** 47 | * Returns a certain Method in the specified Class 48 | * 49 | * @param c The Class in which the Method is in 50 | * @param method The Method you are looking for 51 | * @return The found Method 52 | */ 53 | public static Method getMethod(Class c, String method) { 54 | for (Method m : c.getMethods()) { 55 | if (m.getName().equals(method)) return m; 56 | } 57 | return null; 58 | } 59 | 60 | /** 61 | * Returns the Method with certain Parameters 62 | * 63 | * @param c The Class in which the Method is in 64 | * @param method The Method you are looking for 65 | * @param paramTypes The Types of the Parameters 66 | * @return The found Method 67 | */ 68 | public static Method getMethod(Class c, String method, Class... paramTypes) { 69 | Class[] t = toPrimitiveTypeArray(paramTypes); 70 | for (Method m : c.getMethods()) { 71 | Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); 72 | if ((m.getName().equals(method)) && (equalsTypeArray(types, t))) 73 | return m; 74 | } 75 | return null; 76 | } 77 | 78 | /** 79 | * Returns the Field of a Class 80 | * 81 | * @param c The Class conating this Field 82 | * @param field The name of the Field you are looking for 83 | * @return The found Field 84 | * 85 | * @throws Exception 86 | */ 87 | public static Field getField(Class c, String field) throws Exception { 88 | return c.getDeclaredField(field); 89 | } 90 | 91 | /** 92 | * Modifies a Field in an Object 93 | * 94 | * @param object The Object containing the Field 95 | * @param field The Name of that Field 96 | * @param value The Value for that Field 97 | */ 98 | public static void setFieldValue(Object object, String field, Object value) throws Exception { 99 | Field f = getField(object.getClass(), field); 100 | f.setAccessible(true); 101 | f.set(object, value); 102 | } 103 | 104 | /** 105 | * Returns the Value of a Field in an Object 106 | * 107 | * @param object The Object containing the Field 108 | * @param field The Name of that Field 109 | * @return The Value of a Field 110 | */ 111 | public static Object getFieldValue(Object object, String field) throws Exception { 112 | Field f = getField(object.getClass(), field); 113 | f.setAccessible(true); 114 | return f.get(object); 115 | } 116 | 117 | /** 118 | * Converts the Classes to a Primitive Type Array 119 | * in order to be used as paramaters 120 | * 121 | * @param classes The Types you want to convert 122 | * @return An Array of primitive Types 123 | */ 124 | public static Class[] toPrimitiveTypeArray(Class... classes) { 125 | int a = classes != null ? classes.length : 0; 126 | Class[] types = new Class[a]; 127 | for (int i = 0; i < a; i++) { 128 | types[i] = conversion.containsKey(classes[i]) ? conversion.get(classes[i]): classes[i]; 129 | } 130 | return types; 131 | } 132 | 133 | /** 134 | * Converts the Classes of the specified Objects 135 | * to a Primitive Type Array 136 | * in order to be used as paramaters 137 | * 138 | * @param objects The Types you want to convert 139 | * @return An Array of primitive Types 140 | */ 141 | public static Class[] toPrimitiveTypeArray(Object... objects) { 142 | int a = objects != null ? objects.length : 0; 143 | Class[] types = new Class[a]; 144 | for (int i = 0; i < a; i++) 145 | types[i] = conversion.containsKey(objects[i].getClass()) ? conversion.get(objects[i].getClass()): objects[i].getClass(); 146 | return types; 147 | } 148 | 149 | /** 150 | * Returns the Constructor of a Class with the specified Parameters 151 | * 152 | * @param c The Class containing the Constructor 153 | * @param paramTypes The Parameters for that Constructor 154 | * @return The Constructor for that Class 155 | */ 156 | public static Constructor getConstructor(Class c, Class... paramTypes) { 157 | Class[] t = toPrimitiveTypeArray(paramTypes); 158 | for (Constructor con : c.getConstructors()) { 159 | Class[] types = toPrimitiveTypeArray(con.getParameterTypes()); 160 | if (equalsTypeArray(types, t)) return con; 161 | } 162 | return null; 163 | } 164 | 165 | /** 166 | * Shortcut for NMS Classes 167 | * 168 | * @param name The Name of the Class you are looking for 169 | * @return The Class with that name in the NMS Package 170 | */ 171 | public static Class getClass(String name) throws Exception { 172 | return getClass(PackageName.NMS, name); 173 | } 174 | 175 | /** 176 | * Returns an Instance of the NMS class for your Object 177 | * 178 | * @param type The Type of NMS Class you want to get 179 | * @param object The Object you want to get the Handle of 180 | * @return An Instance of the NMS class of your Object 181 | * @throws Exception 182 | */ 183 | public static Object getHandle(CraftObject type, Object object) throws Exception { 184 | switch(type) { 185 | case PLAYER: 186 | return handle_player.invoke(object); 187 | case WORLD: 188 | return handle_world.invoke(object); 189 | case ENTITY: 190 | return handle_entity.invoke(object); 191 | case ANIMALS: 192 | return handle_animals.invoke(object); 193 | default: 194 | return null; 195 | } 196 | } 197 | 198 | /** 199 | * Sends a Packet to the specified Player 200 | * 201 | * @param p The Player you want to send the Packet to 202 | * @param packet The Packet you want to send 203 | * @throws Exception 204 | */ 205 | public static void sendPacket(Player p, Object packet) throws Exception { 206 | try { 207 | sendPacket.invoke(player_connection.get(getHandle(CraftObject.PLAYER, p)), packet); 208 | } catch(NullPointerException x) { 209 | x.printStackTrace(); 210 | System.err.println("Packet Method: " + sendPacket); 211 | System.err.println("Player Connection: " + player_connection); 212 | System.err.println("Player Handle: " + getHandle(CraftObject.PLAYER, p)); 213 | System.err.println("Packet: " + packet); 214 | } 215 | } 216 | 217 | /** 218 | * Returns a Class inside a Class 219 | * 220 | * @param path The Package in which the Class can be found in 221 | * @param name The Name of the Class your Inner class is located in 222 | * @param subname The Name of the inner Class you are looking for 223 | * @return The Class in your specified Class 224 | */ 225 | public static Class getInnerClass(PackageName path, String name, String subname) throws Exception { 226 | return getClass(path, name + "$" + subname); 227 | } 228 | 229 | /** 230 | * Returns an OBC/NMS Class via Reflection 231 | * 232 | * @param path The Types of the Package you are targeting 233 | * @param name The Name of the Class you are looking for 234 | * @return The Class in that Package 235 | */ 236 | public static Class getClass(PackageName path, String name) throws Exception { 237 | return Class.forName(new StringBuilder().append(path.toPackage()).append(getVersion()).append(".").append(name).toString()); 238 | } 239 | 240 | /** 241 | * Returns an OBC/NMS Class via Reflection 242 | * 243 | * @param path The Types of the Package you are targeting 244 | * @param names The Names of the Classes you are looking for 245 | * @return The Class in that Package 246 | */ 247 | public static Class tryClass(PackageName path, String... names) throws Exception { 248 | for (String name: names) { 249 | try { 250 | Class c = Class.forName(new StringBuilder().append(path.toPackage()).append(getVersion()).append(".").append(name).toString()); 251 | return c; 252 | } catch(ClassNotFoundException x) { 253 | } 254 | } 255 | System.err.println("[CS-CoreLib - Reflection] Could not find Class(es): \"" + ListUtils.toString(names) + "\""); 256 | return null; 257 | } 258 | 259 | /** 260 | * Returns a Class's field via Reflection 261 | * 262 | * @param c The class you are targeting 263 | * @param names The Names of the fields you are looking for 264 | * @return The field in that class 265 | */ 266 | public static Field tryField(Class c, String... names) throws Exception { 267 | for (String name: names) { 268 | try { 269 | Field f = c.getDeclaredField(name); 270 | if (f != null) return f; 271 | } catch(NoSuchFieldException x) { 272 | } 273 | } 274 | System.err.println("[CS-CoreLib - Reflection] Could not find Field(s): \"" + ListUtils.toString(names) + "\" in Class " + c.getName()); 275 | return null; 276 | } 277 | 278 | /** 279 | * Modifies a Field in an Object 280 | * 281 | * @param object The Object containing the Field 282 | * @param value The Value for that Field 283 | * @param names The Names of the fields you are looking for 284 | */ 285 | public static void trySetField(Object object, Object value, String... names) throws Exception { 286 | Class c = object.getClass(); 287 | for (String name: names) { 288 | try { 289 | Field f = getField(c, name); 290 | f.setAccessible(true); 291 | f.set(object, value); 292 | } catch(Exception x) { 293 | } 294 | } 295 | System.err.println("[CS-CoreLib - Reflection] Could not find Field(s): \"" + ListUtils.toString(names) + "\" in Class " + c.getName()); 296 | } 297 | 298 | /** 299 | * Returns a Class's Method via Reflection 300 | * 301 | * @param c The class you are targeting 302 | * @param names The Names of the methods you are looking for 303 | * @param params The Parameters of your Method 304 | * @return The field in that class 305 | */ 306 | public static Method tryMethod(Class c, String[] names, Class... params) throws Exception { 307 | for (String name: names) { 308 | try { 309 | Method m = getMethod(c, name, params); 310 | if (m != null) return m; 311 | } catch(Exception x) { 312 | } 313 | } 314 | System.err.println("[CS-CoreLib - Reflection] Could not find Method(s): \"" + ListUtils.toString(names) + "\" in Class " + c.getName()); 315 | return null; 316 | } 317 | 318 | /** 319 | * Returns the formatted Server Version usable for Reflection 320 | * 321 | * @return The formatted Server Version 322 | */ 323 | public static String getVersion() { 324 | if (currentVersion == null) currentVersion = Bukkit.getServer().getClass().getPackage().getName().substring(Bukkit.getServer().getClass().getPackage().getName().lastIndexOf(".") + 1); 325 | return currentVersion; 326 | } 327 | 328 | public static boolean isVersion(String... prefixes) { 329 | String version = getVersion(); 330 | 331 | for (String prefix: prefixes) { 332 | if (version.startsWith(prefix)) return true; 333 | } 334 | 335 | return false; 336 | } 337 | 338 | /** 339 | * Compares multiple Type Arrays 340 | * 341 | * @param a The first Array for comparison 342 | * @param o All following Arrays you want to compare 343 | * @return Whether they equal each other 344 | */ 345 | private static boolean equalsTypeArray(Class[] a, Class... o) { 346 | if (a.length != o.length) 347 | return false; 348 | for (int i = 0; i < a.length; i++) 349 | if ((!a[i].equals(o[i])) && (!a[i].isAssignableFrom(o[i]))) 350 | return false; 351 | return true; 352 | } 353 | 354 | /** 355 | * Returns all Enum Constants in an Enum 356 | * 357 | * @param c The Enum you are targeting 358 | * @return An ArrayList of all Enum Constants in that Enum 359 | */ 360 | public static List getEnumConstants(Class c) { 361 | return Arrays.asList(c.getEnumConstants()); 362 | } 363 | 364 | /** 365 | * Returns a specific Enum Constant in an Enum 366 | * 367 | * @param c The Enum you are targeting 368 | * @param name The Name of the Constant you are targeting 369 | * @return The found Enum Constant 370 | */ 371 | public static Object getEnumConstant(Class c, String name) { 372 | for (Object o: c.getEnumConstants()) { 373 | if (o.toString().equals(name)) return o; 374 | } 375 | return null; 376 | } 377 | } 378 | -------------------------------------------------------------------------------- /src/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java: -------------------------------------------------------------------------------- 1 | package me.mrCookieSlime.CSCoreLibPlugin.Configuration; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | import java.util.List; 8 | import java.util.Set; 9 | import java.util.UUID; 10 | 11 | import org.bukkit.Bukkit; 12 | import org.bukkit.ChatColor; 13 | import org.bukkit.Chunk; 14 | import org.bukkit.Location; 15 | import org.bukkit.Sound; 16 | import org.bukkit.World; 17 | import org.bukkit.configuration.file.FileConfiguration; 18 | import org.bukkit.configuration.file.YamlConfiguration; 19 | import org.bukkit.inventory.Inventory; 20 | import org.bukkit.inventory.ItemStack; 21 | import org.bukkit.inventory.meta.ItemMeta; 22 | import org.bukkit.inventory.meta.SkullMeta; 23 | import org.bukkit.plugin.Plugin; 24 | 25 | import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; 26 | import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; 27 | 28 | 29 | public class Config { 30 | 31 | File file; 32 | FileConfiguration config; 33 | 34 | /** 35 | * Creates a new Config Object for the config.yml File of 36 | * the specified Plugin 37 | * 38 | * @param plugin The Instance of the Plugin, the config.yml is referring to 39 | */ 40 | public Config(Plugin plugin) { 41 | this.file = new File("plugins/" + plugin.getDescription().getName().replace(" ", "_") + "/config.yml"); 42 | this.config = YamlConfiguration.loadConfiguration(this.file); 43 | } 44 | 45 | /** 46 | * Creates a new Config Object for the specified File 47 | * 48 | * @param file The File for which the Config object is created for 49 | */ 50 | public Config(File file) { 51 | this.file = file; 52 | this.config = YamlConfiguration.loadConfiguration(this.file); 53 | } 54 | 55 | /** 56 | * Creates a new Config Object for the specified File and FileConfiguration 57 | * 58 | * @param file The File to save to 59 | * @param config The FileConfiguration 60 | */ 61 | public Config(File file, FileConfiguration config) { 62 | this.file=file; 63 | this.config=config; 64 | } 65 | 66 | /** 67 | * Creates a new Config Object for the File with in 68 | * the specified Location 69 | * 70 | * @param path The Path of the File which the Config object is created for 71 | */ 72 | public Config(String path) { 73 | this.file = new File(path); 74 | this.config = YamlConfiguration.loadConfiguration(this.file); 75 | } 76 | 77 | /** 78 | * Returns the File the Config is handling 79 | * 80 | * @return The File this Config is handling 81 | */ 82 | public File getFile() { 83 | return this.file; 84 | } 85 | 86 | /** 87 | * Converts this Config Object into a plain FileConfiguration Object 88 | * 89 | * @return The converted FileConfiguration Object 90 | */ 91 | public FileConfiguration getConfiguration() { 92 | return this.config; 93 | } 94 | 95 | protected void store(String path, Object value) { 96 | this.config.set(path, value); 97 | } 98 | 99 | /** 100 | * Sets the Value for the specified Path 101 | * 102 | * @param path The path in the Config File 103 | * @param value The Value for that Path 104 | */ 105 | public void setValue(String path, Object value) { 106 | if (value == null) { 107 | this.store(path, value); 108 | this.store(path + "_extra", null); 109 | } 110 | else if (value instanceof Inventory) { 111 | for (int i = 0; i < ((Inventory) value).getSize(); i++) { 112 | setValue(path + "." + i, ((Inventory) value).getItem(i)); 113 | } 114 | } 115 | else if (value instanceof Date) { 116 | this.store(path, String.valueOf(((Date) value).getTime())); 117 | } 118 | else if (value instanceof Long) { 119 | this.store(path, String.valueOf(value)); 120 | } 121 | else if (value instanceof UUID) { 122 | this.store(path, value.toString()); 123 | } 124 | else if (value instanceof Sound) { 125 | this.store(path, String.valueOf(value)); 126 | } 127 | else if (value instanceof ItemStack) { 128 | this.store(path, new ItemStack((ItemStack) value)); 129 | try { 130 | if (((ItemStack) value).hasItemMeta() && ((ItemStack) value).getItemMeta() instanceof SkullMeta) { 131 | this.store(path + "_extra.custom-skull", CustomSkull.getTexture((ItemStack) value)); 132 | this.store(path + "_extra.custom-skullOwner", CustomSkull.getName((ItemStack) value)); 133 | } 134 | } catch (Exception e) { 135 | e.printStackTrace(); 136 | } 137 | } 138 | else if (value instanceof Location) { 139 | setValue(path + ".x", ((Location) value).getX()); 140 | setValue(path + ".y", ((Location) value).getY()); 141 | setValue(path + ".z", ((Location) value).getZ()); 142 | setValue(path + ".pitch", ((Location) value).getPitch()); 143 | setValue(path + ".yaw", ((Location) value).getYaw()); 144 | setValue(path + ".world", ((Location) value).getWorld().getName()); 145 | } 146 | else if (value instanceof Chunk) { 147 | setValue(path + ".x", ((Chunk) value).getX()); 148 | setValue(path + ".z", ((Chunk) value).getZ()); 149 | setValue(path + ".world", ((Chunk) value).getWorld().getName()); 150 | } 151 | else if (value instanceof World) { 152 | this.store(path, ((World) value).getName()); 153 | } 154 | else this.store(path, value); 155 | } 156 | 157 | /** 158 | * Saves the Config Object to its File 159 | */ 160 | public void save() { 161 | try { 162 | config.save(file); 163 | } catch (IOException e) { 164 | } 165 | } 166 | 167 | /** 168 | * Saves the Config Object to a File 169 | * 170 | * @param file The File you are saving this Config to 171 | */ 172 | public void save(File file) { 173 | try { 174 | config.save(file); 175 | } catch (IOException e) { 176 | } 177 | } 178 | 179 | 180 | /** 181 | * Sets the Value for the specified Path 182 | * (IF the Path does not yet exist) 183 | * 184 | * @param path The path in the Config File 185 | * @param value The Value for that Path 186 | */ 187 | public void setDefaultValue(String path, Object value) { 188 | if (!contains(path)) setValue(path, value); 189 | } 190 | 191 | /** 192 | * Checks whether the Config contains the specified Path 193 | * 194 | * @param path The path in the Config File 195 | * @return True/false 196 | */ 197 | public boolean contains(String path) { 198 | return config.contains(path); 199 | } 200 | 201 | /** 202 | * Returns the Object at the specified Path 203 | * 204 | * @param path The path in the Config File 205 | * @return The Value at that Path 206 | */ 207 | public Object getValue(String path) { 208 | return config.get(path); 209 | } 210 | 211 | /** 212 | * Returns the ItemStack at the specified Path 213 | * 214 | * @param path The path in the Config File 215 | * @return The ItemStack at that Path 216 | */ 217 | public ItemStack getItem(String path) { 218 | ItemStack item = config.getItemStack(path); 219 | if (item == null) return null; 220 | try { 221 | if (item.hasItemMeta() && item.getItemMeta() instanceof SkullMeta) { 222 | if (this.contains(path + "_extra.custom-skull")) item = CustomSkull.getItem((ItemStack) item, this.getString(path + "_extra.custom-skull")); 223 | if (this.contains(path + "_extra.custom-skullOwner") && !((ItemStack) item).getItemMeta().hasDisplayName()) { 224 | ItemMeta im = ((ItemStack) item).getItemMeta(); 225 | im.setDisplayName(ChatColor.RESET + this.getString(path + "_extra.custom-skullOwner") + "'s Head"); 226 | ((ItemStack) item).setItemMeta(im); 227 | } 228 | } 229 | else { 230 | this.store(path + "_extra.custom-skull", null); 231 | this.store(path + "_extra.custom-skullOwner", null); 232 | } 233 | } catch (Exception e) { 234 | e.printStackTrace(); 235 | } 236 | return item; 237 | } 238 | 239 | /** 240 | * Returns a randomly chosen String from an 241 | * ArrayList at the specified Path 242 | * 243 | * @param path The path in the Config File 244 | * @return A randomly chosen String from the ArrayList at that Path 245 | */ 246 | @Deprecated 247 | public String getRandomStringfromList(String path) { 248 | return getStringList(path).get(CSCoreLib.randomizer().nextInt(getStringList(path).size())); 249 | } 250 | 251 | /** 252 | * Returns a randomly chosen Integer from an 253 | * ArrayList at the specified Path 254 | * 255 | * @param path The path in the Config File 256 | * @return A randomly chosen Integer from the ArrayList at that Path 257 | */ 258 | @Deprecated 259 | public int getRandomIntfromList(String path) { 260 | return getIntList(path).get(CSCoreLib.randomizer().nextInt(getIntList(path).size())); 261 | } 262 | 263 | /** 264 | * Returns the String at the specified Path 265 | * 266 | * @param path The path in the Config File 267 | * @return The String at that Path 268 | */ 269 | public String getString(String path) { 270 | return config.getString(path); 271 | } 272 | 273 | /** 274 | * Returns the Integer at the specified Path 275 | * 276 | * @param path The path in the Config File 277 | * @return The Integer at that Path 278 | */ 279 | public int getInt(String path) { 280 | return config.getInt(path); 281 | } 282 | 283 | /** 284 | * Returns the Boolean at the specified Path 285 | * 286 | * @param path The path in the Config File 287 | * @return The Boolean at that Path 288 | */ 289 | public boolean getBoolean(String path) { 290 | return config.getBoolean(path); 291 | } 292 | 293 | /** 294 | * Returns the StringList at the specified Path 295 | * 296 | * @param path The path in the Config File 297 | * @return The StringList at that Path 298 | */ 299 | public List getStringList(String path) { 300 | return config.getStringList(path); 301 | } 302 | 303 | /** 304 | * Returns the ItemList at the specified Path 305 | * 306 | * @param path The path in the Config File 307 | * @return The ItemList at that Path 308 | */ 309 | public List getItemList(String path) { 310 | List list = new ArrayList(); 311 | for (String key: getKeys(path)) { 312 | if (!key.endsWith("_extra")) list.add(getItem(path + "." + key)); 313 | } 314 | return list; 315 | } 316 | 317 | /** 318 | * Returns the IntegerList at the specified Path 319 | * 320 | * @param path The path in the Config File 321 | * @return The IntegerList at that Path 322 | */ 323 | public List getIntList(String path) { 324 | return config.getIntegerList(path); 325 | } 326 | 327 | /** 328 | * Recreates the File of this Config 329 | */ 330 | public void createFile() { 331 | try { 332 | this.file.createNewFile(); 333 | } catch (IOException e) { 334 | } 335 | } 336 | 337 | /** 338 | * Returns the Float at the specified Path 339 | * 340 | * @param path The path in the Config File 341 | * @return The Float at that Path 342 | */ 343 | public Float getFloat(String path) { 344 | return Float.valueOf(String.valueOf(getValue(path))); 345 | } 346 | 347 | /** 348 | * Returns the Long at the specified Path 349 | * 350 | * @param path The path in the Config File 351 | * @return The Long at that Path 352 | */ 353 | public Long getLong(String path) { 354 | return Long.valueOf(String.valueOf(getValue(path))); 355 | } 356 | 357 | /** 358 | * Returns the Sound at the specified Path 359 | * 360 | * @param path The path in the Config File 361 | * @return The Sound at that Path 362 | */ 363 | public Sound getSound(String path) { 364 | return Sound.valueOf(getString(path)); 365 | } 366 | 367 | /** 368 | * Returns the Date at the specified Path 369 | * 370 | * @param path The path in the Config File 371 | * @return The Date at that Path 372 | */ 373 | public Date getDate(String path) { 374 | return new Date(getLong(path)); 375 | } 376 | 377 | /** 378 | * Returns the Chunk at the specified Path 379 | * 380 | * @param path The path in the Config File 381 | * @return The Chunk at that Path 382 | */ 383 | public Chunk getChunk(String path) { 384 | return Bukkit.getWorld(getString(path + ".world")).getChunkAt(getInt(path + ".x"), getInt(path + ".z")); 385 | } 386 | 387 | /** 388 | * Returns the UUID at the specified Path 389 | * 390 | * @param path The path in the Config File 391 | * @return The UUID at that Path 392 | */ 393 | public UUID getUUID(String path) { 394 | return UUID.fromString(getString(path)); 395 | } 396 | 397 | /** 398 | * Returns the World at the specified Path 399 | * 400 | * @param path The path in the Config File 401 | * @return The World at that Path 402 | */ 403 | public World getWorld(String path) { 404 | return Bukkit.getWorld(getString(path)); 405 | } 406 | 407 | /** 408 | * Returns the Double at the specified Path 409 | * 410 | * @param path The path in the Config File 411 | * @return The Double at that Path 412 | */ 413 | public Double getDouble(String path) { 414 | return config.getDouble(path); 415 | } 416 | 417 | /** 418 | * Returns the Location at the specified Path 419 | * 420 | * @param path The path in the Config File 421 | * @return The Location at that Path 422 | */ 423 | public Location getLocation(String path) { 424 | if (this.contains(path + ".pitch")) { 425 | return new Location( 426 | Bukkit.getWorld( 427 | getString(path + ".world")), 428 | getDouble(path + ".x"), 429 | getDouble(path + ".y"), 430 | getDouble(path + ".z"), 431 | getFloat(path + ".yaw"), 432 | getFloat(path + ".pitch") 433 | ); 434 | } 435 | else { 436 | return new Location( 437 | Bukkit.getWorld( 438 | this.getString(path + ".world")), 439 | this.getDouble(path + ".x"), 440 | this.getDouble(path + ".y"), 441 | this.getDouble(path + ".z") 442 | ); 443 | } 444 | } 445 | 446 | @Deprecated 447 | public void setLocation(String path, Location location) { 448 | setValue(path + ".x", location.getX()); 449 | setValue(path + ".y", location.getY()); 450 | setValue(path + ".z", location.getZ()); 451 | setValue(path + ".world", location.getWorld().getName()); 452 | } 453 | 454 | @Deprecated 455 | public void setInventory(String path, Inventory inventory) { 456 | for (int i = 0; i < inventory.getSize(); i++) { 457 | setValue(path + "." + i, inventory.getItem(i)); 458 | } 459 | } 460 | 461 | /** 462 | * Gets the Contents of an Inventory at the specified Path 463 | * 464 | * @param path The path in the Config File 465 | * @param size The Size of the Inventory 466 | * @param title The Title of the Inventory 467 | * @return The generated Inventory 468 | */ 469 | public Inventory getInventory(String path, int size, String title) { 470 | Inventory inventory = Bukkit.createInventory(null, size, title); 471 | for (int i = 0; i < size; i++) { 472 | inventory.setItem(i, getItem(path + "." + i)); 473 | } 474 | return inventory; 475 | } 476 | 477 | /** 478 | * Returns all Paths in this Config 479 | * 480 | * @return All Paths in this Config 481 | */ 482 | public Set getKeys() { 483 | return config.getKeys(false); 484 | } 485 | 486 | /** 487 | * Returns all Sub-Paths in this Config 488 | * 489 | * @param path The path in the Config File 490 | * @return All Sub-Paths of the specified Path 491 | */ 492 | public Set getKeys(String path) { 493 | return config.getConfigurationSection(path).getKeys(false); 494 | } 495 | 496 | /** 497 | * Reloads the Configuration File 498 | */ 499 | public void reload() { 500 | this.config = YamlConfiguration.loadConfiguration(this.file); 501 | } 502 | } 503 | --------------------------------------------------------------------------------