From 263e3e77689fde0c2589b5cac844f518aead5f62 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 01:07:35 +0000 Subject: [PATCH] forgot to push --- .../core/common/util/UtilOfflinePlayer.java | 29 +++++++++++++ .../core/common/util/UtilStreams.java | 42 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java new file mode 100644 index 000000000..cbc537082 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java @@ -0,0 +1,29 @@ +package mineplex.core.common.util; + +import java.io.File; +import java.io.FileInputStream; + +import org.bukkit.inventory.ItemStack; + +import com.java.sk89q.jnbt.NBTInputStream; +import com.java.sk89q.jnbt.NamedTag; + +public class UtilOfflinePlayer +{ + public static ItemStack loadOfflineInventory(File file) + { + try (NBTInputStream stream = new NBTInputStream(new FileInputStream(file))) + { + NamedTag tag = stream.readNamedTag(); + + System.out.println(tag); + + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java new file mode 100644 index 000000000..94774c9e8 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java @@ -0,0 +1,42 @@ +package mineplex.core.common.util; + +import java.util.stream.Stream; + +public class UtilStreams +{ + public static boolean IsEmpty(Stream stream) + { + return Sum(stream) != 0; + } + + public static int Sum(Stream stream) + { + return stream.mapToInt(v -> 1).sum(); + } + + public static Object[] ToArray(Stream stream) + { + return stream.toArray(); + } + + public static T Get(int index, Stream stream) + { + if (Sum(stream) < index + 1) + { + return null; + } + + return (T) ToArray(stream)[index]; + } + + public static T GetFirst(Stream stream) + { + return Get(0, stream); + } + + public static T GetLast(Stream stream) + { + return Get(Sum(stream) + 1, stream); + } + +}